his_api_controller.go 607KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619
  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("/test/net", &HisApiController{}, "get:TestNet")
  26. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  27. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  28. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  29. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  30. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  31. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  32. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  33. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  34. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  35. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  36. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  37. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  38. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  41. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  42. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  43. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  44. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  45. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  46. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  47. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  48. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  49. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  51. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  52. //新增附加费用
  53. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  54. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  55. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  56. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  57. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  58. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  59. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  60. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  61. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  62. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  63. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  64. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  65. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  66. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  67. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  68. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  92. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  93. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  94. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  95. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  96. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  97. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  98. }
  99. func (c *HisApiController) TestNet() {
  100. c.ServeSuccessJSON(map[string]interface{}{
  101. "msg": "成功",
  102. })
  103. }
  104. func (c *HisApiController) CheckHisPatient() {
  105. record_date := c.GetString("record_date")
  106. patient_id, _ := c.GetInt64("patient_id")
  107. timeLayout := "2006-01-02"
  108. loc, _ := time.LoadLocation("Local")
  109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  110. if err != nil {
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. return
  113. }
  114. recordDateTime := theTime.Unix()
  115. adminInfo := c.GetAdminUserInfo()
  116. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  117. if len(patients) > 1 {
  118. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  119. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  120. c.ServeSuccessJSON(map[string]interface{}{
  121. "status": 1,
  122. "msg": "关联",
  123. "ps": ps,
  124. "his_patient_id": patients[len(patients)-1].ID,
  125. "patient_id": patients[len(patients)-1].PatientId,
  126. })
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. }
  133. } else {
  134. c.ServeSuccessJSON(map[string]interface{}{
  135. "status": 0,
  136. "msg": "无需关联",
  137. })
  138. return
  139. }
  140. }
  141. func (c *HisApiController) AssociationHisPrescription() {
  142. record_date := c.GetString("record_date")
  143. his_patient_id, _ := c.GetInt64("his_patient_id")
  144. patient_id, _ := c.GetInt64("patient_id")
  145. p_ids := c.GetString("p_ids")
  146. p_ids_arr := strings.Split(p_ids, ",")
  147. timeLayout := "2006-01-02"
  148. loc, _ := time.LoadLocation("Local")
  149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  150. if err != nil {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. recordDateTime := theTime.Unix()
  155. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  156. if his_patient_id == 0 || his_patient.ID == 0 {
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  161. if err == nil {
  162. c.ServeSuccessJSON(map[string]interface{}{
  163. "msg": "关联处方成功",
  164. })
  165. return
  166. } else {
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  168. return
  169. }
  170. }
  171. //func (c *HisApiController) AssociationHisPrescription() {
  172. // record_date, _ := c.GetInt64("record_date")
  173. // his_patient_id, _ := c.GetInt64("his_patient_id")
  174. // patient_id, _ := c.GetInt64("patient_id")
  175. // p_ids := c.GetString("p_ids")
  176. // p_ids_arr := strings.Split(p_ids, ",")
  177. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  178. // if his_patient_id == 0 || his_patient.ID == 0 {
  179. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  180. // return
  181. // }
  182. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  183. // if err == nil {
  184. // c.ServeSuccessJSON(map[string]interface{}{
  185. // "msg": "关联处方成功",
  186. // })
  187. // return
  188. // } else {
  189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  190. // return
  191. // }
  192. //}
  193. func (c *HisApiController) GetFaPiaoNumber() {
  194. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  195. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  196. fmt.Println(count)
  197. var zero string
  198. number := count + 1
  199. //if number >= 1000 {
  200. // zero = "0000" + strconv.FormatInt(number, 10)
  201. //} else if number >= 10000 {
  202. // zero = "000" + strconv.FormatInt(number, 10)
  203. //} else if number >= 100000 {
  204. // zero = "00" + strconv.FormatInt(number, 10)
  205. //} else if number >= 1000000 {
  206. // zero = "0" + strconv.FormatInt(number, 10)
  207. //} else {
  208. zero = "0" + strconv.FormatInt(number, 10)
  209. //}
  210. c.ServeSuccessJSON(map[string]interface{}{
  211. "fapiao_number": zero,
  212. })
  213. return
  214. }
  215. func (c *HisApiController) ChangeOrderDesc() {
  216. id, _ := c.GetInt64("id")
  217. desc := c.GetString("desc")
  218. change_type := c.GetString("change_type")
  219. order, _ := service.GetHisOrderByID(id)
  220. if order.ID == 0 {
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  222. return
  223. }
  224. switch change_type {
  225. case "oth_desc":
  226. order.OthDesc = desc
  227. break
  228. case "cash_pay":
  229. order.CashPay = desc
  230. break
  231. case "jifen_pay":
  232. order.JifenPay = desc
  233. break
  234. case "card_desc":
  235. order.CardDesc = desc
  236. break
  237. case "band_card_pay":
  238. order.BandCardPay = desc
  239. break
  240. case "ali_pay":
  241. order.AliPay = desc
  242. break
  243. case "wechat_pay":
  244. order.WechatPay = desc
  245. break
  246. case "fa_piao_number":
  247. order.FaPiaoNumber = desc
  248. break
  249. case "fa_piao_code":
  250. order.FaPiaoCode = desc
  251. break
  252. }
  253. err := service.SaveHisOrder(&order)
  254. if err == nil {
  255. c.ServeSuccessJSON(map[string]interface{}{
  256. "msg": "修改成功",
  257. })
  258. return
  259. } else {
  260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  261. return
  262. }
  263. }
  264. func (c *HisApiController) GetMonthHisPatient() {
  265. record_date := c.GetString("record_date")
  266. //order_status, _ := c.GetInt64("type")
  267. timeLayout := "2006-01-02"
  268. loc, _ := time.LoadLocation("Local")
  269. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  270. if err != nil {
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  272. return
  273. }
  274. recordDateTime := theTime.Unix()
  275. adminInfo := c.GetAdminUserInfo()
  276. var tempPatients []service.NewTempPatients
  277. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  278. // 获取当前时间
  279. now := time.Now()
  280. // 获取本月的第一天
  281. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  282. // 获取下个月的第一天
  283. nextMonth := firstDay.AddDate(0, 1, 0)
  284. // 获取本月的最后一天
  285. lastDay := nextMonth.Add(-time.Nanosecond)
  286. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  287. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  288. var patients []service.NewTempPatients
  289. var patients_two []service.NewTempPatients
  290. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  291. for _, item := range tempPatients {
  292. //过滤掉没挂号的和没开处方的
  293. if len(item.HisPrescription) > 0 {
  294. patients = append(patients, item)
  295. patients_two = append(patients_two, item)
  296. }
  297. ////过滤掉没挂号的
  298. //if len(item.HisPatient) > 0 {
  299. //}
  300. }
  301. } else {
  302. for _, item := range tempPatients {
  303. //过滤掉没挂号的和没开处方的
  304. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  305. patients = append(patients, item)
  306. }
  307. ////过滤掉没挂号的
  308. //if len(item.HisPatient) > 0 {
  309. // patients_two = append(patients_two, item)
  310. //}
  311. }
  312. }
  313. c.ServeSuccessJSON(map[string]interface{}{
  314. "list": patients,
  315. "list_two": patients_two,
  316. "chargePatients": chargePatients,
  317. })
  318. }
  319. func (c *HisApiController) GetBatchSettleAccounts() {
  320. order_ids := c.GetString("order_ids")
  321. admin_user_id, _ := c.GetInt64("admin_user_id")
  322. adminUser := c.GetAdminUserInfo()
  323. orders := strings.Split(order_ids, ",")
  324. var newOrders []models.Orders
  325. for _, item := range orders {
  326. order, _ := service.GetHisOrderByIDTenOne(item)
  327. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  328. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  329. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  330. orderInfos = append(orderInfos, orderInfos_two...)
  331. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  332. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  333. var diagnosis_ids []string
  334. if his.ID > 0 {
  335. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  336. } else {
  337. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  338. }
  339. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  340. var dia_config []*models.HisXtDiagnoseConfig
  341. var name string
  342. for _, item := range diagnosis_ids {
  343. id, _ := strconv.ParseInt(item, 10, 64)
  344. diagnosisConfig, _ := service.FindDiagnoseById(id)
  345. dia_config = append(dia_config, diagnosisConfig)
  346. if len(name) == 0 {
  347. name = diagnosisConfig.ClassName
  348. } else {
  349. name = name + "," + diagnosisConfig.ClassName
  350. }
  351. }
  352. var bedCostTotal float64 = 0 //床位总费
  353. var bedCostSelfTotal float64 = 0 //床位自费
  354. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  355. var bedSelfTotal float64 = 0 //床位部分项目自费
  356. var bedInscpTotal float64 = 0 //床位部分项目自费
  357. var operationCostTotal float64 = 0 //手术费
  358. var operationCostSelfTotal float64 = 0 //手术费
  359. var operationCostPartSelfTotal float64 = 0 //手术费
  360. var operationSelfTotal float64 = 0 //床位部分项目自费
  361. var operationInscpTotal float64 = 0 //床位部分项目自费
  362. var otherCostTotal float64 = 0 //其他费用
  363. var otherCostSelfTotal float64 = 0 //其他费用
  364. var otherCostPartSelfTotal float64 = 0 //其他费用
  365. var otherSelfTotal float64 = 0 //床位部分项目自费
  366. var otherInscpTotal float64 = 0 //床位部分项目自费
  367. var materialCostTotal float64 = 0 //材料费
  368. var materialCostSelfTotal float64 = 0 //材料费
  369. var materialCostPartSelfTotal float64 = 0 //材料费
  370. var materialSelfTotal float64 = 0 //床位部分项目自费
  371. var materialInscpTotal float64 = 0 //床位部分项目自费
  372. var westernMedicineCostTotal float64 = 0 //西药费
  373. var westernMedicineCostSelfTotal float64 = 0 //西药费
  374. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  375. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  376. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  377. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  378. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  379. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  380. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  381. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  382. var checkCostTotal float64 = 0 //检查费
  383. var checkCostSelfTotal float64 = 0 //检查费
  384. var checkCostPartSelfTotal float64 = 0 //检查费
  385. var checkSelfTotal float64 = 0 //床位部分项目自费
  386. var checkInscpTotal float64 = 0 //床位部分项目自费
  387. var laboratoryCostTotal float64 = 0 //化验费
  388. var laboratoryCostSelfTotal float64 = 0 //化验费
  389. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  390. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  391. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  392. var treatCostTotal float64 = 0 //治疗费用
  393. var treatCostSelfTotal float64 = 0 //治疗费用
  394. var treatCostPartSelfTotal float64 = 0 //治疗费用
  395. var treatSelfTotal float64 = 0 //床位部分项目自费
  396. var treatInscpTotal float64 = 0 //床位部分项目自费
  397. decimal.DivisionPrecision = 2
  398. for _, item := range orderInfos {
  399. if item.MedChrgitmType == "01" { //床位费
  400. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  407. if item.MedChrgitmType == "03" { //检查费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. } else {
  415. if item.MedChrgitmType == "03" { //检查费
  416. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. }
  423. if item.MedChrgitmType == "04" { //化验费
  424. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  425. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  426. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  427. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  428. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  429. }
  430. if item.MedChrgitmType == "05" { //治疗费
  431. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  432. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  433. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  434. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  435. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  436. }
  437. if item.MedChrgitmType == "06" { //手术费
  438. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  439. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  440. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  441. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  442. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  443. }
  444. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  445. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  446. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  447. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  448. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  449. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  450. }
  451. if item.MedChrgitmType == "09" { //西药费
  452. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  453. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  454. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  455. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  456. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  457. }
  458. if item.MedChrgitmType == "11" { //中成费
  459. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  460. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  461. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  462. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  463. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  464. }
  465. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  466. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  467. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  468. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  469. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  470. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  471. }
  472. }
  473. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  474. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  475. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  476. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  477. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  478. var doctor_name string
  479. if roles.ID == 0 {
  480. doctor_name = "管理员"
  481. } else {
  482. doctor_name = roles.UserName
  483. }
  484. yiliao_leibie := ""
  485. switch order.MedType {
  486. case "11":
  487. yiliao_leibie = "普通门诊"
  488. break
  489. case "12":
  490. yiliao_leibie = "门诊挂号"
  491. break
  492. case "13":
  493. yiliao_leibie = "急诊"
  494. break
  495. case "14":
  496. yiliao_leibie = "门诊特殊病"
  497. break
  498. case "15":
  499. yiliao_leibie = "门诊统筹"
  500. break
  501. case "16":
  502. yiliao_leibie = "门诊慢性病"
  503. break
  504. case "21":
  505. yiliao_leibie = "普通住院"
  506. break
  507. }
  508. var newOrder models.Orders
  509. newOrder.Diagnosis = name
  510. newOrder.OrderInfos = orderInfos
  511. newOrder.Number = order.MdtrtId
  512. newOrder.Date = order.SettleAccountsDate
  513. newOrder.ChargeAdmin = charge_admin
  514. newOrder.PrintorAdmin = printor_admin
  515. newOrder.Order = order
  516. newOrder.BedCostTotal = bedCostTotal
  517. newOrder.BedCostSelfTotal = bedCostSelfTotal
  518. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  519. newOrder.BedSelfTotal = bedSelfTotal
  520. newOrder.BedInscpTotal = bedInscpTotal
  521. newOrder.OperationCostTotal = operationCostTotal
  522. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  523. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  524. newOrder.OperationSelfTotal = operationSelfTotal
  525. newOrder.OperationInscpTotal = operationInscpTotal
  526. newOrder.OtherCostTotal = otherCostTotal
  527. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  528. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  529. newOrder.OtherSelfTotal = otherSelfTotal
  530. newOrder.OtherInscpTotal = otherInscpTotal
  531. newOrder.MaterialCostTotal = materialCostTotal
  532. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  533. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  534. newOrder.MaterialSelfTotal = materialSelfTotal
  535. newOrder.MaterialInscpTotal = materialInscpTotal
  536. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  537. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  538. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  539. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  540. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  541. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  542. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  543. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  544. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  545. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  546. newOrder.CheckCostTotal = checkCostTotal
  547. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  548. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  549. newOrder.CheckSelfTotal = checkSelfTotal
  550. newOrder.CheckInscpTotal = checkInscpTotal
  551. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  552. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  553. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  554. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  555. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  556. newOrder.TreatCostTotal = treatCostTotal
  557. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  558. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  559. newOrder.TreatSelfTotal = treatSelfTotal
  560. newOrder.TreatInscpTotal = treatInscpTotal
  561. newOrder.DoctorInfo = doctor_info
  562. newOrder.DoctorName = doctor_name
  563. newOrder.HealthCardNo = order.PsnNo
  564. newOrder.YiliaoLeibie = yiliao_leibie
  565. newOrder.Patient = patient
  566. newOrder.OrgName = miConfig.OrgName
  567. newOrder.OrgCode = miConfig.Code
  568. newOrder.OrderNumber = order.Number
  569. newOrder.HisPatient = his
  570. newOrder.DiaConfig = dia_config
  571. newOrders = append(newOrders, newOrder)
  572. }
  573. c.ServeSuccessJSON(map[string]interface{}{
  574. "orders": newOrders,
  575. })
  576. }
  577. func (c *HisApiController) GetTestOrder() {
  578. order_id, _ := c.GetInt64("order_id")
  579. admin_user_id, _ := c.GetInt64("admin_user_id")
  580. adminUser := c.GetAdminUserInfo()
  581. order, _ := service.GetHisOrderByID(order_id)
  582. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  583. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  584. orderInfos = append(orderInfos, orderInfos_two...)
  585. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  586. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  587. var dia_config []*models.HisXtDiagnoseConfig
  588. var name string
  589. var bedCostTotal float64 = 0 //床位总费
  590. var bedCostSelfTotal float64 = 0 //床位自费
  591. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  592. var bedSelfTotal float64 = 0 //床位部分项目自费
  593. var bedInscpTotal float64 = 0 //床位部分项目自费
  594. var operationCostTotal float64 = 0 //手术费
  595. var operationCostSelfTotal float64 = 0 //手术费
  596. var operationCostPartSelfTotal float64 = 0 //手术费
  597. var operationSelfTotal float64 = 0 //床位部分项目自费
  598. var operationInscpTotal float64 = 0 //床位部分项目自费
  599. var otherCostTotal float64 = 0 //其他费用
  600. var otherCostSelfTotal float64 = 0 //其他费用
  601. var otherCostPartSelfTotal float64 = 0 //其他费用
  602. var otherSelfTotal float64 = 0 //床位部分项目自费
  603. var otherInscpTotal float64 = 0 //床位部分项目自费
  604. var materialCostTotal float64 = 0 //材料费
  605. var materialCostSelfTotal float64 = 0 //材料费
  606. var materialCostPartSelfTotal float64 = 0 //材料费
  607. var materialSelfTotal float64 = 0 //床位部分项目自费
  608. var materialInscpTotal float64 = 0 //床位部分项目自费
  609. var westernMedicineCostTotal float64 = 0 //西药费
  610. var westernMedicineCostSelfTotal float64 = 0 //西药费
  611. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  612. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  613. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  614. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  615. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  616. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  617. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  618. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  619. var checkCostTotal float64 = 0 //检查费
  620. var checkCostSelfTotal float64 = 0 //检查费
  621. var checkCostPartSelfTotal float64 = 0 //检查费
  622. var checkSelfTotal float64 = 0 //床位部分项目自费
  623. var checkInscpTotal float64 = 0 //床位部分项目自费
  624. var laboratoryCostTotal float64 = 0 //化验费
  625. var laboratoryCostSelfTotal float64 = 0 //化验费
  626. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  627. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  628. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  629. var treatCostTotal float64 = 0 //治疗费用
  630. var treatCostSelfTotal float64 = 0 //治疗费用
  631. var treatCostPartSelfTotal float64 = 0 //治疗费用
  632. var treatSelfTotal float64 = 0 //床位部分项目自费
  633. var treatInscpTotal float64 = 0 //床位部分项目自费
  634. decimal.DivisionPrecision = 2
  635. for _, item := range orderInfos {
  636. if item.MedChrgitmType == "01" { //床位费
  637. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  644. if item.MedChrgitmType == "03" { //检查费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. } else {
  652. if item.MedChrgitmType == "03" { //检查费
  653. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. }
  660. if item.MedChrgitmType == "04" { //化验费
  661. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  662. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  663. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  664. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  665. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  666. }
  667. if item.MedChrgitmType == "05" { //治疗费
  668. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  669. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  670. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  671. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  672. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  673. }
  674. if item.MedChrgitmType == "06" { //手术费
  675. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  676. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  677. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  678. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  679. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  680. }
  681. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  682. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  683. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  684. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  685. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  686. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  687. }
  688. if item.MedChrgitmType == "09" { //西药费
  689. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  690. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  691. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  692. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  693. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  694. }
  695. if item.MedChrgitmType == "11" { //中成费
  696. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  697. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  698. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  699. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  700. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  701. }
  702. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  703. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  704. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  705. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  706. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  707. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  708. }
  709. }
  710. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  711. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  712. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  713. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  714. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  715. var doctor_name string
  716. if roles.ID == 0 {
  717. doctor_name = "管理员"
  718. } else {
  719. doctor_name = roles.UserName
  720. }
  721. yiliao_leibie := ""
  722. switch order.MedType {
  723. case "11":
  724. yiliao_leibie = "普通门诊"
  725. break
  726. case "12":
  727. yiliao_leibie = "门诊挂号"
  728. break
  729. case "13":
  730. yiliao_leibie = "急诊"
  731. break
  732. case "14":
  733. yiliao_leibie = "门诊特殊病"
  734. break
  735. case "15":
  736. yiliao_leibie = "门诊统筹"
  737. break
  738. case "16":
  739. yiliao_leibie = "门诊慢性病"
  740. break
  741. case "21":
  742. yiliao_leibie = "普通住院"
  743. break
  744. }
  745. c.ServeSuccessJSON(map[string]interface{}{
  746. "diagnosis": name,
  747. "order_infos": orderInfos,
  748. "number": order.MdtrtId,
  749. "date": order.SettleAccountsDate,
  750. "charge_admin": charge_admin,
  751. "printor_admin": printor_admin,
  752. "info": order,
  753. "order": order,
  754. "bedCostTotal": bedCostTotal,
  755. "bedCostSelfTotal": bedCostSelfTotal,
  756. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  757. "bedSelfTotal": bedSelfTotal,
  758. "bedInscpTotal": bedInscpTotal,
  759. "operationCostTotal": operationCostTotal,
  760. "operationCostSelfTotal": operationCostSelfTotal,
  761. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  762. "operationSelfTotal": operationSelfTotal,
  763. "operationInscpTotal": operationInscpTotal,
  764. "otherCostTotal": otherCostTotal,
  765. "otherCostSelfTotal": otherCostSelfTotal,
  766. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  767. "otherSelfTotal": otherSelfTotal,
  768. "otherInscpTotal": otherInscpTotal,
  769. "materialCostTotal": materialCostTotal,
  770. "materialCostSelfTotal": materialCostSelfTotal,
  771. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  772. "materialSelfTotal": materialSelfTotal,
  773. "materialInscpTotal": materialInscpTotal,
  774. "westernMedicineCostTotal": westernMedicineCostTotal,
  775. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  776. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  777. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  778. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  779. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  780. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  781. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  782. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  783. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  784. "checkCostTotal": checkCostTotal,
  785. "checkCostSelfTotal": checkCostSelfTotal,
  786. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  787. "checkSelfTotal": checkSelfTotal,
  788. "checkInscpTotal": checkInscpTotal,
  789. "laboratoryCostTotal": laboratoryCostTotal,
  790. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  791. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  792. "laboratorySelfTotal": laboratorySelfTotal,
  793. "laboratoryInscpTotal": laboratoryInscpTotal,
  794. "treatCostTotal": treatCostTotal,
  795. "treatCostSelfTotal": treatCostSelfTotal,
  796. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  797. "treatSelfTotal": treatSelfTotal,
  798. "treatInscpTotal": treatInscpTotal,
  799. "doctor_info": doctor_info,
  800. "doctor_name": doctor_name,
  801. "health_card_no": order.PsnNo,
  802. "yiliao_leibie": yiliao_leibie,
  803. "patient": patient,
  804. "org_name": miConfig.OrgName,
  805. "org_code": miConfig.Code,
  806. "order_number": order.Number,
  807. "his_hospital": his_hospital,
  808. "dia_config": dia_config,
  809. })
  810. }
  811. type CustomFundPay struct {
  812. FundPayType string `json:"fund_pay_type"`
  813. FundPayamt float64 `json:"fund_payamt"`
  814. InscpScpAmt float64 `json:"inscp_scp_amt"`
  815. }
  816. func (c *PublicApiController) GetBaiLinExportData() {
  817. data := service.GetBaiLinOrderData()
  818. fmt.Println(len(data))
  819. var new_data []*models.NewCustomHisOrder
  820. for _, item := range data {
  821. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  822. new_data = append(new_data, item)
  823. }
  824. }
  825. fmt.Println(len(new_data))
  826. c.ServeSuccessJSON(map[string]interface{}{
  827. "list": new_data,
  828. })
  829. }
  830. func (c *HisApiController) GetHisUnChargePatientList() {
  831. record_date := c.GetString("record_date")
  832. sch_type, _ := c.GetInt64("sch_type")
  833. timeLayout := "2006-01-02"
  834. loc, _ := time.LoadLocation("Local")
  835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  836. if err != nil {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. recordDateTime := theTime.Unix()
  841. adminInfo := c.GetAdminUserInfo()
  842. var tempPatients []*service.NewTempPatients
  843. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  844. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  845. var patients []*service.NewTempPatients
  846. var patients_two []*service.NewTempPatients
  847. for _, item := range tempPatients {
  848. //过滤掉没挂号的和没开处方的
  849. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  850. patients = append(patients, item)
  851. }
  852. //过滤掉没挂号的
  853. if len(item.HisPatient) > 0 {
  854. patients_two = append(patients_two, item)
  855. }
  856. }
  857. c.ServeSuccessJSON(map[string]interface{}{
  858. "list": patients,
  859. "list_two": patients_two,
  860. })
  861. }
  862. func (c *HisApiController) GetPrivateExpensesOrder() {
  863. //id, _ := c.GetInt64("id")
  864. //record_time := c.GetString("record_time")
  865. order_id, _ := c.GetInt64("order_id")
  866. admin_user_id, _ := c.GetInt64("admin_user_id")
  867. //timeLayout := "2006-01-02"
  868. //loc, _ := time.LoadLocation("Local")
  869. //
  870. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  871. //if err != nil {
  872. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  873. // return
  874. //}
  875. //recordDateTime := theTime.Unix()
  876. adminUser := c.GetAdminUserInfo()
  877. order, _ := service.GetHisOrderByID(order_id)
  878. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  879. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  880. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  881. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  882. //var config []*models.HisXtDiagnoseConfig
  883. var name string
  884. if order.PType == 1 {
  885. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  886. for _, item := range diagnosis_ids {
  887. id, _ := strconv.ParseInt(item, 10, 64)
  888. diagnosisConfig, _ := service.FindDiagnoseById(id)
  889. if len(name) == 0 {
  890. name = diagnosisConfig.ClassName
  891. } else {
  892. name = name + "," + diagnosisConfig.ClassName
  893. }
  894. }
  895. } else {
  896. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  897. for _, item := range diagnosis_ids {
  898. id, _ := strconv.ParseInt(item, 10, 64)
  899. diagnosisConfig, _ := service.FindDiagnoseById(id)
  900. if len(name) == 0 {
  901. name = diagnosisConfig.ClassName
  902. } else {
  903. name = name + "," + diagnosisConfig.ClassName
  904. }
  905. }
  906. }
  907. var bedCostTotal float64 = 0 //床位总费
  908. var bedCostSelfTotal float64 = 0 //床位自费
  909. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  910. var bedSelfTotal float64 = 0 //床位部分项目自费
  911. var bedInscpTotal float64 = 0 //床位部分项目自费
  912. var operationCostTotal float64 = 0 //手术费
  913. var operationCostSelfTotal float64 = 0 //手术费
  914. var operationCostPartSelfTotal float64 = 0 //手术费
  915. var operationSelfTotal float64 = 0 //床位部分项目自费
  916. var operationInscpTotal float64 = 0 //床位部分项目自费
  917. var otherCostTotal float64 = 0 //其他费用
  918. //var otherCostSelfTotal float64 = 0 //其他费用
  919. var otherCostPartSelfTotal float64 = 0 //其他费用
  920. //var otherSelfTotal float64 = 0 //床位部分项目自费
  921. //var otherInscpTotal float64 = 0 //床位部分项目自费
  922. var materialCostTotal float64 = 0 //材料费
  923. var materialCostSelfTotal float64 = 0 //材料费
  924. var materialCostPartSelfTotal float64 = 0 //材料费
  925. var materialSelfTotal float64 = 0 //床位部分项目自费
  926. var materialInscpTotal float64 = 0 //床位部分项目自费
  927. var westernMedicineCostTotal float64 = 0 //西药费
  928. var westernMedicineCostSelfTotal float64 = 0 //西药费
  929. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  930. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  931. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  932. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  933. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  934. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  935. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  936. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  937. var checkCostTotal float64 = 0 //检查费
  938. var checkCostSelfTotal float64 = 0 //检查费
  939. var checkCostPartSelfTotal float64 = 0 //检查费
  940. var checkSelfTotal float64 = 0 //床位部分项目自费
  941. var checkInscpTotal float64 = 0 //床位部分项目自费
  942. var laboratoryCostTotal float64 = 0 //化验费
  943. var laboratoryCostSelfTotal float64 = 0 //化验费
  944. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  945. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  946. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  947. var treatCostTotal float64 = 0 //治疗费用
  948. var treatCostSelfTotal float64 = 0 //治疗费用
  949. var treatCostPartSelfTotal float64 = 0 //治疗费用
  950. var treatSelfTotal float64 = 0 //床位部分项目自费
  951. var treatInscpTotal float64 = 0 //床位部分项目自费
  952. var zhenChaCostTotal float64 = 0 //其他费用
  953. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  954. decimal.DivisionPrecision = 2
  955. for _, item := range orderInfos {
  956. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  957. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  958. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  959. item.MedChrgitmType = "09"
  960. }
  961. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  962. if item.HisPrescriptionProject.Type == 2 {
  963. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  964. fmt.Println("CostClassify")
  965. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  966. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  967. case 0:
  968. item.MedChrgitmType = "0"
  969. break
  970. case 1:
  971. item.MedChrgitmType = "14"
  972. break
  973. case 2:
  974. item.MedChrgitmType = "05"
  975. break
  976. case 3:
  977. item.MedChrgitmType = "03"
  978. break
  979. case 4:
  980. item.MedChrgitmType = "03"
  981. break
  982. case 5:
  983. item.MedChrgitmType = "08"
  984. break
  985. case 6:
  986. item.MedChrgitmType = "14"
  987. break
  988. case 7:
  989. item.MedChrgitmType = "14"
  990. break
  991. case 8:
  992. item.MedChrgitmType = "03"
  993. break
  994. case 9:
  995. item.MedChrgitmType = "14"
  996. break
  997. case 10:
  998. item.MedChrgitmType = "14"
  999. break
  1000. case 11:
  1001. item.MedChrgitmType = "06"
  1002. break
  1003. case 12:
  1004. item.MedChrgitmType = "12"
  1005. break
  1006. case 13:
  1007. item.MedChrgitmType = "01"
  1008. break
  1009. case 14:
  1010. item.MedChrgitmType = "04"
  1011. break
  1012. case 15:
  1013. item.MedChrgitmType = "14"
  1014. break
  1015. case 101:
  1016. item.MedChrgitmType = "04"
  1017. break
  1018. }
  1019. } else {
  1020. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1021. case 1:
  1022. item.MedChrgitmType = "14"
  1023. break
  1024. case 2:
  1025. item.MedChrgitmType = "05"
  1026. break
  1027. case 3:
  1028. item.MedChrgitmType = "04"
  1029. break
  1030. case 4:
  1031. item.MedChrgitmType = "14"
  1032. break
  1033. case 5:
  1034. item.MedChrgitmType = "08"
  1035. break
  1036. case 6:
  1037. item.MedChrgitmType = "14"
  1038. break
  1039. case 7:
  1040. item.MedChrgitmType = "14"
  1041. break
  1042. case 8:
  1043. item.MedChrgitmType = "03"
  1044. break
  1045. case 9:
  1046. item.MedChrgitmType = "14"
  1047. break
  1048. case 101:
  1049. item.MedChrgitmType = "04"
  1050. break
  1051. default:
  1052. item.MedChrgitmType = "14"
  1053. break
  1054. }
  1055. }
  1056. } else if item.HisPrescriptionProject.Type == 3 {
  1057. item.MedChrgitmType = "08"
  1058. }
  1059. }
  1060. }
  1061. }
  1062. if order.IsMedicineInsurance != 1 {
  1063. order.PsnCashPay = order.MedfeeSumamt
  1064. }
  1065. for _, item := range orderInfos {
  1066. if item.MedChrgitmType == "01" { //床位费
  1067. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1068. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1069. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1070. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1071. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1072. }
  1073. if item.MedChrgitmType == "02" { //诊察费
  1074. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1075. //zhenChaCostSelfTotal = zhenChaCostTotal
  1076. }
  1077. if item.MedChrgitmType == "03" { //检查费
  1078. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1079. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1080. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1081. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1082. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1083. }
  1084. if item.MedChrgitmType == "02" { //检查费
  1085. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1086. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1087. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1088. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1089. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1090. }
  1091. if item.MedChrgitmType == "04" { //化验费
  1092. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1093. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1094. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1095. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1096. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1097. }
  1098. if item.MedChrgitmType == "05" { //治疗费
  1099. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1100. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1101. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1102. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1103. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1104. }
  1105. if item.MedChrgitmType == "06" { //手术费
  1106. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1107. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1108. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1109. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1110. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1111. }
  1112. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1113. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1114. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1115. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1116. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1117. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1118. }
  1119. if item.MedChrgitmType == "09" { //西药费
  1120. fmt.Println("FulamtOwnpayAmt")
  1121. fmt.Println(item.FulamtOwnpayAmt)
  1122. fmt.Println("FulamtOwnpayAmt")
  1123. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1124. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1125. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1126. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1127. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1128. }
  1129. if item.MedChrgitmType == "11" { //中成费
  1130. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1131. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1132. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1133. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1134. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1135. }
  1136. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1137. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1138. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1139. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1140. }
  1141. }
  1142. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1143. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1144. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1145. var dia_config []*models.HisXtDiagnoseConfig
  1146. var diagnosis_ids []string
  1147. if his.ID > 0 {
  1148. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1149. } else {
  1150. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1151. }
  1152. for _, item := range diagnosis_ids {
  1153. id, _ := strconv.ParseInt(item, 10, 64)
  1154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1155. dia_config = append(dia_config, diagnosisConfig)
  1156. }
  1157. var rf []CustomFundPay
  1158. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1159. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1160. c.ServeSuccessJSON(map[string]interface{}{
  1161. "patient": patient,
  1162. "order_infos": orderInfos,
  1163. "diagnosis": name,
  1164. "bedCostTotal": bedCostTotal,
  1165. "bedCostSelfTotal": bedCostSelfTotal,
  1166. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1167. "bedSelfTotal": bedSelfTotal,
  1168. "bedInscpTotal": bedInscpTotal,
  1169. "operationCostTotal": operationCostTotal,
  1170. "operationCostSelfTotal": operationCostSelfTotal,
  1171. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1172. "operationInscpTotal": operationInscpTotal,
  1173. "operationSelfTotal": operationSelfTotal,
  1174. "otherCostTotal": otherCostTotal,
  1175. //"otherCostSelfTotal": otherCostSelfTotal,
  1176. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1177. "materialCostTotal": materialCostTotal,
  1178. "materialCostSelfTotal": materialCostSelfTotal,
  1179. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1180. "materialSelfTotal": materialSelfTotal,
  1181. "materialInscpTotal": materialInscpTotal,
  1182. "westernMedicineCostTotal": westernMedicineCostTotal,
  1183. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1184. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1185. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1186. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1187. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1188. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1189. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1190. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1191. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1192. "checkCostTotal": checkCostTotal,
  1193. "checkCostSelfTotal": checkCostSelfTotal,
  1194. "checkSelfTotal": checkSelfTotal,
  1195. "checkInscpTotal": checkInscpTotal,
  1196. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1197. "zhenChaCostTotal": zhenChaCostTotal,
  1198. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1199. "laboratoryCostTotal": laboratoryCostTotal,
  1200. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1201. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1202. "laboratorySelfTotal": laboratorySelfTotal,
  1203. "laboratoryInscpTotal": laboratoryInscpTotal,
  1204. "treatCostTotal": treatCostTotal,
  1205. "treatCostSelfTotal": treatCostSelfTotal,
  1206. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1207. "treatSelfTotal": treatSelfTotal,
  1208. "treatInscpTotal": treatInscpTotal,
  1209. "charge_admin": charge_admin,
  1210. "printor_admin": printor_admin,
  1211. "org_name": org.OrgName,
  1212. "org_code": miConfig.Code,
  1213. "name": patient.Name,
  1214. "number": order.MdtrtId,
  1215. "date": order.SettleAccountsDate,
  1216. "info": order,
  1217. "new_order": order,
  1218. "his_hospital": his_hospital,
  1219. "his": his,
  1220. "funds": rf,
  1221. "dia_config": dia_config,
  1222. })
  1223. }
  1224. func (c *HisApiController) RefudDetail() {
  1225. order_id, _ := c.GetInt64("order_id")
  1226. order, _ := service.GetHisOrderByID(order_id)
  1227. adminUser := c.GetAdminUserInfo()
  1228. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1229. c.ServeSuccessJSON(map[string]interface{}{
  1230. "msg": "撤销成功",
  1231. })
  1232. }
  1233. func (c *HisApiController) Sscard() {
  1234. //r := CardInit()
  1235. //if r == 0 {
  1236. // GetBaseInfo()
  1237. //}
  1238. //c.ServeSuccessJSON(map[string]interface{}{
  1239. // "list": "11",
  1240. //})
  1241. }
  1242. func GetBaseInfo() error {
  1243. //handle := syscall.MustLoadDLL("SSCard.dll")
  1244. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1245. //
  1246. //str := make([]byte, 256)
  1247. //str1 := make([]byte, 256)
  1248. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1249. //if ferr != nil {
  1250. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1251. // return ferr
  1252. //}
  1253. //
  1254. //fmt.Println(string(str))
  1255. //
  1256. //fmt.Println(r)
  1257. return nil
  1258. }
  1259. func CardInit() int {
  1260. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1261. //add := DllTestDef.MustFindProc("Init")
  1262. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1263. //if err != nil {
  1264. // fmt.Println("SSCard的运算结果为:", ret)
  1265. //}
  1266. //result := int(ret)
  1267. return 0
  1268. }
  1269. func IntPtr(n int) uintptr {
  1270. return uintptr(n)
  1271. }
  1272. func StrPtr(s string) uintptr {
  1273. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1274. }
  1275. func (c *HisApiController) GetHisPatientList() {
  1276. record_date := c.GetString("record_date")
  1277. sch_type, _ := c.GetInt64("sch_type")
  1278. patient_type, _ := c.GetInt64("patient_type")
  1279. fmt.Println("patient_type")
  1280. fmt.Println(patient_type)
  1281. timeLayout := "2006-01-02"
  1282. loc, _ := time.LoadLocation("Local")
  1283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1284. if err != nil {
  1285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1286. return
  1287. }
  1288. recordDateTime := theTime.Unix()
  1289. adminInfo := c.GetAdminUserInfo()
  1290. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1291. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1292. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1293. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1294. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1295. fmt.Println(patients_three)
  1296. //获取当前用户的信息
  1297. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1298. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1299. //获取所有科室信息
  1300. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1301. //var aa []service.PatientThree
  1302. noElementsSlice := make([]service.PatientThree, 0)
  1303. c.ServeSuccessJSON(map[string]interface{}{
  1304. "list": patients_three,
  1305. "list_two": patients_four,
  1306. "list_three": noElementsSlice,
  1307. "info": adminUserInfo,
  1308. "doctors": doctors,
  1309. "department": department,
  1310. })
  1311. } else {
  1312. //获取当前用户的信息
  1313. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1314. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1315. //获取所有科室信息
  1316. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1317. //var aa []service.PatientThree
  1318. noElementsSlice := make([]service.PatientThree, 0)
  1319. c.ServeSuccessJSON(map[string]interface{}{
  1320. "list": patients,
  1321. "list_two": patients_two,
  1322. "list_three": noElementsSlice,
  1323. "info": adminUserInfo,
  1324. "doctors": doctors,
  1325. "department": department,
  1326. })
  1327. }
  1328. }
  1329. type CustomTemplate struct {
  1330. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1331. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1332. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1333. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1334. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1335. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1336. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1337. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1338. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1339. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1340. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1341. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1342. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1343. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1344. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1345. }
  1346. func (c *HisApiController) GetHisPatientInfo() {
  1347. patient_id, _ := c.GetInt64("patient_id")
  1348. his_patient_id, _ := c.GetInt64("his_patient_id")
  1349. record_date := c.GetString("record_date")
  1350. number := c.GetString("number")
  1351. //start_time := c.GetString("start_time")
  1352. //end_time := c.GetString("end_time")
  1353. p_type, _ := c.GetInt64("p_type")
  1354. timeLayout := "2006-01-02"
  1355. loc, _ := time.LoadLocation("Local")
  1356. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1357. if err != nil {
  1358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1359. return
  1360. }
  1361. recordDateTime := theTime.Unix()
  1362. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1363. //if err != nil {
  1364. //
  1365. //}
  1366. //startRecordDateTime := startTime.Unix()
  1367. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1368. //if err != nil {
  1369. //
  1370. //}
  1371. //endRecordDateTime := endTime.Unix()
  1372. admin := c.GetAdminUserInfo()
  1373. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1374. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1375. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1376. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1377. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1378. var prescriptions []*models.HisPrescription
  1379. var last_prescriptions []*models.HisPrescription
  1380. var sch_prescriptions []CustomTemplate
  1381. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1382. if p_type == 1 { //住院
  1383. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1384. for _, item := range prescriptions {
  1385. for _, subItem := range item.HisDoctorAdviceInfo {
  1386. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1387. if info.RetailPrice > 0 {
  1388. subItem.Drug.MinPrice = info.RetailPrice
  1389. }
  1390. }
  1391. }
  1392. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1393. } else { //门诊
  1394. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1395. for _, item := range prescriptions {
  1396. for _, subItem := range item.HisDoctorAdviceInfo {
  1397. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1398. if info.RetailPrice > 0 {
  1399. subItem.Drug.MinPrice = info.RetailPrice
  1400. }
  1401. }
  1402. }
  1403. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1404. }
  1405. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1406. if sch.ID > 0 {
  1407. var week string
  1408. t := time.Now()
  1409. switch t.Weekday().String() {
  1410. case "Monday":
  1411. week = "周一"
  1412. break
  1413. case "Tuesday":
  1414. week = "周二"
  1415. break
  1416. case "Wednesday":
  1417. week = "周三"
  1418. break
  1419. case "Thursday":
  1420. week = "周四"
  1421. break
  1422. case "Friday":
  1423. week = "周五"
  1424. break
  1425. case "Saturday":
  1426. week = "周六"
  1427. break
  1428. case "Sunday":
  1429. week = "周日"
  1430. break
  1431. }
  1432. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1433. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1434. //根据推送频率组装新的数组
  1435. for _, item := range temp_sch_prescriptions {
  1436. var cus CustomTemplate
  1437. cus.ID = item.ID
  1438. cus.UserOrgId = item.UserOrgId
  1439. cus.PatientId = item.PatientId
  1440. cus.MedType = item.MedType
  1441. cus.RecordDate = item.RecordDate
  1442. cus.Type = item.Type
  1443. cus.PType = item.PType
  1444. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1445. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1446. if subItem.FrequencyType == 1 { //每次必推
  1447. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1448. }
  1449. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1450. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1451. }
  1452. if subItem.FrequencyType == 2 { //按照天数频率
  1453. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1454. now := p.Unix()
  1455. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1456. dayStr2 := "-" + dayStr
  1457. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1458. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1459. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1460. if len(advices) == 0 {
  1461. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1462. }
  1463. }
  1464. }
  1465. }
  1466. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1467. if subItem.Type == 2 {
  1468. if subItem.XtHisProject.MedicalStatus != 1 {
  1469. if subItem.FrequencyType == 1 {
  1470. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1471. }
  1472. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1473. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1474. }
  1475. if subItem.FrequencyType == 2 {
  1476. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1477. now := p.Unix()
  1478. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1479. dayStr2 := "-" + dayStr
  1480. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1481. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1482. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1483. if len(projects) == 0 {
  1484. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1485. }
  1486. }
  1487. }
  1488. } else if subItem.Type == 3 {
  1489. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1490. if subItem.FrequencyType == 1 {
  1491. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1492. }
  1493. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1494. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1495. }
  1496. if subItem.FrequencyType == 2 {
  1497. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1498. now := p.Unix()
  1499. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1500. dayStr2 := "-" + dayStr
  1501. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1502. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1503. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1504. if len(projects) == 0 {
  1505. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1506. }
  1507. }
  1508. }
  1509. }
  1510. }
  1511. sch_prescriptions = append(sch_prescriptions, cus)
  1512. }
  1513. for _, item := range sch_prescriptions {
  1514. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1515. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1516. }
  1517. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1518. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1519. }
  1520. }
  1521. }
  1522. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1523. if config.ID > 0 && config.IsOpen == 1 {
  1524. for _, item := range sch_prescriptions {
  1525. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1526. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1527. if info.RetailPrice > 0 {
  1528. subItem.Drug.MinPrice = info.RetailPrice
  1529. if admin.CurrentOrgId != 10598 {
  1530. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1531. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1532. }
  1533. }
  1534. }
  1535. }
  1536. }
  1537. if config.ID > 0 && config.IsOpen == 1 {
  1538. for _, item := range sch_prescriptions {
  1539. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1540. if subItem.Type == 3 {
  1541. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1542. if info.Price > 0 {
  1543. subItem.GoodInfo.PackingPrice = info.Price
  1544. if admin.CurrentOrgId != 10598 {
  1545. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1546. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1547. }
  1548. }
  1549. }
  1550. }
  1551. }
  1552. }
  1553. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1554. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1555. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1556. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1557. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1558. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1559. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1560. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1561. //获取所有科室信息
  1562. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1563. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1564. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1565. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1566. fmt.Println(prescriptions)
  1567. fmt.Println(sch_prescriptions)
  1568. fmt.Println(last_prescriptions)
  1569. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1570. if len(sch_prescriptions) > 0 {
  1571. var index = 0
  1572. for subindex, item := range sch_prescriptions {
  1573. if item.Type == 2 {
  1574. index = subindex
  1575. }
  1576. }
  1577. fmt.Println(index)
  1578. fmt.Println(len(sch_prescriptions))
  1579. if index >= 0 && index < len(sch_prescriptions) {
  1580. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1581. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1582. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1583. if one.ID > 0 {
  1584. var hpt models.HisPrescriptionProjectTemplate
  1585. hpt.Type = 3
  1586. hpt.ID = 0
  1587. hpt.PatientId = sch_prescriptions[index].PatientId
  1588. hpt.Status = 1
  1589. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1590. hpt.Mtime = time.Now().Unix()
  1591. hpt.Ctime = time.Now().Unix()
  1592. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1593. hpt.Count = "1"
  1594. hpt.Price = one.RetailPrice
  1595. hpt.ProjectId = one.ID
  1596. hpt.FeedetlSn = ""
  1597. hpt.PrescriptionId = sch_prescriptions[index].ID
  1598. hpt.Unit = one.PackingUnit
  1599. hpt.Day = "1"
  1600. hpt.SingleDose = "1"
  1601. hpt.GoodInfo = one
  1602. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1603. }
  1604. if two.ID > 0 {
  1605. var hpt models.HisPrescriptionProjectTemplate
  1606. hpt.Type = 3
  1607. hpt.ID = 0
  1608. hpt.PatientId = sch_prescriptions[index].PatientId
  1609. hpt.Status = 1
  1610. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1611. hpt.Mtime = time.Now().Unix()
  1612. hpt.Ctime = time.Now().Unix()
  1613. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1614. hpt.Count = "1"
  1615. hpt.Price = two.RetailPrice
  1616. hpt.ProjectId = two.ID
  1617. hpt.FeedetlSn = ""
  1618. hpt.PrescriptionId = sch_prescriptions[index].ID
  1619. hpt.Unit = two.PackingUnit
  1620. hpt.Day = "1"
  1621. hpt.SingleDose = "1"
  1622. hpt.GoodInfo = two
  1623. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1624. }
  1625. //if three.ID > 0 {
  1626. // var hpt models.HisPrescriptionProjectTemplate
  1627. // hpt.Type = 3
  1628. // hpt.ID = 0
  1629. // hpt.PatientId = sch_prescriptions[index].PatientId
  1630. // hpt.Status = 1
  1631. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1632. // hpt.Mtime = time.Now().Unix()
  1633. // hpt.Ctime = time.Now().Unix()
  1634. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1635. // hpt.Count = "1"
  1636. // hpt.Price = three.RetailPrice
  1637. // hpt.ProjectId = three.ID
  1638. // hpt.FeedetlSn = ""
  1639. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1640. // hpt.Unit = three.PackingUnit
  1641. // hpt.Day = "1"
  1642. // hpt.SingleDose = "1"
  1643. // hpt.GoodInfo = three
  1644. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1645. //}
  1646. fmt.Println(sch_prescriptions)
  1647. }
  1648. } else {
  1649. if len(last_prescriptions) > 0 {
  1650. var index = 0
  1651. for subindex, item := range last_prescriptions {
  1652. if item.Type == 2 {
  1653. index = subindex
  1654. }
  1655. }
  1656. if index >= 0 && index < len(last_prescriptions) {
  1657. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1658. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1659. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1660. if one.ID > 0 {
  1661. var hpt models.HisPrescriptionProject
  1662. hpt.Type = 3
  1663. hpt.ID = 0
  1664. hpt.PatientId = last_prescriptions[index].PatientId
  1665. hpt.Status = 1
  1666. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1667. hpt.Mtime = time.Now().Unix()
  1668. hpt.Ctime = time.Now().Unix()
  1669. hpt.RecordDate = last_prescriptions[index].RecordDate
  1670. hpt.Count = "1"
  1671. hpt.Price = one.RetailPrice
  1672. hpt.ProjectId = one.ID
  1673. hpt.FeedetlSn = ""
  1674. hpt.PrescriptionId = last_prescriptions[index].ID
  1675. hpt.Unit = one.PackingUnit
  1676. hpt.Day = "1"
  1677. hpt.SingleDose = "1"
  1678. hpt.GoodInfo = one
  1679. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1680. }
  1681. if two.ID > 0 {
  1682. var hpt models.HisPrescriptionProject
  1683. hpt.Type = 3
  1684. hpt.ID = 0
  1685. hpt.PatientId = last_prescriptions[index].PatientId
  1686. hpt.Status = 1
  1687. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1688. hpt.Mtime = time.Now().Unix()
  1689. hpt.Ctime = time.Now().Unix()
  1690. hpt.RecordDate = last_prescriptions[index].RecordDate
  1691. hpt.Count = "1"
  1692. hpt.Price = two.RetailPrice
  1693. hpt.ProjectId = two.ID
  1694. hpt.FeedetlSn = ""
  1695. hpt.PrescriptionId = last_prescriptions[index].ID
  1696. hpt.Unit = two.PackingUnit
  1697. hpt.Day = "1"
  1698. hpt.SingleDose = "1"
  1699. hpt.GoodInfo = two
  1700. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1701. }
  1702. //if three.ID > 0 {
  1703. // var hpt models.HisPrescriptionProject
  1704. // hpt.Type = 3
  1705. // hpt.ID = 0
  1706. // hpt.PatientId = last_prescriptions[index].PatientId
  1707. // hpt.Status = 1
  1708. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1709. // hpt.Mtime = time.Now().Unix()
  1710. // hpt.Ctime = time.Now().Unix()
  1711. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1712. // hpt.Count = "1"
  1713. // hpt.Price = three.RetailPrice
  1714. // hpt.ProjectId = three.ID
  1715. // hpt.FeedetlSn = ""
  1716. // hpt.PrescriptionId = last_prescriptions[index].ID
  1717. // hpt.Unit = three.PackingUnit
  1718. // hpt.Day = "1"
  1719. // hpt.SingleDose = "1"
  1720. // hpt.GoodInfo = three
  1721. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1722. //}
  1723. }
  1724. }
  1725. }
  1726. }
  1727. c.ServeSuccessJSON(map[string]interface{}{
  1728. "his_info": his_patient_info,
  1729. "xt_info": xt_patient_info,
  1730. "prescription": prescriptions,
  1731. "case_history": case_history,
  1732. "info": patientPrescriptionInfo,
  1733. //"month_prescriptions": monthPrescriptions,
  1734. "order": order,
  1735. "doctors": doctors,
  1736. "department": department,
  1737. "sch_prescriptions": sch_prescriptions,
  1738. "last_prescriptions": last_prescriptions,
  1739. "schedule": sch,
  1740. "count": count,
  1741. "drugStockConfig": drugStockConfig,
  1742. "last_info": lastPatientPrescriptionInfo,
  1743. "befor": beforThrity,
  1744. "LastCaseHistory": LastCaseHistory,
  1745. "prescriptionInfo": prescriptionInfo,
  1746. })
  1747. return
  1748. }
  1749. func (c *HisApiController) GetHisPrescriptionConfig() {
  1750. adminInfo := c.GetAdminUserInfo()
  1751. //获取医嘱模版
  1752. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1753. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1754. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1755. //获取所有基础药
  1756. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1757. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1758. if config.ID > 0 && config.IsOpen == 1 {
  1759. for _, item := range drugs {
  1760. var index = 0
  1761. for _, subItem := range item.OtherDrugWarehouseInfo {
  1762. if index == 0 {
  1763. index = index + 1
  1764. if subItem.RetailPrice > 0 {
  1765. item.MinPrice = subItem.RetailPrice
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1772. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1773. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1774. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1775. //获取所有科室信息
  1776. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1777. //获取诊断信息
  1778. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1779. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1780. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1781. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1782. //获取是否开启保存耗材出库的开关
  1783. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1784. c.ServeSuccessJSON(map[string]interface{}{
  1785. "drugs": drugs,
  1786. "advices_template": advices,
  1787. "drugways": drugways,
  1788. "efs": efs,
  1789. "doctors": doctors,
  1790. "department": department,
  1791. "sick": sick,
  1792. "additions": additions,
  1793. "diagnose": diagnose,
  1794. "manufacturers": manufacturers,
  1795. "goodOutOpen": goodOutOpen,
  1796. "patientDiagnose": patientDiagnose,
  1797. })
  1798. }
  1799. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1800. //获取所有基础药
  1801. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1802. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1803. if config.ID > 0 && config.IsOpen == 1 {
  1804. for _, item := range drugs {
  1805. var index = 0
  1806. for _, subItem := range item.OtherDrugWarehouseInfo {
  1807. if index == 0 {
  1808. index = index + 1
  1809. if subItem.RetailPrice > 0 {
  1810. item.MinPrice = subItem.RetailPrice
  1811. }
  1812. }
  1813. }
  1814. }
  1815. }
  1816. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1817. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1818. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1819. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1820. //获取所有科室信息
  1821. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1822. //获取诊断信息
  1823. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1824. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1825. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1826. //获取是否开启保存耗材出库的开关
  1827. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1828. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1829. c.ServeSuccessJSON(map[string]interface{}{
  1830. "drugs": drugs,
  1831. "advices_template": advices,
  1832. "drugways": drugways,
  1833. "efs": efs,
  1834. "doctors": doctors,
  1835. "department": department,
  1836. "sick": sick,
  1837. "additions": additions,
  1838. "diagnose": diagnose,
  1839. "manufacturers": manufacturers,
  1840. "goodOutOpen": goodOutOpen,
  1841. "patientDiagnose": patientDiagnose,
  1842. })
  1843. }
  1844. }
  1845. func (c *HisApiController) CreateHisPrescription() {
  1846. record_date := c.GetString("record_date")
  1847. patient_id, _ := c.GetInt64("patient_id")
  1848. reg_type, _ := c.GetInt64("reg_type")
  1849. diagnose := c.GetString("diagnose")
  1850. sick_type, _ := c.GetInt64("sick_type")
  1851. sick_history := c.GetString("sick_history")
  1852. doctor_id, _ := c.GetInt64("doctor", 0)
  1853. department, _ := c.GetInt64("department", 0)
  1854. his_patient_id, _ := c.GetInt64("his_patient_id")
  1855. p_type, _ := c.GetInt64("p_type")
  1856. patient_diagnose := c.GetString("patient_diagnose")
  1857. dataBody := make(map[string]interface{}, 0)
  1858. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1859. if err != nil {
  1860. utils.ErrorLog(err.Error())
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. //edit, src := GetCompareData(dataBody)
  1865. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1866. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1867. //fmt.Println(drugResult)
  1868. //fmt.Println(goodResult)
  1869. timeLayout := "2006-01-02"
  1870. loc, _ := time.LoadLocation("Local")
  1871. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1872. if err != nil {
  1873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1874. return
  1875. }
  1876. adminInfo := c.GetAdminUserInfo()
  1877. recordDateTime := theTime.Unix()
  1878. //查询默认出库仓库库存
  1879. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1880. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1881. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1882. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1883. if len(lists) == 1 {
  1884. his_patient_id = lists[0].ID
  1885. }
  1886. }
  1887. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1888. //自动出库的开关开启
  1889. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1890. //自动出库
  1891. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1892. //耗材保存处方出库
  1893. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1894. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1895. //已发药和已收费限制逻辑
  1896. isMidicine := false
  1897. isCharge := false
  1898. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1899. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1900. if len(prescriptions) > 0 {
  1901. for _, item := range prescriptions {
  1902. items := item.(map[string]interface{})
  1903. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1904. utils.ErrorLog("id")
  1905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1906. return
  1907. }
  1908. id := int64(items["id"].(float64))
  1909. if id > 0 {
  1910. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1911. if err != nil {
  1912. if new_prescription.OrderStatus == 4 {
  1913. isCharge = true
  1914. }
  1915. }
  1916. }
  1917. }
  1918. }
  1919. }
  1920. if isMidicine == true {
  1921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1922. return
  1923. }
  1924. if isCharge == true {
  1925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1926. return
  1927. }
  1928. // 开始主事务
  1929. db := service.XTWriteDB()
  1930. tx := db.Begin()
  1931. // 在函数结束时处理事务回滚
  1932. defer func() {
  1933. if r := recover(); r != nil {
  1934. tx.Rollback()
  1935. }
  1936. }()
  1937. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1938. //药品发药出库
  1939. if pharmacyConfig.IsOpen == 1 {
  1940. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1941. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1942. if len(prescriptions) > 0 {
  1943. for _, item := range prescriptions {
  1944. items := item.(map[string]interface{})
  1945. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1946. advices := items["advices"].([]interface{})
  1947. if len(advices) > 0 {
  1948. for _, advice := range advices {
  1949. var drug_id int64
  1950. var prescribing_number float64
  1951. var prescribingNumberUnit string
  1952. var adviceId int64
  1953. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1954. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1955. }
  1956. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1957. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1958. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1959. }
  1960. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1961. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1962. }
  1963. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1964. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1965. }
  1966. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1967. if drug.ID == 0 {
  1968. tx.Rollback()
  1969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1970. return
  1971. }
  1972. //查询药品的所有库存
  1973. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1974. var total_count int64
  1975. for _, it := range list {
  1976. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1977. }
  1978. totals := strconv.FormatInt(total_count, 10)
  1979. //查询该药品是否存在开药记录
  1980. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1981. //新增处方盘点库存是否充足
  1982. if advicelist.ID == 0 {
  1983. all_count, _ := strconv.ParseFloat(totals, 64)
  1984. if prescribingNumberUnit == drug.MinUnit {
  1985. if drug.IsUse != 1 {
  1986. if drug.IsProject == 0 || drug.IsProject == 2 {
  1987. if all_count == 0 {
  1988. tx.Rollback()
  1989. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1990. return
  1991. }
  1992. if prescribing_number > all_count {
  1993. tx.Rollback()
  1994. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1995. return
  1996. }
  1997. }
  1998. }
  1999. }
  2000. if prescribingNumberUnit == drug.MaxUnit {
  2001. num := prescribing_number * float64(drug.MinNumber)
  2002. if drug.IsUse != 1 {
  2003. if drug.IsProject == 0 || drug.IsProject == 2 {
  2004. if all_count == 0 {
  2005. tx.Rollback()
  2006. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2007. return
  2008. }
  2009. if num > all_count {
  2010. tx.Rollback()
  2011. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2012. return
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2019. //不使用保存处方出库
  2020. if drugOutConfig.IsOpen != 1 {
  2021. //修改处方
  2022. for _, advice := range advices {
  2023. var drug_id int64
  2024. var prescribing_number float64
  2025. var prescribingNumberUnit string
  2026. var prescribingNumber string
  2027. var adviceId int64
  2028. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2029. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2030. }
  2031. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2032. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2033. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2034. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2035. }
  2036. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2037. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2038. }
  2039. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2040. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2041. }
  2042. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2043. if drug.ID == 0 {
  2044. tx.Rollback()
  2045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2046. return
  2047. }
  2048. //查询药品的所有库存
  2049. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2050. var total_count int64
  2051. for _, it := range list {
  2052. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2053. }
  2054. totals := strconv.FormatInt(total_count, 10)
  2055. //查询该药品是否存在开药记录
  2056. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2057. //新增处方
  2058. if advicelist.ID == 0 {
  2059. all_count, _ := strconv.ParseFloat(totals, 64)
  2060. if prescribingNumberUnit == drug.MinUnit {
  2061. if drug.IsUse != 1 {
  2062. if drug.IsProject == 0 || drug.IsProject == 2 {
  2063. if all_count == 0 {
  2064. tx.Rollback()
  2065. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2066. return
  2067. }
  2068. if prescribing_number > all_count {
  2069. tx.Rollback()
  2070. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2071. return
  2072. }
  2073. }
  2074. }
  2075. } else {
  2076. if prescribingNumberUnit == drug.MaxUnit {
  2077. num := prescribing_number * float64(drug.MinNumber)
  2078. if drug.IsUse != 1 {
  2079. if drug.IsProject == 0 || drug.IsProject == 2 {
  2080. if all_count == 0 {
  2081. tx.Rollback()
  2082. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2083. return
  2084. }
  2085. if num > all_count {
  2086. tx.Rollback()
  2087. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2088. return
  2089. }
  2090. }
  2091. }
  2092. }
  2093. }
  2094. }
  2095. //修改处方
  2096. if advicelist.ID > 0 {
  2097. var device_number int64
  2098. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2099. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2100. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2101. device_number = prescribingNumberInt * drug.MinNumber
  2102. }
  2103. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2104. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2105. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2106. device_number = prescribingNumberInt
  2107. }
  2108. var number_count int64
  2109. if prescribingNumberUnit == drug.MaxUnit {
  2110. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2111. number_count = prescribingNumberInt * drug.MinNumber
  2112. }
  2113. if prescribingNumberUnit == drug.MinUnit {
  2114. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2115. number_count = prescribingNumberInt
  2116. }
  2117. //如果修改的数量大于之前修改的数量
  2118. if (number_count - device_number) > 0 {
  2119. //如果修改的差数量 大于库存数量
  2120. if drug.IsUse != 1 {
  2121. if (number_count - device_number) > total_count {
  2122. tx.Rollback()
  2123. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2124. return
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. }
  2132. }
  2133. }
  2134. }
  2135. }
  2136. }
  2137. }
  2138. //已发药和已收费限制逻辑
  2139. //执行出库的逻辑
  2140. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2141. //校验库存总量
  2142. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2143. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2144. if len(prescriptions) > 0 {
  2145. for _, item := range prescriptions {
  2146. items := item.(map[string]interface{})
  2147. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2148. advices := items["advices"].([]interface{})
  2149. if len(advices) > 0 {
  2150. for _, advice := range advices {
  2151. var drug_id int64
  2152. var prescribing_number float64
  2153. var prescribingNumberUnit string
  2154. var adviceId int64
  2155. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2156. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2157. }
  2158. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2159. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2160. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2161. }
  2162. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2163. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2164. }
  2165. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2166. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2167. }
  2168. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2169. if drug.ID == 0 {
  2170. tx.Rollback()
  2171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2172. return
  2173. }
  2174. //查询药品的所有库存
  2175. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2176. var total_count int64
  2177. for _, it := range list {
  2178. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2179. }
  2180. totals := strconv.FormatInt(total_count, 10)
  2181. //查询该药品是否存在开药记录
  2182. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2183. //查询最新批次库存
  2184. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2185. var batch_number_count int64
  2186. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2187. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2188. //新增处方
  2189. if advicelist.ID == 0 {
  2190. all_count, _ := strconv.ParseFloat(totals, 64)
  2191. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2192. if prescribingNumberUnit == drug.MinUnit {
  2193. if drug.IsUse != 1 {
  2194. if drug.IsProject == 0 || drug.IsProject == 2 {
  2195. if all_count == 0 {
  2196. tx.Rollback()
  2197. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2198. return
  2199. }
  2200. if prescribing_number > all_count {
  2201. tx.Rollback()
  2202. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2203. return
  2204. }
  2205. }
  2206. if adminInfo.CurrentOrgId == 10215 {
  2207. if prescribing_number > batch_number_all_count {
  2208. tx.Rollback()
  2209. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2210. return
  2211. }
  2212. }
  2213. }
  2214. }
  2215. if prescribingNumberUnit == drug.MaxUnit {
  2216. num := prescribing_number * float64(drug.MinNumber)
  2217. if drug.IsUse != 1 {
  2218. if drug.IsProject == 0 || drug.IsProject == 2 {
  2219. if all_count == 0 {
  2220. tx.Rollback()
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2222. return
  2223. }
  2224. if num > all_count {
  2225. tx.Rollback()
  2226. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2227. return
  2228. }
  2229. }
  2230. if adminInfo.CurrentOrgId == 10215 {
  2231. if num > batch_number_all_count {
  2232. tx.Rollback()
  2233. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2234. return
  2235. }
  2236. }
  2237. }
  2238. }
  2239. }
  2240. //不是保存处方出库
  2241. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2242. if drugOutConfig.IsOpen != 1 {
  2243. //修改处方
  2244. for _, advice := range advices {
  2245. var drug_id int64
  2246. var prescribing_number float64
  2247. var prescribingNumberUnit string
  2248. var prescribingNumber string
  2249. var adviceId int64
  2250. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2251. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2252. }
  2253. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2254. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2255. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2256. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2257. }
  2258. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2259. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2260. }
  2261. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2262. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2263. }
  2264. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2265. if drug.ID == 0 {
  2266. tx.Rollback()
  2267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2268. return
  2269. }
  2270. //查询药品的所有库存
  2271. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2272. var total_count int64
  2273. for _, it := range list {
  2274. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2275. }
  2276. totals := strconv.FormatInt(total_count, 10)
  2277. //查询该药品是否存在开药记录
  2278. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2279. //新增处方
  2280. if advicelist.ID == 0 {
  2281. //查询最新批次库存
  2282. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2283. var batch_number_count int64
  2284. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2285. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2286. all_count, _ := strconv.ParseFloat(totals, 64)
  2287. if all_count == 0 {
  2288. tx.Rollback()
  2289. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2290. return
  2291. }
  2292. if prescribingNumberUnit == drug.MinUnit {
  2293. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2294. if drug.IsUse != 1 {
  2295. if drug.IsProject == 0 || drug.IsProject == 2 {
  2296. if all_count == 0 {
  2297. tx.Rollback()
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2299. return
  2300. }
  2301. if prescribing_number > all_count {
  2302. tx.Rollback()
  2303. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2304. return
  2305. }
  2306. }
  2307. if adminInfo.CurrentOrgId == 10215 {
  2308. if prescribing_number > batch_number_all_count {
  2309. tx.Rollback()
  2310. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2311. return
  2312. }
  2313. }
  2314. }
  2315. } else {
  2316. if prescribingNumberUnit == drug.MaxUnit {
  2317. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2318. num := prescribing_number * float64(drug.MinNumber)
  2319. if drug.IsUse != 1 {
  2320. if drug.IsProject == 0 || drug.IsProject == 2 {
  2321. if all_count == 0 {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2324. return
  2325. }
  2326. if num > all_count {
  2327. tx.Rollback()
  2328. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2329. return
  2330. }
  2331. }
  2332. if adminInfo.CurrentOrgId == 10215 {
  2333. if prescribing_number > batch_number_all_count {
  2334. tx.Rollback()
  2335. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2336. return
  2337. }
  2338. }
  2339. }
  2340. }
  2341. }
  2342. }
  2343. //修改处方
  2344. if advicelist.ID > 0 {
  2345. //查询最新批次库存
  2346. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2347. var batch_number_count int64
  2348. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2349. var device_number int64
  2350. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2351. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2352. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2353. device_number = prescribingNumberInt * drug.MinNumber
  2354. }
  2355. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2356. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2357. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2358. device_number = prescribingNumberInt
  2359. //回退库存
  2360. }
  2361. var number_count int64
  2362. if prescribingNumberUnit == drug.MaxUnit {
  2363. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2364. number_count = prescribingNumberInt * drug.MinNumber
  2365. //回退库存
  2366. }
  2367. if prescribingNumberUnit == drug.MinUnit {
  2368. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2369. number_count = prescribingNumberInt
  2370. //回退库存
  2371. }
  2372. //如果修改的数量大于之前修改的数量
  2373. if (number_count - device_number) > 0 {
  2374. //如果修改的差数量 大于库存数量
  2375. if drug.IsUse != 1 {
  2376. if drug.IsProject == 0 || drug.IsProject == 2 {
  2377. if total_count == 0 {
  2378. tx.Rollback()
  2379. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2380. return
  2381. }
  2382. if (number_count - device_number) > total_count {
  2383. tx.Rollback()
  2384. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2385. return
  2386. }
  2387. if (number_count - device_number) > batch_number_count {
  2388. tx.Rollback()
  2389. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2390. return
  2391. }
  2392. }
  2393. if adminInfo.CurrentOrgId == 10215 {
  2394. // 查询该药品最后一次出库记录
  2395. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2396. var out_count int64
  2397. var in_count int64
  2398. var stock_max_number int64
  2399. var stock_min_number int64
  2400. for _, it := range outInfo {
  2401. if it.CountUnit == drug.MaxUnit {
  2402. it.Count = it.Count * drug.MinNumber
  2403. }
  2404. out_count += it.Count
  2405. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2406. stock_max_number = warehouseInfoList.StockMaxNumber
  2407. stock_min_number = warehouseInfoList.StockMinNumber
  2408. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2409. }
  2410. if out_count > 0 {
  2411. if (number_count - device_number) > in_count {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2414. return
  2415. }
  2416. }
  2417. // 未出库
  2418. if out_count == 0 {
  2419. var sum_in_count int64
  2420. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2421. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2422. //如果修改的数量大于有库存的第一个批次
  2423. if number_count > sum_in_count {
  2424. tx.Rollback()
  2425. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2426. return
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. //药品发药
  2433. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2434. //不使用药品发药的功能
  2435. //if pharmacyConfig.IsOpen != 1 {
  2436. // if device_number != number_count {
  2437. //
  2438. // //查询该药品的出库记录
  2439. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2440. // if len(outListExport) > 0 {
  2441. // //
  2442. // for _, item := range outListExport {
  2443. // //回退库存
  2444. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2445. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2446. // }
  2447. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2448. // var stock_max_number int64
  2449. // var stock_min_number int64
  2450. //
  2451. // if number_count >= drug.MinNumber {
  2452. //
  2453. // stock_max_number = device_number / drug.MinNumber
  2454. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2455. //
  2456. // stock_min_number = device_number % drug.MinNumber
  2457. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2458. //
  2459. // } else {
  2460. //
  2461. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2462. //
  2463. // }
  2464. // }
  2465. //
  2466. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2467. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2468. // }
  2469. // }
  2470. // }
  2471. //
  2472. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2473. // var sum_count int64
  2474. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2475. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2476. // for _, its := range stockInfo {
  2477. // if its.MaxUnit == drug.MaxUnit {
  2478. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2479. // }
  2480. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2481. // }
  2482. // //更新字典里面的库存
  2483. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2484. //
  2485. // //剩余库存
  2486. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2487. //
  2488. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2489. // //减少出库数量
  2490. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2491. //
  2492. // }
  2493. //}
  2494. }
  2495. }
  2496. }
  2497. //保存处方开药
  2498. if drugOutConfig.IsOpen == 1 {
  2499. //修改处方
  2500. for _, advice := range advices {
  2501. var drug_id int64
  2502. var prescribing_number float64
  2503. var prescribingNumberUnit string
  2504. var prescribingNumber string
  2505. var adviceId int64
  2506. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2507. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2508. }
  2509. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2510. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2511. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2512. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2513. }
  2514. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2515. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2516. }
  2517. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2518. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2519. }
  2520. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2521. if drug.ID == 0 {
  2522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2523. return
  2524. }
  2525. //查询药品的所有库存
  2526. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2527. var total_count int64
  2528. for _, it := range list {
  2529. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2530. }
  2531. totals := strconv.FormatInt(total_count, 10)
  2532. //查询该药品是否存在开药记录
  2533. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2534. //新增处方
  2535. if advicelist.ID == 0 {
  2536. //查询最新批次库存
  2537. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2538. var batch_number_count int64
  2539. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2540. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2541. all_count, _ := strconv.ParseFloat(totals, 64)
  2542. if prescribingNumberUnit == drug.MinUnit {
  2543. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2544. if drug.IsUse != 1 {
  2545. if drug.IsProject == 0 || drug.IsProject == 2 {
  2546. if all_count == 0 {
  2547. tx.Rollback()
  2548. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2549. return
  2550. }
  2551. if prescribing_number > all_count {
  2552. tx.Rollback()
  2553. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2554. return
  2555. }
  2556. }
  2557. if adminInfo.CurrentOrgId == 10215 {
  2558. if prescribing_number > batch_number_all_count {
  2559. tx.Rollback()
  2560. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2561. return
  2562. }
  2563. }
  2564. }
  2565. } else {
  2566. if prescribingNumberUnit == drug.MaxUnit {
  2567. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2568. num := prescribing_number * float64(drug.MinNumber)
  2569. if drug.IsUse != 1 {
  2570. if drug.IsProject == 0 || drug.IsProject == 2 {
  2571. if all_count == 0 {
  2572. tx.Rollback()
  2573. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2574. return
  2575. }
  2576. if num > all_count {
  2577. tx.Rollback()
  2578. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2579. return
  2580. }
  2581. }
  2582. if adminInfo.CurrentOrgId == 10215 {
  2583. if prescribing_number > batch_number_all_count {
  2584. tx.Rollback()
  2585. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2586. return
  2587. }
  2588. }
  2589. }
  2590. }
  2591. }
  2592. }
  2593. //修改处方
  2594. if advicelist.ID > 0 {
  2595. //查询最新批次库存
  2596. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2597. var batch_number_count int64
  2598. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2599. var device_number int64
  2600. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2601. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2602. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2603. device_number = prescribingNumberInt * drug.MinNumber
  2604. }
  2605. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2606. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2607. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2608. device_number = prescribingNumberInt
  2609. }
  2610. var number_count int64
  2611. if prescribingNumberUnit == drug.MaxUnit {
  2612. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2613. number_count = prescribingNumberInt * drug.MinNumber
  2614. }
  2615. if prescribingNumberUnit == drug.MinUnit {
  2616. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2617. number_count = prescribingNumberInt
  2618. }
  2619. //如果修改的数量大于之前修改的数量
  2620. if (number_count - device_number) > 0 {
  2621. //如果修改的差数量 大于库存数量
  2622. if drug.IsUse != 1 {
  2623. if drug.IsProject == 0 || drug.IsProject == 2 {
  2624. if total_count == 0 {
  2625. tx.Rollback()
  2626. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2627. return
  2628. }
  2629. if (number_count - device_number) > total_count {
  2630. tx.Rollback()
  2631. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2632. return
  2633. }
  2634. }
  2635. if adminInfo.CurrentOrgId == 10215 {
  2636. if (number_count - device_number) > batch_number_count {
  2637. tx.Rollback()
  2638. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2639. return
  2640. }
  2641. }
  2642. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2643. //查询历史出库数据总批次
  2644. // 查询该药品最后一次出库记录
  2645. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2646. var out_count int64
  2647. var in_count int64
  2648. var stock_max_number int64
  2649. var stock_min_number int64
  2650. for _, it := range outInfo {
  2651. if it.CountUnit == drug.MaxUnit {
  2652. it.Count = it.Count * drug.MinNumber
  2653. }
  2654. out_count += it.Count
  2655. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2656. stock_max_number = warehouseInfoList.StockMaxNumber
  2657. stock_min_number = warehouseInfoList.StockMinNumber
  2658. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2659. }
  2660. if out_count > 0 {
  2661. if (number_count - device_number) > in_count {
  2662. tx.Rollback()
  2663. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2664. return
  2665. }
  2666. }
  2667. // 未出库
  2668. if out_count == 0 {
  2669. var sum_in_count int64
  2670. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2671. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2672. if sum_in_count == 0 {
  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. if number_count > sum_in_count {
  2679. tx.Rollback()
  2680. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2681. return
  2682. }
  2683. }
  2684. }
  2685. }
  2686. }
  2687. }
  2688. }
  2689. }
  2690. }
  2691. }
  2692. }
  2693. }
  2694. }
  2695. }
  2696. }
  2697. //校验耗材库存
  2698. if goodOutConfig.IsOpen == 1 {
  2699. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2700. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2701. if len(prescriptions) > 0 {
  2702. for _, item := range prescriptions {
  2703. items := item.(map[string]interface{})
  2704. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2705. projects := items["project"].([]interface{})
  2706. if len(projects) > 0 {
  2707. for _, project := range projects {
  2708. var project_id int64
  2709. var project_type int64
  2710. var totals float64
  2711. var project_name string
  2712. var parsetotal int64
  2713. var id int64
  2714. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2715. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2716. }
  2717. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2718. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2719. }
  2720. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2721. total, _ := project.(map[string]interface{})["total"].(string)
  2722. totals, _ = strconv.ParseFloat(total, 64)
  2723. }
  2724. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2725. project_name = project.(map[string]interface{})["project_name"].(string)
  2726. }
  2727. if project_type == 3 {
  2728. //查找该耗材的出库记录
  2729. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2730. if len(goodWarehouseInfo) == 0 {
  2731. //查询耗材库存
  2732. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2733. var stock_count int64
  2734. for _, it := range list {
  2735. stock_count += it.StockCount
  2736. }
  2737. stock_counts := strconv.FormatInt(stock_count, 10)
  2738. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2739. if stock_total_count == 0 {
  2740. tx.Rollback()
  2741. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2742. return
  2743. }
  2744. if totals > stock_total_count {
  2745. tx.Rollback()
  2746. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2747. return
  2748. }
  2749. }
  2750. if len(goodWarehouseInfo) > 0 {
  2751. //查询该患者耗材的历史数据
  2752. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2753. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2754. //数量发生改变
  2755. if parsetotal != count {
  2756. //如果现在的数量大于历史数量,就要看库存是否足够
  2757. if parsetotal > count {
  2758. //查询耗材所有库存
  2759. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2760. var stock_count int64
  2761. for _, it := range list {
  2762. stock_count += it.StockCount
  2763. }
  2764. //库存不足
  2765. if stock_count == 0 {
  2766. tx.Rollback()
  2767. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2768. return
  2769. }
  2770. if (parsetotal - count) > stock_count {
  2771. tx.Rollback()
  2772. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2773. return
  2774. }
  2775. }
  2776. }
  2777. }
  2778. }
  2779. }
  2780. }
  2781. }
  2782. }
  2783. }
  2784. }
  2785. }
  2786. //不使用耗材保存处方出库
  2787. if goodOutConfig.IsOpen != 1 {
  2788. if stockConfig.IsOpen == 1 {
  2789. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2790. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2791. if len(prescriptions) > 0 {
  2792. for _, item := range prescriptions {
  2793. items := item.(map[string]interface{})
  2794. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2795. projects := items["project"].([]interface{})
  2796. if len(projects) > 0 {
  2797. for _, project := range projects {
  2798. var project_id int64
  2799. var project_type int64
  2800. var totals float64
  2801. var project_name string
  2802. var parsetotal int64
  2803. var id int64
  2804. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2805. id = int64(project.(map[string]interface{})["id"].(float64))
  2806. }
  2807. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2808. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2809. }
  2810. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2811. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2812. }
  2813. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2814. total, _ := project.(map[string]interface{})["total"].(string)
  2815. totals, _ = strconv.ParseFloat(total, 64)
  2816. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2817. }
  2818. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2819. project_name = project.(map[string]interface{})["project_name"].(string)
  2820. }
  2821. if project_type == 3 {
  2822. //查找该耗材的出库记录
  2823. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2824. //没有出库记录
  2825. if len(goodWarehouseInfo) == 0 {
  2826. //查询耗材库存
  2827. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2828. var stock_count int64
  2829. for _, it := range list {
  2830. stock_count += it.StockCount
  2831. }
  2832. stock_counts := strconv.FormatInt(stock_count, 10)
  2833. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2834. if stock_total_count == 0 {
  2835. tx.Rollback()
  2836. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2837. return
  2838. }
  2839. if totals > stock_total_count {
  2840. tx.Rollback()
  2841. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2842. return
  2843. }
  2844. //查找今日该患者已经出库的所有耗材
  2845. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2846. for _, item := range goodList {
  2847. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2848. var flush_count int64
  2849. for _, it := range goodListSix {
  2850. flush_count += it.StockCount
  2851. }
  2852. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2853. creater := adminInfo.AdminUser.Id
  2854. if errs != nil {
  2855. goodErrcode := models.XtGoodErrcode{
  2856. UserOrgId: item.OrgId,
  2857. Errcode: "手动出库更新剩余出库失败",
  2858. GoodId: item.GoodId,
  2859. Status: 1,
  2860. Ctime: time.Now().Unix(),
  2861. Mtime: 0,
  2862. Count: 0,
  2863. StockCount: 0,
  2864. Creater: creater,
  2865. BatchNumberId: 0,
  2866. WarehouseOutId: 0,
  2867. }
  2868. service.CreateGoodErrcode(goodErrcode)
  2869. }
  2870. }
  2871. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2872. }
  2873. //有出库记录
  2874. if len(goodWarehouseInfo) > 0 {
  2875. //查询该患者耗材的历史数据
  2876. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2877. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2878. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2879. //数量发生改变
  2880. if parsetotal != count {
  2881. //查找今日该患者已经出库的所有耗材
  2882. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2883. for _, item := range goodList {
  2884. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2885. var flush_count int64
  2886. for _, it := range goodListSix {
  2887. flush_count += it.StockCount
  2888. }
  2889. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2890. //减少出库数量
  2891. creater := adminInfo.AdminUser.Id
  2892. if errs != nil {
  2893. goodErrcode := models.XtGoodErrcode{
  2894. UserOrgId: item.OrgId,
  2895. Errcode: "手动出库更新剩余出库失败",
  2896. GoodId: item.GoodId,
  2897. Status: 1,
  2898. Ctime: time.Now().Unix(),
  2899. Mtime: 0,
  2900. Count: 0,
  2901. StockCount: 0,
  2902. Creater: creater,
  2903. BatchNumberId: 0,
  2904. WarehouseOutId: 0,
  2905. }
  2906. service.CreateGoodErrcode(goodErrcode)
  2907. }
  2908. //查询默认仓库
  2909. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2910. var total_count int64
  2911. for _, it := range stockList {
  2912. total_count += it.StockCount
  2913. }
  2914. //基础库插入数据
  2915. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2916. }
  2917. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2918. }
  2919. }
  2920. }
  2921. }
  2922. }
  2923. }
  2924. }
  2925. }
  2926. }
  2927. }
  2928. }
  2929. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2930. var hpInfo models.HisPrescriptionInfo
  2931. if info.ID == 0 {
  2932. var randNum int
  2933. randNum = rand.Intn(10000) + 1000
  2934. timestamp := time.Now().Unix()
  2935. tempTime := time.Unix(timestamp, 0)
  2936. timeFormat := tempTime.Format("20060102150405")
  2937. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2938. hpInfo = models.HisPrescriptionInfo{
  2939. HisPatientId: his_patient_id,
  2940. UserOrgId: adminInfo.CurrentOrgId,
  2941. RecordDate: theTime.Unix(),
  2942. PatientId: patient_id,
  2943. Status: 1,
  2944. Ctime: time.Now().Unix(),
  2945. Mtime: time.Now().Unix(),
  2946. Creator: adminInfo.AdminUser.Id,
  2947. Modifier: adminInfo.AdminUser.Id,
  2948. Diagnosis: diagnose,
  2949. SickHistory: sick_history,
  2950. Departments: department,
  2951. RegisterType: reg_type,
  2952. PrescriptionNumber: p_number,
  2953. PrescriptionStatus: 1,
  2954. Doctor: role.UserName,
  2955. DoctorId: doctor_id,
  2956. SickType: sick_type,
  2957. PType: p_type,
  2958. PatientDiagnosis: patient_diagnose,
  2959. }
  2960. service.SavePatientPrescriptionInfo(hpInfo)
  2961. //创建步骤表
  2962. finish := models.XtDialysisFinish{
  2963. IsFinish: 1,
  2964. UserOrgId: adminInfo.CurrentOrgId,
  2965. Status: 1,
  2966. Ctime: time.Now().Unix(),
  2967. Mtime: 0,
  2968. Module: 4,
  2969. RecordDate: theTime.Unix(),
  2970. Sourse: 1,
  2971. PatientId: patient_id,
  2972. }
  2973. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2974. if dialysisFinish.ID == 0 {
  2975. service.CreateDialysisFinish(finish)
  2976. }
  2977. redis := service.RedisClient()
  2978. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2979. redis.Set(key, "", time.Second)
  2980. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2981. redis.Set(keyOne, "", time.Second)
  2982. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2983. redis.Set(keySeven, "", time.Second)
  2984. defer redis.Close()
  2985. } else {
  2986. hpInfo = models.HisPrescriptionInfo{
  2987. ID: info.ID,
  2988. UserOrgId: adminInfo.CurrentOrgId,
  2989. RecordDate: info.RecordDate,
  2990. PatientId: info.PatientId,
  2991. Status: 1,
  2992. Ctime: info.Ctime,
  2993. Mtime: time.Now().Unix(),
  2994. Creator: info.Creator,
  2995. Modifier: adminInfo.AdminUser.Id,
  2996. Diagnosis: diagnose,
  2997. SickHistory: sick_history,
  2998. Departments: department,
  2999. RegisterType: reg_type,
  3000. PrescriptionNumber: info.PrescriptionNumber,
  3001. Doctor: role.UserName,
  3002. PrescriptionStatus: info.PrescriptionStatus,
  3003. DoctorId: doctor_id,
  3004. SickType: sick_type,
  3005. PType: info.PType,
  3006. HisPatientId: info.HisPatientId,
  3007. PatientDiagnosis: patient_diagnose,
  3008. }
  3009. service.SavePatientPrescriptionInfo(hpInfo)
  3010. //创建步骤表
  3011. finish := models.XtDialysisFinish{
  3012. IsFinish: 1,
  3013. UserOrgId: adminInfo.CurrentOrgId,
  3014. Status: 1,
  3015. Ctime: time.Now().Unix(),
  3016. Mtime: 0,
  3017. Module: 4,
  3018. RecordDate: info.RecordDate,
  3019. Sourse: 1,
  3020. PatientId: info.PatientId,
  3021. }
  3022. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3023. if dialysisFinish.ID == 0 {
  3024. service.CreateDialysisFinish(finish)
  3025. }
  3026. redis := service.RedisClient()
  3027. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3028. redis.Set(key, "", time.Second)
  3029. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3030. redis.Set(keyOne, "", time.Second)
  3031. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3032. redis.Set(keySeven, "", time.Second)
  3033. defer redis.Close()
  3034. }
  3035. //定义切片
  3036. var adviceList []models.HisDoctorAdviceInfo
  3037. var projectList []models.HisPrescriptionProject
  3038. 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 {
  3039. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3040. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3041. var tempPrescription *models.HisPrescription
  3042. if len(prescriptions) > 0 {
  3043. for _, item := range prescriptions {
  3044. // 开始外部循环的事务
  3045. tx := db.Begin()
  3046. // 在函数结束时处理事务回滚
  3047. defer func() {
  3048. if r := recover(); r != nil {
  3049. tx.Rollback()
  3050. }
  3051. }()
  3052. items := item.(map[string]interface{})
  3053. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3054. utils.ErrorLog("id")
  3055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3056. return
  3057. }
  3058. id := int64(items["id"].(float64))
  3059. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3060. tempPrescription = &new_prescription
  3061. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3062. utils.ErrorLog("type")
  3063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3064. return
  3065. }
  3066. types := int64(items["type"].(float64))
  3067. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3068. utils.ErrorLog("med_type")
  3069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3070. return
  3071. }
  3072. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3073. if med_type == "0" {
  3074. med_type = "14"
  3075. }
  3076. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3077. // utils.ErrorLog("diagnoses")
  3078. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3079. // return
  3080. //}
  3081. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3082. diagnoses, _ := items["diagnoses"].(string)
  3083. //if order_status == 0 {
  3084. // order_status = 1
  3085. //}
  3086. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3087. utils.ErrorLog("pre_time")
  3088. }
  3089. preTime, _ := items["pre_time"].(string)
  3090. fmt.Println("preTime", preTime)
  3091. timeLayout := "2006-01-02"
  3092. loc, _ := time.LoadLocation("Local")
  3093. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3094. //result := strings.Split(preTime, " ")
  3095. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3096. if err != nil {
  3097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3098. return
  3099. }
  3100. pTime := theTime2.Unix()
  3101. ctime := time.Now().Unix()
  3102. if tempPrescription.ID == 0 {
  3103. prescription := &models.HisPrescription{
  3104. ID: 0,
  3105. PatientId: patient_id,
  3106. UserOrgId: adminInfo.CurrentOrgId,
  3107. RecordDate: recordDateTime,
  3108. Ctime: ctime,
  3109. Mtime: ctime,
  3110. Type: types,
  3111. Modifier: adminInfo.AdminUser.Id,
  3112. Creator: adminInfo.AdminUser.Id,
  3113. Status: 1,
  3114. Doctor: role.UserName,
  3115. HisPatientId: his_patient_id,
  3116. OrderStatus: 1,
  3117. BatchNumber: "",
  3118. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3119. PreTime: pTime,
  3120. PType: p_type,
  3121. MedType: med_type,
  3122. Diagnose: diagnoses,
  3123. }
  3124. tempPrescription = prescription
  3125. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3126. redis := service.RedisClient()
  3127. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3128. redis.Set(key, "", time.Second)
  3129. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3130. redis.Set(keyOne, "", time.Second)
  3131. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3132. redis.Set(keySeven, "", time.Second)
  3133. defer redis.Close()
  3134. } else {
  3135. tempPrescription.ID = id
  3136. tempPrescription.Type = types
  3137. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3138. tempPrescription.Mtime = time.Now().Unix()
  3139. tempPrescription.Doctor = role.UserName
  3140. //tempPrescription.OrderStatus = order_status
  3141. tempPrescription.PreTime = pTime
  3142. tempPrescription.MedType = med_type
  3143. tempPrescription.Diagnose = diagnoses
  3144. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3145. redis := service.RedisClient()
  3146. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3147. redis.Set(key, "", time.Second)
  3148. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3149. redis.Set(keyOne, "", time.Second)
  3150. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3151. redis.Set(keySeven, "", time.Second)
  3152. defer redis.Close()
  3153. }
  3154. //service.SaveHisPrescription(prescription)
  3155. //更改患者挂号状态
  3156. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3157. fmt.Println("更改失败", err2)
  3158. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3159. advices := items["advices"].([]interface{})
  3160. groupNo := int64(0)
  3161. if len(advices) > 0 {
  3162. for _, advice := range advices {
  3163. tx := db.Begin()
  3164. // 在函数结束时处理事务回滚
  3165. defer func() {
  3166. if r := recover(); r != nil {
  3167. tx.Rollback()
  3168. }
  3169. }()
  3170. var s models.HisDoctorAdviceInfo
  3171. s.PrescriptionId = tempPrescription.ID
  3172. s.AdviceType = 2
  3173. s.AdviceDoctor = doctor_id
  3174. s.StopState = 2
  3175. s.ExecutionState = 2
  3176. s.AdviceDate = theTime3.Unix()
  3177. s.Status = 1
  3178. s.UserOrgId = adminInfo.CurrentOrgId
  3179. s.RecordDate = theTime3.Unix()
  3180. s.StartTime = tempPrescription.PreTime
  3181. s.Groupno = groupNo
  3182. s.PatientId = patient_id
  3183. s.HisPatientId = his_patient_id
  3184. s.StartTime = pTime
  3185. s.IsSettle = 2
  3186. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3187. if errcode > 0 {
  3188. c.ServeFailJSONWithSGJErrorCode(errcode)
  3189. return
  3190. }
  3191. s.StartTime = pTime
  3192. var total_count int64 //处方总库存
  3193. //查询改药品信息
  3194. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3195. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3196. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3197. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3198. total_count += prescribingNumberSeven * medical.MinNumber
  3199. }
  3200. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3201. total_count += prescribingNumberSeven
  3202. }
  3203. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3204. total_count += prescribingNumberSeven
  3205. }
  3206. //if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3207. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3208. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3209. // if s.Price != lastWarehouse.RetailPrice {
  3210. // s.Price = lastWarehouse.RetailPrice
  3211. // }
  3212. // if s.Price == 0 {
  3213. // if lastWarehouse.ID == 0 {
  3214. // lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3215. // s.Price = lastWarehouseTwo.RetailPrice
  3216. // }
  3217. //
  3218. // }
  3219. //}
  3220. //查询保存处方出库开关是否打开
  3221. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3222. if s.PatientId != 30038 {
  3223. if drugOutConfig.IsOpen == 1 {
  3224. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3225. // 查询该药品最后一次出库记录
  3226. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3227. var is_user_total int64
  3228. var no_user_total int64
  3229. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3230. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3231. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3232. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3233. }
  3234. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3235. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3236. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3237. no_user_total += prescribingNumberSevenTy
  3238. }
  3239. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3240. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3241. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3242. no_user_total += prescribingNumberSevenTy
  3243. }
  3244. if len(druginfo) > 0 {
  3245. for _, it := range druginfo {
  3246. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3247. it.Count = it.Count * drug.MinNumber
  3248. is_user_total += it.Count
  3249. }
  3250. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3251. is_user_total += it.Count
  3252. }
  3253. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3254. is_user_total += it.Count
  3255. }
  3256. }
  3257. }
  3258. //库存不足
  3259. if s.UserOrgId != 10206 {
  3260. //判断库存不足的地方
  3261. if s.ID == 0 {
  3262. //查询改药品是否已经停用
  3263. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3264. if base.ID > 0 {
  3265. tx.Rollback()
  3266. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3267. return
  3268. }
  3269. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3270. if drugMedical.SumCount == 0 {
  3271. tx.Rollback()
  3272. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3273. return
  3274. }
  3275. list, _ := service.GetLastDrugWarehouseInfoList(s.DrugId)
  3276. if len(list) == 0 {
  3277. tx.Rollback()
  3278. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3279. return
  3280. }
  3281. //针对康德
  3282. //if s.UserOrgId == 10402 || s.UserOrgId == 10164 {
  3283. // //获取该药品的总入库数量
  3284. // drugWarehouseinfo, _ := service.GetAllDrugInfoList(s.DrugId, s.UserOrgId)
  3285. //
  3286. // //获取该药品总共开了多少支医嘱
  3287. // hisDocInfoList, _ := service.GetHisDocInfoList(s.DrugId, s.UserOrgId)
  3288. // var in_count int64
  3289. // var in_prescription_number_total int64
  3290. // if len(drugWarehouseinfo) > 0 {
  3291. // for _, item := range drugWarehouseinfo {
  3292. // if item.MaxUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3293. //
  3294. // in_count += item.WarehousingCount * drugMedical.MinNumber
  3295. // }
  3296. //
  3297. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3298. //
  3299. // in_count += item.WarehousingCount
  3300. // }
  3301. //
  3302. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3303. //
  3304. // in_count += item.WarehousingCount
  3305. // }
  3306. //
  3307. // }
  3308. // }
  3309. //
  3310. // if len(hisDocInfoList) > 0 {
  3311. //
  3312. // for _, item := range hisDocInfoList {
  3313. // if item.PrescribingNumberUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3314. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3315. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3316. //
  3317. // in_prescription_number_total += prescribingNumberSevenTy * drug.MinNumber
  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. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3327. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3328. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3329. // in_prescription_number_total += prescribingNumberSevenTy
  3330. // }
  3331. // }
  3332. // }
  3333. // //
  3334. // //fmt.Println("no_user_total------------------------------", no_user_total)
  3335. // //fmt.Println("in_prescription_number_total---------------------------", in_prescription_number_total)
  3336. // //fmt.Println("in_count----------------------------------", in_count)
  3337. //
  3338. // //如果已经开过的医嘱 加上未开的医嘱数量 大于 入库总数量则提示库存不足
  3339. // if no_user_total+in_prescription_number_total > in_count {
  3340. // tx.Rollback()
  3341. // c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3342. // return
  3343. // }
  3344. //
  3345. //}
  3346. //查询该药品所有入库数量
  3347. }
  3348. fmt.Println("s.ID==========================", s.ID)
  3349. if s.ID > 0 {
  3350. //查询改药品是否已经停用
  3351. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3352. if base.ID > 0 {
  3353. tx.Rollback()
  3354. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3355. return
  3356. }
  3357. }
  3358. }
  3359. fmt.Println("药品名称----------------------", drug.DrugName)
  3360. fmt.Println("药品名称----------------------", drug.IsUse)
  3361. fmt.Println("drug_iiiiiiiiiiiiiiiiiiii", drug.ID)
  3362. fmt.Println("is_user_total-------------------------", is_user_total)
  3363. fmt.Println("no_user_total-------------------------", no_user_total)
  3364. fmt.Println("drug.IsUse---------------", drug.IsUse)
  3365. fmt.Println("00000000000000000000", s.UserOrgId)
  3366. if is_user_total != no_user_total {
  3367. //出库
  3368. //针对御享天源
  3369. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  3370. //查询改药品是否已经停用
  3371. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3372. if base.ID > 0 {
  3373. tx.Rollback()
  3374. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3375. return
  3376. }
  3377. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3378. if drugMedical.SumCount == 0 {
  3379. tx.Rollback()
  3380. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3381. return
  3382. }
  3383. creater := adminInfo.AdminUser.Id
  3384. newadviceInfo := &models.HisDoctorAdviceInfo{
  3385. ID: s.ID,
  3386. UserOrgId: s.UserOrgId,
  3387. PatientId: s.PatientId,
  3388. HisPatientId: s.HisPatientId,
  3389. AdviceType: s.AdviceType,
  3390. AdviceDate: s.AdviceDate,
  3391. StartTime: s.StartTime,
  3392. AdviceName: s.AdviceName,
  3393. AdviceDesc: s.AdviceDesc,
  3394. ReminderDate: s.ReminderDate,
  3395. SingleDose: s.SingleDose,
  3396. SingleDoseUnit: s.SingleDoseUnit,
  3397. PrescribingNumber: s.PrescribingNumber,
  3398. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3399. DeliveryWay: s.DeliveryWay,
  3400. ExecutionFrequency: s.ExecutionFrequency,
  3401. AdviceDoctor: s.AdviceDoctor,
  3402. Status: s.Status,
  3403. CreatedTime: s.CreatedTime,
  3404. UpdatedTime: s.UpdatedTime,
  3405. AdviceAffirm: s.AdviceAffirm,
  3406. Remark: s.Remark,
  3407. StopTime: s.StopTime,
  3408. StopReason: s.StopReason,
  3409. StopDoctor: s.StopDoctor,
  3410. StopState: s.StopState,
  3411. ParentId: s.ParentId,
  3412. ExecutionTime: s.ExecutionTime,
  3413. ExecutionStaff: s.ExecutionStaff,
  3414. ExecutionState: s.ExecutionState,
  3415. Checker: s.Checker,
  3416. RecordDate: s.RecordDate,
  3417. DialysisOrderId: s.DialysisOrderId,
  3418. CheckTime: s.CheckTime,
  3419. CheckState: s.CheckState,
  3420. DrugSpec: s.DrugSpec,
  3421. DrugSpecUnit: s.DrugSpecUnit,
  3422. Groupno: s.Groupno,
  3423. RemindType: s.RemindType,
  3424. FrequencyType: s.FrequencyType,
  3425. DayCount: s.DayCount,
  3426. WeekDay: s.WeekDay,
  3427. TemplateId: s.TemplateId,
  3428. Modifier: s.Modifier,
  3429. DrugId: s.DrugId,
  3430. Price: s.Price,
  3431. PrescriptionId: s.PrescriptionId,
  3432. MedListCodg: s.MedListCodg,
  3433. FeedetlSn: s.FeedetlSn,
  3434. Day: s.DayCount,
  3435. ChildDoctorAdvice: nil,
  3436. Drug: models.Drug{},
  3437. Diagnosis: s.Diagnosis,
  3438. Way: s.Way,
  3439. HospApprFlag: s.HospApprFlag,
  3440. LmtUsedFlag: s.LmtUsedFlag,
  3441. HisOrderInfo: models.HisOrderInfo{},
  3442. IsMedicine: s.IsMedicine,
  3443. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3444. Child: nil,
  3445. IsSettle: s.IsSettle,
  3446. IsMobile: s.IsMobile,
  3447. IsSelfDrug: s.IsSelfDrug,
  3448. DrugWayCount: s.DrugWayCount,
  3449. }
  3450. var history_count int64
  3451. var local_count int64
  3452. //查找已经开过的医嘱信息
  3453. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3454. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3455. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3456. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3457. local_count += prescribingNumberSevenTy * drug.MinNumber
  3458. }
  3459. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3460. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3461. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3462. local_count += prescribingNumberSevenTy
  3463. }
  3464. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3465. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3466. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3467. local_count += prescribingNumberSevenTy
  3468. }
  3469. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3470. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3471. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3472. history_count += prescribingNumberSevenTy * drug.MinNumber
  3473. }
  3474. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3475. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3476. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3477. history_count += prescribingNumberSevenTy
  3478. }
  3479. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3480. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3481. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3482. history_count += prescribingNumberSevenTy
  3483. }
  3484. fmt.Println("local_count---------------", local_count)
  3485. fmt.Println("history_count---------------", history_count)
  3486. //如果当前出库数量大于历史出库数量则需要出库
  3487. if local_count > history_count {
  3488. //按最小单位出库
  3489. var cha_count = local_count - history_count
  3490. newadviceInfo.PrescribingNumber = float64(cha_count)
  3491. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3492. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3493. }
  3494. //如果当前出库数量小于历史出库数量则需要退库
  3495. if local_count < history_count {
  3496. var cha_count = history_count - local_count
  3497. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3498. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3499. }
  3500. if local_count == history_count {
  3501. if is_user_total == 0 {
  3502. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3503. }
  3504. }
  3505. }
  3506. if drug.IsUse == 2 {
  3507. creater := adminInfo.AdminUser.Id
  3508. newadviceInfo := &models.HisDoctorAdviceInfo{
  3509. ID: s.ID,
  3510. UserOrgId: s.UserOrgId,
  3511. PatientId: s.PatientId,
  3512. HisPatientId: s.HisPatientId,
  3513. AdviceType: s.AdviceType,
  3514. AdviceDate: s.AdviceDate,
  3515. StartTime: s.StartTime,
  3516. AdviceName: s.AdviceName,
  3517. AdviceDesc: s.AdviceDesc,
  3518. ReminderDate: s.ReminderDate,
  3519. SingleDose: s.SingleDose,
  3520. SingleDoseUnit: s.SingleDoseUnit,
  3521. PrescribingNumber: s.PrescribingNumber,
  3522. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3523. DeliveryWay: s.DeliveryWay,
  3524. ExecutionFrequency: s.ExecutionFrequency,
  3525. AdviceDoctor: s.AdviceDoctor,
  3526. Status: s.Status,
  3527. CreatedTime: s.CreatedTime,
  3528. UpdatedTime: s.UpdatedTime,
  3529. AdviceAffirm: s.AdviceAffirm,
  3530. Remark: s.Remark,
  3531. StopTime: s.StopTime,
  3532. StopReason: s.StopReason,
  3533. StopDoctor: s.StopDoctor,
  3534. StopState: s.StopState,
  3535. ParentId: s.ParentId,
  3536. ExecutionTime: s.ExecutionTime,
  3537. ExecutionStaff: s.ExecutionStaff,
  3538. ExecutionState: s.ExecutionState,
  3539. Checker: s.Checker,
  3540. RecordDate: s.RecordDate,
  3541. DialysisOrderId: s.DialysisOrderId,
  3542. CheckTime: s.CheckTime,
  3543. CheckState: s.CheckState,
  3544. DrugSpec: s.DrugSpec,
  3545. DrugSpecUnit: s.DrugSpecUnit,
  3546. Groupno: s.Groupno,
  3547. RemindType: s.RemindType,
  3548. FrequencyType: s.FrequencyType,
  3549. DayCount: s.DayCount,
  3550. WeekDay: s.WeekDay,
  3551. TemplateId: s.TemplateId,
  3552. Modifier: s.Modifier,
  3553. DrugId: s.DrugId,
  3554. Price: s.Price,
  3555. PrescriptionId: s.PrescriptionId,
  3556. MedListCodg: s.MedListCodg,
  3557. FeedetlSn: s.FeedetlSn,
  3558. Day: s.DayCount,
  3559. ChildDoctorAdvice: nil,
  3560. Drug: models.Drug{},
  3561. Diagnosis: s.Diagnosis,
  3562. Way: s.Way,
  3563. HospApprFlag: s.HospApprFlag,
  3564. LmtUsedFlag: s.LmtUsedFlag,
  3565. HisOrderInfo: models.HisOrderInfo{},
  3566. IsMedicine: s.IsMedicine,
  3567. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3568. Child: nil,
  3569. IsSettle: s.IsSettle,
  3570. IsMobile: s.IsMobile,
  3571. IsSelfDrug: s.IsSelfDrug,
  3572. DrugWayCount: s.DrugWayCount,
  3573. }
  3574. var history_count int64
  3575. var local_count int64
  3576. //查找已经开过的医嘱信息
  3577. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3578. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3579. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3580. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3581. local_count += prescribingNumberSevenTy * drug.MinNumber
  3582. }
  3583. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3584. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3585. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3586. local_count += prescribingNumberSevenTy
  3587. }
  3588. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3589. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3590. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3591. local_count += prescribingNumberSevenTy
  3592. }
  3593. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3594. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3595. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3596. history_count += prescribingNumberSevenTy * drug.MinNumber
  3597. }
  3598. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3599. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3600. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3601. history_count += prescribingNumberSevenTy
  3602. }
  3603. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3604. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3605. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3606. history_count += prescribingNumberSevenTy
  3607. }
  3608. fmt.Println("local_count---------------", local_count)
  3609. fmt.Println("history_count---------------", history_count)
  3610. //如果当前出库数量大于历史出库数量则需要出库
  3611. if local_count > history_count {
  3612. //按最小单位出库
  3613. var cha_count = local_count - history_count
  3614. newadviceInfo.PrescribingNumber = float64(cha_count)
  3615. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3616. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3617. }
  3618. //如果当前出库数量小于历史出库数量则需要退库
  3619. if local_count < history_count {
  3620. var cha_count = history_count - local_count
  3621. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3622. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3623. }
  3624. if local_count == history_count {
  3625. if is_user_total == 0 {
  3626. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3627. }
  3628. }
  3629. }
  3630. //更新字典里面的库存
  3631. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3632. var sum_count int64
  3633. for _, its := range stockInfo {
  3634. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3635. if its.MaxUnit == baseDrug.MaxUnit {
  3636. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3637. }
  3638. sum_count += its.StockMaxNumber + its.StockMinNumber
  3639. }
  3640. //更新基础库存
  3641. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3642. //剩余库存
  3643. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3644. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3645. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3646. //创建医嘱
  3647. service.CreateHisDoctorAdviceOne(&s, tx)
  3648. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3649. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3650. if len(outInfoTwo) > 0 {
  3651. for _, item := range outInfoTwo {
  3652. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3653. }
  3654. }
  3655. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3656. if len(drugAutoDetail) > 0 {
  3657. for _, item := range drugAutoDetail {
  3658. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3659. }
  3660. }
  3661. }
  3662. }
  3663. }
  3664. //记录日志
  3665. byterequest, _ := json.Marshal(s)
  3666. adviceLog := models.XtDoctorAdviceLog{
  3667. UserOrgId: s.UserOrgId,
  3668. PatientId: s.PatientId,
  3669. AdminUserId: adminInfo.AdminUser.Id,
  3670. Module: 1,
  3671. ErrLog: string(byterequest),
  3672. Status: 1,
  3673. Ctime: time.Now().Unix(),
  3674. Mtime: 0,
  3675. Source: "电脑端新建his医嘱",
  3676. RecordDate: s.AdviceDate,
  3677. }
  3678. service.CreateDoctorAdviceLog(adviceLog)
  3679. //存储切片中
  3680. adviceList = append(adviceList, s)
  3681. redis := service.RedisClient()
  3682. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3683. redis.Set(key, "", time.Second)
  3684. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3685. redis.Set(keyOne, "", time.Second)
  3686. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3687. redis.Set(keySeven, "", time.Second)
  3688. var randNum int
  3689. randNum = rand.Intn(1000) + 1000
  3690. //timestamp := time.Now().Unix()
  3691. //tempTime := time.Unix(timestamp, 0)
  3692. //timeFormat := tempTime.Format("20060102150405")
  3693. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3694. //赤峰
  3695. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3696. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3697. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3698. if info.RetailPrice > 0 {
  3699. if s.DeliveryWay == "口服" {
  3700. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3701. s.Price = drug.RetailPrice
  3702. }
  3703. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3704. s.Price = info.RetailPrice
  3705. }
  3706. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3707. s.Price = info.RetailPrice
  3708. }
  3709. }
  3710. }
  3711. }
  3712. service.CreateHisDoctorAdviceOne(&s, tx)
  3713. tx.Commit()
  3714. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3715. redis.Set(keySix, "", time.Second)
  3716. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3717. redis.Set(keyFive, "", time.Second)
  3718. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3719. redis.Set(keyEight, "", time.Second)
  3720. defer redis.Close()
  3721. }
  3722. }
  3723. }
  3724. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3725. projects := items["project"].([]interface{})
  3726. if len(projects) > 0 {
  3727. for _, project := range projects {
  3728. tx := db.Begin()
  3729. // 在函数结束时处理事务回滚
  3730. defer func() {
  3731. if r := recover(); r != nil {
  3732. tx.Rollback()
  3733. }
  3734. }()
  3735. var p models.HisPrescriptionProject
  3736. p.PrescriptionId = tempPrescription.ID
  3737. p.PatientId = patient_id
  3738. p.RecordDate = theTime3.Unix()
  3739. p.Doctor = doctor_id
  3740. p.UserOrgId = adminInfo.CurrentOrgId
  3741. p.HisPatientId = his_patient_id
  3742. p.Status = 1
  3743. p.StartTime = pTime
  3744. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3745. if errcode > 0 {
  3746. tx.Rollback()
  3747. c.ServeFailJSONWithSGJErrorCode(errcode)
  3748. return
  3749. }
  3750. if p.ID == 0 {
  3751. p.IsOut = 2
  3752. }
  3753. if p.ID > 0 {
  3754. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3755. p.IsOut = projectDetail.IsOut
  3756. }
  3757. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3758. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3759. if p.Type == 3 {
  3760. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3761. if p.Price != lastWarehouse.PackingPrice {
  3762. p.Price = lastWarehouse.PackingPrice
  3763. }
  3764. if p.Price == 0 {
  3765. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3766. p.Price = lastWarehouseTwo.PackingPrice
  3767. }
  3768. if p.Unit == "" {
  3769. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3770. p.Unit = goodInfoOne.PackingUnit
  3771. }
  3772. }
  3773. }
  3774. if adminInfo.CurrentOrgId != 10206 {
  3775. if p.Type == 3 {
  3776. //判断耗材库存充不充足
  3777. if p.ID == 0 {
  3778. //查询该耗材是否停用
  3779. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3780. //表示该耗材已经停用,不能保存
  3781. if goodInfoSeven.ID == 0 {
  3782. tx.Rollback()
  3783. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3784. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3785. return
  3786. }
  3787. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3788. if goodInfoOne.SumCount == 0 {
  3789. tx.Rollback()
  3790. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3791. return
  3792. }
  3793. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3794. if len(goodListOne) == 0 {
  3795. tx.Rollback()
  3796. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3797. return
  3798. }
  3799. }
  3800. if p.ID > 0 {
  3801. //查询该耗材是否停用
  3802. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3803. //表示该耗材已经停用,不能保存
  3804. if goodInfoSeven.ID == 0 {
  3805. tx.Rollback()
  3806. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3807. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3808. return
  3809. }
  3810. //查询该耗材今日是否已经出过库
  3811. goodOutList, _ := service.GetGoodWareHouseOutInfoByGood(p.ProjectId, p.RecordDate, p.UserOrgId)
  3812. var his_count int64
  3813. if len(goodOutList) > 0 {
  3814. for _, item := range goodOutList {
  3815. his_count += item.Count
  3816. }
  3817. }
  3818. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3819. //如果当前的处方数量大于 历史出库数量 要判断库存够不够
  3820. if nowCount > his_count {
  3821. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3822. if goodInfoOne.SumCount == 0 {
  3823. tx.Rollback()
  3824. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3825. return
  3826. }
  3827. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3828. if len(goodListOne) == 0 {
  3829. tx.Rollback()
  3830. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3831. return
  3832. }
  3833. }
  3834. if len(goodOutList) == 0 {
  3835. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3836. if goodInfoOne.SumCount == 0 {
  3837. tx.Rollback()
  3838. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3839. return
  3840. }
  3841. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3842. if len(goodListOne) == 0 {
  3843. tx.Rollback()
  3844. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3845. return
  3846. }
  3847. }
  3848. }
  3849. }
  3850. }
  3851. //查询保存耗材出库开关是否打开
  3852. if p.PatientId != 30038 {
  3853. //用机构ID区分
  3854. if adminInfo.CurrentOrgId != 9671 {
  3855. if goodOutConfig.IsOpen == 1 {
  3856. //耗材出库
  3857. if p.Type == 3 {
  3858. //对比当前数据和历史出库数据
  3859. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3860. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3861. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3862. ////针对康德
  3863. //if p.UserOrgId == 10164 || p.UserOrgId == 10402 {
  3864. //
  3865. // //查询耗材的总入库数量
  3866. // warehouseInfo, _ := service.GetAllWarehouseInfo(p.ProjectId, adminInfo.CurrentOrgId)
  3867. //
  3868. // //查询该耗材的总出库数量
  3869. // prescriptionGood, _ := service.GetHisPrescriptionByGoodId(p.ProjectId, adminInfo.CurrentOrgId)
  3870. //
  3871. // var all_good_count int64
  3872. //
  3873. // var prescription_count int64
  3874. // if len(warehouseInfo) > 0 {
  3875. //
  3876. // for _, item := range warehouseInfo {
  3877. // all_good_count += item.WarehousingCount
  3878. // }
  3879. // }
  3880. // if len(prescriptionGood) > 0 {
  3881. // for _, item := range prescriptionGood {
  3882. //
  3883. // hisCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3884. // prescription_count += hisCount
  3885. // }
  3886. // }
  3887. //
  3888. // //fmt.Println("prescription_count-------------------------", prescription_count)
  3889. // //fmt.Println("nowCount-------------------------", nowCount)
  3890. // //fmt.Println("all_good_count-------------------------", all_good_count)
  3891. //
  3892. // if prescription_count+nowCount > all_good_count {
  3893. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3894. // tx.Rollback()
  3895. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3896. // return
  3897. // }
  3898. //}
  3899. //如果当前处方数量大于历史数据,则需要出库
  3900. if nowCount > historyCount {
  3901. var cha_count int64
  3902. cha_count = nowCount - historyCount
  3903. timeStr := time.Now().Format("2006-01-02")
  3904. timeArr := strings.Split(timeStr, "-")
  3905. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3906. total = total + 1
  3907. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3908. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3909. number = number + total
  3910. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3911. operation_time := time.Now().Unix()
  3912. creater := c.GetAdminUserInfo().AdminUser.Id
  3913. recordDateStr := time.Now().Format("2006-01-02")
  3914. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3915. nowtime := recordDate.Unix()
  3916. warehouseOut := models.WarehouseOut{
  3917. WarehouseOutOrderNumber: warehousing_out_order,
  3918. OperationTime: operation_time,
  3919. OrgId: adminInfo.CurrentOrgId,
  3920. Creater: creater,
  3921. Ctime: time.Now().Unix(),
  3922. Status: 1,
  3923. WarehouseOutTime: nowtime,
  3924. Type: 1,
  3925. StorehouseId: storeConfig.StorehouseOutInfo,
  3926. IsCheck: 1,
  3927. IsSys: 1,
  3928. }
  3929. //查询是否生成出库单
  3930. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3931. if out.ID == 0 {
  3932. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3933. }
  3934. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3935. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3936. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3937. dialyPrepareOne := models.DialysisBeforePrepare{
  3938. GoodTypeId: goodObj.GoodTypeId,
  3939. GoodId: p.ProjectId,
  3940. PatientId: p.PatientId,
  3941. RecordDate: p.RecordDate,
  3942. UserOrgId: adminInfo.CurrentOrgId,
  3943. Count: cha_count,
  3944. Ctime: time.Now().Unix(),
  3945. Creater: creater,
  3946. Status: 1,
  3947. StorehouseId: houseConfig.StorehouseOutInfo,
  3948. ProjectId: p.ID,
  3949. }
  3950. //出库
  3951. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3952. }
  3953. //如果当前处方数量小于历史数据,怎需要退库
  3954. if nowCount < historyCount {
  3955. var cha_count int64
  3956. cha_count = historyCount - nowCount
  3957. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3958. creater := c.GetAdminUserInfo().AdminUser.Id
  3959. newPrescriptionProject := &models.HisPrescriptionProject{
  3960. ID: p.ID,
  3961. ProjectId: p.ProjectId,
  3962. Price: p.Price,
  3963. UserOrgId: p.UserOrgId,
  3964. Status: 1,
  3965. Ctime: time.Now().Unix(),
  3966. Mtime: time.Now().Unix(),
  3967. PatientId: p.PatientId,
  3968. HisPatientId: p.HisPatientId,
  3969. RecordDate: p.RecordDate,
  3970. PrescriptionId: p.PrescriptionId,
  3971. Count: p.Count,
  3972. FeedetlSn: p.FeedetlSn,
  3973. MedListCodg: p.MedListCodg,
  3974. SingleDose: p.SingleDose,
  3975. DeliveryWay: p.DeliveryWay,
  3976. ExecutionFrequency: p.ExecutionFrequency,
  3977. Day: p.Day,
  3978. HisProject: models.HisProject{},
  3979. GoodInfo: models.GoodInfo{},
  3980. Remark: p.Remark,
  3981. Unit: p.Unit,
  3982. Type: p.Type,
  3983. Doctor: p.Doctor,
  3984. ExecutionTime: p.ExecutionTime,
  3985. ExecutionStaff: p.ExecutionStaff,
  3986. ExecutionState: p.ExecutionState,
  3987. CheckTime: p.CheckTime,
  3988. CheckState: p.CheckState,
  3989. Checker: p.Checker,
  3990. StartTime: p.StartTime,
  3991. TeamId: p.TeamId,
  3992. XtHisProjectTeam: models.XtHisProjectTeam{},
  3993. FrequencyType: p.FrequencyType,
  3994. DayCount: p.DayCount,
  3995. WeekDay: p.WeekDay,
  3996. IsCheckTeam: p.IsCheckTeam,
  3997. HisOrderInfo: models.HisOrderInfo{},
  3998. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3999. IsOut: p.IsOut,
  4000. YbSyncStatus: p.YbSyncStatus,
  4001. }
  4002. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4003. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4004. }
  4005. if nowCount == historyCount {
  4006. if historyCount == 0 {
  4007. recordDateStr := time.Now().Format("2006-01-02")
  4008. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4009. nowtime := recordDate.Unix()
  4010. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4011. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4012. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4013. creater := c.GetAdminUserInfo().AdminUser.Id
  4014. dialyPrepareOne := models.DialysisBeforePrepare{
  4015. GoodTypeId: goodObj.GoodTypeId,
  4016. GoodId: p.ProjectId,
  4017. PatientId: p.PatientId,
  4018. RecordDate: p.RecordDate,
  4019. UserOrgId: adminInfo.CurrentOrgId,
  4020. Count: nowCount,
  4021. Ctime: time.Now().Unix(),
  4022. Creater: creater,
  4023. Status: 1,
  4024. StorehouseId: houseConfig.StorehouseOutInfo,
  4025. ProjectId: p.ID,
  4026. }
  4027. //出库
  4028. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4029. }
  4030. }
  4031. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4032. //查询历史出库数据
  4033. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4034. var out_count_five int64
  4035. for _, item := range flowGood {
  4036. out_count_five += item.Count
  4037. }
  4038. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4039. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4040. if out_count_five != parseIntCount {
  4041. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4042. detail := models.AutomaticReduceDetail{
  4043. WarehouseOutId: 0,
  4044. WarehouseOutOrderNumber: "",
  4045. PatientId: p.PatientId,
  4046. Ctime: time.Now().Unix(),
  4047. Mtime: 0,
  4048. Status: 1,
  4049. RecordTime: p.RecordDate,
  4050. OrgId: p.UserOrgId,
  4051. GoodId: p.ProjectId,
  4052. GoodTypeId: 0,
  4053. Count: parseIntCount,
  4054. Type: 0,
  4055. ProjectId: lastHisProject.ID,
  4056. StorehouseId: 0,
  4057. }
  4058. service.CreateNewAutoDetail(detail, tx)
  4059. }
  4060. // //查询耗材最后一次出库记录
  4061. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4062. // //查询默认出库仓库库存
  4063. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4064. // if len(wareOut) > 0 {
  4065. //
  4066. // for _, it := range wareOut {
  4067. // //回退库存
  4068. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4069. //
  4070. // //删除出库记录
  4071. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4072. //
  4073. // }
  4074. // }
  4075. //
  4076. // timeStr := time.Now().Format("2006-01-02")
  4077. // timeArr := strings.Split(timeStr, "-")
  4078. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4079. //
  4080. // total = total + 1
  4081. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4082. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4083. // number = number + total
  4084. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4085. //
  4086. // operation_time := time.Now().Unix()
  4087. // creater := c.GetAdminUserInfo().AdminUser.Id
  4088. //
  4089. // recordDateStr := time.Now().Format("2006-01-02")
  4090. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4091. // nowtime := recordDate.Unix()
  4092. // warehouseOut := models.WarehouseOut{
  4093. // WarehouseOutOrderNumber: warehousing_out_order,
  4094. // OperationTime: operation_time,
  4095. // OrgId: adminInfo.CurrentOrgId,
  4096. // Creater: creater,
  4097. // Ctime: time.Now().Unix(),
  4098. // Status: 1,
  4099. // WarehouseOutTime: nowtime,
  4100. // Type: 1,
  4101. // StorehouseId: storeConfig.StorehouseOutInfo,
  4102. // IsCheck: 1,
  4103. // IsSys: 1,
  4104. // }
  4105. // //查询是否生成出库单
  4106. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4107. // if out.ID == 0 {
  4108. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4109. // }
  4110. //
  4111. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4112. //
  4113. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4114. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4115. //
  4116. // dialyPrepareOne := models.DialysisBeforePrepare{
  4117. // GoodTypeId: goodObj.GoodTypeId,
  4118. // GoodId: p.ProjectId,
  4119. // PatientId: p.PatientId,
  4120. // RecordDate: p.RecordDate,
  4121. // UserOrgId: adminInfo.CurrentOrgId,
  4122. // Count: parseIntCount,
  4123. // Ctime: time.Now().Unix(),
  4124. // Creater: creater,
  4125. // Status: 1,
  4126. // StorehouseId: houseConfig.StorehouseOutInfo,
  4127. // ProjectId: lastHisProject.ID,
  4128. // }
  4129. // //判断是否是零用耗材(非零用)
  4130. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4131. //
  4132. // //查询历史出库数据
  4133. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4134. // var out_count int64
  4135. // for _, item := range flowGood {
  4136. // out_count += item.Count
  4137. // }
  4138. // //如果历史数和当前数据不想等才进行退库出库
  4139. // if out_count != parseIntCount {
  4140. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4141. //
  4142. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4143. // detail := models.AutomaticReduceDetail{
  4144. // WarehouseOutId: 0,
  4145. // WarehouseOutOrderNumber: "",
  4146. // PatientId: p.PatientId,
  4147. // Ctime: time.Now().Unix(),
  4148. // Mtime: 0,
  4149. // Status: 1,
  4150. // RecordTime: p.RecordDate,
  4151. // OrgId: p.UserOrgId,
  4152. // GoodId: p.ProjectId,
  4153. // GoodTypeId: 0,
  4154. // Count: parseIntCount,
  4155. // Type: 0,
  4156. // ProjectId: lastHisProject.ID,
  4157. // StorehouseId: 0,
  4158. // }
  4159. //
  4160. // service.CreateNewAutoDetail(detail, tx)
  4161. //
  4162. // //查询剩余库存
  4163. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4164. // var sum_count int64
  4165. // for _, item := range goodList {
  4166. // sum_count += item.StockCount
  4167. // }
  4168. //
  4169. // //更新剩余库存
  4170. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4171. //
  4172. // //耗材
  4173. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4174. //
  4175. // }
  4176. // //判断是否是零用耗材(零用但是是出库耗材)
  4177. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4178. //
  4179. // //查询历史出库数据
  4180. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4181. // var out_count int64
  4182. // for _, item := range flowGood {
  4183. // out_count += item.Count
  4184. // }
  4185. // //如果历史数和当前数据不想等才进行退库出库
  4186. // if out_count != parseIntCount {
  4187. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4188. //
  4189. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4190. // detail := models.AutomaticReduceDetail{
  4191. // WarehouseOutId: 0,
  4192. // WarehouseOutOrderNumber: "",
  4193. // PatientId: p.PatientId,
  4194. // Ctime: time.Now().Unix(),
  4195. // Mtime: 0,
  4196. // Status: 1,
  4197. // RecordTime: p.RecordDate,
  4198. // OrgId: p.UserOrgId,
  4199. // GoodId: p.ProjectId,
  4200. // GoodTypeId: 0,
  4201. // Count: parseIntCount,
  4202. // Type: 0,
  4203. // ProjectId: p.ID,
  4204. // StorehouseId: 0,
  4205. // }
  4206. //
  4207. // service.CreateNewAutoDetail(detail, tx)
  4208. //
  4209. // //查询剩余库存
  4210. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4211. // var sum_count int64
  4212. // for _, item := range goodList {
  4213. // sum_count += item.StockCount
  4214. // }
  4215. //
  4216. // //更新剩余库存
  4217. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4218. //
  4219. // //耗材
  4220. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4221. // }
  4222. //
  4223. // }
  4224. //
  4225. // }
  4226. //
  4227. //}
  4228. //记录日志
  4229. byterequest, _ := json.Marshal(p)
  4230. adviceLog := models.XtDoctorAdviceLog{
  4231. UserOrgId: p.UserOrgId,
  4232. PatientId: p.PatientId,
  4233. AdminUserId: adminInfo.AdminUser.Id,
  4234. Module: 1,
  4235. ErrLog: string(byterequest),
  4236. Status: 1,
  4237. Ctime: time.Now().Unix(),
  4238. Mtime: 0,
  4239. Source: "电脑端新建his项目",
  4240. RecordDate: p.RecordDate,
  4241. }
  4242. service.CreateDoctorAdviceLog(adviceLog)
  4243. projectList = append(projectList, p)
  4244. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4245. //新增或者编辑项目,修改对应的标签数据
  4246. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4247. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4248. var label models.HisLabelPrintInfo
  4249. project, _ := service.GetProjectDetail(p.ProjectId)
  4250. if project.CostClassify == 3 { //类别为检验检查
  4251. if p.TeamId > 0 { //检验检查组套
  4252. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4253. if tempLabel.ID == 0 {
  4254. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4255. label.Number = tempPrescription.PrescriptionNumber
  4256. label.ProjectId = project.ID
  4257. label.Status = 1
  4258. label.IsPrint = 2
  4259. label.DoctorId = info.DoctorId
  4260. label.UserOrgId = p.UserOrgId
  4261. label.PatientId = patient_id
  4262. label.RecordDate = recordDateTime
  4263. label.Ctime = time.Now().Unix()
  4264. label.Mtime = time.Now().Unix()
  4265. label.ItemId = p.TeamId
  4266. label.FeedetlSn = p.FeedetlSn
  4267. label.PProjectId = p.ID
  4268. label.ProjectName = team.ProjectTeam
  4269. label.PatientName = patient.Name
  4270. service.CreateNewHisLabelRecord(&label, tx)
  4271. }
  4272. } else { //单条检验检查项目
  4273. label.Number = tempPrescription.PrescriptionNumber
  4274. label.ProjectId = project.ID
  4275. label.Status = 1
  4276. label.DoctorId = info.DoctorId
  4277. label.UserOrgId = p.UserOrgId
  4278. label.PatientId = patient_id
  4279. label.RecordDate = recordDateTime
  4280. label.IsPrint = 2
  4281. label.Ctime = time.Now().Unix()
  4282. label.Mtime = time.Now().Unix()
  4283. label.FeedetlSn = p.FeedetlSn
  4284. label.PProjectId = p.ID
  4285. label.ItemId = p.TeamId
  4286. label.ProjectName = project.ProjectName
  4287. label.PatientName = patient.Name
  4288. service.CreateNewHisLabelRecord(&label, tx)
  4289. }
  4290. }
  4291. }
  4292. }
  4293. }
  4294. }
  4295. }
  4296. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4297. //
  4298. // //耗材出库
  4299. // if p.Type == 3 {
  4300. //
  4301. // //对比当前数据和历史出库数据
  4302. //
  4303. // historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4304. //
  4305. // historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4306. //
  4307. // nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4308. //
  4309. // //如果当前处方数量大于历史数据,则需要出库
  4310. // if nowCount > historyCount {
  4311. //
  4312. // var cha_count int64
  4313. // cha_count = nowCount - historyCount
  4314. //
  4315. // timeStr := time.Now().Format("2006-01-02")
  4316. // timeArr := strings.Split(timeStr, "-")
  4317. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4318. //
  4319. // total = total + 1
  4320. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4321. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4322. // number = number + total
  4323. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4324. //
  4325. // operation_time := time.Now().Unix()
  4326. // creater := c.GetAdminUserInfo().AdminUser.Id
  4327. //
  4328. // recordDateStr := time.Now().Format("2006-01-02")
  4329. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4330. // nowtime := recordDate.Unix()
  4331. // warehouseOut := models.WarehouseOut{
  4332. // WarehouseOutOrderNumber: warehousing_out_order,
  4333. // OperationTime: operation_time,
  4334. // OrgId: adminInfo.CurrentOrgId,
  4335. // Creater: creater,
  4336. // Ctime: time.Now().Unix(),
  4337. // Status: 1,
  4338. // WarehouseOutTime: nowtime,
  4339. // Type: 1,
  4340. // StorehouseId: storeConfig.StorehouseOutInfo,
  4341. // IsCheck: 1,
  4342. // IsSys: 1,
  4343. // }
  4344. // //查询是否生成出库单
  4345. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4346. // if out.ID == 0 {
  4347. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4348. // }
  4349. //
  4350. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4351. //
  4352. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4353. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4354. //
  4355. // dialyPrepareOne := models.DialysisBeforePrepare{
  4356. // GoodTypeId: goodObj.GoodTypeId,
  4357. // GoodId: p.ProjectId,
  4358. // PatientId: p.PatientId,
  4359. // RecordDate: p.RecordDate,
  4360. // UserOrgId: adminInfo.CurrentOrgId,
  4361. // Count: cha_count,
  4362. // Ctime: time.Now().Unix(),
  4363. // Creater: creater,
  4364. // Status: 1,
  4365. // StorehouseId: houseConfig.StorehouseOutInfo,
  4366. // ProjectId: p.ID,
  4367. // }
  4368. // //出库
  4369. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4370. //
  4371. // }
  4372. //
  4373. // //如果当前处方数量小于历史数据,怎需要退库
  4374. // if nowCount < historyCount {
  4375. //
  4376. // var cha_count int64
  4377. // cha_count = historyCount - nowCount
  4378. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4379. // creater := c.GetAdminUserInfo().AdminUser.Id
  4380. //
  4381. // newPrescriptionProject := &models.HisPrescriptionProject{
  4382. // ID: p.ID,
  4383. // ProjectId: p.ProjectId,
  4384. // Price: p.Price,
  4385. // UserOrgId: p.UserOrgId,
  4386. // Status: 1,
  4387. // Ctime: time.Now().Unix(),
  4388. // Mtime: time.Now().Unix(),
  4389. // PatientId: p.PatientId,
  4390. // HisPatientId: p.HisPatientId,
  4391. // RecordDate: p.RecordDate,
  4392. // PrescriptionId: p.PrescriptionId,
  4393. // Count: p.Count,
  4394. // FeedetlSn: p.FeedetlSn,
  4395. // MedListCodg: p.MedListCodg,
  4396. // SingleDose: p.SingleDose,
  4397. // DeliveryWay: p.DeliveryWay,
  4398. // ExecutionFrequency: p.ExecutionFrequency,
  4399. // Day: p.Day,
  4400. // HisProject: models.HisProject{},
  4401. // GoodInfo: models.GoodInfo{},
  4402. // Remark: p.Remark,
  4403. // Unit: p.Unit,
  4404. // Type: p.Type,
  4405. // Doctor: p.Doctor,
  4406. // ExecutionTime: p.ExecutionTime,
  4407. // ExecutionStaff: p.ExecutionStaff,
  4408. // ExecutionState: p.ExecutionState,
  4409. // CheckTime: p.CheckTime,
  4410. // CheckState: p.CheckState,
  4411. // Checker: p.Checker,
  4412. // StartTime: p.StartTime,
  4413. // TeamId: p.TeamId,
  4414. // XtHisProjectTeam: models.XtHisProjectTeam{},
  4415. // FrequencyType: p.FrequencyType,
  4416. // DayCount: p.DayCount,
  4417. // WeekDay: p.WeekDay,
  4418. // IsCheckTeam: p.IsCheckTeam,
  4419. // HisOrderInfo: models.HisOrderInfo{},
  4420. // ExecutionFrequencyId: p.ExecutionFrequencyId,
  4421. // IsOut: p.IsOut,
  4422. // YbSyncStatus: p.YbSyncStatus,
  4423. // }
  4424. //
  4425. // service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4426. //
  4427. // service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4428. //
  4429. // }
  4430. //
  4431. // if nowCount == historyCount {
  4432. // if historyCount == 0 {
  4433. // recordDateStr := time.Now().Format("2006-01-02")
  4434. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4435. // nowtime := recordDate.Unix()
  4436. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4437. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4438. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4439. // creater := c.GetAdminUserInfo().AdminUser.Id
  4440. // dialyPrepareOne := models.DialysisBeforePrepare{
  4441. // GoodTypeId: goodObj.GoodTypeId,
  4442. // GoodId: p.ProjectId,
  4443. // PatientId: p.PatientId,
  4444. // RecordDate: p.RecordDate,
  4445. // UserOrgId: adminInfo.CurrentOrgId,
  4446. // Count: nowCount,
  4447. // Ctime: time.Now().Unix(),
  4448. // Creater: creater,
  4449. // Status: 1,
  4450. // StorehouseId: houseConfig.StorehouseOutInfo,
  4451. // ProjectId: p.ID,
  4452. // }
  4453. // //出库
  4454. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4455. // }
  4456. // }
  4457. //
  4458. // lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4459. // //查询历史出库数据
  4460. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4461. //
  4462. // var out_count_five int64
  4463. // for _, item := range flowGood {
  4464. // out_count_five += item.Count
  4465. // }
  4466. // parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4467. //
  4468. // //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4469. // if out_count_five != parseIntCount {
  4470. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4471. // detail := models.AutomaticReduceDetail{
  4472. // WarehouseOutId: 0,
  4473. // WarehouseOutOrderNumber: "",
  4474. // PatientId: p.PatientId,
  4475. // Ctime: time.Now().Unix(),
  4476. // Mtime: 0,
  4477. // Status: 1,
  4478. // RecordTime: p.RecordDate,
  4479. // OrgId: p.UserOrgId,
  4480. // GoodId: p.ProjectId,
  4481. // GoodTypeId: 0,
  4482. // Count: parseIntCount,
  4483. // Type: 0,
  4484. // ProjectId: lastHisProject.ID,
  4485. // StorehouseId: 0,
  4486. // }
  4487. //
  4488. // service.CreateNewAutoDetail(detail, tx)
  4489. // }
  4490. // // //查询耗材最后一次出库记录
  4491. // // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4492. // // //查询默认出库仓库库存
  4493. // // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4494. // // if len(wareOut) > 0 {
  4495. // //
  4496. // // for _, it := range wareOut {
  4497. // // //回退库存
  4498. // // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4499. // //
  4500. // // //删除出库记录
  4501. // // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4502. // //
  4503. // // }
  4504. // // }
  4505. // //
  4506. // // timeStr := time.Now().Format("2006-01-02")
  4507. // // timeArr := strings.Split(timeStr, "-")
  4508. // // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4509. // //
  4510. // // total = total + 1
  4511. // // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4512. // // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4513. // // number = number + total
  4514. // // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4515. // //
  4516. // // operation_time := time.Now().Unix()
  4517. // // creater := c.GetAdminUserInfo().AdminUser.Id
  4518. // //
  4519. // // recordDateStr := time.Now().Format("2006-01-02")
  4520. // // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4521. // // nowtime := recordDate.Unix()
  4522. // // warehouseOut := models.WarehouseOut{
  4523. // // WarehouseOutOrderNumber: warehousing_out_order,
  4524. // // OperationTime: operation_time,
  4525. // // OrgId: adminInfo.CurrentOrgId,
  4526. // // Creater: creater,
  4527. // // Ctime: time.Now().Unix(),
  4528. // // Status: 1,
  4529. // // WarehouseOutTime: nowtime,
  4530. // // Type: 1,
  4531. // // StorehouseId: storeConfig.StorehouseOutInfo,
  4532. // // IsCheck: 1,
  4533. // // IsSys: 1,
  4534. // // }
  4535. // // //查询是否生成出库单
  4536. // // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4537. // // if out.ID == 0 {
  4538. // // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4539. // // }
  4540. // //
  4541. // // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4542. // //
  4543. // // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4544. // // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4545. // //
  4546. // // dialyPrepareOne := models.DialysisBeforePrepare{
  4547. // // GoodTypeId: goodObj.GoodTypeId,
  4548. // // GoodId: p.ProjectId,
  4549. // // PatientId: p.PatientId,
  4550. // // RecordDate: p.RecordDate,
  4551. // // UserOrgId: adminInfo.CurrentOrgId,
  4552. // // Count: parseIntCount,
  4553. // // Ctime: time.Now().Unix(),
  4554. // // Creater: creater,
  4555. // // Status: 1,
  4556. // // StorehouseId: houseConfig.StorehouseOutInfo,
  4557. // // ProjectId: lastHisProject.ID,
  4558. // // }
  4559. // // //判断是否是零用耗材(非零用)
  4560. // // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4561. // //
  4562. // // //查询历史出库数据
  4563. // // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4564. // // var out_count int64
  4565. // // for _, item := range flowGood {
  4566. // // out_count += item.Count
  4567. // // }
  4568. // // //如果历史数和当前数据不想等才进行退库出库
  4569. // // if out_count != parseIntCount {
  4570. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4571. // //
  4572. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4573. // // detail := models.AutomaticReduceDetail{
  4574. // // WarehouseOutId: 0,
  4575. // // WarehouseOutOrderNumber: "",
  4576. // // PatientId: p.PatientId,
  4577. // // Ctime: time.Now().Unix(),
  4578. // // Mtime: 0,
  4579. // // Status: 1,
  4580. // // RecordTime: p.RecordDate,
  4581. // // OrgId: p.UserOrgId,
  4582. // // GoodId: p.ProjectId,
  4583. // // GoodTypeId: 0,
  4584. // // Count: parseIntCount,
  4585. // // Type: 0,
  4586. // // ProjectId: lastHisProject.ID,
  4587. // // StorehouseId: 0,
  4588. // // }
  4589. // //
  4590. // // service.CreateNewAutoDetail(detail, tx)
  4591. // //
  4592. // // //查询剩余库存
  4593. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4594. // // var sum_count int64
  4595. // // for _, item := range goodList {
  4596. // // sum_count += item.StockCount
  4597. // // }
  4598. // //
  4599. // // //更新剩余库存
  4600. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4601. // //
  4602. // // //耗材
  4603. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4604. // //
  4605. // // }
  4606. // // //判断是否是零用耗材(零用但是是出库耗材)
  4607. // // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4608. // //
  4609. // // //查询历史出库数据
  4610. // // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4611. // // var out_count int64
  4612. // // for _, item := range flowGood {
  4613. // // out_count += item.Count
  4614. // // }
  4615. // // //如果历史数和当前数据不想等才进行退库出库
  4616. // // if out_count != parseIntCount {
  4617. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4618. // //
  4619. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4620. // // detail := models.AutomaticReduceDetail{
  4621. // // WarehouseOutId: 0,
  4622. // // WarehouseOutOrderNumber: "",
  4623. // // PatientId: p.PatientId,
  4624. // // Ctime: time.Now().Unix(),
  4625. // // Mtime: 0,
  4626. // // Status: 1,
  4627. // // RecordTime: p.RecordDate,
  4628. // // OrgId: p.UserOrgId,
  4629. // // GoodId: p.ProjectId,
  4630. // // GoodTypeId: 0,
  4631. // // Count: parseIntCount,
  4632. // // Type: 0,
  4633. // // ProjectId: p.ID,
  4634. // // StorehouseId: 0,
  4635. // // }
  4636. // //
  4637. // // service.CreateNewAutoDetail(detail, tx)
  4638. // //
  4639. // // //查询剩余库存
  4640. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4641. // // var sum_count int64
  4642. // // for _, item := range goodList {
  4643. // // sum_count += item.StockCount
  4644. // // }
  4645. // //
  4646. // // //更新剩余库存
  4647. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4648. // //
  4649. // // //耗材
  4650. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4651. // // }
  4652. // //
  4653. // // }
  4654. // //
  4655. // // }
  4656. // //
  4657. // //}
  4658. //
  4659. // //记录日志
  4660. // byterequest, _ := json.Marshal(p)
  4661. // adviceLog := models.XtDoctorAdviceLog{
  4662. // UserOrgId: p.UserOrgId,
  4663. // PatientId: p.PatientId,
  4664. // AdminUserId: adminInfo.AdminUser.Id,
  4665. // Module: 1,
  4666. // ErrLog: string(byterequest),
  4667. // Status: 1,
  4668. // Ctime: time.Now().Unix(),
  4669. // Mtime: 0,
  4670. // Source: "电脑端新建his项目",
  4671. // RecordDate: p.RecordDate,
  4672. // }
  4673. // service.CreateDoctorAdviceLog(adviceLog)
  4674. //
  4675. // projectList = append(projectList, p)
  4676. //
  4677. // if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4678. // //新增或者编辑项目,修改对应的标签数据
  4679. // labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4680. // if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4681. // var label models.HisLabelPrintInfo
  4682. // project, _ := service.GetProjectDetail(p.ProjectId)
  4683. // if project.CostClassify == 3 { //类别为检验检查
  4684. // if p.TeamId > 0 { //检验检查组套
  4685. // tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4686. // if tempLabel.ID == 0 {
  4687. // team, _ := service.GetProjectTeamDetail(p.TeamId)
  4688. // label.Number = tempPrescription.PrescriptionNumber
  4689. // label.ProjectId = project.ID
  4690. // label.Status = 1
  4691. // label.IsPrint = 2
  4692. // label.DoctorId = info.DoctorId
  4693. // label.UserOrgId = p.UserOrgId
  4694. // label.PatientId = patient_id
  4695. // label.RecordDate = recordDateTime
  4696. // label.Ctime = time.Now().Unix()
  4697. // label.Mtime = time.Now().Unix()
  4698. // label.ItemId = p.TeamId
  4699. // label.FeedetlSn = p.FeedetlSn
  4700. // label.PProjectId = p.ID
  4701. // label.ProjectName = team.ProjectTeam
  4702. // label.PatientName = patient.Name
  4703. // service.CreateNewHisLabelRecord(&label, tx)
  4704. // }
  4705. // } else { //单条检验检查项目
  4706. // label.Number = tempPrescription.PrescriptionNumber
  4707. // label.ProjectId = project.ID
  4708. // label.Status = 1
  4709. // label.DoctorId = info.DoctorId
  4710. // label.UserOrgId = p.UserOrgId
  4711. // label.PatientId = patient_id
  4712. // label.RecordDate = recordDateTime
  4713. // label.IsPrint = 2
  4714. // label.Ctime = time.Now().Unix()
  4715. // label.Mtime = time.Now().Unix()
  4716. // label.FeedetlSn = p.FeedetlSn
  4717. // label.PProjectId = p.ID
  4718. // label.ItemId = p.TeamId
  4719. // label.ProjectName = project.ProjectName
  4720. // label.PatientName = patient.Name
  4721. // service.CreateNewHisLabelRecord(&label, tx)
  4722. // }
  4723. // }
  4724. // }
  4725. // }
  4726. //
  4727. // }
  4728. //}
  4729. }
  4730. //插入检验数据
  4731. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4732. //新增或者编辑项目,修改对应的标签数据
  4733. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4734. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4735. var label models.HisLabelPrintInfo
  4736. project, _ := service.GetProjectDetail(p.ProjectId)
  4737. if project.CostClassify == 3 { //类别为检验检查
  4738. if p.TeamId > 0 { //检验检查组套
  4739. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4740. if tempLabel.ID == 0 {
  4741. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4742. label.Number = tempPrescription.PrescriptionNumber
  4743. label.ProjectId = project.ID
  4744. label.Status = 1
  4745. label.IsPrint = 2
  4746. label.DoctorId = info.DoctorId
  4747. label.UserOrgId = p.UserOrgId
  4748. label.PatientId = patient_id
  4749. label.RecordDate = recordDateTime
  4750. label.Ctime = time.Now().Unix()
  4751. label.Mtime = time.Now().Unix()
  4752. label.ItemId = p.TeamId
  4753. label.FeedetlSn = p.FeedetlSn
  4754. label.PProjectId = p.ID
  4755. label.ProjectName = team.ProjectTeam
  4756. label.PatientName = patient.Name
  4757. service.CreateHisLabelRecord(&label)
  4758. }
  4759. } else { //单条检验检查项目
  4760. label.Number = tempPrescription.PrescriptionNumber
  4761. label.ProjectId = project.ID
  4762. label.Status = 1
  4763. label.DoctorId = info.DoctorId
  4764. label.UserOrgId = p.UserOrgId
  4765. label.PatientId = patient_id
  4766. label.RecordDate = recordDateTime
  4767. label.IsPrint = 2
  4768. label.Ctime = time.Now().Unix()
  4769. label.Mtime = time.Now().Unix()
  4770. label.FeedetlSn = p.FeedetlSn
  4771. label.PProjectId = p.ID
  4772. label.ItemId = p.TeamId
  4773. label.ProjectName = project.ProjectName
  4774. label.PatientName = patient.Name
  4775. service.CreateHisLabelRecord(&label)
  4776. }
  4777. }
  4778. }
  4779. }
  4780. service.CreateNewHisProjectTwo(&p, tx)
  4781. var randNum int
  4782. randNum = rand.Intn(1000) + 1000
  4783. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4784. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4785. if goodBase.ID > 0 {
  4786. tx.Rollback()
  4787. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4788. return
  4789. }
  4790. service.CreateNewHisProjectTwo(&p, tx)
  4791. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4792. //查询剩余库存
  4793. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4794. var sum_count int64
  4795. for _, item := range goodList {
  4796. sum_count += item.StockCount
  4797. }
  4798. //更新剩余库存
  4799. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4800. //耗材
  4801. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4802. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4803. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4804. if len(outInfoTwo) > 0 {
  4805. for _, item := range outInfoTwo {
  4806. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4807. }
  4808. }
  4809. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4810. if len(drugAutoDetail) > 0 {
  4811. for _, item := range drugAutoDetail {
  4812. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4813. }
  4814. }
  4815. tx.Commit()
  4816. }
  4817. }
  4818. }
  4819. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4820. // addition := items["addition"].([]interface{})
  4821. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4822. // ctime := time.Now().Unix()
  4823. // mtime := ctime
  4824. // if len(addition) > 0 {
  4825. // for _, item := range addition {
  4826. // var s models.HisAdditionalCharge
  4827. // s.PrescriptionId = tempPrescription.ID
  4828. // s.Status = 1
  4829. // s.UserOrgId = adminInfo.CurrentOrgId
  4830. // s.RecordDate = recordDateTime
  4831. // s.CreatedTime = ctime
  4832. // s.UpdatedTime = mtime
  4833. // s.PatientId = patient_id
  4834. // s.HisPatientId = his_patient_id
  4835. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4836. // if errcode > 0 {
  4837. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4838. // return
  4839. // }
  4840. // service.CreateAdditionalCharge(&s)
  4841. // var randNum int
  4842. // randNum = rand.Intn(10000) + 1000
  4843. // timestamp := time.Now().Unix()
  4844. // tempTime := time.Unix(timestamp, 0)
  4845. // timeFormat := tempTime.Format("20060102150405")
  4846. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4847. // service.CreateAdditionalCharge(&s)
  4848. //
  4849. // }
  4850. // }
  4851. //}
  4852. }
  4853. }
  4854. }
  4855. tx.Commit()
  4856. if err == nil {
  4857. c.ServeSuccessJSON(map[string]interface{}{
  4858. "msg": "保存成功",
  4859. })
  4860. return
  4861. } else {
  4862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4863. return
  4864. }
  4865. } else {
  4866. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4867. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4868. var tempPrescription *models.HisPrescription
  4869. if len(prescriptions) > 0 {
  4870. for _, item := range prescriptions {
  4871. items := item.(map[string]interface{})
  4872. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4873. utils.ErrorLog("id")
  4874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4875. return
  4876. }
  4877. id := int64(items["id"].(float64))
  4878. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4879. tempPrescription = &new_prescription
  4880. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4881. utils.ErrorLog("type")
  4882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4883. return
  4884. }
  4885. types := int64(items["type"].(float64))
  4886. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4887. utils.ErrorLog("med_type")
  4888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4889. return
  4890. }
  4891. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4892. if med_type == "0" {
  4893. med_type = "14"
  4894. }
  4895. //if order_status == 0 {
  4896. // order_status = 1
  4897. //}
  4898. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4899. // utils.ErrorLog("diagnoses")
  4900. //}
  4901. diagnoses, _ := items["diagnoses"].(string)
  4902. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4903. utils.ErrorLog("pre_time")
  4904. }
  4905. preTime, _ := items["pre_time"].(string)
  4906. timeLayout := "2006-01-02"
  4907. loc, _ := time.LoadLocation("Local")
  4908. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4909. //result := strings.Split(preTime, " ")
  4910. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4911. if err != nil {
  4912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4913. return
  4914. }
  4915. pTime := theTime2.Unix()
  4916. ctime := time.Now().Unix()
  4917. if tempPrescription.ID == 0 {
  4918. prescription := &models.HisPrescription{
  4919. ID: 0,
  4920. PatientId: patient_id,
  4921. UserOrgId: adminInfo.CurrentOrgId,
  4922. RecordDate: recordDateTime,
  4923. Ctime: ctime,
  4924. Mtime: ctime,
  4925. Type: types,
  4926. Modifier: adminInfo.AdminUser.Id,
  4927. Creator: adminInfo.AdminUser.Id,
  4928. Status: 1,
  4929. Doctor: role.UserName,
  4930. HisPatientId: his_patient_id,
  4931. OrderStatus: 1,
  4932. BatchNumber: "",
  4933. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4934. PreTime: pTime,
  4935. PType: p_type,
  4936. MedType: med_type,
  4937. Diagnose: diagnoses,
  4938. }
  4939. tempPrescription = prescription
  4940. service.SaveHisPrescription(tempPrescription)
  4941. redis := service.RedisClient()
  4942. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4943. redis.Set(key, "", time.Second)
  4944. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4945. redis.Set(keyOne, "", time.Second)
  4946. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4947. redis.Set(keySeven, "", time.Second)
  4948. defer redis.Close()
  4949. } else {
  4950. tempPrescription.ID = id
  4951. tempPrescription.Type = types
  4952. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4953. tempPrescription.Mtime = time.Now().Unix()
  4954. tempPrescription.Doctor = role.UserName
  4955. //tempPrescription.OrderStatus = order_status
  4956. tempPrescription.PreTime = pTime
  4957. tempPrescription.MedType = med_type
  4958. tempPrescription.Diagnose = diagnoses
  4959. service.SaveHisPrescription(tempPrescription)
  4960. redis := service.RedisClient()
  4961. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4962. redis.Set(key, "", time.Second)
  4963. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4964. redis.Set(keyOne, "", time.Second)
  4965. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4966. redis.Set(keySeven, "", time.Second)
  4967. defer redis.Close()
  4968. }
  4969. //service.SaveHisPrescription(prescription)
  4970. //更改患者挂号状态
  4971. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4972. fmt.Println("更改失败", err2)
  4973. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4974. advices := items["advices"].([]interface{})
  4975. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4976. groupNo := int64(0)
  4977. if len(advices) > 0 {
  4978. for _, advice := range advices {
  4979. var s models.HisDoctorAdviceInfo
  4980. s.PrescriptionId = tempPrescription.ID
  4981. s.AdviceType = 2
  4982. s.AdviceDoctor = doctor_id
  4983. s.StopState = 2
  4984. s.ExecutionState = 2
  4985. s.AdviceDate = theTime3.Unix()
  4986. s.Status = 1
  4987. s.UserOrgId = adminInfo.CurrentOrgId
  4988. s.RecordDate = theTime3.Unix()
  4989. s.StartTime = tempPrescription.PreTime
  4990. s.Groupno = groupNo
  4991. s.PatientId = patient_id
  4992. s.HisPatientId = his_patient_id
  4993. s.StartTime = pTime
  4994. s.IsSettle = 2
  4995. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4996. if errcode > 0 {
  4997. c.ServeFailJSONWithSGJErrorCode(errcode)
  4998. return
  4999. }
  5000. s.StartTime = pTime
  5001. var total_count int64 //处方总库存
  5002. //查询改药品信息
  5003. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  5004. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  5005. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5006. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5007. total_count += prescribingNumberSeven * medical.MinNumber
  5008. }
  5009. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5010. total_count += prescribingNumberSeven
  5011. }
  5012. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  5013. total_count += prescribingNumberSeven
  5014. }
  5015. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5016. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5017. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5018. if s.Price != lastWarehouse.RetailPrice {
  5019. s.Price = lastWarehouse.RetailPrice
  5020. }
  5021. if s.Price == 0 {
  5022. if lastWarehouse.ID == 0 {
  5023. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  5024. s.Price = lastWarehouseTwo.RetailPrice
  5025. }
  5026. }
  5027. }
  5028. if adminInfo.CurrentOrgId != 10206 {
  5029. if s.ID == 0 {
  5030. //查询改药品是否已经停用
  5031. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  5032. if base.ID > 0 {
  5033. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  5034. return
  5035. }
  5036. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  5037. if drugMedical.SumCount == 0 {
  5038. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  5039. return
  5040. }
  5041. }
  5042. }
  5043. //赤峰
  5044. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  5045. drug, _ := service.GetDrugByGoodId(s.DrugId)
  5046. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  5047. if info.RetailPrice > 0 {
  5048. if s.DeliveryWay == "口服" {
  5049. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5050. s.Price = drug.RetailPrice
  5051. }
  5052. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5053. s.Price = info.RetailPrice
  5054. }
  5055. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5056. s.Price = info.RetailPrice
  5057. }
  5058. }
  5059. }
  5060. }
  5061. service.CreateHisDoctorAdvice(&s)
  5062. //记录日志
  5063. byterequest, _ := json.Marshal(s)
  5064. adviceLog := models.XtDoctorAdviceLog{
  5065. UserOrgId: s.UserOrgId,
  5066. PatientId: s.PatientId,
  5067. AdminUserId: adminInfo.AdminUser.Id,
  5068. Module: 1,
  5069. ErrLog: string(byterequest),
  5070. Status: 1,
  5071. Ctime: time.Now().Unix(),
  5072. Mtime: 0,
  5073. Source: "电脑端新建his医嘱",
  5074. RecordDate: s.AdviceDate,
  5075. }
  5076. service.CreateDoctorAdviceLog(adviceLog)
  5077. //存储切片中
  5078. adviceList = append(adviceList, s)
  5079. redis := service.RedisClient()
  5080. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5081. redis.Set(key, "", time.Second)
  5082. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5083. redis.Set(keyOne, "", time.Second)
  5084. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5085. redis.Set(keySeven, "", time.Second)
  5086. var randNum int
  5087. randNum = rand.Intn(1000) + 1000
  5088. //timestamp := time.Now().Unix()
  5089. //tempTime := time.Unix(timestamp, 0)
  5090. //timeFormat := tempTime.Format("20060102150405")
  5091. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  5092. service.CreateHisDoctorAdvice(&s)
  5093. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5094. redis.Set(keySix, "", time.Second)
  5095. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5096. redis.Set(keyFive, "", time.Second)
  5097. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5098. redis.Set(keyEight, "", time.Second)
  5099. defer redis.Close()
  5100. }
  5101. }
  5102. }
  5103. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5104. projects := items["project"].([]interface{})
  5105. if len(projects) > 0 {
  5106. for _, project := range projects {
  5107. var p models.HisPrescriptionProject
  5108. p.PrescriptionId = tempPrescription.ID
  5109. p.PatientId = patient_id
  5110. p.RecordDate = theTime3.Unix()
  5111. p.Doctor = doctor_id
  5112. p.UserOrgId = adminInfo.CurrentOrgId
  5113. p.HisPatientId = his_patient_id
  5114. p.Status = 1
  5115. p.StartTime = pTime
  5116. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  5117. if errcode > 0 {
  5118. c.ServeFailJSONWithSGJErrorCode(errcode)
  5119. return
  5120. }
  5121. if p.ID == 0 {
  5122. p.IsOut = 2
  5123. }
  5124. if p.ID > 0 {
  5125. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5126. p.IsOut = projectDetail.IsOut
  5127. }
  5128. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5129. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5130. if p.Type == 3 {
  5131. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5132. if p.Price != lastWarehouse.PackingPrice {
  5133. p.Price = lastWarehouse.PackingPrice
  5134. }
  5135. if p.Price == 0 {
  5136. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5137. p.Price = lastWarehouseTwo.PackingPrice
  5138. }
  5139. if p.Unit == "" {
  5140. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5141. p.Unit = goodInfoOne.PackingUnit
  5142. }
  5143. }
  5144. }
  5145. if adminInfo.CurrentOrgId != 10206 {
  5146. if p.Type == 3 {
  5147. if p.ID == 0 {
  5148. //查询该耗材是否停用
  5149. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5150. //表示该耗材已经停用,不能保存
  5151. if goodInfoSeven.ID == 0 {
  5152. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5153. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5154. return
  5155. }
  5156. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5157. if goodInfoOne.SumCount == 0 {
  5158. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5159. return
  5160. }
  5161. }
  5162. }
  5163. }
  5164. service.CreateHisProjectTwo(&p)
  5165. //记录日志
  5166. byterequest, _ := json.Marshal(p)
  5167. adviceLog := models.XtDoctorAdviceLog{
  5168. UserOrgId: p.UserOrgId,
  5169. PatientId: p.PatientId,
  5170. AdminUserId: adminInfo.AdminUser.Id,
  5171. Module: 1,
  5172. ErrLog: string(byterequest),
  5173. Status: 1,
  5174. Ctime: time.Now().Unix(),
  5175. Mtime: 0,
  5176. Source: "电脑端新建his项目",
  5177. RecordDate: p.RecordDate,
  5178. }
  5179. service.CreateDoctorAdviceLog(adviceLog)
  5180. projectList = append(projectList, p)
  5181. var randNum int
  5182. randNum = rand.Intn(1000) + 1000
  5183. p.FeedetlSn = 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. }