his_api_controller.go 607KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/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. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "card_desc":
  229. order.CardDesc = desc
  230. break
  231. case "band_card_pay":
  232. order.BandCardPay = desc
  233. break
  234. case "ali_pay":
  235. order.AliPay = desc
  236. break
  237. case "wechat_pay":
  238. order.WechatPay = desc
  239. break
  240. case "fa_piao_number":
  241. order.FaPiaoNumber = desc
  242. break
  243. case "fa_piao_code":
  244. order.FaPiaoCode = desc
  245. break
  246. }
  247. err := service.SaveHisOrder(&order)
  248. if err == nil {
  249. c.ServeSuccessJSON(map[string]interface{}{
  250. "msg": "修改成功",
  251. })
  252. return
  253. } else {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  255. return
  256. }
  257. }
  258. func (c *HisApiController) GetMonthHisPatient() {
  259. record_date := c.GetString("record_date")
  260. //order_status, _ := c.GetInt64("type")
  261. timeLayout := "2006-01-02"
  262. loc, _ := time.LoadLocation("Local")
  263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  264. if err != nil {
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. recordDateTime := theTime.Unix()
  269. adminInfo := c.GetAdminUserInfo()
  270. var tempPatients []service.NewTempPatients
  271. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  272. // 获取当前时间
  273. now := time.Now()
  274. // 获取本月的第一天
  275. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  276. // 获取下个月的第一天
  277. nextMonth := firstDay.AddDate(0, 1, 0)
  278. // 获取本月的最后一天
  279. lastDay := nextMonth.Add(-time.Nanosecond)
  280. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  281. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  282. var patients []service.NewTempPatients
  283. var patients_two []service.NewTempPatients
  284. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. patients_two = append(patients_two, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. //}
  294. }
  295. } else {
  296. for _, item := range tempPatients {
  297. //过滤掉没挂号的和没开处方的
  298. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  299. patients = append(patients, item)
  300. }
  301. ////过滤掉没挂号的
  302. //if len(item.HisPatient) > 0 {
  303. // patients_two = append(patients_two, item)
  304. //}
  305. }
  306. }
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "list": patients,
  309. "list_two": patients_two,
  310. "chargePatients": chargePatients,
  311. })
  312. }
  313. func (c *HisApiController) GetBatchSettleAccounts() {
  314. order_ids := c.GetString("order_ids")
  315. admin_user_id, _ := c.GetInt64("admin_user_id")
  316. adminUser := c.GetAdminUserInfo()
  317. orders := strings.Split(order_ids, ",")
  318. var newOrders []models.Orders
  319. for _, item := range orders {
  320. order, _ := service.GetHisOrderByIDTenOne(item)
  321. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  322. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  323. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  324. orderInfos = append(orderInfos, orderInfos_two...)
  325. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  326. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  327. var diagnosis_ids []string
  328. if his.ID > 0 {
  329. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  330. } else {
  331. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  332. }
  333. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  334. var dia_config []*models.HisXtDiagnoseConfig
  335. var name string
  336. for _, item := range diagnosis_ids {
  337. id, _ := strconv.ParseInt(item, 10, 64)
  338. diagnosisConfig, _ := service.FindDiagnoseById(id)
  339. dia_config = append(dia_config, diagnosisConfig)
  340. if len(name) == 0 {
  341. name = diagnosisConfig.ClassName
  342. } else {
  343. name = name + "," + diagnosisConfig.ClassName
  344. }
  345. }
  346. var bedCostTotal float64 = 0 //床位总费
  347. var bedCostSelfTotal float64 = 0 //床位自费
  348. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  349. var bedSelfTotal float64 = 0 //床位部分项目自费
  350. var bedInscpTotal float64 = 0 //床位部分项目自费
  351. var operationCostTotal float64 = 0 //手术费
  352. var operationCostSelfTotal float64 = 0 //手术费
  353. var operationCostPartSelfTotal float64 = 0 //手术费
  354. var operationSelfTotal float64 = 0 //床位部分项目自费
  355. var operationInscpTotal float64 = 0 //床位部分项目自费
  356. var otherCostTotal float64 = 0 //其他费用
  357. var otherCostSelfTotal float64 = 0 //其他费用
  358. var otherCostPartSelfTotal float64 = 0 //其他费用
  359. var otherSelfTotal float64 = 0 //床位部分项目自费
  360. var otherInscpTotal float64 = 0 //床位部分项目自费
  361. var materialCostTotal float64 = 0 //材料费
  362. var materialCostSelfTotal float64 = 0 //材料费
  363. var materialCostPartSelfTotal float64 = 0 //材料费
  364. var materialSelfTotal float64 = 0 //床位部分项目自费
  365. var materialInscpTotal float64 = 0 //床位部分项目自费
  366. var westernMedicineCostTotal float64 = 0 //西药费
  367. var westernMedicineCostSelfTotal float64 = 0 //西药费
  368. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  369. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  370. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  371. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  372. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  373. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  374. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  375. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  376. var checkCostTotal float64 = 0 //检查费
  377. var checkCostSelfTotal float64 = 0 //检查费
  378. var checkCostPartSelfTotal float64 = 0 //检查费
  379. var checkSelfTotal float64 = 0 //床位部分项目自费
  380. var checkInscpTotal float64 = 0 //床位部分项目自费
  381. var laboratoryCostTotal float64 = 0 //化验费
  382. var laboratoryCostSelfTotal float64 = 0 //化验费
  383. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  384. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  385. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  386. var treatCostTotal float64 = 0 //治疗费用
  387. var treatCostSelfTotal float64 = 0 //治疗费用
  388. var treatCostPartSelfTotal float64 = 0 //治疗费用
  389. var treatSelfTotal float64 = 0 //床位部分项目自费
  390. var treatInscpTotal float64 = 0 //床位部分项目自费
  391. decimal.DivisionPrecision = 2
  392. for _, item := range orderInfos {
  393. if item.MedChrgitmType == "01" { //床位费
  394. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  395. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  396. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  397. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  398. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  399. }
  400. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  401. if item.MedChrgitmType == "03" { //检查费
  402. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  403. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  404. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  405. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  406. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  407. }
  408. } else {
  409. if item.MedChrgitmType == "03" { //检查费
  410. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  411. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  412. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  413. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  414. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  415. }
  416. }
  417. if item.MedChrgitmType == "04" { //化验费
  418. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  419. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  420. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  421. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  422. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  423. }
  424. if item.MedChrgitmType == "05" { //治疗费
  425. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  426. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  427. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  428. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  429. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  430. }
  431. if item.MedChrgitmType == "06" { //手术费
  432. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  433. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  434. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  435. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  436. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  437. }
  438. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  439. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  440. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  441. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  442. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  443. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  444. }
  445. if item.MedChrgitmType == "09" { //西药费
  446. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  447. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  448. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  449. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  450. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  451. }
  452. if item.MedChrgitmType == "11" { //中成费
  453. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  454. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  455. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  456. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  457. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  458. }
  459. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  461. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  462. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  463. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  464. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  465. }
  466. }
  467. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  468. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  470. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  471. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  472. var doctor_name string
  473. if roles.ID == 0 {
  474. doctor_name = "管理员"
  475. } else {
  476. doctor_name = roles.UserName
  477. }
  478. yiliao_leibie := ""
  479. switch order.MedType {
  480. case "11":
  481. yiliao_leibie = "普通门诊"
  482. break
  483. case "12":
  484. yiliao_leibie = "门诊挂号"
  485. break
  486. case "13":
  487. yiliao_leibie = "急诊"
  488. break
  489. case "14":
  490. yiliao_leibie = "门诊特殊病"
  491. break
  492. case "15":
  493. yiliao_leibie = "门诊统筹"
  494. break
  495. case "16":
  496. yiliao_leibie = "门诊慢性病"
  497. break
  498. case "21":
  499. yiliao_leibie = "普通住院"
  500. break
  501. }
  502. var newOrder models.Orders
  503. newOrder.Diagnosis = name
  504. newOrder.OrderInfos = orderInfos
  505. newOrder.Number = order.MdtrtId
  506. newOrder.Date = order.SettleAccountsDate
  507. newOrder.ChargeAdmin = charge_admin
  508. newOrder.PrintorAdmin = printor_admin
  509. newOrder.Order = order
  510. newOrder.BedCostTotal = bedCostTotal
  511. newOrder.BedCostSelfTotal = bedCostSelfTotal
  512. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  513. newOrder.BedSelfTotal = bedSelfTotal
  514. newOrder.BedInscpTotal = bedInscpTotal
  515. newOrder.OperationCostTotal = operationCostTotal
  516. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  517. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  518. newOrder.OperationSelfTotal = operationSelfTotal
  519. newOrder.OperationInscpTotal = operationInscpTotal
  520. newOrder.OtherCostTotal = otherCostTotal
  521. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  522. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  523. newOrder.OtherSelfTotal = otherSelfTotal
  524. newOrder.OtherInscpTotal = otherInscpTotal
  525. newOrder.MaterialCostTotal = materialCostTotal
  526. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  527. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  528. newOrder.MaterialSelfTotal = materialSelfTotal
  529. newOrder.MaterialInscpTotal = materialInscpTotal
  530. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  531. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  532. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  533. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  534. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  535. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  536. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  537. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  538. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  539. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  540. newOrder.CheckCostTotal = checkCostTotal
  541. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  542. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  543. newOrder.CheckSelfTotal = checkSelfTotal
  544. newOrder.CheckInscpTotal = checkInscpTotal
  545. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  546. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  547. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  548. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  549. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  550. newOrder.TreatCostTotal = treatCostTotal
  551. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  552. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  553. newOrder.TreatSelfTotal = treatSelfTotal
  554. newOrder.TreatInscpTotal = treatInscpTotal
  555. newOrder.DoctorInfo = doctor_info
  556. newOrder.DoctorName = doctor_name
  557. newOrder.HealthCardNo = order.PsnNo
  558. newOrder.YiliaoLeibie = yiliao_leibie
  559. newOrder.Patient = patient
  560. newOrder.OrgName = miConfig.OrgName
  561. newOrder.OrgCode = miConfig.Code
  562. newOrder.OrderNumber = order.Number
  563. newOrder.HisPatient = his
  564. newOrder.DiaConfig = dia_config
  565. newOrders = append(newOrders, newOrder)
  566. }
  567. c.ServeSuccessJSON(map[string]interface{}{
  568. "orders": newOrders,
  569. })
  570. }
  571. func (c *HisApiController) GetTestOrder() {
  572. order_id, _ := c.GetInt64("order_id")
  573. admin_user_id, _ := c.GetInt64("admin_user_id")
  574. adminUser := c.GetAdminUserInfo()
  575. order, _ := service.GetHisOrderByID(order_id)
  576. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  577. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  578. orderInfos = append(orderInfos, orderInfos_two...)
  579. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  580. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  581. var dia_config []*models.HisXtDiagnoseConfig
  582. var name string
  583. var bedCostTotal float64 = 0 //床位总费
  584. var bedCostSelfTotal float64 = 0 //床位自费
  585. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  586. var bedSelfTotal float64 = 0 //床位部分项目自费
  587. var bedInscpTotal float64 = 0 //床位部分项目自费
  588. var operationCostTotal float64 = 0 //手术费
  589. var operationCostSelfTotal float64 = 0 //手术费
  590. var operationCostPartSelfTotal float64 = 0 //手术费
  591. var operationSelfTotal float64 = 0 //床位部分项目自费
  592. var operationInscpTotal float64 = 0 //床位部分项目自费
  593. var otherCostTotal float64 = 0 //其他费用
  594. var otherCostSelfTotal float64 = 0 //其他费用
  595. var otherCostPartSelfTotal float64 = 0 //其他费用
  596. var otherSelfTotal float64 = 0 //床位部分项目自费
  597. var otherInscpTotal float64 = 0 //床位部分项目自费
  598. var materialCostTotal float64 = 0 //材料费
  599. var materialCostSelfTotal float64 = 0 //材料费
  600. var materialCostPartSelfTotal float64 = 0 //材料费
  601. var materialSelfTotal float64 = 0 //床位部分项目自费
  602. var materialInscpTotal float64 = 0 //床位部分项目自费
  603. var westernMedicineCostTotal float64 = 0 //西药费
  604. var westernMedicineCostSelfTotal float64 = 0 //西药费
  605. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  606. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  607. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  608. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  609. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  610. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  611. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  612. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  613. var checkCostTotal float64 = 0 //检查费
  614. var checkCostSelfTotal float64 = 0 //检查费
  615. var checkCostPartSelfTotal float64 = 0 //检查费
  616. var checkSelfTotal float64 = 0 //床位部分项目自费
  617. var checkInscpTotal float64 = 0 //床位部分项目自费
  618. var laboratoryCostTotal float64 = 0 //化验费
  619. var laboratoryCostSelfTotal float64 = 0 //化验费
  620. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  621. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  622. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  623. var treatCostTotal float64 = 0 //治疗费用
  624. var treatCostSelfTotal float64 = 0 //治疗费用
  625. var treatCostPartSelfTotal float64 = 0 //治疗费用
  626. var treatSelfTotal float64 = 0 //床位部分项目自费
  627. var treatInscpTotal float64 = 0 //床位部分项目自费
  628. decimal.DivisionPrecision = 2
  629. for _, item := range orderInfos {
  630. if item.MedChrgitmType == "01" { //床位费
  631. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  632. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  633. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  634. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  635. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  636. }
  637. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  638. if item.MedChrgitmType == "03" { //检查费
  639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  640. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  641. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  642. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  643. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  644. }
  645. } else {
  646. if item.MedChrgitmType == "03" { //检查费
  647. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  648. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  649. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  650. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  651. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  652. }
  653. }
  654. if item.MedChrgitmType == "04" { //化验费
  655. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  656. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  657. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  658. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  659. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  660. }
  661. if item.MedChrgitmType == "05" { //治疗费
  662. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  663. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  664. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  665. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  666. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  667. }
  668. if item.MedChrgitmType == "06" { //手术费
  669. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  670. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  671. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  672. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  673. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  674. }
  675. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  676. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  677. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  678. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  679. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  680. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  681. }
  682. if item.MedChrgitmType == "09" { //西药费
  683. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  684. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  685. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  686. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  687. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  688. }
  689. if item.MedChrgitmType == "11" { //中成费
  690. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  691. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  692. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  693. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  694. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  695. }
  696. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  698. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  699. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  700. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  701. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  702. }
  703. }
  704. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  705. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  707. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  708. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  709. var doctor_name string
  710. if roles.ID == 0 {
  711. doctor_name = "管理员"
  712. } else {
  713. doctor_name = roles.UserName
  714. }
  715. yiliao_leibie := ""
  716. switch order.MedType {
  717. case "11":
  718. yiliao_leibie = "普通门诊"
  719. break
  720. case "12":
  721. yiliao_leibie = "门诊挂号"
  722. break
  723. case "13":
  724. yiliao_leibie = "急诊"
  725. break
  726. case "14":
  727. yiliao_leibie = "门诊特殊病"
  728. break
  729. case "15":
  730. yiliao_leibie = "门诊统筹"
  731. break
  732. case "16":
  733. yiliao_leibie = "门诊慢性病"
  734. break
  735. case "21":
  736. yiliao_leibie = "普通住院"
  737. break
  738. }
  739. c.ServeSuccessJSON(map[string]interface{}{
  740. "diagnosis": name,
  741. "order_infos": orderInfos,
  742. "number": order.MdtrtId,
  743. "date": order.SettleAccountsDate,
  744. "charge_admin": charge_admin,
  745. "printor_admin": printor_admin,
  746. "info": order,
  747. "order": order,
  748. "bedCostTotal": bedCostTotal,
  749. "bedCostSelfTotal": bedCostSelfTotal,
  750. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  751. "bedSelfTotal": bedSelfTotal,
  752. "bedInscpTotal": bedInscpTotal,
  753. "operationCostTotal": operationCostTotal,
  754. "operationCostSelfTotal": operationCostSelfTotal,
  755. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  756. "operationSelfTotal": operationSelfTotal,
  757. "operationInscpTotal": operationInscpTotal,
  758. "otherCostTotal": otherCostTotal,
  759. "otherCostSelfTotal": otherCostSelfTotal,
  760. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  761. "otherSelfTotal": otherSelfTotal,
  762. "otherInscpTotal": otherInscpTotal,
  763. "materialCostTotal": materialCostTotal,
  764. "materialCostSelfTotal": materialCostSelfTotal,
  765. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  766. "materialSelfTotal": materialSelfTotal,
  767. "materialInscpTotal": materialInscpTotal,
  768. "westernMedicineCostTotal": westernMedicineCostTotal,
  769. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  770. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  771. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  772. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  773. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  774. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  775. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  776. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  777. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  778. "checkCostTotal": checkCostTotal,
  779. "checkCostSelfTotal": checkCostSelfTotal,
  780. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  781. "checkSelfTotal": checkSelfTotal,
  782. "checkInscpTotal": checkInscpTotal,
  783. "laboratoryCostTotal": laboratoryCostTotal,
  784. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  785. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  786. "laboratorySelfTotal": laboratorySelfTotal,
  787. "laboratoryInscpTotal": laboratoryInscpTotal,
  788. "treatCostTotal": treatCostTotal,
  789. "treatCostSelfTotal": treatCostSelfTotal,
  790. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  791. "treatSelfTotal": treatSelfTotal,
  792. "treatInscpTotal": treatInscpTotal,
  793. "doctor_info": doctor_info,
  794. "doctor_name": doctor_name,
  795. "health_card_no": order.PsnNo,
  796. "yiliao_leibie": yiliao_leibie,
  797. "patient": patient,
  798. "org_name": miConfig.OrgName,
  799. "org_code": miConfig.Code,
  800. "order_number": order.Number,
  801. "his_hospital": his_hospital,
  802. "dia_config": dia_config,
  803. })
  804. }
  805. type CustomFundPay struct {
  806. FundPayType string `json:"fund_pay_type"`
  807. FundPayamt float64 `json:"fund_payamt"`
  808. InscpScpAmt float64 `json:"inscp_scp_amt"`
  809. }
  810. func (c *PublicApiController) GetBaiLinExportData() {
  811. data := service.GetBaiLinOrderData()
  812. fmt.Println(len(data))
  813. var new_data []*models.NewCustomHisOrder
  814. for _, item := range data {
  815. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  816. new_data = append(new_data, item)
  817. }
  818. }
  819. fmt.Println(len(new_data))
  820. c.ServeSuccessJSON(map[string]interface{}{
  821. "list": new_data,
  822. })
  823. }
  824. func (c *HisApiController) GetHisUnChargePatientList() {
  825. record_date := c.GetString("record_date")
  826. sch_type, _ := c.GetInt64("sch_type")
  827. timeLayout := "2006-01-02"
  828. loc, _ := time.LoadLocation("Local")
  829. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  830. if err != nil {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. recordDateTime := theTime.Unix()
  835. adminInfo := c.GetAdminUserInfo()
  836. var tempPatients []*service.NewTempPatients
  837. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  838. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  839. var patients []*service.NewTempPatients
  840. var patients_two []*service.NewTempPatients
  841. for _, item := range tempPatients {
  842. //过滤掉没挂号的和没开处方的
  843. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  844. patients = append(patients, item)
  845. }
  846. //过滤掉没挂号的
  847. if len(item.HisPatient) > 0 {
  848. patients_two = append(patients_two, item)
  849. }
  850. }
  851. c.ServeSuccessJSON(map[string]interface{}{
  852. "list": patients,
  853. "list_two": patients_two,
  854. })
  855. }
  856. func (c *HisApiController) GetPrivateExpensesOrder() {
  857. //id, _ := c.GetInt64("id")
  858. //record_time := c.GetString("record_time")
  859. order_id, _ := c.GetInt64("order_id")
  860. admin_user_id, _ := c.GetInt64("admin_user_id")
  861. //timeLayout := "2006-01-02"
  862. //loc, _ := time.LoadLocation("Local")
  863. //
  864. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  865. //if err != nil {
  866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. // return
  868. //}
  869. //recordDateTime := theTime.Unix()
  870. adminUser := c.GetAdminUserInfo()
  871. order, _ := service.GetHisOrderByID(order_id)
  872. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  873. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  874. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  875. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  876. //var config []*models.HisXtDiagnoseConfig
  877. var name string
  878. if order.PType == 1 {
  879. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  880. for _, item := range diagnosis_ids {
  881. id, _ := strconv.ParseInt(item, 10, 64)
  882. diagnosisConfig, _ := service.FindDiagnoseById(id)
  883. if len(name) == 0 {
  884. name = diagnosisConfig.ClassName
  885. } else {
  886. name = name + "," + diagnosisConfig.ClassName
  887. }
  888. }
  889. } else {
  890. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  891. for _, item := range diagnosis_ids {
  892. id, _ := strconv.ParseInt(item, 10, 64)
  893. diagnosisConfig, _ := service.FindDiagnoseById(id)
  894. if len(name) == 0 {
  895. name = diagnosisConfig.ClassName
  896. } else {
  897. name = name + "," + diagnosisConfig.ClassName
  898. }
  899. }
  900. }
  901. var bedCostTotal float64 = 0 //床位总费
  902. var bedCostSelfTotal float64 = 0 //床位自费
  903. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  904. var bedSelfTotal float64 = 0 //床位部分项目自费
  905. var bedInscpTotal float64 = 0 //床位部分项目自费
  906. var operationCostTotal float64 = 0 //手术费
  907. var operationCostSelfTotal float64 = 0 //手术费
  908. var operationCostPartSelfTotal float64 = 0 //手术费
  909. var operationSelfTotal float64 = 0 //床位部分项目自费
  910. var operationInscpTotal float64 = 0 //床位部分项目自费
  911. var otherCostTotal float64 = 0 //其他费用
  912. //var otherCostSelfTotal float64 = 0 //其他费用
  913. var otherCostPartSelfTotal float64 = 0 //其他费用
  914. //var otherSelfTotal float64 = 0 //床位部分项目自费
  915. //var otherInscpTotal float64 = 0 //床位部分项目自费
  916. var materialCostTotal float64 = 0 //材料费
  917. var materialCostSelfTotal float64 = 0 //材料费
  918. var materialCostPartSelfTotal float64 = 0 //材料费
  919. var materialSelfTotal float64 = 0 //床位部分项目自费
  920. var materialInscpTotal float64 = 0 //床位部分项目自费
  921. var westernMedicineCostTotal float64 = 0 //西药费
  922. var westernMedicineCostSelfTotal float64 = 0 //西药费
  923. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  924. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  925. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  926. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  927. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  928. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  929. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  930. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  931. var checkCostTotal float64 = 0 //检查费
  932. var checkCostSelfTotal float64 = 0 //检查费
  933. var checkCostPartSelfTotal float64 = 0 //检查费
  934. var checkSelfTotal float64 = 0 //床位部分项目自费
  935. var checkInscpTotal float64 = 0 //床位部分项目自费
  936. var laboratoryCostTotal float64 = 0 //化验费
  937. var laboratoryCostSelfTotal float64 = 0 //化验费
  938. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  939. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  940. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  941. var treatCostTotal float64 = 0 //治疗费用
  942. var treatCostSelfTotal float64 = 0 //治疗费用
  943. var treatCostPartSelfTotal float64 = 0 //治疗费用
  944. var treatSelfTotal float64 = 0 //床位部分项目自费
  945. var treatInscpTotal float64 = 0 //床位部分项目自费
  946. var zhenChaCostTotal float64 = 0 //其他费用
  947. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  948. decimal.DivisionPrecision = 2
  949. for _, item := range orderInfos {
  950. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  951. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  952. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  953. item.MedChrgitmType = "09"
  954. }
  955. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  956. if item.HisPrescriptionProject.Type == 2 {
  957. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  958. fmt.Println("CostClassify")
  959. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  960. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  961. case 0:
  962. item.MedChrgitmType = "0"
  963. break
  964. case 1:
  965. item.MedChrgitmType = "14"
  966. break
  967. case 2:
  968. item.MedChrgitmType = "05"
  969. break
  970. case 3:
  971. item.MedChrgitmType = "03"
  972. break
  973. case 4:
  974. item.MedChrgitmType = "03"
  975. break
  976. case 5:
  977. item.MedChrgitmType = "08"
  978. break
  979. case 6:
  980. item.MedChrgitmType = "14"
  981. break
  982. case 7:
  983. item.MedChrgitmType = "14"
  984. break
  985. case 8:
  986. item.MedChrgitmType = "03"
  987. break
  988. case 9:
  989. item.MedChrgitmType = "14"
  990. break
  991. case 10:
  992. item.MedChrgitmType = "14"
  993. break
  994. case 11:
  995. item.MedChrgitmType = "06"
  996. break
  997. case 12:
  998. item.MedChrgitmType = "12"
  999. break
  1000. case 13:
  1001. item.MedChrgitmType = "01"
  1002. break
  1003. case 14:
  1004. item.MedChrgitmType = "04"
  1005. break
  1006. case 15:
  1007. item.MedChrgitmType = "14"
  1008. break
  1009. case 101:
  1010. item.MedChrgitmType = "04"
  1011. break
  1012. }
  1013. } else {
  1014. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1015. case 1:
  1016. item.MedChrgitmType = "14"
  1017. break
  1018. case 2:
  1019. item.MedChrgitmType = "05"
  1020. break
  1021. case 3:
  1022. item.MedChrgitmType = "04"
  1023. break
  1024. case 4:
  1025. item.MedChrgitmType = "14"
  1026. break
  1027. case 5:
  1028. item.MedChrgitmType = "08"
  1029. break
  1030. case 6:
  1031. item.MedChrgitmType = "14"
  1032. break
  1033. case 7:
  1034. item.MedChrgitmType = "14"
  1035. break
  1036. case 8:
  1037. item.MedChrgitmType = "03"
  1038. break
  1039. case 9:
  1040. item.MedChrgitmType = "14"
  1041. break
  1042. case 101:
  1043. item.MedChrgitmType = "04"
  1044. break
  1045. default:
  1046. item.MedChrgitmType = "14"
  1047. break
  1048. }
  1049. }
  1050. } else if item.HisPrescriptionProject.Type == 3 {
  1051. item.MedChrgitmType = "08"
  1052. }
  1053. }
  1054. }
  1055. }
  1056. if order.IsMedicineInsurance != 1 {
  1057. order.PsnCashPay = order.MedfeeSumamt
  1058. }
  1059. for _, item := range orderInfos {
  1060. if item.MedChrgitmType == "01" { //床位费
  1061. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1062. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1063. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1064. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1065. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1066. }
  1067. if item.MedChrgitmType == "02" { //诊察费
  1068. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1069. //zhenChaCostSelfTotal = zhenChaCostTotal
  1070. }
  1071. if item.MedChrgitmType == "03" { //检查费
  1072. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1073. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1074. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1075. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1076. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1077. }
  1078. if item.MedChrgitmType == "02" { //检查费
  1079. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1080. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1081. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1082. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1083. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1084. }
  1085. if item.MedChrgitmType == "04" { //化验费
  1086. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1087. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1088. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1089. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1090. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1091. }
  1092. if item.MedChrgitmType == "05" { //治疗费
  1093. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1094. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1095. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1096. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1097. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1098. }
  1099. if item.MedChrgitmType == "06" { //手术费
  1100. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1101. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1102. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1103. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1104. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1105. }
  1106. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1107. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1108. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1109. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1110. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1111. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1112. }
  1113. if item.MedChrgitmType == "09" { //西药费
  1114. fmt.Println("FulamtOwnpayAmt")
  1115. fmt.Println(item.FulamtOwnpayAmt)
  1116. fmt.Println("FulamtOwnpayAmt")
  1117. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1118. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1119. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1120. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1121. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1122. }
  1123. if item.MedChrgitmType == "11" { //中成费
  1124. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1125. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1126. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1127. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1128. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1129. }
  1130. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1131. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1132. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1133. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1134. }
  1135. }
  1136. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1137. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1138. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1139. var dia_config []*models.HisXtDiagnoseConfig
  1140. var diagnosis_ids []string
  1141. if his.ID > 0 {
  1142. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1143. } else {
  1144. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1145. }
  1146. for _, item := range diagnosis_ids {
  1147. id, _ := strconv.ParseInt(item, 10, 64)
  1148. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1149. dia_config = append(dia_config, diagnosisConfig)
  1150. }
  1151. var rf []CustomFundPay
  1152. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1153. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1154. c.ServeSuccessJSON(map[string]interface{}{
  1155. "patient": patient,
  1156. "order_infos": orderInfos,
  1157. "diagnosis": name,
  1158. "bedCostTotal": bedCostTotal,
  1159. "bedCostSelfTotal": bedCostSelfTotal,
  1160. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1161. "bedSelfTotal": bedSelfTotal,
  1162. "bedInscpTotal": bedInscpTotal,
  1163. "operationCostTotal": operationCostTotal,
  1164. "operationCostSelfTotal": operationCostSelfTotal,
  1165. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1166. "operationInscpTotal": operationInscpTotal,
  1167. "operationSelfTotal": operationSelfTotal,
  1168. "otherCostTotal": otherCostTotal,
  1169. //"otherCostSelfTotal": otherCostSelfTotal,
  1170. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1171. "materialCostTotal": materialCostTotal,
  1172. "materialCostSelfTotal": materialCostSelfTotal,
  1173. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1174. "materialSelfTotal": materialSelfTotal,
  1175. "materialInscpTotal": materialInscpTotal,
  1176. "westernMedicineCostTotal": westernMedicineCostTotal,
  1177. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1178. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1179. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1180. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1181. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1182. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1183. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1184. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1185. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1186. "checkCostTotal": checkCostTotal,
  1187. "checkCostSelfTotal": checkCostSelfTotal,
  1188. "checkSelfTotal": checkSelfTotal,
  1189. "checkInscpTotal": checkInscpTotal,
  1190. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1191. "zhenChaCostTotal": zhenChaCostTotal,
  1192. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1193. "laboratoryCostTotal": laboratoryCostTotal,
  1194. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1195. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1196. "laboratorySelfTotal": laboratorySelfTotal,
  1197. "laboratoryInscpTotal": laboratoryInscpTotal,
  1198. "treatCostTotal": treatCostTotal,
  1199. "treatCostSelfTotal": treatCostSelfTotal,
  1200. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1201. "treatSelfTotal": treatSelfTotal,
  1202. "treatInscpTotal": treatInscpTotal,
  1203. "charge_admin": charge_admin,
  1204. "printor_admin": printor_admin,
  1205. "org_name": org.OrgName,
  1206. "org_code": miConfig.Code,
  1207. "name": patient.Name,
  1208. "number": order.MdtrtId,
  1209. "date": order.SettleAccountsDate,
  1210. "info": order,
  1211. "new_order": order,
  1212. "his_hospital": his_hospital,
  1213. "his": his,
  1214. "funds": rf,
  1215. "dia_config": dia_config,
  1216. })
  1217. }
  1218. func (c *HisApiController) RefudDetail() {
  1219. order_id, _ := c.GetInt64("order_id")
  1220. order, _ := service.GetHisOrderByID(order_id)
  1221. adminUser := c.GetAdminUserInfo()
  1222. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1223. c.ServeSuccessJSON(map[string]interface{}{
  1224. "msg": "撤销成功",
  1225. })
  1226. }
  1227. func (c *HisApiController) Sscard() {
  1228. //r := CardInit()
  1229. //if r == 0 {
  1230. // GetBaseInfo()
  1231. //}
  1232. //c.ServeSuccessJSON(map[string]interface{}{
  1233. // "list": "11",
  1234. //})
  1235. }
  1236. func GetBaseInfo() error {
  1237. //handle := syscall.MustLoadDLL("SSCard.dll")
  1238. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1239. //
  1240. //str := make([]byte, 256)
  1241. //str1 := make([]byte, 256)
  1242. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1243. //if ferr != nil {
  1244. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1245. // return ferr
  1246. //}
  1247. //
  1248. //fmt.Println(string(str))
  1249. //
  1250. //fmt.Println(r)
  1251. return nil
  1252. }
  1253. func CardInit() int {
  1254. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1255. //add := DllTestDef.MustFindProc("Init")
  1256. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1257. //if err != nil {
  1258. // fmt.Println("SSCard的运算结果为:", ret)
  1259. //}
  1260. //result := int(ret)
  1261. return 0
  1262. }
  1263. func IntPtr(n int) uintptr {
  1264. return uintptr(n)
  1265. }
  1266. func StrPtr(s string) uintptr {
  1267. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1268. }
  1269. func (c *HisApiController) GetHisPatientList() {
  1270. record_date := c.GetString("record_date")
  1271. sch_type, _ := c.GetInt64("sch_type")
  1272. patient_type, _ := c.GetInt64("patient_type")
  1273. fmt.Println("patient_type")
  1274. fmt.Println(patient_type)
  1275. timeLayout := "2006-01-02"
  1276. loc, _ := time.LoadLocation("Local")
  1277. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1278. if err != nil {
  1279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1280. return
  1281. }
  1282. recordDateTime := theTime.Unix()
  1283. adminInfo := c.GetAdminUserInfo()
  1284. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1285. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1286. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1287. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1288. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1289. fmt.Println(patients_three)
  1290. //获取当前用户的信息
  1291. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1292. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1293. //获取所有科室信息
  1294. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1295. //var aa []service.PatientThree
  1296. noElementsSlice := make([]service.PatientThree, 0)
  1297. c.ServeSuccessJSON(map[string]interface{}{
  1298. "list": patients_three,
  1299. "list_two": patients_four,
  1300. "list_three": noElementsSlice,
  1301. "info": adminUserInfo,
  1302. "doctors": doctors,
  1303. "department": department,
  1304. })
  1305. } else {
  1306. //获取当前用户的信息
  1307. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1308. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1309. //获取所有科室信息
  1310. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1311. //var aa []service.PatientThree
  1312. noElementsSlice := make([]service.PatientThree, 0)
  1313. c.ServeSuccessJSON(map[string]interface{}{
  1314. "list": patients,
  1315. "list_two": patients_two,
  1316. "list_three": noElementsSlice,
  1317. "info": adminUserInfo,
  1318. "doctors": doctors,
  1319. "department": department,
  1320. })
  1321. }
  1322. }
  1323. type CustomTemplate struct {
  1324. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1325. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1326. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1327. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1328. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1329. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1330. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1331. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1332. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1333. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1334. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1335. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1336. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1337. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1338. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1339. }
  1340. func (c *HisApiController) GetHisPatientInfo() {
  1341. patient_id, _ := c.GetInt64("patient_id")
  1342. his_patient_id, _ := c.GetInt64("his_patient_id")
  1343. record_date := c.GetString("record_date")
  1344. number := c.GetString("number")
  1345. //start_time := c.GetString("start_time")
  1346. //end_time := c.GetString("end_time")
  1347. p_type, _ := c.GetInt64("p_type")
  1348. timeLayout := "2006-01-02"
  1349. loc, _ := time.LoadLocation("Local")
  1350. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1351. if err != nil {
  1352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1353. return
  1354. }
  1355. recordDateTime := theTime.Unix()
  1356. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1357. //if err != nil {
  1358. //
  1359. //}
  1360. //startRecordDateTime := startTime.Unix()
  1361. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1362. //if err != nil {
  1363. //
  1364. //}
  1365. //endRecordDateTime := endTime.Unix()
  1366. admin := c.GetAdminUserInfo()
  1367. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1368. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1369. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1370. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1371. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1372. var prescriptions []*models.HisPrescription
  1373. var last_prescriptions []*models.HisPrescription
  1374. var sch_prescriptions []CustomTemplate
  1375. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1376. if p_type == 1 { //住院
  1377. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1378. for _, item := range prescriptions {
  1379. for _, subItem := range item.HisDoctorAdviceInfo {
  1380. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1381. if info.RetailPrice > 0 {
  1382. subItem.Drug.MinPrice = info.RetailPrice
  1383. }
  1384. }
  1385. }
  1386. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1387. } else { //门诊
  1388. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1389. for _, item := range prescriptions {
  1390. for _, subItem := range item.HisDoctorAdviceInfo {
  1391. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1392. if info.RetailPrice > 0 {
  1393. subItem.Drug.MinPrice = info.RetailPrice
  1394. }
  1395. }
  1396. }
  1397. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1398. }
  1399. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1400. if sch.ID > 0 {
  1401. var week string
  1402. t := time.Now()
  1403. switch t.Weekday().String() {
  1404. case "Monday":
  1405. week = "周一"
  1406. break
  1407. case "Tuesday":
  1408. week = "周二"
  1409. break
  1410. case "Wednesday":
  1411. week = "周三"
  1412. break
  1413. case "Thursday":
  1414. week = "周四"
  1415. break
  1416. case "Friday":
  1417. week = "周五"
  1418. break
  1419. case "Saturday":
  1420. week = "周六"
  1421. break
  1422. case "Sunday":
  1423. week = "周日"
  1424. break
  1425. }
  1426. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1427. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1428. //根据推送频率组装新的数组
  1429. for _, item := range temp_sch_prescriptions {
  1430. var cus CustomTemplate
  1431. cus.ID = item.ID
  1432. cus.UserOrgId = item.UserOrgId
  1433. cus.PatientId = item.PatientId
  1434. cus.MedType = item.MedType
  1435. cus.RecordDate = item.RecordDate
  1436. cus.Type = item.Type
  1437. cus.PType = item.PType
  1438. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1439. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1440. if subItem.FrequencyType == 1 { //每次必推
  1441. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1442. }
  1443. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1444. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1445. }
  1446. if subItem.FrequencyType == 2 { //按照天数频率
  1447. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1448. now := p.Unix()
  1449. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1450. dayStr2 := "-" + dayStr
  1451. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1452. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1453. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1454. if len(advices) == 0 {
  1455. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1456. }
  1457. }
  1458. }
  1459. }
  1460. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1461. if subItem.Type == 2 {
  1462. if subItem.XtHisProject.MedicalStatus != 1 {
  1463. if subItem.FrequencyType == 1 {
  1464. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1465. }
  1466. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1467. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1468. }
  1469. if subItem.FrequencyType == 2 {
  1470. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1471. now := p.Unix()
  1472. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1473. dayStr2 := "-" + dayStr
  1474. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1475. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1476. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1477. if len(projects) == 0 {
  1478. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1479. }
  1480. }
  1481. }
  1482. } else if subItem.Type == 3 {
  1483. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1484. if subItem.FrequencyType == 1 {
  1485. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1486. }
  1487. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1488. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1489. }
  1490. if subItem.FrequencyType == 2 {
  1491. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1492. now := p.Unix()
  1493. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1494. dayStr2 := "-" + dayStr
  1495. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1496. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1497. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1498. if len(projects) == 0 {
  1499. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1500. }
  1501. }
  1502. }
  1503. }
  1504. }
  1505. sch_prescriptions = append(sch_prescriptions, cus)
  1506. }
  1507. for _, item := range sch_prescriptions {
  1508. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1509. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1510. }
  1511. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1512. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1513. }
  1514. }
  1515. }
  1516. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1517. if config.ID > 0 && config.IsOpen == 1 {
  1518. for _, item := range sch_prescriptions {
  1519. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1520. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1521. if info.RetailPrice > 0 {
  1522. subItem.Drug.MinPrice = info.RetailPrice
  1523. if admin.CurrentOrgId != 10598 {
  1524. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1525. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1526. }
  1527. }
  1528. }
  1529. }
  1530. }
  1531. if config.ID > 0 && config.IsOpen == 1 {
  1532. for _, item := range sch_prescriptions {
  1533. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1534. if subItem.Type == 3 {
  1535. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1536. if info.Price > 0 {
  1537. subItem.GoodInfo.PackingPrice = info.Price
  1538. if admin.CurrentOrgId != 10598 {
  1539. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1540. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1541. }
  1542. }
  1543. }
  1544. }
  1545. }
  1546. }
  1547. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1548. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1549. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1550. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1551. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1552. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1553. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1554. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1555. //获取所有科室信息
  1556. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1557. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1558. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1559. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1560. fmt.Println(prescriptions)
  1561. fmt.Println(sch_prescriptions)
  1562. fmt.Println(last_prescriptions)
  1563. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1564. if len(sch_prescriptions) > 0 {
  1565. var index = 0
  1566. for subindex, item := range sch_prescriptions {
  1567. if item.Type == 2 {
  1568. index = subindex
  1569. }
  1570. }
  1571. fmt.Println(index)
  1572. fmt.Println(len(sch_prescriptions))
  1573. if index >= 0 && index < len(sch_prescriptions) {
  1574. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1575. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1576. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1577. if one.ID > 0 {
  1578. var hpt models.HisPrescriptionProjectTemplate
  1579. hpt.Type = 3
  1580. hpt.ID = 0
  1581. hpt.PatientId = sch_prescriptions[index].PatientId
  1582. hpt.Status = 1
  1583. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1584. hpt.Mtime = time.Now().Unix()
  1585. hpt.Ctime = time.Now().Unix()
  1586. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1587. hpt.Count = "1"
  1588. hpt.Price = one.RetailPrice
  1589. hpt.ProjectId = one.ID
  1590. hpt.FeedetlSn = ""
  1591. hpt.PrescriptionId = sch_prescriptions[index].ID
  1592. hpt.Unit = one.PackingUnit
  1593. hpt.Day = "1"
  1594. hpt.SingleDose = "1"
  1595. hpt.GoodInfo = one
  1596. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1597. }
  1598. if two.ID > 0 {
  1599. var hpt models.HisPrescriptionProjectTemplate
  1600. hpt.Type = 3
  1601. hpt.ID = 0
  1602. hpt.PatientId = sch_prescriptions[index].PatientId
  1603. hpt.Status = 1
  1604. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1605. hpt.Mtime = time.Now().Unix()
  1606. hpt.Ctime = time.Now().Unix()
  1607. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1608. hpt.Count = "1"
  1609. hpt.Price = two.RetailPrice
  1610. hpt.ProjectId = two.ID
  1611. hpt.FeedetlSn = ""
  1612. hpt.PrescriptionId = sch_prescriptions[index].ID
  1613. hpt.Unit = two.PackingUnit
  1614. hpt.Day = "1"
  1615. hpt.SingleDose = "1"
  1616. hpt.GoodInfo = two
  1617. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1618. }
  1619. //if three.ID > 0 {
  1620. // var hpt models.HisPrescriptionProjectTemplate
  1621. // hpt.Type = 3
  1622. // hpt.ID = 0
  1623. // hpt.PatientId = sch_prescriptions[index].PatientId
  1624. // hpt.Status = 1
  1625. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1626. // hpt.Mtime = time.Now().Unix()
  1627. // hpt.Ctime = time.Now().Unix()
  1628. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1629. // hpt.Count = "1"
  1630. // hpt.Price = three.RetailPrice
  1631. // hpt.ProjectId = three.ID
  1632. // hpt.FeedetlSn = ""
  1633. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1634. // hpt.Unit = three.PackingUnit
  1635. // hpt.Day = "1"
  1636. // hpt.SingleDose = "1"
  1637. // hpt.GoodInfo = three
  1638. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1639. //}
  1640. fmt.Println(sch_prescriptions)
  1641. }
  1642. } else {
  1643. if len(last_prescriptions) > 0 {
  1644. var index = 0
  1645. for subindex, item := range last_prescriptions {
  1646. if item.Type == 2 {
  1647. index = subindex
  1648. }
  1649. }
  1650. if index >= 0 && index < len(last_prescriptions) {
  1651. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1652. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1653. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1654. if one.ID > 0 {
  1655. var hpt models.HisPrescriptionProject
  1656. hpt.Type = 3
  1657. hpt.ID = 0
  1658. hpt.PatientId = last_prescriptions[index].PatientId
  1659. hpt.Status = 1
  1660. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1661. hpt.Mtime = time.Now().Unix()
  1662. hpt.Ctime = time.Now().Unix()
  1663. hpt.RecordDate = last_prescriptions[index].RecordDate
  1664. hpt.Count = "1"
  1665. hpt.Price = one.RetailPrice
  1666. hpt.ProjectId = one.ID
  1667. hpt.FeedetlSn = ""
  1668. hpt.PrescriptionId = last_prescriptions[index].ID
  1669. hpt.Unit = one.PackingUnit
  1670. hpt.Day = "1"
  1671. hpt.SingleDose = "1"
  1672. hpt.GoodInfo = one
  1673. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1674. }
  1675. if two.ID > 0 {
  1676. var hpt models.HisPrescriptionProject
  1677. hpt.Type = 3
  1678. hpt.ID = 0
  1679. hpt.PatientId = last_prescriptions[index].PatientId
  1680. hpt.Status = 1
  1681. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1682. hpt.Mtime = time.Now().Unix()
  1683. hpt.Ctime = time.Now().Unix()
  1684. hpt.RecordDate = last_prescriptions[index].RecordDate
  1685. hpt.Count = "1"
  1686. hpt.Price = two.RetailPrice
  1687. hpt.ProjectId = two.ID
  1688. hpt.FeedetlSn = ""
  1689. hpt.PrescriptionId = last_prescriptions[index].ID
  1690. hpt.Unit = two.PackingUnit
  1691. hpt.Day = "1"
  1692. hpt.SingleDose = "1"
  1693. hpt.GoodInfo = two
  1694. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1695. }
  1696. //if three.ID > 0 {
  1697. // var hpt models.HisPrescriptionProject
  1698. // hpt.Type = 3
  1699. // hpt.ID = 0
  1700. // hpt.PatientId = last_prescriptions[index].PatientId
  1701. // hpt.Status = 1
  1702. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1703. // hpt.Mtime = time.Now().Unix()
  1704. // hpt.Ctime = time.Now().Unix()
  1705. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1706. // hpt.Count = "1"
  1707. // hpt.Price = three.RetailPrice
  1708. // hpt.ProjectId = three.ID
  1709. // hpt.FeedetlSn = ""
  1710. // hpt.PrescriptionId = last_prescriptions[index].ID
  1711. // hpt.Unit = three.PackingUnit
  1712. // hpt.Day = "1"
  1713. // hpt.SingleDose = "1"
  1714. // hpt.GoodInfo = three
  1715. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1716. //}
  1717. }
  1718. }
  1719. }
  1720. }
  1721. c.ServeSuccessJSON(map[string]interface{}{
  1722. "his_info": his_patient_info,
  1723. "xt_info": xt_patient_info,
  1724. "prescription": prescriptions,
  1725. "case_history": case_history,
  1726. "info": patientPrescriptionInfo,
  1727. //"month_prescriptions": monthPrescriptions,
  1728. "order": order,
  1729. "doctors": doctors,
  1730. "department": department,
  1731. "sch_prescriptions": sch_prescriptions,
  1732. "last_prescriptions": last_prescriptions,
  1733. "schedule": sch,
  1734. "count": count,
  1735. "drugStockConfig": drugStockConfig,
  1736. "last_info": lastPatientPrescriptionInfo,
  1737. "befor": beforThrity,
  1738. "LastCaseHistory": LastCaseHistory,
  1739. "prescriptionInfo": prescriptionInfo,
  1740. })
  1741. return
  1742. }
  1743. func (c *HisApiController) GetHisPrescriptionConfig() {
  1744. adminInfo := c.GetAdminUserInfo()
  1745. //获取医嘱模版
  1746. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1747. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1748. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1749. //获取所有基础药
  1750. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1751. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1752. if config.ID > 0 && config.IsOpen == 1 {
  1753. for _, item := range drugs {
  1754. var index = 0
  1755. for _, subItem := range item.OtherDrugWarehouseInfo {
  1756. if index == 0 {
  1757. index = index + 1
  1758. if subItem.RetailPrice > 0 {
  1759. item.MinPrice = subItem.RetailPrice
  1760. }
  1761. }
  1762. }
  1763. }
  1764. }
  1765. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1766. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1767. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1768. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1769. //获取所有科室信息
  1770. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1771. //获取诊断信息
  1772. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1773. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1774. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1775. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1776. //获取是否开启保存耗材出库的开关
  1777. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1778. c.ServeSuccessJSON(map[string]interface{}{
  1779. "drugs": drugs,
  1780. "advices_template": advices,
  1781. "drugways": drugways,
  1782. "efs": efs,
  1783. "doctors": doctors,
  1784. "department": department,
  1785. "sick": sick,
  1786. "additions": additions,
  1787. "diagnose": diagnose,
  1788. "manufacturers": manufacturers,
  1789. "goodOutOpen": goodOutOpen,
  1790. "patientDiagnose": patientDiagnose,
  1791. })
  1792. }
  1793. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1794. //获取所有基础药
  1795. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1796. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1797. if config.ID > 0 && config.IsOpen == 1 {
  1798. for _, item := range drugs {
  1799. var index = 0
  1800. for _, subItem := range item.OtherDrugWarehouseInfo {
  1801. if index == 0 {
  1802. index = index + 1
  1803. if subItem.RetailPrice > 0 {
  1804. item.MinPrice = subItem.RetailPrice
  1805. }
  1806. }
  1807. }
  1808. }
  1809. }
  1810. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1811. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1812. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1813. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1814. //获取所有科室信息
  1815. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1816. //获取诊断信息
  1817. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1818. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1819. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1820. //获取是否开启保存耗材出库的开关
  1821. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1822. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1823. c.ServeSuccessJSON(map[string]interface{}{
  1824. "drugs": drugs,
  1825. "advices_template": advices,
  1826. "drugways": drugways,
  1827. "efs": efs,
  1828. "doctors": doctors,
  1829. "department": department,
  1830. "sick": sick,
  1831. "additions": additions,
  1832. "diagnose": diagnose,
  1833. "manufacturers": manufacturers,
  1834. "goodOutOpen": goodOutOpen,
  1835. "patientDiagnose": patientDiagnose,
  1836. })
  1837. }
  1838. }
  1839. func (c *HisApiController) CreateHisPrescription() {
  1840. record_date := c.GetString("record_date")
  1841. patient_id, _ := c.GetInt64("patient_id")
  1842. reg_type, _ := c.GetInt64("reg_type")
  1843. diagnose := c.GetString("diagnose")
  1844. sick_type, _ := c.GetInt64("sick_type")
  1845. sick_history := c.GetString("sick_history")
  1846. doctor_id, _ := c.GetInt64("doctor", 0)
  1847. department, _ := c.GetInt64("department", 0)
  1848. his_patient_id, _ := c.GetInt64("his_patient_id")
  1849. p_type, _ := c.GetInt64("p_type")
  1850. patient_diagnose := c.GetString("patient_diagnose")
  1851. dataBody := make(map[string]interface{}, 0)
  1852. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1853. if err != nil {
  1854. utils.ErrorLog(err.Error())
  1855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1856. return
  1857. }
  1858. //edit, src := GetCompareData(dataBody)
  1859. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1860. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1861. //fmt.Println(drugResult)
  1862. //fmt.Println(goodResult)
  1863. timeLayout := "2006-01-02"
  1864. loc, _ := time.LoadLocation("Local")
  1865. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1866. if err != nil {
  1867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1868. return
  1869. }
  1870. adminInfo := c.GetAdminUserInfo()
  1871. recordDateTime := theTime.Unix()
  1872. //查询默认出库仓库库存
  1873. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1874. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1875. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1876. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1877. if len(lists) == 1 {
  1878. his_patient_id = lists[0].ID
  1879. }
  1880. }
  1881. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1882. //自动出库的开关开启
  1883. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1884. //自动出库
  1885. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1886. //耗材保存处方出库
  1887. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1888. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1889. //已发药和已收费限制逻辑
  1890. isMidicine := false
  1891. isCharge := false
  1892. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1893. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1894. if len(prescriptions) > 0 {
  1895. for _, item := range prescriptions {
  1896. items := item.(map[string]interface{})
  1897. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1898. utils.ErrorLog("id")
  1899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1900. return
  1901. }
  1902. id := int64(items["id"].(float64))
  1903. if id > 0 {
  1904. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1905. if err != nil {
  1906. if new_prescription.OrderStatus == 4 {
  1907. isCharge = true
  1908. }
  1909. }
  1910. }
  1911. }
  1912. }
  1913. }
  1914. if isMidicine == true {
  1915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1916. return
  1917. }
  1918. if isCharge == true {
  1919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1920. return
  1921. }
  1922. // 开始主事务
  1923. db := service.XTWriteDB()
  1924. tx := db.Begin()
  1925. // 在函数结束时处理事务回滚
  1926. defer func() {
  1927. if r := recover(); r != nil {
  1928. tx.Rollback()
  1929. }
  1930. }()
  1931. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1932. //药品发药出库
  1933. if pharmacyConfig.IsOpen == 1 {
  1934. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1935. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1936. if len(prescriptions) > 0 {
  1937. for _, item := range prescriptions {
  1938. items := item.(map[string]interface{})
  1939. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1940. advices := items["advices"].([]interface{})
  1941. if len(advices) > 0 {
  1942. for _, advice := range advices {
  1943. var drug_id int64
  1944. var prescribing_number float64
  1945. var prescribingNumberUnit string
  1946. var adviceId int64
  1947. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1948. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1949. }
  1950. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1951. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1952. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1953. }
  1954. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1955. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1956. }
  1957. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1958. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1959. }
  1960. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1961. if drug.ID == 0 {
  1962. tx.Rollback()
  1963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1964. return
  1965. }
  1966. //查询药品的所有库存
  1967. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1968. var total_count int64
  1969. for _, it := range list {
  1970. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1971. }
  1972. totals := strconv.FormatInt(total_count, 10)
  1973. //查询该药品是否存在开药记录
  1974. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1975. //新增处方盘点库存是否充足
  1976. if advicelist.ID == 0 {
  1977. all_count, _ := strconv.ParseFloat(totals, 64)
  1978. if prescribingNumberUnit == drug.MinUnit {
  1979. if drug.IsUse != 1 {
  1980. if drug.IsProject == 0 || drug.IsProject == 2 {
  1981. if all_count == 0 {
  1982. tx.Rollback()
  1983. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1984. return
  1985. }
  1986. if prescribing_number > all_count {
  1987. tx.Rollback()
  1988. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1989. return
  1990. }
  1991. }
  1992. }
  1993. }
  1994. if prescribingNumberUnit == drug.MaxUnit {
  1995. num := prescribing_number * float64(drug.MinNumber)
  1996. if drug.IsUse != 1 {
  1997. if drug.IsProject == 0 || drug.IsProject == 2 {
  1998. if all_count == 0 {
  1999. tx.Rollback()
  2000. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2001. return
  2002. }
  2003. if num > all_count {
  2004. tx.Rollback()
  2005. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2006. return
  2007. }
  2008. }
  2009. }
  2010. }
  2011. }
  2012. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2013. //不使用保存处方出库
  2014. if drugOutConfig.IsOpen != 1 {
  2015. //修改处方
  2016. for _, advice := range advices {
  2017. var drug_id int64
  2018. var prescribing_number float64
  2019. var prescribingNumberUnit string
  2020. var prescribingNumber string
  2021. var adviceId int64
  2022. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2023. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2024. }
  2025. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2026. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2027. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2028. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2029. }
  2030. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2031. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2032. }
  2033. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2034. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2035. }
  2036. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2037. if drug.ID == 0 {
  2038. tx.Rollback()
  2039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2040. return
  2041. }
  2042. //查询药品的所有库存
  2043. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2044. var total_count int64
  2045. for _, it := range list {
  2046. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2047. }
  2048. totals := strconv.FormatInt(total_count, 10)
  2049. //查询该药品是否存在开药记录
  2050. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2051. //新增处方
  2052. if advicelist.ID == 0 {
  2053. all_count, _ := strconv.ParseFloat(totals, 64)
  2054. if prescribingNumberUnit == drug.MinUnit {
  2055. if drug.IsUse != 1 {
  2056. if drug.IsProject == 0 || drug.IsProject == 2 {
  2057. if all_count == 0 {
  2058. tx.Rollback()
  2059. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2060. return
  2061. }
  2062. if prescribing_number > all_count {
  2063. tx.Rollback()
  2064. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2065. return
  2066. }
  2067. }
  2068. }
  2069. } else {
  2070. if prescribingNumberUnit == drug.MaxUnit {
  2071. num := prescribing_number * float64(drug.MinNumber)
  2072. if drug.IsUse != 1 {
  2073. if drug.IsProject == 0 || drug.IsProject == 2 {
  2074. if all_count == 0 {
  2075. tx.Rollback()
  2076. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2077. return
  2078. }
  2079. if num > all_count {
  2080. tx.Rollback()
  2081. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2082. return
  2083. }
  2084. }
  2085. }
  2086. }
  2087. }
  2088. }
  2089. //修改处方
  2090. if advicelist.ID > 0 {
  2091. var device_number int64
  2092. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2093. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2094. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2095. device_number = prescribingNumberInt * drug.MinNumber
  2096. }
  2097. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2098. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2099. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2100. device_number = prescribingNumberInt
  2101. }
  2102. var number_count int64
  2103. if prescribingNumberUnit == drug.MaxUnit {
  2104. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2105. number_count = prescribingNumberInt * drug.MinNumber
  2106. }
  2107. if prescribingNumberUnit == drug.MinUnit {
  2108. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2109. number_count = prescribingNumberInt
  2110. }
  2111. //如果修改的数量大于之前修改的数量
  2112. if (number_count - device_number) > 0 {
  2113. //如果修改的差数量 大于库存数量
  2114. if drug.IsUse != 1 {
  2115. if (number_count - device_number) > total_count {
  2116. tx.Rollback()
  2117. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2118. return
  2119. }
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. }
  2132. //已发药和已收费限制逻辑
  2133. //执行出库的逻辑
  2134. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2135. //校验库存总量
  2136. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2137. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2138. if len(prescriptions) > 0 {
  2139. for _, item := range prescriptions {
  2140. items := item.(map[string]interface{})
  2141. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2142. advices := items["advices"].([]interface{})
  2143. if len(advices) > 0 {
  2144. for _, advice := range advices {
  2145. var drug_id int64
  2146. var prescribing_number float64
  2147. var prescribingNumberUnit string
  2148. var adviceId int64
  2149. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2150. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2151. }
  2152. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2153. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2154. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2155. }
  2156. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2157. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2158. }
  2159. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2160. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2161. }
  2162. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2163. if drug.ID == 0 {
  2164. tx.Rollback()
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2166. return
  2167. }
  2168. //查询药品的所有库存
  2169. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2170. var total_count int64
  2171. for _, it := range list {
  2172. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2173. }
  2174. totals := strconv.FormatInt(total_count, 10)
  2175. //查询该药品是否存在开药记录
  2176. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2177. //查询最新批次库存
  2178. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2179. var batch_number_count int64
  2180. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2181. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2182. //新增处方
  2183. if advicelist.ID == 0 {
  2184. all_count, _ := strconv.ParseFloat(totals, 64)
  2185. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2186. if prescribingNumberUnit == drug.MinUnit {
  2187. if drug.IsUse != 1 {
  2188. if drug.IsProject == 0 || drug.IsProject == 2 {
  2189. if all_count == 0 {
  2190. tx.Rollback()
  2191. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2192. return
  2193. }
  2194. if prescribing_number > all_count {
  2195. tx.Rollback()
  2196. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2197. return
  2198. }
  2199. }
  2200. if adminInfo.CurrentOrgId == 10215 {
  2201. if prescribing_number > batch_number_all_count {
  2202. tx.Rollback()
  2203. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2204. return
  2205. }
  2206. }
  2207. }
  2208. }
  2209. if prescribingNumberUnit == drug.MaxUnit {
  2210. num := prescribing_number * float64(drug.MinNumber)
  2211. if drug.IsUse != 1 {
  2212. if drug.IsProject == 0 || drug.IsProject == 2 {
  2213. if all_count == 0 {
  2214. tx.Rollback()
  2215. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2216. return
  2217. }
  2218. if num > all_count {
  2219. tx.Rollback()
  2220. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2221. return
  2222. }
  2223. }
  2224. if adminInfo.CurrentOrgId == 10215 {
  2225. if num > batch_number_all_count {
  2226. tx.Rollback()
  2227. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2228. return
  2229. }
  2230. }
  2231. }
  2232. }
  2233. }
  2234. //不是保存处方出库
  2235. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2236. if drugOutConfig.IsOpen != 1 {
  2237. //修改处方
  2238. for _, advice := range advices {
  2239. var drug_id int64
  2240. var prescribing_number float64
  2241. var prescribingNumberUnit string
  2242. var prescribingNumber string
  2243. var adviceId int64
  2244. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2245. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2246. }
  2247. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2248. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2249. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2250. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2251. }
  2252. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2253. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2254. }
  2255. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2256. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2257. }
  2258. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2259. if drug.ID == 0 {
  2260. tx.Rollback()
  2261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2262. return
  2263. }
  2264. //查询药品的所有库存
  2265. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2266. var total_count int64
  2267. for _, it := range list {
  2268. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2269. }
  2270. totals := strconv.FormatInt(total_count, 10)
  2271. //查询该药品是否存在开药记录
  2272. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2273. //新增处方
  2274. if advicelist.ID == 0 {
  2275. //查询最新批次库存
  2276. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2277. var batch_number_count int64
  2278. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2279. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2280. all_count, _ := strconv.ParseFloat(totals, 64)
  2281. if all_count == 0 {
  2282. tx.Rollback()
  2283. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2284. return
  2285. }
  2286. if prescribingNumberUnit == drug.MinUnit {
  2287. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2288. if drug.IsUse != 1 {
  2289. if drug.IsProject == 0 || drug.IsProject == 2 {
  2290. if all_count == 0 {
  2291. tx.Rollback()
  2292. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2293. return
  2294. }
  2295. if prescribing_number > all_count {
  2296. tx.Rollback()
  2297. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2298. return
  2299. }
  2300. }
  2301. if adminInfo.CurrentOrgId == 10215 {
  2302. if prescribing_number > batch_number_all_count {
  2303. tx.Rollback()
  2304. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2305. return
  2306. }
  2307. }
  2308. }
  2309. } else {
  2310. if prescribingNumberUnit == drug.MaxUnit {
  2311. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2312. num := prescribing_number * float64(drug.MinNumber)
  2313. if drug.IsUse != 1 {
  2314. if drug.IsProject == 0 || drug.IsProject == 2 {
  2315. if all_count == 0 {
  2316. tx.Rollback()
  2317. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2318. return
  2319. }
  2320. if num > all_count {
  2321. tx.Rollback()
  2322. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2323. return
  2324. }
  2325. }
  2326. if adminInfo.CurrentOrgId == 10215 {
  2327. if prescribing_number > batch_number_all_count {
  2328. tx.Rollback()
  2329. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2330. return
  2331. }
  2332. }
  2333. }
  2334. }
  2335. }
  2336. }
  2337. //修改处方
  2338. if advicelist.ID > 0 {
  2339. //查询最新批次库存
  2340. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2341. var batch_number_count int64
  2342. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2343. var device_number int64
  2344. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2345. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2346. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2347. device_number = prescribingNumberInt * drug.MinNumber
  2348. }
  2349. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2350. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2351. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2352. device_number = prescribingNumberInt
  2353. //回退库存
  2354. }
  2355. var number_count int64
  2356. if prescribingNumberUnit == drug.MaxUnit {
  2357. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2358. number_count = prescribingNumberInt * drug.MinNumber
  2359. //回退库存
  2360. }
  2361. if prescribingNumberUnit == drug.MinUnit {
  2362. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2363. number_count = prescribingNumberInt
  2364. //回退库存
  2365. }
  2366. //如果修改的数量大于之前修改的数量
  2367. if (number_count - device_number) > 0 {
  2368. //如果修改的差数量 大于库存数量
  2369. if drug.IsUse != 1 {
  2370. if drug.IsProject == 0 || drug.IsProject == 2 {
  2371. if total_count == 0 {
  2372. tx.Rollback()
  2373. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2374. return
  2375. }
  2376. if (number_count - device_number) > total_count {
  2377. tx.Rollback()
  2378. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2379. return
  2380. }
  2381. if (number_count - device_number) > batch_number_count {
  2382. tx.Rollback()
  2383. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2384. return
  2385. }
  2386. }
  2387. if adminInfo.CurrentOrgId == 10215 {
  2388. // 查询该药品最后一次出库记录
  2389. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2390. var out_count int64
  2391. var in_count int64
  2392. var stock_max_number int64
  2393. var stock_min_number int64
  2394. for _, it := range outInfo {
  2395. if it.CountUnit == drug.MaxUnit {
  2396. it.Count = it.Count * drug.MinNumber
  2397. }
  2398. out_count += it.Count
  2399. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2400. stock_max_number = warehouseInfoList.StockMaxNumber
  2401. stock_min_number = warehouseInfoList.StockMinNumber
  2402. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2403. }
  2404. if out_count > 0 {
  2405. if (number_count - device_number) > in_count {
  2406. tx.Rollback()
  2407. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2408. return
  2409. }
  2410. }
  2411. // 未出库
  2412. if out_count == 0 {
  2413. var sum_in_count int64
  2414. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2415. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2416. //如果修改的数量大于有库存的第一个批次
  2417. if number_count > sum_in_count {
  2418. tx.Rollback()
  2419. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2420. return
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. //药品发药
  2427. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2428. //不使用药品发药的功能
  2429. //if pharmacyConfig.IsOpen != 1 {
  2430. // if device_number != number_count {
  2431. //
  2432. // //查询该药品的出库记录
  2433. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2434. // if len(outListExport) > 0 {
  2435. // //
  2436. // for _, item := range outListExport {
  2437. // //回退库存
  2438. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2439. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2440. // }
  2441. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2442. // var stock_max_number int64
  2443. // var stock_min_number int64
  2444. //
  2445. // if number_count >= drug.MinNumber {
  2446. //
  2447. // stock_max_number = device_number / drug.MinNumber
  2448. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2449. //
  2450. // stock_min_number = device_number % drug.MinNumber
  2451. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2452. //
  2453. // } else {
  2454. //
  2455. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2456. //
  2457. // }
  2458. // }
  2459. //
  2460. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2461. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2462. // }
  2463. // }
  2464. // }
  2465. //
  2466. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2467. // var sum_count int64
  2468. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2469. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2470. // for _, its := range stockInfo {
  2471. // if its.MaxUnit == drug.MaxUnit {
  2472. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2473. // }
  2474. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2475. // }
  2476. // //更新字典里面的库存
  2477. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2478. //
  2479. // //剩余库存
  2480. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2481. //
  2482. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2483. // //减少出库数量
  2484. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2485. //
  2486. // }
  2487. //}
  2488. }
  2489. }
  2490. }
  2491. //保存处方开药
  2492. if drugOutConfig.IsOpen == 1 {
  2493. //修改处方
  2494. for _, advice := range advices {
  2495. var drug_id int64
  2496. var prescribing_number float64
  2497. var prescribingNumberUnit string
  2498. var prescribingNumber string
  2499. var adviceId int64
  2500. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2501. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2502. }
  2503. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2504. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2505. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2506. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2507. }
  2508. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2509. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2510. }
  2511. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2512. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2513. }
  2514. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2515. if drug.ID == 0 {
  2516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2517. return
  2518. }
  2519. //查询药品的所有库存
  2520. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2521. var total_count int64
  2522. for _, it := range list {
  2523. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2524. }
  2525. totals := strconv.FormatInt(total_count, 10)
  2526. //查询该药品是否存在开药记录
  2527. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2528. //新增处方
  2529. if advicelist.ID == 0 {
  2530. //查询最新批次库存
  2531. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2532. var batch_number_count int64
  2533. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2534. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2535. all_count, _ := strconv.ParseFloat(totals, 64)
  2536. if prescribingNumberUnit == drug.MinUnit {
  2537. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2538. if drug.IsUse != 1 {
  2539. if drug.IsProject == 0 || drug.IsProject == 2 {
  2540. if all_count == 0 {
  2541. tx.Rollback()
  2542. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2543. return
  2544. }
  2545. if prescribing_number > all_count {
  2546. tx.Rollback()
  2547. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2548. return
  2549. }
  2550. }
  2551. if adminInfo.CurrentOrgId == 10215 {
  2552. if prescribing_number > batch_number_all_count {
  2553. tx.Rollback()
  2554. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2555. return
  2556. }
  2557. }
  2558. }
  2559. } else {
  2560. if prescribingNumberUnit == drug.MaxUnit {
  2561. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2562. num := prescribing_number * float64(drug.MinNumber)
  2563. if drug.IsUse != 1 {
  2564. if drug.IsProject == 0 || drug.IsProject == 2 {
  2565. if all_count == 0 {
  2566. tx.Rollback()
  2567. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2568. return
  2569. }
  2570. if num > all_count {
  2571. tx.Rollback()
  2572. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2573. return
  2574. }
  2575. }
  2576. if adminInfo.CurrentOrgId == 10215 {
  2577. if prescribing_number > batch_number_all_count {
  2578. tx.Rollback()
  2579. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2580. return
  2581. }
  2582. }
  2583. }
  2584. }
  2585. }
  2586. }
  2587. //修改处方
  2588. if advicelist.ID > 0 {
  2589. //查询最新批次库存
  2590. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2591. var batch_number_count int64
  2592. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2593. var device_number int64
  2594. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2595. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2596. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2597. device_number = prescribingNumberInt * drug.MinNumber
  2598. }
  2599. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2600. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2601. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2602. device_number = prescribingNumberInt
  2603. }
  2604. var number_count int64
  2605. if prescribingNumberUnit == drug.MaxUnit {
  2606. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2607. number_count = prescribingNumberInt * drug.MinNumber
  2608. }
  2609. if prescribingNumberUnit == drug.MinUnit {
  2610. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2611. number_count = prescribingNumberInt
  2612. }
  2613. //如果修改的数量大于之前修改的数量
  2614. if (number_count - device_number) > 0 {
  2615. //如果修改的差数量 大于库存数量
  2616. if drug.IsUse != 1 {
  2617. if drug.IsProject == 0 || drug.IsProject == 2 {
  2618. if total_count == 0 {
  2619. tx.Rollback()
  2620. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2621. return
  2622. }
  2623. if (number_count - device_number) > total_count {
  2624. tx.Rollback()
  2625. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2626. return
  2627. }
  2628. }
  2629. if adminInfo.CurrentOrgId == 10215 {
  2630. if (number_count - device_number) > batch_number_count {
  2631. tx.Rollback()
  2632. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2633. return
  2634. }
  2635. }
  2636. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2637. //查询历史出库数据总批次
  2638. // 查询该药品最后一次出库记录
  2639. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2640. var out_count int64
  2641. var in_count int64
  2642. var stock_max_number int64
  2643. var stock_min_number int64
  2644. for _, it := range outInfo {
  2645. if it.CountUnit == drug.MaxUnit {
  2646. it.Count = it.Count * drug.MinNumber
  2647. }
  2648. out_count += it.Count
  2649. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2650. stock_max_number = warehouseInfoList.StockMaxNumber
  2651. stock_min_number = warehouseInfoList.StockMinNumber
  2652. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2653. }
  2654. if out_count > 0 {
  2655. if (number_count - device_number) > in_count {
  2656. tx.Rollback()
  2657. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2658. return
  2659. }
  2660. }
  2661. // 未出库
  2662. if out_count == 0 {
  2663. var sum_in_count int64
  2664. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2665. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2666. if sum_in_count == 0 {
  2667. tx.Rollback()
  2668. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2669. return
  2670. }
  2671. //如果修改的数量大于有库存的第一个批次
  2672. if number_count > sum_in_count {
  2673. tx.Rollback()
  2674. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2675. return
  2676. }
  2677. }
  2678. }
  2679. }
  2680. }
  2681. }
  2682. }
  2683. }
  2684. }
  2685. }
  2686. }
  2687. }
  2688. }
  2689. }
  2690. }
  2691. //校验耗材库存
  2692. if goodOutConfig.IsOpen == 1 {
  2693. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2694. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2695. if len(prescriptions) > 0 {
  2696. for _, item := range prescriptions {
  2697. items := item.(map[string]interface{})
  2698. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2699. projects := items["project"].([]interface{})
  2700. if len(projects) > 0 {
  2701. for _, project := range projects {
  2702. var project_id int64
  2703. var project_type int64
  2704. var totals float64
  2705. var project_name string
  2706. var parsetotal int64
  2707. var id int64
  2708. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2709. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2710. }
  2711. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2712. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2713. }
  2714. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2715. total, _ := project.(map[string]interface{})["total"].(string)
  2716. totals, _ = strconv.ParseFloat(total, 64)
  2717. }
  2718. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2719. project_name = project.(map[string]interface{})["project_name"].(string)
  2720. }
  2721. if project_type == 3 {
  2722. //查找该耗材的出库记录
  2723. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2724. if len(goodWarehouseInfo) == 0 {
  2725. //查询耗材库存
  2726. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2727. var stock_count int64
  2728. for _, it := range list {
  2729. stock_count += it.StockCount
  2730. }
  2731. stock_counts := strconv.FormatInt(stock_count, 10)
  2732. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2733. if stock_total_count == 0 {
  2734. tx.Rollback()
  2735. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2736. return
  2737. }
  2738. if totals > stock_total_count {
  2739. tx.Rollback()
  2740. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2741. return
  2742. }
  2743. }
  2744. if len(goodWarehouseInfo) > 0 {
  2745. //查询该患者耗材的历史数据
  2746. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2747. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2748. //数量发生改变
  2749. if parsetotal != count {
  2750. //如果现在的数量大于历史数量,就要看库存是否足够
  2751. if parsetotal > count {
  2752. //查询耗材所有库存
  2753. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2754. var stock_count int64
  2755. for _, it := range list {
  2756. stock_count += it.StockCount
  2757. }
  2758. //库存不足
  2759. if stock_count == 0 {
  2760. tx.Rollback()
  2761. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2762. return
  2763. }
  2764. if (parsetotal - count) > stock_count {
  2765. tx.Rollback()
  2766. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2767. return
  2768. }
  2769. }
  2770. }
  2771. }
  2772. }
  2773. }
  2774. }
  2775. }
  2776. }
  2777. }
  2778. }
  2779. }
  2780. //不使用耗材保存处方出库
  2781. if goodOutConfig.IsOpen != 1 {
  2782. if stockConfig.IsOpen == 1 {
  2783. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2784. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2785. if len(prescriptions) > 0 {
  2786. for _, item := range prescriptions {
  2787. items := item.(map[string]interface{})
  2788. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2789. projects := items["project"].([]interface{})
  2790. if len(projects) > 0 {
  2791. for _, project := range projects {
  2792. var project_id int64
  2793. var project_type int64
  2794. var totals float64
  2795. var project_name string
  2796. var parsetotal int64
  2797. var id int64
  2798. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2799. id = int64(project.(map[string]interface{})["id"].(float64))
  2800. }
  2801. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2802. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2803. }
  2804. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2805. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2806. }
  2807. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2808. total, _ := project.(map[string]interface{})["total"].(string)
  2809. totals, _ = strconv.ParseFloat(total, 64)
  2810. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2811. }
  2812. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2813. project_name = project.(map[string]interface{})["project_name"].(string)
  2814. }
  2815. if project_type == 3 {
  2816. //查找该耗材的出库记录
  2817. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2818. //没有出库记录
  2819. if len(goodWarehouseInfo) == 0 {
  2820. //查询耗材库存
  2821. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2822. var stock_count int64
  2823. for _, it := range list {
  2824. stock_count += it.StockCount
  2825. }
  2826. stock_counts := strconv.FormatInt(stock_count, 10)
  2827. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2828. if stock_total_count == 0 {
  2829. tx.Rollback()
  2830. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2831. return
  2832. }
  2833. if totals > stock_total_count {
  2834. tx.Rollback()
  2835. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2836. return
  2837. }
  2838. //查找今日该患者已经出库的所有耗材
  2839. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2840. for _, item := range goodList {
  2841. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2842. var flush_count int64
  2843. for _, it := range goodListSix {
  2844. flush_count += it.StockCount
  2845. }
  2846. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2847. creater := adminInfo.AdminUser.Id
  2848. if errs != nil {
  2849. goodErrcode := models.XtGoodErrcode{
  2850. UserOrgId: item.OrgId,
  2851. Errcode: "手动出库更新剩余出库失败",
  2852. GoodId: item.GoodId,
  2853. Status: 1,
  2854. Ctime: time.Now().Unix(),
  2855. Mtime: 0,
  2856. Count: 0,
  2857. StockCount: 0,
  2858. Creater: creater,
  2859. BatchNumberId: 0,
  2860. WarehouseOutId: 0,
  2861. }
  2862. service.CreateGoodErrcode(goodErrcode)
  2863. }
  2864. }
  2865. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2866. }
  2867. //有出库记录
  2868. if len(goodWarehouseInfo) > 0 {
  2869. //查询该患者耗材的历史数据
  2870. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2871. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2872. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2873. //数量发生改变
  2874. if parsetotal != count {
  2875. //查找今日该患者已经出库的所有耗材
  2876. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2877. for _, item := range goodList {
  2878. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2879. var flush_count int64
  2880. for _, it := range goodListSix {
  2881. flush_count += it.StockCount
  2882. }
  2883. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2884. //减少出库数量
  2885. creater := adminInfo.AdminUser.Id
  2886. if errs != nil {
  2887. goodErrcode := models.XtGoodErrcode{
  2888. UserOrgId: item.OrgId,
  2889. Errcode: "手动出库更新剩余出库失败",
  2890. GoodId: item.GoodId,
  2891. Status: 1,
  2892. Ctime: time.Now().Unix(),
  2893. Mtime: 0,
  2894. Count: 0,
  2895. StockCount: 0,
  2896. Creater: creater,
  2897. BatchNumberId: 0,
  2898. WarehouseOutId: 0,
  2899. }
  2900. service.CreateGoodErrcode(goodErrcode)
  2901. }
  2902. //查询默认仓库
  2903. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2904. var total_count int64
  2905. for _, it := range stockList {
  2906. total_count += it.StockCount
  2907. }
  2908. //基础库插入数据
  2909. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2910. }
  2911. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. }
  2918. }
  2919. }
  2920. }
  2921. }
  2922. }
  2923. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2924. var hpInfo models.HisPrescriptionInfo
  2925. if info.ID == 0 {
  2926. var randNum int
  2927. randNum = rand.Intn(10000) + 1000
  2928. timestamp := time.Now().Unix()
  2929. tempTime := time.Unix(timestamp, 0)
  2930. timeFormat := tempTime.Format("20060102150405")
  2931. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2932. hpInfo = models.HisPrescriptionInfo{
  2933. HisPatientId: his_patient_id,
  2934. UserOrgId: adminInfo.CurrentOrgId,
  2935. RecordDate: theTime.Unix(),
  2936. PatientId: patient_id,
  2937. Status: 1,
  2938. Ctime: time.Now().Unix(),
  2939. Mtime: time.Now().Unix(),
  2940. Creator: adminInfo.AdminUser.Id,
  2941. Modifier: adminInfo.AdminUser.Id,
  2942. Diagnosis: diagnose,
  2943. SickHistory: sick_history,
  2944. Departments: department,
  2945. RegisterType: reg_type,
  2946. PrescriptionNumber: p_number,
  2947. PrescriptionStatus: 1,
  2948. Doctor: role.UserName,
  2949. DoctorId: doctor_id,
  2950. SickType: sick_type,
  2951. PType: p_type,
  2952. PatientDiagnosis: patient_diagnose,
  2953. }
  2954. service.SavePatientPrescriptionInfo(hpInfo)
  2955. //创建步骤表
  2956. finish := models.XtDialysisFinish{
  2957. IsFinish: 1,
  2958. UserOrgId: adminInfo.CurrentOrgId,
  2959. Status: 1,
  2960. Ctime: time.Now().Unix(),
  2961. Mtime: 0,
  2962. Module: 4,
  2963. RecordDate: theTime.Unix(),
  2964. Sourse: 1,
  2965. PatientId: patient_id,
  2966. }
  2967. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2968. if dialysisFinish.ID == 0 {
  2969. service.CreateDialysisFinish(finish)
  2970. }
  2971. redis := service.RedisClient()
  2972. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2973. redis.Set(key, "", time.Second)
  2974. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2975. redis.Set(keyOne, "", time.Second)
  2976. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2977. redis.Set(keySeven, "", time.Second)
  2978. defer redis.Close()
  2979. } else {
  2980. hpInfo = models.HisPrescriptionInfo{
  2981. ID: info.ID,
  2982. UserOrgId: adminInfo.CurrentOrgId,
  2983. RecordDate: info.RecordDate,
  2984. PatientId: info.PatientId,
  2985. Status: 1,
  2986. Ctime: info.Ctime,
  2987. Mtime: time.Now().Unix(),
  2988. Creator: info.Creator,
  2989. Modifier: adminInfo.AdminUser.Id,
  2990. Diagnosis: diagnose,
  2991. SickHistory: sick_history,
  2992. Departments: department,
  2993. RegisterType: reg_type,
  2994. PrescriptionNumber: info.PrescriptionNumber,
  2995. Doctor: role.UserName,
  2996. PrescriptionStatus: info.PrescriptionStatus,
  2997. DoctorId: doctor_id,
  2998. SickType: sick_type,
  2999. PType: info.PType,
  3000. HisPatientId: info.HisPatientId,
  3001. PatientDiagnosis: patient_diagnose,
  3002. }
  3003. service.SavePatientPrescriptionInfo(hpInfo)
  3004. //创建步骤表
  3005. finish := models.XtDialysisFinish{
  3006. IsFinish: 1,
  3007. UserOrgId: adminInfo.CurrentOrgId,
  3008. Status: 1,
  3009. Ctime: time.Now().Unix(),
  3010. Mtime: 0,
  3011. Module: 4,
  3012. RecordDate: info.RecordDate,
  3013. Sourse: 1,
  3014. PatientId: info.PatientId,
  3015. }
  3016. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3017. if dialysisFinish.ID == 0 {
  3018. service.CreateDialysisFinish(finish)
  3019. }
  3020. redis := service.RedisClient()
  3021. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3022. redis.Set(key, "", time.Second)
  3023. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3024. redis.Set(keyOne, "", time.Second)
  3025. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3026. redis.Set(keySeven, "", time.Second)
  3027. defer redis.Close()
  3028. }
  3029. //定义切片
  3030. var adviceList []models.HisDoctorAdviceInfo
  3031. var projectList []models.HisPrescriptionProject
  3032. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10635 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 || adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10726 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10571 || adminInfo.CurrentOrgId == 10724 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10653 || adminInfo.CurrentOrgId == 10567 {
  3033. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3034. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3035. var tempPrescription *models.HisPrescription
  3036. if len(prescriptions) > 0 {
  3037. for _, item := range prescriptions {
  3038. // 开始外部循环的事务
  3039. tx := db.Begin()
  3040. // 在函数结束时处理事务回滚
  3041. defer func() {
  3042. if r := recover(); r != nil {
  3043. tx.Rollback()
  3044. }
  3045. }()
  3046. items := item.(map[string]interface{})
  3047. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3048. utils.ErrorLog("id")
  3049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3050. return
  3051. }
  3052. id := int64(items["id"].(float64))
  3053. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3054. tempPrescription = &new_prescription
  3055. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3056. utils.ErrorLog("type")
  3057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3058. return
  3059. }
  3060. types := int64(items["type"].(float64))
  3061. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3062. utils.ErrorLog("med_type")
  3063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3064. return
  3065. }
  3066. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3067. if med_type == "0" {
  3068. med_type = "14"
  3069. }
  3070. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3071. // utils.ErrorLog("diagnoses")
  3072. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3073. // return
  3074. //}
  3075. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3076. diagnoses, _ := items["diagnoses"].(string)
  3077. //if order_status == 0 {
  3078. // order_status = 1
  3079. //}
  3080. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3081. utils.ErrorLog("pre_time")
  3082. }
  3083. preTime, _ := items["pre_time"].(string)
  3084. fmt.Println("preTime", preTime)
  3085. timeLayout := "2006-01-02"
  3086. loc, _ := time.LoadLocation("Local")
  3087. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3088. //result := strings.Split(preTime, " ")
  3089. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3090. if err != nil {
  3091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3092. return
  3093. }
  3094. pTime := theTime2.Unix()
  3095. ctime := time.Now().Unix()
  3096. if tempPrescription.ID == 0 {
  3097. prescription := &models.HisPrescription{
  3098. ID: 0,
  3099. PatientId: patient_id,
  3100. UserOrgId: adminInfo.CurrentOrgId,
  3101. RecordDate: recordDateTime,
  3102. Ctime: ctime,
  3103. Mtime: ctime,
  3104. Type: types,
  3105. Modifier: adminInfo.AdminUser.Id,
  3106. Creator: adminInfo.AdminUser.Id,
  3107. Status: 1,
  3108. Doctor: role.UserName,
  3109. HisPatientId: his_patient_id,
  3110. OrderStatus: 1,
  3111. BatchNumber: "",
  3112. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3113. PreTime: pTime,
  3114. PType: p_type,
  3115. MedType: med_type,
  3116. Diagnose: diagnoses,
  3117. }
  3118. tempPrescription = prescription
  3119. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3120. redis := service.RedisClient()
  3121. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3122. redis.Set(key, "", time.Second)
  3123. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3124. redis.Set(keyOne, "", time.Second)
  3125. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3126. redis.Set(keySeven, "", time.Second)
  3127. defer redis.Close()
  3128. } else {
  3129. tempPrescription.ID = id
  3130. tempPrescription.Type = types
  3131. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3132. tempPrescription.Mtime = time.Now().Unix()
  3133. tempPrescription.Doctor = role.UserName
  3134. //tempPrescription.OrderStatus = order_status
  3135. tempPrescription.PreTime = pTime
  3136. tempPrescription.MedType = med_type
  3137. tempPrescription.Diagnose = diagnoses
  3138. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3139. redis := service.RedisClient()
  3140. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3141. redis.Set(key, "", time.Second)
  3142. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3143. redis.Set(keyOne, "", time.Second)
  3144. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3145. redis.Set(keySeven, "", time.Second)
  3146. defer redis.Close()
  3147. }
  3148. //service.SaveHisPrescription(prescription)
  3149. //更改患者挂号状态
  3150. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3151. fmt.Println("更改失败", err2)
  3152. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3153. advices := items["advices"].([]interface{})
  3154. groupNo := int64(0)
  3155. if len(advices) > 0 {
  3156. for _, advice := range advices {
  3157. tx := db.Begin()
  3158. // 在函数结束时处理事务回滚
  3159. defer func() {
  3160. if r := recover(); r != nil {
  3161. tx.Rollback()
  3162. }
  3163. }()
  3164. var s models.HisDoctorAdviceInfo
  3165. s.PrescriptionId = tempPrescription.ID
  3166. s.AdviceType = 2
  3167. s.AdviceDoctor = doctor_id
  3168. s.StopState = 2
  3169. s.ExecutionState = 2
  3170. s.AdviceDate = theTime3.Unix()
  3171. s.Status = 1
  3172. s.UserOrgId = adminInfo.CurrentOrgId
  3173. s.RecordDate = theTime3.Unix()
  3174. s.StartTime = tempPrescription.PreTime
  3175. s.Groupno = groupNo
  3176. s.PatientId = patient_id
  3177. s.HisPatientId = his_patient_id
  3178. s.StartTime = pTime
  3179. s.IsSettle = 2
  3180. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3181. if errcode > 0 {
  3182. c.ServeFailJSONWithSGJErrorCode(errcode)
  3183. return
  3184. }
  3185. s.StartTime = pTime
  3186. var total_count int64 //处方总库存
  3187. //查询改药品信息
  3188. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3189. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3190. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3191. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3192. total_count += prescribingNumberSeven * medical.MinNumber
  3193. }
  3194. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3195. total_count += prescribingNumberSeven
  3196. }
  3197. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3198. total_count += prescribingNumberSeven
  3199. }
  3200. //if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3201. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3202. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3203. // if s.Price != lastWarehouse.RetailPrice {
  3204. // s.Price = lastWarehouse.RetailPrice
  3205. // }
  3206. // if s.Price == 0 {
  3207. // if lastWarehouse.ID == 0 {
  3208. // lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3209. // s.Price = lastWarehouseTwo.RetailPrice
  3210. // }
  3211. //
  3212. // }
  3213. //}
  3214. //查询保存处方出库开关是否打开
  3215. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3216. if s.PatientId != 30038 {
  3217. if drugOutConfig.IsOpen == 1 {
  3218. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3219. // 查询该药品最后一次出库记录
  3220. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3221. var is_user_total int64
  3222. var no_user_total int64
  3223. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3224. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3225. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3226. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3227. }
  3228. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3229. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3230. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3231. no_user_total += prescribingNumberSevenTy
  3232. }
  3233. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3234. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3235. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3236. no_user_total += prescribingNumberSevenTy
  3237. }
  3238. if len(druginfo) > 0 {
  3239. for _, it := range druginfo {
  3240. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3241. it.Count = it.Count * drug.MinNumber
  3242. is_user_total += it.Count
  3243. }
  3244. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3245. is_user_total += it.Count
  3246. }
  3247. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3248. is_user_total += it.Count
  3249. }
  3250. }
  3251. }
  3252. //库存不足
  3253. if s.UserOrgId != 10206 {
  3254. //判断库存不足的地方
  3255. if s.ID == 0 {
  3256. //查询改药品是否已经停用
  3257. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3258. if base.ID > 0 {
  3259. tx.Rollback()
  3260. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3261. return
  3262. }
  3263. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3264. if drugMedical.SumCount == 0 {
  3265. tx.Rollback()
  3266. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3267. return
  3268. }
  3269. list, _ := service.GetLastDrugWarehouseInfoList(s.DrugId)
  3270. if len(list) == 0 {
  3271. tx.Rollback()
  3272. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3273. return
  3274. }
  3275. //针对康德
  3276. //if s.UserOrgId == 10402 || s.UserOrgId == 10164 {
  3277. // //获取该药品的总入库数量
  3278. // drugWarehouseinfo, _ := service.GetAllDrugInfoList(s.DrugId, s.UserOrgId)
  3279. //
  3280. // //获取该药品总共开了多少支医嘱
  3281. // hisDocInfoList, _ := service.GetHisDocInfoList(s.DrugId, s.UserOrgId)
  3282. // var in_count int64
  3283. // var in_prescription_number_total int64
  3284. // if len(drugWarehouseinfo) > 0 {
  3285. // for _, item := range drugWarehouseinfo {
  3286. // if item.MaxUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3287. //
  3288. // in_count += item.WarehousingCount * drugMedical.MinNumber
  3289. // }
  3290. //
  3291. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3292. //
  3293. // in_count += item.WarehousingCount
  3294. // }
  3295. //
  3296. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3297. //
  3298. // in_count += item.WarehousingCount
  3299. // }
  3300. //
  3301. // }
  3302. // }
  3303. //
  3304. // if len(hisDocInfoList) > 0 {
  3305. //
  3306. // for _, item := range hisDocInfoList {
  3307. // if item.PrescribingNumberUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3308. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3309. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3310. //
  3311. // in_prescription_number_total += prescribingNumberSevenTy * drug.MinNumber
  3312. // }
  3313. //
  3314. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3315. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3316. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3317. // in_prescription_number_total += prescribingNumberSevenTy
  3318. // }
  3319. //
  3320. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3321. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3322. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3323. // in_prescription_number_total += prescribingNumberSevenTy
  3324. // }
  3325. // }
  3326. // }
  3327. // //
  3328. // //fmt.Println("no_user_total------------------------------", no_user_total)
  3329. // //fmt.Println("in_prescription_number_total---------------------------", in_prescription_number_total)
  3330. // //fmt.Println("in_count----------------------------------", in_count)
  3331. //
  3332. // //如果已经开过的医嘱 加上未开的医嘱数量 大于 入库总数量则提示库存不足
  3333. // if no_user_total+in_prescription_number_total > in_count {
  3334. // tx.Rollback()
  3335. // c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3336. // return
  3337. // }
  3338. //
  3339. //}
  3340. //查询该药品所有入库数量
  3341. }
  3342. fmt.Println("s.ID==========================", s.ID)
  3343. if s.ID > 0 {
  3344. //查询改药品是否已经停用
  3345. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3346. if base.ID > 0 {
  3347. tx.Rollback()
  3348. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3349. return
  3350. }
  3351. }
  3352. }
  3353. fmt.Println("药品名称----------------------", drug.DrugName)
  3354. fmt.Println("药品名称----------------------", drug.IsUse)
  3355. fmt.Println("drug_iiiiiiiiiiiiiiiiiiii", drug.ID)
  3356. fmt.Println("is_user_total-------------------------", is_user_total)
  3357. fmt.Println("no_user_total-------------------------", no_user_total)
  3358. fmt.Println("drug.IsUse---------------", drug.IsUse)
  3359. fmt.Println("00000000000000000000", s.UserOrgId)
  3360. if is_user_total != no_user_total {
  3361. //出库
  3362. //针对御享天源
  3363. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  3364. //查询改药品是否已经停用
  3365. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3366. if base.ID > 0 {
  3367. tx.Rollback()
  3368. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3369. return
  3370. }
  3371. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3372. if drugMedical.SumCount == 0 {
  3373. tx.Rollback()
  3374. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3375. return
  3376. }
  3377. creater := adminInfo.AdminUser.Id
  3378. newadviceInfo := &models.HisDoctorAdviceInfo{
  3379. ID: s.ID,
  3380. UserOrgId: s.UserOrgId,
  3381. PatientId: s.PatientId,
  3382. HisPatientId: s.HisPatientId,
  3383. AdviceType: s.AdviceType,
  3384. AdviceDate: s.AdviceDate,
  3385. StartTime: s.StartTime,
  3386. AdviceName: s.AdviceName,
  3387. AdviceDesc: s.AdviceDesc,
  3388. ReminderDate: s.ReminderDate,
  3389. SingleDose: s.SingleDose,
  3390. SingleDoseUnit: s.SingleDoseUnit,
  3391. PrescribingNumber: s.PrescribingNumber,
  3392. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3393. DeliveryWay: s.DeliveryWay,
  3394. ExecutionFrequency: s.ExecutionFrequency,
  3395. AdviceDoctor: s.AdviceDoctor,
  3396. Status: s.Status,
  3397. CreatedTime: s.CreatedTime,
  3398. UpdatedTime: s.UpdatedTime,
  3399. AdviceAffirm: s.AdviceAffirm,
  3400. Remark: s.Remark,
  3401. StopTime: s.StopTime,
  3402. StopReason: s.StopReason,
  3403. StopDoctor: s.StopDoctor,
  3404. StopState: s.StopState,
  3405. ParentId: s.ParentId,
  3406. ExecutionTime: s.ExecutionTime,
  3407. ExecutionStaff: s.ExecutionStaff,
  3408. ExecutionState: s.ExecutionState,
  3409. Checker: s.Checker,
  3410. RecordDate: s.RecordDate,
  3411. DialysisOrderId: s.DialysisOrderId,
  3412. CheckTime: s.CheckTime,
  3413. CheckState: s.CheckState,
  3414. DrugSpec: s.DrugSpec,
  3415. DrugSpecUnit: s.DrugSpecUnit,
  3416. Groupno: s.Groupno,
  3417. RemindType: s.RemindType,
  3418. FrequencyType: s.FrequencyType,
  3419. DayCount: s.DayCount,
  3420. WeekDay: s.WeekDay,
  3421. TemplateId: s.TemplateId,
  3422. Modifier: s.Modifier,
  3423. DrugId: s.DrugId,
  3424. Price: s.Price,
  3425. PrescriptionId: s.PrescriptionId,
  3426. MedListCodg: s.MedListCodg,
  3427. FeedetlSn: s.FeedetlSn,
  3428. Day: s.DayCount,
  3429. ChildDoctorAdvice: nil,
  3430. Drug: models.Drug{},
  3431. Diagnosis: s.Diagnosis,
  3432. Way: s.Way,
  3433. HospApprFlag: s.HospApprFlag,
  3434. LmtUsedFlag: s.LmtUsedFlag,
  3435. HisOrderInfo: models.HisOrderInfo{},
  3436. IsMedicine: s.IsMedicine,
  3437. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3438. Child: nil,
  3439. IsSettle: s.IsSettle,
  3440. IsMobile: s.IsMobile,
  3441. IsSelfDrug: s.IsSelfDrug,
  3442. DrugWayCount: s.DrugWayCount,
  3443. }
  3444. var history_count int64
  3445. var local_count int64
  3446. //查找已经开过的医嘱信息
  3447. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3448. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3449. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3450. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3451. local_count += prescribingNumberSevenTy * drug.MinNumber
  3452. }
  3453. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3454. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3455. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3456. local_count += prescribingNumberSevenTy
  3457. }
  3458. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3459. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3460. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3461. local_count += prescribingNumberSevenTy
  3462. }
  3463. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3464. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3465. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3466. history_count += prescribingNumberSevenTy * drug.MinNumber
  3467. }
  3468. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3469. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3470. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3471. history_count += prescribingNumberSevenTy
  3472. }
  3473. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3474. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3475. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3476. history_count += prescribingNumberSevenTy
  3477. }
  3478. fmt.Println("local_count---------------", local_count)
  3479. fmt.Println("history_count---------------", history_count)
  3480. //如果当前出库数量大于历史出库数量则需要出库
  3481. if local_count > history_count {
  3482. //按最小单位出库
  3483. var cha_count = local_count - history_count
  3484. newadviceInfo.PrescribingNumber = float64(cha_count)
  3485. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3486. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3487. }
  3488. //如果当前出库数量小于历史出库数量则需要退库
  3489. if local_count < history_count {
  3490. var cha_count = history_count - local_count
  3491. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3492. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3493. }
  3494. if local_count == history_count {
  3495. if is_user_total == 0 {
  3496. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3497. }
  3498. }
  3499. }
  3500. if drug.IsUse == 2 {
  3501. creater := adminInfo.AdminUser.Id
  3502. newadviceInfo := &models.HisDoctorAdviceInfo{
  3503. ID: s.ID,
  3504. UserOrgId: s.UserOrgId,
  3505. PatientId: s.PatientId,
  3506. HisPatientId: s.HisPatientId,
  3507. AdviceType: s.AdviceType,
  3508. AdviceDate: s.AdviceDate,
  3509. StartTime: s.StartTime,
  3510. AdviceName: s.AdviceName,
  3511. AdviceDesc: s.AdviceDesc,
  3512. ReminderDate: s.ReminderDate,
  3513. SingleDose: s.SingleDose,
  3514. SingleDoseUnit: s.SingleDoseUnit,
  3515. PrescribingNumber: s.PrescribingNumber,
  3516. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3517. DeliveryWay: s.DeliveryWay,
  3518. ExecutionFrequency: s.ExecutionFrequency,
  3519. AdviceDoctor: s.AdviceDoctor,
  3520. Status: s.Status,
  3521. CreatedTime: s.CreatedTime,
  3522. UpdatedTime: s.UpdatedTime,
  3523. AdviceAffirm: s.AdviceAffirm,
  3524. Remark: s.Remark,
  3525. StopTime: s.StopTime,
  3526. StopReason: s.StopReason,
  3527. StopDoctor: s.StopDoctor,
  3528. StopState: s.StopState,
  3529. ParentId: s.ParentId,
  3530. ExecutionTime: s.ExecutionTime,
  3531. ExecutionStaff: s.ExecutionStaff,
  3532. ExecutionState: s.ExecutionState,
  3533. Checker: s.Checker,
  3534. RecordDate: s.RecordDate,
  3535. DialysisOrderId: s.DialysisOrderId,
  3536. CheckTime: s.CheckTime,
  3537. CheckState: s.CheckState,
  3538. DrugSpec: s.DrugSpec,
  3539. DrugSpecUnit: s.DrugSpecUnit,
  3540. Groupno: s.Groupno,
  3541. RemindType: s.RemindType,
  3542. FrequencyType: s.FrequencyType,
  3543. DayCount: s.DayCount,
  3544. WeekDay: s.WeekDay,
  3545. TemplateId: s.TemplateId,
  3546. Modifier: s.Modifier,
  3547. DrugId: s.DrugId,
  3548. Price: s.Price,
  3549. PrescriptionId: s.PrescriptionId,
  3550. MedListCodg: s.MedListCodg,
  3551. FeedetlSn: s.FeedetlSn,
  3552. Day: s.DayCount,
  3553. ChildDoctorAdvice: nil,
  3554. Drug: models.Drug{},
  3555. Diagnosis: s.Diagnosis,
  3556. Way: s.Way,
  3557. HospApprFlag: s.HospApprFlag,
  3558. LmtUsedFlag: s.LmtUsedFlag,
  3559. HisOrderInfo: models.HisOrderInfo{},
  3560. IsMedicine: s.IsMedicine,
  3561. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3562. Child: nil,
  3563. IsSettle: s.IsSettle,
  3564. IsMobile: s.IsMobile,
  3565. IsSelfDrug: s.IsSelfDrug,
  3566. DrugWayCount: s.DrugWayCount,
  3567. }
  3568. var history_count int64
  3569. var local_count int64
  3570. //查找已经开过的医嘱信息
  3571. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3572. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3573. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3574. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3575. local_count += prescribingNumberSevenTy * drug.MinNumber
  3576. }
  3577. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3578. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3579. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3580. local_count += prescribingNumberSevenTy
  3581. }
  3582. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3583. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3584. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3585. local_count += prescribingNumberSevenTy
  3586. }
  3587. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3588. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3589. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3590. history_count += prescribingNumberSevenTy * drug.MinNumber
  3591. }
  3592. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3593. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3594. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3595. history_count += prescribingNumberSevenTy
  3596. }
  3597. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3598. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3599. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3600. history_count += prescribingNumberSevenTy
  3601. }
  3602. fmt.Println("local_count---------------", local_count)
  3603. fmt.Println("history_count---------------", history_count)
  3604. //如果当前出库数量大于历史出库数量则需要出库
  3605. if local_count > history_count {
  3606. //按最小单位出库
  3607. var cha_count = local_count - history_count
  3608. newadviceInfo.PrescribingNumber = float64(cha_count)
  3609. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3610. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3611. }
  3612. //如果当前出库数量小于历史出库数量则需要退库
  3613. if local_count < history_count {
  3614. var cha_count = history_count - local_count
  3615. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3616. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3617. }
  3618. if local_count == history_count {
  3619. if is_user_total == 0 {
  3620. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3621. }
  3622. }
  3623. }
  3624. //更新字典里面的库存
  3625. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3626. var sum_count int64
  3627. for _, its := range stockInfo {
  3628. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3629. if its.MaxUnit == baseDrug.MaxUnit {
  3630. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3631. }
  3632. sum_count += its.StockMaxNumber + its.StockMinNumber
  3633. }
  3634. //更新基础库存
  3635. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3636. //剩余库存
  3637. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3638. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3639. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3640. //创建医嘱
  3641. service.CreateHisDoctorAdviceOne(&s, tx)
  3642. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3643. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3644. if len(outInfoTwo) > 0 {
  3645. for _, item := range outInfoTwo {
  3646. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3647. }
  3648. }
  3649. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3650. if len(drugAutoDetail) > 0 {
  3651. for _, item := range drugAutoDetail {
  3652. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3653. }
  3654. }
  3655. }
  3656. }
  3657. }
  3658. //记录日志
  3659. byterequest, _ := json.Marshal(s)
  3660. adviceLog := models.XtDoctorAdviceLog{
  3661. UserOrgId: s.UserOrgId,
  3662. PatientId: s.PatientId,
  3663. AdminUserId: adminInfo.AdminUser.Id,
  3664. Module: 1,
  3665. ErrLog: string(byterequest),
  3666. Status: 1,
  3667. Ctime: time.Now().Unix(),
  3668. Mtime: 0,
  3669. Source: "电脑端新建his医嘱",
  3670. RecordDate: s.AdviceDate,
  3671. }
  3672. service.CreateDoctorAdviceLog(adviceLog)
  3673. //存储切片中
  3674. adviceList = append(adviceList, s)
  3675. redis := service.RedisClient()
  3676. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3677. redis.Set(key, "", time.Second)
  3678. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3679. redis.Set(keyOne, "", time.Second)
  3680. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3681. redis.Set(keySeven, "", time.Second)
  3682. var randNum int
  3683. randNum = rand.Intn(10000) + 1000
  3684. timestamp := time.Now().Unix()
  3685. tempTime := time.Unix(timestamp, 0)
  3686. timeFormat := tempTime.Format("20060102150405")
  3687. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3688. //赤峰
  3689. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3690. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3691. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3692. if info.RetailPrice > 0 {
  3693. if s.DeliveryWay == "口服" {
  3694. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3695. s.Price = drug.RetailPrice
  3696. }
  3697. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3698. s.Price = info.RetailPrice
  3699. }
  3700. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3701. s.Price = info.RetailPrice
  3702. }
  3703. }
  3704. }
  3705. }
  3706. service.CreateHisDoctorAdviceOne(&s, tx)
  3707. tx.Commit()
  3708. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3709. redis.Set(keySix, "", time.Second)
  3710. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3711. redis.Set(keyFive, "", time.Second)
  3712. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3713. redis.Set(keyEight, "", time.Second)
  3714. defer redis.Close()
  3715. }
  3716. }
  3717. }
  3718. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3719. projects := items["project"].([]interface{})
  3720. if len(projects) > 0 {
  3721. for _, project := range projects {
  3722. tx := db.Begin()
  3723. // 在函数结束时处理事务回滚
  3724. defer func() {
  3725. if r := recover(); r != nil {
  3726. tx.Rollback()
  3727. }
  3728. }()
  3729. var p models.HisPrescriptionProject
  3730. p.PrescriptionId = tempPrescription.ID
  3731. p.PatientId = patient_id
  3732. p.RecordDate = theTime3.Unix()
  3733. p.Doctor = doctor_id
  3734. p.UserOrgId = adminInfo.CurrentOrgId
  3735. p.HisPatientId = his_patient_id
  3736. p.Status = 1
  3737. p.StartTime = pTime
  3738. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3739. if errcode > 0 {
  3740. tx.Rollback()
  3741. c.ServeFailJSONWithSGJErrorCode(errcode)
  3742. return
  3743. }
  3744. if p.ID == 0 {
  3745. p.IsOut = 2
  3746. }
  3747. if p.ID > 0 {
  3748. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3749. p.IsOut = projectDetail.IsOut
  3750. }
  3751. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3752. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3753. if p.Type == 3 {
  3754. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3755. if p.Price != lastWarehouse.PackingPrice {
  3756. p.Price = lastWarehouse.PackingPrice
  3757. }
  3758. if p.Price == 0 {
  3759. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3760. p.Price = lastWarehouseTwo.PackingPrice
  3761. }
  3762. if p.Unit == "" {
  3763. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3764. p.Unit = goodInfoOne.PackingUnit
  3765. }
  3766. }
  3767. }
  3768. if adminInfo.CurrentOrgId != 10206 {
  3769. if p.Type == 3 {
  3770. //判断耗材库存充不充足
  3771. if p.ID == 0 {
  3772. //查询该耗材是否停用
  3773. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3774. //表示该耗材已经停用,不能保存
  3775. if goodInfoSeven.ID == 0 {
  3776. tx.Rollback()
  3777. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3778. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3779. return
  3780. }
  3781. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3782. if goodInfoOne.SumCount == 0 {
  3783. tx.Rollback()
  3784. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3785. return
  3786. }
  3787. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3788. if len(goodListOne) == 0 {
  3789. tx.Rollback()
  3790. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3791. return
  3792. }
  3793. }
  3794. if p.ID > 0 {
  3795. //查询该耗材是否停用
  3796. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3797. //表示该耗材已经停用,不能保存
  3798. if goodInfoSeven.ID == 0 {
  3799. tx.Rollback()
  3800. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3801. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3802. return
  3803. }
  3804. //查询该耗材今日是否已经出过库
  3805. goodOutList, _ := service.GetGoodWareHouseOutInfoByGood(p.ProjectId, p.RecordDate, p.UserOrgId)
  3806. var his_count int64
  3807. if len(goodOutList) > 0 {
  3808. for _, item := range goodOutList {
  3809. his_count += item.Count
  3810. }
  3811. }
  3812. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3813. //如果当前的处方数量大于 历史出库数量 要判断库存够不够
  3814. if nowCount > his_count {
  3815. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3816. if goodInfoOne.SumCount == 0 {
  3817. tx.Rollback()
  3818. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3819. return
  3820. }
  3821. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3822. if len(goodListOne) == 0 {
  3823. tx.Rollback()
  3824. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3825. return
  3826. }
  3827. }
  3828. if len(goodOutList) == 0 {
  3829. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3830. if goodInfoOne.SumCount == 0 {
  3831. tx.Rollback()
  3832. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3833. return
  3834. }
  3835. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3836. if len(goodListOne) == 0 {
  3837. tx.Rollback()
  3838. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3839. return
  3840. }
  3841. }
  3842. }
  3843. }
  3844. }
  3845. //查询保存耗材出库开关是否打开
  3846. if p.PatientId != 30038 {
  3847. //用机构ID区分
  3848. if adminInfo.CurrentOrgId != 9671 {
  3849. if goodOutConfig.IsOpen == 1 {
  3850. //耗材出库
  3851. if p.Type == 3 {
  3852. //对比当前数据和历史出库数据
  3853. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3854. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3855. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3856. ////针对康德
  3857. //if p.UserOrgId == 10164 || p.UserOrgId == 10402 {
  3858. //
  3859. // //查询耗材的总入库数量
  3860. // warehouseInfo, _ := service.GetAllWarehouseInfo(p.ProjectId, adminInfo.CurrentOrgId)
  3861. //
  3862. // //查询该耗材的总出库数量
  3863. // prescriptionGood, _ := service.GetHisPrescriptionByGoodId(p.ProjectId, adminInfo.CurrentOrgId)
  3864. //
  3865. // var all_good_count int64
  3866. //
  3867. // var prescription_count int64
  3868. // if len(warehouseInfo) > 0 {
  3869. //
  3870. // for _, item := range warehouseInfo {
  3871. // all_good_count += item.WarehousingCount
  3872. // }
  3873. // }
  3874. // if len(prescriptionGood) > 0 {
  3875. // for _, item := range prescriptionGood {
  3876. //
  3877. // hisCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3878. // prescription_count += hisCount
  3879. // }
  3880. // }
  3881. //
  3882. // //fmt.Println("prescription_count-------------------------", prescription_count)
  3883. // //fmt.Println("nowCount-------------------------", nowCount)
  3884. // //fmt.Println("all_good_count-------------------------", all_good_count)
  3885. //
  3886. // if prescription_count+nowCount > all_good_count {
  3887. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3888. // tx.Rollback()
  3889. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3890. // return
  3891. // }
  3892. //}
  3893. //如果当前处方数量大于历史数据,则需要出库
  3894. if nowCount > historyCount {
  3895. var cha_count int64
  3896. cha_count = nowCount - historyCount
  3897. timeStr := time.Now().Format("2006-01-02")
  3898. timeArr := strings.Split(timeStr, "-")
  3899. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3900. total = total + 1
  3901. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3902. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3903. number = number + total
  3904. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3905. operation_time := time.Now().Unix()
  3906. creater := c.GetAdminUserInfo().AdminUser.Id
  3907. recordDateStr := time.Now().Format("2006-01-02")
  3908. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3909. nowtime := recordDate.Unix()
  3910. warehouseOut := models.WarehouseOut{
  3911. WarehouseOutOrderNumber: warehousing_out_order,
  3912. OperationTime: operation_time,
  3913. OrgId: adminInfo.CurrentOrgId,
  3914. Creater: creater,
  3915. Ctime: time.Now().Unix(),
  3916. Status: 1,
  3917. WarehouseOutTime: nowtime,
  3918. Type: 1,
  3919. StorehouseId: storeConfig.StorehouseOutInfo,
  3920. IsCheck: 1,
  3921. IsSys: 1,
  3922. }
  3923. //查询是否生成出库单
  3924. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3925. if out.ID == 0 {
  3926. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3927. }
  3928. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3929. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3930. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3931. dialyPrepareOne := models.DialysisBeforePrepare{
  3932. GoodTypeId: goodObj.GoodTypeId,
  3933. GoodId: p.ProjectId,
  3934. PatientId: p.PatientId,
  3935. RecordDate: p.RecordDate,
  3936. UserOrgId: adminInfo.CurrentOrgId,
  3937. Count: cha_count,
  3938. Ctime: time.Now().Unix(),
  3939. Creater: creater,
  3940. Status: 1,
  3941. StorehouseId: houseConfig.StorehouseOutInfo,
  3942. ProjectId: p.ID,
  3943. }
  3944. //出库
  3945. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3946. }
  3947. //如果当前处方数量小于历史数据,怎需要退库
  3948. if nowCount < historyCount {
  3949. var cha_count int64
  3950. cha_count = historyCount - nowCount
  3951. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3952. creater := c.GetAdminUserInfo().AdminUser.Id
  3953. newPrescriptionProject := &models.HisPrescriptionProject{
  3954. ID: p.ID,
  3955. ProjectId: p.ProjectId,
  3956. Price: p.Price,
  3957. UserOrgId: p.UserOrgId,
  3958. Status: 1,
  3959. Ctime: time.Now().Unix(),
  3960. Mtime: time.Now().Unix(),
  3961. PatientId: p.PatientId,
  3962. HisPatientId: p.HisPatientId,
  3963. RecordDate: p.RecordDate,
  3964. PrescriptionId: p.PrescriptionId,
  3965. Count: p.Count,
  3966. FeedetlSn: p.FeedetlSn,
  3967. MedListCodg: p.MedListCodg,
  3968. SingleDose: p.SingleDose,
  3969. DeliveryWay: p.DeliveryWay,
  3970. ExecutionFrequency: p.ExecutionFrequency,
  3971. Day: p.Day,
  3972. HisProject: models.HisProject{},
  3973. GoodInfo: models.GoodInfo{},
  3974. Remark: p.Remark,
  3975. Unit: p.Unit,
  3976. Type: p.Type,
  3977. Doctor: p.Doctor,
  3978. ExecutionTime: p.ExecutionTime,
  3979. ExecutionStaff: p.ExecutionStaff,
  3980. ExecutionState: p.ExecutionState,
  3981. CheckTime: p.CheckTime,
  3982. CheckState: p.CheckState,
  3983. Checker: p.Checker,
  3984. StartTime: p.StartTime,
  3985. TeamId: p.TeamId,
  3986. XtHisProjectTeam: models.XtHisProjectTeam{},
  3987. FrequencyType: p.FrequencyType,
  3988. DayCount: p.DayCount,
  3989. WeekDay: p.WeekDay,
  3990. IsCheckTeam: p.IsCheckTeam,
  3991. HisOrderInfo: models.HisOrderInfo{},
  3992. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3993. IsOut: p.IsOut,
  3994. YbSyncStatus: p.YbSyncStatus,
  3995. }
  3996. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3997. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3998. }
  3999. if nowCount == historyCount {
  4000. if historyCount == 0 {
  4001. recordDateStr := time.Now().Format("2006-01-02")
  4002. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4003. nowtime := recordDate.Unix()
  4004. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4005. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4006. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4007. creater := c.GetAdminUserInfo().AdminUser.Id
  4008. dialyPrepareOne := models.DialysisBeforePrepare{
  4009. GoodTypeId: goodObj.GoodTypeId,
  4010. GoodId: p.ProjectId,
  4011. PatientId: p.PatientId,
  4012. RecordDate: p.RecordDate,
  4013. UserOrgId: adminInfo.CurrentOrgId,
  4014. Count: nowCount,
  4015. Ctime: time.Now().Unix(),
  4016. Creater: creater,
  4017. Status: 1,
  4018. StorehouseId: houseConfig.StorehouseOutInfo,
  4019. ProjectId: p.ID,
  4020. }
  4021. //出库
  4022. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4023. }
  4024. }
  4025. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4026. //查询历史出库数据
  4027. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4028. var out_count_five int64
  4029. for _, item := range flowGood {
  4030. out_count_five += item.Count
  4031. }
  4032. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4033. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4034. if out_count_five != parseIntCount {
  4035. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4036. detail := models.AutomaticReduceDetail{
  4037. WarehouseOutId: 0,
  4038. WarehouseOutOrderNumber: "",
  4039. PatientId: p.PatientId,
  4040. Ctime: time.Now().Unix(),
  4041. Mtime: 0,
  4042. Status: 1,
  4043. RecordTime: p.RecordDate,
  4044. OrgId: p.UserOrgId,
  4045. GoodId: p.ProjectId,
  4046. GoodTypeId: 0,
  4047. Count: parseIntCount,
  4048. Type: 0,
  4049. ProjectId: lastHisProject.ID,
  4050. StorehouseId: 0,
  4051. }
  4052. service.CreateNewAutoDetail(detail, tx)
  4053. }
  4054. // //查询耗材最后一次出库记录
  4055. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4056. // //查询默认出库仓库库存
  4057. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4058. // if len(wareOut) > 0 {
  4059. //
  4060. // for _, it := range wareOut {
  4061. // //回退库存
  4062. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4063. //
  4064. // //删除出库记录
  4065. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4066. //
  4067. // }
  4068. // }
  4069. //
  4070. // timeStr := time.Now().Format("2006-01-02")
  4071. // timeArr := strings.Split(timeStr, "-")
  4072. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4073. //
  4074. // total = total + 1
  4075. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4076. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4077. // number = number + total
  4078. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4079. //
  4080. // operation_time := time.Now().Unix()
  4081. // creater := c.GetAdminUserInfo().AdminUser.Id
  4082. //
  4083. // recordDateStr := time.Now().Format("2006-01-02")
  4084. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4085. // nowtime := recordDate.Unix()
  4086. // warehouseOut := models.WarehouseOut{
  4087. // WarehouseOutOrderNumber: warehousing_out_order,
  4088. // OperationTime: operation_time,
  4089. // OrgId: adminInfo.CurrentOrgId,
  4090. // Creater: creater,
  4091. // Ctime: time.Now().Unix(),
  4092. // Status: 1,
  4093. // WarehouseOutTime: nowtime,
  4094. // Type: 1,
  4095. // StorehouseId: storeConfig.StorehouseOutInfo,
  4096. // IsCheck: 1,
  4097. // IsSys: 1,
  4098. // }
  4099. // //查询是否生成出库单
  4100. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4101. // if out.ID == 0 {
  4102. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4103. // }
  4104. //
  4105. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4106. //
  4107. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4108. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4109. //
  4110. // dialyPrepareOne := models.DialysisBeforePrepare{
  4111. // GoodTypeId: goodObj.GoodTypeId,
  4112. // GoodId: p.ProjectId,
  4113. // PatientId: p.PatientId,
  4114. // RecordDate: p.RecordDate,
  4115. // UserOrgId: adminInfo.CurrentOrgId,
  4116. // Count: parseIntCount,
  4117. // Ctime: time.Now().Unix(),
  4118. // Creater: creater,
  4119. // Status: 1,
  4120. // StorehouseId: houseConfig.StorehouseOutInfo,
  4121. // ProjectId: lastHisProject.ID,
  4122. // }
  4123. // //判断是否是零用耗材(非零用)
  4124. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4125. //
  4126. // //查询历史出库数据
  4127. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4128. // var out_count int64
  4129. // for _, item := range flowGood {
  4130. // out_count += item.Count
  4131. // }
  4132. // //如果历史数和当前数据不想等才进行退库出库
  4133. // if out_count != parseIntCount {
  4134. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4135. //
  4136. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4137. // detail := models.AutomaticReduceDetail{
  4138. // WarehouseOutId: 0,
  4139. // WarehouseOutOrderNumber: "",
  4140. // PatientId: p.PatientId,
  4141. // Ctime: time.Now().Unix(),
  4142. // Mtime: 0,
  4143. // Status: 1,
  4144. // RecordTime: p.RecordDate,
  4145. // OrgId: p.UserOrgId,
  4146. // GoodId: p.ProjectId,
  4147. // GoodTypeId: 0,
  4148. // Count: parseIntCount,
  4149. // Type: 0,
  4150. // ProjectId: lastHisProject.ID,
  4151. // StorehouseId: 0,
  4152. // }
  4153. //
  4154. // service.CreateNewAutoDetail(detail, tx)
  4155. //
  4156. // //查询剩余库存
  4157. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4158. // var sum_count int64
  4159. // for _, item := range goodList {
  4160. // sum_count += item.StockCount
  4161. // }
  4162. //
  4163. // //更新剩余库存
  4164. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4165. //
  4166. // //耗材
  4167. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4168. //
  4169. // }
  4170. // //判断是否是零用耗材(零用但是是出库耗材)
  4171. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4172. //
  4173. // //查询历史出库数据
  4174. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4175. // var out_count int64
  4176. // for _, item := range flowGood {
  4177. // out_count += item.Count
  4178. // }
  4179. // //如果历史数和当前数据不想等才进行退库出库
  4180. // if out_count != parseIntCount {
  4181. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4182. //
  4183. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4184. // detail := models.AutomaticReduceDetail{
  4185. // WarehouseOutId: 0,
  4186. // WarehouseOutOrderNumber: "",
  4187. // PatientId: p.PatientId,
  4188. // Ctime: time.Now().Unix(),
  4189. // Mtime: 0,
  4190. // Status: 1,
  4191. // RecordTime: p.RecordDate,
  4192. // OrgId: p.UserOrgId,
  4193. // GoodId: p.ProjectId,
  4194. // GoodTypeId: 0,
  4195. // Count: parseIntCount,
  4196. // Type: 0,
  4197. // ProjectId: p.ID,
  4198. // StorehouseId: 0,
  4199. // }
  4200. //
  4201. // service.CreateNewAutoDetail(detail, tx)
  4202. //
  4203. // //查询剩余库存
  4204. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4205. // var sum_count int64
  4206. // for _, item := range goodList {
  4207. // sum_count += item.StockCount
  4208. // }
  4209. //
  4210. // //更新剩余库存
  4211. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4212. //
  4213. // //耗材
  4214. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4215. // }
  4216. //
  4217. // }
  4218. //
  4219. // }
  4220. //
  4221. //}
  4222. //记录日志
  4223. byterequest, _ := json.Marshal(p)
  4224. adviceLog := models.XtDoctorAdviceLog{
  4225. UserOrgId: p.UserOrgId,
  4226. PatientId: p.PatientId,
  4227. AdminUserId: adminInfo.AdminUser.Id,
  4228. Module: 1,
  4229. ErrLog: string(byterequest),
  4230. Status: 1,
  4231. Ctime: time.Now().Unix(),
  4232. Mtime: 0,
  4233. Source: "电脑端新建his项目",
  4234. RecordDate: p.RecordDate,
  4235. }
  4236. service.CreateDoctorAdviceLog(adviceLog)
  4237. projectList = append(projectList, p)
  4238. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4239. //新增或者编辑项目,修改对应的标签数据
  4240. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4241. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4242. var label models.HisLabelPrintInfo
  4243. project, _ := service.GetProjectDetail(p.ProjectId)
  4244. if project.CostClassify == 3 { //类别为检验检查
  4245. if p.TeamId > 0 { //检验检查组套
  4246. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4247. if tempLabel.ID == 0 {
  4248. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4249. label.Number = tempPrescription.PrescriptionNumber
  4250. label.ProjectId = project.ID
  4251. label.Status = 1
  4252. label.IsPrint = 2
  4253. label.DoctorId = info.DoctorId
  4254. label.UserOrgId = p.UserOrgId
  4255. label.PatientId = patient_id
  4256. label.RecordDate = recordDateTime
  4257. label.Ctime = time.Now().Unix()
  4258. label.Mtime = time.Now().Unix()
  4259. label.ItemId = p.TeamId
  4260. label.FeedetlSn = p.FeedetlSn
  4261. label.PProjectId = p.ID
  4262. label.ProjectName = team.ProjectTeam
  4263. label.PatientName = patient.Name
  4264. service.CreateNewHisLabelRecord(&label, tx)
  4265. }
  4266. } else { //单条检验检查项目
  4267. label.Number = tempPrescription.PrescriptionNumber
  4268. label.ProjectId = project.ID
  4269. label.Status = 1
  4270. label.DoctorId = info.DoctorId
  4271. label.UserOrgId = p.UserOrgId
  4272. label.PatientId = patient_id
  4273. label.RecordDate = recordDateTime
  4274. label.IsPrint = 2
  4275. label.Ctime = time.Now().Unix()
  4276. label.Mtime = time.Now().Unix()
  4277. label.FeedetlSn = p.FeedetlSn
  4278. label.PProjectId = p.ID
  4279. label.ItemId = p.TeamId
  4280. label.ProjectName = project.ProjectName
  4281. label.PatientName = patient.Name
  4282. service.CreateNewHisLabelRecord(&label, tx)
  4283. }
  4284. }
  4285. }
  4286. }
  4287. }
  4288. }
  4289. }
  4290. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4291. //
  4292. // //耗材出库
  4293. // if p.Type == 3 {
  4294. //
  4295. // //对比当前数据和历史出库数据
  4296. //
  4297. // historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4298. //
  4299. // historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4300. //
  4301. // nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4302. //
  4303. // //如果当前处方数量大于历史数据,则需要出库
  4304. // if nowCount > historyCount {
  4305. //
  4306. // var cha_count int64
  4307. // cha_count = nowCount - historyCount
  4308. //
  4309. // timeStr := time.Now().Format("2006-01-02")
  4310. // timeArr := strings.Split(timeStr, "-")
  4311. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4312. //
  4313. // total = total + 1
  4314. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4315. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4316. // number = number + total
  4317. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4318. //
  4319. // operation_time := time.Now().Unix()
  4320. // creater := c.GetAdminUserInfo().AdminUser.Id
  4321. //
  4322. // recordDateStr := time.Now().Format("2006-01-02")
  4323. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4324. // nowtime := recordDate.Unix()
  4325. // warehouseOut := models.WarehouseOut{
  4326. // WarehouseOutOrderNumber: warehousing_out_order,
  4327. // OperationTime: operation_time,
  4328. // OrgId: adminInfo.CurrentOrgId,
  4329. // Creater: creater,
  4330. // Ctime: time.Now().Unix(),
  4331. // Status: 1,
  4332. // WarehouseOutTime: nowtime,
  4333. // Type: 1,
  4334. // StorehouseId: storeConfig.StorehouseOutInfo,
  4335. // IsCheck: 1,
  4336. // IsSys: 1,
  4337. // }
  4338. // //查询是否生成出库单
  4339. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4340. // if out.ID == 0 {
  4341. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4342. // }
  4343. //
  4344. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4345. //
  4346. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4347. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4348. //
  4349. // dialyPrepareOne := models.DialysisBeforePrepare{
  4350. // GoodTypeId: goodObj.GoodTypeId,
  4351. // GoodId: p.ProjectId,
  4352. // PatientId: p.PatientId,
  4353. // RecordDate: p.RecordDate,
  4354. // UserOrgId: adminInfo.CurrentOrgId,
  4355. // Count: cha_count,
  4356. // Ctime: time.Now().Unix(),
  4357. // Creater: creater,
  4358. // Status: 1,
  4359. // StorehouseId: houseConfig.StorehouseOutInfo,
  4360. // ProjectId: p.ID,
  4361. // }
  4362. // //出库
  4363. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4364. //
  4365. // }
  4366. //
  4367. // //如果当前处方数量小于历史数据,怎需要退库
  4368. // if nowCount < historyCount {
  4369. //
  4370. // var cha_count int64
  4371. // cha_count = historyCount - nowCount
  4372. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4373. // creater := c.GetAdminUserInfo().AdminUser.Id
  4374. //
  4375. // newPrescriptionProject := &models.HisPrescriptionProject{
  4376. // ID: p.ID,
  4377. // ProjectId: p.ProjectId,
  4378. // Price: p.Price,
  4379. // UserOrgId: p.UserOrgId,
  4380. // Status: 1,
  4381. // Ctime: time.Now().Unix(),
  4382. // Mtime: time.Now().Unix(),
  4383. // PatientId: p.PatientId,
  4384. // HisPatientId: p.HisPatientId,
  4385. // RecordDate: p.RecordDate,
  4386. // PrescriptionId: p.PrescriptionId,
  4387. // Count: p.Count,
  4388. // FeedetlSn: p.FeedetlSn,
  4389. // MedListCodg: p.MedListCodg,
  4390. // SingleDose: p.SingleDose,
  4391. // DeliveryWay: p.DeliveryWay,
  4392. // ExecutionFrequency: p.ExecutionFrequency,
  4393. // Day: p.Day,
  4394. // HisProject: models.HisProject{},
  4395. // GoodInfo: models.GoodInfo{},
  4396. // Remark: p.Remark,
  4397. // Unit: p.Unit,
  4398. // Type: p.Type,
  4399. // Doctor: p.Doctor,
  4400. // ExecutionTime: p.ExecutionTime,
  4401. // ExecutionStaff: p.ExecutionStaff,
  4402. // ExecutionState: p.ExecutionState,
  4403. // CheckTime: p.CheckTime,
  4404. // CheckState: p.CheckState,
  4405. // Checker: p.Checker,
  4406. // StartTime: p.StartTime,
  4407. // TeamId: p.TeamId,
  4408. // XtHisProjectTeam: models.XtHisProjectTeam{},
  4409. // FrequencyType: p.FrequencyType,
  4410. // DayCount: p.DayCount,
  4411. // WeekDay: p.WeekDay,
  4412. // IsCheckTeam: p.IsCheckTeam,
  4413. // HisOrderInfo: models.HisOrderInfo{},
  4414. // ExecutionFrequencyId: p.ExecutionFrequencyId,
  4415. // IsOut: p.IsOut,
  4416. // YbSyncStatus: p.YbSyncStatus,
  4417. // }
  4418. //
  4419. // service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4420. //
  4421. // service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4422. //
  4423. // }
  4424. //
  4425. // if nowCount == historyCount {
  4426. // if historyCount == 0 {
  4427. // recordDateStr := time.Now().Format("2006-01-02")
  4428. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4429. // nowtime := recordDate.Unix()
  4430. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4431. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4432. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4433. // creater := c.GetAdminUserInfo().AdminUser.Id
  4434. // dialyPrepareOne := models.DialysisBeforePrepare{
  4435. // GoodTypeId: goodObj.GoodTypeId,
  4436. // GoodId: p.ProjectId,
  4437. // PatientId: p.PatientId,
  4438. // RecordDate: p.RecordDate,
  4439. // UserOrgId: adminInfo.CurrentOrgId,
  4440. // Count: nowCount,
  4441. // Ctime: time.Now().Unix(),
  4442. // Creater: creater,
  4443. // Status: 1,
  4444. // StorehouseId: houseConfig.StorehouseOutInfo,
  4445. // ProjectId: p.ID,
  4446. // }
  4447. // //出库
  4448. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4449. // }
  4450. // }
  4451. //
  4452. // lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4453. // //查询历史出库数据
  4454. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4455. //
  4456. // var out_count_five int64
  4457. // for _, item := range flowGood {
  4458. // out_count_five += item.Count
  4459. // }
  4460. // parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4461. //
  4462. // //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4463. // if out_count_five != parseIntCount {
  4464. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4465. // detail := models.AutomaticReduceDetail{
  4466. // WarehouseOutId: 0,
  4467. // WarehouseOutOrderNumber: "",
  4468. // PatientId: p.PatientId,
  4469. // Ctime: time.Now().Unix(),
  4470. // Mtime: 0,
  4471. // Status: 1,
  4472. // RecordTime: p.RecordDate,
  4473. // OrgId: p.UserOrgId,
  4474. // GoodId: p.ProjectId,
  4475. // GoodTypeId: 0,
  4476. // Count: parseIntCount,
  4477. // Type: 0,
  4478. // ProjectId: lastHisProject.ID,
  4479. // StorehouseId: 0,
  4480. // }
  4481. //
  4482. // service.CreateNewAutoDetail(detail, tx)
  4483. // }
  4484. // // //查询耗材最后一次出库记录
  4485. // // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4486. // // //查询默认出库仓库库存
  4487. // // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4488. // // if len(wareOut) > 0 {
  4489. // //
  4490. // // for _, it := range wareOut {
  4491. // // //回退库存
  4492. // // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4493. // //
  4494. // // //删除出库记录
  4495. // // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4496. // //
  4497. // // }
  4498. // // }
  4499. // //
  4500. // // timeStr := time.Now().Format("2006-01-02")
  4501. // // timeArr := strings.Split(timeStr, "-")
  4502. // // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4503. // //
  4504. // // total = total + 1
  4505. // // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4506. // // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4507. // // number = number + total
  4508. // // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4509. // //
  4510. // // operation_time := time.Now().Unix()
  4511. // // creater := c.GetAdminUserInfo().AdminUser.Id
  4512. // //
  4513. // // recordDateStr := time.Now().Format("2006-01-02")
  4514. // // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4515. // // nowtime := recordDate.Unix()
  4516. // // warehouseOut := models.WarehouseOut{
  4517. // // WarehouseOutOrderNumber: warehousing_out_order,
  4518. // // OperationTime: operation_time,
  4519. // // OrgId: adminInfo.CurrentOrgId,
  4520. // // Creater: creater,
  4521. // // Ctime: time.Now().Unix(),
  4522. // // Status: 1,
  4523. // // WarehouseOutTime: nowtime,
  4524. // // Type: 1,
  4525. // // StorehouseId: storeConfig.StorehouseOutInfo,
  4526. // // IsCheck: 1,
  4527. // // IsSys: 1,
  4528. // // }
  4529. // // //查询是否生成出库单
  4530. // // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4531. // // if out.ID == 0 {
  4532. // // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4533. // // }
  4534. // //
  4535. // // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4536. // //
  4537. // // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4538. // // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4539. // //
  4540. // // dialyPrepareOne := models.DialysisBeforePrepare{
  4541. // // GoodTypeId: goodObj.GoodTypeId,
  4542. // // GoodId: p.ProjectId,
  4543. // // PatientId: p.PatientId,
  4544. // // RecordDate: p.RecordDate,
  4545. // // UserOrgId: adminInfo.CurrentOrgId,
  4546. // // Count: parseIntCount,
  4547. // // Ctime: time.Now().Unix(),
  4548. // // Creater: creater,
  4549. // // Status: 1,
  4550. // // StorehouseId: houseConfig.StorehouseOutInfo,
  4551. // // ProjectId: lastHisProject.ID,
  4552. // // }
  4553. // // //判断是否是零用耗材(非零用)
  4554. // // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4555. // //
  4556. // // //查询历史出库数据
  4557. // // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4558. // // var out_count int64
  4559. // // for _, item := range flowGood {
  4560. // // out_count += item.Count
  4561. // // }
  4562. // // //如果历史数和当前数据不想等才进行退库出库
  4563. // // if out_count != parseIntCount {
  4564. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4565. // //
  4566. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4567. // // detail := models.AutomaticReduceDetail{
  4568. // // WarehouseOutId: 0,
  4569. // // WarehouseOutOrderNumber: "",
  4570. // // PatientId: p.PatientId,
  4571. // // Ctime: time.Now().Unix(),
  4572. // // Mtime: 0,
  4573. // // Status: 1,
  4574. // // RecordTime: p.RecordDate,
  4575. // // OrgId: p.UserOrgId,
  4576. // // GoodId: p.ProjectId,
  4577. // // GoodTypeId: 0,
  4578. // // Count: parseIntCount,
  4579. // // Type: 0,
  4580. // // ProjectId: lastHisProject.ID,
  4581. // // StorehouseId: 0,
  4582. // // }
  4583. // //
  4584. // // service.CreateNewAutoDetail(detail, tx)
  4585. // //
  4586. // // //查询剩余库存
  4587. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4588. // // var sum_count int64
  4589. // // for _, item := range goodList {
  4590. // // sum_count += item.StockCount
  4591. // // }
  4592. // //
  4593. // // //更新剩余库存
  4594. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4595. // //
  4596. // // //耗材
  4597. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4598. // //
  4599. // // }
  4600. // // //判断是否是零用耗材(零用但是是出库耗材)
  4601. // // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4602. // //
  4603. // // //查询历史出库数据
  4604. // // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4605. // // var out_count int64
  4606. // // for _, item := range flowGood {
  4607. // // out_count += item.Count
  4608. // // }
  4609. // // //如果历史数和当前数据不想等才进行退库出库
  4610. // // if out_count != parseIntCount {
  4611. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4612. // //
  4613. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4614. // // detail := models.AutomaticReduceDetail{
  4615. // // WarehouseOutId: 0,
  4616. // // WarehouseOutOrderNumber: "",
  4617. // // PatientId: p.PatientId,
  4618. // // Ctime: time.Now().Unix(),
  4619. // // Mtime: 0,
  4620. // // Status: 1,
  4621. // // RecordTime: p.RecordDate,
  4622. // // OrgId: p.UserOrgId,
  4623. // // GoodId: p.ProjectId,
  4624. // // GoodTypeId: 0,
  4625. // // Count: parseIntCount,
  4626. // // Type: 0,
  4627. // // ProjectId: p.ID,
  4628. // // StorehouseId: 0,
  4629. // // }
  4630. // //
  4631. // // service.CreateNewAutoDetail(detail, tx)
  4632. // //
  4633. // // //查询剩余库存
  4634. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4635. // // var sum_count int64
  4636. // // for _, item := range goodList {
  4637. // // sum_count += item.StockCount
  4638. // // }
  4639. // //
  4640. // // //更新剩余库存
  4641. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4642. // //
  4643. // // //耗材
  4644. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4645. // // }
  4646. // //
  4647. // // }
  4648. // //
  4649. // // }
  4650. // //
  4651. // //}
  4652. //
  4653. // //记录日志
  4654. // byterequest, _ := json.Marshal(p)
  4655. // adviceLog := models.XtDoctorAdviceLog{
  4656. // UserOrgId: p.UserOrgId,
  4657. // PatientId: p.PatientId,
  4658. // AdminUserId: adminInfo.AdminUser.Id,
  4659. // Module: 1,
  4660. // ErrLog: string(byterequest),
  4661. // Status: 1,
  4662. // Ctime: time.Now().Unix(),
  4663. // Mtime: 0,
  4664. // Source: "电脑端新建his项目",
  4665. // RecordDate: p.RecordDate,
  4666. // }
  4667. // service.CreateDoctorAdviceLog(adviceLog)
  4668. //
  4669. // projectList = append(projectList, p)
  4670. //
  4671. // if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4672. // //新增或者编辑项目,修改对应的标签数据
  4673. // labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4674. // if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4675. // var label models.HisLabelPrintInfo
  4676. // project, _ := service.GetProjectDetail(p.ProjectId)
  4677. // if project.CostClassify == 3 { //类别为检验检查
  4678. // if p.TeamId > 0 { //检验检查组套
  4679. // tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4680. // if tempLabel.ID == 0 {
  4681. // team, _ := service.GetProjectTeamDetail(p.TeamId)
  4682. // label.Number = tempPrescription.PrescriptionNumber
  4683. // label.ProjectId = project.ID
  4684. // label.Status = 1
  4685. // label.IsPrint = 2
  4686. // label.DoctorId = info.DoctorId
  4687. // label.UserOrgId = p.UserOrgId
  4688. // label.PatientId = patient_id
  4689. // label.RecordDate = recordDateTime
  4690. // label.Ctime = time.Now().Unix()
  4691. // label.Mtime = time.Now().Unix()
  4692. // label.ItemId = p.TeamId
  4693. // label.FeedetlSn = p.FeedetlSn
  4694. // label.PProjectId = p.ID
  4695. // label.ProjectName = team.ProjectTeam
  4696. // label.PatientName = patient.Name
  4697. // service.CreateNewHisLabelRecord(&label, tx)
  4698. // }
  4699. // } else { //单条检验检查项目
  4700. // label.Number = tempPrescription.PrescriptionNumber
  4701. // label.ProjectId = project.ID
  4702. // label.Status = 1
  4703. // label.DoctorId = info.DoctorId
  4704. // label.UserOrgId = p.UserOrgId
  4705. // label.PatientId = patient_id
  4706. // label.RecordDate = recordDateTime
  4707. // label.IsPrint = 2
  4708. // label.Ctime = time.Now().Unix()
  4709. // label.Mtime = time.Now().Unix()
  4710. // label.FeedetlSn = p.FeedetlSn
  4711. // label.PProjectId = p.ID
  4712. // label.ItemId = p.TeamId
  4713. // label.ProjectName = project.ProjectName
  4714. // label.PatientName = patient.Name
  4715. // service.CreateNewHisLabelRecord(&label, tx)
  4716. // }
  4717. // }
  4718. // }
  4719. // }
  4720. //
  4721. // }
  4722. //}
  4723. }
  4724. //插入检验数据
  4725. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4726. //新增或者编辑项目,修改对应的标签数据
  4727. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4728. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4729. var label models.HisLabelPrintInfo
  4730. project, _ := service.GetProjectDetail(p.ProjectId)
  4731. if project.CostClassify == 3 { //类别为检验检查
  4732. if p.TeamId > 0 { //检验检查组套
  4733. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4734. if tempLabel.ID == 0 {
  4735. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4736. label.Number = tempPrescription.PrescriptionNumber
  4737. label.ProjectId = project.ID
  4738. label.Status = 1
  4739. label.IsPrint = 2
  4740. label.DoctorId = info.DoctorId
  4741. label.UserOrgId = p.UserOrgId
  4742. label.PatientId = patient_id
  4743. label.RecordDate = recordDateTime
  4744. label.Ctime = time.Now().Unix()
  4745. label.Mtime = time.Now().Unix()
  4746. label.ItemId = p.TeamId
  4747. label.FeedetlSn = p.FeedetlSn
  4748. label.PProjectId = p.ID
  4749. label.ProjectName = team.ProjectTeam
  4750. label.PatientName = patient.Name
  4751. service.CreateHisLabelRecord(&label)
  4752. }
  4753. } else { //单条检验检查项目
  4754. label.Number = tempPrescription.PrescriptionNumber
  4755. label.ProjectId = project.ID
  4756. label.Status = 1
  4757. label.DoctorId = info.DoctorId
  4758. label.UserOrgId = p.UserOrgId
  4759. label.PatientId = patient_id
  4760. label.RecordDate = recordDateTime
  4761. label.IsPrint = 2
  4762. label.Ctime = time.Now().Unix()
  4763. label.Mtime = time.Now().Unix()
  4764. label.FeedetlSn = p.FeedetlSn
  4765. label.PProjectId = p.ID
  4766. label.ItemId = p.TeamId
  4767. label.ProjectName = project.ProjectName
  4768. label.PatientName = patient.Name
  4769. service.CreateHisLabelRecord(&label)
  4770. }
  4771. }
  4772. }
  4773. }
  4774. service.CreateNewHisProjectTwo(&p, tx)
  4775. var randNum int
  4776. randNum = rand.Intn(10000) + 1000
  4777. timestamp := time.Now().Unix()
  4778. tempTime := time.Unix(timestamp, 0)
  4779. timeFormat := tempTime.Format("20060102150405")
  4780. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4781. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4782. if goodBase.ID > 0 {
  4783. tx.Rollback()
  4784. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4785. return
  4786. }
  4787. service.CreateNewHisProjectTwo(&p, tx)
  4788. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4789. //查询剩余库存
  4790. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4791. var sum_count int64
  4792. for _, item := range goodList {
  4793. sum_count += item.StockCount
  4794. }
  4795. //更新剩余库存
  4796. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4797. //耗材
  4798. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4799. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4800. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4801. if len(outInfoTwo) > 0 {
  4802. for _, item := range outInfoTwo {
  4803. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4804. }
  4805. }
  4806. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4807. if len(drugAutoDetail) > 0 {
  4808. for _, item := range drugAutoDetail {
  4809. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4810. }
  4811. }
  4812. tx.Commit()
  4813. }
  4814. }
  4815. }
  4816. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4817. // addition := items["addition"].([]interface{})
  4818. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4819. // ctime := time.Now().Unix()
  4820. // mtime := ctime
  4821. // if len(addition) > 0 {
  4822. // for _, item := range addition {
  4823. // var s models.HisAdditionalCharge
  4824. // s.PrescriptionId = tempPrescription.ID
  4825. // s.Status = 1
  4826. // s.UserOrgId = adminInfo.CurrentOrgId
  4827. // s.RecordDate = recordDateTime
  4828. // s.CreatedTime = ctime
  4829. // s.UpdatedTime = mtime
  4830. // s.PatientId = patient_id
  4831. // s.HisPatientId = his_patient_id
  4832. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4833. // if errcode > 0 {
  4834. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4835. // return
  4836. // }
  4837. // service.CreateAdditionalCharge(&s)
  4838. // var randNum int
  4839. // randNum = rand.Intn(10000) + 1000
  4840. // timestamp := time.Now().Unix()
  4841. // tempTime := time.Unix(timestamp, 0)
  4842. // timeFormat := tempTime.Format("20060102150405")
  4843. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4844. // service.CreateAdditionalCharge(&s)
  4845. //
  4846. // }
  4847. // }
  4848. //}
  4849. }
  4850. }
  4851. }
  4852. tx.Commit()
  4853. if err == nil {
  4854. c.ServeSuccessJSON(map[string]interface{}{
  4855. "msg": "保存成功",
  4856. })
  4857. return
  4858. } else {
  4859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4860. return
  4861. }
  4862. } else {
  4863. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4864. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4865. var tempPrescription *models.HisPrescription
  4866. if len(prescriptions) > 0 {
  4867. for _, item := range prescriptions {
  4868. items := item.(map[string]interface{})
  4869. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4870. utils.ErrorLog("id")
  4871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4872. return
  4873. }
  4874. id := int64(items["id"].(float64))
  4875. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4876. tempPrescription = &new_prescription
  4877. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4878. utils.ErrorLog("type")
  4879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4880. return
  4881. }
  4882. types := int64(items["type"].(float64))
  4883. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4884. utils.ErrorLog("med_type")
  4885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4886. return
  4887. }
  4888. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4889. if med_type == "0" {
  4890. med_type = "14"
  4891. }
  4892. //if order_status == 0 {
  4893. // order_status = 1
  4894. //}
  4895. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4896. // utils.ErrorLog("diagnoses")
  4897. //}
  4898. diagnoses, _ := items["diagnoses"].(string)
  4899. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4900. utils.ErrorLog("pre_time")
  4901. }
  4902. preTime, _ := items["pre_time"].(string)
  4903. timeLayout := "2006-01-02"
  4904. loc, _ := time.LoadLocation("Local")
  4905. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4906. //result := strings.Split(preTime, " ")
  4907. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4908. if err != nil {
  4909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4910. return
  4911. }
  4912. pTime := theTime2.Unix()
  4913. ctime := time.Now().Unix()
  4914. if tempPrescription.ID == 0 {
  4915. prescription := &models.HisPrescription{
  4916. ID: 0,
  4917. PatientId: patient_id,
  4918. UserOrgId: adminInfo.CurrentOrgId,
  4919. RecordDate: recordDateTime,
  4920. Ctime: ctime,
  4921. Mtime: ctime,
  4922. Type: types,
  4923. Modifier: adminInfo.AdminUser.Id,
  4924. Creator: adminInfo.AdminUser.Id,
  4925. Status: 1,
  4926. Doctor: role.UserName,
  4927. HisPatientId: his_patient_id,
  4928. OrderStatus: 1,
  4929. BatchNumber: "",
  4930. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4931. PreTime: pTime,
  4932. PType: p_type,
  4933. MedType: med_type,
  4934. Diagnose: diagnoses,
  4935. }
  4936. tempPrescription = prescription
  4937. service.SaveHisPrescription(tempPrescription)
  4938. redis := service.RedisClient()
  4939. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4940. redis.Set(key, "", time.Second)
  4941. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4942. redis.Set(keyOne, "", time.Second)
  4943. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4944. redis.Set(keySeven, "", time.Second)
  4945. defer redis.Close()
  4946. } else {
  4947. tempPrescription.ID = id
  4948. tempPrescription.Type = types
  4949. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4950. tempPrescription.Mtime = time.Now().Unix()
  4951. tempPrescription.Doctor = role.UserName
  4952. //tempPrescription.OrderStatus = order_status
  4953. tempPrescription.PreTime = pTime
  4954. tempPrescription.MedType = med_type
  4955. tempPrescription.Diagnose = diagnoses
  4956. service.SaveHisPrescription(tempPrescription)
  4957. redis := service.RedisClient()
  4958. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4959. redis.Set(key, "", time.Second)
  4960. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4961. redis.Set(keyOne, "", time.Second)
  4962. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4963. redis.Set(keySeven, "", time.Second)
  4964. defer redis.Close()
  4965. }
  4966. //service.SaveHisPrescription(prescription)
  4967. //更改患者挂号状态
  4968. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4969. fmt.Println("更改失败", err2)
  4970. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4971. advices := items["advices"].([]interface{})
  4972. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4973. groupNo := int64(0)
  4974. if len(advices) > 0 {
  4975. for _, advice := range advices {
  4976. var s models.HisDoctorAdviceInfo
  4977. s.PrescriptionId = tempPrescription.ID
  4978. s.AdviceType = 2
  4979. s.AdviceDoctor = doctor_id
  4980. s.StopState = 2
  4981. s.ExecutionState = 2
  4982. s.AdviceDate = theTime3.Unix()
  4983. s.Status = 1
  4984. s.UserOrgId = adminInfo.CurrentOrgId
  4985. s.RecordDate = theTime3.Unix()
  4986. s.StartTime = tempPrescription.PreTime
  4987. s.Groupno = groupNo
  4988. s.PatientId = patient_id
  4989. s.HisPatientId = his_patient_id
  4990. s.StartTime = pTime
  4991. s.IsSettle = 2
  4992. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4993. if errcode > 0 {
  4994. c.ServeFailJSONWithSGJErrorCode(errcode)
  4995. return
  4996. }
  4997. s.StartTime = pTime
  4998. var total_count int64 //处方总库存
  4999. //查询改药品信息
  5000. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  5001. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  5002. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5003. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5004. total_count += prescribingNumberSeven * medical.MinNumber
  5005. }
  5006. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5007. total_count += prescribingNumberSeven
  5008. }
  5009. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  5010. total_count += prescribingNumberSeven
  5011. }
  5012. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5013. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5014. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5015. if s.Price != lastWarehouse.RetailPrice {
  5016. s.Price = lastWarehouse.RetailPrice
  5017. }
  5018. if s.Price == 0 {
  5019. if lastWarehouse.ID == 0 {
  5020. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  5021. s.Price = lastWarehouseTwo.RetailPrice
  5022. }
  5023. }
  5024. }
  5025. if adminInfo.CurrentOrgId != 10206 {
  5026. if s.ID == 0 {
  5027. //查询改药品是否已经停用
  5028. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  5029. if base.ID > 0 {
  5030. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  5031. return
  5032. }
  5033. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  5034. if drugMedical.SumCount == 0 {
  5035. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  5036. return
  5037. }
  5038. }
  5039. }
  5040. //赤峰
  5041. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  5042. drug, _ := service.GetDrugByGoodId(s.DrugId)
  5043. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  5044. if info.RetailPrice > 0 {
  5045. if s.DeliveryWay == "口服" {
  5046. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5047. s.Price = drug.RetailPrice
  5048. }
  5049. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5050. s.Price = info.RetailPrice
  5051. }
  5052. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5053. s.Price = info.RetailPrice
  5054. }
  5055. }
  5056. }
  5057. }
  5058. service.CreateHisDoctorAdvice(&s)
  5059. //记录日志
  5060. byterequest, _ := json.Marshal(s)
  5061. adviceLog := models.XtDoctorAdviceLog{
  5062. UserOrgId: s.UserOrgId,
  5063. PatientId: s.PatientId,
  5064. AdminUserId: adminInfo.AdminUser.Id,
  5065. Module: 1,
  5066. ErrLog: string(byterequest),
  5067. Status: 1,
  5068. Ctime: time.Now().Unix(),
  5069. Mtime: 0,
  5070. Source: "电脑端新建his医嘱",
  5071. RecordDate: s.AdviceDate,
  5072. }
  5073. service.CreateDoctorAdviceLog(adviceLog)
  5074. //存储切片中
  5075. adviceList = append(adviceList, s)
  5076. redis := service.RedisClient()
  5077. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5078. redis.Set(key, "", time.Second)
  5079. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5080. redis.Set(keyOne, "", time.Second)
  5081. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5082. redis.Set(keySeven, "", time.Second)
  5083. var randNum int
  5084. randNum = rand.Intn(10000) + 1000
  5085. timestamp := time.Now().Unix()
  5086. tempTime := time.Unix(timestamp, 0)
  5087. timeFormat := tempTime.Format("20060102150405")
  5088. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  5089. service.CreateHisDoctorAdvice(&s)
  5090. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5091. redis.Set(keySix, "", time.Second)
  5092. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5093. redis.Set(keyFive, "", time.Second)
  5094. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5095. redis.Set(keyEight, "", time.Second)
  5096. defer redis.Close()
  5097. }
  5098. }
  5099. }
  5100. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5101. projects := items["project"].([]interface{})
  5102. if len(projects) > 0 {
  5103. for _, project := range projects {
  5104. var p models.HisPrescriptionProject
  5105. p.PrescriptionId = tempPrescription.ID
  5106. p.PatientId = patient_id
  5107. p.RecordDate = theTime3.Unix()
  5108. p.Doctor = doctor_id
  5109. p.UserOrgId = adminInfo.CurrentOrgId
  5110. p.HisPatientId = his_patient_id
  5111. p.Status = 1
  5112. p.StartTime = pTime
  5113. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  5114. if errcode > 0 {
  5115. c.ServeFailJSONWithSGJErrorCode(errcode)
  5116. return
  5117. }
  5118. if p.ID == 0 {
  5119. p.IsOut = 2
  5120. }
  5121. if p.ID > 0 {
  5122. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5123. p.IsOut = projectDetail.IsOut
  5124. }
  5125. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5126. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5127. if p.Type == 3 {
  5128. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5129. if p.Price != lastWarehouse.PackingPrice {
  5130. p.Price = lastWarehouse.PackingPrice
  5131. }
  5132. if p.Price == 0 {
  5133. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5134. p.Price = lastWarehouseTwo.PackingPrice
  5135. }
  5136. if p.Unit == "" {
  5137. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5138. p.Unit = goodInfoOne.PackingUnit
  5139. }
  5140. }
  5141. }
  5142. if adminInfo.CurrentOrgId != 10206 {
  5143. if p.Type == 3 {
  5144. if p.ID == 0 {
  5145. //查询该耗材是否停用
  5146. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5147. //表示该耗材已经停用,不能保存
  5148. if goodInfoSeven.ID == 0 {
  5149. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5150. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5151. return
  5152. }
  5153. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5154. if goodInfoOne.SumCount == 0 {
  5155. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5156. return
  5157. }
  5158. }
  5159. }
  5160. }
  5161. service.CreateHisProjectTwo(&p)
  5162. //记录日志
  5163. byterequest, _ := json.Marshal(p)
  5164. adviceLog := models.XtDoctorAdviceLog{
  5165. UserOrgId: p.UserOrgId,
  5166. PatientId: p.PatientId,
  5167. AdminUserId: adminInfo.AdminUser.Id,
  5168. Module: 1,
  5169. ErrLog: string(byterequest),
  5170. Status: 1,
  5171. Ctime: time.Now().Unix(),
  5172. Mtime: 0,
  5173. Source: "电脑端新建his项目",
  5174. RecordDate: p.RecordDate,
  5175. }
  5176. service.CreateDoctorAdviceLog(adviceLog)
  5177. projectList = append(projectList, p)
  5178. var randNum int
  5179. randNum = rand.Intn(10000) + 1000
  5180. timestamp := time.Now().Unix()
  5181. tempTime := time.Unix(timestamp, 0)
  5182. timeFormat := tempTime.Format("20060102150405")
  5183. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  5184. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  5185. //新增或者编辑项目,修改对应的标签数据
  5186. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  5187. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  5188. var label models.HisLabelPrintInfo
  5189. project, _ := service.GetProjectDetail(p.ProjectId)
  5190. if project.CostClassify == 3 { //类别为检验检查
  5191. if p.TeamId > 0 { //检验检查组套
  5192. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  5193. if tempLabel.ID == 0 {
  5194. team, _ := service.GetProjectTeamDetail(p.TeamId)
  5195. label.Number = tempPrescription.PrescriptionNumber
  5196. label.ProjectId = project.ID
  5197. label.Status = 1
  5198. label.IsPrint = 2
  5199. label.DoctorId = info.DoctorId
  5200. label.UserOrgId = p.UserOrgId
  5201. label.PatientId = patient_id
  5202. label.RecordDate = recordDateTime
  5203. label.Ctime = time.Now().Unix()
  5204. label.Mtime = time.Now().Unix()
  5205. label.ItemId = p.TeamId
  5206. label.FeedetlSn = p.FeedetlSn
  5207. label.PProjectId = p.ID
  5208. label.ProjectName = team.ProjectTeam
  5209. label.PatientName = patient.Name
  5210. service.CreateHisLabelRecord(&label)
  5211. }
  5212. } else { //单条检验检查项目
  5213. label.Number = tempPrescription.PrescriptionNumber
  5214. label.ProjectId = project.ID
  5215. label.Status = 1
  5216. label.DoctorId = info.DoctorId
  5217. label.UserOrgId = p.UserOrgId
  5218. label.PatientId = patient_id
  5219. label.RecordDate = recordDateTime
  5220. label.IsPrint = 2
  5221. label.Ctime = time.Now().Unix()
  5222. label.Mtime = time.Now().Unix()
  5223. label.FeedetlSn = p.FeedetlSn
  5224. label.PProjectId = p.ID
  5225. label.ItemId = p.TeamId
  5226. label.ProjectName = project.ProjectName
  5227. label.PatientName = patient.Name
  5228. service.CreateHisLabelRecord(&label)
  5229. }
  5230. }
  5231. }
  5232. }
  5233. service.SaveHisProjectTwo(&p)
  5234. }
  5235. }
  5236. }
  5237. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5238. // addition := items["addition"].([]interface{})
  5239. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5240. // ctime := time.Now().Unix()
  5241. // mtime := ctime
  5242. // if len(addition) > 0 {
  5243. // for _, item := range addition {
  5244. // var s models.HisAdditionalCharge
  5245. // s.PrescriptionId = tempPrescription.ID
  5246. // s.Status = 1
  5247. // s.UserOrgId = adminInfo.CurrentOrgId
  5248. // s.RecordDate = recordDateTime
  5249. // s.CreatedTime = ctime
  5250. // s.UpdatedTime = mtime
  5251. // s.PatientId = patient_id
  5252. // s.HisPatientId = his_patient_id
  5253. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5254. // if errcode > 0 {
  5255. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5256. // return
  5257. // }
  5258. // service.CreateAdditionalCharge(&s)
  5259. // var randNum int
  5260. // randNum = rand.Intn(10000) + 1000
  5261. // timestamp := time.Now().Unix()
  5262. // tempTime := time.Unix(timestamp, 0)
  5263. // timeFormat := tempTime.Format("20060102150405")
  5264. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5265. // service.CreateAdditionalCharge(&s)
  5266. //
  5267. // }
  5268. // }
  5269. //}
  5270. }
  5271. }
  5272. //查询今日该患者开的药品处方
  5273. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5274. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5275. //药品出库
  5276. if drugOutConfig.IsOpen == 1 {
  5277. for _, item := range hisdoctorlist {
  5278. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5279. // 查询该药品最后一次出库记录
  5280. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5281. if len(druginfo) > 0 {
  5282. //回退库存
  5283. for _, it := range druginfo {
  5284. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5285. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5286. }
  5287. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5288. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5289. }
  5290. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5291. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5292. }
  5293. }
  5294. }
  5295. //删除记录
  5296. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5297. //查询最后一次数据
  5298. if drugOutConfig.IsOpen == 1 {
  5299. //出库
  5300. if drug.IsUse == 2 {
  5301. creater := adminInfo.AdminUser.Id
  5302. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5303. }
  5304. //更新字典里面的库存
  5305. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5306. var sum_count int64
  5307. for _, its := range stockInfo {
  5308. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5309. if its.MaxUnit == baseDrug.MaxUnit {
  5310. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5311. }
  5312. sum_count += its.StockMaxNumber + its.StockMinNumber
  5313. }
  5314. //更新基础库存
  5315. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5316. //剩余库存
  5317. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5318. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5319. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5320. }
  5321. }
  5322. }
  5323. //耗材保存处方出库
  5324. if goodOutConfig.IsOpen == 1 {
  5325. //查询今日耗材出库数量
  5326. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5327. for _, item := range hisgoodlist {
  5328. //查询历史出库数据
  5329. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5330. var out_count_five int64
  5331. for _, item := range flowGood {
  5332. out_count_five += item.Count
  5333. }
  5334. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5335. if out_count_five != parseIntCount {
  5336. //查询耗材最后一次出库记录
  5337. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5338. //查询默认出库仓库库存
  5339. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5340. if len(wareOut) > 0 {
  5341. for _, it := range wareOut {
  5342. //回退库存
  5343. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5344. //删除出库记录
  5345. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5346. }
  5347. }
  5348. timeStr := time.Now().Format("2006-01-02")
  5349. timeArr := strings.Split(timeStr, "-")
  5350. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5351. total = total + 1
  5352. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5353. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5354. number = number + total
  5355. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5356. operation_time := time.Now().Unix()
  5357. creater := c.GetAdminUserInfo().AdminUser.Id
  5358. recordDateStr := time.Now().Format("2006-01-02")
  5359. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5360. nowtime := recordDate.Unix()
  5361. warehouseOut := models.WarehouseOut{
  5362. WarehouseOutOrderNumber: warehousing_out_order,
  5363. OperationTime: operation_time,
  5364. OrgId: adminInfo.CurrentOrgId,
  5365. Creater: creater,
  5366. Ctime: time.Now().Unix(),
  5367. Status: 1,
  5368. WarehouseOutTime: nowtime,
  5369. Type: 1,
  5370. StorehouseId: storeConfig.StorehouseOutInfo,
  5371. IsCheck: 1,
  5372. IsSys: 1,
  5373. }
  5374. //查询是否生成出库单
  5375. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5376. if out.ID == 0 {
  5377. service.AddSigleWarehouseOutOne(&warehouseOut)
  5378. }
  5379. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5380. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5381. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5382. dialyPrepareOne := models.DialysisBeforePrepare{
  5383. GoodTypeId: goodObj.GoodTypeId,
  5384. GoodId: item.ProjectId,
  5385. PatientId: item.PatientId,
  5386. RecordDate: item.RecordDate,
  5387. UserOrgId: adminInfo.CurrentOrgId,
  5388. Count: parseIntCount,
  5389. Ctime: time.Now().Unix(),
  5390. Creater: creater,
  5391. Status: 1,
  5392. StorehouseId: houseConfig.StorehouseOutInfo,
  5393. ProjectId: item.ID,
  5394. }
  5395. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5396. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5397. //查询历史出库数据
  5398. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5399. var out_count int64
  5400. for _, item := range flowGood {
  5401. out_count += item.Count
  5402. }
  5403. //如果历史数和当前数据不想等才进行退库出库
  5404. if out_count != parseIntCount {
  5405. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5406. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5407. detail := models.AutomaticReduceDetail{
  5408. WarehouseOutId: 0,
  5409. WarehouseOutOrderNumber: "",
  5410. PatientId: item.PatientId,
  5411. Ctime: time.Now().Unix(),
  5412. Mtime: 0,
  5413. Status: 1,
  5414. RecordTime: item.RecordDate,
  5415. OrgId: item.UserOrgId,
  5416. GoodId: item.ProjectId,
  5417. GoodTypeId: 0,
  5418. Count: parseIntCount,
  5419. Type: 0,
  5420. ProjectId: item.ID,
  5421. StorehouseId: 0,
  5422. }
  5423. service.CreateAutoDetail(detail)
  5424. //查询剩余库存
  5425. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5426. var sum_count int64
  5427. for _, item := range goodList {
  5428. sum_count += item.StockCount
  5429. }
  5430. //更新剩余库存
  5431. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5432. //耗材
  5433. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5434. }
  5435. }
  5436. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5437. //查询历史出库数据
  5438. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5439. var out_count int64
  5440. for _, item := range flowGood {
  5441. out_count += item.Count
  5442. }
  5443. //如果历史数和当前数据不想等才进行退库出库
  5444. if out_count != parseIntCount {
  5445. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5446. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5447. detail := models.AutomaticReduceDetail{
  5448. WarehouseOutId: 0,
  5449. WarehouseOutOrderNumber: "",
  5450. PatientId: item.PatientId,
  5451. Ctime: time.Now().Unix(),
  5452. Mtime: 0,
  5453. Status: 1,
  5454. RecordTime: item.RecordDate,
  5455. OrgId: item.UserOrgId,
  5456. GoodId: item.ProjectId,
  5457. GoodTypeId: 0,
  5458. Count: parseIntCount,
  5459. Type: 0,
  5460. ProjectId: item.ID,
  5461. StorehouseId: 0,
  5462. }
  5463. service.CreateAutoDetail(detail)
  5464. //查询剩余库存
  5465. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5466. var sum_count int64
  5467. for _, item := range goodList {
  5468. sum_count += item.StockCount
  5469. }
  5470. //更新剩余库存
  5471. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5472. //耗材
  5473. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5474. }
  5475. }
  5476. }
  5477. }
  5478. }
  5479. ////同步到自备药
  5480. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5481. if selfPrescriptionOpen.IsOpen == 1 {
  5482. timeStr := time.Now().Format("2006-01-02")
  5483. timeArr := strings.Split(timeStr, "-")
  5484. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5485. total = total + 1
  5486. operation_time := time.Now().Unix()
  5487. creater := adminInfo.AdminUser.Id
  5488. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5489. warehousing := models.XtSelfDrugWarehouse{
  5490. WarehousingOrder: warehousing_order,
  5491. OperationTime: operation_time,
  5492. OrgId: adminInfo.CurrentOrgId,
  5493. Creater: creater,
  5494. Ctime: time.Now().Unix(),
  5495. Status: 1,
  5496. WarehousingTime: recordDateTime,
  5497. Type: 0,
  5498. StorehouseId: 0,
  5499. IsCheck: 1,
  5500. PatientId: patient_id,
  5501. IsSys: 1,
  5502. }
  5503. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5504. if selfDrugWarehouse.ID == 0 {
  5505. service.AddSelfDrugWarehouse(&warehousing, tx)
  5506. }
  5507. if selfDrugWarehouse.ID > 0 {
  5508. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5509. }
  5510. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5511. fmt.Println(info)
  5512. for _, item := range hisdoctorlist {
  5513. //查询该病人的该药品是否已经入库
  5514. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5515. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5516. var in_count int64
  5517. if len(selfdruginfo) > 0 {
  5518. for _, item := range selfdruginfo {
  5519. var in_count_one int64
  5520. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5521. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5522. }
  5523. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5524. in_count_one = item.WarehousingCount
  5525. }
  5526. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5527. in_count_one = item.WarehousingCount
  5528. }
  5529. in_count += in_count_one
  5530. }
  5531. }
  5532. if selfBasedrug.IsSelfDrug == 1 {
  5533. var total_count int64
  5534. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5535. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5536. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5537. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5538. }
  5539. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5540. total_count += prescribingNumberSeven
  5541. }
  5542. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5543. total_count += prescribingNumberSeven
  5544. }
  5545. //入库
  5546. if total_count > in_count {
  5547. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5548. WarehousingOrder: warehousing_order,
  5549. WarehousingId: info.ID,
  5550. DrugId: item.DrugId,
  5551. Number: "",
  5552. ProductDate: 0,
  5553. ExpiryDate: 0,
  5554. WarehousingCount: total_count - in_count,
  5555. WarehouseingUnit: selfBasedrug.MinUnit,
  5556. Price: 0,
  5557. TotalPrice: 0,
  5558. Status: 1,
  5559. Ctime: time.Now().Unix(),
  5560. Remark: "",
  5561. OrgId: adminInfo.CurrentOrgId,
  5562. Type: 0,
  5563. Manufacturer: selfBasedrug.Manufacturer,
  5564. Dealer: selfBasedrug.Dealer,
  5565. StockMaxNumber: total_count - in_count,
  5566. RetailTotalPrice: 0,
  5567. BatchNumber: "",
  5568. MaxUnit: selfBasedrug.MinUnit,
  5569. MinUnit: selfBasedrug.MinUnit,
  5570. RetailPrice: 0,
  5571. StorehouseId: 0,
  5572. IsCheck: 1,
  5573. StockMinNumber: 0,
  5574. PatientId: patient_id,
  5575. IsSys: 1,
  5576. RecordDate: item.RecordDate,
  5577. AdviceId: item.ID,
  5578. }
  5579. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5580. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5581. Creator := adminInfo.AdminUser.Id
  5582. //查询默认仓库剩余多少库存
  5583. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5584. var sum_count int64
  5585. for _, it := range list {
  5586. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5587. if it.MaxUnit == baseDrug.MaxUnit {
  5588. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5589. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5590. }
  5591. sum_count += it.StockMaxNumber + it.StockMinNumber
  5592. }
  5593. flow := &models.XtSelfDrugFlow{
  5594. WarehousingId: info.ID,
  5595. DrugId: item.DrugId,
  5596. Number: "",
  5597. BatchNumber: "",
  5598. Count: total_count - in_count,
  5599. UserOrgId: adminInfo.CurrentOrgId,
  5600. PatientId: item.PatientId,
  5601. SystemTime: time.Now().Unix(),
  5602. ConsumableType: 1,
  5603. IsSys: 1,
  5604. WarehousingOrder: warehousing_order,
  5605. WarehouseOutId: 0,
  5606. WarehouseOutOrderNumber: "",
  5607. IsEdit: 0,
  5608. CancelStockId: 0,
  5609. CancelOrderNumber: "",
  5610. Manufacturer: selfBasedrug.Manufacturer,
  5611. Dealer: selfBasedrug.Dealer,
  5612. Creator: Creator,
  5613. UpdateCreator: Creator,
  5614. Status: 1,
  5615. Ctime: item.AdviceDate,
  5616. Mtime: 0,
  5617. Price: item.Price,
  5618. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5619. WarehouseOutDetailId: 0,
  5620. CancelOutDetailId: 0,
  5621. ExpireDate: 0,
  5622. ProductDate: 0,
  5623. MaxUnit: selfBasedrug.MinUnit,
  5624. MinUnit: selfBasedrug.MinUnit,
  5625. StorehouseId: 0,
  5626. OverCount: sum_count,
  5627. OperateTime: time.Now().Unix(),
  5628. AdviceId: item.ID,
  5629. }
  5630. service.CreateSelfDrugFlow(flow, tx)
  5631. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5632. var total_count int64 // 入库总数量
  5633. var over_count int64 //剩余库存
  5634. for _, it := range drugInfolist {
  5635. if it.MaxUnit == selfBasedrug.MaxUnit {
  5636. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5637. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5638. }
  5639. }
  5640. for _, it := range drugInfolist {
  5641. total_count += it.WarehousingCount
  5642. over_count += it.StockMaxNumber + it.StockMinNumber
  5643. }
  5644. //查询该仓库是否有默认数据
  5645. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5646. if selfDrugStock.ID == 0 {
  5647. drugStock := models.XtSelfDrugStockCount{
  5648. UserOrgId: item.UserOrgId,
  5649. PatientId: item.PatientId,
  5650. SumInCount: total_count,
  5651. SumOutCount: 0,
  5652. SumCancelCount: 0,
  5653. DrugId: item.DrugId,
  5654. Ctime: time.Now().Unix(),
  5655. Mtime: 0,
  5656. Status: 1,
  5657. FlushCount: over_count,
  5658. SumActOutCount: 0,
  5659. }
  5660. service.CreateSelfDrugStockSum(drugStock, tx)
  5661. }
  5662. if selfDrugStock.ID > 0 {
  5663. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5664. }
  5665. }
  5666. //查询这个单据的出库数量
  5667. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5668. var his_out_count int64
  5669. for _, item := range drugFlowList {
  5670. his_out_count += item.Count
  5671. }
  5672. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5673. if (total_count + his_out_count) <= in_count {
  5674. // 出库
  5675. if total_count < in_count {
  5676. var cha_count int64
  5677. cha_count = in_count - total_count
  5678. var stock_number int64 = 0
  5679. //查询库存是否充足
  5680. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5681. // 将该批次的剩余库存数量转换为拆零数量
  5682. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5683. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5684. }
  5685. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5686. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5687. }
  5688. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5689. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5690. }
  5691. if stock_number >= cha_count {
  5692. var maxNumber int64 = 0
  5693. var minNumber int64 = 0
  5694. maxNumber = cha_count / selfBasedrug.MinNumber
  5695. minNumber = cha_count % selfBasedrug.MinNumber
  5696. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5697. minNumber = maxNumber
  5698. }
  5699. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5700. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5702. return
  5703. }
  5704. }
  5705. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5706. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5707. }
  5708. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5709. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5710. }
  5711. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5712. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5713. }
  5714. if warehouse.StockMaxNumber < 0 {
  5715. warehouse.StockMaxNumber = 0
  5716. }
  5717. if warehouse.StockMinNumber < 0 {
  5718. warehouse.StockMinNumber = 0
  5719. }
  5720. warehouse.Mtime = time.Now().Unix()
  5721. if warehouse.StockMinNumber < minNumber {
  5722. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5723. if warehouse.MaxUnit != warehouse.MinUnit {
  5724. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5725. }
  5726. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5727. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5728. }
  5729. } else {
  5730. if minNumber > 0 {
  5731. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5732. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5733. }
  5734. }
  5735. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5736. if warehouse.StockMinNumber > 0 {
  5737. if warehouse.StockMinNumber-cha_count >= 0 {
  5738. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5739. }
  5740. }
  5741. }
  5742. }
  5743. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5744. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5745. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5746. }
  5747. }
  5748. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5749. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5751. return
  5752. }
  5753. }
  5754. if warehouse.StockMinNumber <= 0 {
  5755. warehouse.StockMinNumber = 0
  5756. }
  5757. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5758. //查询该药品剩余库存
  5759. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5760. var over_count int64
  5761. for _, its := range infolist {
  5762. if its.MaxUnit == selfBasedrug.MaxUnit {
  5763. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5764. }
  5765. over_count += its.StockMaxNumber + its.StockMinNumber
  5766. }
  5767. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5768. drugflow := models.XtSelfDrugFlow{
  5769. WarehouseOutId: 0,
  5770. WarehouseOutOrderNumber: warehousing_order,
  5771. WarehousingOrder: warehousing_order,
  5772. DrugId: item.DrugId,
  5773. Number: warehouse.Number,
  5774. ProductDate: warehouse.ProductDate,
  5775. ExpireDate: warehouse.ExpiryDate,
  5776. Count: cha_count,
  5777. Price: warehouse.RetailPrice,
  5778. Status: 1,
  5779. Ctime: item.AdviceDate,
  5780. Mtime: time.Now().Unix(),
  5781. UserOrgId: item.UserOrgId,
  5782. Manufacturer: warehouse.Manufacturer,
  5783. Dealer: warehouse.Dealer,
  5784. BatchNumber: warehouse.BatchNumber,
  5785. MaxUnit: selfBasedrug.MinUnit,
  5786. ConsumableType: 20,
  5787. IsEdit: 1,
  5788. Creator: 0,
  5789. IsSys: 3,
  5790. WarehouseOutDetailId: drugWareInfo.ID,
  5791. AdviceId: item.ID,
  5792. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5793. StorehouseId: 0,
  5794. AdminUserId: creater,
  5795. LastPrice: warehouse.Price,
  5796. StockCount: "",
  5797. WarehousingDetailId: 0,
  5798. OverCount: over_count,
  5799. RetailPrice: item.Price, //手动出库出库价格
  5800. WarehousingId: warehouse.ID,
  5801. SystemTime: item.AdviceDate,
  5802. PatientId: item.PatientId,
  5803. Remark: "保存处方入库数据差",
  5804. OperateTime: time.Now().Unix(),
  5805. }
  5806. if warehouse.RetailPrice == 0 {
  5807. drugflow.Price = item.Price
  5808. }
  5809. service.CreateSelfDrugFlowOne(drugflow, tx)
  5810. var out_count int64
  5811. out_count = in_count - total_count
  5812. //
  5813. //fmt.Println("in_count------------------", in_count)
  5814. //fmt.Println("total_count------------------", total_count)
  5815. //添加出库数量
  5816. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5817. //查询剩余库存
  5818. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5819. var sum_count int64
  5820. for _, its := range stockInfo {
  5821. if its.MaxUnit == selfBasedrug.MaxUnit {
  5822. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5823. }
  5824. sum_count += its.StockMaxNumber + its.StockMinNumber
  5825. }
  5826. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5827. } else {
  5828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5829. return
  5830. }
  5831. }
  5832. }
  5833. }
  5834. }
  5835. }
  5836. }
  5837. tx.Commit()
  5838. if err == nil {
  5839. c.ServeSuccessJSON(map[string]interface{}{
  5840. "msg": "保存成功",
  5841. })
  5842. return
  5843. } else {
  5844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5845. return
  5846. }
  5847. }
  5848. }
  5849. //func (c *HisApiController) EditHisPrescription() {
  5850. // record_date := c.GetString("record_date")
  5851. // patient_id, _ := c.GetInt64("patient_id")
  5852. // reg_type, _ := c.GetInt64("reg_type")
  5853. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5854. // diagnose := c.GetString("diagnose")
  5855. // sick_type, _ := c.GetInt64("sick_type")
  5856. // sick_history := c.GetString("sick_history")
  5857. // doctor_id, _ := c.GetInt64("doctor", 0)
  5858. // department, _ := c.GetInt64("department", 0)
  5859. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5860. // p_type, _ := c.GetInt64("p_type")
  5861. //
  5862. // dataBody := make(map[string]interface{}, 0)
  5863. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5864. // if err != nil {
  5865. // utils.ErrorLog(err.Error())
  5866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5867. // return
  5868. // }
  5869. //
  5870. // timeLayout := "2006-01-02"
  5871. // loc, _ := time.LoadLocation("Local")
  5872. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5873. // if err != nil {
  5874. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5875. // return
  5876. // }
  5877. // adminInfo := c.GetAdminUserInfo()
  5878. // recordDateTime := theTime.Unix()
  5879. //
  5880. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5881. //
  5882. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5883. // var hpInfo models.HisPrescriptionInfo
  5884. // if info.ID == 0 {
  5885. // var randNum int
  5886. // randNum = rand.Intn(10000) + 1000
  5887. // timestamp := time.Now().Unix()
  5888. // tempTime := time.Unix(timestamp, 0)
  5889. // timeFormat := tempTime.Format("20060102150405")
  5890. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5891. //
  5892. // hpInfo = models.HisPrescriptionInfo{
  5893. // UserOrgId: adminInfo.CurrentOrgId,
  5894. // RecordDate: theTime.Unix(),
  5895. // PatientId: patient_id,
  5896. // Status: 1,
  5897. // Ctime: time.Now().Unix(),
  5898. // Mtime: time.Now().Unix(),
  5899. // Creator: adminInfo.AdminUser.Id,
  5900. // Modifier: adminInfo.AdminUser.Id,
  5901. // Diagnosis: diagnose,
  5902. // SickHistory: sick_history,
  5903. // Departments: department,
  5904. // RegisterType: reg_type,
  5905. // PrescriptionNumber: p_number,
  5906. // PrescriptionStatus: 1,
  5907. // Doctor: role.UserName,
  5908. // DoctorId: doctor_id,
  5909. // SickType: sick_type,
  5910. // PType: p_type,
  5911. // }
  5912. // service.SavePatientPrescriptionInfo(hpInfo)
  5913. //
  5914. // } else {
  5915. // hpInfo = models.HisPrescriptionInfo{
  5916. // ID: info.ID,
  5917. // UserOrgId: adminInfo.CurrentOrgId,
  5918. // RecordDate: info.RecordDate,
  5919. // PatientId: info.PatientId,
  5920. // Status: 1,
  5921. // Ctime: info.Ctime,
  5922. // Mtime: time.Now().Unix(),
  5923. // Creator: info.Creator,
  5924. // Modifier: adminInfo.AdminUser.Id,
  5925. // Diagnosis: diagnose,
  5926. // SickHistory: sick_history,
  5927. // Departments: department,
  5928. // RegisterType: reg_type,
  5929. // PrescriptionNumber: info.PrescriptionNumber,
  5930. // Doctor: role.UserName,
  5931. // PrescriptionStatus: info.PrescriptionStatus,
  5932. // DoctorId: doctor_id,
  5933. // SickType: sick_type,
  5934. // PType: info.PType,
  5935. // }
  5936. // service.SavePatientPrescriptionInfo(hpInfo)
  5937. // }
  5938. //
  5939. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5940. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5941. //
  5942. // if len(prescriptions) > 0 {
  5943. // for _, item := range prescriptions {
  5944. // items := item.(map[string]interface{})
  5945. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5946. // utils.ErrorLog("id")
  5947. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5948. // return
  5949. // }
  5950. // id := int64(items["id"].(float64))
  5951. //
  5952. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5953. // utils.ErrorLog("type")
  5954. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5955. // return
  5956. // }
  5957. // types := int64(items["type"].(float64))
  5958. //
  5959. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5960. // utils.ErrorLog("med_type")
  5961. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5962. // return
  5963. // }
  5964. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5965. //
  5966. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5967. //
  5968. // ctime := time.Now().Unix()
  5969. //
  5970. // prescription := &models.HisPrescription{
  5971. // ID: id,
  5972. // PatientId: patient_id,
  5973. // UserOrgId: adminInfo.CurrentOrgId,
  5974. // RecordDate: recordDateTime,
  5975. // Ctime: ctime,
  5976. // Mtime: ctime,
  5977. // Type: types,
  5978. // Modifier: adminInfo.AdminUser.Id,
  5979. // Creator: adminInfo.AdminUser.Id,
  5980. // Status: 1,
  5981. // Doctor: role.UserName,
  5982. // HisPatientId: his_patient_id,
  5983. // OrderStatus: 1,
  5984. // BatchNumber: "",
  5985. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5986. // PType: hpInfo.PType,
  5987. // MedType: med_type,
  5988. // }
  5989. //
  5990. // if historyPrescription.ID > 0 {
  5991. // prescription.PreTime = historyPrescription.PreTime
  5992. //
  5993. // }
  5994. //
  5995. // service.SaveHisPrescription(prescription)
  5996. //
  5997. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5998. // advices := items["advices"].([]interface{})
  5999. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6000. // groupNo := int64(0)
  6001. // ctime := time.Now().Unix()
  6002. // mtime := ctime
  6003. // if len(advices) > 0 {
  6004. // for _, advice := range advices {
  6005. // var s models.HisDoctorAdviceInfo
  6006. // s.PrescriptionId = prescription.ID
  6007. // s.AdviceType = 2
  6008. // s.AdviceDoctor = adminInfo.AdminUser.Id
  6009. // s.StopState = 2
  6010. // s.ExecutionState = 2
  6011. // s.AdviceDate = recordDateTime
  6012. // s.Status = 1
  6013. // s.UserOrgId = adminInfo.CurrentOrgId
  6014. // s.RecordDate = recordDateTime
  6015. // s.StartTime = prescription.PreTime
  6016. // s.Groupno = groupNo
  6017. // s.CreatedTime = ctime
  6018. // s.UpdatedTime = mtime
  6019. // s.PatientId = patient_id
  6020. // s.HisPatientId = his_patient_id
  6021. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  6022. // if errcode > 0 {
  6023. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6024. // return
  6025. // }
  6026. //
  6027. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  6028. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  6029. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  6030. // if s.Price == 0 {
  6031. // s.Price = lastWarehouse.RetailPrice
  6032. // }
  6033. // }
  6034. //
  6035. // service.CreateHisDoctorAdvice(&s)
  6036. // //记录日志
  6037. // byterequest, _ := json.Marshal(s)
  6038. // adviceLog := models.XtDoctorAdviceLog{
  6039. // UserOrgId: s.UserOrgId,
  6040. // PatientId: s.PatientId,
  6041. // AdminUserId: adminInfo.AdminUser.Id,
  6042. // Module: 1,
  6043. // ErrLog: string(byterequest),
  6044. // Status: 1,
  6045. // Ctime: time.Now().Unix(),
  6046. // Mtime: 0,
  6047. // Source: "电脑端his医嘱修改",
  6048. // RecordDate: s.AdviceDate,
  6049. // }
  6050. // service.CreateDoctorAdviceLog(adviceLog)
  6051. // redis := service.RedisClient()
  6052. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  6053. // redis.Set(key, "", time.Second)
  6054. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  6055. // fmt.Println("keyOne", keyOne)
  6056. // redis.Set(keyOne, "", time.Second)
  6057. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  6058. // redis.Set(keySeven, "", time.Second)
  6059. // redis.Close()
  6060. //
  6061. // }
  6062. // }
  6063. // }
  6064. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6065. // projects := items["project"].([]interface{})
  6066. // if len(projects) > 0 {
  6067. // for _, project := range projects {
  6068. // var p models.HisPrescriptionProject
  6069. // p.PrescriptionId = prescription.ID
  6070. // p.Ctime = time.Now().Unix()
  6071. // p.Mtime = time.Now().Unix()
  6072. // p.PatientId = patient_id
  6073. // p.RecordDate = recordDateTime
  6074. // p.UserOrgId = adminInfo.CurrentOrgId
  6075. // p.HisPatientId = his_patient_id
  6076. // p.Status = 1
  6077. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  6078. // if errcode > 0 {
  6079. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6080. // return
  6081. // }
  6082. // service.CreateHisProjectTwo(&p)
  6083. //
  6084. // //记录日志
  6085. // byterequest, _ := json.Marshal(p)
  6086. // adviceLog := models.XtDoctorAdviceLog{
  6087. // UserOrgId: p.UserOrgId,
  6088. // PatientId: p.PatientId,
  6089. // AdminUserId: adminInfo.AdminUser.Id,
  6090. // Module: 1,
  6091. // ErrLog: string(byterequest),
  6092. // Status: 1,
  6093. // Ctime: time.Now().Unix(),
  6094. // Mtime: 0,
  6095. // Source: "电脑端his项目修改",
  6096. // RecordDate: p.RecordDate,
  6097. // }
  6098. // service.CreateDoctorAdviceLog(adviceLog)
  6099. // }
  6100. // }
  6101. // }
  6102. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  6103. // addition := items["addition"].([]interface{})
  6104. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6105. // ctime := time.Now().Unix()
  6106. // mtime := ctime
  6107. // if len(addition) > 0 {
  6108. // for _, item := range addition {
  6109. // var s models.HisAdditionalCharge
  6110. // s.PrescriptionId = prescription.ID
  6111. // s.Status = 1
  6112. // s.UserOrgId = adminInfo.CurrentOrgId
  6113. // s.RecordDate = recordDateTime
  6114. // s.CreatedTime = ctime
  6115. // s.UpdatedTime = mtime
  6116. // s.PatientId = patient_id
  6117. // s.HisPatientId = his_patient_id
  6118. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  6119. // if errcode > 0 {
  6120. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6121. // return
  6122. // }
  6123. // service.CreateAdditionalCharge(&s)
  6124. // }
  6125. // }
  6126. // }
  6127. //
  6128. // }
  6129. // }
  6130. // }
  6131. // if err == nil {
  6132. // c.ServeSuccessJSON(map[string]interface{}{
  6133. // "msg": "保存成功",
  6134. // })
  6135. // return
  6136. //
  6137. // } else {
  6138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6139. // return
  6140. // }
  6141. //}
  6142. func (c *HisApiController) DeletePrescription() {
  6143. prescription_id, _ := c.GetInt64("id")
  6144. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  6145. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  6146. ////同步到自备药
  6147. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6148. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6149. if selfPrescriptionOpen.IsOpen == 1 {
  6150. // 在函数结束时处理事务回滚
  6151. db := service.XTWriteDB()
  6152. tx := db.Begin()
  6153. defer func() {
  6154. if r := recover(); r != nil {
  6155. tx.Rollback()
  6156. } else {
  6157. tx.Commit()
  6158. }
  6159. }()
  6160. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  6161. for _, item := range advicesList {
  6162. timeStr := time.Now().Format("2006-01-02")
  6163. timeArr := strings.Split(timeStr, "-")
  6164. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6165. total = total + 1
  6166. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6167. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6168. number = number + total
  6169. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6170. operation_time := time.Now().Unix()
  6171. creater := c.GetAdminUserInfo().AdminUser.Id
  6172. //创建一个出库单
  6173. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6174. WarehouseOutOrderNumber: warehousing_out_order,
  6175. OperationTime: operation_time,
  6176. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6177. Creater: creater,
  6178. Ctime: time.Now().Unix(),
  6179. Status: 1,
  6180. WarehouseOutTime: item.AdviceDate,
  6181. Type: 0,
  6182. PatientId: item.PatientId,
  6183. IsCheck: 1,
  6184. }
  6185. //查询今日是否有出库数据
  6186. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  6187. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  6188. if lastWarehouseOut.ID == 0 {
  6189. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6190. }
  6191. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  6192. var total_count int64
  6193. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  6194. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6195. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6196. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6197. }
  6198. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6199. total_count += prescribingNumberSeven
  6200. }
  6201. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6202. total_count += prescribingNumberSeven
  6203. }
  6204. //出库
  6205. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6206. WarehouseOutOrderNumber: warehousing_out_order,
  6207. WarehouseOutId: lastWarehouseOut.ID,
  6208. DrugId: item.DrugId,
  6209. Count: total_count,
  6210. Price: 0,
  6211. TotalPrice: 0,
  6212. Status: 1,
  6213. Ctime: item.AdviceDate,
  6214. Mtime: item.AdviceDate,
  6215. Remark: "",
  6216. OrgId: item.UserOrgId,
  6217. Type: 0,
  6218. Manufacturer: selfBasedrug.Manufacturer,
  6219. Dealer: selfBasedrug.Dealer,
  6220. RetailPrice: 0,
  6221. RetailTotalPrice: 0,
  6222. CountUnit: selfBasedrug.MinUnit,
  6223. ExpiryDate: 0,
  6224. ProductDate: 0,
  6225. Number: "",
  6226. BatchNumber: "",
  6227. IsSys: 1,
  6228. WarehouseInfoId: 0,
  6229. AdminUserId: 0,
  6230. StockCount: "",
  6231. IsCheck: 1,
  6232. SysRecordTime: item.AdviceDate,
  6233. PatientId: item.PatientId,
  6234. ClassType: "",
  6235. AdviceId: item.ID,
  6236. }
  6237. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6238. }
  6239. fmt.Println("长度-------------------------------", warehousingOutInfo)
  6240. for _, it := range warehousingOutInfo {
  6241. //查询今日是否有出库数据
  6242. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6243. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6244. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6245. //出库逻辑
  6246. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6247. //查询剩余库存
  6248. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6249. var sum_count int64
  6250. for _, its := range stockInfo {
  6251. if its.MaxUnit == medical.MaxUnit {
  6252. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6253. }
  6254. sum_count += its.StockMaxNumber + its.StockMinNumber
  6255. }
  6256. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6257. }
  6258. }
  6259. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6260. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6261. //耗材保存处方出库
  6262. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6263. //已收费和已发药限制逻辑
  6264. isCharge := false
  6265. isMedicine := false
  6266. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6267. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6268. if new_prescription.IsMedicine == 1 {
  6269. isMedicine = true
  6270. }
  6271. for _, item := range new_prescriptions {
  6272. if item.OrderStatus == 4 {
  6273. isCharge = true
  6274. }
  6275. }
  6276. if p_err != nil {
  6277. if new_prescription.ID > 0 {
  6278. if new_prescription.OrderStatus == 2 {
  6279. isCharge = true
  6280. }
  6281. }
  6282. }
  6283. for _, item := range advices {
  6284. if item.IsMedicine == 1 {
  6285. isMedicine = true
  6286. }
  6287. }
  6288. if isCharge {
  6289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6290. return
  6291. }
  6292. if isMedicine {
  6293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6294. return
  6295. }
  6296. //已收费和已发药限制逻辑
  6297. if len(projects) > 0 {
  6298. for _, item := range projects {
  6299. service.DeletePrintInfo(item.ID) //删除打印信息
  6300. if goodOutConfig.IsOpen != 1 {
  6301. if stockConfig.IsOpen == 1 {
  6302. if item.Type == 3 && item.IsOut == 1 {
  6303. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6304. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6305. good.Total = good.Total + f_count
  6306. service.UpdateGoodInfo(&good)
  6307. operation_time := time.Now().Unix()
  6308. creater := c.GetAdminUserInfo().AdminUser.Id
  6309. //创建退库单
  6310. timeStr := time.Now().Format("2006-01-02")
  6311. timeArr := strings.Split(timeStr, "-")
  6312. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6313. total = total + 1
  6314. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6315. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6316. cancelStock := models.CancelStock{
  6317. OrderNumber: orderNumber,
  6318. OperaTime: operation_time,
  6319. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6320. Creater: creater,
  6321. Ctime: time.Now().Unix(),
  6322. Status: 1,
  6323. ReturnTime: item.RecordDate,
  6324. Type: 1,
  6325. StorehouseId: houseConfig.StorehouseOutInfo,
  6326. IsCheck: 1,
  6327. }
  6328. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6329. if msgerrkonde == gorm.ErrRecordNotFound {
  6330. service.AddSigleCancelStock(&cancelStock)
  6331. }
  6332. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6333. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6334. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6335. //查询该耗材是否出库
  6336. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6337. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6338. deaerler, _ := service.GetDealerById(info.Dealer)
  6339. var total_count int64
  6340. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6341. total_count += count
  6342. if info.ID > 0 {
  6343. if info.Count >= total_count {
  6344. //回退库存
  6345. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6346. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6347. var flush_count int64
  6348. for _, it := range goodList {
  6349. flush_count += it.StockCount
  6350. }
  6351. cancelStockInfo := models.CancelStockInfo{
  6352. GoodId: item.ProjectId,
  6353. CancelStockId: cancel.ID,
  6354. GoodTypeId: good.GoodTypeId,
  6355. Count: prescribingNumber,
  6356. Price: info.Price,
  6357. Total: 0,
  6358. ProductDate: info.ProductDate,
  6359. ExpiryDate: info.ExpiryDate,
  6360. Ctime: time.Now().Unix(),
  6361. Status: 1,
  6362. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6363. OrderNumber: cancel.OrderNumber,
  6364. Type: 0,
  6365. Dealer: deaerler.DealerName,
  6366. Manufacturer: manufacturer.ManufacturerName,
  6367. Number: info.Number,
  6368. RegisterAccount: "",
  6369. Remark: "",
  6370. WarehouseInfoId: info.WarehouseInfotId,
  6371. PatientId: info.PatientId,
  6372. RecordDate: info.SysRecordTime,
  6373. StorehouseId: houseConfig.StorehouseOutInfo,
  6374. IsCheck: 1,
  6375. }
  6376. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6377. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6378. flow := models.VmStockFlow{
  6379. WarehousingId: info.WarehouseInfotId,
  6380. GoodId: item.ProjectId,
  6381. Number: info.Number,
  6382. LicenseNumber: info.LicenseNumber,
  6383. Count: prescribingNumber,
  6384. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6385. PatientId: item.PatientId,
  6386. SystemTime: info.SysRecordTime,
  6387. ConsumableType: 7,
  6388. IsSys: 0,
  6389. WarehousingOrder: "",
  6390. WarehouseOutId: info.WarehouseOutId,
  6391. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6392. IsEdit: 0,
  6393. CancelStockId: cancel.ID,
  6394. CancelOrderNumber: cancel.OrderNumber,
  6395. Manufacturer: manufacturer.ID,
  6396. Dealer: 0,
  6397. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6398. UpdateCreator: 0,
  6399. Status: 1,
  6400. Ctime: time.Now().Unix(),
  6401. Mtime: 0,
  6402. Price: info.Price,
  6403. WarehousingDetailId: info.WarehouseInfotId,
  6404. WarehouseOutDetailId: info.ID,
  6405. CancelOutDetailId: cancelInfo.ID,
  6406. ProductDate: info.ProductDate,
  6407. ExpireDate: info.ExpiryDate,
  6408. StorehouseId: houseConfig.StorehouseOutInfo,
  6409. OverCount: flush_count,
  6410. OperateTime: time.Now().Unix(),
  6411. }
  6412. service.CreateStockFlowOne(flow)
  6413. //退库数量增加
  6414. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6415. //出库数量减少
  6416. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6417. }
  6418. if info.Count < total_count {
  6419. //回退库存
  6420. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6421. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6422. var flush_count int64
  6423. for _, it := range goodList {
  6424. flush_count += it.StockCount
  6425. }
  6426. cancelStockInfo := models.CancelStockInfo{
  6427. GoodId: item.ProjectId,
  6428. CancelStockId: cancel.ID,
  6429. GoodTypeId: good.GoodTypeId,
  6430. Count: info.Count,
  6431. Price: info.Price,
  6432. Total: 0,
  6433. ProductDate: info.ProductDate,
  6434. ExpiryDate: info.ExpiryDate,
  6435. Ctime: time.Now().Unix(),
  6436. Status: 1,
  6437. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6438. OrderNumber: cancel.OrderNumber,
  6439. Type: 0,
  6440. Dealer: deaerler.DealerName,
  6441. Manufacturer: manufacturer.ManufacturerName,
  6442. Number: info.Number,
  6443. RegisterAccount: "",
  6444. Remark: "",
  6445. WarehouseInfoId: info.WarehouseInfotId,
  6446. PatientId: info.PatientId,
  6447. RecordDate: info.SysRecordTime,
  6448. StorehouseId: houseConfig.StorehouseOutInfo,
  6449. IsCheck: 1,
  6450. }
  6451. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6452. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6453. flow := models.VmStockFlow{
  6454. WarehousingId: info.WarehouseInfotId,
  6455. GoodId: item.ProjectId,
  6456. Number: info.Number,
  6457. LicenseNumber: info.LicenseNumber,
  6458. Count: info.Count,
  6459. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6460. PatientId: item.PatientId,
  6461. SystemTime: info.SysRecordTime,
  6462. ConsumableType: 7,
  6463. IsSys: 0,
  6464. WarehousingOrder: "",
  6465. WarehouseOutId: info.WarehouseOutId,
  6466. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6467. IsEdit: 0,
  6468. CancelStockId: cancel.ID,
  6469. CancelOrderNumber: cancel.OrderNumber,
  6470. Manufacturer: manufacturer.ID,
  6471. Dealer: 0,
  6472. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6473. UpdateCreator: 0,
  6474. Status: 1,
  6475. Ctime: time.Now().Unix(),
  6476. Mtime: 0,
  6477. Price: info.Price,
  6478. WarehousingDetailId: info.WarehouseInfotId,
  6479. WarehouseOutDetailId: info.ID,
  6480. CancelOutDetailId: cancelInfo.ID,
  6481. ProductDate: info.ProductDate,
  6482. ExpireDate: info.ExpiryDate,
  6483. StorehouseId: houseConfig.StorehouseOutInfo,
  6484. OverCount: flush_count,
  6485. OperateTime: time.Now().Unix(),
  6486. }
  6487. service.CreateStockFlowOne(flow)
  6488. //退库数量增加
  6489. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6490. //出库数量减少
  6491. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6492. }
  6493. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6494. var flush_count int64
  6495. for _, it := range goodList {
  6496. flush_count += it.StockCount
  6497. }
  6498. //查询已出库数量
  6499. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6500. if prescribingNumber < dialysisInfo.Count {
  6501. //改变数量
  6502. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6503. }
  6504. if prescribingNumber >= dialysisInfo.Count {
  6505. //删除出库表
  6506. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6507. }
  6508. //更新库存
  6509. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6510. //更新基础库库存
  6511. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6512. }
  6513. }
  6514. }
  6515. }
  6516. //保存耗材出库
  6517. if goodOutConfig.IsOpen == 1 {
  6518. if item.Type == 3 {
  6519. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6520. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6521. good.Total = good.Total + f_count
  6522. service.UpdateGoodInfo(&good)
  6523. operation_time := time.Now().Unix()
  6524. creater := c.GetAdminUserInfo().AdminUser.Id
  6525. //创建退库单
  6526. timeStr := time.Now().Format("2006-01-02")
  6527. timeArr := strings.Split(timeStr, "-")
  6528. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6529. total = total + 1
  6530. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6531. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6532. cancelStock := models.CancelStock{
  6533. OrderNumber: orderNumber,
  6534. OperaTime: operation_time,
  6535. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6536. Creater: creater,
  6537. Ctime: time.Now().Unix(),
  6538. Status: 1,
  6539. ReturnTime: item.RecordDate,
  6540. Type: 1,
  6541. StorehouseId: houseConfig.StorehouseOutInfo,
  6542. IsCheck: 1,
  6543. }
  6544. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6545. if msgerrkonde == gorm.ErrRecordNotFound {
  6546. service.AddSigleCancelStock(&cancelStock)
  6547. }
  6548. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6549. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6550. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6551. //查询该耗材是否出库
  6552. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6553. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6554. deaerler, _ := service.GetDealerById(info.Dealer)
  6555. var total_count int64
  6556. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6557. total_count += count
  6558. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6559. var flush_count int64
  6560. for _, it := range goodList {
  6561. flush_count += it.StockCount
  6562. }
  6563. fmt.Println("历史出库数据", info.Count)
  6564. fmt.Println("出库数量", total_count)
  6565. if info.ID > 0 {
  6566. cancelStockInfo := models.CancelStockInfo{
  6567. GoodId: item.ProjectId,
  6568. CancelStockId: cancel.ID,
  6569. GoodTypeId: good.GoodTypeId,
  6570. Count: prescribingNumber,
  6571. Price: info.Price,
  6572. Total: 0,
  6573. ProductDate: info.ProductDate,
  6574. ExpiryDate: info.ExpiryDate,
  6575. Ctime: time.Now().Unix(),
  6576. Status: 1,
  6577. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6578. OrderNumber: cancel.OrderNumber,
  6579. Type: 0,
  6580. Dealer: deaerler.DealerName,
  6581. Manufacturer: manufacturer.ManufacturerName,
  6582. Number: info.Number,
  6583. RegisterAccount: "",
  6584. Remark: "",
  6585. WarehouseInfoId: info.WarehouseInfotId,
  6586. PatientId: info.PatientId,
  6587. RecordDate: info.SysRecordTime,
  6588. StorehouseId: houseConfig.StorehouseOutInfo,
  6589. IsCheck: 1,
  6590. }
  6591. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6592. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6593. //查询出库数量
  6594. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6595. //出库数据 大于 退库数量
  6596. if len(list) > 0 {
  6597. for _, it := range list {
  6598. //回退库存
  6599. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6600. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6601. var flush_count_one int64
  6602. for _, it := range goodList {
  6603. flush_count_one += it.StockCount
  6604. }
  6605. //查询该批次是否有退库数据
  6606. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6607. creater := c.GetAdminUserInfo().AdminUser.Id
  6608. flow := models.VmStockFlow{
  6609. WarehousingId: it.WarehouseInfotId,
  6610. GoodId: it.GoodId,
  6611. Number: it.Number,
  6612. LicenseNumber: it.LicenseNumber,
  6613. Count: it.Count,
  6614. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6615. PatientId: it.PatientId,
  6616. SystemTime: it.SysRecordTime,
  6617. ConsumableType: 7,
  6618. IsSys: 0,
  6619. WarehousingOrder: "",
  6620. WarehouseOutId: it.WarehouseOutId,
  6621. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6622. IsEdit: 0,
  6623. CancelStockId: cancel.ID,
  6624. CancelOrderNumber: cancel.OrderNumber,
  6625. Manufacturer: manufacturer.ID,
  6626. Dealer: 0,
  6627. Creator: creater,
  6628. UpdateCreator: 0,
  6629. Status: 1,
  6630. Ctime: time.Now().Unix(),
  6631. Mtime: 0,
  6632. Price: it.Price,
  6633. WarehousingDetailId: it.WarehouseInfotId,
  6634. WarehouseOutDetailId: it.ID,
  6635. CancelOutDetailId: cancelInfo.ID,
  6636. ProductDate: it.ProductDate,
  6637. ExpireDate: it.ExpiryDate,
  6638. StorehouseId: houseConfig.StorehouseOutInfo,
  6639. OverCount: flush_count_one,
  6640. OperateTime: time.Now().Unix(),
  6641. }
  6642. service.CreateStockFlowOne(flow)
  6643. //if flow.ID > 0 {
  6644. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6645. //}
  6646. }
  6647. }
  6648. //flow := models.VmStockFlow{
  6649. // WarehousingId: info.WarehouseInfotId,
  6650. // GoodId: item.ProjectId,
  6651. // Number: info.Number,
  6652. // LicenseNumber: info.LicenseNumber,
  6653. // Count: prescribingNumber,
  6654. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6655. // PatientId: item.PatientId,
  6656. // SystemTime: info.SysRecordTime,
  6657. // ConsumableType: 7,
  6658. // IsSys: 0,
  6659. // WarehousingOrder: "",
  6660. // WarehouseOutId: info.WarehouseOutId,
  6661. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6662. // IsEdit: 0,
  6663. // CancelStockId: cancel.ID,
  6664. // CancelOrderNumber: cancel.OrderNumber,
  6665. // Manufacturer: manufacturer.ID,
  6666. // Dealer: 0,
  6667. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6668. // UpdateCreator: 0,
  6669. // Status: 1,
  6670. // Ctime: time.Now().Unix(),
  6671. // Mtime: 0,
  6672. // Price: info.Price,
  6673. // WarehousingDetailId: info.WarehouseInfotId,
  6674. // WarehouseOutDetailId: info.ID,
  6675. // CancelOutDetailId: cancelInfo.ID,
  6676. // ProductDate: info.ProductDate,
  6677. // ExpireDate: info.ExpiryDate,
  6678. // StorehouseId: houseConfig.StorehouseOutInfo,
  6679. // OverCount: flush_count,
  6680. //}
  6681. //service.CreateStockFlowOne(flow)
  6682. //退库数量增加
  6683. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6684. //出库数量减少
  6685. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6686. //查询已出库数量
  6687. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6688. if prescribingNumber < dialysisInfo.Count {
  6689. //改变数量
  6690. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6691. }
  6692. if prescribingNumber >= dialysisInfo.Count {
  6693. //删除出库表
  6694. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6695. }
  6696. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6697. var flush_count_one int64
  6698. for _, it := range goodList {
  6699. flush_count_one += it.StockCount
  6700. }
  6701. //更新库存
  6702. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6703. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6704. //更新基础库库存
  6705. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6706. }
  6707. }
  6708. }
  6709. }
  6710. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6711. fmt.Println(err)
  6712. }
  6713. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6714. fmt.Println(err)
  6715. if len(advices) > 0 {
  6716. for _, item := range advices {
  6717. redis := service.RedisClient()
  6718. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6719. redis.Set(keyFive, "", time.Second)
  6720. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6721. redis.Set(keyOne, "", time.Second)
  6722. redis.Close()
  6723. }
  6724. }
  6725. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6726. if len(advices) > 0 {
  6727. for _, item := range advices {
  6728. creater := c.GetAdminUserInfo().AdminUser.Id
  6729. service.DrugAutoAddCancelInfo(item, creater)
  6730. }
  6731. }
  6732. } else {
  6733. if drugOutConfig.IsOpen == 1 {
  6734. if len(advices) > 0 {
  6735. for _, item := range advices {
  6736. creater := c.GetAdminUserInfo().AdminUser.Id
  6737. service.DrugAutoAddCancelInfo(item, creater)
  6738. }
  6739. }
  6740. } else {
  6741. if len(advices) > 0 {
  6742. for _, item := range advices {
  6743. creater := c.GetAdminUserInfo().AdminUser.Id
  6744. service.DrugAutoAddCancelInfo(item, creater)
  6745. }
  6746. }
  6747. }
  6748. }
  6749. c.ServeSuccessJSON(map[string]interface{}{
  6750. "msg": "删除成功",
  6751. })
  6752. return
  6753. }
  6754. func (c *HisApiController) DeleteDoctorAdvice() {
  6755. id, _ := c.GetInt64("id")
  6756. advice, _ := service.GetHisDoctorAdvicesById(id)
  6757. ////同步到自备药
  6758. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6759. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6760. if selfPrescriptionOpen.IsOpen == 1 {
  6761. db := service.XTWriteDB()
  6762. tx := db.Begin()
  6763. defer func() {
  6764. if r := recover(); r != nil {
  6765. tx.Rollback()
  6766. } else {
  6767. tx.Commit()
  6768. }
  6769. }()
  6770. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6771. var total_count int64
  6772. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6773. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6774. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6775. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6776. }
  6777. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6778. total_count += prescribingNumberSeven
  6779. }
  6780. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6781. total_count += prescribingNumberSeven
  6782. }
  6783. timeStr := time.Now().Format("2006-01-02")
  6784. timeArr := strings.Split(timeStr, "-")
  6785. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6786. total = total + 1
  6787. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6788. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6789. number = number + total
  6790. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6791. operation_time := time.Now().Unix()
  6792. creater := c.GetAdminUserInfo().AdminUser.Id
  6793. //创建一个出库单
  6794. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6795. WarehouseOutOrderNumber: warehousing_out_order,
  6796. OperationTime: operation_time,
  6797. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6798. Creater: creater,
  6799. Ctime: time.Now().Unix(),
  6800. Status: 1,
  6801. WarehouseOutTime: advice.AdviceDate,
  6802. Type: 0,
  6803. PatientId: advice.PatientId,
  6804. IsCheck: 1,
  6805. }
  6806. //查询今日是否有出库数据
  6807. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6808. if lastWarehouseOut.ID == 0 {
  6809. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6810. }
  6811. //出库
  6812. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6813. WarehouseOutId: lastWarehouseOut.ID,
  6814. WarehouseOutOrderNumber: warehousing_out_order,
  6815. DrugId: advice.DrugId,
  6816. Count: total_count,
  6817. Price: 0,
  6818. TotalPrice: 0,
  6819. Status: 1,
  6820. Ctime: advice.AdviceDate,
  6821. Mtime: advice.AdviceDate,
  6822. Remark: "",
  6823. OrgId: advice.UserOrgId,
  6824. Type: 0,
  6825. Manufacturer: selfBasedrug.Manufacturer,
  6826. Dealer: selfBasedrug.Dealer,
  6827. RetailPrice: 0,
  6828. RetailTotalPrice: 0,
  6829. CountUnit: advice.PrescribingNumberUnit,
  6830. ExpiryDate: 0,
  6831. ProductDate: 0,
  6832. Number: "",
  6833. BatchNumber: "",
  6834. IsSys: 0,
  6835. WarehouseInfoId: 0,
  6836. AdminUserId: 0,
  6837. StockCount: "",
  6838. IsCheck: 1,
  6839. SysRecordTime: advice.AdviceDate,
  6840. PatientId: advice.PatientId,
  6841. AdviceId: advice.ID,
  6842. ClassType: "",
  6843. }
  6844. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6845. for _, it := range warehousingOutInfo {
  6846. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6847. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6848. //出库逻辑
  6849. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6850. //查询剩余库存
  6851. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6852. var sum_count int64
  6853. for _, its := range stockInfo {
  6854. if its.MaxUnit == medical.MaxUnit {
  6855. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6856. }
  6857. sum_count += its.StockMaxNumber + its.StockMinNumber
  6858. }
  6859. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6860. }
  6861. }
  6862. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6863. //已收费和已发药的限制逻辑
  6864. isCharge := false
  6865. isMedicine := false
  6866. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6867. //获取今天该患者所有处方,判断是否发药或者收费
  6868. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6869. //for _, item := range new_prescriptions {
  6870. if new_prescription.IsMedicine == 1 {
  6871. isMedicine = true
  6872. }
  6873. //}
  6874. for _, item := range new_prescriptions {
  6875. if item.OrderStatus == 4 {
  6876. isCharge = true
  6877. }
  6878. }
  6879. if isMedicine {
  6880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6881. return
  6882. }
  6883. if isCharge {
  6884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6885. return
  6886. }
  6887. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6888. creater := c.GetAdminUserInfo().AdminUser.Id
  6889. for _, item := range advices {
  6890. if item.IsMedicine == 1 {
  6891. isMedicine = true
  6892. }
  6893. byterequest, _ := json.Marshal(item)
  6894. adviceLog := models.XtDoctorAdviceLog{
  6895. UserOrgId: item.UserOrgId,
  6896. PatientId: item.PatientId,
  6897. AdminUserId: creater,
  6898. Module: 1,
  6899. ErrLog: string(byterequest),
  6900. Status: 1,
  6901. Ctime: time.Now().Unix(),
  6902. Mtime: 0,
  6903. Source: "电脑端删除医嘱",
  6904. RecordDate: item.AdviceDate,
  6905. }
  6906. service.CreateDoctorAdviceLog(adviceLog)
  6907. }
  6908. if isMedicine {
  6909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6910. return
  6911. }
  6912. if new_prescription.ID > 0 {
  6913. if new_prescription.OrderStatus == 2 {
  6914. isCharge = true
  6915. }
  6916. }
  6917. if isCharge {
  6918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6919. return
  6920. }
  6921. //已收费和已发药的限制逻辑
  6922. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6923. redis := service.RedisClient()
  6924. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6925. redis.Set(keyFive, "", time.Second)
  6926. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6927. redis.Set(keyOne, "", time.Second)
  6928. defer redis.Close()
  6929. if err == nil {
  6930. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6931. //查询是否在处方中出库
  6932. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6933. if openConfig.IsOpen != 1 {
  6934. //判断该医嘱是否执行了
  6935. if advice.ExecutionState == 1 {
  6936. creater := c.GetAdminUserInfo().AdminUser.Id
  6937. service.DrugAutoAddCancelInfo(&advice, creater)
  6938. }
  6939. }
  6940. //开启保存处方扣减功能
  6941. if openConfig.IsOpen == 1 {
  6942. creater := c.GetAdminUserInfo().AdminUser.Id
  6943. service.DrugAutoAddCancelInfo(&advice, creater)
  6944. }
  6945. } else {
  6946. if drugOutConfig.IsOpen == 1 {
  6947. //查询是否在处方中出库
  6948. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6949. if openConfig.IsOpen != 1 {
  6950. //判断该医嘱是否执行了
  6951. if advice.ExecutionState == 1 {
  6952. creater := c.GetAdminUserInfo().AdminUser.Id
  6953. service.DrugAutoAddCancelInfo(&advice, creater)
  6954. }
  6955. }
  6956. //开启保存处方扣减功能
  6957. if openConfig.IsOpen == 1 {
  6958. creater := c.GetAdminUserInfo().AdminUser.Id
  6959. service.DrugAutoAddCancelInfo(&advice, creater)
  6960. }
  6961. } else {
  6962. //判断该医嘱是否执行了
  6963. if advice.ExecutionState == 1 {
  6964. creater := c.GetAdminUserInfo().AdminUser.Id
  6965. service.DrugAutoAddCancelInfo(&advice, creater)
  6966. }
  6967. }
  6968. }
  6969. c.ServeSuccessJSON(map[string]interface{}{
  6970. "msg": "删除成功",
  6971. })
  6972. return
  6973. } else {
  6974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6975. return
  6976. }
  6977. }
  6978. func (c *HisApiController) DeleteProject() {
  6979. id, _ := c.GetInt64("id")
  6980. adminInfo := c.GetAdminUserInfo()
  6981. project, _ := service.GetHisProjectByID(id)
  6982. // var consumable models.DialysisBeforePrepare
  6983. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6984. //耗材保存处方出库
  6985. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6986. isCharge := false
  6987. isMedicine := false
  6988. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6989. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6990. creater := c.GetAdminUserInfo().AdminUser.Id
  6991. for _, item := range new_prescriptions {
  6992. if item.IsMedicine == 1 {
  6993. isMedicine = true
  6994. }
  6995. byterequest, _ := json.Marshal(item)
  6996. adviceLog := models.XtDoctorAdviceLog{
  6997. UserOrgId: item.UserOrgId,
  6998. PatientId: item.PatientId,
  6999. AdminUserId: creater,
  7000. Module: 1,
  7001. ErrLog: string(byterequest),
  7002. Status: 1,
  7003. Ctime: time.Now().Unix(),
  7004. Mtime: 0,
  7005. Source: "电脑端删除医嘱",
  7006. RecordDate: item.RecordDate,
  7007. }
  7008. service.CreateDoctorAdviceLog(adviceLog)
  7009. }
  7010. for _, item := range new_prescriptions {
  7011. if item.OrderStatus == 4 {
  7012. isCharge = true
  7013. }
  7014. }
  7015. if isMedicine {
  7016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  7017. return
  7018. }
  7019. if isCharge {
  7020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  7021. return
  7022. }
  7023. if new_prescription.ID > 0 {
  7024. if new_prescription.OrderStatus == 2 {
  7025. isCharge = true
  7026. }
  7027. }
  7028. if isCharge {
  7029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  7030. return
  7031. }
  7032. service.DeletePrintInfo(id)
  7033. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  7034. label.Status = 0
  7035. service.CreateHisLabelRecordTwo(&label)
  7036. fmt.Println(goodOutConfig.IsOpen)
  7037. if goodOutConfig.IsOpen != 1 {
  7038. if stockConfig.IsOpen == 1 {
  7039. if project.Type == 2 {
  7040. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7041. fmt.Println(err)
  7042. }
  7043. if project.Type == 3 && project.IsOut == 1 {
  7044. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7045. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7046. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7047. operation_time := time.Now().Unix()
  7048. creater := adminInfo.AdminUser.Id
  7049. //创建退库单
  7050. timeStr := time.Now().Format("2006-01-02")
  7051. timeArr := strings.Split(timeStr, "-")
  7052. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7053. total = total + 1
  7054. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7055. cancelStock := models.CancelStock{
  7056. OrderNumber: orderNumber,
  7057. OperaTime: operation_time,
  7058. OrgId: adminInfo.CurrentOrgId,
  7059. Creater: creater,
  7060. Ctime: time.Now().Unix(),
  7061. Status: 1,
  7062. ReturnTime: project.RecordDate,
  7063. Type: 1,
  7064. StorehouseId: houseConfig.StorehouseOutInfo,
  7065. IsCheck: 1,
  7066. }
  7067. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7068. if msgerrkonde == gorm.ErrRecordNotFound {
  7069. service.AddSigleCancelStock(&cancelStock)
  7070. }
  7071. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7072. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7073. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7074. //查询是否有出库
  7075. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7076. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7077. deaerler, _ := service.GetDealerById(info.Dealer)
  7078. if info.ID > 0 {
  7079. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7080. if info.Count >= prescribingNumber {
  7081. cancelStockInfo := models.CancelStockInfo{
  7082. GoodId: project.ProjectId,
  7083. CancelStockId: cancel.ID,
  7084. GoodTypeId: good.GoodTypeId,
  7085. Count: prescribingNumber,
  7086. Price: info.Price,
  7087. Total: 0,
  7088. ProductDate: info.ProductDate,
  7089. ExpiryDate: info.ExpiryDate,
  7090. Ctime: time.Now().Unix(),
  7091. Status: 1,
  7092. OrgId: adminInfo.CurrentOrgId,
  7093. OrderNumber: cancel.OrderNumber,
  7094. Type: 0,
  7095. Dealer: deaerler.DealerName,
  7096. Manufacturer: manufacturer.ManufacturerName,
  7097. Number: info.Number,
  7098. RegisterAccount: "",
  7099. Remark: "",
  7100. WarehouseInfoId: info.WarehouseInfotId,
  7101. PatientId: info.PatientId,
  7102. RecordDate: info.SysRecordTime,
  7103. StorehouseId: houseConfig.StorehouseOutInfo,
  7104. IsCheck: 1,
  7105. }
  7106. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7107. //回退库存
  7108. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  7109. //退库数量增加
  7110. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7111. //出库数量减少
  7112. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7113. }
  7114. if info.Count < prescribingNumber {
  7115. cancelStockInfo := models.CancelStockInfo{
  7116. GoodId: project.ProjectId,
  7117. CancelStockId: cancel.ID,
  7118. GoodTypeId: good.GoodTypeId,
  7119. Count: info.Count,
  7120. Price: info.Price,
  7121. Total: 0,
  7122. ProductDate: info.ProductDate,
  7123. ExpiryDate: info.ExpiryDate,
  7124. Ctime: time.Now().Unix(),
  7125. Status: 1,
  7126. OrgId: adminInfo.CurrentOrgId,
  7127. OrderNumber: cancel.OrderNumber,
  7128. Type: 0,
  7129. Dealer: deaerler.DealerName,
  7130. Manufacturer: manufacturer.ManufacturerName,
  7131. Number: info.Number,
  7132. RegisterAccount: "",
  7133. Remark: "",
  7134. WarehouseInfoId: info.WarehouseInfotId,
  7135. PatientId: info.PatientId,
  7136. RecordDate: info.SysRecordTime,
  7137. StorehouseId: houseConfig.StorehouseOutInfo,
  7138. IsCheck: 1,
  7139. }
  7140. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7141. //回退库存
  7142. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7143. //退库数量增加
  7144. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  7145. //出库数量减少
  7146. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  7147. }
  7148. //查询剩余库存
  7149. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7150. var over_count int64
  7151. for _, it := range goodList {
  7152. over_count += it.StockCount
  7153. }
  7154. //出库数据 大于 退库数量
  7155. if info.Count >= prescribingNumber {
  7156. flow := models.VmStockFlow{
  7157. WarehousingId: info.WarehouseInfotId,
  7158. GoodId: project.ProjectId,
  7159. Number: info.Number,
  7160. LicenseNumber: info.LicenseNumber,
  7161. Count: prescribingNumber,
  7162. UserOrgId: adminInfo.CurrentOrgId,
  7163. PatientId: project.PatientId,
  7164. SystemTime: info.SysRecordTime,
  7165. ConsumableType: 7,
  7166. IsSys: 0,
  7167. WarehousingOrder: "",
  7168. WarehouseOutId: info.WarehouseOutId,
  7169. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7170. IsEdit: 0,
  7171. CancelStockId: cancel.ID,
  7172. CancelOrderNumber: cancel.OrderNumber,
  7173. Manufacturer: manufacturer.ID,
  7174. Dealer: 0,
  7175. Creator: adminInfo.AdminUser.Id,
  7176. UpdateCreator: 0,
  7177. Status: 1,
  7178. Ctime: time.Now().Unix(),
  7179. Mtime: 0,
  7180. Price: info.Price,
  7181. WarehousingDetailId: info.WarehouseInfotId,
  7182. WarehouseOutDetailId: info.ID,
  7183. CancelOutDetailId: cancelInfo.ID,
  7184. ProductDate: info.ProductDate,
  7185. ExpireDate: info.ExpiryDate,
  7186. StorehouseId: houseConfig.StorehouseOutInfo,
  7187. OverCount: over_count,
  7188. OperateTime: time.Now().Unix(),
  7189. }
  7190. service.CreateStockFlowOne(flow)
  7191. }
  7192. //出库数据小于退库数据
  7193. if info.Count < prescribingNumber {
  7194. flow := models.VmStockFlow{
  7195. WarehousingId: info.WarehouseInfotId,
  7196. GoodId: project.ProjectId,
  7197. Number: info.Number,
  7198. LicenseNumber: info.LicenseNumber,
  7199. Count: info.Count,
  7200. UserOrgId: adminInfo.CurrentOrgId,
  7201. PatientId: project.PatientId,
  7202. SystemTime: info.SysRecordTime,
  7203. ConsumableType: 7,
  7204. IsSys: 0,
  7205. WarehousingOrder: "",
  7206. WarehouseOutId: info.WarehouseOutId,
  7207. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7208. IsEdit: 0,
  7209. CancelStockId: cancel.ID,
  7210. CancelOrderNumber: cancel.OrderNumber,
  7211. Manufacturer: manufacturer.ID,
  7212. Dealer: 0,
  7213. Creator: adminInfo.AdminUser.Id,
  7214. UpdateCreator: 0,
  7215. Status: 1,
  7216. Ctime: time.Now().Unix(),
  7217. Mtime: 0,
  7218. Price: info.Price,
  7219. WarehousingDetailId: info.WarehouseInfotId,
  7220. WarehouseOutDetailId: info.ID,
  7221. CancelOutDetailId: cancelInfo.ID,
  7222. ProductDate: info.ProductDate,
  7223. ExpireDate: info.ExpiryDate,
  7224. StorehouseId: houseConfig.StorehouseOutInfo,
  7225. OverCount: over_count,
  7226. OperateTime: time.Now().Unix(),
  7227. }
  7228. service.CreateStockFlowOne(flow)
  7229. }
  7230. //查询已出库数量
  7231. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7232. if prescribingNumber < dialysisInfo.Count {
  7233. //改变数量
  7234. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7235. }
  7236. if prescribingNumber >= dialysisInfo.Count {
  7237. //删除出库表
  7238. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7239. }
  7240. //更新剩余库存
  7241. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7242. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7243. var total_count_one int64
  7244. for _, it := range stockList {
  7245. total_count_one += it.StockCount
  7246. }
  7247. //基础库插入数据
  7248. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7249. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7250. var flush_count int64
  7251. for _, it := range goodListOne {
  7252. flush_count += it.StockCount
  7253. }
  7254. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7255. if errs != nil {
  7256. goodErrcode := models.XtGoodErrcode{
  7257. UserOrgId: project.UserOrgId,
  7258. Errcode: "手动出库更新剩余出库失败",
  7259. GoodId: project.ProjectId,
  7260. Status: 1,
  7261. Ctime: time.Now().Unix(),
  7262. Mtime: 0,
  7263. Count: 0,
  7264. StockCount: 0,
  7265. Creater: creater,
  7266. BatchNumberId: 0,
  7267. WarehouseOutId: 0,
  7268. }
  7269. service.CreateGoodErrcode(goodErrcode)
  7270. }
  7271. }
  7272. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7273. fmt.Println(err)
  7274. } else {
  7275. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7276. fmt.Println(err)
  7277. }
  7278. } else {
  7279. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7280. fmt.Println(err)
  7281. }
  7282. }
  7283. //保存处方出库
  7284. if goodOutConfig.IsOpen == 1 {
  7285. if project.Type == 3 {
  7286. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7287. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7288. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7289. operation_time := time.Now().Unix()
  7290. creater := adminInfo.AdminUser.Id
  7291. //创建退库单
  7292. timeStr := time.Now().Format("2006-01-02")
  7293. timeArr := strings.Split(timeStr, "-")
  7294. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7295. total = total + 1
  7296. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7297. cancelStock := models.CancelStock{
  7298. OrderNumber: orderNumber,
  7299. OperaTime: operation_time,
  7300. OrgId: adminInfo.CurrentOrgId,
  7301. Creater: creater,
  7302. Ctime: time.Now().Unix(),
  7303. Status: 1,
  7304. ReturnTime: project.RecordDate,
  7305. Type: 1,
  7306. StorehouseId: houseConfig.StorehouseOutInfo,
  7307. IsCheck: 1,
  7308. }
  7309. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7310. if msgerrkonde == gorm.ErrRecordNotFound {
  7311. service.AddSigleCancelStock(&cancelStock)
  7312. }
  7313. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7314. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7315. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7316. //获取出库数据
  7317. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7318. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7319. deaerler, _ := service.GetDealerById(info.Dealer)
  7320. if info.ID > 0 {
  7321. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7322. if info.Count >= prescribingNumber {
  7323. cancelStockInfo := models.CancelStockInfo{
  7324. GoodId: project.ProjectId,
  7325. CancelStockId: cancel.ID,
  7326. GoodTypeId: good.GoodTypeId,
  7327. Count: prescribingNumber,
  7328. Price: info.Price,
  7329. Total: 0,
  7330. ProductDate: info.ProductDate,
  7331. ExpiryDate: info.ExpiryDate,
  7332. Ctime: time.Now().Unix(),
  7333. Status: 1,
  7334. OrgId: adminInfo.CurrentOrgId,
  7335. OrderNumber: cancel.OrderNumber,
  7336. Type: 0,
  7337. Dealer: deaerler.DealerName,
  7338. Manufacturer: manufacturer.ManufacturerName,
  7339. Number: info.Number,
  7340. RegisterAccount: "",
  7341. Remark: "",
  7342. WarehouseInfoId: info.WarehouseInfotId,
  7343. PatientId: info.PatientId,
  7344. RecordDate: info.SysRecordTime,
  7345. StorehouseId: houseConfig.StorehouseOutInfo,
  7346. IsCheck: 1,
  7347. }
  7348. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7349. //退库数量增加
  7350. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7351. //出库数量减少
  7352. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7353. }
  7354. if info.Count < prescribingNumber {
  7355. cancelStockInfo := models.CancelStockInfo{
  7356. GoodId: project.ProjectId,
  7357. CancelStockId: cancel.ID,
  7358. GoodTypeId: good.GoodTypeId,
  7359. Count: prescribingNumber,
  7360. Price: info.Price,
  7361. Total: 0,
  7362. ProductDate: info.ProductDate,
  7363. ExpiryDate: info.ExpiryDate,
  7364. Ctime: time.Now().Unix(),
  7365. Status: 1,
  7366. OrgId: adminInfo.CurrentOrgId,
  7367. OrderNumber: cancel.OrderNumber,
  7368. Type: 0,
  7369. Dealer: deaerler.DealerName,
  7370. Manufacturer: manufacturer.ManufacturerName,
  7371. Number: info.Number,
  7372. RegisterAccount: "",
  7373. Remark: "",
  7374. WarehouseInfoId: info.WarehouseInfotId,
  7375. PatientId: info.PatientId,
  7376. RecordDate: info.SysRecordTime,
  7377. StorehouseId: houseConfig.StorehouseOutInfo,
  7378. IsCheck: 1,
  7379. }
  7380. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7381. //回退库存
  7382. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7383. }
  7384. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7385. var over_count int64
  7386. for _, it := range goodList {
  7387. over_count += it.StockCount
  7388. }
  7389. //查询出库数量
  7390. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7391. //出库数据 大于 退库数量
  7392. if len(list) > 0 {
  7393. for _, it := range list {
  7394. //回退库存
  7395. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7396. //退库数量增加
  7397. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7398. //出库数量减少
  7399. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7400. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7401. var over_count_one int64
  7402. for _, it := range goodList {
  7403. over_count_one += it.StockCount
  7404. }
  7405. //查询该批次是否有退库数据
  7406. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7407. flow := models.VmStockFlow{
  7408. WarehousingId: it.WarehouseInfotId,
  7409. GoodId: it.GoodId,
  7410. Number: it.Number,
  7411. LicenseNumber: it.LicenseNumber,
  7412. Count: it.Count,
  7413. UserOrgId: adminInfo.CurrentOrgId,
  7414. PatientId: it.PatientId,
  7415. SystemTime: it.SysRecordTime,
  7416. ConsumableType: 7,
  7417. IsSys: 0,
  7418. WarehousingOrder: "",
  7419. WarehouseOutId: it.WarehouseOutId,
  7420. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7421. IsEdit: 0,
  7422. CancelStockId: cancel.ID,
  7423. CancelOrderNumber: cancel.OrderNumber,
  7424. Manufacturer: manufacturer.ID,
  7425. Dealer: 0,
  7426. Creator: adminInfo.AdminUser.Id,
  7427. UpdateCreator: 0,
  7428. Status: 1,
  7429. Ctime: time.Now().Unix(),
  7430. Mtime: 0,
  7431. Price: it.Price,
  7432. WarehousingDetailId: it.WarehouseInfotId,
  7433. WarehouseOutDetailId: it.ID,
  7434. CancelOutDetailId: cancelInfo.ID,
  7435. ProductDate: it.ProductDate,
  7436. ExpireDate: it.ExpiryDate,
  7437. StorehouseId: houseConfig.StorehouseOutInfo,
  7438. OverCount: over_count_one,
  7439. OperateTime: time.Now().Unix(),
  7440. }
  7441. service.CreateStockFlowOne(flow)
  7442. }
  7443. }
  7444. //查询已出库数量
  7445. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7446. if prescribingNumber < dialysisInfo.Count {
  7447. //改变数量
  7448. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7449. }
  7450. if prescribingNumber >= dialysisInfo.Count {
  7451. //删除出库表
  7452. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7453. }
  7454. //更新剩余库存
  7455. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7456. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7457. var total_count_one int64
  7458. for _, it := range stockList {
  7459. total_count_one += it.StockCount
  7460. }
  7461. //基础库插入数据
  7462. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7463. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7464. var flush_count int64
  7465. for _, it := range goodListOne {
  7466. flush_count += it.StockCount
  7467. }
  7468. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7469. if errs != nil {
  7470. goodErrcode := models.XtGoodErrcode{
  7471. UserOrgId: project.UserOrgId,
  7472. Errcode: "手动出库更新剩余出库失败",
  7473. GoodId: project.ProjectId,
  7474. Status: 1,
  7475. Ctime: time.Now().Unix(),
  7476. Mtime: 0,
  7477. Count: 0,
  7478. StockCount: 0,
  7479. Creater: creater,
  7480. BatchNumberId: 0,
  7481. WarehouseOutId: 0,
  7482. }
  7483. service.CreateGoodErrcode(goodErrcode)
  7484. }
  7485. }
  7486. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7487. fmt.Println(err)
  7488. } else {
  7489. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7490. fmt.Println(err)
  7491. }
  7492. }
  7493. c.ServeSuccessJSON(map[string]interface{}{
  7494. "msg": "删除成功",
  7495. })
  7496. return
  7497. }
  7498. func (c *HisApiController) CreateHisAdditionalCharge() {
  7499. his_patient_id, _ := c.GetInt64("his_patient_id")
  7500. patient_id, _ := c.GetInt64("patient_id")
  7501. record_date := c.GetString("record_date")
  7502. timeLayout := "2006-01-02"
  7503. loc, _ := time.LoadLocation("Local")
  7504. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7505. if err != nil {
  7506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7507. return
  7508. }
  7509. adminInfo := c.GetAdminUserInfo()
  7510. recordDateTime := theTime.Unix()
  7511. dataBody := make(map[string]interface{}, 0)
  7512. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7513. if err != nil {
  7514. utils.ErrorLog(err.Error())
  7515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7516. return
  7517. }
  7518. var additions []*models.HisAdditionalCharge
  7519. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7520. additions, _ := dataBody["addition"].([]interface{})
  7521. if len(additions) > 0 {
  7522. for _, item := range additions {
  7523. items := item.(map[string]interface{})
  7524. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7525. utils.ErrorLog("item_id")
  7526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7527. return
  7528. }
  7529. item_id := int64(items["item_id"].(float64))
  7530. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7531. utils.ErrorLog("item_name")
  7532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7533. return
  7534. }
  7535. item_name := items["item_name"].(string)
  7536. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7537. utils.ErrorLog("price")
  7538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7539. return
  7540. }
  7541. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7542. ctime := time.Now().Unix()
  7543. additional := &models.HisAdditionalCharge{
  7544. PatientId: patient_id,
  7545. HisPatientId: his_patient_id,
  7546. UserOrgId: adminInfo.CurrentOrgId,
  7547. RecordDate: recordDateTime,
  7548. CreatedTime: ctime,
  7549. UpdatedTime: ctime,
  7550. Modifier: adminInfo.AdminUser.Id,
  7551. Creator: adminInfo.AdminUser.Id,
  7552. Price: price,
  7553. ItemName: item_name,
  7554. ItemId: item_id,
  7555. Status: 1,
  7556. }
  7557. additions = append(additions, additional)
  7558. }
  7559. }
  7560. }
  7561. for _, item := range additions {
  7562. service.CreateAddtionalCharge(item)
  7563. }
  7564. c.ServeSuccessJSON(map[string]interface{}{
  7565. "msg": "创建成功",
  7566. })
  7567. }
  7568. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7569. blood_fat := c.GetString("blood_fat")
  7570. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7571. blood_sugar := c.GetString("blood_sugar")
  7572. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7573. chief_conplaint := c.GetString("chief_conplaint")
  7574. dbp := c.GetString("dbp")
  7575. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7576. delivery_way, _ := c.GetInt64("delivery_way")
  7577. diagnostic := c.GetString("diagnostic")
  7578. family_history := c.GetString("family_history")
  7579. height := c.GetString("height")
  7580. history_of_present_illness := c.GetString("history_of_present_illness")
  7581. is_infect, _ := c.GetInt64("is_infect")
  7582. past_history := c.GetString("past_history")
  7583. patient_id, _ := c.GetInt64("patient_id")
  7584. his_patient_id, _ := c.GetInt64("his_patient_id")
  7585. personal_history := c.GetString("personal_history")
  7586. pulse := c.GetString("pulse")
  7587. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7588. sbp := c.GetString("sbp")
  7589. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7590. heightfloat, _ := strconv.ParseFloat(height, 64)
  7591. sicktype := c.GetString("sick_type")
  7592. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7593. symptom := c.GetString("symptom")
  7594. sick_date := c.GetString("sick_date")
  7595. temperatures := c.GetString("temperature")
  7596. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7597. record_date := c.GetString("record_date")
  7598. breathing := c.GetString("breathing")
  7599. doctor_advice := c.GetString("doctor_advice")
  7600. remark := c.GetString("remark")
  7601. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7602. sick, _ := c.GetInt64("sick")
  7603. diagnose, _ := c.GetInt64("diagnose")
  7604. //id, _ := c.GetInt64("id")
  7605. timeLayout := "2006-01-02"
  7606. loc, _ := time.LoadLocation("Local")
  7607. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7608. allergic_history := c.GetString("allergic_history")
  7609. if err != nil {
  7610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7611. return
  7612. }
  7613. recordDateTime := theTime.Unix()
  7614. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7615. if err != nil {
  7616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7617. return
  7618. }
  7619. sickTimes := sickTime.Unix()
  7620. ctime := time.Now().Unix()
  7621. primary_disease := c.GetString("primary_disease")
  7622. confirm_failure_date := c.GetString("confirm_failure_date")
  7623. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7624. drug_allergy_history := c.GetString("drug_allergy_history")
  7625. physical_examination := c.GetString("physical_examination")
  7626. special_inspection := c.GetString("special_inspection")
  7627. lab_apparatus := c.GetString("lab_apparatus")
  7628. caseHistory := models.HisPatientCaseHistory{
  7629. HisPatientId: his_patient_id,
  7630. PatientId: patient_id,
  7631. Temperature: temperature,
  7632. BloodSugar: bloodsugarfloat,
  7633. Pulse: pulsefloat,
  7634. Sbp: sbpfloat,
  7635. Dbp: dbpfloat,
  7636. Height: heightfloat,
  7637. BloodFat: bloodfatfloat,
  7638. SickType: sick_type,
  7639. Symptom: symptom,
  7640. SickDate: sickTimes,
  7641. IsInfect: is_infect,
  7642. HistoryOfPresentIllness: history_of_present_illness,
  7643. PastHistory: past_history,
  7644. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7645. ChiefConplaint: chief_conplaint,
  7646. PersonalHistory: personal_history,
  7647. FamilyHistory: family_history,
  7648. Diagnostic: diagnostic,
  7649. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7650. Status: 1,
  7651. Ctime: ctime,
  7652. Mtime: ctime,
  7653. RecordDate: recordDateTime,
  7654. DeliveryWay: delivery_way,
  7655. Breathing: breathingfloat,
  7656. DoctorAdvice: doctor_advice,
  7657. Remark: remark,
  7658. Sick: sick,
  7659. Diagnose: diagnose,
  7660. AllergicHistory: allergic_history,
  7661. PrimaryDisease: primary_disease,
  7662. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7663. DrugAllergyHistory: drug_allergy_history,
  7664. PhysicalExamination: physical_examination,
  7665. SpecialInspection: special_inspection,
  7666. LabApparatus: lab_apparatus,
  7667. }
  7668. //查询该患者是否有病历
  7669. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7670. if errcodes == gorm.ErrRecordNotFound {
  7671. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7672. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7673. if err != nil {
  7674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7675. return
  7676. }
  7677. c.ServeSuccessJSON(map[string]interface{}{
  7678. "caseHistory": caseHistory,
  7679. "historyInfo": historyInfo,
  7680. })
  7681. return
  7682. } else if errcodes == nil {
  7683. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7684. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7685. if err != nil {
  7686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7687. return
  7688. }
  7689. c.ServeSuccessJSON(map[string]interface{}{
  7690. "caseHistory": caseHistory,
  7691. "historyInfo": historyInfo,
  7692. })
  7693. }
  7694. //查询该患者是否有病历
  7695. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7696. //if errcode == gorm.ErrRecordNotFound {
  7697. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7698. // if err != nil {
  7699. // c.ServeSuccessJSON(map[string]interface{}{
  7700. // "msg": "保存成功",
  7701. // })
  7702. // }
  7703. //} else if errcode == nil {
  7704. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7705. // return
  7706. //}
  7707. }
  7708. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7709. patient_id, _ := c.GetInt64("patient_id", 0)
  7710. adminUser := c.GetAdminUserInfo()
  7711. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7712. c.ServeSuccessJSON(map[string]interface{}{
  7713. "list": caseHistorys,
  7714. })
  7715. }
  7716. func (c *HisApiController) GetHisPatientCaseHistory() {
  7717. record_date, _ := c.GetInt64("record_date", 0)
  7718. patient_id, _ := c.GetInt64("patient_id", 0)
  7719. admin := c.GetAdminUserInfo()
  7720. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7721. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7722. c.ServeSuccessJSON(map[string]interface{}{
  7723. "info": info,
  7724. "case_history": case_history,
  7725. })
  7726. }
  7727. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7728. template_name := c.GetString("template_name")
  7729. template_remark := c.GetString("template_remark")
  7730. doctor := c.GetAdminUserInfo().AdminUser.Id
  7731. diagnostic := c.GetString("diagnostic")
  7732. chief_conplaint := c.GetString("chief_conplain")
  7733. history_of_present_illness := c.GetString("history_of_present_illness")
  7734. past_history := c.GetString("past_history")
  7735. personal_history := c.GetString("personal_history")
  7736. family_history := c.GetString("family_history")
  7737. user_name := c.GetString("user_name")
  7738. doctor_advice := c.GetString("doctor_advice")
  7739. remark := c.GetString("remark")
  7740. //record_date := c.GetString("record_date")
  7741. //fmt.Println("record_date--------",record_date)
  7742. //timeLayout := "2006-01-02"
  7743. //loc, _ := time.LoadLocation("Local")
  7744. //
  7745. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7746. //if err != nil {
  7747. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7748. // return
  7749. //}
  7750. //recordDateTime := theTime.Unix()
  7751. ctime := time.Now().Unix()
  7752. template := models.HisCaseHistoryTemplate{
  7753. HistoryOfPresentIllness: history_of_present_illness,
  7754. PastHistory: past_history,
  7755. ChiefConplaint: chief_conplaint,
  7756. PersonalHistory: personal_history,
  7757. FamilyHistory: family_history,
  7758. Diagnostic: diagnostic,
  7759. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7760. Status: 1,
  7761. Ctime: ctime,
  7762. Mtime: ctime,
  7763. RecordDate: time.Now().Unix(),
  7764. TemplateName: template_name,
  7765. TemplateRemark: template_remark,
  7766. Creator: doctor,
  7767. Modifier: doctor,
  7768. UserName: user_name,
  7769. DoctorAdvice: doctor_advice,
  7770. Remark: remark,
  7771. }
  7772. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7773. if err == nil {
  7774. c.ServeSuccessJSON(map[string]interface{}{
  7775. "msg": "保存成功",
  7776. })
  7777. } else {
  7778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7779. return
  7780. }
  7781. }
  7782. func (c *HisApiController) GetCaseHistoryTemplate() {
  7783. timeLayout := "2006-01-02"
  7784. loc, _ := time.LoadLocation("Local")
  7785. keyword := c.GetString("keyword")
  7786. start_time := c.GetString("start_time")
  7787. end_time := c.GetString("end_time")
  7788. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7789. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7790. admin := c.GetAdminUserInfo()
  7791. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7792. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7793. c.ServeSuccessJSON(map[string]interface{}{
  7794. "template": template,
  7795. //"history": history,
  7796. })
  7797. }
  7798. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7799. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7800. utils.ErrorLog("drug_name")
  7801. return enums.ErrorCodeParamWrong
  7802. }
  7803. adviceName, _ := json["drug_name"].(string)
  7804. if len(adviceName) == 0 {
  7805. utils.ErrorLog("len(advice_name) == 0")
  7806. return enums.ErrorCodeParamWrong
  7807. }
  7808. advice.AdviceName = adviceName
  7809. adviceDesc, _ := json["advice_desc"].(string)
  7810. advice.AdviceDesc = adviceDesc
  7811. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7812. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7813. advice.DrugSpec = drugSpec
  7814. }
  7815. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7816. remark, _ := json["remark"].(string)
  7817. advice.Remark = remark
  7818. }
  7819. if json["id"] == nil {
  7820. advice.DrugId = 0
  7821. } else {
  7822. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7823. drug_id := int64(json["id"].(float64))
  7824. advice.DrugId = drug_id
  7825. }
  7826. }
  7827. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7828. advice_id := int64(json["advice_id"].(float64))
  7829. advice.ID = advice_id
  7830. if advice.ID > 0 {
  7831. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7832. if err == nil {
  7833. if hisAdvice.ID > 0 {
  7834. advice.ExecutionTime = hisAdvice.ExecutionTime
  7835. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7836. advice.ExecutionState = hisAdvice.ExecutionState
  7837. advice.CheckTime = hisAdvice.CheckTime
  7838. advice.Checker = hisAdvice.Checker
  7839. advice.CheckState = hisAdvice.CheckState
  7840. advice.StartTime = hisAdvice.StartTime
  7841. advice.FeedetlSn = hisAdvice.FeedetlSn
  7842. }
  7843. }
  7844. }
  7845. }
  7846. //
  7847. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7848. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7849. // advice.ExecutionTime = execution_time
  7850. //}
  7851. //
  7852. //
  7853. //
  7854. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7855. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7856. // advice.ExecutionStaff = execution_staff
  7857. //}
  7858. //
  7859. //
  7860. //
  7861. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7862. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7863. // advice.ExecutionState = execution_state
  7864. //}
  7865. //
  7866. //
  7867. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7868. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7869. // advice.CheckTime = check_time
  7870. //}
  7871. //
  7872. //
  7873. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7874. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7875. // advice.CheckState = check_state
  7876. //}
  7877. //
  7878. //
  7879. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7880. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7881. // advice.Checker = checker
  7882. //}
  7883. //
  7884. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7885. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7886. // advice.StartTime = start_time
  7887. //}
  7888. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7889. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7890. advice.IsSelfDrug = is_self_drug
  7891. }
  7892. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7893. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7894. drug_way_count, _ := json["drug_way_count"].(string)
  7895. advice.DrugWayCount = drug_way_count
  7896. }
  7897. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7898. drugSpecUnit, _ := json["min_unit"].(string)
  7899. advice.DrugSpecUnit = drugSpecUnit
  7900. }
  7901. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7902. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7903. advice.SingleDose = singleDose
  7904. }
  7905. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7906. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7907. advice.SingleDoseUnit = singleDoseUnit
  7908. }
  7909. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7910. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7911. advice.PrescribingNumber = prescribingNumber
  7912. }
  7913. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7914. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7915. advice.PrescribingNumberUnit = prescribingNumberUnit
  7916. }
  7917. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7918. deliveryWay, _ := json["delivery_way"].(string)
  7919. advice.DeliveryWay = deliveryWay
  7920. }
  7921. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7922. executionFrequency, _ := json["execution_frequency"].(string)
  7923. advice.ExecutionFrequency = executionFrequency
  7924. }
  7925. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7926. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7927. advice.Price = price
  7928. }
  7929. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7930. med_list_codg, _ := json["medical_insurance_number"].(string)
  7931. advice.MedListCodg = med_list_codg
  7932. }
  7933. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7934. day := int64(json["day"].(float64))
  7935. advice.Day = day
  7936. }
  7937. return 0
  7938. }
  7939. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7940. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7941. id := int64(json["id"].(float64))
  7942. project.ID = id
  7943. historyProject, _ := service.GetHisProjectByID(id)
  7944. project.FeedetlSn = historyProject.FeedetlSn
  7945. }
  7946. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7947. project_id := int64(json["project_id"].(float64))
  7948. project.ProjectId = project_id
  7949. }
  7950. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7951. // price := int64(json["price"].(float64))
  7952. // formatInt_price := strconv.FormatInt(price, 10)
  7953. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7954. // project.Price = float_price
  7955. // }
  7956. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7957. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7958. project.Price = price
  7959. }
  7960. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7961. total, _ := json["total"].(string)
  7962. project.Count = total
  7963. }
  7964. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7965. medical_code, _ := json["medical_code"].(string)
  7966. project.MedListCodg = medical_code
  7967. }
  7968. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7969. single_dose, _ := json["single_dose"].(string)
  7970. project.SingleDose = single_dose
  7971. }
  7972. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7973. delivery_way, _ := json["delivery_way"].(string)
  7974. project.DeliveryWay = delivery_way
  7975. }
  7976. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7977. execution_frequency, _ := json["execution_frequency"].(string)
  7978. project.ExecutionFrequency = execution_frequency
  7979. }
  7980. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7981. remark, _ := json["remark"].(string)
  7982. project.Remark = remark
  7983. }
  7984. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7985. day, _ := json["number_days"].(string)
  7986. project.Day = day
  7987. }
  7988. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7989. unit, _ := json["unit"].(string)
  7990. project.Unit = unit
  7991. }
  7992. return 0
  7993. }
  7994. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7995. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7996. id := int64(json["id"].(float64))
  7997. historyAddtions, _ := service.GetHisAdditionByID(id)
  7998. additionalCharge.ID = id
  7999. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  8000. }
  8001. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8002. item_id := int64(json["item_id"].(float64))
  8003. additionalCharge.ItemId = item_id
  8004. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8005. if config.ID > 0 {
  8006. if len(config.Code) > 0 {
  8007. additionalCharge.MedListCodg = config.Code
  8008. }
  8009. }
  8010. }
  8011. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8012. // price := int64(json["price"].(float64))
  8013. // formatInt_price := strconv.FormatInt(price, 10)
  8014. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8015. // additionalCharge.Price = float_price
  8016. // }
  8017. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8018. // price := int64(json["price"].(float64))
  8019. // formatInt_price := strconv.FormatInt(price, 10)
  8020. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8021. // additionalCharge.Price = float_price
  8022. //}
  8023. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8024. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8025. additionalCharge.Price = price
  8026. }
  8027. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8028. count, _ := json["count"].(string)
  8029. counts, _ := strconv.ParseInt(count, 10, 64)
  8030. additionalCharge.Count = counts
  8031. }
  8032. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8033. item_name, _ := json["item_name"].(string)
  8034. additionalCharge.ItemName = item_name
  8035. }
  8036. return 0
  8037. }
  8038. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8039. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8040. utils.ErrorLog("drug_name")
  8041. return enums.ErrorCodeParamWrong
  8042. }
  8043. adviceName, _ := json["drug_name"].(string)
  8044. if len(adviceName) == 0 {
  8045. utils.ErrorLog("len(advice_name) == 0")
  8046. return enums.ErrorCodeParamWrong
  8047. }
  8048. advice.AdviceName = adviceName
  8049. adviceDesc, _ := json["advice_desc"].(string)
  8050. advice.AdviceDesc = adviceDesc
  8051. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8052. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8053. advice.DrugSpec = drugSpec
  8054. }
  8055. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8056. remark, _ := json["remark"].(string)
  8057. advice.Remark = remark
  8058. }
  8059. if json["id"] == nil {
  8060. advice.DrugId = 0
  8061. } else {
  8062. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8063. drug_id := int64(json["id"].(float64))
  8064. advice.DrugId = drug_id
  8065. }
  8066. }
  8067. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8068. groupno := int64(json["groupno"].(float64))
  8069. advice.Groupno = groupno
  8070. }
  8071. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8072. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8073. advice.IsSelfDrug = is_self_drug
  8074. }
  8075. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8076. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8077. drug_way_count, _ := json["drug_way_count"].(string)
  8078. advice.DrugWayCount = drug_way_count
  8079. }
  8080. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8081. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8082. advice.HospApprFlag = hosp_appr_flag
  8083. }
  8084. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8085. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8086. advice.PrescribingNumber = prescribingNumber
  8087. }
  8088. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8089. // frequency_type := int64(json["frequency_type"].(float64))
  8090. // advice.FrequencyType = frequency_type
  8091. //}
  8092. //
  8093. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8094. // day_count := int64(json["day_count"].(float64))
  8095. // advice.DayCount = day_count
  8096. //}
  8097. //
  8098. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8099. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8100. // week_day, _ := json["week_day"].(string)
  8101. // advice.WeekDay = week_day
  8102. //}
  8103. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8104. drugSpecUnit, _ := json["min_unit"].(string)
  8105. advice.DrugSpecUnit = drugSpecUnit
  8106. }
  8107. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8108. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8109. advice.SingleDose = singleDose
  8110. }
  8111. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8112. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8113. advice.SingleDoseUnit = singleDoseUnit
  8114. }
  8115. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8116. deliveryWay, _ := json["delivery_way"].(string)
  8117. advice.DeliveryWay = deliveryWay
  8118. }
  8119. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8120. executionFrequency, _ := json["execution_frequency"].(string)
  8121. advice.ExecutionFrequency = executionFrequency
  8122. }
  8123. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8124. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8125. advice.Price = price
  8126. }
  8127. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8128. med_list_codg, _ := json["medical_insurance_number"].(string)
  8129. advice.MedListCodg = med_list_codg
  8130. }
  8131. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8132. day := int64(json["day"].(float64))
  8133. advice.Day = day
  8134. }
  8135. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8136. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8137. advice.PrescribingNumberUnit = prescribingNumberUnit
  8138. }
  8139. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8140. advice_id := int64(json["advice_id"].(float64))
  8141. advice.ID = advice_id
  8142. if advice.ID > 0 {
  8143. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8144. if err == nil {
  8145. if hisAdvice.ID > 0 {
  8146. advice.ExecutionTime = hisAdvice.ExecutionTime
  8147. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8148. advice.ExecutionState = hisAdvice.ExecutionState
  8149. advice.CheckTime = hisAdvice.CheckTime
  8150. advice.Checker = hisAdvice.Checker
  8151. advice.CheckState = hisAdvice.CheckState
  8152. advice.StartTime = hisAdvice.StartTime
  8153. advice.HospApprFlag = hisAdvice.HospApprFlag
  8154. advice.IsMedicine = hisAdvice.IsMedicine
  8155. if hisAdvice.UserOrgId == 10028 {
  8156. 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 {
  8157. advice.ExecutionTime = 0
  8158. advice.ExecutionStaff = 0
  8159. advice.ExecutionState = 2
  8160. advice.CheckTime = 0
  8161. advice.Checker = 0
  8162. advice.CheckState = 2
  8163. }
  8164. } else {
  8165. 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 {
  8166. advice.ExecutionTime = 0
  8167. advice.ExecutionStaff = 0
  8168. advice.ExecutionState = 2
  8169. advice.CheckTime = 0
  8170. advice.Checker = 0
  8171. advice.CheckState = 2
  8172. advice.UpdatedTime = time.Now().Unix()
  8173. }
  8174. }
  8175. //advice.Groupno = hisAdvice.Groupno
  8176. }
  8177. }
  8178. }
  8179. }
  8180. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8181. //
  8182. //if drugStockConfig.IsOpen == 1 {
  8183. //
  8184. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8185. // if advice.ID == 0 { //医嘱不存在
  8186. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8187. // drug.Total = drug.Total - advice.PrescribingNumber
  8188. // service.UpdateBaseDrugLib(&drug)
  8189. //
  8190. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8191. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8192. // drug.Total = drug.Total - num
  8193. // service.UpdateBaseDrugLib(&drug)
  8194. // }
  8195. //
  8196. // } else if advice.ID > 0 { //医嘱存在
  8197. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8198. // var num float64
  8199. //
  8200. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8201. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8202. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8203. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8204. // drug.Total = drug.Total + num
  8205. // service.UpdateBaseDrugLib(&drug)
  8206. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8207. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8208. // drug.Total = drug.Total - num
  8209. // service.UpdateBaseDrugLib(&drug)
  8210. // }
  8211. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8212. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8213. // if num2 > advice.PrescribingNumber {
  8214. // num = num2 - advice.PrescribingNumber
  8215. // drug.Total = drug.Total + num
  8216. // service.UpdateBaseDrugLib(&drug)
  8217. // } else if num2 < advice.PrescribingNumber {
  8218. // num = advice.PrescribingNumber - num2
  8219. // drug.Total = drug.Total - num
  8220. // service.UpdateBaseDrugLib(&drug)
  8221. // }
  8222. //
  8223. // }
  8224. //
  8225. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8226. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8227. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8228. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8229. // if num1 > num2 {
  8230. // num = num1 - num2
  8231. // drug.Total = drug.Total + num
  8232. // service.UpdateBaseDrugLib(&drug)
  8233. // } else if num1 < num2 {
  8234. // num = num2 - num1
  8235. // drug.Total = drug.Total - num
  8236. // service.UpdateBaseDrugLib(&drug)
  8237. // }
  8238. //
  8239. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8240. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8241. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8242. // if hisAdvice.PrescribingNumber > num2 {
  8243. // num = hisAdvice.PrescribingNumber - num2
  8244. // drug.Total = drug.Total + num
  8245. // service.UpdateBaseDrugLib(&drug)
  8246. // } else if num2 < advice.PrescribingNumber {
  8247. // num = num2 - hisAdvice.PrescribingNumber
  8248. // drug.Total = drug.Total - num
  8249. // service.UpdateBaseDrugLib(&drug)
  8250. // }
  8251. //
  8252. // }
  8253. // }
  8254. // }
  8255. //}
  8256. //
  8257. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8258. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8259. // advice.ExecutionTime = execution_time
  8260. //}
  8261. //
  8262. //
  8263. //
  8264. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8265. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8266. // advice.ExecutionStaff = execution_staff
  8267. //}
  8268. //
  8269. //
  8270. //
  8271. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8272. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8273. // advice.ExecutionState = execution_state
  8274. //}
  8275. //
  8276. //
  8277. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8278. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8279. // advice.CheckTime = check_time
  8280. //}
  8281. //
  8282. //
  8283. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8284. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8285. // advice.CheckState = check_state
  8286. //}
  8287. //
  8288. //
  8289. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8290. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8291. // advice.Checker = checker
  8292. //}
  8293. //
  8294. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8295. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8296. // advice.StartTime = start_time
  8297. //}
  8298. return 0
  8299. }
  8300. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8301. project.ExecutionStaff = 0
  8302. project.ExecutionState = 2
  8303. project.ExecutionTime = 0
  8304. project.Checker = 0
  8305. project.CheckState = 2
  8306. project.CheckTime = 0
  8307. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8308. id := int64(json["id"].(float64))
  8309. project.ID = id
  8310. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8311. project.ExecutionStaff = temp_project.ExecutionStaff
  8312. project.ExecutionState = temp_project.ExecutionState
  8313. project.ExecutionTime = temp_project.ExecutionTime
  8314. project.Checker = temp_project.Checker
  8315. project.CheckState = temp_project.CheckState
  8316. project.CheckTime = temp_project.CheckTime
  8317. project.TeamId = temp_project.TeamId
  8318. }
  8319. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8320. types := int64(json["type"].(float64))
  8321. project.Type = types
  8322. }
  8323. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8324. project_id := int64(json["project_id"].(float64))
  8325. project.ProjectId = project_id
  8326. }
  8327. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8328. team_id := int64(json["team_id"].(float64))
  8329. project.TeamId = team_id
  8330. }
  8331. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8332. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8333. project.Price = price
  8334. }
  8335. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8336. total, _ := json["total"].(string)
  8337. //totals, _ := strconv.ParseInt(total, 10, 64)
  8338. project.Count = total
  8339. }
  8340. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8341. medical_code, _ := json["medical_code"].(string)
  8342. project.MedListCodg = medical_code
  8343. }
  8344. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8345. single_dose, _ := json["single_dose"].(string)
  8346. project.SingleDose = single_dose
  8347. }
  8348. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8349. delivery_way, _ := json["delivery_way"].(string)
  8350. project.DeliveryWay = delivery_way
  8351. }
  8352. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8353. execution_frequency, _ := json["execution_frequency"].(string)
  8354. project.ExecutionFrequency = execution_frequency
  8355. }
  8356. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8357. remark, _ := json["remark"].(string)
  8358. project.Remark = remark
  8359. }
  8360. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8361. day, _ := json["number_days"].(string)
  8362. project.Day = day
  8363. }
  8364. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8365. unit, _ := json["unit"].(string)
  8366. project.Unit = unit
  8367. }
  8368. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8369. // frequency_type := int64(json["frequency_type"].(float64))
  8370. // project.FrequencyType = frequency_type
  8371. //}
  8372. //
  8373. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8374. // day_count := int64(json["day_count"].(float64))
  8375. // project.DayCount = day_count
  8376. //}
  8377. //
  8378. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8379. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8380. // week_day, _ := json["week_day"].(string)
  8381. // project.WeekDay = week_day
  8382. //}
  8383. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8384. //
  8385. //if project.ID == 0 {
  8386. // if stockConfig.IsOpen == 1 {
  8387. // if project.Type == 3 {
  8388. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8389. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8390. // good.Total = good.Total - f_count
  8391. // service.UpdateGoodInfo(&good)
  8392. // }
  8393. // }
  8394. //
  8395. //} else {
  8396. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8397. //
  8398. // if stockConfig.IsOpen == 1 {
  8399. // if project.Type == 3 {
  8400. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8401. // if project.Count < temp_project.Count {
  8402. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8403. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8404. //
  8405. // other_count := f_count_two - f_count_one
  8406. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8407. // good.Total = good.Total + other_count_two
  8408. // service.UpdateGoodInfo(&good)
  8409. // } else if project.Count > temp_project.Count {
  8410. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8411. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8412. //
  8413. // other_count := f_count_one - f_count_two
  8414. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8415. // good.Total = good.Total - other_count_two
  8416. // service.UpdateGoodInfo(&good)
  8417. // }
  8418. //
  8419. // }
  8420. // }
  8421. //
  8422. //}
  8423. return 0
  8424. }
  8425. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8426. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8427. utils.ErrorLog("drug_name")
  8428. return enums.ErrorCodeParamWrong
  8429. }
  8430. adviceName, _ := json["drug_name"].(string)
  8431. if len(adviceName) == 0 {
  8432. utils.ErrorLog("len(advice_name) == 0")
  8433. return enums.ErrorCodeParamWrong
  8434. }
  8435. advice.AdviceName = adviceName
  8436. adviceDesc, _ := json["advice_desc"].(string)
  8437. advice.AdviceDesc = adviceDesc
  8438. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8439. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8440. advice.DrugSpec = drugSpec
  8441. }
  8442. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8443. remark, _ := json["remark"].(string)
  8444. advice.Remark = remark
  8445. }
  8446. if json["id"] == nil {
  8447. advice.DrugId = 0
  8448. } else {
  8449. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8450. drug_id := int64(json["id"].(float64))
  8451. advice.DrugId = drug_id
  8452. }
  8453. }
  8454. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8455. groupno := int64(json["groupno"].(float64))
  8456. advice.Groupno = groupno
  8457. }
  8458. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8459. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8460. advice.IsSelfDrug = is_self_drug
  8461. }
  8462. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8463. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8464. drug_way_count, _ := json["drug_way_count"].(string)
  8465. advice.DrugWayCount = drug_way_count
  8466. }
  8467. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8468. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8469. advice.HospApprFlag = hosp_appr_flag
  8470. }
  8471. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8472. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8473. advice.PrescribingNumber = prescribingNumber
  8474. }
  8475. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8476. // frequency_type := int64(json["frequency_type"].(float64))
  8477. // advice.FrequencyType = frequency_type
  8478. //}
  8479. //
  8480. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8481. // day_count := int64(json["day_count"].(float64))
  8482. // advice.DayCount = day_count
  8483. //}
  8484. //
  8485. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8486. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8487. // week_day, _ := json["week_day"].(string)
  8488. // advice.WeekDay = week_day
  8489. //}
  8490. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8491. drugSpecUnit, _ := json["min_unit"].(string)
  8492. advice.DrugSpecUnit = drugSpecUnit
  8493. }
  8494. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8495. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8496. advice.SingleDose = singleDose
  8497. }
  8498. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8499. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8500. advice.SingleDoseUnit = singleDoseUnit
  8501. }
  8502. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8503. deliveryWay, _ := json["delivery_way"].(string)
  8504. advice.DeliveryWay = deliveryWay
  8505. }
  8506. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8507. executionFrequency, _ := json["execution_frequency"].(string)
  8508. advice.ExecutionFrequency = executionFrequency
  8509. }
  8510. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8511. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8512. advice.Price = price
  8513. }
  8514. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8515. med_list_codg, _ := json["medical_insurance_number"].(string)
  8516. advice.MedListCodg = med_list_codg
  8517. }
  8518. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8519. day := int64(json["day"].(float64))
  8520. advice.Day = day
  8521. }
  8522. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8523. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8524. advice.PrescribingNumberUnit = prescribingNumberUnit
  8525. }
  8526. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8527. advice_id := int64(json["advice_id"].(float64))
  8528. advice.ID = advice_id
  8529. if advice.ID > 0 {
  8530. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8531. if err == nil {
  8532. if hisAdvice.ID > 0 {
  8533. advice.ExecutionTime = hisAdvice.ExecutionTime
  8534. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8535. advice.ExecutionState = hisAdvice.ExecutionState
  8536. advice.CheckTime = hisAdvice.CheckTime
  8537. advice.Checker = hisAdvice.Checker
  8538. advice.DrugCode = hisAdvice.DrugCode
  8539. advice.CheckState = hisAdvice.CheckState
  8540. advice.StartTime = hisAdvice.StartTime
  8541. advice.HospApprFlag = hisAdvice.HospApprFlag
  8542. advice.IsMedicine = hisAdvice.IsMedicine
  8543. if hisAdvice.UserOrgId == 10028 {
  8544. 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 {
  8545. advice.ExecutionTime = 0
  8546. advice.ExecutionStaff = 0
  8547. advice.ExecutionState = 2
  8548. advice.CheckTime = 0
  8549. advice.Checker = 0
  8550. advice.CheckState = 2
  8551. }
  8552. } else {
  8553. if hisAdvice.SingleDoseUnit != advice.SingleDoseUnit || 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 {
  8554. advice.ExecutionTime = 0
  8555. advice.ExecutionStaff = 0
  8556. advice.ExecutionState = 2
  8557. advice.CheckTime = 0
  8558. advice.Checker = 0
  8559. advice.CheckState = 2
  8560. //advice.UpdatedTime = time.Now().Unix()
  8561. advice.CreatedTime = hisAdvice.CreatedTime
  8562. advice.UpdatedTime = time.Now().Unix()
  8563. } else {
  8564. advice.CreatedTime = hisAdvice.CreatedTime
  8565. advice.UpdatedTime = hisAdvice.UpdatedTime
  8566. }
  8567. }
  8568. //advice.Groupno = hisAdvice.Groupno
  8569. } else {
  8570. advice.IsMedicine = 0
  8571. ctime := time.Now().Unix()
  8572. advice.CreatedTime = ctime
  8573. advice.UpdatedTime = ctime
  8574. }
  8575. }
  8576. } else {
  8577. advice.IsMedicine = 0
  8578. ctime := time.Now().Unix()
  8579. advice.CreatedTime = ctime
  8580. advice.UpdatedTime = ctime
  8581. }
  8582. }
  8583. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8584. //
  8585. //if drugStockConfig.IsOpen == 1 {
  8586. //
  8587. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8588. // if advice.ID == 0 { //医嘱不存在
  8589. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8590. // drug.Total = drug.Total - advice.PrescribingNumber
  8591. // service.UpdateBaseDrugLib(&drug)
  8592. //
  8593. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8594. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8595. // drug.Total = drug.Total - num
  8596. // service.UpdateBaseDrugLib(&drug)
  8597. // }
  8598. //
  8599. // } else if advice.ID > 0 { //医嘱存在
  8600. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8601. // var num float64
  8602. //
  8603. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8604. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8605. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8606. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8607. // drug.Total = drug.Total + num
  8608. // service.UpdateBaseDrugLib(&drug)
  8609. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8610. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8611. // drug.Total = drug.Total - num
  8612. // service.UpdateBaseDrugLib(&drug)
  8613. // }
  8614. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8615. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8616. // if num2 > advice.PrescribingNumber {
  8617. // num = num2 - advice.PrescribingNumber
  8618. // drug.Total = drug.Total + num
  8619. // service.UpdateBaseDrugLib(&drug)
  8620. // } else if num2 < advice.PrescribingNumber {
  8621. // num = advice.PrescribingNumber - num2
  8622. // drug.Total = drug.Total - num
  8623. // service.UpdateBaseDrugLib(&drug)
  8624. // }
  8625. //
  8626. // }
  8627. //
  8628. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8629. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8630. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8631. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8632. // if num1 > num2 {
  8633. // num = num1 - num2
  8634. // drug.Total = drug.Total + num
  8635. // service.UpdateBaseDrugLib(&drug)
  8636. // } else if num1 < num2 {
  8637. // num = num2 - num1
  8638. // drug.Total = drug.Total - num
  8639. // service.UpdateBaseDrugLib(&drug)
  8640. // }
  8641. //
  8642. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8643. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8644. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8645. // if hisAdvice.PrescribingNumber > num2 {
  8646. // num = hisAdvice.PrescribingNumber - num2
  8647. // drug.Total = drug.Total + num
  8648. // service.UpdateBaseDrugLib(&drug)
  8649. // } else if num2 < advice.PrescribingNumber {
  8650. // num = num2 - hisAdvice.PrescribingNumber
  8651. // drug.Total = drug.Total - num
  8652. // service.UpdateBaseDrugLib(&drug)
  8653. // }
  8654. //
  8655. // }
  8656. // }
  8657. // }
  8658. //}
  8659. //
  8660. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8661. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8662. // advice.ExecutionTime = execution_time
  8663. //}
  8664. //
  8665. //
  8666. //
  8667. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8668. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8669. // advice.ExecutionStaff = execution_staff
  8670. //}
  8671. //
  8672. //
  8673. //
  8674. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8675. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8676. // advice.ExecutionState = execution_state
  8677. //}
  8678. //
  8679. //
  8680. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8681. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8682. // advice.CheckTime = check_time
  8683. //}
  8684. //
  8685. //
  8686. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8687. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8688. // advice.CheckState = check_state
  8689. //}
  8690. //
  8691. //
  8692. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8693. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8694. // advice.Checker = checker
  8695. //}
  8696. //
  8697. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8698. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8699. // advice.StartTime = start_time
  8700. //}
  8701. return 0
  8702. }
  8703. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8704. project.ExecutionStaff = 0
  8705. project.ExecutionState = 2
  8706. project.ExecutionTime = 0
  8707. project.Checker = 0
  8708. project.CheckState = 2
  8709. project.CheckTime = 0
  8710. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8711. id := int64(json["id"].(float64))
  8712. project.ID = id
  8713. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8714. project.ExecutionStaff = temp_project.ExecutionStaff
  8715. project.ExecutionState = temp_project.ExecutionState
  8716. project.ExecutionTime = temp_project.ExecutionTime
  8717. project.Checker = temp_project.Checker
  8718. project.CheckState = temp_project.CheckState
  8719. project.CheckTime = temp_project.CheckTime
  8720. project.TeamId = temp_project.TeamId
  8721. }
  8722. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8723. types := int64(json["type"].(float64))
  8724. project.Type = types
  8725. }
  8726. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8727. project_id := int64(json["project_id"].(float64))
  8728. project.ProjectId = project_id
  8729. }
  8730. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8731. team_id := int64(json["team_id"].(float64))
  8732. project.TeamId = team_id
  8733. }
  8734. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8735. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8736. project.Price = price
  8737. }
  8738. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8739. total, _ := json["total"].(string)
  8740. //totals, _ := strconv.ParseInt(total, 10, 64)
  8741. project.Count = total
  8742. }
  8743. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8744. medical_code, _ := json["medical_code"].(string)
  8745. project.MedListCodg = medical_code
  8746. }
  8747. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8748. single_dose, _ := json["single_dose"].(string)
  8749. project.SingleDose = single_dose
  8750. }
  8751. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8752. delivery_way, _ := json["delivery_way"].(string)
  8753. project.DeliveryWay = delivery_way
  8754. }
  8755. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8756. execution_frequency, _ := json["execution_frequency"].(string)
  8757. project.ExecutionFrequency = execution_frequency
  8758. }
  8759. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8760. remark, _ := json["remark"].(string)
  8761. project.Remark = remark
  8762. }
  8763. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8764. day, _ := json["number_days"].(string)
  8765. project.Day = day
  8766. }
  8767. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8768. unit, _ := json["unit"].(string)
  8769. project.Unit = unit
  8770. }
  8771. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8772. // frequency_type := int64(json["frequency_type"].(float64))
  8773. // project.FrequencyType = frequency_type
  8774. //}
  8775. //
  8776. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8777. // day_count := int64(json["day_count"].(float64))
  8778. // project.DayCount = day_count
  8779. //}
  8780. //
  8781. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8782. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8783. // week_day, _ := json["week_day"].(string)
  8784. // project.WeekDay = week_day
  8785. //}
  8786. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8787. //
  8788. //if project.ID == 0 {
  8789. // if stockConfig.IsOpen == 1 {
  8790. // if project.Type == 3 {
  8791. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8792. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8793. // good.Total = good.Total - f_count
  8794. // service.UpdateGoodInfo(&good)
  8795. // }
  8796. // }
  8797. //
  8798. //} else {
  8799. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8800. //
  8801. // if stockConfig.IsOpen == 1 {
  8802. // if project.Type == 3 {
  8803. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8804. // if project.Count < temp_project.Count {
  8805. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8806. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8807. //
  8808. // other_count := f_count_two - f_count_one
  8809. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8810. // good.Total = good.Total + other_count_two
  8811. // service.UpdateGoodInfo(&good)
  8812. // } else if project.Count > temp_project.Count {
  8813. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8814. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8815. //
  8816. // other_count := f_count_one - f_count_two
  8817. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8818. // good.Total = good.Total - other_count_two
  8819. // service.UpdateGoodInfo(&good)
  8820. // }
  8821. //
  8822. // }
  8823. // }
  8824. //
  8825. //}
  8826. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8827. id := int64(json["id"].(float64))
  8828. if id > 0 {
  8829. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8830. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8831. fmt.Println("666666")
  8832. project.Mtime = time.Now().Unix()
  8833. project.Ctime = temp_project.Ctime
  8834. } else {
  8835. project.Mtime = temp_project.Mtime
  8836. project.Ctime = temp_project.Ctime
  8837. }
  8838. } else {
  8839. ctime := time.Now().Unix()
  8840. project.Mtime = ctime
  8841. project.Ctime = ctime
  8842. }
  8843. }
  8844. return 0
  8845. }
  8846. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8847. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8848. id := int64(json["id"].(float64))
  8849. additionalCharge.ID = id
  8850. }
  8851. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8852. item_id := int64(json["item_id"].(float64))
  8853. additionalCharge.ItemId = item_id
  8854. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8855. if config.ID > 0 {
  8856. if len(config.Code) > 0 {
  8857. additionalCharge.MedListCodg = config.Code
  8858. }
  8859. }
  8860. }
  8861. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8862. // price := int64(json["price"].(float64))
  8863. // formatInt_price := strconv.FormatInt(price, 10)
  8864. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8865. // additionalCharge.Price = float_price
  8866. // }
  8867. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8868. // price := int64(json["price"].(float64))
  8869. // formatInt_price := strconv.FormatInt(price, 10)
  8870. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8871. // additionalCharge.Price = float_price
  8872. //}
  8873. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8874. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8875. additionalCharge.Price = price
  8876. }
  8877. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8878. count, _ := json["count"].(string)
  8879. counts, _ := strconv.ParseInt(count, 10, 64)
  8880. additionalCharge.Count = counts
  8881. }
  8882. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8883. item_name, _ := json["item_name"].(string)
  8884. additionalCharge.ItemName = item_name
  8885. }
  8886. return 0
  8887. }
  8888. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8889. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8890. utils.ErrorLog("drug_name")
  8891. return enums.ErrorCodeParamWrong
  8892. }
  8893. adviceName, _ := json["drug_name"].(string)
  8894. if len(adviceName) == 0 {
  8895. utils.ErrorLog("len(advice_name) == 0")
  8896. return enums.ErrorCodeParamWrong
  8897. }
  8898. advice.AdviceName = adviceName
  8899. adviceDesc, _ := json["advice_desc"].(string)
  8900. advice.AdviceDesc = adviceDesc
  8901. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8902. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8903. advice.DrugSpec = drugSpec
  8904. }
  8905. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8906. remark, _ := json["remark"].(string)
  8907. advice.Remark = remark
  8908. }
  8909. if json["id"] == nil {
  8910. advice.DrugId = 0
  8911. } else {
  8912. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8913. drug_id := int64(json["id"].(float64))
  8914. advice.DrugId = drug_id
  8915. }
  8916. }
  8917. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8918. groupno := int64(json["groupno"].(float64))
  8919. advice.Groupno = groupno
  8920. }
  8921. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8922. drugSpecUnit, _ := json["min_unit"].(string)
  8923. advice.DrugSpecUnit = drugSpecUnit
  8924. }
  8925. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8926. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8927. advice.SingleDose = singleDose
  8928. }
  8929. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8930. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8931. advice.SingleDoseUnit = singleDoseUnit
  8932. }
  8933. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8934. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8935. advice.PrescribingNumber = prescribingNumber
  8936. }
  8937. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8938. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8939. advice.PrescribingNumberUnit = prescribingNumberUnit
  8940. }
  8941. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8942. deliveryWay, _ := json["delivery_way"].(string)
  8943. advice.DeliveryWay = deliveryWay
  8944. }
  8945. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8946. executionFrequency, _ := json["execution_frequency"].(string)
  8947. advice.ExecutionFrequency = executionFrequency
  8948. }
  8949. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8950. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8951. advice.Price = price
  8952. }
  8953. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8954. med_list_codg, _ := json["medical_insurance_number"].(string)
  8955. advice.MedListCodg = med_list_codg
  8956. }
  8957. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8958. day := int64(json["day"].(float64))
  8959. advice.Day = day
  8960. }
  8961. advice.FrequencyType = 1
  8962. return 0
  8963. }
  8964. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8965. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8966. types := int64(json["type"].(float64))
  8967. project.Type = types
  8968. }
  8969. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8970. project_id := int64(json["project_id"].(float64))
  8971. project.ProjectId = project_id
  8972. }
  8973. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8974. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8975. project.Price = price
  8976. }
  8977. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8978. total, _ := json["total"].(string)
  8979. //totals, _ := strconv.ParseInt(total, 10, 64)
  8980. project.Count = total
  8981. }
  8982. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8983. medical_code, _ := json["medical_code"].(string)
  8984. project.MedListCodg = medical_code
  8985. }
  8986. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8987. single_dose, _ := json["single_dose"].(string)
  8988. project.SingleDose = single_dose
  8989. }
  8990. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8991. delivery_way, _ := json["delivery_way"].(string)
  8992. project.DeliveryWay = delivery_way
  8993. }
  8994. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8995. execution_frequency, _ := json["execution_frequency"].(string)
  8996. project.ExecutionFrequency = execution_frequency
  8997. }
  8998. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8999. remark, _ := json["remark"].(string)
  9000. project.Remark = remark
  9001. }
  9002. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  9003. day, _ := json["number_days"].(string)
  9004. project.Day = day
  9005. }
  9006. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  9007. unit, _ := json["unit"].(string)
  9008. project.Unit = unit
  9009. }
  9010. project.FrequencyType = 1
  9011. return 0
  9012. }
  9013. func (c *HisApiController) GetHisOrderListTwo() {
  9014. start_time := c.GetString("start_time")
  9015. end_time := c.GetString("end_time")
  9016. timeLayout := "2006-01-02"
  9017. loc, _ := time.LoadLocation("Local")
  9018. var startTime int64
  9019. if len(start_time) > 0 {
  9020. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9021. if err != nil {
  9022. //fmt.Println(err)
  9023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9024. return
  9025. }
  9026. startTime = theTime.Unix()
  9027. }
  9028. var endTime int64
  9029. if len(end_time) > 0 {
  9030. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9031. if err != nil {
  9032. utils.ErrorLog(err.Error())
  9033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9034. return
  9035. }
  9036. endTime = theTime.Unix()
  9037. }
  9038. adminUser := c.GetAdminUserInfo()
  9039. org_id := adminUser.CurrentOrgId
  9040. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  9041. if err == nil {
  9042. c.ServeSuccessJSON(map[string]interface{}{
  9043. "order2": order,
  9044. })
  9045. } else {
  9046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9047. return
  9048. }
  9049. }
  9050. func (c *HisApiController) GetHisOrderList() {
  9051. page, _ := c.GetInt64("page", -1)
  9052. limit, _ := c.GetInt64("limit", -1)
  9053. start_time := c.GetString("start_time")
  9054. end_time := c.GetString("end_time")
  9055. types, _ := c.GetInt64("type", 0)
  9056. keywords := c.GetString("keywords")
  9057. p_type, _ := c.GetInt64("p_type", 0)
  9058. sort_type, _ := c.GetInt64("sort_type", 0)
  9059. charge_type, _ := c.GetInt64("charge_type", 0)
  9060. sch_type, _ := c.GetInt64("sch_type", 0)
  9061. zone_type, _ := c.GetInt64("zone_type", 0)
  9062. med_type, _ := c.GetInt64("med_type", 0)
  9063. timeLayout := "2006-01-02"
  9064. loc, _ := time.LoadLocation("Local")
  9065. var startTime int64
  9066. if len(start_time) > 0 {
  9067. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9068. if err != nil {
  9069. //fmt.Println(err)
  9070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9071. return
  9072. }
  9073. startTime = theTime.Unix()
  9074. }
  9075. var endTime int64
  9076. if len(end_time) > 0 {
  9077. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9078. if err != nil {
  9079. utils.ErrorLog(err.Error())
  9080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9081. return
  9082. }
  9083. endTime = theTime.Unix()
  9084. }
  9085. adminUser := c.GetAdminUserInfo()
  9086. org_id := adminUser.CurrentOrgId
  9087. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  9088. for _, item := range order {
  9089. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  9090. item.DoctorName = info.Doctor
  9091. item.DepartmentName = info.XtHisDepartment.Name
  9092. }
  9093. if err == nil {
  9094. c.ServeSuccessJSON(map[string]interface{}{
  9095. "order": order,
  9096. "total": total,
  9097. })
  9098. } else {
  9099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9100. return
  9101. }
  9102. }
  9103. func (c *HisApiController) GetHisOrder() {
  9104. patient_id, _ := c.GetInt64("patient_id", 0)
  9105. number := c.GetString("number")
  9106. adminInfo := c.GetAdminUserInfo()
  9107. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  9108. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  9109. if err == nil {
  9110. c.ServeSuccessJSON(map[string]interface{}{
  9111. "order": order,
  9112. "prescription": prescriptions,
  9113. })
  9114. } else {
  9115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9116. return
  9117. }
  9118. }
  9119. func (c *HisApiController) GetHisPrescriptionList() {
  9120. record_date := c.GetString("record_date")
  9121. keywords := c.GetString("keywords")
  9122. page, _ := c.GetInt64("page")
  9123. limit, _ := c.GetInt64("limit")
  9124. sch_type, _ := c.GetInt64("sch_type")
  9125. timeLayout := "2006-01-02"
  9126. loc, _ := time.LoadLocation("Local")
  9127. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9128. if err != nil {
  9129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9130. return
  9131. }
  9132. recordDateTime := theTime.Unix()
  9133. adminInfo := c.GetAdminUserInfo()
  9134. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  9135. //adminInfo := c.GetAdminUserInfo()
  9136. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  9137. //fmt.Println(prescriptionOrder)
  9138. if err == nil {
  9139. c.ServeSuccessJSON(map[string]interface{}{
  9140. "order": prescriptionOrder,
  9141. "total": total,
  9142. })
  9143. } else {
  9144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9145. return
  9146. }
  9147. }
  9148. func (c *HisApiController) GetHisPrescriptionInfo() {
  9149. id, _ := c.GetInt64("id")
  9150. adminInfo := c.GetAdminUserInfo()
  9151. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  9152. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  9153. if err == nil {
  9154. c.ServeSuccessJSON(map[string]interface{}{
  9155. "order": prescriptionOrder,
  9156. "prescription": prescription,
  9157. })
  9158. } else {
  9159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9160. return
  9161. }
  9162. }
  9163. func (c *HisApiController) GetMedicalInsuranceConfig() {
  9164. adminUser := c.GetAdminUserInfo()
  9165. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  9166. c.ServeSuccessJSON(map[string]interface{}{
  9167. "config": config,
  9168. })
  9169. }
  9170. type ResultTwo struct {
  9171. ErrMsg interface{} `json:"err_msg"`
  9172. InfRefmsgid string `json:"inf_refmsgid"`
  9173. Infcode int64 `json:"infcode"`
  9174. Output struct {
  9175. Baseinfo struct {
  9176. Age float64 `json:"age"`
  9177. Brdy string `json:"brdy"`
  9178. Certno string `json:"certno"`
  9179. Gend string `json:"gend"`
  9180. Naty string `json:"naty"`
  9181. PsnCertType string `json:"psn_cert_type"`
  9182. PsnName string `json:"psn_name"`
  9183. PsnNo string `json:"psn_no"`
  9184. } `json:"baseinfo"`
  9185. Idetinfo []interface{} `json:"idetinfo"`
  9186. Iinfo []struct {
  9187. Balc float64 `json:"balc"`
  9188. CvlservFlag string `json:"cvlserv_flag"`
  9189. EmpName string `json:"emp_name"`
  9190. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  9191. Insutype string `json:"insutype"`
  9192. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  9193. PausInsuDate interface{} `json:"paus_insu_date"`
  9194. PsnInsuDate string `json:"psn_insu_date"`
  9195. PsnInsuStas string `json:"psn_insu_stas"`
  9196. PsnType string `json:"psn_type"`
  9197. } `json:"insuinfo"`
  9198. } `json:"output"`
  9199. RefmsgTime string `json:"refmsg_time"`
  9200. RespondTime string `json:"respond_time"`
  9201. Signtype interface{} `json:"signtype"`
  9202. WarnInfo interface{} `json:"warn_info"`
  9203. }
  9204. type ResultThree struct {
  9205. Cainfo interface{} `json:"cainfo"`
  9206. ErrMsg interface{} `json:"err_msg"`
  9207. InfRefmsgid string `json:"inf_refmsgid"`
  9208. Infcode int64 `json:"infcode"`
  9209. Output struct {
  9210. Data struct {
  9211. IptOtpNo string `json:"ipt_otp_no"`
  9212. MdtrtID string `json:"mdtrt_id"`
  9213. PsnNo string `json:"psn_no"`
  9214. } `json:"data"`
  9215. } `json:"output"`
  9216. RefmsgTime string `json:"refmsg_time"`
  9217. RespondTime string `json:"respond_time"`
  9218. Signtype interface{} `json:"signtype"`
  9219. WarnMsg interface{} `json:"warn_msg"`
  9220. }
  9221. type ResultFour struct {
  9222. Cainfo string `json:"cainfo"`
  9223. ErrMsg string `json:"err_msg"`
  9224. InfRefmsgid string `json:"inf_refmsgid"`
  9225. Infcode int64 `json:"infcode"`
  9226. Output struct {
  9227. Result []struct {
  9228. BasMednFlag string `json:"bas_medn_flag"`
  9229. ChldMedcFlag string `json:"chld_medc_flag"`
  9230. ChrgitmLv string `json:"chrgitm_lv"`
  9231. Cnt float64 `json:"cnt"`
  9232. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9233. DrtReimFlag string `json:"drt_reim_flag"`
  9234. FeedetlSn string `json:"feedetl_sn"`
  9235. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9236. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9237. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9238. ListSpItemFlag string `json:"list_sp_item_flag"`
  9239. LmtUsedFlag string `json:"lmt_used_flag"`
  9240. MedChrgitmType string `json:"med_chrgitm_type"`
  9241. Memo string `json:"memo"`
  9242. OverlmtAmt float64 `json:"overlmt_amt"`
  9243. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9244. Pric float64 `json:"pric"`
  9245. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9246. SelfpayProp float64 `json:"selfpay_prop"`
  9247. } `json:"result"`
  9248. } `json:"output"`
  9249. RefmsgTime string `json:"refmsg_time"`
  9250. RespondTime string `json:"respond_time"`
  9251. Signtype string `json:"signtype"`
  9252. WarnMsg string `json:"warn_msg"`
  9253. }
  9254. type ResultFive struct {
  9255. Insutype string `json:"insutype"`
  9256. }
  9257. type ResultSix struct {
  9258. Cainfo interface{} `json:"cainfo"`
  9259. ErrMsg interface{} `json:"err_msg"`
  9260. InfRefmsgid string `json:"inf_refmsgid"`
  9261. Infcode int64 `json:"infcode"`
  9262. Output struct {
  9263. } `json:"output"`
  9264. RefmsgTime string `json:"refmsg_time"`
  9265. RespondTime string `json:"respond_time"`
  9266. Signtype interface{} `json:"signtype"`
  9267. WarnMsg interface{} `json:"warn_msg"`
  9268. }
  9269. type ResultSeven struct {
  9270. Cainfo string `json:"cainfo"`
  9271. ErrMsg string `json:"err_msg"`
  9272. InfRefmsgid string `json:"inf_refmsgid"`
  9273. Infcode int64 `json:"infcode"`
  9274. Output struct {
  9275. Setldetail []interface{} `json:"setldetail"`
  9276. Setlinfo struct {
  9277. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9278. AcctPay float64 `json:"acct_pay"`
  9279. ActPayDedc float64 `json:"act_pay_dedc"`
  9280. Age float64 `json:"age"`
  9281. Balc float64 `json:"balc"`
  9282. Brdy string `json:"brdy"`
  9283. Certno string `json:"certno"`
  9284. ClrOptins string `json:"clr_optins"`
  9285. ClrType string `json:"clr_type"`
  9286. ClrWay string `json:"clr_way"`
  9287. CvlservFlag string `json:"cvlserv_flag"`
  9288. CvlservPay float64 `json:"cvlserv_pay"`
  9289. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9290. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9291. Gend string `json:"gend"`
  9292. HifesPay float64 `json:"hifes_pay"`
  9293. HifmiPay float64 `json:"hifmi_pay"`
  9294. HifobPay float64 `json:"hifob_pay"`
  9295. HifpPay float64 `json:"hifp_pay"`
  9296. HospPartAmt float64 `json:"hosp_part_amt"`
  9297. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9298. Insutype string `json:"insutype"`
  9299. MafPay float64 `json:"maf_pay"`
  9300. MdtrtCertType string `json:"mdtrt_cert_type"`
  9301. MdtrtID string `json:"mdtrt_id"`
  9302. MedType string `json:"med_type"`
  9303. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9304. MedinsSetlID string `json:"medins_setl_id"`
  9305. Naty string `json:"naty"`
  9306. OthPay float64 `json:"oth_pay"`
  9307. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9308. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9309. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9310. PsnCashPay float64 `json:"psn_cash_pay"`
  9311. PsnCertType string `json:"psn_cert_type"`
  9312. PsnName string `json:"psn_name"`
  9313. PsnNo string `json:"psn_no"`
  9314. PsnPartAmt float64 `json:"psn_part_amt"`
  9315. PsnType string `json:"psn_type"`
  9316. SetlID string `json:"setl_id"`
  9317. SetlTime string `json:"setl_time"`
  9318. } `json:"setlinfo"`
  9319. } `json:"output"`
  9320. RefmsgTime string `json:"refmsg_time"`
  9321. RespondTime string `json:"respond_time"`
  9322. Signtype interface{} `json:"signtype"`
  9323. WarnMsg interface{} `json:"warn_msg"`
  9324. }
  9325. type ResultEight struct {
  9326. Cainfo string `json:"cainfo"`
  9327. ErrMsg string `json:"err_msg"`
  9328. InfRefmsgid string `json:"inf_refmsgid"`
  9329. Infcode int64 `json:"infcode"`
  9330. Output struct {
  9331. Stmtinfo struct {
  9332. SetlOptins string `json:"setl_optins"`
  9333. StmtRslt string `json:"stmt_rslt"`
  9334. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9335. } `json:"stmtinfo"`
  9336. } `json:"output"`
  9337. RefmsgTime string `json:"refmsg_time"`
  9338. RespondTime string `json:"respond_time"`
  9339. Signtype interface{} `json:"signtype"`
  9340. WarnMsg interface{} `json:"warn_msg"`
  9341. }
  9342. type ResultNine struct {
  9343. Cainfo string `json:"cainfo"`
  9344. ErrMsg string `json:"err_msg"`
  9345. InfRefmsgid string `json:"inf_refmsgid"`
  9346. Infcode int64 `json:"infcode"`
  9347. Output struct {
  9348. FileQuryNo string `json:"file_qury_no"`
  9349. } `json:"output"`
  9350. RefmsgTime string `json:"refmsg_time"`
  9351. RespondTime string `json:"respond_time"`
  9352. Signtype interface{} `json:"signtype"`
  9353. WarnMsg interface{} `json:"warn_msg"`
  9354. }
  9355. type ResultTen struct {
  9356. Cainfo string `json:"cainfo"`
  9357. ErrMsg string `json:"err_msg"`
  9358. InfRefmsgid string `json:"inf_refmsgid"`
  9359. Infcode int64 `json:"infcode"`
  9360. Output struct {
  9361. DldEndtime string `json:"dld_endtime"`
  9362. FileQuryNo string `json:"file_qury_no"`
  9363. Filename string `json:"filename"`
  9364. } `json:"output"`
  9365. RefmsgTime string `json:"refmsg_time"`
  9366. RespondTime string `json:"respond_time"`
  9367. Signtype interface{} `json:"signtype"`
  9368. WarnMsg interface{} `json:"warn_msg"`
  9369. }
  9370. type ResultEleven struct {
  9371. Cainfo string `json:"cainfo"`
  9372. ErrMsg string `json:"err_msg"`
  9373. InfRefmsgid string `json:"inf_refmsgid"`
  9374. Infcode int64 `json:"infcode"`
  9375. Output struct {
  9376. Setlinfo struct {
  9377. FixmedinsName string `json:"fixmedins_name"`
  9378. FixmedinsCode string `json:"fixmedins_code"`
  9379. PsnNo string `json:"psn_no"`
  9380. PsnName string `json:"psn_name"`
  9381. HifobPay float64 `json:"hifob_pay"`
  9382. Gend string `json:"gend"`
  9383. Brdy string `json:"brdy"`
  9384. PsnCertType string `json:"psn_cert_type"`
  9385. PsnType string `json:"psn_type"`
  9386. EmpName string `json:"emp_name"`
  9387. Certno string `json:"certno"`
  9388. Insutype string `json:"insutype"`
  9389. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9390. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9391. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9392. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9393. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9394. ActPayDedc float64 `json:"act_pay_dedc"`
  9395. HifpPay float64 `json:"hifp_pay"`
  9396. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9397. CvlservPay float64 `json:"cvlserv_pay"`
  9398. HifesPay float64 `json:"hifes_pay"`
  9399. HifmiPay float64 `json:"hifmi_pay"`
  9400. MafPay float64 `json:"maf_pay"`
  9401. OthPay float64 `json:"oth_pay"`
  9402. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9403. PsnPay float64 `json:"psn_pay"`
  9404. AcctPay float64 `json:"acct_pay"`
  9405. CashPayamt float64 `json:"cash_payamt"`
  9406. Balc float64 `json:"balc"`
  9407. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9408. MedinsSetlId string `json:"medins_setl_id"`
  9409. RefdSetlFlag string `json:"refd_setl_flag"`
  9410. SetlTime string `json:"setl_time"`
  9411. MedType string `json:"med_type"`
  9412. } `json:"setlinfo"`
  9413. } `json:"output"`
  9414. RefmsgTime string `json:"refmsg_time"`
  9415. RespondTime string `json:"respond_time"`
  9416. Signtype interface{} `json:"signtype"`
  9417. WarnMsg interface{} `json:"warn_msg"`
  9418. }
  9419. type Custom struct {
  9420. DetItemFeeSumamt string
  9421. Cut string
  9422. FeedetlSn string
  9423. Price string
  9424. MedListCodg string
  9425. Type int64
  9426. AdviceId int64
  9427. ProjectId int64
  9428. ItemId int64
  9429. CostType int64
  9430. }
  9431. // 获取个人信息----挂号-----上传就诊信息
  9432. func (c *HisApiController) GetRegisterInfo() {
  9433. id, _ := c.GetInt64("id")
  9434. record_time := c.GetString("record_time")
  9435. settlementValue, _ := c.GetInt64("settlement_value")
  9436. medical_insurance_card := c.GetString("medical_insurance_card")
  9437. name := c.GetString("name")
  9438. id_card_type, _ := c.GetInt64("id_card_type")
  9439. certificates, _ := c.GetInt64("certificates")
  9440. medical_care, _ := c.GetInt64("medical_care")
  9441. birthday := c.GetString("birthday")
  9442. age, _ := c.GetInt64("age")
  9443. id_card := c.GetString("id_card")
  9444. register_type, _ := c.GetInt64("register")
  9445. doctor, _ := c.GetInt64("doctor")
  9446. department, _ := c.GetInt64("department")
  9447. gender, _ := c.GetInt64("sex")
  9448. phone := c.GetString("phone")
  9449. registration_fee, _ := c.GetFloat("registration_fee")
  9450. medical_expenses, _ := c.GetFloat("medical_expenses")
  9451. social_type, _ := c.GetInt64("social_type")
  9452. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9453. diagnosis_ids := c.GetString("diagnosis")
  9454. sick_type, _ := c.GetInt64("sick_type")
  9455. reg_type := c.GetString("p_type")
  9456. timeLayout := "2006-01-02"
  9457. loc, _ := time.LoadLocation("Local")
  9458. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9459. birthUnix := birthdays.Unix()
  9460. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9461. if err != nil {
  9462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9463. return
  9464. }
  9465. recordDateTime := theTime.Unix()
  9466. adminInfo := c.GetAdminUserInfo()
  9467. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9468. if tempPatient.ID == 0 {
  9469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9470. return
  9471. }
  9472. var patient service.Patients
  9473. if id == 0 {
  9474. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9475. } else {
  9476. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9477. }
  9478. if patient.ID == 0 {
  9479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9480. return
  9481. }
  9482. if len(patient.IdCardNo) == 0 {
  9483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9484. return
  9485. }
  9486. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9487. if len(his) >= 1 {
  9488. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9489. if len(his) >= 1 && order.ID == 0 {
  9490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9491. return
  9492. }
  9493. }
  9494. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9495. fmt.Println(timeStr)
  9496. timeArr := strings.Split(timeStr, " ")
  9497. fmt.Println(timeArr)
  9498. timeArrTwo := strings.Split(timeArr[0], "-")
  9499. timeArrThree := strings.Split(timeArr[1], ":")
  9500. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9501. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9502. if len(lists) == 0 {
  9503. var hisPatient models.XtHisPatient
  9504. hisPatient = models.XtHisPatient{
  9505. Name: name,
  9506. Age: age,
  9507. Gender: gender,
  9508. Birthday: birthUnix,
  9509. Phone: phone,
  9510. MedicalTreatmentType: medical_care,
  9511. IdType: certificates,
  9512. IdCardNo: id_card,
  9513. BalanceAccountsType: settlementValue,
  9514. SocialType: social_type,
  9515. MedicalInsuranceNumber: medical_insurance_card,
  9516. RegisterType: register_type,
  9517. RegisterCost: registration_fee,
  9518. TreatmentCost: medical_expenses,
  9519. AdminUserId: adminInfo.AdminUser.Id,
  9520. UserOrgId: adminInfo.CurrentOrgId,
  9521. Status: 1,
  9522. RecordDate: recordDateTime,
  9523. IsReturn: 1,
  9524. PatientId: patient.ID,
  9525. Ctime: time.Now().Unix(),
  9526. Mtime: time.Now().Unix(),
  9527. Number: str,
  9528. IdCardType: id_card_type,
  9529. Departments: department,
  9530. Doctor: doctor,
  9531. PType: reg_type,
  9532. Diagnosis: diagnosis_ids,
  9533. SickType: sick_type,
  9534. }
  9535. service.CreateHisPatient(&hisPatient)
  9536. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9537. c.ServeSuccessJSON(map[string]interface{}{
  9538. "his_info": hisPatient,
  9539. })
  9540. } else {
  9541. //chrgBchno := rand.Intn(1000000) + 10000
  9542. var hisPatient models.XtHisPatient
  9543. hisPatient = models.XtHisPatient{
  9544. Name: name,
  9545. Age: age,
  9546. Gender: gender,
  9547. Birthday: birthUnix,
  9548. Phone: phone,
  9549. MedicalTreatmentType: medical_care,
  9550. IdType: certificates,
  9551. IdCardNo: id_card,
  9552. BalanceAccountsType: settlementValue,
  9553. SocialType: social_type,
  9554. MedicalInsuranceNumber: medical_insurance_card,
  9555. RegisterType: register_type,
  9556. RegisterCost: registration_fee,
  9557. TreatmentCost: medical_expenses,
  9558. AdminUserId: adminInfo.AdminUser.Id,
  9559. UserOrgId: adminInfo.CurrentOrgId,
  9560. Status: 1,
  9561. RecordDate: recordDateTime,
  9562. IsReturn: 1,
  9563. PatientId: patient.ID,
  9564. Ctime: time.Now().Unix(),
  9565. Mtime: time.Now().Unix(),
  9566. Number: str,
  9567. IdCardType: id_card_type,
  9568. Departments: department,
  9569. Doctor: doctor,
  9570. PType: reg_type,
  9571. Diagnosis: diagnosis_ids,
  9572. SickType: sick_type,
  9573. }
  9574. service.CreateHisPatient(&hisPatient)
  9575. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9576. c.ServeSuccessJSON(map[string]interface{}{
  9577. "his_info": hisPatient,
  9578. })
  9579. }
  9580. }
  9581. // 上传明细----结算
  9582. func (c *HisApiController) GetUploadInfo() {
  9583. id, _ := c.GetInt64("id")
  9584. record_time := c.GetString("record_time")
  9585. his_patient_id, _ := c.GetInt64("his_patient_id")
  9586. oth_desc := c.GetString("oth_desc")
  9587. pay_way, _ := c.GetInt64("pay_way")
  9588. pay_ways := c.GetString("pay_ways")
  9589. pay_price, _ := c.GetFloat("pay_price")
  9590. pay_card_no := c.GetString("pay_card_no")
  9591. discount_price, _ := c.GetFloat("discount_price")
  9592. preferential_price, _ := c.GetFloat("preferential_price")
  9593. reality_price, _ := c.GetFloat("reality_price")
  9594. found_price, _ := c.GetFloat("found_price")
  9595. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9596. private_price, _ := c.GetFloat("private_price")
  9597. timeLayout := "2006-01-02"
  9598. loc, _ := time.LoadLocation("Local")
  9599. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9600. fapiao_code := c.GetString("fapiao_code")
  9601. fapiao_number := c.GetString("fapiao_number")
  9602. diagnosis_id := c.GetString("diagnosis")
  9603. sick_type, _ := c.GetInt64("sick_type")
  9604. reg_type, _ := c.GetInt64("p_type")
  9605. order_id, _ := c.GetInt64("order_id")
  9606. cash_pay := c.GetString("cash_pay")
  9607. wechat_pay := c.GetString("wechat_pay")
  9608. ali_pay := c.GetString("ali_pay")
  9609. jifen_pay := c.GetString("jifen_pay")
  9610. card_desc := c.GetString("card_desc")
  9611. band_card_pay := c.GetString("band_card_pay")
  9612. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9613. tmp_decimal := c.GetString("tmp_decimal")
  9614. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9615. var decimal float64 //本次使用的押金
  9616. var errmsg error
  9617. tx := service.XTWriteDB().Begin() //开了事务
  9618. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9619. defer func() {
  9620. if errmsg != nil {
  9621. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9622. tx.Rollback()
  9623. } else {
  9624. tx.Commit()
  9625. }
  9626. }()
  9627. fmt.Println("dec_way", dec_way)
  9628. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9629. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9630. return
  9631. }
  9632. if len(tmp_decimal) > 0 {
  9633. if tmp_decimal[0] == 45 {
  9634. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9635. return
  9636. }
  9637. }
  9638. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9639. fmt.Println(errs)
  9640. decimal = tt
  9641. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9642. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9643. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9644. if err != nil {
  9645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9646. return
  9647. }
  9648. recordDateTime := theTime.Unix()
  9649. adminUser := c.GetAdminUserInfo()
  9650. var prescriptions []*models.HisPrescription
  9651. var prescriptionsOne []*models.HisPrescription
  9652. var start_time int64
  9653. var end_time int64
  9654. ids_str := c.GetString("ids")
  9655. ids_arr := strings.Split(ids_str, ",")
  9656. if tempOrder.ID == 0 {
  9657. if settle_accounts_type == 1 { //日结
  9658. fmt.Println(reg_type)
  9659. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9660. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9661. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9662. } else {
  9663. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9664. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9665. }
  9666. } else { //月结
  9667. start_time_str := c.GetString("start_time")
  9668. end_time_str := c.GetString("end_time")
  9669. timeLayout := "2006-01-02"
  9670. loc, _ := time.LoadLocation("Local")
  9671. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9672. if err != nil {
  9673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9674. return
  9675. }
  9676. recordStartTime := theStartTime.Unix()
  9677. start_time = recordStartTime
  9678. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9679. if err != nil {
  9680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9681. return
  9682. }
  9683. recordEndTime := theEndTime.Unix()
  9684. end_time = recordEndTime
  9685. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9686. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9687. }
  9688. var goods []*models.DialysisBeforePrepareGoods
  9689. var newGoods []*models.NewDialysisBeforePrepareGoods
  9690. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9691. var infos []*models.HisDoctorAdviceInfo
  9692. var infoList []*models.HisDoctorAdviceInfo
  9693. var hisAdvice []*models.HisDoctorAdviceInfo
  9694. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9695. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9696. //判断库存不足
  9697. //结算出库开关
  9698. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9699. if settConfig.IsOpen == 1 {
  9700. //判断库存的地方
  9701. for _, info := range prescriptions {
  9702. if info.Type == 1 {
  9703. infos = append(infos, info.HisDoctorAdviceInfo...)
  9704. }
  9705. if info.Type == 2 {
  9706. for _, sumItem := range info.HisPrescriptionProject {
  9707. if sumItem.Type == 3 {
  9708. var good models.DialysisBeforePrepareGoods
  9709. var newGood models.NewDialysisBeforePrepareGoods
  9710. good.GoodId = sumItem.GoodInfo.ID
  9711. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9712. count, _ := strconv.Atoi(sumItem.Count)
  9713. good.Count = int64(count)
  9714. good.StorehouseId = houseConfig.StorehouseOutInfo
  9715. good.ProjectId = sumItem.ID
  9716. goods = append(goods, &good)
  9717. newGood.GoodId = sumItem.GoodInfo.ID
  9718. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9719. count2, _ := strconv.Atoi(sumItem.Count)
  9720. newGood.Count = int64(count2)
  9721. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9722. newGood.ProjectId = sumItem.ID
  9723. newGoods = append(newGoods, &newGood)
  9724. }
  9725. }
  9726. }
  9727. }
  9728. for _, info := range prescriptionsOne {
  9729. if info.Type == 1 {
  9730. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9731. }
  9732. if info.Type == 2 {
  9733. for _, sumItem := range info.HisPrescriptionProject {
  9734. if sumItem.Type == 3 {
  9735. var newGood models.NewDialysisBeforePrepareGoods
  9736. newGood.GoodId = sumItem.GoodInfo.ID
  9737. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9738. count2, _ := strconv.Atoi(sumItem.Count)
  9739. newGood.Count = int64(count2)
  9740. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9741. newGood.ProjectId = sumItem.ID
  9742. newGoodOne = append(newGoodOne, &newGood)
  9743. }
  9744. }
  9745. }
  9746. }
  9747. //判断
  9748. for _, itemOne := range infos {
  9749. for _, itemTwo := range hisAdvice {
  9750. if itemOne.DrugId == itemTwo.DrugId {
  9751. itemTwo.Child = append(itemTwo.Child, itemOne)
  9752. }
  9753. }
  9754. }
  9755. for _, itemTwo := range hisAdvice {
  9756. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9757. var sum_out_count int64
  9758. for _, itemThree := range itemTwo.Child {
  9759. var prescribing_number int64
  9760. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9761. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9762. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9763. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9764. }
  9765. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9766. prescribing_number = parseIntPrescribingNumber
  9767. }
  9768. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9769. prescribing_number = parseIntPrescribingNumber
  9770. }
  9771. sum_out_count += prescribing_number
  9772. }
  9773. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9774. if sum_out_count > drugStockOut.FlushCount {
  9775. c.ServeSuccessJSON(map[string]interface{}{
  9776. "msg": "2",
  9777. "drug": medical,
  9778. })
  9779. return
  9780. }
  9781. }
  9782. for _, itemOne := range newGoods {
  9783. for _, item := range newGoodOne {
  9784. if itemOne.GoodId == item.GoodId {
  9785. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9786. }
  9787. }
  9788. }
  9789. for _, item := range newGoodOne {
  9790. var sum_out_count_one int64
  9791. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9792. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9793. sum_out_count_one += itemOne.Count
  9794. }
  9795. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9796. fmt.Println("sum_out_count_one", sum_out_count_one)
  9797. fmt.Println("list.FlushCount", list.FlushCount)
  9798. if sum_out_count_one > list.FlushCount {
  9799. c.ServeSuccessJSON(map[string]interface{}{
  9800. "msg": "3",
  9801. "good": good,
  9802. })
  9803. return
  9804. }
  9805. }
  9806. }
  9807. timestamp := time.Now().Unix()
  9808. tempTime := time.Unix(timestamp, 0)
  9809. timeFormat := tempTime.Format("20060102150405")
  9810. chrgBchno := rand.Intn(100000) + 10000
  9811. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9812. strconv.FormatInt(his.PatientId, 10)
  9813. var ids []int64
  9814. for _, item := range prescriptions {
  9815. ids = append(ids, item.ID)
  9816. }
  9817. var total float64
  9818. for _, item := range prescriptions {
  9819. fmt.Println(item)
  9820. if item.Type == 1 { //药品
  9821. for _, subItem := range item.HisDoctorAdviceInfo {
  9822. if subItem.Drug.IsUser != 1 {
  9823. total = total + (subItem.Price * subItem.PrescribingNumber)
  9824. }
  9825. }
  9826. }
  9827. if item.Type == 2 { //项目
  9828. for _, subItem := range item.HisPrescriptionProject {
  9829. if subItem.Type == 2 {
  9830. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9831. total = total + (subItem.Price * cnt)
  9832. } else {
  9833. if subItem.GoodInfo.IsUser != 1 {
  9834. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9835. total = total + (subItem.Price * cnt)
  9836. }
  9837. }
  9838. }
  9839. }
  9840. for _, subItem := range item.HisAdditionalCharge {
  9841. total = total + (subItem.Price * float64(subItem.Count))
  9842. }
  9843. }
  9844. if reg_type == 1111 || reg_type == 1112 {
  9845. reg_type = 11
  9846. }
  9847. tm := time.Unix(time.Now().Unix(), 0)
  9848. allTotal := fmt.Sprintf("%.4f", total)
  9849. totals, _ := strconv.ParseFloat(allTotal, 64)
  9850. order := &models.HisOrder{
  9851. UserOrgId: adminUser.CurrentOrgId,
  9852. HisPatientId: his.ID,
  9853. PatientId: id,
  9854. SettleAccountsDate: recordDateTime,
  9855. Ctime: time.Now().Unix(),
  9856. Mtime: time.Now().Unix(),
  9857. Status: 1,
  9858. OrderStatus: 2,
  9859. MdtrtId: his.Number,
  9860. Number: chrg_bchno,
  9861. MedfeeSumamt: totals,
  9862. PayWay: pay_way,
  9863. PayWays: pay_ways,
  9864. PayPrice: pay_price,
  9865. MedType: strconv.Itoa(int(reg_type)),
  9866. PayCardNo: pay_card_no,
  9867. DiscountPrice: discount_price,
  9868. PreferentialPrice: preferential_price,
  9869. RealityPrice: reality_price,
  9870. FoundPrice: found_price,
  9871. MedicalInsurancePrice: medical_insurance_price,
  9872. PrivatePrice: private_price,
  9873. SettleEndTime: end_time,
  9874. SettleStartTime: start_time,
  9875. PsnPartAmt: totals,
  9876. PsnCashPay: totals,
  9877. SettleType: settle_accounts_type,
  9878. FaPiaoCode: fapiao_code,
  9879. FaPiaoNumber: fapiao_number,
  9880. Diagnosis: diagnosis_id,
  9881. PType: 2,
  9882. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9883. Decimal: decimal,
  9884. OthDesc: oth_desc,
  9885. CashPay: cash_pay,
  9886. WechatPay: wechat_pay,
  9887. AliPay: ali_pay,
  9888. JifenPay: jifen_pay,
  9889. BandCardPay: band_card_pay,
  9890. Creator: adminUser.AdminUser.Id,
  9891. CardDesc: card_desc,
  9892. }
  9893. err = service.CreateOrderTX(order, tx)
  9894. if err != nil {
  9895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9896. return
  9897. }
  9898. var customs []*Custom
  9899. for _, item := range prescriptions {
  9900. if item.Type == 1 { //药品a
  9901. for _, subItem := range item.HisDoctorAdviceInfo {
  9902. if subItem.Drug.IsUser != 1 {
  9903. cus := &Custom{
  9904. AdviceId: subItem.ID,
  9905. ProjectId: 0,
  9906. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9907. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9908. FeedetlSn: subItem.FeedetlSn,
  9909. Price: fmt.Sprintf("%.4f", subItem.Price),
  9910. MedListCodg: subItem.MedListCodg,
  9911. Type: 1,
  9912. CostType: 9,
  9913. }
  9914. customs = append(customs, cus)
  9915. }
  9916. }
  9917. }
  9918. if item.Type == 2 { //项目
  9919. for _, subItem := range item.HisPrescriptionProject {
  9920. if subItem.Type == 2 {
  9921. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9922. cus := &Custom{
  9923. AdviceId: 0,
  9924. ProjectId: subItem.ID,
  9925. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9926. Cut: fmt.Sprintf("%.4f", cnt),
  9927. FeedetlSn: subItem.FeedetlSn,
  9928. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9929. MedListCodg: subItem.MedListCodg,
  9930. Type: 2,
  9931. CostType: subItem.HisProject.CostClassify,
  9932. }
  9933. customs = append(customs, cus)
  9934. } else {
  9935. if subItem.GoodInfo.IsUser != 1 {
  9936. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9937. cus := &Custom{
  9938. AdviceId: 0,
  9939. ProjectId: subItem.ID,
  9940. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9941. Cut: fmt.Sprintf("%.4f", cnt),
  9942. FeedetlSn: subItem.FeedetlSn,
  9943. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9944. MedListCodg: subItem.MedListCodg,
  9945. Type: 2,
  9946. CostType: subItem.HisProject.CostClassify,
  9947. }
  9948. customs = append(customs, cus)
  9949. }
  9950. }
  9951. }
  9952. }
  9953. for _, item := range item.HisAdditionalCharge {
  9954. cus := &Custom{
  9955. ItemId: item.ID,
  9956. AdviceId: 0,
  9957. ProjectId: 0,
  9958. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9959. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9960. FeedetlSn: item.FeedetlSn,
  9961. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9962. MedListCodg: item.XtHisAddtionConfig.Code,
  9963. Type: 3,
  9964. CostType: 5,
  9965. }
  9966. customs = append(customs, cus)
  9967. }
  9968. }
  9969. for _, item := range customs {
  9970. var advice_id int64 = 0
  9971. var project_id int64 = 0
  9972. var item_id int64 = 0
  9973. var types int64 = 0
  9974. var med_chrgitm_type string
  9975. if item.Type == 1 {
  9976. advice_id = item.AdviceId
  9977. project_id = 0
  9978. item_id = 0
  9979. med_chrgitm_type = "09"
  9980. } else if item.Type == 2 {
  9981. med_chrgitm_type = "05"
  9982. if item.CostType == 3 {
  9983. med_chrgitm_type = "04"
  9984. }
  9985. if item.CostType == 8 {
  9986. med_chrgitm_type = "03"
  9987. }
  9988. advice_id = 0
  9989. item_id = 0
  9990. project_id = item.ProjectId
  9991. } else if item.Type == 3 {
  9992. advice_id = 0
  9993. item_id = item.ItemId
  9994. project_id = 0
  9995. med_chrgitm_type = "08"
  9996. }
  9997. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9998. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9999. pric, _ := strconv.ParseFloat(item.Price, 32)
  10000. info := &models.HisOrderInfo{
  10001. OrderNumber: order.Number,
  10002. UploadDate: time.Now().Unix(),
  10003. AdviceId: advice_id,
  10004. DetItemFeeSumamt: detItemFeeSumamt,
  10005. MedChrgitmType: med_chrgitm_type,
  10006. Cnt: cut,
  10007. Pric: pric,
  10008. PatientId: id,
  10009. Status: 1,
  10010. Mtime: time.Now().Unix(),
  10011. Ctime: time.Now().Unix(),
  10012. UserOrgId: adminUser.CurrentOrgId,
  10013. HisPatientId: his.ID,
  10014. OrderId: order.ID,
  10015. ProjectId: project_id,
  10016. Type: types,
  10017. ItemId: item_id,
  10018. }
  10019. service.CreateOrderInfoTX(info, tx)
  10020. }
  10021. his.Diagnosis = diagnosis_id
  10022. his.SickType = sick_type
  10023. his.RegisterType = reg_type
  10024. his.MedicalTreatmentType = reg_type
  10025. service.UpdataHisPateintTX(&his, tx)
  10026. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  10027. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  10028. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  10029. //判断是否使用了押金
  10030. if dec_way == "true" {
  10031. tmpstring := strconv.FormatInt(order.ID, 10)
  10032. //扣押金
  10033. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  10034. order.Decimal = decimal
  10035. service.UpDateOrderTwo(order, tx)
  10036. if errmsg != nil {
  10037. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  10038. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10039. return
  10040. }
  10041. }
  10042. if err == nil {
  10043. for _, info := range prescriptions {
  10044. if info.Type == 1 {
  10045. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  10046. }
  10047. if info.Type == 2 {
  10048. for _, sumItem := range info.HisPrescriptionProject {
  10049. if sumItem.Type == 3 {
  10050. var good models.DialysisBeforePrepareGoods
  10051. var newGood models.NewDialysisBeforePrepareGoods
  10052. var oldGood models.OldDialysisBeforePrepareGoods
  10053. good.GoodId = sumItem.GoodInfo.ID
  10054. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10055. count, _ := strconv.Atoi(sumItem.Count)
  10056. good.Count = int64(count)
  10057. good.StorehouseId = houseConfig.StorehouseOutInfo
  10058. good.ProjectId = sumItem.ID
  10059. good.PatientId = sumItem.PatientId
  10060. goods = append(goods, &good)
  10061. newGood.GoodId = sumItem.GoodInfo.ID
  10062. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10063. count2, _ := strconv.Atoi(sumItem.Count)
  10064. newGood.Count = int64(count2)
  10065. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10066. newGood.ProjectId = sumItem.ID
  10067. newGood.PatientId = sumItem.HisPatientId
  10068. newGoods = append(newGoods, &newGood)
  10069. oldGood.GoodId = sumItem.GoodInfo.ID
  10070. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10071. count3, _ := strconv.Atoi(sumItem.Count)
  10072. oldGood.Count = int64(count3)
  10073. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  10074. oldGood.ProjectId = sumItem.ID
  10075. oldGood.RecordDate = sumItem.RecordDate
  10076. oldGood.PatientId = sumItem.HisPatientId
  10077. oldGoods = append(oldGoods, &oldGood)
  10078. }
  10079. }
  10080. }
  10081. }
  10082. if settConfig.IsOpen == 1 {
  10083. for _, item := range infoList {
  10084. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  10085. if medical.IsUse == 2 {
  10086. //药品出库
  10087. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  10088. //查询默认仓库
  10089. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  10090. //查询默认仓库剩余多少库存
  10091. var sum_count int64
  10092. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  10093. for _, its := range stockInfo {
  10094. if its.MaxUnit == medical.MaxUnit {
  10095. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  10096. }
  10097. sum_count += its.StockMaxNumber + its.StockMinNumber
  10098. }
  10099. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  10100. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  10101. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  10102. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  10103. }
  10104. }
  10105. orgId := c.GetAdminUserInfo().CurrentOrgId
  10106. if len(oldGoods) > 0 {
  10107. timeStr := time.Now().Format("2006-01-02")
  10108. timeArr := strings.Split(timeStr, "-")
  10109. total, _ := service.FindAllWarehouseOut(orgId)
  10110. total = total + 1
  10111. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  10112. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  10113. number = number + total
  10114. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  10115. operation_time := time.Now().Unix()
  10116. creater := c.GetAdminUserInfo().AdminUser.Id
  10117. //查询默认出库仓库库存
  10118. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  10119. recordDateStr := time.Now().Format("2006-01-02")
  10120. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  10121. nowtime := recordDate.Unix()
  10122. warehouseOut := models.WarehouseOut{
  10123. WarehouseOutOrderNumber: warehousing_out_order,
  10124. OperationTime: operation_time,
  10125. OrgId: orgId,
  10126. Creater: creater,
  10127. Ctime: time.Now().Unix(),
  10128. Status: 1,
  10129. WarehouseOutTime: nowtime,
  10130. Type: 1,
  10131. StorehouseId: storeConfig.StorehouseOutInfo,
  10132. IsCheck: 1,
  10133. OrderId: order.ID,
  10134. IsSys: 5,
  10135. }
  10136. //查询是否生成出库单
  10137. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10138. if out.ID == 0 {
  10139. service.AddSigleWarehouseOutOne(&warehouseOut)
  10140. }
  10141. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10142. for _, item := range oldGoods {
  10143. dialyPrepareOne := models.DialysisBeforePrepare{
  10144. GoodTypeId: item.GoodTypeId,
  10145. GoodId: item.GoodId,
  10146. PatientId: his.PatientId,
  10147. RecordDate: item.RecordDate,
  10148. UserOrgId: adminUser.CurrentOrgId,
  10149. Count: item.Count,
  10150. Ctime: time.Now().Unix(),
  10151. Creater: adminUser.AdminUser.Id,
  10152. CommdityCode: item.CommdityCode,
  10153. Status: 1,
  10154. StorehouseId: houseConfig.StorehouseOutInfo,
  10155. }
  10156. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  10157. //非零用
  10158. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  10159. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10160. //查询剩余库存
  10161. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10162. var sum_count int64
  10163. for _, item := range goodList {
  10164. sum_count += item.StockCount
  10165. }
  10166. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10167. //耗材
  10168. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10169. }
  10170. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  10171. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10172. //查询剩余库存
  10173. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10174. var sum_count int64
  10175. for _, item := range goodList {
  10176. sum_count += item.StockCount
  10177. }
  10178. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10179. //耗材
  10180. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10181. }
  10182. }
  10183. }
  10184. }
  10185. c.ServeSuccessJSON(map[string]interface{}{
  10186. "msg": "结算成功",
  10187. })
  10188. }
  10189. }
  10190. }
  10191. // 退款
  10192. func (c *HisApiController) Refund() {
  10193. order_id, _ := c.GetInt64("order_id")
  10194. order, _ := service.GetHisOrderByID(order_id)
  10195. adminUser := c.GetAdminUserInfo()
  10196. orgid := c.GetAdminUserInfo().CurrentOrgId
  10197. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  10198. if err != nil {
  10199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10200. return
  10201. }
  10202. tmp := strconv.FormatInt(order.ID, 10)
  10203. //当押金不为零时产生退费记录
  10204. if order.Decimal != 0 {
  10205. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  10206. if err != nil {
  10207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10208. return
  10209. }
  10210. }
  10211. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  10212. if fapiao.ID > 0 {
  10213. c.ServeSuccessJSON(map[string]interface{}{
  10214. "failed_code": -10,
  10215. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  10216. })
  10217. return
  10218. }
  10219. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  10220. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  10221. var goods []*models.DialysisBeforePrepareGoods
  10222. var newGoods []*models.NewDialysisBeforePrepareGoods
  10223. var infos []*models.HisDoctorAdviceInfo
  10224. for _, info := range orders {
  10225. if info.AdviceId > 0 && info.ProjectId == 0 {
  10226. infos = append(infos, &info.HisDoctorAdviceInfo)
  10227. }
  10228. if info.ProjectId > 0 && info.AdviceId == 0 {
  10229. if info.HisPrescriptionProject.Type == 3 {
  10230. var good models.DialysisBeforePrepareGoods
  10231. var newGood models.NewDialysisBeforePrepareGoods
  10232. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10233. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10234. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10235. good.Count = int64(count)
  10236. good.StorehouseId = houseConfig.StorehouseOutInfo
  10237. good.ProjectId = info.HisPrescriptionProject.ID
  10238. good.PatientId = info.PatientId
  10239. good.OrderId = order_id
  10240. goods = append(goods, &good)
  10241. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10242. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10243. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10244. newGood.Count = int64(count2)
  10245. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10246. newGood.ProjectId = info.HisPrescriptionProject.ID
  10247. newGood.RecordDate = order.SettleAccountsDate
  10248. newGood.UserOrgId = order.UserOrgId
  10249. newGood.PatientId = info.PatientId
  10250. newGood.OrderId = order_id
  10251. newGoods = append(newGoods, &newGood)
  10252. }
  10253. }
  10254. }
  10255. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10256. if settConfig.IsOpen == 1 {
  10257. for _, item := range infos {
  10258. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10259. }
  10260. for _, item := range newGoods {
  10261. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10262. }
  10263. }
  10264. c.ServeSuccessJSON(map[string]interface{}{
  10265. "msg": "退费成功",
  10266. })
  10267. }
  10268. func (c *HisApiController) RefundNumber() {
  10269. his_patient_id, _ := c.GetInt64("id")
  10270. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10271. info.Status = 0
  10272. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10273. if count > 0 {
  10274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10275. return
  10276. }
  10277. err := service.SaveHisPatient(info)
  10278. if err == nil {
  10279. c.ServeSuccessJSON(map[string]interface{}{
  10280. "msg": "退号成功",
  10281. })
  10282. } else {
  10283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10284. return
  10285. }
  10286. }
  10287. func (this *HisApiController) AdditionalCharge() {
  10288. dataBody := make(map[string]interface{}, 0)
  10289. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10290. fmt.Println(err)
  10291. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10292. patient_id := int64(dataBody["patient_id"].(float64))
  10293. medicineData, _ := dataBody["medicineData"].([]interface{})
  10294. adminUserInfo := this.GetAdminUserInfo()
  10295. orgId := adminUserInfo.CurrentOrgId
  10296. admin_user_id := adminUserInfo.AdminUser.Id
  10297. timeStr := time.Now().Format("2006-01-02")
  10298. timeLayout := "2006-01-02 15:04:05"
  10299. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10300. timenow := timeStringToTime.Unix()
  10301. var additionalCharges []*models.HisAdditionalCharge
  10302. for _, item := range medicineData {
  10303. var randNum int
  10304. randNum = rand.Intn(10000) + 1000
  10305. timestamp := time.Now().Unix()
  10306. tempTime := time.Unix(timestamp, 0)
  10307. timeFormat := tempTime.Format("20060102150405")
  10308. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10309. items := item.(map[string]interface{})
  10310. money := items["price"].(string)
  10311. item_id_str := items["item_id"].(string)
  10312. name := items["name"].(string)
  10313. id_str := items["id"].(string)
  10314. moneys, _ := strconv.ParseInt(money, 10, 64)
  10315. monStr := strconv.FormatInt(moneys, 10)
  10316. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10317. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10318. id, _ := strconv.ParseInt(id_str, 10, 64)
  10319. additionalCharge := &models.HisAdditionalCharge{
  10320. ID: id,
  10321. HisPatientId: his_patient_id,
  10322. UserOrgId: orgId,
  10323. PatientId: patient_id,
  10324. RecordDate: timenow,
  10325. Price: monneyStr,
  10326. Status: 1,
  10327. ItemName: name,
  10328. ItemId: item_id,
  10329. AdminUserId: admin_user_id,
  10330. CreatedTime: time.Now().Unix(),
  10331. OrderStatus: 0,
  10332. PrescriptionNumber: "",
  10333. BatchNumber: "",
  10334. FeedetlSn: p_number,
  10335. }
  10336. service.CreateAdditionalCharge(additionalCharge)
  10337. additionalCharges = append(additionalCharges, additionalCharge)
  10338. }
  10339. this.ServeSuccessJSON(map[string]interface{}{
  10340. "msg": "添加成功",
  10341. "additional_charges": additionalCharges,
  10342. })
  10343. }
  10344. func (this *HisApiController) DeleteAddition() {
  10345. id, _ := this.GetInt64("id")
  10346. //TODO 需要判断是否已经结算
  10347. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10348. if err == nil {
  10349. this.ServeSuccessJSON(map[string]interface{}{
  10350. "msg": "删除成功",
  10351. })
  10352. return
  10353. } else {
  10354. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10355. return
  10356. }
  10357. }
  10358. func (this *HisApiController) GetAdminUsers() {
  10359. adminUser := this.GetAdminUserInfo()
  10360. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10361. this.ServeSuccessJSON(map[string]interface{}{
  10362. "doctors": doctors,
  10363. })
  10364. }
  10365. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10366. change_type, _ := this.GetInt64("type", 0)
  10367. record_date := this.GetString("record_time")
  10368. patient_id, _ := this.GetInt64("patient_id", 0)
  10369. p_type, _ := this.GetInt64("p_type", 0)
  10370. timeLayout := "2006-01-02"
  10371. loc, _ := time.LoadLocation("Local")
  10372. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10373. record_time := theAdviceRecordTime.Unix()
  10374. adminUserInfo := this.GetAdminUserInfo()
  10375. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10376. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10377. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10378. if config.ID > 0 && config.IsOpen == 1 {
  10379. for _, subitems := range prescriptions {
  10380. for _, item := range subitems.VMHisPrescription {
  10381. for _, subItem := range item.HisDoctorAdviceInfo {
  10382. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10383. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10384. if info.RetailPrice > 0 {
  10385. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10386. subItem.Drug.RetailPrice = drug.RetailPrice
  10387. }
  10388. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10389. subItem.Drug.MinPrice = info.RetailPrice
  10390. subItem.Drug.RetailPrice = info.RetailPrice
  10391. }
  10392. }
  10393. }
  10394. }
  10395. }
  10396. }
  10397. if config.ID > 0 && config.IsOpen == 1 {
  10398. for _, subitems := range prescriptions {
  10399. for _, item := range subitems.VMHisPrescription {
  10400. for _, subItem := range item.HisPrescriptionProject {
  10401. if subItem.Type == 3 {
  10402. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10403. if info.Price > 0 {
  10404. subItem.GoodInfo.PackingPrice = info.Price
  10405. }
  10406. }
  10407. }
  10408. }
  10409. }
  10410. }
  10411. }
  10412. if err == nil {
  10413. if len(prescriptions) == 0 {
  10414. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10415. return
  10416. } else {
  10417. this.ServeSuccessJSON(map[string]interface{}{
  10418. "prescriptions": prescriptions,
  10419. })
  10420. return
  10421. }
  10422. } else {
  10423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10424. return
  10425. }
  10426. }
  10427. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10428. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10429. for i := 0; i < len(arr); i++ {
  10430. repeat := false
  10431. for j := i + 1; j < len(arr); j++ {
  10432. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10433. repeat = true
  10434. break
  10435. }
  10436. }
  10437. if !repeat {
  10438. newArr = append(newArr, arr[i])
  10439. }
  10440. }
  10441. return
  10442. }
  10443. func (this *HisApiController) GetCallHisPrescription() {
  10444. patient_id, _ := this.GetInt64("patient_id", 0)
  10445. timeLayout := "2006-01-02"
  10446. loc, _ := time.LoadLocation("Local")
  10447. start_time := this.GetString("start_time")
  10448. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10449. end_time := this.GetString("end_time")
  10450. p_type, _ := this.GetInt64("p_type")
  10451. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10452. adminUserInfo := this.GetAdminUserInfo()
  10453. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10454. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10455. //if
  10456. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10457. //
  10458. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10459. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10460. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10461. if config.ID > 0 && config.IsOpen == 1 {
  10462. for _, subitems := range prescriptions {
  10463. for _, item := range subitems.VMHisPrescription {
  10464. for _, subItem := range item.HisDoctorAdviceInfo {
  10465. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10466. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10467. if info.RetailPrice > 0 {
  10468. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10469. subItem.Drug.RetailPrice = drug.RetailPrice
  10470. }
  10471. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10472. subItem.Drug.MinPrice = info.RetailPrice
  10473. subItem.Drug.RetailPrice = info.RetailPrice
  10474. }
  10475. }
  10476. }
  10477. }
  10478. }
  10479. }
  10480. if config.ID > 0 && config.IsOpen == 1 {
  10481. for _, subitems := range prescriptions {
  10482. for _, item := range subitems.VMHisPrescription {
  10483. for _, subItem := range item.HisPrescriptionProject {
  10484. if subItem.Type == 3 {
  10485. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10486. if info.Price > 0 {
  10487. subItem.GoodInfo.PackingPrice = info.Price
  10488. }
  10489. }
  10490. }
  10491. }
  10492. }
  10493. }
  10494. }
  10495. if err == nil {
  10496. this.ServeSuccessJSON(map[string]interface{}{
  10497. "prescriptions": prescriptions,
  10498. })
  10499. return
  10500. } else {
  10501. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10502. return
  10503. }
  10504. }
  10505. func (this *HisApiController) GetHisDayPrescription() {
  10506. timeLayout := "2006-01-02"
  10507. loc, _ := time.LoadLocation("Local")
  10508. start_time := this.GetString("start_time")
  10509. patient_id, _ := this.GetInt64("patient_id", 0)
  10510. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10511. end_time := this.GetString("end_time")
  10512. p_type, _ := this.GetInt64("p_type")
  10513. order_status, _ := this.GetInt64("type")
  10514. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10515. adminUserInfo := this.GetAdminUserInfo()
  10516. var dayHisPrescription []*models.HisPrescription
  10517. var err error
  10518. if order_status == 1 || order_status == 0 {
  10519. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10520. } else if order_status == 2 {
  10521. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10522. }
  10523. var settle_total float64
  10524. for _, item := range dayHisPrescription {
  10525. if len(item.HisPrescriptionProject) > 0 {
  10526. for _, subItem := range item.HisPrescriptionProject {
  10527. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10528. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10529. settle_total = settle_total + total
  10530. }
  10531. }
  10532. if len(item.HisDoctorAdviceInfo) > 0 {
  10533. for _, subItem := range item.HisDoctorAdviceInfo {
  10534. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10535. settle_total = settle_total + total
  10536. }
  10537. }
  10538. }
  10539. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10540. if err == nil {
  10541. this.ServeSuccessJSON(map[string]interface{}{
  10542. "day_prescription": dayHisPrescription,
  10543. "settle_total": settle_total,
  10544. })
  10545. return
  10546. } else {
  10547. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10548. return
  10549. }
  10550. }
  10551. func (c *HisApiController) GetHisChargePatientList() {
  10552. record_date := c.GetString("record_date")
  10553. order_status, _ := c.GetInt64("type")
  10554. sch_type, _ := c.GetInt64("sch_type")
  10555. timeLayout := "2006-01-02"
  10556. loc, _ := time.LoadLocation("Local")
  10557. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10558. if err != nil {
  10559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10560. return
  10561. }
  10562. recordDateTime := theTime.Unix()
  10563. adminInfo := c.GetAdminUserInfo()
  10564. var tempPatients []*service.NewTempPatients
  10565. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10566. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10567. if order_status != 2 {
  10568. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10569. } else {
  10570. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10571. }
  10572. } else {
  10573. if order_status != 2 {
  10574. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10575. } else {
  10576. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10577. }
  10578. }
  10579. var patients []*service.NewTempPatients
  10580. var patients_two []*service.NewTempPatients
  10581. for _, item := range tempPatients {
  10582. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10583. //过滤掉没挂号的和没开处方的
  10584. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10585. patients = append(patients, item)
  10586. }
  10587. //过滤掉没挂号的
  10588. if len(item.HisPatient) > 0 {
  10589. patients_two = append(patients_two, item)
  10590. }
  10591. } else {
  10592. if len(item.HisPrescription) > 0 {
  10593. patients = append(patients, item)
  10594. }
  10595. }
  10596. }
  10597. c.ServeSuccessJSON(map[string]interface{}{
  10598. "list": patients,
  10599. "list_two": patients_two,
  10600. })
  10601. }
  10602. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10603. record_date := c.GetString("record_date")
  10604. timeLayout := "2006-01-02"
  10605. loc, _ := time.LoadLocation("Local")
  10606. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10607. if err != nil {
  10608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10609. return
  10610. }
  10611. recordDateTime := theTime.Unix()
  10612. adminUser := c.GetAdminUserInfo()
  10613. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10614. var patients []*service.Patients
  10615. for _, item := range tempPatients {
  10616. if item.HisPatient.ID == 0 {
  10617. patients = append(patients, item)
  10618. }
  10619. }
  10620. c.ServeSuccessJSON(map[string]interface{}{
  10621. "list": patients,
  10622. //"list_two": patients_two,
  10623. })
  10624. }
  10625. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10626. newArr = make([]*service.Patients, 0)
  10627. for i := 0; i < len(patient); i++ {
  10628. repeat := false
  10629. for j := i + 1; j < len(patient); j++ {
  10630. if patient[i].ID == patient[j].ID {
  10631. repeat = true
  10632. break
  10633. }
  10634. }
  10635. if !repeat {
  10636. newArr = append(newArr, patient[i])
  10637. }
  10638. }
  10639. return
  10640. }
  10641. func (c *HisApiController) GetHisChargePatientInfo() {
  10642. patient_id, _ := c.GetInt64("patient_id")
  10643. his_patient_id, _ := c.GetInt64("his_patient_id")
  10644. record_date := c.GetString("record_date")
  10645. //start_time := c.GetString("start_time")
  10646. //end_time := c.GetString("end_time")
  10647. order_status, _ := c.GetInt64("type", 0)
  10648. p_type, _ := c.GetInt64("p_type", 0)
  10649. order_id, _ := c.GetInt64("order_id", 0)
  10650. timeLayout := "2006-01-02"
  10651. loc, _ := time.LoadLocation("Local")
  10652. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10653. if err != nil {
  10654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10655. return
  10656. }
  10657. recordDateTime := theTime.Unix()
  10658. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10659. //if err != nil {
  10660. //
  10661. //}
  10662. //startRecordDateTime := startTime.Unix()
  10663. //
  10664. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10665. //if err != nil {
  10666. //
  10667. //}
  10668. //endRecordDateTime := endTime.Unix()
  10669. admin := c.GetAdminUserInfo()
  10670. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10671. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10672. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10673. var prescriptions []*models.HisPrescription
  10674. //var unChargeMonthPrescriptions []*models.HisPrescription
  10675. order, _ := service.GetHisOrderByID(order_id)
  10676. if order_status == 1 || order_status == 0 {
  10677. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10678. } else if order_status == 2 {
  10679. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10680. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10681. }
  10682. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10683. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10684. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10685. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10686. //获取所有科室信息
  10687. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10688. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10689. c.ServeSuccessJSON(map[string]interface{}{
  10690. "his_info": his_patient_info,
  10691. "last_his_patient_info": last_his_patient_info,
  10692. "xt_info": xt_patient_info,
  10693. "prescription": prescriptions,
  10694. "case_history": case_history,
  10695. "info": patientPrescriptionInfo,
  10696. "last_info": lastPatientPrescriptionInfo,
  10697. "order": order,
  10698. "doctors": doctors,
  10699. "department": department,
  10700. "sch": sch,
  10701. })
  10702. return
  10703. }
  10704. func (c *HisApiController) GetAllOrderDetail() {
  10705. order_id, _ := c.GetInt64("id", 0)
  10706. order, _ := service.GetHisOrderByID(order_id)
  10707. if order.ID == 0 {
  10708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10709. return
  10710. }
  10711. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10712. org_id := c.GetAdminUserInfo().CurrentOrgId
  10713. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10714. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10715. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10716. c.ServeSuccessJSON(map[string]interface{}{
  10717. "order": order,
  10718. "order_info": order_info,
  10719. "patient": patient,
  10720. "admin_info": adminInfo,
  10721. "hospital_record": record,
  10722. })
  10723. return
  10724. }
  10725. func (c *HisApiController) GetAllOrderDetailCollect() {
  10726. order_id, _ := c.GetInt64("id", 0)
  10727. order, _ := service.GetHisOrderByID(order_id)
  10728. if order.ID == 0 {
  10729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10730. return
  10731. }
  10732. org_id := c.GetAdminUserInfo().CurrentOrgId
  10733. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10734. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10735. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10736. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10737. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10738. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10739. var bedCostTotal float64 = 0 //床位总费
  10740. //var bedCostSelfTotal float64 = 0 //床位自费
  10741. var operationCostTotal float64 = 0 //手术费
  10742. //var operationCostSelfTotal float64 = 0 //手术费
  10743. var otherCostTotal float64 = 0 //其他费用
  10744. //var otherCostSelfTotal float64 = 0 //其他费用
  10745. var materialCostTotal float64 = 0 //材料费
  10746. //var materialCostSelfTotal float64 = 0 //材料费
  10747. var westernMedicineCostTotal float64 = 0 //西药费
  10748. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10749. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10750. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10751. var checkCostTotal float64 = 0 //检查费
  10752. //var checkCostSelfTotal float64 = 0 //检查费
  10753. var laboratoryCostTotal float64 = 0 //化验费
  10754. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10755. var treatCostTotal float64 = 0 //治疗费用
  10756. //var treatCostSelfTotal float64 = 0 //治疗费用
  10757. var zhenChaCostTotal float64 = 0 //其他费用
  10758. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10759. decimal.DivisionPrecision = 2
  10760. var BalanceAccountsType int64
  10761. if his.ID > 0 {
  10762. BalanceAccountsType = his.BalanceAccountsType
  10763. } else {
  10764. BalanceAccountsType = record.BalanceAccountsType
  10765. }
  10766. if BalanceAccountsType != 2 {
  10767. for _, item := range order_info {
  10768. if org_id == 10215 {
  10769. if item.MedChrgitmType == "01" { //床位费
  10770. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10771. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10772. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10773. }
  10774. if item.MedChrgitmType == "02" { //诊察费
  10775. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10776. //zhenChaCostSelfTotal = zhenChaCostTotal
  10777. }
  10778. if item.MedChrgitmType == "03" { //检查费
  10779. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10780. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10781. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10782. }
  10783. //if item.MedChrgitmType == "02" { //检查费
  10784. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10785. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10786. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10787. //}
  10788. if item.MedChrgitmType == "04" { //化验费
  10789. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10790. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10791. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10792. }
  10793. if item.MedChrgitmType == "05" { //治疗费
  10794. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10795. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10796. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10797. }
  10798. if item.MedChrgitmType == "06" { //手术费
  10799. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10800. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10801. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10802. }
  10803. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10804. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10805. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10806. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10807. }
  10808. if item.MedChrgitmType == "09" { //西药费
  10809. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10810. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10811. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10812. }
  10813. if item.MedChrgitmType == "11" { //中成费
  10814. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10815. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10816. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10817. }
  10818. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10819. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10820. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10821. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10822. }
  10823. } else if org_id == 10188 || org_id == 10217 {
  10824. if item.MedChrgitmType == "01" { //床位费
  10825. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10826. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10827. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10828. }
  10829. if item.MedChrgitmType == "02" { //诊察费
  10830. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10831. //zhenChaCostSelfTotal = zhenChaCostTotal
  10832. }
  10833. if item.MedChrgitmType == "03" { //检查费
  10834. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10835. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10836. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10837. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10838. }
  10839. //if item.MedChrgitmType == "02" { //检查费
  10840. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10841. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10842. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10843. //}
  10844. if item.MedChrgitmType == "04" { //化验费
  10845. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10846. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10847. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10848. }
  10849. if item.MedChrgitmType == "05" { //治疗费
  10850. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10851. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10852. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10853. }
  10854. if item.MedChrgitmType == "06" { //手术费
  10855. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10856. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10857. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10858. }
  10859. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10860. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10861. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10862. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10863. }
  10864. if item.MedChrgitmType == "09" { //西药费
  10865. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10866. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10867. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10868. }
  10869. if item.MedChrgitmType == "11" { //中成费
  10870. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10871. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10872. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10873. }
  10874. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10875. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10876. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10877. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10878. }
  10879. } else {
  10880. if item.MedChrgitmType == "01" { //床位费
  10881. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10882. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10883. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10884. }
  10885. //if item.MedChrgitmType == "02" { //诊察费
  10886. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10887. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10888. //}
  10889. if item.MedChrgitmType == "03" { //检查费
  10890. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10891. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10892. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10893. }
  10894. //if item.MedChrgitmType == "02" { //检查费
  10895. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10896. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10897. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10898. //}
  10899. if item.MedChrgitmType == "04" { //化验费
  10900. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10901. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10902. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10903. }
  10904. if item.MedChrgitmType == "05" { //治疗费
  10905. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10906. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10907. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10908. }
  10909. if item.MedChrgitmType == "06" { //手术费
  10910. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10911. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10912. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10913. }
  10914. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10915. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10916. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10917. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10918. }
  10919. if item.MedChrgitmType == "09" { //西药费
  10920. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10921. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10922. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10923. }
  10924. if item.MedChrgitmType == "11" { //中成费
  10925. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10926. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10927. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10928. }
  10929. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10930. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10931. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10932. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10933. }
  10934. }
  10935. }
  10936. c.ServeSuccessJSON(map[string]interface{}{
  10937. "order": order,
  10938. "order_info": order_info,
  10939. "patient": patient,
  10940. "admin_info": adminInfo,
  10941. "his_hospital": record,
  10942. "bedCostTotal": bedCostTotal,
  10943. "operationCostTotal": operationCostTotal,
  10944. "otherCostTotal": otherCostTotal,
  10945. "materialCostTotal": materialCostTotal,
  10946. "westernMedicineCostTotal": westernMedicineCostTotal,
  10947. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10948. "checkCostTotal": checkCostTotal,
  10949. "zhenChaCostTotal": zhenChaCostTotal,
  10950. "laboratoryCostTotal": laboratoryCostTotal,
  10951. "treatCostTotal": treatCostTotal,
  10952. })
  10953. } else {
  10954. for _, item := range order_info {
  10955. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10956. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10957. item.MedChrgitmType = "09"
  10958. }
  10959. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10960. if item.HisPrescriptionProject.Type == 2 {
  10961. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10962. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10963. case 0:
  10964. item.MedChrgitmType = "0"
  10965. break
  10966. case 1:
  10967. item.MedChrgitmType = "14"
  10968. break
  10969. case 2:
  10970. item.MedChrgitmType = "05"
  10971. break
  10972. case 3:
  10973. item.MedChrgitmType = "03"
  10974. break
  10975. case 4:
  10976. item.MedChrgitmType = "03"
  10977. break
  10978. case 5:
  10979. item.MedChrgitmType = "08"
  10980. break
  10981. case 6:
  10982. item.MedChrgitmType = "14"
  10983. break
  10984. case 7:
  10985. item.MedChrgitmType = "14"
  10986. break
  10987. case 8:
  10988. item.MedChrgitmType = "03"
  10989. break
  10990. case 9:
  10991. item.MedChrgitmType = "14"
  10992. break
  10993. case 10:
  10994. item.MedChrgitmType = "14"
  10995. break
  10996. case 11:
  10997. item.MedChrgitmType = "06"
  10998. break
  10999. case 12:
  11000. item.MedChrgitmType = "12"
  11001. break
  11002. case 13:
  11003. item.MedChrgitmType = "01"
  11004. break
  11005. case 14:
  11006. item.MedChrgitmType = "04"
  11007. break
  11008. case 15:
  11009. item.MedChrgitmType = "14"
  11010. break
  11011. }
  11012. } else {
  11013. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11014. case 1:
  11015. item.MedChrgitmType = "14"
  11016. break
  11017. case 2:
  11018. item.MedChrgitmType = "05"
  11019. break
  11020. case 3:
  11021. item.MedChrgitmType = "04"
  11022. break
  11023. case 4:
  11024. item.MedChrgitmType = "14"
  11025. break
  11026. case 5:
  11027. item.MedChrgitmType = "08"
  11028. break
  11029. case 6:
  11030. item.MedChrgitmType = "14"
  11031. break
  11032. case 7:
  11033. item.MedChrgitmType = "14"
  11034. break
  11035. case 8:
  11036. item.MedChrgitmType = "03"
  11037. break
  11038. case 9:
  11039. item.MedChrgitmType = "14"
  11040. break
  11041. }
  11042. }
  11043. } else if item.HisPrescriptionProject.Type == 3 {
  11044. item.MedChrgitmType = "08"
  11045. }
  11046. }
  11047. }
  11048. for _, item := range order_info {
  11049. if org_id == 10215 {
  11050. if item.MedChrgitmType == "01" { //床位费
  11051. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11052. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11053. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11054. }
  11055. if item.MedChrgitmType == "02" { //诊察费
  11056. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11057. //zhenChaCostSelfTotal = zhenChaCostTotal
  11058. }
  11059. if item.MedChrgitmType == "03" { //检查费
  11060. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11061. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11062. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11063. }
  11064. //if item.MedChrgitmType == "02" { //检查费
  11065. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11066. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11067. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11068. //}
  11069. if item.MedChrgitmType == "04" { //化验费
  11070. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11071. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11072. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11073. }
  11074. if item.MedChrgitmType == "05" { //治疗费
  11075. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11076. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11077. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11078. }
  11079. if item.MedChrgitmType == "06" { //手术费
  11080. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11081. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11082. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11083. }
  11084. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11085. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11086. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11087. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11088. }
  11089. if item.MedChrgitmType == "09" { //西药费
  11090. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11091. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11092. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11093. }
  11094. if item.MedChrgitmType == "11" { //中成费
  11095. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11096. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11097. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11098. }
  11099. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11100. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11101. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11102. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11103. }
  11104. } else {
  11105. if item.MedChrgitmType == "01" { //床位费
  11106. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11107. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11108. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11109. }
  11110. //if item.MedChrgitmType == "02" { //诊察费
  11111. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11112. // //zhenChaCostSelfTotal = zhenChaCostTotal
  11113. //}
  11114. if item.MedChrgitmType == "03" { //检查费
  11115. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11116. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11117. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11118. }
  11119. //if item.MedChrgitmType == "02" { //检查费
  11120. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11121. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11122. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11123. //}
  11124. if item.MedChrgitmType == "04" { //化验费
  11125. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11126. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11127. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11128. }
  11129. if item.MedChrgitmType == "05" { //治疗费
  11130. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11131. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11132. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11133. }
  11134. if item.MedChrgitmType == "06" { //手术费
  11135. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11136. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11137. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11138. }
  11139. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11140. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11141. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11142. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11143. }
  11144. if item.MedChrgitmType == "09" { //西药费
  11145. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11146. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11147. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11148. }
  11149. if item.MedChrgitmType == "11" { //中成费
  11150. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11151. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11152. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11153. }
  11154. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11155. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11156. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11157. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11158. }
  11159. }
  11160. }
  11161. c.ServeSuccessJSON(map[string]interface{}{
  11162. "order": order,
  11163. "order_info": order_info,
  11164. "patient": patient,
  11165. "admin_info": adminInfo,
  11166. "his_hospital": record,
  11167. "bedCostTotal": bedCostTotal,
  11168. "operationCostTotal": operationCostTotal,
  11169. "otherCostTotal": otherCostTotal,
  11170. "materialCostTotal": materialCostTotal,
  11171. "westernMedicineCostTotal": westernMedicineCostTotal,
  11172. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11173. "checkCostTotal": checkCostTotal,
  11174. "zhenChaCostTotal": zhenChaCostTotal,
  11175. "laboratoryCostTotal": laboratoryCostTotal,
  11176. "treatCostTotal": treatCostTotal,
  11177. })
  11178. }
  11179. }
  11180. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  11181. page, _ := c.GetInt64("page")
  11182. limit, _ := c.GetInt64("limit")
  11183. keywords := c.GetString("keywords")
  11184. start_time := c.GetString("start_time")
  11185. end_time := c.GetString("end_time")
  11186. //clr_type := c.GetString("clr_type")
  11187. insutype := c.GetString("insutype")
  11188. timeLayout := "2006-01-02"
  11189. loc, _ := time.LoadLocation("Local")
  11190. var theStartTIme int64
  11191. if len(start_time) > 0 {
  11192. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11193. theStartTIme = theTime.Unix()
  11194. }
  11195. var theEndtTIme int64
  11196. if len(end_time) > 0 {
  11197. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11198. theEndtTIme = theTime.Unix()
  11199. }
  11200. if page <= 0 {
  11201. page = 1
  11202. }
  11203. if limit <= 0 {
  11204. limit = 10
  11205. }
  11206. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  11207. c.ServeSuccessJSON(map[string]interface{}{
  11208. "total": total,
  11209. "list": list,
  11210. })
  11211. return
  11212. }
  11213. func (c *HisApiController) GetPutOnRecordList() {
  11214. page, _ := c.GetInt64("page")
  11215. limit, _ := c.GetInt64("limit")
  11216. keywords := c.GetString("keywords")
  11217. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  11218. if page <= 0 {
  11219. page = 1
  11220. }
  11221. if limit <= 0 {
  11222. limit = 10
  11223. }
  11224. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  11225. c.ServeSuccessJSON(map[string]interface{}{
  11226. "total": total,
  11227. "list": list,
  11228. })
  11229. return
  11230. }
  11231. func (c *HisApiController) GetCompareData() {
  11232. start_time := c.GetString("start_time")
  11233. end_time := c.GetString("end_time")
  11234. insutype := c.GetString("insutype")
  11235. clr_type := c.GetString("clr_type")
  11236. timeLayout := "2006-01-02"
  11237. loc, _ := time.LoadLocation("Local")
  11238. var theStartTIme int64
  11239. if len(start_time) > 0 {
  11240. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11241. if err != nil {
  11242. theStartTIme = 0
  11243. }
  11244. theStartTIme = theTime.Unix()
  11245. }
  11246. var theEndtTIme int64
  11247. if len(end_time) > 0 {
  11248. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11249. if err != nil {
  11250. theEndtTIme = 0
  11251. }
  11252. theEndtTIme = theTime.Unix()
  11253. }
  11254. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11255. fmt.Println(err)
  11256. if err == nil {
  11257. c.ServeSuccessJSON(map[string]interface{}{
  11258. "list": formData,
  11259. })
  11260. } else {
  11261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11262. return
  11263. }
  11264. }
  11265. func (c *HisApiController) GetFaPiaoData() {
  11266. order_id, _ := c.GetInt64("order_id")
  11267. patient_id, _ := c.GetInt64("patient_id")
  11268. //number := c.GetString("number")
  11269. adminUser := c.GetAdminUserInfo()
  11270. order, _ := service.GetHisOrderByID(order_id)
  11271. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11272. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11273. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11274. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11275. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11276. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11277. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11278. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11279. var bedCostTotal float64 = 0 //床位总费
  11280. var bedCostSelfTotal float64 = 0 //床位自费
  11281. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11282. var operationCostTotal float64 = 0 //手术费
  11283. var operationCostSelfTotal float64 = 0 //手术费
  11284. var operationCostPartSelfTotal float64 = 0 //手术费
  11285. var otherCostTotal float64 = 0 //其他费用
  11286. var otherCostSelfTotal float64 = 0 //其他费用
  11287. var otherCostPartSelfTotal float64 = 0 //其他费用
  11288. var materialCostTotal float64 = 0 //材料费
  11289. var materialCostSelfTotal float64 = 0 //材料费
  11290. var materialCostPartSelfTotal float64 = 0 //材料费
  11291. var westernMedicineCostTotal float64 = 0 //西药费
  11292. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11293. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11294. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11295. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11296. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11297. var checkCostTotal float64 = 0 //检查费
  11298. var checkCostSelfTotal float64 = 0 //检查费
  11299. var checkCostPartSelfTotal float64 = 0 //检查费
  11300. var hiliCostTotal float64 = 0 //护理费
  11301. var hiliCostSelfTotal float64 = 0 //护理费
  11302. var hiliCostPartSelfTotal float64 = 0 //护理费
  11303. var laboratoryCostTotal float64 = 0 //化验费
  11304. var laboratoryCostSelfTotal float64 = 0 //化验费
  11305. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11306. var treatCostTotal float64 = 0 //治疗费用
  11307. var treatCostSelfTotal float64 = 0 //治疗费用
  11308. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11309. var zhenChaCostTotal float64 = 0 //其他费用
  11310. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11311. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11312. decimal.DivisionPrecision = 2
  11313. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11314. var balanceAccountsType int64
  11315. if his.ID > 0 {
  11316. balanceAccountsType = his.BalanceAccountsType
  11317. } else {
  11318. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11319. }
  11320. if balanceAccountsType == 2 {
  11321. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11322. for _, item := range orderInfos_two {
  11323. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11324. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11325. item.MedChrgitmType = "09"
  11326. }
  11327. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11328. if item.HisPrescriptionProject.Type == 2 {
  11329. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11330. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11331. case 0:
  11332. item.MedChrgitmType = "0"
  11333. break
  11334. case 1:
  11335. item.MedChrgitmType = "14"
  11336. break
  11337. case 2:
  11338. item.MedChrgitmType = "05"
  11339. break
  11340. case 3:
  11341. item.MedChrgitmType = "03"
  11342. break
  11343. case 4:
  11344. item.MedChrgitmType = "03"
  11345. break
  11346. case 5:
  11347. item.MedChrgitmType = "08"
  11348. break
  11349. case 6:
  11350. item.MedChrgitmType = "14"
  11351. break
  11352. case 7:
  11353. item.MedChrgitmType = "14"
  11354. break
  11355. case 8:
  11356. item.MedChrgitmType = "03"
  11357. break
  11358. case 9:
  11359. item.MedChrgitmType = "14"
  11360. break
  11361. case 10:
  11362. item.MedChrgitmType = "14"
  11363. break
  11364. case 11:
  11365. item.MedChrgitmType = "06"
  11366. break
  11367. case 12:
  11368. item.MedChrgitmType = "12"
  11369. break
  11370. case 13:
  11371. item.MedChrgitmType = "01"
  11372. break
  11373. case 14:
  11374. item.MedChrgitmType = "04"
  11375. break
  11376. case 15:
  11377. item.MedChrgitmType = "02"
  11378. break
  11379. }
  11380. } else {
  11381. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11382. case 1:
  11383. item.MedChrgitmType = "14"
  11384. break
  11385. case 2:
  11386. item.MedChrgitmType = "05"
  11387. break
  11388. case 3:
  11389. item.MedChrgitmType = "04"
  11390. break
  11391. case 4:
  11392. item.MedChrgitmType = "03"
  11393. break
  11394. case 5:
  11395. item.MedChrgitmType = "08"
  11396. break
  11397. case 6:
  11398. item.MedChrgitmType = "14"
  11399. break
  11400. case 7:
  11401. item.MedChrgitmType = "14"
  11402. break
  11403. case 8:
  11404. item.MedChrgitmType = "03"
  11405. break
  11406. case 9:
  11407. item.MedChrgitmType = "14"
  11408. break
  11409. }
  11410. }
  11411. } else if item.HisPrescriptionProject.Type == 3 {
  11412. item.MedChrgitmType = "08"
  11413. }
  11414. }
  11415. }
  11416. for _, item := range orderInfos_two {
  11417. fmt.Println(item.MedChrgitmType)
  11418. if item.MedChrgitmType == "07" { //床位费
  11419. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11420. hiliCostSelfTotal = hiliCostTotal
  11421. }
  11422. if item.MedChrgitmType == "01" { //床位费
  11423. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11424. bedCostSelfTotal = bedCostTotal
  11425. }
  11426. if item.MedChrgitmType == "02" { //诊察费
  11427. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11428. zhenChaCostSelfTotal = zhenChaCostTotal
  11429. }
  11430. if item.MedChrgitmType == "03" { //检查费
  11431. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11432. checkCostSelfTotal = checkCostTotal
  11433. }
  11434. if item.MedChrgitmType == "04" { //化验费
  11435. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11436. laboratoryCostSelfTotal = laboratoryCostTotal
  11437. }
  11438. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11439. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11440. treatCostSelfTotal = treatCostTotal
  11441. }
  11442. if item.MedChrgitmType == "06" { //手术费
  11443. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11444. operationCostSelfTotal = treatCostTotal
  11445. }
  11446. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11447. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11448. materialCostSelfTotal = materialCostTotal
  11449. }
  11450. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11451. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11452. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11453. }
  11454. if item.MedChrgitmType == "11" { //中成费
  11455. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11456. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11457. }
  11458. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11459. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11461. otherCostSelfTotal = otherCostTotal
  11462. }
  11463. } else {
  11464. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11465. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11466. otherCostSelfTotal = otherCostTotal
  11467. }
  11468. }
  11469. }
  11470. } else {
  11471. for _, item := range orderInfos {
  11472. if item.MedChrgitmType == "01" { //床位费
  11473. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11474. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11475. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11476. }
  11477. if item.MedChrgitmType == "02" { //诊察费
  11478. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11479. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11480. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11481. }
  11482. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11483. if item.MedChrgitmType == "03" { //检查费
  11484. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11485. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11486. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11487. }
  11488. } else {
  11489. if item.MedChrgitmType == "03" { //检查费
  11490. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11491. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11492. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11493. }
  11494. }
  11495. if item.MedChrgitmType == "04" { //化验费
  11496. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11497. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11498. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11499. }
  11500. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11501. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11502. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11503. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11504. }
  11505. if item.MedChrgitmType == "06" { //手术费
  11506. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11507. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11508. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11509. }
  11510. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11511. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11512. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11513. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11514. }
  11515. if item.MedChrgitmType == "07" { //护理
  11516. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11517. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11518. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11519. }
  11520. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11521. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11522. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11523. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11524. }
  11525. if item.MedChrgitmType == "11" { //中成费
  11526. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11527. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11528. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11529. }
  11530. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11531. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11532. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11533. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11534. }
  11535. }
  11536. }
  11537. timeLayout := "2006-01-02"
  11538. loc, _ := time.LoadLocation("Local")
  11539. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11540. if err != nil {
  11541. }
  11542. startRecordDateTime := startTime.Unix()
  11543. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11544. if err != nil {
  11545. }
  11546. endRecordDateTime := endTime.Unix()
  11547. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11548. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11549. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11550. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11551. c.ServeSuccessJSON(map[string]interface{}{
  11552. "charge_admin_name": charge_admin.UserName,
  11553. "order_number": order.Number, //业务流水号
  11554. "id_card_no": his.IdCardNo, //社会保障号
  11555. "patient": patient,
  11556. "department_name": department.Name, //科室
  11557. "number": his.Number, //门诊号
  11558. "date": order.SettleAccountsDate, //结算日期
  11559. "name": order.PsnName, //姓名
  11560. "gender": patient.Gender, //性别
  11561. "psn_cash_money": order.PsnCashPay, //个人支付
  11562. "pay_way": "门诊", //结算方式
  11563. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11564. "admin_user_name": admin.UserName, //收款员
  11565. "order": order,
  11566. "order_info": orderInfos_two,
  11567. "his": his,
  11568. "bedCostTotal": bedCostTotal,
  11569. "bedCostSelfTotal": bedCostSelfTotal,
  11570. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11571. "operationCostTotal": operationCostTotal,
  11572. "operationCostSelfTotal": operationCostSelfTotal,
  11573. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11574. "otherCostTotal": otherCostTotal,
  11575. "otherCostSelfTotal": otherCostSelfTotal,
  11576. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11577. "materialCostTotal": materialCostTotal,
  11578. "materialCostSelfTotal": materialCostSelfTotal,
  11579. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11580. "westernMedicineCostTotal": westernMedicineCostTotal,
  11581. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11582. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11583. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11584. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11585. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11586. "checkCostTotal": checkCostTotal,
  11587. "checkCostSelfTotal": checkCostSelfTotal,
  11588. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11589. "laboratoryCostTotal": laboratoryCostTotal,
  11590. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11591. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11592. "treatCostTotal": treatCostTotal,
  11593. "treatCostSelfTotal": treatCostSelfTotal,
  11594. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11595. "zhenChaCostTotal": zhenChaCostTotal,
  11596. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11597. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11598. "his_hospital_record": his_hospital_record,
  11599. "pre_pay_money": pre_pay_money,
  11600. "refund_sum": sum,
  11601. "doctor_info": doctor_info,
  11602. "hiliCostTotal": hiliCostTotal,
  11603. "hiliCostSelfTotal": hiliCostSelfTotal,
  11604. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11605. })
  11606. }
  11607. //func (c *HisApiController) GetFaPiaoDatas() {
  11608. // order_ids := c.GetString("order_ids")
  11609. // patient_id, _ := c.GetInt64("patient_id")
  11610. // adminUser := c.GetAdminUserInfo()
  11611. //
  11612. // orders := strings.Split(order_ids, ",")
  11613. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11614. //
  11615. // for _, item := range orders {
  11616. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11617. // order, _ := service.GetHisOrderByID(order_id)
  11618. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11619. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11620. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11621. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11622. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11623. //
  11624. // }
  11625. //
  11626. // var bedCostTotal float64 = 0 //床位总费
  11627. // var bedCostSelfTotal float64 = 0 //床位自费
  11628. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11629. //
  11630. // var operationCostTotal float64 = 0 //手术费
  11631. // var operationCostSelfTotal float64 = 0 //手术费
  11632. // var operationCostPartSelfTotal float64 = 0 //手术费
  11633. //
  11634. // var otherCostTotal float64 = 0 //其他费用
  11635. // var otherCostSelfTotal float64 = 0 //其他费用
  11636. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11637. //
  11638. // var materialCostTotal float64 = 0 //材料费
  11639. // var materialCostSelfTotal float64 = 0 //材料费
  11640. // var materialCostPartSelfTotal float64 = 0 //材料费
  11641. //
  11642. // var westernMedicineCostTotal float64 = 0 //西药费
  11643. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11644. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11645. //
  11646. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11647. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11648. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11649. //
  11650. // var checkCostTotal float64 = 0 //检查费
  11651. // var checkCostSelfTotal float64 = 0 //检查费
  11652. // var checkCostPartSelfTotal float64 = 0 //检查费
  11653. //
  11654. // var laboratoryCostTotal float64 = 0 //化验费
  11655. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11656. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11657. //
  11658. // var treatCostTotal float64 = 0 //治疗费用
  11659. // var treatCostSelfTotal float64 = 0 //治疗费用
  11660. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11661. //
  11662. // var zhenChaCostTotal float64 = 0 //其他费用
  11663. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11664. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11665. //
  11666. // decimal.DivisionPrecision = 2
  11667. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11668. //
  11669. // var balanceAccountsType int64
  11670. // if his.ID > 0 {
  11671. // balanceAccountsType = his.BalanceAccountsType
  11672. // } else {
  11673. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11674. // }
  11675. // if balanceAccountsType == 2 {
  11676. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11677. // for _, item := range orderInfos_two {
  11678. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11679. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11680. // item.MedChrgitmType = "09"
  11681. // }
  11682. //
  11683. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11684. // if item.HisPrescriptionProject.Type == 2 {
  11685. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11686. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11687. // case 0:
  11688. // item.MedChrgitmType = "0"
  11689. // break
  11690. // case 1:
  11691. // item.MedChrgitmType = "14"
  11692. // break
  11693. // case 2:
  11694. // item.MedChrgitmType = "05"
  11695. //
  11696. // break
  11697. // case 3:
  11698. // item.MedChrgitmType = "03"
  11699. //
  11700. // break
  11701. // case 4:
  11702. // item.MedChrgitmType = "03"
  11703. //
  11704. // break
  11705. // case 5:
  11706. // item.MedChrgitmType = "08"
  11707. //
  11708. // break
  11709. // case 6:
  11710. // item.MedChrgitmType = "14"
  11711. //
  11712. // break
  11713. // case 7:
  11714. // item.MedChrgitmType = "14"
  11715. //
  11716. // break
  11717. // case 8:
  11718. // item.MedChrgitmType = "03"
  11719. // break
  11720. // case 9:
  11721. // item.MedChrgitmType = "14"
  11722. // break
  11723. // case 10:
  11724. // item.MedChrgitmType = "14"
  11725. // break
  11726. // case 11:
  11727. // item.MedChrgitmType = "06"
  11728. // break
  11729. // case 12:
  11730. // item.MedChrgitmType = "12"
  11731. // break
  11732. // case 13:
  11733. // item.MedChrgitmType = "01"
  11734. // break
  11735. // case 14:
  11736. // item.MedChrgitmType = "04"
  11737. // break
  11738. // case 15:
  11739. // item.MedChrgitmType = "02"
  11740. // break
  11741. //
  11742. // }
  11743. //
  11744. // } else {
  11745. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11746. //
  11747. // case 1:
  11748. // item.MedChrgitmType = "14"
  11749. // break
  11750. // case 2:
  11751. // item.MedChrgitmType = "05"
  11752. //
  11753. // break
  11754. // case 3:
  11755. // item.MedChrgitmType = "03"
  11756. //
  11757. // break
  11758. // case 4:
  11759. // item.MedChrgitmType = "03"
  11760. //
  11761. // break
  11762. // case 5:
  11763. // item.MedChrgitmType = "08"
  11764. //
  11765. // break
  11766. // case 6:
  11767. // item.MedChrgitmType = "14"
  11768. //
  11769. // break
  11770. // case 7:
  11771. // item.MedChrgitmType = "14"
  11772. //
  11773. // break
  11774. // case 8:
  11775. // item.MedChrgitmType = "03"
  11776. // break
  11777. // case 9:
  11778. // item.MedChrgitmType = "14"
  11779. // break
  11780. //
  11781. // }
  11782. //
  11783. // }
  11784. //
  11785. // } else if item.HisPrescriptionProject.Type == 3 {
  11786. // item.MedChrgitmType = "08"
  11787. // }
  11788. // }
  11789. // }
  11790. //
  11791. // for _, item := range orderInfos_two {
  11792. // fmt.Println(item.MedChrgitmType)
  11793. // if item.MedChrgitmType == "01" { //床位费
  11794. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11795. // bedCostSelfTotal = bedCostTotal
  11796. // }
  11797. //
  11798. // if item.MedChrgitmType == "02" { //诊察费
  11799. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11800. // zhenChaCostSelfTotal = zhenChaCostTotal
  11801. // }
  11802. //
  11803. // if item.MedChrgitmType == "03" { //检查费
  11804. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11805. // checkCostSelfTotal = checkCostTotal
  11806. // }
  11807. //
  11808. // if item.MedChrgitmType == "04" { //化验费
  11809. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11810. // laboratoryCostSelfTotal = laboratoryCostTotal
  11811. // }
  11812. //
  11813. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11814. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11815. // treatCostSelfTotal = treatCostTotal
  11816. // }
  11817. //
  11818. // if item.MedChrgitmType == "06" { //手术费
  11819. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11820. // operationCostSelfTotal = treatCostTotal
  11821. // }
  11822. //
  11823. // if item.MedChrgitmType == "08" { //材料费
  11824. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11825. // materialCostSelfTotal = materialCostTotal
  11826. // }
  11827. //
  11828. // if item.MedChrgitmType == "09" { //西药费
  11829. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11830. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11831. // }
  11832. //
  11833. // if item.MedChrgitmType == "11" { //中成费
  11834. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11835. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11836. // }
  11837. //
  11838. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11839. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11840. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11841. // otherCostSelfTotal = otherCostTotal
  11842. // }
  11843. // } else {
  11844. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11845. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11846. // otherCostSelfTotal = otherCostTotal
  11847. // }
  11848. //
  11849. // }
  11850. //
  11851. // }
  11852. //
  11853. // } else {
  11854. // for _, item := range orderInfos {
  11855. // if item.MedChrgitmType == "01" { //床位费
  11856. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11857. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11858. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11859. // }
  11860. //
  11861. // if item.MedChrgitmType == "02" { //诊察费
  11862. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11863. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11864. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11865. // }
  11866. //
  11867. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11868. // if item.MedChrgitmType == "03" { //检查费
  11869. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11870. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11871. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11872. //
  11873. // }
  11874. // } else {
  11875. // if item.MedChrgitmType == "03" { //检查费
  11876. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11877. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11878. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11879. // }
  11880. //
  11881. // }
  11882. //
  11883. // if item.MedChrgitmType == "04" { //化验费
  11884. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11885. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11886. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11887. //
  11888. // }
  11889. //
  11890. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11891. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11892. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11893. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11894. //
  11895. // }
  11896. //
  11897. // if item.MedChrgitmType == "06" { //手术费
  11898. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11899. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11900. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11901. // }
  11902. //
  11903. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11904. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11905. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11906. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11907. // }
  11908. //
  11909. // if item.MedChrgitmType == "09" { //西药费
  11910. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11911. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11912. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11913. // }
  11914. //
  11915. // if item.MedChrgitmType == "11" { //中成费
  11916. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11917. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11918. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11919. // }
  11920. //
  11921. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11922. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11923. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11924. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11925. // }
  11926. //
  11927. // }
  11928. // }
  11929. // timeLayout := "2006-01-02"
  11930. // loc, _ := time.LoadLocation("Local")
  11931. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11932. // if err != nil {
  11933. // }
  11934. // startRecordDateTime := startTime.Unix()
  11935. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11936. // if err != nil {
  11937. // }
  11938. // endRecordDateTime := endTime.Unix()
  11939. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11940. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11941. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11942. //
  11943. // c.ServeSuccessJSON(map[string]interface{}{
  11944. // "order_number": order.Number, //业务流水号
  11945. // "id_card_no": his.IdCardNo, //社会保障号
  11946. // "department_name": department.Name, //科室
  11947. // "number": his.Number, //门诊号
  11948. // "date": order.SettleAccountsDate, //结算日期
  11949. // "name": order.PsnName, //姓名
  11950. // "gender": patient.Gender, //性别
  11951. // "psn_cash_money": order.PsnCashPay, //个人支付
  11952. // "pay_way": "门诊", //结算方式
  11953. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11954. // "admin_user_name": admin.UserName, //收款员
  11955. // "order": order,
  11956. // "order_info": orderInfos_two,
  11957. // "his": his,
  11958. // "bedCostTotal": bedCostTotal,
  11959. // "bedCostSelfTotal": bedCostSelfTotal,
  11960. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11961. // "operationCostTotal": operationCostTotal,
  11962. // "operationCostSelfTotal": operationCostSelfTotal,
  11963. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11964. // "otherCostTotal": otherCostTotal,
  11965. // "otherCostSelfTotal": otherCostSelfTotal,
  11966. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11967. // "materialCostTotal": materialCostTotal,
  11968. // "materialCostSelfTotal": materialCostSelfTotal,
  11969. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11970. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11971. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11972. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11973. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11974. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11975. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11976. // "checkCostTotal": checkCostTotal,
  11977. // "checkCostSelfTotal": checkCostSelfTotal,
  11978. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11979. // "laboratoryCostTotal": laboratoryCostTotal,
  11980. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11981. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11982. // "treatCostTotal": treatCostTotal,
  11983. // "treatCostSelfTotal": treatCostSelfTotal,
  11984. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11985. // "zhenChaCostTotal": zhenChaCostTotal,
  11986. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11987. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11988. // "his_hospital_record": his_hospital_record,
  11989. // "pre_pay_money": pre_pay_money,
  11990. // "refund_sum": sum,
  11991. // })
  11992. //
  11993. //}
  11994. func (this *HisApiController) GetIncomeStatisticsData() {
  11995. start_time := this.GetString("start_time")
  11996. end_time := this.GetString("end_time")
  11997. key_words := this.GetString("key_words")
  11998. limit, _ := this.GetInt64("limit")
  11999. page, _ := this.GetInt64("page")
  12000. if page <= 0 {
  12001. page = 1
  12002. }
  12003. if limit <= 0 {
  12004. limit = 10
  12005. }
  12006. statistics_type, _ := this.GetInt64("statistics_type")
  12007. admin := this.GetAdminUserInfo()
  12008. timeLayout := "2006-01-02"
  12009. loc, _ := time.LoadLocation("Local")
  12010. var theStartTIme int64
  12011. if len(start_time) > 0 {
  12012. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12013. if err != nil {
  12014. theStartTIme = 0
  12015. }
  12016. theStartTIme = theTime.Unix()
  12017. }
  12018. var theEndtTIme int64
  12019. if len(end_time) > 0 {
  12020. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12021. if err != nil {
  12022. theEndtTIme = 0
  12023. }
  12024. theEndtTIme = theTime.Unix()
  12025. }
  12026. if statistics_type == 1 {
  12027. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12028. this.ServeSuccessJSON(map[string]interface{}{
  12029. "list": list,
  12030. "total": total,
  12031. })
  12032. } else {
  12033. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12034. this.ServeSuccessJSON(map[string]interface{}{
  12035. "list": list,
  12036. "total": total,
  12037. })
  12038. }
  12039. }
  12040. func (c *HisApiController) PostProjectInformation() {
  12041. adminUser := c.GetAdminUserInfo()
  12042. orgId := adminUser.CurrentOrgId
  12043. dataBody := make(map[string]interface{}, 0)
  12044. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12045. if err != nil {
  12046. utils.ErrorLog(err.Error())
  12047. return
  12048. }
  12049. utils.ErrorLog("%v", dataBody)
  12050. var projectList []*models.HisProject
  12051. var total_goods []interface{}
  12052. tempProjects := dataBody["projects"].([]interface{})
  12053. total_goods = tempProjects
  12054. for index, projectMap := range tempProjects {
  12055. projectM := projectMap.(map[string]interface{})
  12056. var project models.HisProject
  12057. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  12058. utils.ErrorLog("project_name")
  12059. return
  12060. }
  12061. project_name, _ := projectM["project_name"].(string)
  12062. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  12063. err_log := models.ExportErrLog{
  12064. LogType: 6,
  12065. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12066. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  12067. Status: 1,
  12068. CreateTime: time.Now().Unix(),
  12069. UpdateTime: time.Now().Unix(),
  12070. ExportTime: time.Now().Unix(),
  12071. }
  12072. service.CreateExportErrLog(&err_log)
  12073. continue
  12074. }
  12075. project.ProjectName = project_name
  12076. prices := projectM["price"].(string)
  12077. price, _ := strconv.ParseFloat(prices, 64)
  12078. if price <= 0 { //名字为空则生成一条导入错误日志
  12079. err_log := models.ExportErrLog{
  12080. LogType: 6,
  12081. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12082. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  12083. Status: 1,
  12084. CreateTime: time.Now().Unix(),
  12085. UpdateTime: time.Now().Unix(),
  12086. ExportTime: time.Now().Unix(),
  12087. }
  12088. service.CreateExportErrLog(&err_log)
  12089. continue
  12090. }
  12091. project.Price = price
  12092. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  12093. utils.ErrorLog("unit_id")
  12094. return
  12095. }
  12096. unit := projectM["unit"].(string)
  12097. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  12098. err_log := models.ExportErrLog{
  12099. LogType: 6,
  12100. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12101. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  12102. Status: 1,
  12103. CreateTime: time.Now().Unix(),
  12104. UpdateTime: time.Now().Unix(),
  12105. ExportTime: time.Now().Unix(),
  12106. }
  12107. service.CreateExportErrLog(&err_log)
  12108. continue
  12109. }
  12110. project.Unit = unit
  12111. cost_classify := projectM["cost_classify"].(string)
  12112. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  12113. err_log := models.ExportErrLog{
  12114. LogType: 6,
  12115. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12116. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12117. Status: 1,
  12118. CreateTime: time.Now().Unix(),
  12119. UpdateTime: time.Now().Unix(),
  12120. ExportTime: time.Now().Unix(),
  12121. }
  12122. service.CreateExportErrLog(&err_log)
  12123. continue
  12124. }
  12125. var costClassify = "费用类别"
  12126. var cost_classify_id int64
  12127. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  12128. if len(cost_classify) != 0 {
  12129. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  12130. if errcode == gorm.ErrRecordNotFound {
  12131. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  12132. dataconfig := models.DictDataconfig{
  12133. ParentId: costClassifyConfig.ID,
  12134. Module: "system",
  12135. OrgId: orgId,
  12136. Name: cost_classify,
  12137. FieldName: "",
  12138. Value: costConfig.Value + 1,
  12139. CreatedTime: "",
  12140. UpdatedTime: "",
  12141. CreateUserId: adminUser.AdminUser.Id,
  12142. Status: 1,
  12143. Remark: "",
  12144. DeleteIdSystem: 0,
  12145. Title: "",
  12146. Content: "",
  12147. Order: 0,
  12148. Code: "",
  12149. }
  12150. service.CreatedDicConfig(&dataconfig)
  12151. }
  12152. }
  12153. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  12154. for _, it := range costClassList {
  12155. if cost_classify == it.Name {
  12156. cost_classify_id = int64(it.Value)
  12157. }
  12158. }
  12159. project.CostClassify = cost_classify_id
  12160. executive_section := projectM["executive_section"].(string)
  12161. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  12162. err_log := models.ExportErrLog{
  12163. LogType: 6,
  12164. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12165. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  12166. Status: 1,
  12167. CreateTime: time.Now().Unix(),
  12168. UpdateTime: time.Now().Unix(),
  12169. ExportTime: time.Now().Unix(),
  12170. }
  12171. service.CreateExportErrLog(&err_log)
  12172. continue
  12173. }
  12174. if len(executive_section) != 0 {
  12175. //查找科室是否有内容
  12176. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  12177. if errcodedepart == gorm.ErrRecordNotFound {
  12178. department := models.XtHisDepartment{
  12179. Name: executive_section,
  12180. Status: 1,
  12181. UserOrgId: adminUser.CurrentOrgId,
  12182. CreatedTime: time.Now().Unix(),
  12183. }
  12184. service.CreateDePartment(&department)
  12185. }
  12186. }
  12187. var executive_section_id int64
  12188. departMentList, _ := service.GetAllDepartMent(orgId)
  12189. for _, it := range departMentList {
  12190. if executive_section == it.Name {
  12191. executive_section_id = it.ID
  12192. }
  12193. }
  12194. project.ExecutiveSection = executive_section_id
  12195. medical_coverage := projectM["medical_coverage"].(string)
  12196. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  12197. err_log := models.ExportErrLog{
  12198. LogType: 6,
  12199. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12200. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12201. Status: 1,
  12202. CreateTime: time.Now().Unix(),
  12203. UpdateTime: time.Now().Unix(),
  12204. ExportTime: time.Now().Unix(),
  12205. }
  12206. service.CreateExportErrLog(&err_log)
  12207. continue
  12208. }
  12209. var medicalCoverage = "医保等级"
  12210. var medical_coverage_id int64
  12211. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  12212. if len(medical_coverage) != 0 {
  12213. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  12214. if errormedicalcoverage == gorm.ErrRecordNotFound {
  12215. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  12216. dataconfig := models.DictDataconfig{
  12217. ParentId: medicalCoverageConfig.ID,
  12218. Module: "system",
  12219. OrgId: orgId,
  12220. Name: medical_coverage,
  12221. FieldName: "",
  12222. Value: medicalCoverageConfig.Value + 1,
  12223. CreatedTime: "",
  12224. UpdatedTime: "",
  12225. CreateUserId: adminUser.AdminUser.Id,
  12226. Status: 1,
  12227. Remark: "",
  12228. DeleteIdSystem: 0,
  12229. Title: "",
  12230. Content: "",
  12231. Order: 0,
  12232. Code: "",
  12233. }
  12234. service.CreatedDicConfig(&dataconfig)
  12235. }
  12236. }
  12237. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12238. for _, it := range medicalCoverageList {
  12239. if medical_coverage == it.Name {
  12240. medical_coverage_id = int64(it.Value)
  12241. }
  12242. }
  12243. project.MedicalCoverage = medical_coverage_id
  12244. pinyin := projectM["pinyin"].(string)
  12245. project.Pinyin = pinyin
  12246. wubi := projectM["wubi"].(string)
  12247. project.Wubi = wubi
  12248. statistical_classification := projectM["statistical_classification"].(string)
  12249. var statisticalClassification = "统计分类"
  12250. var statistical_classification_id int64
  12251. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12252. if len(statistical_classification) != 0 {
  12253. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12254. if classificationerrcodes == gorm.ErrRecordNotFound {
  12255. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12256. dataconfig := models.DictDataconfig{
  12257. ParentId: classiFication.ID,
  12258. Module: "system",
  12259. OrgId: orgId,
  12260. Name: statistical_classification,
  12261. FieldName: "",
  12262. Value: classiFicationConfig.Value + 1,
  12263. CreatedTime: "",
  12264. UpdatedTime: "",
  12265. CreateUserId: adminUser.AdminUser.Id,
  12266. Status: 1,
  12267. Remark: "",
  12268. DeleteIdSystem: 0,
  12269. Title: "",
  12270. Content: "",
  12271. Order: 0,
  12272. Code: "",
  12273. }
  12274. service.CreatedDicConfig(&dataconfig)
  12275. }
  12276. }
  12277. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12278. for _, it := range classiFicationList {
  12279. if statistical_classification == it.Name {
  12280. statistical_classification_id = int64(it.Value)
  12281. }
  12282. }
  12283. project.StatisticalClassification = statistical_classification_id
  12284. disease_directory := int64(projectM["disease_directory"].(float64))
  12285. project.DiseaseDirectory = disease_directory
  12286. is_record := int64(projectM["is_record"].(float64))
  12287. project.IsRecord = is_record
  12288. medical_code := projectM["medical_code"].(string)
  12289. project.MedicalCode = medical_code
  12290. tube_color := projectM["tube_color"].(string)
  12291. var tubeColor = "试管颜色"
  12292. var tube_color_id int64
  12293. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12294. if len(tube_color) != 0 {
  12295. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12296. if errcodetube == gorm.ErrRecordNotFound {
  12297. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12298. dataconfig := models.DictDataconfig{
  12299. ParentId: tubeColorConfig.ID,
  12300. Module: "system",
  12301. OrgId: orgId,
  12302. Name: tube_color,
  12303. FieldName: "",
  12304. Value: tubeConfig.Value + 1,
  12305. CreatedTime: "",
  12306. UpdatedTime: "",
  12307. CreateUserId: adminUser.AdminUser.Id,
  12308. Status: 1,
  12309. Remark: "",
  12310. DeleteIdSystem: 0,
  12311. Title: "",
  12312. Content: "",
  12313. Order: 0,
  12314. Code: "",
  12315. }
  12316. service.CreatedDicConfig(&dataconfig)
  12317. }
  12318. }
  12319. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12320. for _, it := range tubeColorList {
  12321. if tube_color == it.Name {
  12322. tube_color_id = int64(it.Value)
  12323. }
  12324. }
  12325. project.TubeColor = tube_color_id
  12326. single_dose := projectM["single_dose"].(string)
  12327. project.SingleDose = single_dose
  12328. execution_frequency := projectM["execution_frequency"].(string)
  12329. project.ExecutionFrequency = execution_frequency
  12330. delivery_way := projectM["delivery_way"].(string)
  12331. project.DeliveryWay = delivery_way
  12332. number_days := projectM["number_days"].(string)
  12333. project.NumberDays = number_days
  12334. total := projectM["total"].(string)
  12335. project.Total = total
  12336. medical_status := int64(projectM["medical_status"].(float64))
  12337. project.MedicalStatus = medical_status
  12338. category := int64(projectM["category"].(float64))
  12339. project.Category = category
  12340. specail_project := int64(projectM["specail_project"].(float64))
  12341. project.SpecailProject = specail_project
  12342. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12343. project.SocialSecurityDirectoryCode = social_security_directory_code
  12344. remark := projectM["remark"].(string)
  12345. project.Remark = remark
  12346. record_date := projectM["record_date"].(string)
  12347. timeLayout := "2006-01-02"
  12348. loc, _ := time.LoadLocation("Local")
  12349. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12350. project.RecordDate = theTime.Unix()
  12351. projectList = append(projectList, &project)
  12352. }
  12353. export_time := time.Now().Unix()
  12354. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12355. if len(projectList) > 0 {
  12356. for _, item := range projectList {
  12357. hans := item.ProjectName // 要转换的汉字字符串
  12358. // 创建一个拼音转换器
  12359. p := pinyin.NewArgs()
  12360. // 将汉字转为拼音
  12361. pinyinSlice := pinyin.Pinyin(hans, p)
  12362. // 输出拼音
  12363. fmt.Println("Pinyin:", pinyinSlice)
  12364. // 获取首字母
  12365. firstLetter := ""
  12366. for _, py := range pinyinSlice {
  12367. if len(py) > 0 {
  12368. firstLetter += string(py[0][0])
  12369. }
  12370. }
  12371. item.FirstLetter = firstLetter
  12372. project := models.HisProject{
  12373. ProjectName: item.ProjectName,
  12374. Price: item.Price,
  12375. Unit: item.Unit,
  12376. CostClassify: item.CostClassify,
  12377. ExecutiveSection: item.ExecutiveSection,
  12378. MedicalCoverage: item.MedicalCoverage,
  12379. UserOrgId: orgId,
  12380. Status: 1,
  12381. CreatedTime: time.Now().Unix(),
  12382. Pinyin: item.Pinyin,
  12383. Wubi: item.Wubi,
  12384. StatisticalClassification: item.StatisticalClassification,
  12385. DiseaseDirectory: item.DiseaseDirectory,
  12386. IsRecord: item.IsRecord,
  12387. MedicalCode: item.MedicalCode,
  12388. TubeColor: item.TubeColor,
  12389. SingleDose: item.SingleDose,
  12390. DeliveryWay: item.DeliveryWay,
  12391. NumberDays: item.NumberDays,
  12392. Total: item.Total,
  12393. Category: item.Category,
  12394. MedicalStatus: item.MedicalStatus,
  12395. SpecailProject: item.SpecailProject,
  12396. RecordDate: item.RecordDate,
  12397. Remark: item.Remark,
  12398. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12399. ExecutionFrequency: item.ExecutionFrequency,
  12400. FirstLetter: item.FirstLetter,
  12401. }
  12402. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12403. if errcodeproject == gorm.ErrRecordNotFound {
  12404. service.CreateProjectInfomation(&project)
  12405. } else if errcodeproject == nil {
  12406. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12407. }
  12408. log := models.ExportLog{
  12409. LogType: 6,
  12410. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12411. TotalNum: int64(len(total_goods)),
  12412. FailNum: int64(len(errLogs)),
  12413. SuccessNum: int64(len(projectList)),
  12414. CreateTime: time.Now().Unix(),
  12415. UpdateTime: time.Now().Unix(),
  12416. ExportTime: export_time,
  12417. Status: 1,
  12418. }
  12419. service.CreateExportLog(&log)
  12420. c.ServeSuccessJSON(map[string]interface{}{
  12421. "msg": "导入成功",
  12422. "total_num": len(total_goods),
  12423. "success_num": len(projectList),
  12424. "fail_num": int64(len(errLogs)),
  12425. })
  12426. }
  12427. } else {
  12428. log := models.ExportLog{
  12429. LogType: 6,
  12430. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12431. TotalNum: int64(len(total_goods)),
  12432. FailNum: int64(len(errLogs)),
  12433. SuccessNum: int64(len(projectList)),
  12434. CreateTime: time.Now().Unix(),
  12435. UpdateTime: time.Now().Unix(),
  12436. ExportTime: export_time,
  12437. Status: 1,
  12438. }
  12439. service.CreateExportLog(&log)
  12440. c.ServeSuccessJSON(map[string]interface{}{
  12441. "msg": "导入成功",
  12442. "total_num": len(total_goods),
  12443. "success_num": len(projectList),
  12444. "fail_num": int64(len(errLogs)),
  12445. })
  12446. }
  12447. }
  12448. //func (this *HisApiController) EditProjectInformation(){
  12449. //
  12450. // id, _ := this.GetInt64("id")
  12451. // project_team := this.GetString("project_team")
  12452. // price := this.GetString("price")
  12453. // price_float, _ := strconv.ParseFloat(price, 64)
  12454. // pinyin := this.GetString("pinyin")
  12455. // wubi := this.GetString("wubi")
  12456. // tube_color, _ := this.GetInt64("tube_color")
  12457. // team_type, _ := this.GetInt64("team_type")
  12458. // remark := this.GetString("remark")
  12459. // ids := this.GetString("ids")
  12460. // item_id := this.GetString("item_id")
  12461. // projectTeam := models.XtHisProjectTeam{
  12462. // ProjectTeam: project_team,
  12463. // Price: price_float,
  12464. // Pinyin: pinyin,
  12465. // Wubi: wubi,
  12466. // TubeColor: tube_color,
  12467. // TeamType: team_type,
  12468. // Remark: remark,
  12469. // ProjectId: ids,
  12470. // ItemId: item_id,
  12471. // }
  12472. //
  12473. //
  12474. // dataBody := make(map[string]interface{}, 0)
  12475. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12476. // if err != nil {
  12477. // utils.ErrorLog(err.Error())
  12478. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12479. // return
  12480. // }
  12481. //
  12482. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12483. //
  12484. //
  12485. // if err != nil {
  12486. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12487. // return
  12488. // }
  12489. //
  12490. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12491. // infos, _ := dataBody["info"].([]interface{})
  12492. // if len(infos) > 0 {
  12493. // var ids []string
  12494. //
  12495. // for _, item := range infos {
  12496. // items := item.(map[string]interface{})
  12497. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12498. // utils.ErrorLog("id")
  12499. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12500. // return
  12501. // }
  12502. // id := int64(items["id"].(float64))
  12503. //
  12504. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12505. // utils.ErrorLog("type")
  12506. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12507. // return
  12508. // }
  12509. // types := int64(items["type"].(float64))
  12510. //
  12511. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12512. // utils.ErrorLog("number")
  12513. // }
  12514. //
  12515. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12516. //
  12517. // projectList := models.XtHisProjectList{
  12518. // Number: number,
  12519. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12520. // ProjectId: id,
  12521. // Status: 1,
  12522. // CreatedTime: time.Now().Unix(),
  12523. // UpdatedTime: time.Now().Unix(),
  12524. // TeamId: projectTeam.ID,
  12525. // Type: types,
  12526. // }
  12527. // list := projectList
  12528. //
  12529. // service.CreateProjectList(&list)
  12530. //
  12531. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12532. //
  12533. // }
  12534. // ids_str := strings.Join(ids, ",")
  12535. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12536. // service.SaveProjectTeam(&projectTeam)
  12537. // this.ServeSuccessJSON(map[string]interface{}{
  12538. // "projectTeam": projectTeam,
  12539. // })
  12540. // }
  12541. // }
  12542. //}
  12543. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12544. name := c.GetString("name")
  12545. mode_id, _ := c.GetInt64("mode", 0)
  12546. types, _ := c.GetInt64("type", 0)
  12547. patient_id, _ := c.GetInt64("patient_id", 0)
  12548. types = 1
  12549. adminInfo := c.GetAdminUserInfo()
  12550. template := &models.HisPrescriptionTemplate{
  12551. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12552. PatientId: patient_id,
  12553. Type: types,
  12554. Status: 1,
  12555. Ctime: time.Now().Unix(),
  12556. Mtime: time.Now().Unix(),
  12557. Name: name,
  12558. Mode: mode_id,
  12559. }
  12560. dataBody := make(map[string]interface{}, 0)
  12561. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12562. if err != nil {
  12563. utils.ErrorLog(err.Error())
  12564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12565. return
  12566. }
  12567. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12568. //如果已经存在记录则删除处方
  12569. if template_one.ID > 0 {
  12570. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12571. var ids []int64
  12572. var org_id int64
  12573. for _, item := range ps {
  12574. org_id = c.GetAdminUserInfo().CurrentOrgId
  12575. ids = append(ids, item.ID)
  12576. }
  12577. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12578. if err2 == nil {
  12579. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12580. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12581. if len(prescriptions) > 0 {
  12582. for _, item := range prescriptions {
  12583. items := item.(map[string]interface{})
  12584. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12585. utils.ErrorLog("type")
  12586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12587. return
  12588. }
  12589. types := int64(items["type"].(float64))
  12590. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12591. utils.ErrorLog("med_type")
  12592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12593. return
  12594. }
  12595. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12596. ctime := time.Now().Unix()
  12597. prescription := &models.HisPrescriptionInfoTemplate{
  12598. PatientId: patient_id,
  12599. UserOrgId: adminInfo.CurrentOrgId,
  12600. Ctime: ctime,
  12601. Mtime: ctime,
  12602. Type: types,
  12603. Modifier: adminInfo.AdminUser.Id,
  12604. Creator: adminInfo.AdminUser.Id,
  12605. Status: 1,
  12606. PTemplateId: template_one.ID,
  12607. MedType: med_type,
  12608. }
  12609. service.CreateHisPrescriptionInfoTemplate(prescription)
  12610. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12611. advices := items["advices"].([]interface{})
  12612. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12613. ctime := time.Now().Unix()
  12614. mtime := ctime
  12615. if len(advices) > 0 {
  12616. for _, advice := range advices {
  12617. var s models.HisPrescriptionAdviceTemplate
  12618. s.PrescriptionId = prescription.ID
  12619. s.AdviceType = 2
  12620. s.StopState = 2
  12621. s.ExecutionState = 2
  12622. s.Status = 1
  12623. s.UserOrgId = adminInfo.CurrentOrgId
  12624. s.CreatedTime = ctime
  12625. s.UpdatedTime = mtime
  12626. s.PatientId = patient_id
  12627. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12628. if errcode > 0 {
  12629. c.ServeFailJSONWithSGJErrorCode(errcode)
  12630. return
  12631. }
  12632. service.CreateHisPrescriptionAdviceTemplate(&s)
  12633. }
  12634. }
  12635. }
  12636. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12637. projects := items["project"].([]interface{})
  12638. if len(projects) > 0 {
  12639. for _, project := range projects {
  12640. var p models.HisPrescriptionProjectTemplate
  12641. p.PrescriptionId = prescription.ID
  12642. p.Ctime = time.Now().Unix()
  12643. p.Mtime = time.Now().Unix()
  12644. p.PatientId = patient_id
  12645. p.UserOrgId = adminInfo.CurrentOrgId
  12646. p.Status = 1
  12647. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12648. if errcode > 0 {
  12649. c.ServeFailJSONWithSGJErrorCode(errcode)
  12650. return
  12651. }
  12652. service.CreateHisPrescriptionProjectTemplate(&p)
  12653. }
  12654. }
  12655. }
  12656. }
  12657. c.ServeSuccessJSON(map[string]interface{}{
  12658. "msg": "创建成功",
  12659. })
  12660. }
  12661. }
  12662. } else {
  12663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12664. return
  12665. }
  12666. } else {
  12667. err3 := service.CreateHisPrescriptionTemplate(template)
  12668. if err3 == nil {
  12669. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12670. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12671. if len(prescriptions) > 0 {
  12672. for _, item := range prescriptions {
  12673. items := item.(map[string]interface{})
  12674. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12675. utils.ErrorLog("type")
  12676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12677. return
  12678. }
  12679. types := int64(items["type"].(float64))
  12680. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12681. utils.ErrorLog("med_type")
  12682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12683. return
  12684. }
  12685. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12686. ctime := time.Now().Unix()
  12687. prescription := &models.HisPrescriptionInfoTemplate{
  12688. PatientId: patient_id,
  12689. UserOrgId: adminInfo.CurrentOrgId,
  12690. Ctime: ctime,
  12691. Mtime: ctime,
  12692. Type: types,
  12693. Modifier: adminInfo.AdminUser.Id,
  12694. Creator: adminInfo.AdminUser.Id,
  12695. Status: 1,
  12696. PTemplateId: template.ID,
  12697. MedType: med_type,
  12698. }
  12699. service.CreateHisPrescriptionInfoTemplate(prescription)
  12700. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12701. advices := items["advices"].([]interface{})
  12702. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12703. ctime := time.Now().Unix()
  12704. mtime := ctime
  12705. if len(advices) > 0 {
  12706. for _, advice := range advices {
  12707. var s models.HisPrescriptionAdviceTemplate
  12708. s.PrescriptionId = prescription.ID
  12709. s.AdviceType = 2
  12710. s.StopState = 2
  12711. s.ExecutionState = 2
  12712. s.Status = 1
  12713. s.UserOrgId = adminInfo.CurrentOrgId
  12714. s.CreatedTime = ctime
  12715. s.UpdatedTime = mtime
  12716. s.PatientId = patient_id
  12717. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12718. if errcode > 0 {
  12719. c.ServeFailJSONWithSGJErrorCode(errcode)
  12720. return
  12721. }
  12722. service.CreateHisPrescriptionAdviceTemplate(&s)
  12723. }
  12724. }
  12725. }
  12726. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12727. projects := items["project"].([]interface{})
  12728. if len(projects) > 0 {
  12729. for _, project := range projects {
  12730. var p models.HisPrescriptionProjectTemplate
  12731. p.PrescriptionId = prescription.ID
  12732. p.Ctime = time.Now().Unix()
  12733. p.Mtime = time.Now().Unix()
  12734. p.PatientId = patient_id
  12735. p.UserOrgId = adminInfo.CurrentOrgId
  12736. p.Status = 1
  12737. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12738. if errcode > 0 {
  12739. c.ServeFailJSONWithSGJErrorCode(errcode)
  12740. return
  12741. }
  12742. service.CreateHisPrescriptionProjectTemplate(&p)
  12743. }
  12744. }
  12745. }
  12746. }
  12747. c.ServeSuccessJSON(map[string]interface{}{
  12748. "msg": "创建成功",
  12749. })
  12750. }
  12751. }
  12752. } else {
  12753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12754. return
  12755. }
  12756. }
  12757. }
  12758. func (c *HisApiController) PreSettle() {
  12759. id, _ := c.GetInt64("id")
  12760. record_time := c.GetString("record_time")
  12761. his_patient_id, _ := c.GetInt64("his_patient_id")
  12762. timeLayout := "2006-01-02"
  12763. loc, _ := time.LoadLocation("Local")
  12764. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12765. diagnosis_id := c.GetString("diagnosis")
  12766. sick_type, _ := c.GetInt64("sick_type")
  12767. reg_type, _ := c.GetInt64("p_type")
  12768. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12769. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12770. if err != nil {
  12771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12772. return
  12773. }
  12774. recordDateTime := theTime.Unix()
  12775. adminUser := c.GetAdminUserInfo()
  12776. var prescriptions []*models.HisPrescription
  12777. var start_time int64
  12778. var end_time int64
  12779. ids_str := c.GetString("ids")
  12780. ids_arr := strings.Split(ids_str, ",")
  12781. fmt.Println(reg_type)
  12782. if settle_accounts_type == 1 { //日结
  12783. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12784. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12785. } else {
  12786. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12787. }
  12788. fmt.Println(prescriptions)
  12789. } else { //月结
  12790. start_time_str := c.GetString("start_time")
  12791. end_time_str := c.GetString("end_time")
  12792. timeLayout := "2006-01-02"
  12793. loc, _ := time.LoadLocation("Local")
  12794. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12795. if err != nil {
  12796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12797. return
  12798. }
  12799. recordStartTime := theStartTime.Unix()
  12800. start_time = recordStartTime
  12801. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12802. if err != nil {
  12803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12804. return
  12805. }
  12806. recordEndTime := theEndTime.Unix()
  12807. end_time = recordEndTime
  12808. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12809. }
  12810. if reg_type == 1111 || reg_type == 1112 {
  12811. reg_type = 11
  12812. }
  12813. timestamp := time.Now().Unix()
  12814. tempTime := time.Unix(timestamp, 0)
  12815. timeFormat := tempTime.Format("20060102150405")
  12816. chrgBchno := rand.Intn(100000) + 10000
  12817. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12818. strconv.FormatInt(his.PatientId, 10)
  12819. var ids []int64
  12820. for _, item := range prescriptions {
  12821. ids = append(ids, item.ID)
  12822. }
  12823. fmt.Println(ids)
  12824. var total float64
  12825. for _, item := range prescriptions {
  12826. fmt.Println(item)
  12827. if item.Type == 1 { //药品
  12828. for _, subItem := range item.HisDoctorAdviceInfo {
  12829. total = total + (subItem.Price * subItem.PrescribingNumber)
  12830. }
  12831. }
  12832. if item.Type == 2 { //项目
  12833. for _, subItem := range item.HisPrescriptionProject {
  12834. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12835. total = total + (subItem.Price * cnt)
  12836. }
  12837. }
  12838. for _, subItem := range item.HisAdditionalCharge {
  12839. total = total + (subItem.Price * float64(subItem.Count))
  12840. }
  12841. }
  12842. allTotal := fmt.Sprintf("%.2f", total)
  12843. totals, _ := strconv.ParseFloat(allTotal, 64)
  12844. order := &models.HisOrder{
  12845. UserOrgId: adminUser.CurrentOrgId,
  12846. HisPatientId: his.ID,
  12847. PatientId: id,
  12848. SettleAccountsDate: recordDateTime,
  12849. Ctime: time.Now().Unix(),
  12850. Mtime: time.Now().Unix(),
  12851. Status: 1,
  12852. OrderStatus: 1,
  12853. MdtrtId: his.Number,
  12854. Number: chrg_bchno,
  12855. MedfeeSumamt: totals,
  12856. SettleEndTime: end_time,
  12857. SettleStartTime: start_time,
  12858. SettleType: settle_accounts_type,
  12859. PsnPartAmt: totals,
  12860. PsnCashPay: totals,
  12861. PType: 2,
  12862. IsPre: 1,
  12863. MedType: strconv.Itoa(int(reg_type)),
  12864. Diagnosis: diagnosis_id,
  12865. }
  12866. err = service.CreateOrder(order)
  12867. if err != nil {
  12868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12869. return
  12870. }
  12871. var customs []*Custom
  12872. for _, item := range prescriptions {
  12873. fmt.Println(item.Type)
  12874. if item.Type == 1 { //药品
  12875. for _, subItem := range item.HisDoctorAdviceInfo {
  12876. cus := &Custom{
  12877. AdviceId: subItem.ID,
  12878. ProjectId: 0,
  12879. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12880. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12881. FeedetlSn: subItem.FeedetlSn,
  12882. Price: fmt.Sprintf("%.2f", subItem.Price),
  12883. MedListCodg: subItem.MedListCodg,
  12884. Type: 1,
  12885. }
  12886. customs = append(customs, cus)
  12887. }
  12888. }
  12889. if item.Type == 2 { //项目
  12890. for _, subItem := range item.HisPrescriptionProject {
  12891. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12892. cus := &Custom{
  12893. AdviceId: 0,
  12894. ProjectId: subItem.ID,
  12895. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12896. Cut: fmt.Sprintf("%.2f", cnt),
  12897. FeedetlSn: subItem.FeedetlSn,
  12898. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12899. MedListCodg: subItem.MedListCodg,
  12900. Type: 2,
  12901. }
  12902. customs = append(customs, cus)
  12903. }
  12904. }
  12905. for _, item := range item.HisAdditionalCharge {
  12906. cus := &Custom{
  12907. ItemId: item.ID,
  12908. AdviceId: 0,
  12909. ProjectId: 0,
  12910. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12911. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12912. FeedetlSn: item.FeedetlSn,
  12913. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12914. MedListCodg: item.XtHisAddtionConfig.Code,
  12915. Type: 3,
  12916. }
  12917. customs = append(customs, cus)
  12918. }
  12919. }
  12920. fmt.Println(customs)
  12921. for _, item := range customs {
  12922. var advice_id int64 = 0
  12923. var project_id int64 = 0
  12924. var item_id int64 = 0
  12925. var types int64 = 0
  12926. if item.Type == 1 {
  12927. advice_id = item.AdviceId
  12928. project_id = 0
  12929. item_id = 0
  12930. } else if item.Type == 2 {
  12931. advice_id = 0
  12932. item_id = 0
  12933. project_id = item.ProjectId
  12934. } else if item.Type == 3 {
  12935. advice_id = 0
  12936. item_id = item.ItemId
  12937. project_id = 0
  12938. }
  12939. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12940. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12941. pric, _ := strconv.ParseFloat(item.Price, 32)
  12942. info := &models.HisOrderInfo{
  12943. OrderNumber: order.Number,
  12944. UploadDate: time.Now().Unix(),
  12945. AdviceId: advice_id,
  12946. DetItemFeeSumamt: detItemFeeSumamt,
  12947. Cnt: cut,
  12948. Pric: pric,
  12949. PatientId: id,
  12950. Status: 1,
  12951. Mtime: time.Now().Unix(),
  12952. Ctime: time.Now().Unix(),
  12953. UserOrgId: adminUser.CurrentOrgId,
  12954. HisPatientId: his.ID,
  12955. OrderId: order.ID,
  12956. ProjectId: project_id,
  12957. Type: types,
  12958. ItemId: item_id,
  12959. }
  12960. service.CreateOrderInfo(info)
  12961. }
  12962. his.SickType = sick_type
  12963. service.UpdataHisPateint(&his)
  12964. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12965. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12966. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12967. if err == nil {
  12968. c.ServeSuccessJSON(map[string]interface{}{
  12969. "msg": "结算成功",
  12970. })
  12971. }
  12972. }
  12973. type CustomOrderInfo struct {
  12974. Name string
  12975. Spec string
  12976. Unit string
  12977. Count float64
  12978. Price float64
  12979. Total float64
  12980. }
  12981. func (c *HisApiController) GetPrivateExpensesInfo() {
  12982. order_id, _ := c.GetInt64("id", 0)
  12983. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12984. order, _ := service.GetHisOrderByID(order_id)
  12985. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12986. if order.ID == 0 {
  12987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12988. return
  12989. }
  12990. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12991. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12992. org_id := c.GetAdminUserInfo().CurrentOrgId
  12993. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12994. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12995. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12996. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12997. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12998. //var orderInfos_four []*models.HisOrderInfoTwo
  12999. //for _, item := range orderInfos_three {
  13000. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  13001. // item.HisPrescriptionProject.IsCheckTeam = 1
  13002. // orderInfos_four = append(orderInfos_four, item)
  13003. //
  13004. // }
  13005. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  13006. // item.HisPrescriptionProject.IsCheckTeam = 2
  13007. // orderInfos_two = append(orderInfos_two, item)
  13008. // }
  13009. //}
  13010. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  13011. //var cus_slice []CustomOrderInfo
  13012. //for _, item := range new_order_info {
  13013. // var cus CustomOrderInfo
  13014. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  13015. // cus.Unit = ""
  13016. // cus.Spec = ""
  13017. // var total float64
  13018. // for _, subItem := range orderInfos_four {
  13019. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  13020. // total = total + subItem.DetItemFeeSumamt
  13021. // fmt.Println(subItem.DetItemFeeSumamt)
  13022. // }
  13023. // }
  13024. // cus.Count = 1
  13025. // cus.Total = total
  13026. // cus_slice = append(cus_slice, cus)
  13027. //}
  13028. orderInfos = append(orderInfos, orderInfos_two...)
  13029. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  13030. //orderInfos = append(orderInfos, orderInfos_three...)
  13031. //}/**/
  13032. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  13033. c.ServeSuccessJSON(map[string]interface{}{
  13034. "order": order,
  13035. "order_info": orderInfos,
  13036. "patient": patient,
  13037. "admin_info": adminInfo,
  13038. "his": his,
  13039. "current_admin": role,
  13040. "org_config": miConfig,
  13041. //"new_order_info": cus_slice,
  13042. })
  13043. }
  13044. func (this *HisApiController) ChangeMedType() {
  13045. med_type := this.GetString("med_type")
  13046. old_med_type := this.GetString("old_med_type")
  13047. ids := this.GetString("ids")
  13048. settle_type, _ := this.GetInt64("settle_type")
  13049. start_time := this.GetString("start_time")
  13050. end_time := this.GetString("end_time")
  13051. ids_arr := strings.Split(ids, ",")
  13052. if settle_type == 1 { //日结
  13053. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  13054. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  13055. prescription.MedType = med_type
  13056. err := service.SaveHisPrescriptionTwo(&prescription)
  13057. if err == nil {
  13058. this.ServeSuccessJSON(map[string]interface{}{
  13059. "msg": "修改成功",
  13060. })
  13061. } else {
  13062. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13063. return
  13064. }
  13065. } else if settle_type == 2 {
  13066. timeLayout := "2006-01-02"
  13067. loc, _ := time.LoadLocation("Local")
  13068. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13069. if err != nil {
  13070. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13071. return
  13072. }
  13073. recordStartTime := theStartTime.Unix()
  13074. start_time_timestamp := recordStartTime
  13075. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  13076. if err != nil {
  13077. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13078. return
  13079. }
  13080. recordEndTime := theEndTime.Unix()
  13081. end_time_timestamp := recordEndTime
  13082. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  13083. if updateErr == nil {
  13084. this.ServeSuccessJSON(map[string]interface{}{
  13085. "msg": "修改成功",
  13086. })
  13087. } else {
  13088. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13089. return
  13090. }
  13091. }
  13092. }
  13093. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  13094. patient_id, _ := c.GetInt64("patient_id")
  13095. his_patient_id, _ := c.GetInt64("his_patient_id")
  13096. record_date := c.GetString("record_date")
  13097. start_time := c.GetString("start_time")
  13098. end_time := c.GetString("end_time")
  13099. order_status, _ := c.GetInt64("type", 0)
  13100. p_type, _ := c.GetInt64("p_type", 0)
  13101. order_id, _ := c.GetInt64("order_id", 0)
  13102. timeLayout := "2006-01-02"
  13103. loc, _ := time.LoadLocation("Local")
  13104. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13105. if err != nil {
  13106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13107. return
  13108. }
  13109. recordDateTime := theTime.Unix()
  13110. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13111. if err != nil {
  13112. }
  13113. startRecordDateTime := startTime.Unix()
  13114. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13115. if err != nil {
  13116. }
  13117. endRecordDateTime := endTime.Unix()
  13118. admin := c.GetAdminUserInfo()
  13119. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  13120. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13121. order, _ := service.GetHisOrderByID(order_id)
  13122. var monthPrescriptions []*models.HisPrescription
  13123. if order_status == 1 || order_status == 0 {
  13124. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13125. } else if order_status == 2 {
  13126. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  13127. }
  13128. var settle_total float64
  13129. for _, item := range monthPrescriptions {
  13130. if len(item.HisPrescriptionProject) > 0 {
  13131. for _, subItem := range item.HisPrescriptionProject {
  13132. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13133. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13134. settle_total = settle_total + total
  13135. }
  13136. }
  13137. if len(item.HisDoctorAdviceInfo) > 0 {
  13138. for _, subItem := range item.HisDoctorAdviceInfo {
  13139. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13140. settle_total = settle_total + total
  13141. }
  13142. }
  13143. }
  13144. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13145. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13146. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13147. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13148. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13149. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13150. //获取所有科室信息
  13151. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13152. var dia string
  13153. for _, item := range month_p_info {
  13154. if len(dia) == 0 {
  13155. dia = item.Diagnosis
  13156. } else {
  13157. dia = dia + "," + item.Diagnosis
  13158. }
  13159. }
  13160. dia_arr := removeDuplicates(strings.Split(dia, ","))
  13161. dia_arr = removeEmptyStrings(dia_arr)
  13162. c.ServeSuccessJSON(map[string]interface{}{
  13163. "his_info": his_patient_info,
  13164. "xt_info": xt_patient_info,
  13165. "case_history": case_history,
  13166. "info": patientPrescriptionInfo,
  13167. "last_info": lastPatientPrescriptionInfo,
  13168. "month_prescriptions": monthPrescriptions,
  13169. "order": order,
  13170. "doctors": doctors,
  13171. "department": department,
  13172. "settle_total": settle_total,
  13173. "dia_arr": dia_arr,
  13174. })
  13175. return
  13176. }
  13177. func removeEmptyStrings(input []string) []string {
  13178. var output []string
  13179. for _, s := range input {
  13180. if s != "" {
  13181. output = append(output, s)
  13182. }
  13183. }
  13184. return output
  13185. }
  13186. func removeDuplicates(input []string) []string {
  13187. seen := make(map[string]bool)
  13188. output := []string{}
  13189. for _, s := range input {
  13190. if _, exists := seen[s]; !exists {
  13191. seen[s] = true
  13192. output = append(output, s)
  13193. }
  13194. }
  13195. return output
  13196. }
  13197. func (c *HisApiController) GetHisMonthPatientInfo() {
  13198. patient_id, _ := c.GetInt64("patient_id")
  13199. his_patient_id, _ := c.GetInt64("his_patient_id")
  13200. record_date := c.GetString("record_date")
  13201. number := c.GetString("number")
  13202. start_time := c.GetString("start_time")
  13203. end_time := c.GetString("end_time")
  13204. p_type, _ := c.GetInt64("p_type")
  13205. timeLayout := "2006-01-02"
  13206. loc, _ := time.LoadLocation("Local")
  13207. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13208. if err != nil {
  13209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13210. return
  13211. }
  13212. recordDateTime := theTime.Unix()
  13213. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13214. if err != nil {
  13215. }
  13216. startRecordDateTime := startTime.Unix()
  13217. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13218. if err != nil {
  13219. }
  13220. endRecordDateTime := endTime.Unix()
  13221. admin := c.GetAdminUserInfo()
  13222. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  13223. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13224. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  13225. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13226. var settle_total float64
  13227. for _, item := range monthPrescriptions {
  13228. if len(item.HisPrescriptionProject) > 0 {
  13229. for _, subItem := range item.HisPrescriptionProject {
  13230. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13231. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13232. settle_total = settle_total + total
  13233. }
  13234. }
  13235. if len(item.HisDoctorAdviceInfo) > 0 {
  13236. for _, subItem := range item.HisDoctorAdviceInfo {
  13237. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13238. settle_total = settle_total + total
  13239. }
  13240. }
  13241. }
  13242. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13243. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13244. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13245. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13246. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13247. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13248. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13249. //获取所有科室信息
  13250. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13251. c.ServeSuccessJSON(map[string]interface{}{
  13252. "his_info": his_patient_info,
  13253. "xt_info": xt_patient_info,
  13254. "case_history": case_history,
  13255. "info": patientPrescriptionInfo,
  13256. "month_prescriptions": monthPrescriptions,
  13257. "order": order,
  13258. "doctors": doctors,
  13259. "department": department,
  13260. "count": count,
  13261. "drugStockConfig": drugStockConfig,
  13262. "last_info": lastPatientPrescriptionInfo,
  13263. "settle_total": settle_total,
  13264. })
  13265. return
  13266. }
  13267. func (c *HisApiController) GetAllOrder() {
  13268. org_id := c.GetAdminUserInfo().CurrentOrgId
  13269. orders, _ := service.GetNewHisOrderList(org_id)
  13270. c.ServeSuccessJSON(map[string]interface{}{
  13271. "order": orders,
  13272. })
  13273. return
  13274. }
  13275. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13276. newArr = make([]*models.HisOrderInfoTwo, 0)
  13277. for i := 0; i < len(arr); i++ {
  13278. repeat := false
  13279. for j := i + 1; j < len(arr); j++ {
  13280. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13281. repeat = true
  13282. break
  13283. }
  13284. }
  13285. if !repeat {
  13286. newArr = append(newArr, arr[i])
  13287. }
  13288. }
  13289. return
  13290. }
  13291. // 修改处方退库操作 参数传修改之前的处方数据
  13292. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13293. if advice.ExecutionState == 1 {
  13294. //查询该病人该药品是否有库存记录
  13295. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13296. if errcode == gorm.ErrRecordNotFound {
  13297. } else {
  13298. //退库
  13299. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13300. if advice.PrescribingNumberUnit == drug.MinUnit {
  13301. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13302. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13303. //退库
  13304. warehouseInfo := models.DrugWarehouseInfo{
  13305. StockMinNumber: prescribingNumber,
  13306. }
  13307. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13308. operation_time := time.Now().Unix()
  13309. creater := advice.AdviceDoctor
  13310. ctime := time.Now().Unix()
  13311. timeStr := time.Now().Format("2006-01-02")
  13312. timeArr := strings.Split(timeStr, "-")
  13313. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13314. total = total + 1
  13315. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13316. cancelStock := models.DrugCancelStock{
  13317. OrderNumber: orderNumber,
  13318. OperaTime: operation_time,
  13319. OrgId: advice.UserOrgId,
  13320. Creater: creater,
  13321. Ctime: ctime,
  13322. Status: 1,
  13323. ReturnTime: advice.AdviceDate,
  13324. Dealer: info.Dealer,
  13325. Manufacturer: info.Manufacturer,
  13326. Type: 1,
  13327. }
  13328. service.AddSigleDrugCancelStock(&cancelStock)
  13329. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13330. dealer, _ := service.GetDealerById(info.Dealer)
  13331. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13332. cancelStockInfo := models.DrugCancelStockInfo{
  13333. OrderNumber: cancelInfo.OrderNumber,
  13334. CancelStockId: cancelInfo.ID,
  13335. DrugId: info.DrugId,
  13336. Count: info.Count,
  13337. Status: 1,
  13338. Ctime: ctime,
  13339. OrgId: advice.UserOrgId,
  13340. Type: 1,
  13341. Manufacturer: manufactureName.ManufacturerName,
  13342. Dealer: dealer.DealerName,
  13343. Total: 0,
  13344. RetailPrice: info.RetailPrice,
  13345. RetailTotalPrice: info.RetailTotalPrice,
  13346. Price: info.Price,
  13347. RegisterAccount: "",
  13348. Remark: info.Remark,
  13349. BatchNumber: info.BatchNumber,
  13350. MaxUnit: info.CountUnit,
  13351. ProductDate: info.ProductDate,
  13352. ExpiryDate: info.ExpiryDate,
  13353. BatchNumberId: info.WarehouseInfoId,
  13354. }
  13355. flow := models.DrugFlow{
  13356. WarehousingId: 0,
  13357. DrugId: info.DrugId,
  13358. Number: "",
  13359. BatchNumber: info.BatchNumber,
  13360. Count: info.Count,
  13361. UserOrgId: advice.UserOrgId,
  13362. PatientId: 0,
  13363. SystemTime: ctime,
  13364. ConsumableType: 4,
  13365. IsSys: 0,
  13366. WarehousingOrder: "",
  13367. WarehouseOutId: 0,
  13368. WarehouseOutOrderNumber: "",
  13369. IsEdit: 0,
  13370. CancelStockId: cancelStock.ID,
  13371. CancelOrderNumber: cancelStock.OrderNumber,
  13372. Manufacturer: info.Manufacturer,
  13373. Dealer: info.Dealer,
  13374. Creator: advice.UserOrgId,
  13375. UpdateCreator: 0,
  13376. Status: 1,
  13377. Ctime: time.Now().Unix(),
  13378. Mtime: 0,
  13379. Price: info.Price,
  13380. WarehousingDetailId: 0,
  13381. WarehouseOutDetailId: 0,
  13382. CancelOutDetailId: 0,
  13383. ExpireDate: info.ExpiryDate,
  13384. ProductDate: info.ProductDate,
  13385. MaxUnit: info.CountUnit,
  13386. MinUnit: "",
  13387. }
  13388. service.CreatedCancelStock(cancelStockInfo)
  13389. service.CreateDrugFlowOne(flow)
  13390. } else {
  13391. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13392. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13393. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13394. warehouseInfo := models.DrugWarehouseInfo{
  13395. StockMinNumber: prescribingNumber,
  13396. }
  13397. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13398. }
  13399. operation_time := time.Now().Unix()
  13400. creater := advice.AdviceDoctor
  13401. ctime := time.Now().Unix()
  13402. timeStr := time.Now().Format("2006-01-02")
  13403. timeArr := strings.Split(timeStr, "-")
  13404. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13405. total = total + 1
  13406. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13407. cancelStock := models.DrugCancelStock{
  13408. OrderNumber: orderNumber,
  13409. OperaTime: operation_time,
  13410. OrgId: advice.UserOrgId,
  13411. Creater: creater,
  13412. Ctime: ctime,
  13413. Status: 1,
  13414. ReturnTime: advice.AdviceDate,
  13415. Dealer: info.Dealer,
  13416. Manufacturer: info.Manufacturer,
  13417. Type: 1,
  13418. }
  13419. service.AddSigleDrugCancelStock(&cancelStock)
  13420. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13421. dealer, _ := service.GetDealerById(info.Dealer)
  13422. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13423. cancelStockInfo := models.DrugCancelStockInfo{
  13424. OrderNumber: cancelInfo.OrderNumber,
  13425. CancelStockId: cancelInfo.ID,
  13426. DrugId: info.DrugId,
  13427. Count: info.Count,
  13428. Status: 1,
  13429. Ctime: ctime,
  13430. OrgId: advice.UserOrgId,
  13431. Type: 1,
  13432. Manufacturer: manufactureName.ManufacturerName,
  13433. Dealer: dealer.DealerName,
  13434. Total: 0,
  13435. RetailPrice: info.RetailPrice,
  13436. RetailTotalPrice: info.RetailTotalPrice,
  13437. Price: info.Price,
  13438. RegisterAccount: "",
  13439. Remark: info.Remark,
  13440. BatchNumber: info.BatchNumber,
  13441. MaxUnit: info.CountUnit,
  13442. ProductDate: info.ProductDate,
  13443. ExpiryDate: info.ExpiryDate,
  13444. BatchNumberId: info.WarehouseInfoId,
  13445. }
  13446. flow := models.DrugFlow{
  13447. WarehousingId: 0,
  13448. DrugId: info.DrugId,
  13449. Number: "",
  13450. BatchNumber: info.BatchNumber,
  13451. Count: info.Count,
  13452. UserOrgId: advice.UserOrgId,
  13453. PatientId: 0,
  13454. SystemTime: ctime,
  13455. ConsumableType: 4,
  13456. IsSys: 0,
  13457. WarehousingOrder: "",
  13458. WarehouseOutId: 0,
  13459. WarehouseOutOrderNumber: "",
  13460. IsEdit: 0,
  13461. CancelStockId: cancelStock.ID,
  13462. CancelOrderNumber: cancelStock.OrderNumber,
  13463. Manufacturer: info.Manufacturer,
  13464. Dealer: info.Dealer,
  13465. Creator: advice.AdviceDoctor,
  13466. UpdateCreator: 0,
  13467. Status: 1,
  13468. Ctime: time.Now().Unix(),
  13469. Mtime: 0,
  13470. Price: info.Price,
  13471. WarehousingDetailId: 0,
  13472. WarehouseOutDetailId: 0,
  13473. CancelOutDetailId: 0,
  13474. ExpireDate: info.ExpiryDate,
  13475. ProductDate: info.ProductDate,
  13476. MaxUnit: info.CountUnit,
  13477. MinUnit: "",
  13478. }
  13479. service.CreatedCancelStock(cancelStockInfo)
  13480. service.CreateDrugFlowOne(flow)
  13481. }
  13482. }
  13483. }
  13484. return err
  13485. }
  13486. func (this *HisApiController) DeleteNCDS() {
  13487. id, _ := this.GetInt64("id", 0)
  13488. if id > 0 {
  13489. service.DeletePsnNCDSRecordById(id)
  13490. this.ServeSuccessJSON(map[string]interface{}{
  13491. "msg": "删除成功",
  13492. })
  13493. } else {
  13494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13495. return
  13496. }
  13497. }
  13498. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13499. id, _ := c.GetInt64("id")
  13500. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13501. c.ServeSuccessJSON(map[string]interface{}{
  13502. "advice": advice,
  13503. })
  13504. return
  13505. }
  13506. func (c *HisApiController) GetHisMonthChargePatientList() {
  13507. record_date := c.GetString("record_date")
  13508. start_time := c.GetString("start_time")
  13509. end_time := c.GetString("end_time")
  13510. timeLayout := "2006-01-02"
  13511. loc, _ := time.LoadLocation("Local")
  13512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13513. if err != nil {
  13514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13515. return
  13516. }
  13517. if err != nil {
  13518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13519. return
  13520. }
  13521. recordDateTime := theTime.Unix()
  13522. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13523. if err != nil {
  13524. }
  13525. startRecordDateTime := startTime.Unix()
  13526. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13527. if err != nil {
  13528. }
  13529. endRecordDateTime := endTime.Unix()
  13530. adminInfo := c.GetAdminUserInfo()
  13531. var tempMonthChargePatients []*service.MonthChargePatients
  13532. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13533. for _, item := range tempPatients {
  13534. //过滤没有处方的
  13535. if len(item.HisPrescription) == 0 {
  13536. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13537. }
  13538. }
  13539. c.ServeSuccessJSON(map[string]interface{}{
  13540. "list": tempMonthChargePatients,
  13541. })
  13542. }
  13543. // PrescriptionDifference 医嘱数量差值结构体
  13544. type PrescriptionDrugDifference struct {
  13545. DrugID int64 //基础库药品id
  13546. ID int64 //医嘱id
  13547. Difference float64 //差值
  13548. Unit string //单位
  13549. }
  13550. type PrescriptionGoodDifference struct {
  13551. GoodID int64 //基础库项目耗材id
  13552. ID int64 //医嘱id
  13553. Difference int64 //差值
  13554. Unit string //单位
  13555. Type int64 //类型
  13556. }
  13557. type EditCustomData struct {
  13558. adviceList []*models.HisDoctorAdviceInfo
  13559. projectList []*models.HisPrescriptionProject
  13560. }
  13561. type SrcCustomData struct {
  13562. adviceList []*models.HisDoctorAdviceInfo
  13563. projectList []*models.HisPrescriptionProject
  13564. }
  13565. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13566. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13567. differences := make([]*PrescriptionDrugDifference, 0)
  13568. // 创建一个 map 来存储第一个切片中的药品信息
  13569. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13570. for _, advice := range firstPrescription {
  13571. firstMap[advice.DrugId] = advice
  13572. }
  13573. // 遍历第二个切片中的药品信息,并比较数量差值
  13574. for _, advice := range secondPrescription {
  13575. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13576. diff := &PrescriptionDrugDifference{
  13577. DrugID: advice.DrugId,
  13578. ID: firstAdvice.ID,
  13579. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13580. Unit: firstAdvice.PrescribingNumberUnit,
  13581. }
  13582. differences = append(differences, diff)
  13583. }
  13584. }
  13585. return differences
  13586. }
  13587. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13588. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13589. differences := make([]*PrescriptionGoodDifference, 0)
  13590. // 创建一个 map 来存储第一个切片中的耗材信息
  13591. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13592. for _, good := range firstPrescription {
  13593. firstMap[good.ProjectId] = good
  13594. }
  13595. // 遍历第二个切片中的耗材信息,并比较数量差值
  13596. for _, good := range secondPrescription {
  13597. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13598. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13599. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13600. diff := &PrescriptionGoodDifference{
  13601. GoodID: good.ProjectId,
  13602. ID: firstGood.ID,
  13603. Difference: count - firstCount,
  13604. Unit: firstGood.Unit,
  13605. Type: firstGood.Type,
  13606. }
  13607. differences = append(differences, diff)
  13608. }
  13609. }
  13610. return differences
  13611. }
  13612. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13613. var adviceList []*models.HisDoctorAdviceInfo
  13614. var projectList []*models.HisPrescriptionProject
  13615. var advice_ids []int64
  13616. var project_ids []int64
  13617. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13618. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13619. //var tempPrescription *models.HisPrescriptionProjectscription
  13620. if len(prescriptions) > 0 {
  13621. for _, item := range prescriptions {
  13622. items := item.(map[string]interface{})
  13623. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13624. advices := items["advices"].([]interface{})
  13625. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13626. groupNo := int64(0)
  13627. ctime := time.Now().Unix()
  13628. mtime := ctime
  13629. if len(advices) > 0 {
  13630. for _, advice := range advices {
  13631. var s models.HisDoctorAdviceInfo
  13632. s.AdviceType = 2
  13633. s.StopState = 2
  13634. s.ExecutionState = 2
  13635. s.Status = 1
  13636. s.Groupno = groupNo
  13637. s.CreatedTime = ctime
  13638. s.UpdatedTime = mtime
  13639. s.IsSettle = 2
  13640. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13641. //存储切片中
  13642. if s.ID > 0 {
  13643. advice_ids = append(advice_ids, s.ID)
  13644. adviceList = append(adviceList, &s)
  13645. }
  13646. }
  13647. }
  13648. }
  13649. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13650. projects := items["project"].([]interface{})
  13651. if len(projects) > 0 {
  13652. for _, project := range projects {
  13653. var p models.HisPrescriptionProject
  13654. p.Ctime = time.Now().Unix()
  13655. p.Mtime = time.Now().Unix()
  13656. p.Status = 1
  13657. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13658. if p.ID > 0 {
  13659. project_ids = append(project_ids, p.ID)
  13660. projectList = append(projectList, &p)
  13661. }
  13662. }
  13663. }
  13664. }
  13665. }
  13666. }
  13667. }
  13668. editCustomData.projectList = projectList
  13669. editCustomData.adviceList = adviceList
  13670. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13671. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13672. srcCustomData.adviceList = list
  13673. srcCustomData.projectList = list2
  13674. return
  13675. }
  13676. func (c *HisApiController) GetAllGoodInforList() {
  13677. orgId := c.GetAdminUserInfo().CurrentOrgId
  13678. goodList, _ := service.GetAllGoodList(orgId)
  13679. c.ServeSuccessJSON(map[string]interface{}{
  13680. "goodList": goodList,
  13681. })
  13682. return
  13683. }
  13684. func (this *HisApiController) SaveGoodList() {
  13685. project_name := this.GetString("project_name")
  13686. sort, _ := this.GetInt64("sort")
  13687. orgId := this.GetAdminUserInfo().CurrentOrgId
  13688. dataBody := make(map[string]interface{}, 0)
  13689. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13690. if err != nil {
  13691. utils.ErrorLog(err.Error())
  13692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13693. return
  13694. }
  13695. goodTeam := models.XtGoodTeam{
  13696. ProjectName: project_name,
  13697. Sort: sort,
  13698. UserOrgId: orgId,
  13699. Status: 1,
  13700. Ctime: time.Now().Unix(),
  13701. Mtime: time.Now().Unix(),
  13702. }
  13703. service.CreateGoodTeam(goodTeam)
  13704. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13705. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13706. infos, _ := dataBody["info"].([]interface{})
  13707. if len(infos) > 0 {
  13708. for _, item := range infos {
  13709. items := item.(map[string]interface{})
  13710. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13711. utils.ErrorLog("good_id")
  13712. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13713. return
  13714. }
  13715. good_id := int64(items["good_id"].(float64))
  13716. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13717. utils.ErrorLog("number")
  13718. }
  13719. number := int64(items["number"].(float64))
  13720. xtGoodTeamList := models.XtGoodTeamList{
  13721. GoodId: good_id,
  13722. Count: number,
  13723. TeamId: lastGoodTeam.ID,
  13724. UserOrgId: orgId,
  13725. Status: 1,
  13726. Ctime: time.Now().Unix(),
  13727. Mtime: time.Now().Unix(),
  13728. }
  13729. service.CreateGoodList(xtGoodTeamList)
  13730. }
  13731. this.ServeSuccessJSON(map[string]interface{}{
  13732. "lastGoodTeam": lastGoodTeam,
  13733. })
  13734. }
  13735. }
  13736. return
  13737. }
  13738. func (this *HisApiController) GetGoodList() {
  13739. orgId := this.GetAdminUserInfo().CurrentOrgId
  13740. limit, _ := this.GetInt64("limit")
  13741. page, _ := this.GetInt64("page")
  13742. keyword := this.GetString("keyword")
  13743. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13744. this.ServeSuccessJSON(map[string]interface{}{
  13745. "list": list,
  13746. "total": total,
  13747. })
  13748. }
  13749. func (this *HisApiController) GetGoodNameDetail() {
  13750. id, _ := this.GetInt64("id")
  13751. orgId := this.GetAdminUserInfo().CurrentOrgId
  13752. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13753. goodList, _ := service.GetAllGoodList(orgId)
  13754. this.ServeSuccessJSON(map[string]interface{}{
  13755. "goodNameDetail": goodNameDetail,
  13756. "goodList": goodList,
  13757. })
  13758. }
  13759. func (this *HisApiController) UpdateGoodList() {
  13760. project_name := this.GetString("project_name")
  13761. sort, _ := this.GetInt64("sort")
  13762. id, _ := this.GetInt64("id")
  13763. orgId := this.GetAdminUserInfo().CurrentOrgId
  13764. dataBody := make(map[string]interface{}, 0)
  13765. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13766. if err != nil {
  13767. utils.ErrorLog(err.Error())
  13768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13769. return
  13770. }
  13771. goodTeam := models.XtGoodTeam{
  13772. ProjectName: project_name,
  13773. Sort: sort,
  13774. UserOrgId: orgId,
  13775. Status: 1,
  13776. Ctime: time.Now().Unix(),
  13777. Mtime: time.Now().Unix(),
  13778. ID: id,
  13779. }
  13780. service.SaveGoodTeam(goodTeam)
  13781. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13782. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13783. infos, _ := dataBody["info"].([]interface{})
  13784. if len(infos) > 0 {
  13785. for _, item := range infos {
  13786. items := item.(map[string]interface{})
  13787. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13788. utils.ErrorLog("good_id")
  13789. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13790. return
  13791. }
  13792. good_id := int64(items["good_id"].(float64))
  13793. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13794. utils.ErrorLog("id")
  13795. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13796. return
  13797. }
  13798. id := int64(items["id"].(float64))
  13799. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13800. utils.ErrorLog("number")
  13801. }
  13802. number := int64(items["number"].(float64))
  13803. xtGoodTeamList := models.XtGoodTeamList{
  13804. ID: id,
  13805. GoodId: good_id,
  13806. Count: number,
  13807. TeamId: lastGoodTeam.ID,
  13808. UserOrgId: orgId,
  13809. Status: 1,
  13810. Ctime: time.Now().Unix(),
  13811. Mtime: time.Now().Unix(),
  13812. }
  13813. service.SaveGoodList(xtGoodTeamList)
  13814. }
  13815. this.ServeSuccessJSON(map[string]interface{}{
  13816. "lastGoodTeam": lastGoodTeam,
  13817. })
  13818. }
  13819. }
  13820. return
  13821. }
  13822. func (this *HisApiController) DeleteGoodTeam() {
  13823. id, _ := this.GetInt64("id")
  13824. team, _ := service.DeleteGoodTeam(id)
  13825. this.ServeSuccessJSON(map[string]interface{}{
  13826. "team": team,
  13827. })
  13828. }
  13829. func (this *HisApiController) DeleteGood() {
  13830. id, _ := this.GetInt64("id")
  13831. good, _ := service.DeleteGood(id)
  13832. this.ServeSuccessJSON(map[string]interface{}{
  13833. "good": good,
  13834. })
  13835. }