his_api_controller.go 607KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628
  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 || adminInfo.CurrentOrgId == 10751 || adminInfo.CurrentOrgId == 10752 {
  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. fmt.Println("nowCount222=================", nowCount)
  3900. fmt.Println("historyCount-333----------------", historyCount)
  3901. //如果当前处方数量大于历史数据,则需要出库
  3902. if nowCount > historyCount {
  3903. var cha_count int64
  3904. cha_count = nowCount - historyCount
  3905. timeStr := time.Now().Format("2006-01-02")
  3906. timeArr := strings.Split(timeStr, "-")
  3907. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3908. total = total + 1
  3909. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3910. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3911. number = number + total
  3912. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3913. operation_time := time.Now().Unix()
  3914. creater := c.GetAdminUserInfo().AdminUser.Id
  3915. recordDateStr := time.Now().Format("2006-01-02")
  3916. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3917. nowtime := recordDate.Unix()
  3918. warehouseOut := models.WarehouseOut{
  3919. WarehouseOutOrderNumber: warehousing_out_order,
  3920. OperationTime: operation_time,
  3921. OrgId: adminInfo.CurrentOrgId,
  3922. Creater: creater,
  3923. Ctime: time.Now().Unix(),
  3924. Status: 1,
  3925. WarehouseOutTime: nowtime,
  3926. Type: 1,
  3927. StorehouseId: storeConfig.StorehouseOutInfo,
  3928. IsCheck: 1,
  3929. IsSys: 1,
  3930. }
  3931. //查询是否生成出库单
  3932. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3933. if out.ID == 0 {
  3934. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3935. }
  3936. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3937. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3938. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3939. dialyPrepareOne := models.DialysisBeforePrepare{
  3940. GoodTypeId: goodObj.GoodTypeId,
  3941. GoodId: p.ProjectId,
  3942. PatientId: p.PatientId,
  3943. RecordDate: p.RecordDate,
  3944. UserOrgId: adminInfo.CurrentOrgId,
  3945. Count: cha_count,
  3946. Ctime: time.Now().Unix(),
  3947. Creater: creater,
  3948. Status: 1,
  3949. StorehouseId: houseConfig.StorehouseOutInfo,
  3950. ProjectId: p.ID,
  3951. }
  3952. //出库
  3953. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3954. }
  3955. //如果当前处方数量小于历史数据,怎需要退库
  3956. if nowCount < historyCount {
  3957. var cha_count int64
  3958. cha_count = historyCount - nowCount
  3959. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3960. creater := c.GetAdminUserInfo().AdminUser.Id
  3961. newPrescriptionProject := &models.HisPrescriptionProject{
  3962. ID: p.ID,
  3963. ProjectId: p.ProjectId,
  3964. Price: p.Price,
  3965. UserOrgId: p.UserOrgId,
  3966. Status: 1,
  3967. Ctime: time.Now().Unix(),
  3968. Mtime: time.Now().Unix(),
  3969. PatientId: p.PatientId,
  3970. HisPatientId: p.HisPatientId,
  3971. RecordDate: p.RecordDate,
  3972. PrescriptionId: p.PrescriptionId,
  3973. Count: p.Count,
  3974. FeedetlSn: p.FeedetlSn,
  3975. MedListCodg: p.MedListCodg,
  3976. SingleDose: p.SingleDose,
  3977. DeliveryWay: p.DeliveryWay,
  3978. ExecutionFrequency: p.ExecutionFrequency,
  3979. Day: p.Day,
  3980. HisProject: models.HisProject{},
  3981. GoodInfo: models.GoodInfo{},
  3982. Remark: p.Remark,
  3983. Unit: p.Unit,
  3984. Type: p.Type,
  3985. Doctor: p.Doctor,
  3986. ExecutionTime: p.ExecutionTime,
  3987. ExecutionStaff: p.ExecutionStaff,
  3988. ExecutionState: p.ExecutionState,
  3989. CheckTime: p.CheckTime,
  3990. CheckState: p.CheckState,
  3991. Checker: p.Checker,
  3992. StartTime: p.StartTime,
  3993. TeamId: p.TeamId,
  3994. XtHisProjectTeam: models.XtHisProjectTeam{},
  3995. FrequencyType: p.FrequencyType,
  3996. DayCount: p.DayCount,
  3997. WeekDay: p.WeekDay,
  3998. IsCheckTeam: p.IsCheckTeam,
  3999. HisOrderInfo: models.HisOrderInfo{},
  4000. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4001. IsOut: p.IsOut,
  4002. YbSyncStatus: p.YbSyncStatus,
  4003. }
  4004. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4005. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4006. }
  4007. if nowCount == historyCount {
  4008. if historyCount == 0 {
  4009. recordDateStr := time.Now().Format("2006-01-02")
  4010. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4011. nowtime := recordDate.Unix()
  4012. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4013. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4014. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4015. creater := c.GetAdminUserInfo().AdminUser.Id
  4016. dialyPrepareOne := models.DialysisBeforePrepare{
  4017. GoodTypeId: goodObj.GoodTypeId,
  4018. GoodId: p.ProjectId,
  4019. PatientId: p.PatientId,
  4020. RecordDate: p.RecordDate,
  4021. UserOrgId: adminInfo.CurrentOrgId,
  4022. Count: nowCount,
  4023. Ctime: time.Now().Unix(),
  4024. Creater: creater,
  4025. Status: 1,
  4026. StorehouseId: houseConfig.StorehouseOutInfo,
  4027. ProjectId: p.ID,
  4028. }
  4029. //出库
  4030. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4031. }
  4032. }
  4033. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4034. //查询历史出库数据
  4035. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4036. var out_count_five int64
  4037. for _, item := range flowGood {
  4038. out_count_five += item.Count
  4039. }
  4040. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4041. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4042. if out_count_five != parseIntCount {
  4043. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4044. detail := models.AutomaticReduceDetail{
  4045. WarehouseOutId: 0,
  4046. WarehouseOutOrderNumber: "",
  4047. PatientId: p.PatientId,
  4048. Ctime: time.Now().Unix(),
  4049. Mtime: 0,
  4050. Status: 1,
  4051. RecordTime: p.RecordDate,
  4052. OrgId: p.UserOrgId,
  4053. GoodId: p.ProjectId,
  4054. GoodTypeId: 0,
  4055. Count: parseIntCount,
  4056. Type: 0,
  4057. ProjectId: lastHisProject.ID,
  4058. StorehouseId: 0,
  4059. }
  4060. service.CreateNewAutoDetail(detail, tx)
  4061. }
  4062. // //查询耗材最后一次出库记录
  4063. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4064. // //查询默认出库仓库库存
  4065. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4066. // if len(wareOut) > 0 {
  4067. //
  4068. // for _, it := range wareOut {
  4069. // //回退库存
  4070. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4071. //
  4072. // //删除出库记录
  4073. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4074. //
  4075. // }
  4076. // }
  4077. //
  4078. // timeStr := time.Now().Format("2006-01-02")
  4079. // timeArr := strings.Split(timeStr, "-")
  4080. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4081. //
  4082. // total = total + 1
  4083. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4084. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4085. // number = number + total
  4086. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4087. //
  4088. // operation_time := time.Now().Unix()
  4089. // creater := c.GetAdminUserInfo().AdminUser.Id
  4090. //
  4091. // recordDateStr := time.Now().Format("2006-01-02")
  4092. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4093. // nowtime := recordDate.Unix()
  4094. // warehouseOut := models.WarehouseOut{
  4095. // WarehouseOutOrderNumber: warehousing_out_order,
  4096. // OperationTime: operation_time,
  4097. // OrgId: adminInfo.CurrentOrgId,
  4098. // Creater: creater,
  4099. // Ctime: time.Now().Unix(),
  4100. // Status: 1,
  4101. // WarehouseOutTime: nowtime,
  4102. // Type: 1,
  4103. // StorehouseId: storeConfig.StorehouseOutInfo,
  4104. // IsCheck: 1,
  4105. // IsSys: 1,
  4106. // }
  4107. // //查询是否生成出库单
  4108. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4109. // if out.ID == 0 {
  4110. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4111. // }
  4112. //
  4113. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4114. //
  4115. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4116. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4117. //
  4118. // dialyPrepareOne := models.DialysisBeforePrepare{
  4119. // GoodTypeId: goodObj.GoodTypeId,
  4120. // GoodId: p.ProjectId,
  4121. // PatientId: p.PatientId,
  4122. // RecordDate: p.RecordDate,
  4123. // UserOrgId: adminInfo.CurrentOrgId,
  4124. // Count: parseIntCount,
  4125. // Ctime: time.Now().Unix(),
  4126. // Creater: creater,
  4127. // Status: 1,
  4128. // StorehouseId: houseConfig.StorehouseOutInfo,
  4129. // ProjectId: lastHisProject.ID,
  4130. // }
  4131. // //判断是否是零用耗材(非零用)
  4132. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4133. //
  4134. // //查询历史出库数据
  4135. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4136. // var out_count int64
  4137. // for _, item := range flowGood {
  4138. // out_count += item.Count
  4139. // }
  4140. // //如果历史数和当前数据不想等才进行退库出库
  4141. // if out_count != parseIntCount {
  4142. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4143. //
  4144. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4145. // detail := models.AutomaticReduceDetail{
  4146. // WarehouseOutId: 0,
  4147. // WarehouseOutOrderNumber: "",
  4148. // PatientId: p.PatientId,
  4149. // Ctime: time.Now().Unix(),
  4150. // Mtime: 0,
  4151. // Status: 1,
  4152. // RecordTime: p.RecordDate,
  4153. // OrgId: p.UserOrgId,
  4154. // GoodId: p.ProjectId,
  4155. // GoodTypeId: 0,
  4156. // Count: parseIntCount,
  4157. // Type: 0,
  4158. // ProjectId: lastHisProject.ID,
  4159. // StorehouseId: 0,
  4160. // }
  4161. //
  4162. // service.CreateNewAutoDetail(detail, tx)
  4163. //
  4164. // //查询剩余库存
  4165. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4166. // var sum_count int64
  4167. // for _, item := range goodList {
  4168. // sum_count += item.StockCount
  4169. // }
  4170. //
  4171. // //更新剩余库存
  4172. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4173. //
  4174. // //耗材
  4175. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4176. //
  4177. // }
  4178. // //判断是否是零用耗材(零用但是是出库耗材)
  4179. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4180. //
  4181. // //查询历史出库数据
  4182. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4183. // var out_count int64
  4184. // for _, item := range flowGood {
  4185. // out_count += item.Count
  4186. // }
  4187. // //如果历史数和当前数据不想等才进行退库出库
  4188. // if out_count != parseIntCount {
  4189. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4190. //
  4191. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4192. // detail := models.AutomaticReduceDetail{
  4193. // WarehouseOutId: 0,
  4194. // WarehouseOutOrderNumber: "",
  4195. // PatientId: p.PatientId,
  4196. // Ctime: time.Now().Unix(),
  4197. // Mtime: 0,
  4198. // Status: 1,
  4199. // RecordTime: p.RecordDate,
  4200. // OrgId: p.UserOrgId,
  4201. // GoodId: p.ProjectId,
  4202. // GoodTypeId: 0,
  4203. // Count: parseIntCount,
  4204. // Type: 0,
  4205. // ProjectId: p.ID,
  4206. // StorehouseId: 0,
  4207. // }
  4208. //
  4209. // service.CreateNewAutoDetail(detail, tx)
  4210. //
  4211. // //查询剩余库存
  4212. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4213. // var sum_count int64
  4214. // for _, item := range goodList {
  4215. // sum_count += item.StockCount
  4216. // }
  4217. //
  4218. // //更新剩余库存
  4219. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4220. //
  4221. // //耗材
  4222. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4223. // }
  4224. //
  4225. // }
  4226. //
  4227. // }
  4228. //
  4229. //}
  4230. //记录日志
  4231. byterequest, _ := json.Marshal(p)
  4232. adviceLog := models.XtDoctorAdviceLog{
  4233. UserOrgId: p.UserOrgId,
  4234. PatientId: p.PatientId,
  4235. AdminUserId: adminInfo.AdminUser.Id,
  4236. Module: 1,
  4237. ErrLog: string(byterequest),
  4238. Status: 1,
  4239. Ctime: time.Now().Unix(),
  4240. Mtime: 0,
  4241. Source: "电脑端新建his项目",
  4242. RecordDate: p.RecordDate,
  4243. }
  4244. service.CreateDoctorAdviceLog(adviceLog)
  4245. projectList = append(projectList, p)
  4246. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4247. //新增或者编辑项目,修改对应的标签数据
  4248. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4249. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4250. var label models.HisLabelPrintInfo
  4251. project, _ := service.GetProjectDetail(p.ProjectId)
  4252. if project.CostClassify == 3 { //类别为检验检查
  4253. if p.TeamId > 0 { //检验检查组套
  4254. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4255. if tempLabel.ID == 0 {
  4256. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4257. label.Number = tempPrescription.PrescriptionNumber
  4258. label.ProjectId = project.ID
  4259. label.Status = 1
  4260. label.IsPrint = 2
  4261. label.DoctorId = info.DoctorId
  4262. label.UserOrgId = p.UserOrgId
  4263. label.PatientId = patient_id
  4264. label.RecordDate = recordDateTime
  4265. label.Ctime = time.Now().Unix()
  4266. label.Mtime = time.Now().Unix()
  4267. label.ItemId = p.TeamId
  4268. label.FeedetlSn = p.FeedetlSn
  4269. label.PProjectId = p.ID
  4270. label.ProjectName = team.ProjectTeam
  4271. label.PatientName = patient.Name
  4272. service.CreateNewHisLabelRecord(&label, tx)
  4273. }
  4274. } else { //单条检验检查项目
  4275. label.Number = tempPrescription.PrescriptionNumber
  4276. label.ProjectId = project.ID
  4277. label.Status = 1
  4278. label.DoctorId = info.DoctorId
  4279. label.UserOrgId = p.UserOrgId
  4280. label.PatientId = patient_id
  4281. label.RecordDate = recordDateTime
  4282. label.IsPrint = 2
  4283. label.Ctime = time.Now().Unix()
  4284. label.Mtime = time.Now().Unix()
  4285. label.FeedetlSn = p.FeedetlSn
  4286. label.PProjectId = p.ID
  4287. label.ItemId = p.TeamId
  4288. label.ProjectName = project.ProjectName
  4289. label.PatientName = patient.Name
  4290. service.CreateNewHisLabelRecord(&label, tx)
  4291. }
  4292. }
  4293. }
  4294. }
  4295. }
  4296. }
  4297. }
  4298. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4299. //
  4300. // //耗材出库
  4301. // if p.Type == 3 {
  4302. //
  4303. // //对比当前数据和历史出库数据
  4304. //
  4305. // historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4306. //
  4307. // historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4308. //
  4309. // nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4310. //
  4311. // //如果当前处方数量大于历史数据,则需要出库
  4312. // if nowCount > historyCount {
  4313. //
  4314. // var cha_count int64
  4315. // cha_count = nowCount - historyCount
  4316. //
  4317. // timeStr := time.Now().Format("2006-01-02")
  4318. // timeArr := strings.Split(timeStr, "-")
  4319. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4320. //
  4321. // total = total + 1
  4322. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4323. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4324. // number = number + total
  4325. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4326. //
  4327. // operation_time := time.Now().Unix()
  4328. // creater := c.GetAdminUserInfo().AdminUser.Id
  4329. //
  4330. // recordDateStr := time.Now().Format("2006-01-02")
  4331. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4332. // nowtime := recordDate.Unix()
  4333. // warehouseOut := models.WarehouseOut{
  4334. // WarehouseOutOrderNumber: warehousing_out_order,
  4335. // OperationTime: operation_time,
  4336. // OrgId: adminInfo.CurrentOrgId,
  4337. // Creater: creater,
  4338. // Ctime: time.Now().Unix(),
  4339. // Status: 1,
  4340. // WarehouseOutTime: nowtime,
  4341. // Type: 1,
  4342. // StorehouseId: storeConfig.StorehouseOutInfo,
  4343. // IsCheck: 1,
  4344. // IsSys: 1,
  4345. // }
  4346. // //查询是否生成出库单
  4347. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4348. // if out.ID == 0 {
  4349. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4350. // }
  4351. //
  4352. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4353. //
  4354. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4355. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4356. //
  4357. // dialyPrepareOne := models.DialysisBeforePrepare{
  4358. // GoodTypeId: goodObj.GoodTypeId,
  4359. // GoodId: p.ProjectId,
  4360. // PatientId: p.PatientId,
  4361. // RecordDate: p.RecordDate,
  4362. // UserOrgId: adminInfo.CurrentOrgId,
  4363. // Count: cha_count,
  4364. // Ctime: time.Now().Unix(),
  4365. // Creater: creater,
  4366. // Status: 1,
  4367. // StorehouseId: houseConfig.StorehouseOutInfo,
  4368. // ProjectId: p.ID,
  4369. // }
  4370. // //出库
  4371. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4372. //
  4373. // }
  4374. //
  4375. // //如果当前处方数量小于历史数据,怎需要退库
  4376. // if nowCount < historyCount {
  4377. //
  4378. // var cha_count int64
  4379. // cha_count = historyCount - nowCount
  4380. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4381. // creater := c.GetAdminUserInfo().AdminUser.Id
  4382. //
  4383. // newPrescriptionProject := &models.HisPrescriptionProject{
  4384. // ID: p.ID,
  4385. // ProjectId: p.ProjectId,
  4386. // Price: p.Price,
  4387. // UserOrgId: p.UserOrgId,
  4388. // Status: 1,
  4389. // Ctime: time.Now().Unix(),
  4390. // Mtime: time.Now().Unix(),
  4391. // PatientId: p.PatientId,
  4392. // HisPatientId: p.HisPatientId,
  4393. // RecordDate: p.RecordDate,
  4394. // PrescriptionId: p.PrescriptionId,
  4395. // Count: p.Count,
  4396. // FeedetlSn: p.FeedetlSn,
  4397. // MedListCodg: p.MedListCodg,
  4398. // SingleDose: p.SingleDose,
  4399. // DeliveryWay: p.DeliveryWay,
  4400. // ExecutionFrequency: p.ExecutionFrequency,
  4401. // Day: p.Day,
  4402. // HisProject: models.HisProject{},
  4403. // GoodInfo: models.GoodInfo{},
  4404. // Remark: p.Remark,
  4405. // Unit: p.Unit,
  4406. // Type: p.Type,
  4407. // Doctor: p.Doctor,
  4408. // ExecutionTime: p.ExecutionTime,
  4409. // ExecutionStaff: p.ExecutionStaff,
  4410. // ExecutionState: p.ExecutionState,
  4411. // CheckTime: p.CheckTime,
  4412. // CheckState: p.CheckState,
  4413. // Checker: p.Checker,
  4414. // StartTime: p.StartTime,
  4415. // TeamId: p.TeamId,
  4416. // XtHisProjectTeam: models.XtHisProjectTeam{},
  4417. // FrequencyType: p.FrequencyType,
  4418. // DayCount: p.DayCount,
  4419. // WeekDay: p.WeekDay,
  4420. // IsCheckTeam: p.IsCheckTeam,
  4421. // HisOrderInfo: models.HisOrderInfo{},
  4422. // ExecutionFrequencyId: p.ExecutionFrequencyId,
  4423. // IsOut: p.IsOut,
  4424. // YbSyncStatus: p.YbSyncStatus,
  4425. // }
  4426. //
  4427. // service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4428. //
  4429. // service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4430. //
  4431. // }
  4432. //
  4433. // if nowCount == historyCount {
  4434. // if historyCount == 0 {
  4435. // recordDateStr := time.Now().Format("2006-01-02")
  4436. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4437. // nowtime := recordDate.Unix()
  4438. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4439. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4440. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4441. // creater := c.GetAdminUserInfo().AdminUser.Id
  4442. // dialyPrepareOne := models.DialysisBeforePrepare{
  4443. // GoodTypeId: goodObj.GoodTypeId,
  4444. // GoodId: p.ProjectId,
  4445. // PatientId: p.PatientId,
  4446. // RecordDate: p.RecordDate,
  4447. // UserOrgId: adminInfo.CurrentOrgId,
  4448. // Count: nowCount,
  4449. // Ctime: time.Now().Unix(),
  4450. // Creater: creater,
  4451. // Status: 1,
  4452. // StorehouseId: houseConfig.StorehouseOutInfo,
  4453. // ProjectId: p.ID,
  4454. // }
  4455. // //出库
  4456. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4457. // }
  4458. // }
  4459. //
  4460. // lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4461. // //查询历史出库数据
  4462. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4463. //
  4464. // var out_count_five int64
  4465. // for _, item := range flowGood {
  4466. // out_count_five += item.Count
  4467. // }
  4468. // parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4469. //
  4470. // //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4471. // if out_count_five != parseIntCount {
  4472. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4473. // detail := models.AutomaticReduceDetail{
  4474. // WarehouseOutId: 0,
  4475. // WarehouseOutOrderNumber: "",
  4476. // PatientId: p.PatientId,
  4477. // Ctime: time.Now().Unix(),
  4478. // Mtime: 0,
  4479. // Status: 1,
  4480. // RecordTime: p.RecordDate,
  4481. // OrgId: p.UserOrgId,
  4482. // GoodId: p.ProjectId,
  4483. // GoodTypeId: 0,
  4484. // Count: parseIntCount,
  4485. // Type: 0,
  4486. // ProjectId: lastHisProject.ID,
  4487. // StorehouseId: 0,
  4488. // }
  4489. //
  4490. // service.CreateNewAutoDetail(detail, tx)
  4491. // }
  4492. // // //查询耗材最后一次出库记录
  4493. // // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4494. // // //查询默认出库仓库库存
  4495. // // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4496. // // if len(wareOut) > 0 {
  4497. // //
  4498. // // for _, it := range wareOut {
  4499. // // //回退库存
  4500. // // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4501. // //
  4502. // // //删除出库记录
  4503. // // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4504. // //
  4505. // // }
  4506. // // }
  4507. // //
  4508. // // timeStr := time.Now().Format("2006-01-02")
  4509. // // timeArr := strings.Split(timeStr, "-")
  4510. // // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4511. // //
  4512. // // total = total + 1
  4513. // // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4514. // // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4515. // // number = number + total
  4516. // // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4517. // //
  4518. // // operation_time := time.Now().Unix()
  4519. // // creater := c.GetAdminUserInfo().AdminUser.Id
  4520. // //
  4521. // // recordDateStr := time.Now().Format("2006-01-02")
  4522. // // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4523. // // nowtime := recordDate.Unix()
  4524. // // warehouseOut := models.WarehouseOut{
  4525. // // WarehouseOutOrderNumber: warehousing_out_order,
  4526. // // OperationTime: operation_time,
  4527. // // OrgId: adminInfo.CurrentOrgId,
  4528. // // Creater: creater,
  4529. // // Ctime: time.Now().Unix(),
  4530. // // Status: 1,
  4531. // // WarehouseOutTime: nowtime,
  4532. // // Type: 1,
  4533. // // StorehouseId: storeConfig.StorehouseOutInfo,
  4534. // // IsCheck: 1,
  4535. // // IsSys: 1,
  4536. // // }
  4537. // // //查询是否生成出库单
  4538. // // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4539. // // if out.ID == 0 {
  4540. // // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4541. // // }
  4542. // //
  4543. // // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4544. // //
  4545. // // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4546. // // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4547. // //
  4548. // // dialyPrepareOne := models.DialysisBeforePrepare{
  4549. // // GoodTypeId: goodObj.GoodTypeId,
  4550. // // GoodId: p.ProjectId,
  4551. // // PatientId: p.PatientId,
  4552. // // RecordDate: p.RecordDate,
  4553. // // UserOrgId: adminInfo.CurrentOrgId,
  4554. // // Count: parseIntCount,
  4555. // // Ctime: time.Now().Unix(),
  4556. // // Creater: creater,
  4557. // // Status: 1,
  4558. // // StorehouseId: houseConfig.StorehouseOutInfo,
  4559. // // ProjectId: lastHisProject.ID,
  4560. // // }
  4561. // // //判断是否是零用耗材(非零用)
  4562. // // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4563. // //
  4564. // // //查询历史出库数据
  4565. // // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4566. // // var out_count int64
  4567. // // for _, item := range flowGood {
  4568. // // out_count += item.Count
  4569. // // }
  4570. // // //如果历史数和当前数据不想等才进行退库出库
  4571. // // if out_count != parseIntCount {
  4572. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4573. // //
  4574. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4575. // // detail := models.AutomaticReduceDetail{
  4576. // // WarehouseOutId: 0,
  4577. // // WarehouseOutOrderNumber: "",
  4578. // // PatientId: p.PatientId,
  4579. // // Ctime: time.Now().Unix(),
  4580. // // Mtime: 0,
  4581. // // Status: 1,
  4582. // // RecordTime: p.RecordDate,
  4583. // // OrgId: p.UserOrgId,
  4584. // // GoodId: p.ProjectId,
  4585. // // GoodTypeId: 0,
  4586. // // Count: parseIntCount,
  4587. // // Type: 0,
  4588. // // ProjectId: lastHisProject.ID,
  4589. // // StorehouseId: 0,
  4590. // // }
  4591. // //
  4592. // // service.CreateNewAutoDetail(detail, tx)
  4593. // //
  4594. // // //查询剩余库存
  4595. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4596. // // var sum_count int64
  4597. // // for _, item := range goodList {
  4598. // // sum_count += item.StockCount
  4599. // // }
  4600. // //
  4601. // // //更新剩余库存
  4602. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4603. // //
  4604. // // //耗材
  4605. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4606. // //
  4607. // // }
  4608. // // //判断是否是零用耗材(零用但是是出库耗材)
  4609. // // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4610. // //
  4611. // // //查询历史出库数据
  4612. // // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4613. // // var out_count int64
  4614. // // for _, item := range flowGood {
  4615. // // out_count += item.Count
  4616. // // }
  4617. // // //如果历史数和当前数据不想等才进行退库出库
  4618. // // if out_count != parseIntCount {
  4619. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4620. // //
  4621. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4622. // // detail := models.AutomaticReduceDetail{
  4623. // // WarehouseOutId: 0,
  4624. // // WarehouseOutOrderNumber: "",
  4625. // // PatientId: p.PatientId,
  4626. // // Ctime: time.Now().Unix(),
  4627. // // Mtime: 0,
  4628. // // Status: 1,
  4629. // // RecordTime: p.RecordDate,
  4630. // // OrgId: p.UserOrgId,
  4631. // // GoodId: p.ProjectId,
  4632. // // GoodTypeId: 0,
  4633. // // Count: parseIntCount,
  4634. // // Type: 0,
  4635. // // ProjectId: p.ID,
  4636. // // StorehouseId: 0,
  4637. // // }
  4638. // //
  4639. // // service.CreateNewAutoDetail(detail, tx)
  4640. // //
  4641. // // //查询剩余库存
  4642. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4643. // // var sum_count int64
  4644. // // for _, item := range goodList {
  4645. // // sum_count += item.StockCount
  4646. // // }
  4647. // //
  4648. // // //更新剩余库存
  4649. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4650. // //
  4651. // // //耗材
  4652. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4653. // // }
  4654. // //
  4655. // // }
  4656. // //
  4657. // // }
  4658. // //
  4659. // //}
  4660. //
  4661. // //记录日志
  4662. // byterequest, _ := json.Marshal(p)
  4663. // adviceLog := models.XtDoctorAdviceLog{
  4664. // UserOrgId: p.UserOrgId,
  4665. // PatientId: p.PatientId,
  4666. // AdminUserId: adminInfo.AdminUser.Id,
  4667. // Module: 1,
  4668. // ErrLog: string(byterequest),
  4669. // Status: 1,
  4670. // Ctime: time.Now().Unix(),
  4671. // Mtime: 0,
  4672. // Source: "电脑端新建his项目",
  4673. // RecordDate: p.RecordDate,
  4674. // }
  4675. // service.CreateDoctorAdviceLog(adviceLog)
  4676. //
  4677. // projectList = append(projectList, p)
  4678. //
  4679. // if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4680. // //新增或者编辑项目,修改对应的标签数据
  4681. // labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4682. // if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4683. // var label models.HisLabelPrintInfo
  4684. // project, _ := service.GetProjectDetail(p.ProjectId)
  4685. // if project.CostClassify == 3 { //类别为检验检查
  4686. // if p.TeamId > 0 { //检验检查组套
  4687. // tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4688. // if tempLabel.ID == 0 {
  4689. // team, _ := service.GetProjectTeamDetail(p.TeamId)
  4690. // label.Number = tempPrescription.PrescriptionNumber
  4691. // label.ProjectId = project.ID
  4692. // label.Status = 1
  4693. // label.IsPrint = 2
  4694. // label.DoctorId = info.DoctorId
  4695. // label.UserOrgId = p.UserOrgId
  4696. // label.PatientId = patient_id
  4697. // label.RecordDate = recordDateTime
  4698. // label.Ctime = time.Now().Unix()
  4699. // label.Mtime = time.Now().Unix()
  4700. // label.ItemId = p.TeamId
  4701. // label.FeedetlSn = p.FeedetlSn
  4702. // label.PProjectId = p.ID
  4703. // label.ProjectName = team.ProjectTeam
  4704. // label.PatientName = patient.Name
  4705. // service.CreateNewHisLabelRecord(&label, tx)
  4706. // }
  4707. // } else { //单条检验检查项目
  4708. // label.Number = tempPrescription.PrescriptionNumber
  4709. // label.ProjectId = project.ID
  4710. // label.Status = 1
  4711. // label.DoctorId = info.DoctorId
  4712. // label.UserOrgId = p.UserOrgId
  4713. // label.PatientId = patient_id
  4714. // label.RecordDate = recordDateTime
  4715. // label.IsPrint = 2
  4716. // label.Ctime = time.Now().Unix()
  4717. // label.Mtime = time.Now().Unix()
  4718. // label.FeedetlSn = p.FeedetlSn
  4719. // label.PProjectId = p.ID
  4720. // label.ItemId = p.TeamId
  4721. // label.ProjectName = project.ProjectName
  4722. // label.PatientName = patient.Name
  4723. // service.CreateNewHisLabelRecord(&label, tx)
  4724. // }
  4725. // }
  4726. // }
  4727. // }
  4728. //
  4729. // }
  4730. //}
  4731. }
  4732. //插入检验数据
  4733. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4734. //新增或者编辑项目,修改对应的标签数据
  4735. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4736. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4737. var label models.HisLabelPrintInfo
  4738. project, _ := service.GetProjectDetail(p.ProjectId)
  4739. if project.CostClassify == 3 { //类别为检验检查
  4740. if p.TeamId > 0 { //检验检查组套
  4741. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4742. if tempLabel.ID == 0 {
  4743. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4744. label.Number = tempPrescription.PrescriptionNumber
  4745. label.ProjectId = project.ID
  4746. label.Status = 1
  4747. label.IsPrint = 2
  4748. label.DoctorId = info.DoctorId
  4749. label.UserOrgId = p.UserOrgId
  4750. label.PatientId = patient_id
  4751. label.RecordDate = recordDateTime
  4752. label.Ctime = time.Now().Unix()
  4753. label.Mtime = time.Now().Unix()
  4754. label.ItemId = p.TeamId
  4755. label.FeedetlSn = p.FeedetlSn
  4756. label.PProjectId = p.ID
  4757. label.ProjectName = team.ProjectTeam
  4758. label.PatientName = patient.Name
  4759. service.CreateHisLabelRecord(&label)
  4760. }
  4761. } else { //单条检验检查项目
  4762. label.Number = tempPrescription.PrescriptionNumber
  4763. label.ProjectId = project.ID
  4764. label.Status = 1
  4765. label.DoctorId = info.DoctorId
  4766. label.UserOrgId = p.UserOrgId
  4767. label.PatientId = patient_id
  4768. label.RecordDate = recordDateTime
  4769. label.IsPrint = 2
  4770. label.Ctime = time.Now().Unix()
  4771. label.Mtime = time.Now().Unix()
  4772. label.FeedetlSn = p.FeedetlSn
  4773. label.PProjectId = p.ID
  4774. label.ItemId = p.TeamId
  4775. label.ProjectName = project.ProjectName
  4776. label.PatientName = patient.Name
  4777. service.CreateHisLabelRecord(&label)
  4778. }
  4779. }
  4780. }
  4781. }
  4782. service.CreateNewHisProjectTwo(&p, tx)
  4783. var randNum int
  4784. randNum = rand.Intn(1000) + 1000
  4785. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4786. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4787. if goodBase.ID > 0 {
  4788. tx.Rollback()
  4789. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4790. return
  4791. }
  4792. service.CreateNewHisProjectTwo(&p, tx)
  4793. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4794. //查询剩余库存
  4795. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4796. var sum_count int64
  4797. for _, item := range goodList {
  4798. sum_count += item.StockCount
  4799. }
  4800. //更新剩余库存
  4801. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4802. //耗材
  4803. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4804. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4805. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4806. if len(outInfoTwo) > 0 {
  4807. for _, item := range outInfoTwo {
  4808. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4809. }
  4810. }
  4811. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4812. if len(drugAutoDetail) > 0 {
  4813. for _, item := range drugAutoDetail {
  4814. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4815. }
  4816. }
  4817. tx.Commit()
  4818. }
  4819. }
  4820. }
  4821. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4822. // addition := items["addition"].([]interface{})
  4823. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4824. // ctime := time.Now().Unix()
  4825. // mtime := ctime
  4826. // if len(addition) > 0 {
  4827. // for _, item := range addition {
  4828. // var s models.HisAdditionalCharge
  4829. // s.PrescriptionId = tempPrescription.ID
  4830. // s.Status = 1
  4831. // s.UserOrgId = adminInfo.CurrentOrgId
  4832. // s.RecordDate = recordDateTime
  4833. // s.CreatedTime = ctime
  4834. // s.UpdatedTime = mtime
  4835. // s.PatientId = patient_id
  4836. // s.HisPatientId = his_patient_id
  4837. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4838. // if errcode > 0 {
  4839. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4840. // return
  4841. // }
  4842. // service.CreateAdditionalCharge(&s)
  4843. // var randNum int
  4844. // randNum = rand.Intn(10000) + 1000
  4845. // timestamp := time.Now().Unix()
  4846. // tempTime := time.Unix(timestamp, 0)
  4847. // timeFormat := tempTime.Format("20060102150405")
  4848. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4849. // service.CreateAdditionalCharge(&s)
  4850. //
  4851. // }
  4852. // }
  4853. //}
  4854. }
  4855. }
  4856. }
  4857. tx.Commit()
  4858. if err == nil {
  4859. c.ServeSuccessJSON(map[string]interface{}{
  4860. "msg": "保存成功",
  4861. })
  4862. return
  4863. } else {
  4864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4865. return
  4866. }
  4867. } else {
  4868. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4869. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4870. var tempPrescription *models.HisPrescription
  4871. if len(prescriptions) > 0 {
  4872. for _, item := range prescriptions {
  4873. items := item.(map[string]interface{})
  4874. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4875. utils.ErrorLog("id")
  4876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4877. return
  4878. }
  4879. id := int64(items["id"].(float64))
  4880. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4881. tempPrescription = &new_prescription
  4882. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4883. utils.ErrorLog("type")
  4884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4885. return
  4886. }
  4887. types := int64(items["type"].(float64))
  4888. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4889. utils.ErrorLog("med_type")
  4890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4891. return
  4892. }
  4893. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4894. if med_type == "0" {
  4895. med_type = "14"
  4896. }
  4897. //if order_status == 0 {
  4898. // order_status = 1
  4899. //}
  4900. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4901. // utils.ErrorLog("diagnoses")
  4902. //}
  4903. diagnoses, _ := items["diagnoses"].(string)
  4904. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4905. utils.ErrorLog("pre_time")
  4906. }
  4907. preTime, _ := items["pre_time"].(string)
  4908. timeLayout := "2006-01-02"
  4909. loc, _ := time.LoadLocation("Local")
  4910. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4911. //result := strings.Split(preTime, " ")
  4912. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4913. if err != nil {
  4914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4915. return
  4916. }
  4917. pTime := theTime2.Unix()
  4918. ctime := time.Now().Unix()
  4919. if tempPrescription.ID == 0 {
  4920. prescription := &models.HisPrescription{
  4921. ID: 0,
  4922. PatientId: patient_id,
  4923. UserOrgId: adminInfo.CurrentOrgId,
  4924. RecordDate: recordDateTime,
  4925. Ctime: ctime,
  4926. Mtime: ctime,
  4927. Type: types,
  4928. Modifier: adminInfo.AdminUser.Id,
  4929. Creator: adminInfo.AdminUser.Id,
  4930. Status: 1,
  4931. Doctor: role.UserName,
  4932. HisPatientId: his_patient_id,
  4933. OrderStatus: 1,
  4934. BatchNumber: "",
  4935. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4936. PreTime: pTime,
  4937. PType: p_type,
  4938. MedType: med_type,
  4939. Diagnose: diagnoses,
  4940. }
  4941. tempPrescription = prescription
  4942. service.SaveHisPrescription(tempPrescription)
  4943. redis := service.RedisClient()
  4944. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4945. redis.Set(key, "", time.Second)
  4946. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4947. redis.Set(keyOne, "", time.Second)
  4948. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4949. redis.Set(keySeven, "", time.Second)
  4950. defer redis.Close()
  4951. } else {
  4952. tempPrescription.ID = id
  4953. tempPrescription.Type = types
  4954. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4955. tempPrescription.Mtime = time.Now().Unix()
  4956. tempPrescription.Doctor = role.UserName
  4957. //tempPrescription.OrderStatus = order_status
  4958. tempPrescription.PreTime = pTime
  4959. tempPrescription.MedType = med_type
  4960. tempPrescription.Diagnose = diagnoses
  4961. service.SaveHisPrescription(tempPrescription)
  4962. redis := service.RedisClient()
  4963. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4964. redis.Set(key, "", time.Second)
  4965. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4966. redis.Set(keyOne, "", time.Second)
  4967. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4968. redis.Set(keySeven, "", time.Second)
  4969. defer redis.Close()
  4970. }
  4971. //service.SaveHisPrescription(prescription)
  4972. //更改患者挂号状态
  4973. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4974. fmt.Println("更改失败", err2)
  4975. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4976. advices := items["advices"].([]interface{})
  4977. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4978. groupNo := int64(0)
  4979. if len(advices) > 0 {
  4980. for _, advice := range advices {
  4981. var s models.HisDoctorAdviceInfo
  4982. s.PrescriptionId = tempPrescription.ID
  4983. s.AdviceType = 2
  4984. s.AdviceDoctor = doctor_id
  4985. s.StopState = 2
  4986. s.ExecutionState = 2
  4987. s.AdviceDate = theTime3.Unix()
  4988. s.Status = 1
  4989. s.UserOrgId = adminInfo.CurrentOrgId
  4990. s.RecordDate = theTime3.Unix()
  4991. s.StartTime = tempPrescription.PreTime
  4992. s.Groupno = groupNo
  4993. s.PatientId = patient_id
  4994. s.HisPatientId = his_patient_id
  4995. s.StartTime = pTime
  4996. s.IsSettle = 2
  4997. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4998. if errcode > 0 {
  4999. c.ServeFailJSONWithSGJErrorCode(errcode)
  5000. return
  5001. }
  5002. s.StartTime = pTime
  5003. var total_count int64 //处方总库存
  5004. //查询改药品信息
  5005. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  5006. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  5007. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5008. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5009. total_count += prescribingNumberSeven * medical.MinNumber
  5010. }
  5011. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5012. total_count += prescribingNumberSeven
  5013. }
  5014. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  5015. total_count += prescribingNumberSeven
  5016. }
  5017. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5018. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5019. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5020. if s.Price != lastWarehouse.RetailPrice {
  5021. s.Price = lastWarehouse.RetailPrice
  5022. }
  5023. if s.Price == 0 {
  5024. if lastWarehouse.ID == 0 {
  5025. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  5026. s.Price = lastWarehouseTwo.RetailPrice
  5027. }
  5028. }
  5029. }
  5030. if adminInfo.CurrentOrgId != 10206 {
  5031. if s.ID == 0 {
  5032. //查询改药品是否已经停用
  5033. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  5034. if base.ID > 0 {
  5035. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  5036. return
  5037. }
  5038. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  5039. if drugMedical.SumCount == 0 {
  5040. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  5041. return
  5042. }
  5043. }
  5044. }
  5045. //赤峰
  5046. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  5047. drug, _ := service.GetDrugByGoodId(s.DrugId)
  5048. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  5049. if info.RetailPrice > 0 {
  5050. if s.DeliveryWay == "口服" {
  5051. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5052. s.Price = drug.RetailPrice
  5053. }
  5054. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5055. s.Price = info.RetailPrice
  5056. }
  5057. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5058. s.Price = info.RetailPrice
  5059. }
  5060. }
  5061. }
  5062. }
  5063. service.CreateHisDoctorAdvice(&s)
  5064. //记录日志
  5065. byterequest, _ := json.Marshal(s)
  5066. adviceLog := models.XtDoctorAdviceLog{
  5067. UserOrgId: s.UserOrgId,
  5068. PatientId: s.PatientId,
  5069. AdminUserId: adminInfo.AdminUser.Id,
  5070. Module: 1,
  5071. ErrLog: string(byterequest),
  5072. Status: 1,
  5073. Ctime: time.Now().Unix(),
  5074. Mtime: 0,
  5075. Source: "电脑端新建his医嘱",
  5076. RecordDate: s.AdviceDate,
  5077. }
  5078. service.CreateDoctorAdviceLog(adviceLog)
  5079. //存储切片中
  5080. adviceList = append(adviceList, s)
  5081. redis := service.RedisClient()
  5082. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5083. redis.Set(key, "", time.Second)
  5084. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5085. redis.Set(keyOne, "", time.Second)
  5086. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5087. redis.Set(keySeven, "", time.Second)
  5088. var randNum int
  5089. randNum = rand.Intn(1000) + 1000
  5090. //timestamp := time.Now().Unix()
  5091. //tempTime := time.Unix(timestamp, 0)
  5092. //timeFormat := tempTime.Format("20060102150405")
  5093. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  5094. service.CreateHisDoctorAdvice(&s)
  5095. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5096. redis.Set(keySix, "", time.Second)
  5097. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5098. redis.Set(keyFive, "", time.Second)
  5099. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5100. redis.Set(keyEight, "", time.Second)
  5101. defer redis.Close()
  5102. }
  5103. }
  5104. }
  5105. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5106. projects := items["project"].([]interface{})
  5107. if len(projects) > 0 {
  5108. for _, project := range projects {
  5109. var p models.HisPrescriptionProject
  5110. p.PrescriptionId = tempPrescription.ID
  5111. p.PatientId = patient_id
  5112. p.RecordDate = theTime3.Unix()
  5113. p.Doctor = doctor_id
  5114. p.UserOrgId = adminInfo.CurrentOrgId
  5115. p.HisPatientId = his_patient_id
  5116. p.Status = 1
  5117. p.StartTime = pTime
  5118. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  5119. if errcode > 0 {
  5120. c.ServeFailJSONWithSGJErrorCode(errcode)
  5121. return
  5122. }
  5123. if p.ID == 0 {
  5124. p.IsOut = 2
  5125. }
  5126. if p.ID > 0 {
  5127. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5128. p.IsOut = projectDetail.IsOut
  5129. }
  5130. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5131. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5132. if p.Type == 3 {
  5133. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5134. if p.Price != lastWarehouse.PackingPrice {
  5135. p.Price = lastWarehouse.PackingPrice
  5136. }
  5137. if p.Price == 0 {
  5138. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5139. p.Price = lastWarehouseTwo.PackingPrice
  5140. }
  5141. if p.Unit == "" {
  5142. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5143. p.Unit = goodInfoOne.PackingUnit
  5144. }
  5145. }
  5146. }
  5147. if adminInfo.CurrentOrgId != 10206 {
  5148. if p.Type == 3 {
  5149. if p.ID == 0 {
  5150. //查询该耗材是否停用
  5151. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5152. //表示该耗材已经停用,不能保存
  5153. if goodInfoSeven.ID == 0 {
  5154. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5155. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5156. return
  5157. }
  5158. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5159. if goodInfoOne.SumCount == 0 {
  5160. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5161. return
  5162. }
  5163. }
  5164. }
  5165. }
  5166. service.CreateHisProjectTwo(&p)
  5167. //记录日志
  5168. byterequest, _ := json.Marshal(p)
  5169. adviceLog := models.XtDoctorAdviceLog{
  5170. UserOrgId: p.UserOrgId,
  5171. PatientId: p.PatientId,
  5172. AdminUserId: adminInfo.AdminUser.Id,
  5173. Module: 1,
  5174. ErrLog: string(byterequest),
  5175. Status: 1,
  5176. Ctime: time.Now().Unix(),
  5177. Mtime: 0,
  5178. Source: "电脑端新建his项目",
  5179. RecordDate: p.RecordDate,
  5180. }
  5181. service.CreateDoctorAdviceLog(adviceLog)
  5182. projectList = append(projectList, p)
  5183. var randNum int
  5184. randNum = rand.Intn(1000) + 1000
  5185. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  5186. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  5187. //新增或者编辑项目,修改对应的标签数据
  5188. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  5189. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  5190. var label models.HisLabelPrintInfo
  5191. project, _ := service.GetProjectDetail(p.ProjectId)
  5192. if project.CostClassify == 3 { //类别为检验检查
  5193. if p.TeamId > 0 { //检验检查组套
  5194. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  5195. if tempLabel.ID == 0 {
  5196. team, _ := service.GetProjectTeamDetail(p.TeamId)
  5197. label.Number = tempPrescription.PrescriptionNumber
  5198. label.ProjectId = project.ID
  5199. label.Status = 1
  5200. label.IsPrint = 2
  5201. label.DoctorId = info.DoctorId
  5202. label.UserOrgId = p.UserOrgId
  5203. label.PatientId = patient_id
  5204. label.RecordDate = recordDateTime
  5205. label.Ctime = time.Now().Unix()
  5206. label.Mtime = time.Now().Unix()
  5207. label.ItemId = p.TeamId
  5208. label.FeedetlSn = p.FeedetlSn
  5209. label.PProjectId = p.ID
  5210. label.ProjectName = team.ProjectTeam
  5211. label.PatientName = patient.Name
  5212. service.CreateHisLabelRecord(&label)
  5213. }
  5214. } else { //单条检验检查项目
  5215. label.Number = tempPrescription.PrescriptionNumber
  5216. label.ProjectId = project.ID
  5217. label.Status = 1
  5218. label.DoctorId = info.DoctorId
  5219. label.UserOrgId = p.UserOrgId
  5220. label.PatientId = patient_id
  5221. label.RecordDate = recordDateTime
  5222. label.IsPrint = 2
  5223. label.Ctime = time.Now().Unix()
  5224. label.Mtime = time.Now().Unix()
  5225. label.FeedetlSn = p.FeedetlSn
  5226. label.PProjectId = p.ID
  5227. label.ItemId = p.TeamId
  5228. label.ProjectName = project.ProjectName
  5229. label.PatientName = patient.Name
  5230. service.CreateHisLabelRecord(&label)
  5231. }
  5232. }
  5233. }
  5234. }
  5235. service.SaveHisProjectTwo(&p)
  5236. }
  5237. }
  5238. }
  5239. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5240. // addition := items["addition"].([]interface{})
  5241. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5242. // ctime := time.Now().Unix()
  5243. // mtime := ctime
  5244. // if len(addition) > 0 {
  5245. // for _, item := range addition {
  5246. // var s models.HisAdditionalCharge
  5247. // s.PrescriptionId = tempPrescription.ID
  5248. // s.Status = 1
  5249. // s.UserOrgId = adminInfo.CurrentOrgId
  5250. // s.RecordDate = recordDateTime
  5251. // s.CreatedTime = ctime
  5252. // s.UpdatedTime = mtime
  5253. // s.PatientId = patient_id
  5254. // s.HisPatientId = his_patient_id
  5255. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5256. // if errcode > 0 {
  5257. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5258. // return
  5259. // }
  5260. // service.CreateAdditionalCharge(&s)
  5261. // var randNum int
  5262. // randNum = rand.Intn(10000) + 1000
  5263. // timestamp := time.Now().Unix()
  5264. // tempTime := time.Unix(timestamp, 0)
  5265. // timeFormat := tempTime.Format("20060102150405")
  5266. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5267. // service.CreateAdditionalCharge(&s)
  5268. //
  5269. // }
  5270. // }
  5271. //}
  5272. }
  5273. }
  5274. //查询今日该患者开的药品处方
  5275. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5276. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5277. //药品出库
  5278. if drugOutConfig.IsOpen == 1 {
  5279. for _, item := range hisdoctorlist {
  5280. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5281. // 查询该药品最后一次出库记录
  5282. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5283. if len(druginfo) > 0 {
  5284. //回退库存
  5285. for _, it := range druginfo {
  5286. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5287. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5288. }
  5289. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5290. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5291. }
  5292. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5293. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5294. }
  5295. }
  5296. }
  5297. //删除记录
  5298. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5299. //查询最后一次数据
  5300. if drugOutConfig.IsOpen == 1 {
  5301. //出库
  5302. if drug.IsUse == 2 {
  5303. creater := adminInfo.AdminUser.Id
  5304. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5305. }
  5306. //更新字典里面的库存
  5307. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5308. var sum_count int64
  5309. for _, its := range stockInfo {
  5310. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5311. if its.MaxUnit == baseDrug.MaxUnit {
  5312. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5313. }
  5314. sum_count += its.StockMaxNumber + its.StockMinNumber
  5315. }
  5316. //更新基础库存
  5317. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5318. //剩余库存
  5319. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5320. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5321. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5322. }
  5323. }
  5324. }
  5325. fmt.Println("耗材----------------------------------", goodOutConfig.IsOpen)
  5326. //耗材保存处方出库
  5327. if goodOutConfig.IsOpen == 1 {
  5328. //查询今日耗材出库数量
  5329. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5330. for _, item := range hisgoodlist {
  5331. //查询历史出库数据
  5332. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5333. var out_count_five int64
  5334. for _, item := range flowGood {
  5335. out_count_five += item.Count
  5336. }
  5337. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5338. fmt.Println("out_count_five-------------------", out_count_five)
  5339. fmt.Println("parseIntCount---------------", parseIntCount)
  5340. if out_count_five != parseIntCount {
  5341. //查询耗材最后一次出库记录
  5342. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5343. //查询默认出库仓库库存
  5344. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5345. if len(wareOut) > 0 {
  5346. for _, it := range wareOut {
  5347. //回退库存
  5348. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5349. //删除出库记录
  5350. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5351. }
  5352. }
  5353. timeStr := time.Now().Format("2006-01-02")
  5354. timeArr := strings.Split(timeStr, "-")
  5355. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5356. total = total + 1
  5357. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5358. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5359. number = number + total
  5360. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5361. operation_time := time.Now().Unix()
  5362. creater := c.GetAdminUserInfo().AdminUser.Id
  5363. recordDateStr := time.Now().Format("2006-01-02")
  5364. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5365. nowtime := recordDate.Unix()
  5366. warehouseOut := models.WarehouseOut{
  5367. WarehouseOutOrderNumber: warehousing_out_order,
  5368. OperationTime: operation_time,
  5369. OrgId: adminInfo.CurrentOrgId,
  5370. Creater: creater,
  5371. Ctime: time.Now().Unix(),
  5372. Status: 1,
  5373. WarehouseOutTime: nowtime,
  5374. Type: 1,
  5375. StorehouseId: storeConfig.StorehouseOutInfo,
  5376. IsCheck: 1,
  5377. IsSys: 1,
  5378. }
  5379. //查询是否生成出库单
  5380. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5381. if out.ID == 0 {
  5382. service.AddSigleWarehouseOutOne(&warehouseOut)
  5383. }
  5384. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5385. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5386. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5387. dialyPrepareOne := models.DialysisBeforePrepare{
  5388. GoodTypeId: goodObj.GoodTypeId,
  5389. GoodId: item.ProjectId,
  5390. PatientId: item.PatientId,
  5391. RecordDate: item.RecordDate,
  5392. UserOrgId: adminInfo.CurrentOrgId,
  5393. Count: parseIntCount,
  5394. Ctime: time.Now().Unix(),
  5395. Creater: creater,
  5396. Status: 1,
  5397. StorehouseId: houseConfig.StorehouseOutInfo,
  5398. ProjectId: item.ID,
  5399. }
  5400. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5401. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5402. //查询历史出库数据
  5403. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5404. var out_count int64
  5405. for _, item := range flowGood {
  5406. out_count += item.Count
  5407. }
  5408. //如果历史数和当前数据不想等才进行退库出库
  5409. if out_count != parseIntCount {
  5410. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5411. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5412. detail := models.AutomaticReduceDetail{
  5413. WarehouseOutId: 0,
  5414. WarehouseOutOrderNumber: "",
  5415. PatientId: item.PatientId,
  5416. Ctime: time.Now().Unix(),
  5417. Mtime: 0,
  5418. Status: 1,
  5419. RecordTime: item.RecordDate,
  5420. OrgId: item.UserOrgId,
  5421. GoodId: item.ProjectId,
  5422. GoodTypeId: 0,
  5423. Count: parseIntCount,
  5424. Type: 0,
  5425. ProjectId: item.ID,
  5426. StorehouseId: 0,
  5427. }
  5428. service.CreateAutoDetail(detail)
  5429. //查询剩余库存
  5430. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5431. var sum_count int64
  5432. for _, item := range goodList {
  5433. sum_count += item.StockCount
  5434. }
  5435. //更新剩余库存
  5436. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5437. //耗材
  5438. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5439. }
  5440. }
  5441. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5442. //查询历史出库数据
  5443. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5444. var out_count int64
  5445. for _, item := range flowGood {
  5446. out_count += item.Count
  5447. }
  5448. //如果历史数和当前数据不想等才进行退库出库
  5449. if out_count != parseIntCount {
  5450. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5451. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5452. detail := models.AutomaticReduceDetail{
  5453. WarehouseOutId: 0,
  5454. WarehouseOutOrderNumber: "",
  5455. PatientId: item.PatientId,
  5456. Ctime: time.Now().Unix(),
  5457. Mtime: 0,
  5458. Status: 1,
  5459. RecordTime: item.RecordDate,
  5460. OrgId: item.UserOrgId,
  5461. GoodId: item.ProjectId,
  5462. GoodTypeId: 0,
  5463. Count: parseIntCount,
  5464. Type: 0,
  5465. ProjectId: item.ID,
  5466. StorehouseId: 0,
  5467. }
  5468. service.CreateAutoDetail(detail)
  5469. //查询剩余库存
  5470. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5471. var sum_count int64
  5472. for _, item := range goodList {
  5473. sum_count += item.StockCount
  5474. }
  5475. //更新剩余库存
  5476. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5477. //耗材
  5478. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5479. }
  5480. }
  5481. }
  5482. }
  5483. }
  5484. ////同步到自备药
  5485. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5486. if selfPrescriptionOpen.IsOpen == 1 {
  5487. timeStr := time.Now().Format("2006-01-02")
  5488. timeArr := strings.Split(timeStr, "-")
  5489. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5490. total = total + 1
  5491. operation_time := time.Now().Unix()
  5492. creater := adminInfo.AdminUser.Id
  5493. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5494. warehousing := models.XtSelfDrugWarehouse{
  5495. WarehousingOrder: warehousing_order,
  5496. OperationTime: operation_time,
  5497. OrgId: adminInfo.CurrentOrgId,
  5498. Creater: creater,
  5499. Ctime: time.Now().Unix(),
  5500. Status: 1,
  5501. WarehousingTime: recordDateTime,
  5502. Type: 0,
  5503. StorehouseId: 0,
  5504. IsCheck: 1,
  5505. PatientId: patient_id,
  5506. IsSys: 1,
  5507. }
  5508. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5509. if selfDrugWarehouse.ID == 0 {
  5510. service.AddSelfDrugWarehouse(&warehousing, tx)
  5511. }
  5512. if selfDrugWarehouse.ID > 0 {
  5513. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5514. }
  5515. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5516. fmt.Println(info)
  5517. for _, item := range hisdoctorlist {
  5518. //查询该病人的该药品是否已经入库
  5519. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5520. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5521. var in_count int64
  5522. if len(selfdruginfo) > 0 {
  5523. for _, item := range selfdruginfo {
  5524. var in_count_one int64
  5525. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5526. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5527. }
  5528. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5529. in_count_one = item.WarehousingCount
  5530. }
  5531. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5532. in_count_one = item.WarehousingCount
  5533. }
  5534. in_count += in_count_one
  5535. }
  5536. }
  5537. if selfBasedrug.IsSelfDrug == 1 {
  5538. var total_count int64
  5539. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5540. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5541. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5542. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5543. }
  5544. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5545. total_count += prescribingNumberSeven
  5546. }
  5547. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5548. total_count += prescribingNumberSeven
  5549. }
  5550. //入库
  5551. if total_count > in_count {
  5552. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5553. WarehousingOrder: warehousing_order,
  5554. WarehousingId: info.ID,
  5555. DrugId: item.DrugId,
  5556. Number: "",
  5557. ProductDate: 0,
  5558. ExpiryDate: 0,
  5559. WarehousingCount: total_count - in_count,
  5560. WarehouseingUnit: selfBasedrug.MinUnit,
  5561. Price: 0,
  5562. TotalPrice: 0,
  5563. Status: 1,
  5564. Ctime: time.Now().Unix(),
  5565. Remark: "",
  5566. OrgId: adminInfo.CurrentOrgId,
  5567. Type: 0,
  5568. Manufacturer: selfBasedrug.Manufacturer,
  5569. Dealer: selfBasedrug.Dealer,
  5570. StockMaxNumber: total_count - in_count,
  5571. RetailTotalPrice: 0,
  5572. BatchNumber: "",
  5573. MaxUnit: selfBasedrug.MinUnit,
  5574. MinUnit: selfBasedrug.MinUnit,
  5575. RetailPrice: 0,
  5576. StorehouseId: 0,
  5577. IsCheck: 1,
  5578. StockMinNumber: 0,
  5579. PatientId: patient_id,
  5580. IsSys: 1,
  5581. RecordDate: item.RecordDate,
  5582. AdviceId: item.ID,
  5583. }
  5584. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5585. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5586. Creator := adminInfo.AdminUser.Id
  5587. //查询默认仓库剩余多少库存
  5588. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5589. var sum_count int64
  5590. for _, it := range list {
  5591. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5592. if it.MaxUnit == baseDrug.MaxUnit {
  5593. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5594. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5595. }
  5596. sum_count += it.StockMaxNumber + it.StockMinNumber
  5597. }
  5598. flow := &models.XtSelfDrugFlow{
  5599. WarehousingId: info.ID,
  5600. DrugId: item.DrugId,
  5601. Number: "",
  5602. BatchNumber: "",
  5603. Count: total_count - in_count,
  5604. UserOrgId: adminInfo.CurrentOrgId,
  5605. PatientId: item.PatientId,
  5606. SystemTime: time.Now().Unix(),
  5607. ConsumableType: 1,
  5608. IsSys: 1,
  5609. WarehousingOrder: warehousing_order,
  5610. WarehouseOutId: 0,
  5611. WarehouseOutOrderNumber: "",
  5612. IsEdit: 0,
  5613. CancelStockId: 0,
  5614. CancelOrderNumber: "",
  5615. Manufacturer: selfBasedrug.Manufacturer,
  5616. Dealer: selfBasedrug.Dealer,
  5617. Creator: Creator,
  5618. UpdateCreator: Creator,
  5619. Status: 1,
  5620. Ctime: item.AdviceDate,
  5621. Mtime: 0,
  5622. Price: item.Price,
  5623. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5624. WarehouseOutDetailId: 0,
  5625. CancelOutDetailId: 0,
  5626. ExpireDate: 0,
  5627. ProductDate: 0,
  5628. MaxUnit: selfBasedrug.MinUnit,
  5629. MinUnit: selfBasedrug.MinUnit,
  5630. StorehouseId: 0,
  5631. OverCount: sum_count,
  5632. OperateTime: time.Now().Unix(),
  5633. AdviceId: item.ID,
  5634. }
  5635. service.CreateSelfDrugFlow(flow, tx)
  5636. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5637. var total_count int64 // 入库总数量
  5638. var over_count int64 //剩余库存
  5639. for _, it := range drugInfolist {
  5640. if it.MaxUnit == selfBasedrug.MaxUnit {
  5641. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5642. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5643. }
  5644. }
  5645. for _, it := range drugInfolist {
  5646. total_count += it.WarehousingCount
  5647. over_count += it.StockMaxNumber + it.StockMinNumber
  5648. }
  5649. //查询该仓库是否有默认数据
  5650. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5651. if selfDrugStock.ID == 0 {
  5652. drugStock := models.XtSelfDrugStockCount{
  5653. UserOrgId: item.UserOrgId,
  5654. PatientId: item.PatientId,
  5655. SumInCount: total_count,
  5656. SumOutCount: 0,
  5657. SumCancelCount: 0,
  5658. DrugId: item.DrugId,
  5659. Ctime: time.Now().Unix(),
  5660. Mtime: 0,
  5661. Status: 1,
  5662. FlushCount: over_count,
  5663. SumActOutCount: 0,
  5664. }
  5665. service.CreateSelfDrugStockSum(drugStock, tx)
  5666. }
  5667. if selfDrugStock.ID > 0 {
  5668. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5669. }
  5670. }
  5671. //查询这个单据的出库数量
  5672. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5673. var his_out_count int64
  5674. for _, item := range drugFlowList {
  5675. his_out_count += item.Count
  5676. }
  5677. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5678. if (total_count + his_out_count) <= in_count {
  5679. // 出库
  5680. if total_count < in_count {
  5681. var cha_count int64
  5682. cha_count = in_count - total_count
  5683. var stock_number int64 = 0
  5684. //查询库存是否充足
  5685. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5686. // 将该批次的剩余库存数量转换为拆零数量
  5687. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5688. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5689. }
  5690. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5691. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5692. }
  5693. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5694. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5695. }
  5696. if stock_number >= cha_count {
  5697. var maxNumber int64 = 0
  5698. var minNumber int64 = 0
  5699. maxNumber = cha_count / selfBasedrug.MinNumber
  5700. minNumber = cha_count % selfBasedrug.MinNumber
  5701. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5702. minNumber = maxNumber
  5703. }
  5704. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5705. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5707. return
  5708. }
  5709. }
  5710. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5711. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5712. }
  5713. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5714. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5715. }
  5716. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5717. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5718. }
  5719. if warehouse.StockMaxNumber < 0 {
  5720. warehouse.StockMaxNumber = 0
  5721. }
  5722. if warehouse.StockMinNumber < 0 {
  5723. warehouse.StockMinNumber = 0
  5724. }
  5725. warehouse.Mtime = time.Now().Unix()
  5726. if warehouse.StockMinNumber < minNumber {
  5727. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5728. if warehouse.MaxUnit != warehouse.MinUnit {
  5729. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5730. }
  5731. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5732. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5733. }
  5734. } else {
  5735. if minNumber > 0 {
  5736. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5737. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5738. }
  5739. }
  5740. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5741. if warehouse.StockMinNumber > 0 {
  5742. if warehouse.StockMinNumber-cha_count >= 0 {
  5743. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5744. }
  5745. }
  5746. }
  5747. }
  5748. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5749. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5750. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5751. }
  5752. }
  5753. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5754. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5756. return
  5757. }
  5758. }
  5759. if warehouse.StockMinNumber <= 0 {
  5760. warehouse.StockMinNumber = 0
  5761. }
  5762. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5763. //查询该药品剩余库存
  5764. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5765. var over_count int64
  5766. for _, its := range infolist {
  5767. if its.MaxUnit == selfBasedrug.MaxUnit {
  5768. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5769. }
  5770. over_count += its.StockMaxNumber + its.StockMinNumber
  5771. }
  5772. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5773. drugflow := models.XtSelfDrugFlow{
  5774. WarehouseOutId: 0,
  5775. WarehouseOutOrderNumber: warehousing_order,
  5776. WarehousingOrder: warehousing_order,
  5777. DrugId: item.DrugId,
  5778. Number: warehouse.Number,
  5779. ProductDate: warehouse.ProductDate,
  5780. ExpireDate: warehouse.ExpiryDate,
  5781. Count: cha_count,
  5782. Price: warehouse.RetailPrice,
  5783. Status: 1,
  5784. Ctime: item.AdviceDate,
  5785. Mtime: time.Now().Unix(),
  5786. UserOrgId: item.UserOrgId,
  5787. Manufacturer: warehouse.Manufacturer,
  5788. Dealer: warehouse.Dealer,
  5789. BatchNumber: warehouse.BatchNumber,
  5790. MaxUnit: selfBasedrug.MinUnit,
  5791. ConsumableType: 20,
  5792. IsEdit: 1,
  5793. Creator: 0,
  5794. IsSys: 3,
  5795. WarehouseOutDetailId: drugWareInfo.ID,
  5796. AdviceId: item.ID,
  5797. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5798. StorehouseId: 0,
  5799. AdminUserId: creater,
  5800. LastPrice: warehouse.Price,
  5801. StockCount: "",
  5802. WarehousingDetailId: 0,
  5803. OverCount: over_count,
  5804. RetailPrice: item.Price, //手动出库出库价格
  5805. WarehousingId: warehouse.ID,
  5806. SystemTime: item.AdviceDate,
  5807. PatientId: item.PatientId,
  5808. Remark: "保存处方入库数据差",
  5809. OperateTime: time.Now().Unix(),
  5810. }
  5811. if warehouse.RetailPrice == 0 {
  5812. drugflow.Price = item.Price
  5813. }
  5814. service.CreateSelfDrugFlowOne(drugflow, tx)
  5815. var out_count int64
  5816. out_count = in_count - total_count
  5817. //
  5818. //fmt.Println("in_count------------------", in_count)
  5819. //fmt.Println("total_count------------------", total_count)
  5820. //添加出库数量
  5821. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5822. //查询剩余库存
  5823. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5824. var sum_count int64
  5825. for _, its := range stockInfo {
  5826. if its.MaxUnit == selfBasedrug.MaxUnit {
  5827. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5828. }
  5829. sum_count += its.StockMaxNumber + its.StockMinNumber
  5830. }
  5831. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5832. } else {
  5833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5834. return
  5835. }
  5836. }
  5837. }
  5838. }
  5839. }
  5840. }
  5841. }
  5842. tx.Commit()
  5843. if err == nil {
  5844. c.ServeSuccessJSON(map[string]interface{}{
  5845. "msg": "保存成功",
  5846. })
  5847. return
  5848. } else {
  5849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5850. return
  5851. }
  5852. }
  5853. }
  5854. //func (c *HisApiController) EditHisPrescription() {
  5855. // record_date := c.GetString("record_date")
  5856. // patient_id, _ := c.GetInt64("patient_id")
  5857. // reg_type, _ := c.GetInt64("reg_type")
  5858. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5859. // diagnose := c.GetString("diagnose")
  5860. // sick_type, _ := c.GetInt64("sick_type")
  5861. // sick_history := c.GetString("sick_history")
  5862. // doctor_id, _ := c.GetInt64("doctor", 0)
  5863. // department, _ := c.GetInt64("department", 0)
  5864. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5865. // p_type, _ := c.GetInt64("p_type")
  5866. //
  5867. // dataBody := make(map[string]interface{}, 0)
  5868. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5869. // if err != nil {
  5870. // utils.ErrorLog(err.Error())
  5871. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5872. // return
  5873. // }
  5874. //
  5875. // timeLayout := "2006-01-02"
  5876. // loc, _ := time.LoadLocation("Local")
  5877. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5878. // if err != nil {
  5879. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5880. // return
  5881. // }
  5882. // adminInfo := c.GetAdminUserInfo()
  5883. // recordDateTime := theTime.Unix()
  5884. //
  5885. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5886. //
  5887. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5888. // var hpInfo models.HisPrescriptionInfo
  5889. // if info.ID == 0 {
  5890. // var randNum int
  5891. // randNum = rand.Intn(10000) + 1000
  5892. // timestamp := time.Now().Unix()
  5893. // tempTime := time.Unix(timestamp, 0)
  5894. // timeFormat := tempTime.Format("20060102150405")
  5895. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5896. //
  5897. // hpInfo = models.HisPrescriptionInfo{
  5898. // UserOrgId: adminInfo.CurrentOrgId,
  5899. // RecordDate: theTime.Unix(),
  5900. // PatientId: patient_id,
  5901. // Status: 1,
  5902. // Ctime: time.Now().Unix(),
  5903. // Mtime: time.Now().Unix(),
  5904. // Creator: adminInfo.AdminUser.Id,
  5905. // Modifier: adminInfo.AdminUser.Id,
  5906. // Diagnosis: diagnose,
  5907. // SickHistory: sick_history,
  5908. // Departments: department,
  5909. // RegisterType: reg_type,
  5910. // PrescriptionNumber: p_number,
  5911. // PrescriptionStatus: 1,
  5912. // Doctor: role.UserName,
  5913. // DoctorId: doctor_id,
  5914. // SickType: sick_type,
  5915. // PType: p_type,
  5916. // }
  5917. // service.SavePatientPrescriptionInfo(hpInfo)
  5918. //
  5919. // } else {
  5920. // hpInfo = models.HisPrescriptionInfo{
  5921. // ID: info.ID,
  5922. // UserOrgId: adminInfo.CurrentOrgId,
  5923. // RecordDate: info.RecordDate,
  5924. // PatientId: info.PatientId,
  5925. // Status: 1,
  5926. // Ctime: info.Ctime,
  5927. // Mtime: time.Now().Unix(),
  5928. // Creator: info.Creator,
  5929. // Modifier: adminInfo.AdminUser.Id,
  5930. // Diagnosis: diagnose,
  5931. // SickHistory: sick_history,
  5932. // Departments: department,
  5933. // RegisterType: reg_type,
  5934. // PrescriptionNumber: info.PrescriptionNumber,
  5935. // Doctor: role.UserName,
  5936. // PrescriptionStatus: info.PrescriptionStatus,
  5937. // DoctorId: doctor_id,
  5938. // SickType: sick_type,
  5939. // PType: info.PType,
  5940. // }
  5941. // service.SavePatientPrescriptionInfo(hpInfo)
  5942. // }
  5943. //
  5944. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5945. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5946. //
  5947. // if len(prescriptions) > 0 {
  5948. // for _, item := range prescriptions {
  5949. // items := item.(map[string]interface{})
  5950. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5951. // utils.ErrorLog("id")
  5952. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5953. // return
  5954. // }
  5955. // id := int64(items["id"].(float64))
  5956. //
  5957. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5958. // utils.ErrorLog("type")
  5959. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5960. // return
  5961. // }
  5962. // types := int64(items["type"].(float64))
  5963. //
  5964. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5965. // utils.ErrorLog("med_type")
  5966. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5967. // return
  5968. // }
  5969. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5970. //
  5971. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5972. //
  5973. // ctime := time.Now().Unix()
  5974. //
  5975. // prescription := &models.HisPrescription{
  5976. // ID: id,
  5977. // PatientId: patient_id,
  5978. // UserOrgId: adminInfo.CurrentOrgId,
  5979. // RecordDate: recordDateTime,
  5980. // Ctime: ctime,
  5981. // Mtime: ctime,
  5982. // Type: types,
  5983. // Modifier: adminInfo.AdminUser.Id,
  5984. // Creator: adminInfo.AdminUser.Id,
  5985. // Status: 1,
  5986. // Doctor: role.UserName,
  5987. // HisPatientId: his_patient_id,
  5988. // OrderStatus: 1,
  5989. // BatchNumber: "",
  5990. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5991. // PType: hpInfo.PType,
  5992. // MedType: med_type,
  5993. // }
  5994. //
  5995. // if historyPrescription.ID > 0 {
  5996. // prescription.PreTime = historyPrescription.PreTime
  5997. //
  5998. // }
  5999. //
  6000. // service.SaveHisPrescription(prescription)
  6001. //
  6002. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6003. // advices := items["advices"].([]interface{})
  6004. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6005. // groupNo := int64(0)
  6006. // ctime := time.Now().Unix()
  6007. // mtime := ctime
  6008. // if len(advices) > 0 {
  6009. // for _, advice := range advices {
  6010. // var s models.HisDoctorAdviceInfo
  6011. // s.PrescriptionId = prescription.ID
  6012. // s.AdviceType = 2
  6013. // s.AdviceDoctor = adminInfo.AdminUser.Id
  6014. // s.StopState = 2
  6015. // s.ExecutionState = 2
  6016. // s.AdviceDate = recordDateTime
  6017. // s.Status = 1
  6018. // s.UserOrgId = adminInfo.CurrentOrgId
  6019. // s.RecordDate = recordDateTime
  6020. // s.StartTime = prescription.PreTime
  6021. // s.Groupno = groupNo
  6022. // s.CreatedTime = ctime
  6023. // s.UpdatedTime = mtime
  6024. // s.PatientId = patient_id
  6025. // s.HisPatientId = his_patient_id
  6026. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  6027. // if errcode > 0 {
  6028. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6029. // return
  6030. // }
  6031. //
  6032. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  6033. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  6034. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  6035. // if s.Price == 0 {
  6036. // s.Price = lastWarehouse.RetailPrice
  6037. // }
  6038. // }
  6039. //
  6040. // service.CreateHisDoctorAdvice(&s)
  6041. // //记录日志
  6042. // byterequest, _ := json.Marshal(s)
  6043. // adviceLog := models.XtDoctorAdviceLog{
  6044. // UserOrgId: s.UserOrgId,
  6045. // PatientId: s.PatientId,
  6046. // AdminUserId: adminInfo.AdminUser.Id,
  6047. // Module: 1,
  6048. // ErrLog: string(byterequest),
  6049. // Status: 1,
  6050. // Ctime: time.Now().Unix(),
  6051. // Mtime: 0,
  6052. // Source: "电脑端his医嘱修改",
  6053. // RecordDate: s.AdviceDate,
  6054. // }
  6055. // service.CreateDoctorAdviceLog(adviceLog)
  6056. // redis := service.RedisClient()
  6057. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  6058. // redis.Set(key, "", time.Second)
  6059. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  6060. // fmt.Println("keyOne", keyOne)
  6061. // redis.Set(keyOne, "", time.Second)
  6062. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  6063. // redis.Set(keySeven, "", time.Second)
  6064. // redis.Close()
  6065. //
  6066. // }
  6067. // }
  6068. // }
  6069. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6070. // projects := items["project"].([]interface{})
  6071. // if len(projects) > 0 {
  6072. // for _, project := range projects {
  6073. // var p models.HisPrescriptionProject
  6074. // p.PrescriptionId = prescription.ID
  6075. // p.Ctime = time.Now().Unix()
  6076. // p.Mtime = time.Now().Unix()
  6077. // p.PatientId = patient_id
  6078. // p.RecordDate = recordDateTime
  6079. // p.UserOrgId = adminInfo.CurrentOrgId
  6080. // p.HisPatientId = his_patient_id
  6081. // p.Status = 1
  6082. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  6083. // if errcode > 0 {
  6084. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6085. // return
  6086. // }
  6087. // service.CreateHisProjectTwo(&p)
  6088. //
  6089. // //记录日志
  6090. // byterequest, _ := json.Marshal(p)
  6091. // adviceLog := models.XtDoctorAdviceLog{
  6092. // UserOrgId: p.UserOrgId,
  6093. // PatientId: p.PatientId,
  6094. // AdminUserId: adminInfo.AdminUser.Id,
  6095. // Module: 1,
  6096. // ErrLog: string(byterequest),
  6097. // Status: 1,
  6098. // Ctime: time.Now().Unix(),
  6099. // Mtime: 0,
  6100. // Source: "电脑端his项目修改",
  6101. // RecordDate: p.RecordDate,
  6102. // }
  6103. // service.CreateDoctorAdviceLog(adviceLog)
  6104. // }
  6105. // }
  6106. // }
  6107. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  6108. // addition := items["addition"].([]interface{})
  6109. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6110. // ctime := time.Now().Unix()
  6111. // mtime := ctime
  6112. // if len(addition) > 0 {
  6113. // for _, item := range addition {
  6114. // var s models.HisAdditionalCharge
  6115. // s.PrescriptionId = prescription.ID
  6116. // s.Status = 1
  6117. // s.UserOrgId = adminInfo.CurrentOrgId
  6118. // s.RecordDate = recordDateTime
  6119. // s.CreatedTime = ctime
  6120. // s.UpdatedTime = mtime
  6121. // s.PatientId = patient_id
  6122. // s.HisPatientId = his_patient_id
  6123. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  6124. // if errcode > 0 {
  6125. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6126. // return
  6127. // }
  6128. // service.CreateAdditionalCharge(&s)
  6129. // }
  6130. // }
  6131. // }
  6132. //
  6133. // }
  6134. // }
  6135. // }
  6136. // if err == nil {
  6137. // c.ServeSuccessJSON(map[string]interface{}{
  6138. // "msg": "保存成功",
  6139. // })
  6140. // return
  6141. //
  6142. // } else {
  6143. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6144. // return
  6145. // }
  6146. //}
  6147. func (c *HisApiController) DeletePrescription() {
  6148. prescription_id, _ := c.GetInt64("id")
  6149. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  6150. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  6151. ////同步到自备药
  6152. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6153. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6154. if selfPrescriptionOpen.IsOpen == 1 {
  6155. // 在函数结束时处理事务回滚
  6156. db := service.XTWriteDB()
  6157. tx := db.Begin()
  6158. defer func() {
  6159. if r := recover(); r != nil {
  6160. tx.Rollback()
  6161. } else {
  6162. tx.Commit()
  6163. }
  6164. }()
  6165. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  6166. for _, item := range advicesList {
  6167. timeStr := time.Now().Format("2006-01-02")
  6168. timeArr := strings.Split(timeStr, "-")
  6169. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6170. total = total + 1
  6171. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6172. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6173. number = number + total
  6174. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6175. operation_time := time.Now().Unix()
  6176. creater := c.GetAdminUserInfo().AdminUser.Id
  6177. //创建一个出库单
  6178. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6179. WarehouseOutOrderNumber: warehousing_out_order,
  6180. OperationTime: operation_time,
  6181. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6182. Creater: creater,
  6183. Ctime: time.Now().Unix(),
  6184. Status: 1,
  6185. WarehouseOutTime: item.AdviceDate,
  6186. Type: 0,
  6187. PatientId: item.PatientId,
  6188. IsCheck: 1,
  6189. }
  6190. //查询今日是否有出库数据
  6191. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  6192. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  6193. if lastWarehouseOut.ID == 0 {
  6194. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6195. }
  6196. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  6197. var total_count int64
  6198. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  6199. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6200. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6201. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6202. }
  6203. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6204. total_count += prescribingNumberSeven
  6205. }
  6206. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6207. total_count += prescribingNumberSeven
  6208. }
  6209. //出库
  6210. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6211. WarehouseOutOrderNumber: warehousing_out_order,
  6212. WarehouseOutId: lastWarehouseOut.ID,
  6213. DrugId: item.DrugId,
  6214. Count: total_count,
  6215. Price: 0,
  6216. TotalPrice: 0,
  6217. Status: 1,
  6218. Ctime: item.AdviceDate,
  6219. Mtime: item.AdviceDate,
  6220. Remark: "",
  6221. OrgId: item.UserOrgId,
  6222. Type: 0,
  6223. Manufacturer: selfBasedrug.Manufacturer,
  6224. Dealer: selfBasedrug.Dealer,
  6225. RetailPrice: 0,
  6226. RetailTotalPrice: 0,
  6227. CountUnit: selfBasedrug.MinUnit,
  6228. ExpiryDate: 0,
  6229. ProductDate: 0,
  6230. Number: "",
  6231. BatchNumber: "",
  6232. IsSys: 1,
  6233. WarehouseInfoId: 0,
  6234. AdminUserId: 0,
  6235. StockCount: "",
  6236. IsCheck: 1,
  6237. SysRecordTime: item.AdviceDate,
  6238. PatientId: item.PatientId,
  6239. ClassType: "",
  6240. AdviceId: item.ID,
  6241. }
  6242. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6243. }
  6244. fmt.Println("长度-------------------------------", warehousingOutInfo)
  6245. for _, it := range warehousingOutInfo {
  6246. //查询今日是否有出库数据
  6247. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6248. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6249. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6250. //出库逻辑
  6251. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6252. //查询剩余库存
  6253. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6254. var sum_count int64
  6255. for _, its := range stockInfo {
  6256. if its.MaxUnit == medical.MaxUnit {
  6257. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6258. }
  6259. sum_count += its.StockMaxNumber + its.StockMinNumber
  6260. }
  6261. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6262. }
  6263. }
  6264. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6265. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6266. //耗材保存处方出库
  6267. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6268. //已收费和已发药限制逻辑
  6269. isCharge := false
  6270. isMedicine := false
  6271. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6272. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6273. if new_prescription.IsMedicine == 1 {
  6274. isMedicine = true
  6275. }
  6276. for _, item := range new_prescriptions {
  6277. if item.OrderStatus == 4 {
  6278. isCharge = true
  6279. }
  6280. }
  6281. if p_err != nil {
  6282. if new_prescription.ID > 0 {
  6283. if new_prescription.OrderStatus == 2 {
  6284. isCharge = true
  6285. }
  6286. }
  6287. }
  6288. for _, item := range advices {
  6289. if item.IsMedicine == 1 {
  6290. isMedicine = true
  6291. }
  6292. }
  6293. if isCharge {
  6294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6295. return
  6296. }
  6297. if isMedicine {
  6298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6299. return
  6300. }
  6301. //已收费和已发药限制逻辑
  6302. if len(projects) > 0 {
  6303. for _, item := range projects {
  6304. service.DeletePrintInfo(item.ID) //删除打印信息
  6305. if goodOutConfig.IsOpen != 1 {
  6306. if stockConfig.IsOpen == 1 {
  6307. if item.Type == 3 && item.IsOut == 1 {
  6308. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6309. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6310. good.Total = good.Total + f_count
  6311. service.UpdateGoodInfo(&good)
  6312. operation_time := time.Now().Unix()
  6313. creater := c.GetAdminUserInfo().AdminUser.Id
  6314. //创建退库单
  6315. timeStr := time.Now().Format("2006-01-02")
  6316. timeArr := strings.Split(timeStr, "-")
  6317. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6318. total = total + 1
  6319. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6320. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6321. cancelStock := models.CancelStock{
  6322. OrderNumber: orderNumber,
  6323. OperaTime: operation_time,
  6324. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6325. Creater: creater,
  6326. Ctime: time.Now().Unix(),
  6327. Status: 1,
  6328. ReturnTime: item.RecordDate,
  6329. Type: 1,
  6330. StorehouseId: houseConfig.StorehouseOutInfo,
  6331. IsCheck: 1,
  6332. }
  6333. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6334. if msgerrkonde == gorm.ErrRecordNotFound {
  6335. service.AddSigleCancelStock(&cancelStock)
  6336. }
  6337. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6338. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6339. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6340. //查询该耗材是否出库
  6341. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6342. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6343. deaerler, _ := service.GetDealerById(info.Dealer)
  6344. var total_count int64
  6345. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6346. total_count += count
  6347. if info.ID > 0 {
  6348. if info.Count >= total_count {
  6349. //回退库存
  6350. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6351. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6352. var flush_count int64
  6353. for _, it := range goodList {
  6354. flush_count += it.StockCount
  6355. }
  6356. cancelStockInfo := models.CancelStockInfo{
  6357. GoodId: item.ProjectId,
  6358. CancelStockId: cancel.ID,
  6359. GoodTypeId: good.GoodTypeId,
  6360. Count: prescribingNumber,
  6361. Price: info.Price,
  6362. Total: 0,
  6363. ProductDate: info.ProductDate,
  6364. ExpiryDate: info.ExpiryDate,
  6365. Ctime: time.Now().Unix(),
  6366. Status: 1,
  6367. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6368. OrderNumber: cancel.OrderNumber,
  6369. Type: 0,
  6370. Dealer: deaerler.DealerName,
  6371. Manufacturer: manufacturer.ManufacturerName,
  6372. Number: info.Number,
  6373. RegisterAccount: "",
  6374. Remark: "",
  6375. WarehouseInfoId: info.WarehouseInfotId,
  6376. PatientId: info.PatientId,
  6377. RecordDate: info.SysRecordTime,
  6378. StorehouseId: houseConfig.StorehouseOutInfo,
  6379. IsCheck: 1,
  6380. }
  6381. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6382. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6383. flow := models.VmStockFlow{
  6384. WarehousingId: info.WarehouseInfotId,
  6385. GoodId: item.ProjectId,
  6386. Number: info.Number,
  6387. LicenseNumber: info.LicenseNumber,
  6388. Count: prescribingNumber,
  6389. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6390. PatientId: item.PatientId,
  6391. SystemTime: info.SysRecordTime,
  6392. ConsumableType: 7,
  6393. IsSys: 0,
  6394. WarehousingOrder: "",
  6395. WarehouseOutId: info.WarehouseOutId,
  6396. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6397. IsEdit: 0,
  6398. CancelStockId: cancel.ID,
  6399. CancelOrderNumber: cancel.OrderNumber,
  6400. Manufacturer: manufacturer.ID,
  6401. Dealer: 0,
  6402. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6403. UpdateCreator: 0,
  6404. Status: 1,
  6405. Ctime: time.Now().Unix(),
  6406. Mtime: 0,
  6407. Price: info.Price,
  6408. WarehousingDetailId: info.WarehouseInfotId,
  6409. WarehouseOutDetailId: info.ID,
  6410. CancelOutDetailId: cancelInfo.ID,
  6411. ProductDate: info.ProductDate,
  6412. ExpireDate: info.ExpiryDate,
  6413. StorehouseId: houseConfig.StorehouseOutInfo,
  6414. OverCount: flush_count,
  6415. OperateTime: time.Now().Unix(),
  6416. }
  6417. service.CreateStockFlowOne(flow)
  6418. //退库数量增加
  6419. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6420. //出库数量减少
  6421. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6422. }
  6423. if info.Count < total_count {
  6424. //回退库存
  6425. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6426. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6427. var flush_count int64
  6428. for _, it := range goodList {
  6429. flush_count += it.StockCount
  6430. }
  6431. cancelStockInfo := models.CancelStockInfo{
  6432. GoodId: item.ProjectId,
  6433. CancelStockId: cancel.ID,
  6434. GoodTypeId: good.GoodTypeId,
  6435. Count: info.Count,
  6436. Price: info.Price,
  6437. Total: 0,
  6438. ProductDate: info.ProductDate,
  6439. ExpiryDate: info.ExpiryDate,
  6440. Ctime: time.Now().Unix(),
  6441. Status: 1,
  6442. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6443. OrderNumber: cancel.OrderNumber,
  6444. Type: 0,
  6445. Dealer: deaerler.DealerName,
  6446. Manufacturer: manufacturer.ManufacturerName,
  6447. Number: info.Number,
  6448. RegisterAccount: "",
  6449. Remark: "",
  6450. WarehouseInfoId: info.WarehouseInfotId,
  6451. PatientId: info.PatientId,
  6452. RecordDate: info.SysRecordTime,
  6453. StorehouseId: houseConfig.StorehouseOutInfo,
  6454. IsCheck: 1,
  6455. }
  6456. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6457. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6458. flow := models.VmStockFlow{
  6459. WarehousingId: info.WarehouseInfotId,
  6460. GoodId: item.ProjectId,
  6461. Number: info.Number,
  6462. LicenseNumber: info.LicenseNumber,
  6463. Count: info.Count,
  6464. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6465. PatientId: item.PatientId,
  6466. SystemTime: info.SysRecordTime,
  6467. ConsumableType: 7,
  6468. IsSys: 0,
  6469. WarehousingOrder: "",
  6470. WarehouseOutId: info.WarehouseOutId,
  6471. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6472. IsEdit: 0,
  6473. CancelStockId: cancel.ID,
  6474. CancelOrderNumber: cancel.OrderNumber,
  6475. Manufacturer: manufacturer.ID,
  6476. Dealer: 0,
  6477. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6478. UpdateCreator: 0,
  6479. Status: 1,
  6480. Ctime: time.Now().Unix(),
  6481. Mtime: 0,
  6482. Price: info.Price,
  6483. WarehousingDetailId: info.WarehouseInfotId,
  6484. WarehouseOutDetailId: info.ID,
  6485. CancelOutDetailId: cancelInfo.ID,
  6486. ProductDate: info.ProductDate,
  6487. ExpireDate: info.ExpiryDate,
  6488. StorehouseId: houseConfig.StorehouseOutInfo,
  6489. OverCount: flush_count,
  6490. OperateTime: time.Now().Unix(),
  6491. }
  6492. service.CreateStockFlowOne(flow)
  6493. //退库数量增加
  6494. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6495. //出库数量减少
  6496. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6497. }
  6498. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6499. var flush_count int64
  6500. for _, it := range goodList {
  6501. flush_count += it.StockCount
  6502. }
  6503. //查询已出库数量
  6504. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6505. if prescribingNumber < dialysisInfo.Count {
  6506. //改变数量
  6507. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6508. }
  6509. if prescribingNumber >= dialysisInfo.Count {
  6510. //删除出库表
  6511. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6512. }
  6513. //更新库存
  6514. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6515. //更新基础库库存
  6516. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6517. }
  6518. }
  6519. }
  6520. }
  6521. //保存耗材出库
  6522. if goodOutConfig.IsOpen == 1 {
  6523. if item.Type == 3 {
  6524. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6525. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6526. good.Total = good.Total + f_count
  6527. service.UpdateGoodInfo(&good)
  6528. operation_time := time.Now().Unix()
  6529. creater := c.GetAdminUserInfo().AdminUser.Id
  6530. //创建退库单
  6531. timeStr := time.Now().Format("2006-01-02")
  6532. timeArr := strings.Split(timeStr, "-")
  6533. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6534. total = total + 1
  6535. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6536. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6537. cancelStock := models.CancelStock{
  6538. OrderNumber: orderNumber,
  6539. OperaTime: operation_time,
  6540. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6541. Creater: creater,
  6542. Ctime: time.Now().Unix(),
  6543. Status: 1,
  6544. ReturnTime: item.RecordDate,
  6545. Type: 1,
  6546. StorehouseId: houseConfig.StorehouseOutInfo,
  6547. IsCheck: 1,
  6548. }
  6549. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6550. if msgerrkonde == gorm.ErrRecordNotFound {
  6551. service.AddSigleCancelStock(&cancelStock)
  6552. }
  6553. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6554. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6555. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6556. //查询该耗材是否出库
  6557. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6558. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6559. deaerler, _ := service.GetDealerById(info.Dealer)
  6560. var total_count int64
  6561. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6562. total_count += count
  6563. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6564. var flush_count int64
  6565. for _, it := range goodList {
  6566. flush_count += it.StockCount
  6567. }
  6568. fmt.Println("历史出库数据", info.Count)
  6569. fmt.Println("出库数量", total_count)
  6570. if info.ID > 0 {
  6571. cancelStockInfo := models.CancelStockInfo{
  6572. GoodId: item.ProjectId,
  6573. CancelStockId: cancel.ID,
  6574. GoodTypeId: good.GoodTypeId,
  6575. Count: prescribingNumber,
  6576. Price: info.Price,
  6577. Total: 0,
  6578. ProductDate: info.ProductDate,
  6579. ExpiryDate: info.ExpiryDate,
  6580. Ctime: time.Now().Unix(),
  6581. Status: 1,
  6582. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6583. OrderNumber: cancel.OrderNumber,
  6584. Type: 0,
  6585. Dealer: deaerler.DealerName,
  6586. Manufacturer: manufacturer.ManufacturerName,
  6587. Number: info.Number,
  6588. RegisterAccount: "",
  6589. Remark: "",
  6590. WarehouseInfoId: info.WarehouseInfotId,
  6591. PatientId: info.PatientId,
  6592. RecordDate: info.SysRecordTime,
  6593. StorehouseId: houseConfig.StorehouseOutInfo,
  6594. IsCheck: 1,
  6595. }
  6596. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6597. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6598. //查询出库数量
  6599. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6600. //出库数据 大于 退库数量
  6601. if len(list) > 0 {
  6602. for _, it := range list {
  6603. //回退库存
  6604. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6605. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6606. var flush_count_one int64
  6607. for _, it := range goodList {
  6608. flush_count_one += it.StockCount
  6609. }
  6610. //查询该批次是否有退库数据
  6611. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6612. creater := c.GetAdminUserInfo().AdminUser.Id
  6613. flow := models.VmStockFlow{
  6614. WarehousingId: it.WarehouseInfotId,
  6615. GoodId: it.GoodId,
  6616. Number: it.Number,
  6617. LicenseNumber: it.LicenseNumber,
  6618. Count: it.Count,
  6619. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6620. PatientId: it.PatientId,
  6621. SystemTime: it.SysRecordTime,
  6622. ConsumableType: 7,
  6623. IsSys: 0,
  6624. WarehousingOrder: "",
  6625. WarehouseOutId: it.WarehouseOutId,
  6626. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6627. IsEdit: 0,
  6628. CancelStockId: cancel.ID,
  6629. CancelOrderNumber: cancel.OrderNumber,
  6630. Manufacturer: manufacturer.ID,
  6631. Dealer: 0,
  6632. Creator: creater,
  6633. UpdateCreator: 0,
  6634. Status: 1,
  6635. Ctime: time.Now().Unix(),
  6636. Mtime: 0,
  6637. Price: it.Price,
  6638. WarehousingDetailId: it.WarehouseInfotId,
  6639. WarehouseOutDetailId: it.ID,
  6640. CancelOutDetailId: cancelInfo.ID,
  6641. ProductDate: it.ProductDate,
  6642. ExpireDate: it.ExpiryDate,
  6643. StorehouseId: houseConfig.StorehouseOutInfo,
  6644. OverCount: flush_count_one,
  6645. OperateTime: time.Now().Unix(),
  6646. }
  6647. service.CreateStockFlowOne(flow)
  6648. //if flow.ID > 0 {
  6649. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6650. //}
  6651. }
  6652. }
  6653. //flow := models.VmStockFlow{
  6654. // WarehousingId: info.WarehouseInfotId,
  6655. // GoodId: item.ProjectId,
  6656. // Number: info.Number,
  6657. // LicenseNumber: info.LicenseNumber,
  6658. // Count: prescribingNumber,
  6659. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6660. // PatientId: item.PatientId,
  6661. // SystemTime: info.SysRecordTime,
  6662. // ConsumableType: 7,
  6663. // IsSys: 0,
  6664. // WarehousingOrder: "",
  6665. // WarehouseOutId: info.WarehouseOutId,
  6666. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6667. // IsEdit: 0,
  6668. // CancelStockId: cancel.ID,
  6669. // CancelOrderNumber: cancel.OrderNumber,
  6670. // Manufacturer: manufacturer.ID,
  6671. // Dealer: 0,
  6672. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6673. // UpdateCreator: 0,
  6674. // Status: 1,
  6675. // Ctime: time.Now().Unix(),
  6676. // Mtime: 0,
  6677. // Price: info.Price,
  6678. // WarehousingDetailId: info.WarehouseInfotId,
  6679. // WarehouseOutDetailId: info.ID,
  6680. // CancelOutDetailId: cancelInfo.ID,
  6681. // ProductDate: info.ProductDate,
  6682. // ExpireDate: info.ExpiryDate,
  6683. // StorehouseId: houseConfig.StorehouseOutInfo,
  6684. // OverCount: flush_count,
  6685. //}
  6686. //service.CreateStockFlowOne(flow)
  6687. //退库数量增加
  6688. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6689. //出库数量减少
  6690. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6691. //查询已出库数量
  6692. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6693. if prescribingNumber < dialysisInfo.Count {
  6694. //改变数量
  6695. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6696. }
  6697. if prescribingNumber >= dialysisInfo.Count {
  6698. //删除出库表
  6699. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6700. }
  6701. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6702. var flush_count_one int64
  6703. for _, it := range goodList {
  6704. flush_count_one += it.StockCount
  6705. }
  6706. //更新库存
  6707. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6708. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6709. //更新基础库库存
  6710. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6711. }
  6712. }
  6713. }
  6714. }
  6715. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6716. fmt.Println(err)
  6717. }
  6718. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6719. fmt.Println(err)
  6720. if len(advices) > 0 {
  6721. for _, item := range advices {
  6722. redis := service.RedisClient()
  6723. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6724. redis.Set(keyFive, "", time.Second)
  6725. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6726. redis.Set(keyOne, "", time.Second)
  6727. redis.Close()
  6728. }
  6729. }
  6730. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6731. if len(advices) > 0 {
  6732. for _, item := range advices {
  6733. creater := c.GetAdminUserInfo().AdminUser.Id
  6734. service.DrugAutoAddCancelInfo(item, creater)
  6735. }
  6736. }
  6737. } else {
  6738. if drugOutConfig.IsOpen == 1 {
  6739. if len(advices) > 0 {
  6740. for _, item := range advices {
  6741. creater := c.GetAdminUserInfo().AdminUser.Id
  6742. service.DrugAutoAddCancelInfo(item, creater)
  6743. }
  6744. }
  6745. } else {
  6746. if len(advices) > 0 {
  6747. for _, item := range advices {
  6748. creater := c.GetAdminUserInfo().AdminUser.Id
  6749. service.DrugAutoAddCancelInfo(item, creater)
  6750. }
  6751. }
  6752. }
  6753. }
  6754. c.ServeSuccessJSON(map[string]interface{}{
  6755. "msg": "删除成功",
  6756. })
  6757. return
  6758. }
  6759. func (c *HisApiController) DeleteDoctorAdvice() {
  6760. id, _ := c.GetInt64("id")
  6761. advice, _ := service.GetHisDoctorAdvicesById(id)
  6762. ////同步到自备药
  6763. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6764. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6765. if selfPrescriptionOpen.IsOpen == 1 {
  6766. db := service.XTWriteDB()
  6767. tx := db.Begin()
  6768. defer func() {
  6769. if r := recover(); r != nil {
  6770. tx.Rollback()
  6771. } else {
  6772. tx.Commit()
  6773. }
  6774. }()
  6775. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6776. var total_count int64
  6777. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6778. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6779. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6780. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6781. }
  6782. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6783. total_count += prescribingNumberSeven
  6784. }
  6785. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6786. total_count += prescribingNumberSeven
  6787. }
  6788. timeStr := time.Now().Format("2006-01-02")
  6789. timeArr := strings.Split(timeStr, "-")
  6790. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6791. total = total + 1
  6792. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6793. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6794. number = number + total
  6795. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6796. operation_time := time.Now().Unix()
  6797. creater := c.GetAdminUserInfo().AdminUser.Id
  6798. //创建一个出库单
  6799. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6800. WarehouseOutOrderNumber: warehousing_out_order,
  6801. OperationTime: operation_time,
  6802. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6803. Creater: creater,
  6804. Ctime: time.Now().Unix(),
  6805. Status: 1,
  6806. WarehouseOutTime: advice.AdviceDate,
  6807. Type: 0,
  6808. PatientId: advice.PatientId,
  6809. IsCheck: 1,
  6810. }
  6811. //查询今日是否有出库数据
  6812. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6813. if lastWarehouseOut.ID == 0 {
  6814. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6815. }
  6816. //出库
  6817. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6818. WarehouseOutId: lastWarehouseOut.ID,
  6819. WarehouseOutOrderNumber: warehousing_out_order,
  6820. DrugId: advice.DrugId,
  6821. Count: total_count,
  6822. Price: 0,
  6823. TotalPrice: 0,
  6824. Status: 1,
  6825. Ctime: advice.AdviceDate,
  6826. Mtime: advice.AdviceDate,
  6827. Remark: "",
  6828. OrgId: advice.UserOrgId,
  6829. Type: 0,
  6830. Manufacturer: selfBasedrug.Manufacturer,
  6831. Dealer: selfBasedrug.Dealer,
  6832. RetailPrice: 0,
  6833. RetailTotalPrice: 0,
  6834. CountUnit: advice.PrescribingNumberUnit,
  6835. ExpiryDate: 0,
  6836. ProductDate: 0,
  6837. Number: "",
  6838. BatchNumber: "",
  6839. IsSys: 0,
  6840. WarehouseInfoId: 0,
  6841. AdminUserId: 0,
  6842. StockCount: "",
  6843. IsCheck: 1,
  6844. SysRecordTime: advice.AdviceDate,
  6845. PatientId: advice.PatientId,
  6846. AdviceId: advice.ID,
  6847. ClassType: "",
  6848. }
  6849. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6850. for _, it := range warehousingOutInfo {
  6851. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6852. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6853. //出库逻辑
  6854. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6855. //查询剩余库存
  6856. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6857. var sum_count int64
  6858. for _, its := range stockInfo {
  6859. if its.MaxUnit == medical.MaxUnit {
  6860. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6861. }
  6862. sum_count += its.StockMaxNumber + its.StockMinNumber
  6863. }
  6864. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6865. }
  6866. }
  6867. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6868. //已收费和已发药的限制逻辑
  6869. isCharge := false
  6870. isMedicine := false
  6871. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6872. //获取今天该患者所有处方,判断是否发药或者收费
  6873. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6874. //for _, item := range new_prescriptions {
  6875. if new_prescription.IsMedicine == 1 {
  6876. isMedicine = true
  6877. }
  6878. //}
  6879. for _, item := range new_prescriptions {
  6880. if item.OrderStatus == 4 {
  6881. isCharge = true
  6882. }
  6883. }
  6884. if isMedicine {
  6885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6886. return
  6887. }
  6888. if isCharge {
  6889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6890. return
  6891. }
  6892. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6893. creater := c.GetAdminUserInfo().AdminUser.Id
  6894. for _, item := range advices {
  6895. if item.IsMedicine == 1 {
  6896. isMedicine = true
  6897. }
  6898. byterequest, _ := json.Marshal(item)
  6899. adviceLog := models.XtDoctorAdviceLog{
  6900. UserOrgId: item.UserOrgId,
  6901. PatientId: item.PatientId,
  6902. AdminUserId: creater,
  6903. Module: 1,
  6904. ErrLog: string(byterequest),
  6905. Status: 1,
  6906. Ctime: time.Now().Unix(),
  6907. Mtime: 0,
  6908. Source: "电脑端删除医嘱",
  6909. RecordDate: item.AdviceDate,
  6910. }
  6911. service.CreateDoctorAdviceLog(adviceLog)
  6912. }
  6913. if isMedicine {
  6914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6915. return
  6916. }
  6917. if new_prescription.ID > 0 {
  6918. if new_prescription.OrderStatus == 2 {
  6919. isCharge = true
  6920. }
  6921. }
  6922. if isCharge {
  6923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6924. return
  6925. }
  6926. //已收费和已发药的限制逻辑
  6927. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6928. redis := service.RedisClient()
  6929. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6930. redis.Set(keyFive, "", time.Second)
  6931. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6932. redis.Set(keyOne, "", time.Second)
  6933. defer redis.Close()
  6934. if err == nil {
  6935. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6936. //查询是否在处方中出库
  6937. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6938. if openConfig.IsOpen != 1 {
  6939. //判断该医嘱是否执行了
  6940. if advice.ExecutionState == 1 {
  6941. creater := c.GetAdminUserInfo().AdminUser.Id
  6942. service.DrugAutoAddCancelInfo(&advice, creater)
  6943. }
  6944. }
  6945. //开启保存处方扣减功能
  6946. if openConfig.IsOpen == 1 {
  6947. creater := c.GetAdminUserInfo().AdminUser.Id
  6948. service.DrugAutoAddCancelInfo(&advice, creater)
  6949. }
  6950. } else {
  6951. if drugOutConfig.IsOpen == 1 {
  6952. //查询是否在处方中出库
  6953. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6954. if openConfig.IsOpen != 1 {
  6955. //判断该医嘱是否执行了
  6956. if advice.ExecutionState == 1 {
  6957. creater := c.GetAdminUserInfo().AdminUser.Id
  6958. service.DrugAutoAddCancelInfo(&advice, creater)
  6959. }
  6960. }
  6961. //开启保存处方扣减功能
  6962. if openConfig.IsOpen == 1 {
  6963. creater := c.GetAdminUserInfo().AdminUser.Id
  6964. service.DrugAutoAddCancelInfo(&advice, creater)
  6965. }
  6966. } else {
  6967. //判断该医嘱是否执行了
  6968. if advice.ExecutionState == 1 {
  6969. creater := c.GetAdminUserInfo().AdminUser.Id
  6970. service.DrugAutoAddCancelInfo(&advice, creater)
  6971. }
  6972. }
  6973. }
  6974. c.ServeSuccessJSON(map[string]interface{}{
  6975. "msg": "删除成功",
  6976. })
  6977. return
  6978. } else {
  6979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6980. return
  6981. }
  6982. }
  6983. func (c *HisApiController) DeleteProject() {
  6984. id, _ := c.GetInt64("id")
  6985. adminInfo := c.GetAdminUserInfo()
  6986. project, _ := service.GetHisProjectByID(id)
  6987. // var consumable models.DialysisBeforePrepare
  6988. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6989. //耗材保存处方出库
  6990. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6991. isCharge := false
  6992. isMedicine := false
  6993. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6994. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6995. creater := c.GetAdminUserInfo().AdminUser.Id
  6996. for _, item := range new_prescriptions {
  6997. if item.IsMedicine == 1 {
  6998. isMedicine = true
  6999. }
  7000. byterequest, _ := json.Marshal(item)
  7001. adviceLog := models.XtDoctorAdviceLog{
  7002. UserOrgId: item.UserOrgId,
  7003. PatientId: item.PatientId,
  7004. AdminUserId: creater,
  7005. Module: 1,
  7006. ErrLog: string(byterequest),
  7007. Status: 1,
  7008. Ctime: time.Now().Unix(),
  7009. Mtime: 0,
  7010. Source: "电脑端删除医嘱",
  7011. RecordDate: item.RecordDate,
  7012. }
  7013. service.CreateDoctorAdviceLog(adviceLog)
  7014. }
  7015. for _, item := range new_prescriptions {
  7016. if item.OrderStatus == 4 {
  7017. isCharge = true
  7018. }
  7019. }
  7020. if isMedicine {
  7021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  7022. return
  7023. }
  7024. if isCharge {
  7025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  7026. return
  7027. }
  7028. if new_prescription.ID > 0 {
  7029. if new_prescription.OrderStatus == 2 {
  7030. isCharge = true
  7031. }
  7032. }
  7033. if isCharge {
  7034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  7035. return
  7036. }
  7037. service.DeletePrintInfo(id)
  7038. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  7039. label.Status = 0
  7040. service.CreateHisLabelRecordTwo(&label)
  7041. fmt.Println(goodOutConfig.IsOpen)
  7042. if goodOutConfig.IsOpen != 1 {
  7043. if stockConfig.IsOpen == 1 {
  7044. if project.Type == 2 {
  7045. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7046. fmt.Println(err)
  7047. }
  7048. if project.Type == 3 && project.IsOut == 1 {
  7049. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7050. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7051. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7052. operation_time := time.Now().Unix()
  7053. creater := adminInfo.AdminUser.Id
  7054. //创建退库单
  7055. timeStr := time.Now().Format("2006-01-02")
  7056. timeArr := strings.Split(timeStr, "-")
  7057. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7058. total = total + 1
  7059. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7060. cancelStock := models.CancelStock{
  7061. OrderNumber: orderNumber,
  7062. OperaTime: operation_time,
  7063. OrgId: adminInfo.CurrentOrgId,
  7064. Creater: creater,
  7065. Ctime: time.Now().Unix(),
  7066. Status: 1,
  7067. ReturnTime: project.RecordDate,
  7068. Type: 1,
  7069. StorehouseId: houseConfig.StorehouseOutInfo,
  7070. IsCheck: 1,
  7071. }
  7072. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7073. if msgerrkonde == gorm.ErrRecordNotFound {
  7074. service.AddSigleCancelStock(&cancelStock)
  7075. }
  7076. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7077. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7078. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7079. //查询是否有出库
  7080. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7081. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7082. deaerler, _ := service.GetDealerById(info.Dealer)
  7083. if info.ID > 0 {
  7084. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7085. if info.Count >= prescribingNumber {
  7086. cancelStockInfo := models.CancelStockInfo{
  7087. GoodId: project.ProjectId,
  7088. CancelStockId: cancel.ID,
  7089. GoodTypeId: good.GoodTypeId,
  7090. Count: prescribingNumber,
  7091. Price: info.Price,
  7092. Total: 0,
  7093. ProductDate: info.ProductDate,
  7094. ExpiryDate: info.ExpiryDate,
  7095. Ctime: time.Now().Unix(),
  7096. Status: 1,
  7097. OrgId: adminInfo.CurrentOrgId,
  7098. OrderNumber: cancel.OrderNumber,
  7099. Type: 0,
  7100. Dealer: deaerler.DealerName,
  7101. Manufacturer: manufacturer.ManufacturerName,
  7102. Number: info.Number,
  7103. RegisterAccount: "",
  7104. Remark: "",
  7105. WarehouseInfoId: info.WarehouseInfotId,
  7106. PatientId: info.PatientId,
  7107. RecordDate: info.SysRecordTime,
  7108. StorehouseId: houseConfig.StorehouseOutInfo,
  7109. IsCheck: 1,
  7110. }
  7111. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7112. //回退库存
  7113. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  7114. //退库数量增加
  7115. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7116. //出库数量减少
  7117. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7118. }
  7119. if info.Count < prescribingNumber {
  7120. cancelStockInfo := models.CancelStockInfo{
  7121. GoodId: project.ProjectId,
  7122. CancelStockId: cancel.ID,
  7123. GoodTypeId: good.GoodTypeId,
  7124. Count: info.Count,
  7125. Price: info.Price,
  7126. Total: 0,
  7127. ProductDate: info.ProductDate,
  7128. ExpiryDate: info.ExpiryDate,
  7129. Ctime: time.Now().Unix(),
  7130. Status: 1,
  7131. OrgId: adminInfo.CurrentOrgId,
  7132. OrderNumber: cancel.OrderNumber,
  7133. Type: 0,
  7134. Dealer: deaerler.DealerName,
  7135. Manufacturer: manufacturer.ManufacturerName,
  7136. Number: info.Number,
  7137. RegisterAccount: "",
  7138. Remark: "",
  7139. WarehouseInfoId: info.WarehouseInfotId,
  7140. PatientId: info.PatientId,
  7141. RecordDate: info.SysRecordTime,
  7142. StorehouseId: houseConfig.StorehouseOutInfo,
  7143. IsCheck: 1,
  7144. }
  7145. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7146. //回退库存
  7147. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7148. //退库数量增加
  7149. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  7150. //出库数量减少
  7151. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  7152. }
  7153. //查询剩余库存
  7154. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7155. var over_count int64
  7156. for _, it := range goodList {
  7157. over_count += it.StockCount
  7158. }
  7159. //出库数据 大于 退库数量
  7160. if info.Count >= prescribingNumber {
  7161. flow := models.VmStockFlow{
  7162. WarehousingId: info.WarehouseInfotId,
  7163. GoodId: project.ProjectId,
  7164. Number: info.Number,
  7165. LicenseNumber: info.LicenseNumber,
  7166. Count: prescribingNumber,
  7167. UserOrgId: adminInfo.CurrentOrgId,
  7168. PatientId: project.PatientId,
  7169. SystemTime: info.SysRecordTime,
  7170. ConsumableType: 7,
  7171. IsSys: 0,
  7172. WarehousingOrder: "",
  7173. WarehouseOutId: info.WarehouseOutId,
  7174. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7175. IsEdit: 0,
  7176. CancelStockId: cancel.ID,
  7177. CancelOrderNumber: cancel.OrderNumber,
  7178. Manufacturer: manufacturer.ID,
  7179. Dealer: 0,
  7180. Creator: adminInfo.AdminUser.Id,
  7181. UpdateCreator: 0,
  7182. Status: 1,
  7183. Ctime: time.Now().Unix(),
  7184. Mtime: 0,
  7185. Price: info.Price,
  7186. WarehousingDetailId: info.WarehouseInfotId,
  7187. WarehouseOutDetailId: info.ID,
  7188. CancelOutDetailId: cancelInfo.ID,
  7189. ProductDate: info.ProductDate,
  7190. ExpireDate: info.ExpiryDate,
  7191. StorehouseId: houseConfig.StorehouseOutInfo,
  7192. OverCount: over_count,
  7193. OperateTime: time.Now().Unix(),
  7194. }
  7195. service.CreateStockFlowOne(flow)
  7196. }
  7197. //出库数据小于退库数据
  7198. if info.Count < prescribingNumber {
  7199. flow := models.VmStockFlow{
  7200. WarehousingId: info.WarehouseInfotId,
  7201. GoodId: project.ProjectId,
  7202. Number: info.Number,
  7203. LicenseNumber: info.LicenseNumber,
  7204. Count: info.Count,
  7205. UserOrgId: adminInfo.CurrentOrgId,
  7206. PatientId: project.PatientId,
  7207. SystemTime: info.SysRecordTime,
  7208. ConsumableType: 7,
  7209. IsSys: 0,
  7210. WarehousingOrder: "",
  7211. WarehouseOutId: info.WarehouseOutId,
  7212. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7213. IsEdit: 0,
  7214. CancelStockId: cancel.ID,
  7215. CancelOrderNumber: cancel.OrderNumber,
  7216. Manufacturer: manufacturer.ID,
  7217. Dealer: 0,
  7218. Creator: adminInfo.AdminUser.Id,
  7219. UpdateCreator: 0,
  7220. Status: 1,
  7221. Ctime: time.Now().Unix(),
  7222. Mtime: 0,
  7223. Price: info.Price,
  7224. WarehousingDetailId: info.WarehouseInfotId,
  7225. WarehouseOutDetailId: info.ID,
  7226. CancelOutDetailId: cancelInfo.ID,
  7227. ProductDate: info.ProductDate,
  7228. ExpireDate: info.ExpiryDate,
  7229. StorehouseId: houseConfig.StorehouseOutInfo,
  7230. OverCount: over_count,
  7231. OperateTime: time.Now().Unix(),
  7232. }
  7233. service.CreateStockFlowOne(flow)
  7234. }
  7235. //查询已出库数量
  7236. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7237. if prescribingNumber < dialysisInfo.Count {
  7238. //改变数量
  7239. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7240. }
  7241. if prescribingNumber >= dialysisInfo.Count {
  7242. //删除出库表
  7243. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7244. }
  7245. //更新剩余库存
  7246. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7247. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7248. var total_count_one int64
  7249. for _, it := range stockList {
  7250. total_count_one += it.StockCount
  7251. }
  7252. //基础库插入数据
  7253. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7254. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7255. var flush_count int64
  7256. for _, it := range goodListOne {
  7257. flush_count += it.StockCount
  7258. }
  7259. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7260. if errs != nil {
  7261. goodErrcode := models.XtGoodErrcode{
  7262. UserOrgId: project.UserOrgId,
  7263. Errcode: "手动出库更新剩余出库失败",
  7264. GoodId: project.ProjectId,
  7265. Status: 1,
  7266. Ctime: time.Now().Unix(),
  7267. Mtime: 0,
  7268. Count: 0,
  7269. StockCount: 0,
  7270. Creater: creater,
  7271. BatchNumberId: 0,
  7272. WarehouseOutId: 0,
  7273. }
  7274. service.CreateGoodErrcode(goodErrcode)
  7275. }
  7276. }
  7277. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7278. fmt.Println(err)
  7279. } else {
  7280. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7281. fmt.Println(err)
  7282. }
  7283. } else {
  7284. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7285. fmt.Println(err)
  7286. }
  7287. }
  7288. //保存处方出库
  7289. if goodOutConfig.IsOpen == 1 {
  7290. if project.Type == 3 {
  7291. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7292. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7293. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7294. operation_time := time.Now().Unix()
  7295. creater := adminInfo.AdminUser.Id
  7296. //创建退库单
  7297. timeStr := time.Now().Format("2006-01-02")
  7298. timeArr := strings.Split(timeStr, "-")
  7299. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7300. total = total + 1
  7301. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7302. cancelStock := models.CancelStock{
  7303. OrderNumber: orderNumber,
  7304. OperaTime: operation_time,
  7305. OrgId: adminInfo.CurrentOrgId,
  7306. Creater: creater,
  7307. Ctime: time.Now().Unix(),
  7308. Status: 1,
  7309. ReturnTime: project.RecordDate,
  7310. Type: 1,
  7311. StorehouseId: houseConfig.StorehouseOutInfo,
  7312. IsCheck: 1,
  7313. }
  7314. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7315. if msgerrkonde == gorm.ErrRecordNotFound {
  7316. service.AddSigleCancelStock(&cancelStock)
  7317. }
  7318. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7319. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7320. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7321. //获取出库数据
  7322. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7323. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7324. deaerler, _ := service.GetDealerById(info.Dealer)
  7325. if info.ID > 0 {
  7326. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7327. if info.Count >= prescribingNumber {
  7328. cancelStockInfo := models.CancelStockInfo{
  7329. GoodId: project.ProjectId,
  7330. CancelStockId: cancel.ID,
  7331. GoodTypeId: good.GoodTypeId,
  7332. Count: prescribingNumber,
  7333. Price: info.Price,
  7334. Total: 0,
  7335. ProductDate: info.ProductDate,
  7336. ExpiryDate: info.ExpiryDate,
  7337. Ctime: time.Now().Unix(),
  7338. Status: 1,
  7339. OrgId: adminInfo.CurrentOrgId,
  7340. OrderNumber: cancel.OrderNumber,
  7341. Type: 0,
  7342. Dealer: deaerler.DealerName,
  7343. Manufacturer: manufacturer.ManufacturerName,
  7344. Number: info.Number,
  7345. RegisterAccount: "",
  7346. Remark: "",
  7347. WarehouseInfoId: info.WarehouseInfotId,
  7348. PatientId: info.PatientId,
  7349. RecordDate: info.SysRecordTime,
  7350. StorehouseId: houseConfig.StorehouseOutInfo,
  7351. IsCheck: 1,
  7352. }
  7353. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7354. //退库数量增加
  7355. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7356. //出库数量减少
  7357. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7358. }
  7359. if info.Count < prescribingNumber {
  7360. cancelStockInfo := models.CancelStockInfo{
  7361. GoodId: project.ProjectId,
  7362. CancelStockId: cancel.ID,
  7363. GoodTypeId: good.GoodTypeId,
  7364. Count: prescribingNumber,
  7365. Price: info.Price,
  7366. Total: 0,
  7367. ProductDate: info.ProductDate,
  7368. ExpiryDate: info.ExpiryDate,
  7369. Ctime: time.Now().Unix(),
  7370. Status: 1,
  7371. OrgId: adminInfo.CurrentOrgId,
  7372. OrderNumber: cancel.OrderNumber,
  7373. Type: 0,
  7374. Dealer: deaerler.DealerName,
  7375. Manufacturer: manufacturer.ManufacturerName,
  7376. Number: info.Number,
  7377. RegisterAccount: "",
  7378. Remark: "",
  7379. WarehouseInfoId: info.WarehouseInfotId,
  7380. PatientId: info.PatientId,
  7381. RecordDate: info.SysRecordTime,
  7382. StorehouseId: houseConfig.StorehouseOutInfo,
  7383. IsCheck: 1,
  7384. }
  7385. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7386. //回退库存
  7387. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7388. }
  7389. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7390. var over_count int64
  7391. for _, it := range goodList {
  7392. over_count += it.StockCount
  7393. }
  7394. //查询出库数量
  7395. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7396. //出库数据 大于 退库数量
  7397. if len(list) > 0 {
  7398. for _, it := range list {
  7399. //回退库存
  7400. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7401. //退库数量增加
  7402. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7403. //出库数量减少
  7404. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7405. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7406. var over_count_one int64
  7407. for _, it := range goodList {
  7408. over_count_one += it.StockCount
  7409. }
  7410. //查询该批次是否有退库数据
  7411. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7412. flow := models.VmStockFlow{
  7413. WarehousingId: it.WarehouseInfotId,
  7414. GoodId: it.GoodId,
  7415. Number: it.Number,
  7416. LicenseNumber: it.LicenseNumber,
  7417. Count: it.Count,
  7418. UserOrgId: adminInfo.CurrentOrgId,
  7419. PatientId: it.PatientId,
  7420. SystemTime: it.SysRecordTime,
  7421. ConsumableType: 7,
  7422. IsSys: 0,
  7423. WarehousingOrder: "",
  7424. WarehouseOutId: it.WarehouseOutId,
  7425. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7426. IsEdit: 0,
  7427. CancelStockId: cancel.ID,
  7428. CancelOrderNumber: cancel.OrderNumber,
  7429. Manufacturer: manufacturer.ID,
  7430. Dealer: 0,
  7431. Creator: adminInfo.AdminUser.Id,
  7432. UpdateCreator: 0,
  7433. Status: 1,
  7434. Ctime: time.Now().Unix(),
  7435. Mtime: 0,
  7436. Price: it.Price,
  7437. WarehousingDetailId: it.WarehouseInfotId,
  7438. WarehouseOutDetailId: it.ID,
  7439. CancelOutDetailId: cancelInfo.ID,
  7440. ProductDate: it.ProductDate,
  7441. ExpireDate: it.ExpiryDate,
  7442. StorehouseId: houseConfig.StorehouseOutInfo,
  7443. OverCount: over_count_one,
  7444. OperateTime: time.Now().Unix(),
  7445. }
  7446. service.CreateStockFlowOne(flow)
  7447. }
  7448. }
  7449. //查询已出库数量
  7450. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7451. if prescribingNumber < dialysisInfo.Count {
  7452. //改变数量
  7453. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7454. }
  7455. if prescribingNumber >= dialysisInfo.Count {
  7456. //删除出库表
  7457. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7458. }
  7459. //更新剩余库存
  7460. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7461. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7462. var total_count_one int64
  7463. for _, it := range stockList {
  7464. total_count_one += it.StockCount
  7465. }
  7466. //基础库插入数据
  7467. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7468. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7469. var flush_count int64
  7470. for _, it := range goodListOne {
  7471. flush_count += it.StockCount
  7472. }
  7473. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7474. if errs != nil {
  7475. goodErrcode := models.XtGoodErrcode{
  7476. UserOrgId: project.UserOrgId,
  7477. Errcode: "手动出库更新剩余出库失败",
  7478. GoodId: project.ProjectId,
  7479. Status: 1,
  7480. Ctime: time.Now().Unix(),
  7481. Mtime: 0,
  7482. Count: 0,
  7483. StockCount: 0,
  7484. Creater: creater,
  7485. BatchNumberId: 0,
  7486. WarehouseOutId: 0,
  7487. }
  7488. service.CreateGoodErrcode(goodErrcode)
  7489. }
  7490. }
  7491. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7492. fmt.Println(err)
  7493. } else {
  7494. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7495. fmt.Println(err)
  7496. }
  7497. }
  7498. c.ServeSuccessJSON(map[string]interface{}{
  7499. "msg": "删除成功",
  7500. })
  7501. return
  7502. }
  7503. func (c *HisApiController) CreateHisAdditionalCharge() {
  7504. his_patient_id, _ := c.GetInt64("his_patient_id")
  7505. patient_id, _ := c.GetInt64("patient_id")
  7506. record_date := c.GetString("record_date")
  7507. timeLayout := "2006-01-02"
  7508. loc, _ := time.LoadLocation("Local")
  7509. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7510. if err != nil {
  7511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7512. return
  7513. }
  7514. adminInfo := c.GetAdminUserInfo()
  7515. recordDateTime := theTime.Unix()
  7516. dataBody := make(map[string]interface{}, 0)
  7517. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7518. if err != nil {
  7519. utils.ErrorLog(err.Error())
  7520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7521. return
  7522. }
  7523. var additions []*models.HisAdditionalCharge
  7524. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7525. additions, _ := dataBody["addition"].([]interface{})
  7526. if len(additions) > 0 {
  7527. for _, item := range additions {
  7528. items := item.(map[string]interface{})
  7529. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7530. utils.ErrorLog("item_id")
  7531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7532. return
  7533. }
  7534. item_id := int64(items["item_id"].(float64))
  7535. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7536. utils.ErrorLog("item_name")
  7537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7538. return
  7539. }
  7540. item_name := items["item_name"].(string)
  7541. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7542. utils.ErrorLog("price")
  7543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7544. return
  7545. }
  7546. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7547. ctime := time.Now().Unix()
  7548. additional := &models.HisAdditionalCharge{
  7549. PatientId: patient_id,
  7550. HisPatientId: his_patient_id,
  7551. UserOrgId: adminInfo.CurrentOrgId,
  7552. RecordDate: recordDateTime,
  7553. CreatedTime: ctime,
  7554. UpdatedTime: ctime,
  7555. Modifier: adminInfo.AdminUser.Id,
  7556. Creator: adminInfo.AdminUser.Id,
  7557. Price: price,
  7558. ItemName: item_name,
  7559. ItemId: item_id,
  7560. Status: 1,
  7561. }
  7562. additions = append(additions, additional)
  7563. }
  7564. }
  7565. }
  7566. for _, item := range additions {
  7567. service.CreateAddtionalCharge(item)
  7568. }
  7569. c.ServeSuccessJSON(map[string]interface{}{
  7570. "msg": "创建成功",
  7571. })
  7572. }
  7573. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7574. blood_fat := c.GetString("blood_fat")
  7575. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7576. blood_sugar := c.GetString("blood_sugar")
  7577. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7578. chief_conplaint := c.GetString("chief_conplaint")
  7579. dbp := c.GetString("dbp")
  7580. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7581. delivery_way, _ := c.GetInt64("delivery_way")
  7582. diagnostic := c.GetString("diagnostic")
  7583. family_history := c.GetString("family_history")
  7584. height := c.GetString("height")
  7585. history_of_present_illness := c.GetString("history_of_present_illness")
  7586. is_infect, _ := c.GetInt64("is_infect")
  7587. past_history := c.GetString("past_history")
  7588. patient_id, _ := c.GetInt64("patient_id")
  7589. his_patient_id, _ := c.GetInt64("his_patient_id")
  7590. personal_history := c.GetString("personal_history")
  7591. pulse := c.GetString("pulse")
  7592. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7593. sbp := c.GetString("sbp")
  7594. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7595. heightfloat, _ := strconv.ParseFloat(height, 64)
  7596. sicktype := c.GetString("sick_type")
  7597. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7598. symptom := c.GetString("symptom")
  7599. sick_date := c.GetString("sick_date")
  7600. temperatures := c.GetString("temperature")
  7601. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7602. record_date := c.GetString("record_date")
  7603. breathing := c.GetString("breathing")
  7604. doctor_advice := c.GetString("doctor_advice")
  7605. remark := c.GetString("remark")
  7606. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7607. sick, _ := c.GetInt64("sick")
  7608. diagnose, _ := c.GetInt64("diagnose")
  7609. //id, _ := c.GetInt64("id")
  7610. timeLayout := "2006-01-02"
  7611. loc, _ := time.LoadLocation("Local")
  7612. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7613. allergic_history := c.GetString("allergic_history")
  7614. if err != nil {
  7615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7616. return
  7617. }
  7618. recordDateTime := theTime.Unix()
  7619. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7620. if err != nil {
  7621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7622. return
  7623. }
  7624. sickTimes := sickTime.Unix()
  7625. ctime := time.Now().Unix()
  7626. primary_disease := c.GetString("primary_disease")
  7627. confirm_failure_date := c.GetString("confirm_failure_date")
  7628. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7629. drug_allergy_history := c.GetString("drug_allergy_history")
  7630. physical_examination := c.GetString("physical_examination")
  7631. special_inspection := c.GetString("special_inspection")
  7632. lab_apparatus := c.GetString("lab_apparatus")
  7633. caseHistory := models.HisPatientCaseHistory{
  7634. HisPatientId: his_patient_id,
  7635. PatientId: patient_id,
  7636. Temperature: temperature,
  7637. BloodSugar: bloodsugarfloat,
  7638. Pulse: pulsefloat,
  7639. Sbp: sbpfloat,
  7640. Dbp: dbpfloat,
  7641. Height: heightfloat,
  7642. BloodFat: bloodfatfloat,
  7643. SickType: sick_type,
  7644. Symptom: symptom,
  7645. SickDate: sickTimes,
  7646. IsInfect: is_infect,
  7647. HistoryOfPresentIllness: history_of_present_illness,
  7648. PastHistory: past_history,
  7649. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7650. ChiefConplaint: chief_conplaint,
  7651. PersonalHistory: personal_history,
  7652. FamilyHistory: family_history,
  7653. Diagnostic: diagnostic,
  7654. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7655. Status: 1,
  7656. Ctime: ctime,
  7657. Mtime: ctime,
  7658. RecordDate: recordDateTime,
  7659. DeliveryWay: delivery_way,
  7660. Breathing: breathingfloat,
  7661. DoctorAdvice: doctor_advice,
  7662. Remark: remark,
  7663. Sick: sick,
  7664. Diagnose: diagnose,
  7665. AllergicHistory: allergic_history,
  7666. PrimaryDisease: primary_disease,
  7667. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7668. DrugAllergyHistory: drug_allergy_history,
  7669. PhysicalExamination: physical_examination,
  7670. SpecialInspection: special_inspection,
  7671. LabApparatus: lab_apparatus,
  7672. }
  7673. //查询该患者是否有病历
  7674. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7675. if errcodes == gorm.ErrRecordNotFound {
  7676. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7677. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7678. if err != nil {
  7679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7680. return
  7681. }
  7682. c.ServeSuccessJSON(map[string]interface{}{
  7683. "caseHistory": caseHistory,
  7684. "historyInfo": historyInfo,
  7685. })
  7686. return
  7687. } else if errcodes == nil {
  7688. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7689. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7690. if err != nil {
  7691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7692. return
  7693. }
  7694. c.ServeSuccessJSON(map[string]interface{}{
  7695. "caseHistory": caseHistory,
  7696. "historyInfo": historyInfo,
  7697. })
  7698. }
  7699. //查询该患者是否有病历
  7700. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7701. //if errcode == gorm.ErrRecordNotFound {
  7702. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7703. // if err != nil {
  7704. // c.ServeSuccessJSON(map[string]interface{}{
  7705. // "msg": "保存成功",
  7706. // })
  7707. // }
  7708. //} else if errcode == nil {
  7709. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7710. // return
  7711. //}
  7712. }
  7713. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7714. patient_id, _ := c.GetInt64("patient_id", 0)
  7715. adminUser := c.GetAdminUserInfo()
  7716. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7717. c.ServeSuccessJSON(map[string]interface{}{
  7718. "list": caseHistorys,
  7719. })
  7720. }
  7721. func (c *HisApiController) GetHisPatientCaseHistory() {
  7722. record_date, _ := c.GetInt64("record_date", 0)
  7723. patient_id, _ := c.GetInt64("patient_id", 0)
  7724. admin := c.GetAdminUserInfo()
  7725. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7726. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7727. c.ServeSuccessJSON(map[string]interface{}{
  7728. "info": info,
  7729. "case_history": case_history,
  7730. })
  7731. }
  7732. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7733. template_name := c.GetString("template_name")
  7734. template_remark := c.GetString("template_remark")
  7735. doctor := c.GetAdminUserInfo().AdminUser.Id
  7736. diagnostic := c.GetString("diagnostic")
  7737. chief_conplaint := c.GetString("chief_conplain")
  7738. history_of_present_illness := c.GetString("history_of_present_illness")
  7739. past_history := c.GetString("past_history")
  7740. personal_history := c.GetString("personal_history")
  7741. family_history := c.GetString("family_history")
  7742. user_name := c.GetString("user_name")
  7743. doctor_advice := c.GetString("doctor_advice")
  7744. remark := c.GetString("remark")
  7745. //record_date := c.GetString("record_date")
  7746. //fmt.Println("record_date--------",record_date)
  7747. //timeLayout := "2006-01-02"
  7748. //loc, _ := time.LoadLocation("Local")
  7749. //
  7750. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7751. //if err != nil {
  7752. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7753. // return
  7754. //}
  7755. //recordDateTime := theTime.Unix()
  7756. ctime := time.Now().Unix()
  7757. template := models.HisCaseHistoryTemplate{
  7758. HistoryOfPresentIllness: history_of_present_illness,
  7759. PastHistory: past_history,
  7760. ChiefConplaint: chief_conplaint,
  7761. PersonalHistory: personal_history,
  7762. FamilyHistory: family_history,
  7763. Diagnostic: diagnostic,
  7764. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7765. Status: 1,
  7766. Ctime: ctime,
  7767. Mtime: ctime,
  7768. RecordDate: time.Now().Unix(),
  7769. TemplateName: template_name,
  7770. TemplateRemark: template_remark,
  7771. Creator: doctor,
  7772. Modifier: doctor,
  7773. UserName: user_name,
  7774. DoctorAdvice: doctor_advice,
  7775. Remark: remark,
  7776. }
  7777. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7778. if err == nil {
  7779. c.ServeSuccessJSON(map[string]interface{}{
  7780. "msg": "保存成功",
  7781. })
  7782. } else {
  7783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7784. return
  7785. }
  7786. }
  7787. func (c *HisApiController) GetCaseHistoryTemplate() {
  7788. timeLayout := "2006-01-02"
  7789. loc, _ := time.LoadLocation("Local")
  7790. keyword := c.GetString("keyword")
  7791. start_time := c.GetString("start_time")
  7792. end_time := c.GetString("end_time")
  7793. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7794. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7795. admin := c.GetAdminUserInfo()
  7796. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7797. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7798. c.ServeSuccessJSON(map[string]interface{}{
  7799. "template": template,
  7800. //"history": history,
  7801. })
  7802. }
  7803. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7804. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7805. utils.ErrorLog("drug_name")
  7806. return enums.ErrorCodeParamWrong
  7807. }
  7808. adviceName, _ := json["drug_name"].(string)
  7809. if len(adviceName) == 0 {
  7810. utils.ErrorLog("len(advice_name) == 0")
  7811. return enums.ErrorCodeParamWrong
  7812. }
  7813. advice.AdviceName = adviceName
  7814. adviceDesc, _ := json["advice_desc"].(string)
  7815. advice.AdviceDesc = adviceDesc
  7816. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7817. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7818. advice.DrugSpec = drugSpec
  7819. }
  7820. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7821. remark, _ := json["remark"].(string)
  7822. advice.Remark = remark
  7823. }
  7824. if json["id"] == nil {
  7825. advice.DrugId = 0
  7826. } else {
  7827. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7828. drug_id := int64(json["id"].(float64))
  7829. advice.DrugId = drug_id
  7830. }
  7831. }
  7832. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7833. advice_id := int64(json["advice_id"].(float64))
  7834. advice.ID = advice_id
  7835. if advice.ID > 0 {
  7836. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7837. if err == nil {
  7838. if hisAdvice.ID > 0 {
  7839. advice.ExecutionTime = hisAdvice.ExecutionTime
  7840. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7841. advice.ExecutionState = hisAdvice.ExecutionState
  7842. advice.CheckTime = hisAdvice.CheckTime
  7843. advice.Checker = hisAdvice.Checker
  7844. advice.CheckState = hisAdvice.CheckState
  7845. advice.StartTime = hisAdvice.StartTime
  7846. advice.FeedetlSn = hisAdvice.FeedetlSn
  7847. }
  7848. }
  7849. }
  7850. }
  7851. //
  7852. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7853. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7854. // advice.ExecutionTime = execution_time
  7855. //}
  7856. //
  7857. //
  7858. //
  7859. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7860. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7861. // advice.ExecutionStaff = execution_staff
  7862. //}
  7863. //
  7864. //
  7865. //
  7866. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7867. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7868. // advice.ExecutionState = execution_state
  7869. //}
  7870. //
  7871. //
  7872. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7873. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7874. // advice.CheckTime = check_time
  7875. //}
  7876. //
  7877. //
  7878. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7879. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7880. // advice.CheckState = check_state
  7881. //}
  7882. //
  7883. //
  7884. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7885. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7886. // advice.Checker = checker
  7887. //}
  7888. //
  7889. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7890. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7891. // advice.StartTime = start_time
  7892. //}
  7893. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7894. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7895. advice.IsSelfDrug = is_self_drug
  7896. }
  7897. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7898. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7899. drug_way_count, _ := json["drug_way_count"].(string)
  7900. advice.DrugWayCount = drug_way_count
  7901. }
  7902. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7903. drugSpecUnit, _ := json["min_unit"].(string)
  7904. advice.DrugSpecUnit = drugSpecUnit
  7905. }
  7906. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7907. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7908. advice.SingleDose = singleDose
  7909. }
  7910. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7911. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7912. advice.SingleDoseUnit = singleDoseUnit
  7913. }
  7914. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7915. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7916. advice.PrescribingNumber = prescribingNumber
  7917. }
  7918. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7919. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7920. advice.PrescribingNumberUnit = prescribingNumberUnit
  7921. }
  7922. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7923. deliveryWay, _ := json["delivery_way"].(string)
  7924. advice.DeliveryWay = deliveryWay
  7925. }
  7926. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7927. executionFrequency, _ := json["execution_frequency"].(string)
  7928. advice.ExecutionFrequency = executionFrequency
  7929. }
  7930. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7931. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7932. advice.Price = price
  7933. }
  7934. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7935. med_list_codg, _ := json["medical_insurance_number"].(string)
  7936. advice.MedListCodg = med_list_codg
  7937. }
  7938. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7939. day := int64(json["day"].(float64))
  7940. advice.Day = day
  7941. }
  7942. return 0
  7943. }
  7944. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7945. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7946. id := int64(json["id"].(float64))
  7947. project.ID = id
  7948. historyProject, _ := service.GetHisProjectByID(id)
  7949. project.FeedetlSn = historyProject.FeedetlSn
  7950. }
  7951. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7952. project_id := int64(json["project_id"].(float64))
  7953. project.ProjectId = project_id
  7954. }
  7955. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7956. // price := int64(json["price"].(float64))
  7957. // formatInt_price := strconv.FormatInt(price, 10)
  7958. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7959. // project.Price = float_price
  7960. // }
  7961. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7962. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7963. project.Price = price
  7964. }
  7965. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7966. total, _ := json["total"].(string)
  7967. project.Count = total
  7968. }
  7969. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7970. medical_code, _ := json["medical_code"].(string)
  7971. project.MedListCodg = medical_code
  7972. }
  7973. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7974. single_dose, _ := json["single_dose"].(string)
  7975. project.SingleDose = single_dose
  7976. }
  7977. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7978. delivery_way, _ := json["delivery_way"].(string)
  7979. project.DeliveryWay = delivery_way
  7980. }
  7981. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7982. execution_frequency, _ := json["execution_frequency"].(string)
  7983. project.ExecutionFrequency = execution_frequency
  7984. }
  7985. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7986. remark, _ := json["remark"].(string)
  7987. project.Remark = remark
  7988. }
  7989. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7990. day, _ := json["number_days"].(string)
  7991. project.Day = day
  7992. }
  7993. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7994. unit, _ := json["unit"].(string)
  7995. project.Unit = unit
  7996. }
  7997. return 0
  7998. }
  7999. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8000. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8001. id := int64(json["id"].(float64))
  8002. historyAddtions, _ := service.GetHisAdditionByID(id)
  8003. additionalCharge.ID = id
  8004. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  8005. }
  8006. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8007. item_id := int64(json["item_id"].(float64))
  8008. additionalCharge.ItemId = item_id
  8009. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8010. if config.ID > 0 {
  8011. if len(config.Code) > 0 {
  8012. additionalCharge.MedListCodg = config.Code
  8013. }
  8014. }
  8015. }
  8016. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8017. // price := int64(json["price"].(float64))
  8018. // formatInt_price := strconv.FormatInt(price, 10)
  8019. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8020. // additionalCharge.Price = float_price
  8021. // }
  8022. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8023. // price := int64(json["price"].(float64))
  8024. // formatInt_price := strconv.FormatInt(price, 10)
  8025. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8026. // additionalCharge.Price = float_price
  8027. //}
  8028. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8029. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8030. additionalCharge.Price = price
  8031. }
  8032. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8033. count, _ := json["count"].(string)
  8034. counts, _ := strconv.ParseInt(count, 10, 64)
  8035. additionalCharge.Count = counts
  8036. }
  8037. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8038. item_name, _ := json["item_name"].(string)
  8039. additionalCharge.ItemName = item_name
  8040. }
  8041. return 0
  8042. }
  8043. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8044. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8045. utils.ErrorLog("drug_name")
  8046. return enums.ErrorCodeParamWrong
  8047. }
  8048. adviceName, _ := json["drug_name"].(string)
  8049. if len(adviceName) == 0 {
  8050. utils.ErrorLog("len(advice_name) == 0")
  8051. return enums.ErrorCodeParamWrong
  8052. }
  8053. advice.AdviceName = adviceName
  8054. adviceDesc, _ := json["advice_desc"].(string)
  8055. advice.AdviceDesc = adviceDesc
  8056. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8057. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8058. advice.DrugSpec = drugSpec
  8059. }
  8060. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8061. remark, _ := json["remark"].(string)
  8062. advice.Remark = remark
  8063. }
  8064. if json["id"] == nil {
  8065. advice.DrugId = 0
  8066. } else {
  8067. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8068. drug_id := int64(json["id"].(float64))
  8069. advice.DrugId = drug_id
  8070. }
  8071. }
  8072. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8073. groupno := int64(json["groupno"].(float64))
  8074. advice.Groupno = groupno
  8075. }
  8076. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8077. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8078. advice.IsSelfDrug = is_self_drug
  8079. }
  8080. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8081. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8082. drug_way_count, _ := json["drug_way_count"].(string)
  8083. advice.DrugWayCount = drug_way_count
  8084. }
  8085. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8086. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8087. advice.HospApprFlag = hosp_appr_flag
  8088. }
  8089. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8090. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8091. advice.PrescribingNumber = prescribingNumber
  8092. }
  8093. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8094. // frequency_type := int64(json["frequency_type"].(float64))
  8095. // advice.FrequencyType = frequency_type
  8096. //}
  8097. //
  8098. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8099. // day_count := int64(json["day_count"].(float64))
  8100. // advice.DayCount = day_count
  8101. //}
  8102. //
  8103. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8104. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8105. // week_day, _ := json["week_day"].(string)
  8106. // advice.WeekDay = week_day
  8107. //}
  8108. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8109. drugSpecUnit, _ := json["min_unit"].(string)
  8110. advice.DrugSpecUnit = drugSpecUnit
  8111. }
  8112. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8113. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8114. advice.SingleDose = singleDose
  8115. }
  8116. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8117. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8118. advice.SingleDoseUnit = singleDoseUnit
  8119. }
  8120. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8121. deliveryWay, _ := json["delivery_way"].(string)
  8122. advice.DeliveryWay = deliveryWay
  8123. }
  8124. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8125. executionFrequency, _ := json["execution_frequency"].(string)
  8126. advice.ExecutionFrequency = executionFrequency
  8127. }
  8128. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8129. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8130. advice.Price = price
  8131. }
  8132. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8133. med_list_codg, _ := json["medical_insurance_number"].(string)
  8134. advice.MedListCodg = med_list_codg
  8135. }
  8136. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8137. day := int64(json["day"].(float64))
  8138. advice.Day = day
  8139. }
  8140. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8141. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8142. advice.PrescribingNumberUnit = prescribingNumberUnit
  8143. }
  8144. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8145. advice_id := int64(json["advice_id"].(float64))
  8146. advice.ID = advice_id
  8147. if advice.ID > 0 {
  8148. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8149. if err == nil {
  8150. if hisAdvice.ID > 0 {
  8151. advice.ExecutionTime = hisAdvice.ExecutionTime
  8152. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8153. advice.ExecutionState = hisAdvice.ExecutionState
  8154. advice.CheckTime = hisAdvice.CheckTime
  8155. advice.Checker = hisAdvice.Checker
  8156. advice.CheckState = hisAdvice.CheckState
  8157. advice.StartTime = hisAdvice.StartTime
  8158. advice.HospApprFlag = hisAdvice.HospApprFlag
  8159. advice.IsMedicine = hisAdvice.IsMedicine
  8160. if hisAdvice.UserOrgId == 10028 {
  8161. 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 {
  8162. advice.ExecutionTime = 0
  8163. advice.ExecutionStaff = 0
  8164. advice.ExecutionState = 2
  8165. advice.CheckTime = 0
  8166. advice.Checker = 0
  8167. advice.CheckState = 2
  8168. }
  8169. } else {
  8170. 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 {
  8171. advice.ExecutionTime = 0
  8172. advice.ExecutionStaff = 0
  8173. advice.ExecutionState = 2
  8174. advice.CheckTime = 0
  8175. advice.Checker = 0
  8176. advice.CheckState = 2
  8177. advice.UpdatedTime = time.Now().Unix()
  8178. }
  8179. }
  8180. //advice.Groupno = hisAdvice.Groupno
  8181. }
  8182. }
  8183. }
  8184. }
  8185. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8186. //
  8187. //if drugStockConfig.IsOpen == 1 {
  8188. //
  8189. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8190. // if advice.ID == 0 { //医嘱不存在
  8191. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8192. // drug.Total = drug.Total - advice.PrescribingNumber
  8193. // service.UpdateBaseDrugLib(&drug)
  8194. //
  8195. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8196. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8197. // drug.Total = drug.Total - num
  8198. // service.UpdateBaseDrugLib(&drug)
  8199. // }
  8200. //
  8201. // } else if advice.ID > 0 { //医嘱存在
  8202. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8203. // var num float64
  8204. //
  8205. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8206. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8207. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8208. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8209. // drug.Total = drug.Total + num
  8210. // service.UpdateBaseDrugLib(&drug)
  8211. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8212. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8213. // drug.Total = drug.Total - num
  8214. // service.UpdateBaseDrugLib(&drug)
  8215. // }
  8216. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8217. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8218. // if num2 > advice.PrescribingNumber {
  8219. // num = num2 - advice.PrescribingNumber
  8220. // drug.Total = drug.Total + num
  8221. // service.UpdateBaseDrugLib(&drug)
  8222. // } else if num2 < advice.PrescribingNumber {
  8223. // num = advice.PrescribingNumber - num2
  8224. // drug.Total = drug.Total - num
  8225. // service.UpdateBaseDrugLib(&drug)
  8226. // }
  8227. //
  8228. // }
  8229. //
  8230. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8231. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8232. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8233. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8234. // if num1 > num2 {
  8235. // num = num1 - num2
  8236. // drug.Total = drug.Total + num
  8237. // service.UpdateBaseDrugLib(&drug)
  8238. // } else if num1 < num2 {
  8239. // num = num2 - num1
  8240. // drug.Total = drug.Total - num
  8241. // service.UpdateBaseDrugLib(&drug)
  8242. // }
  8243. //
  8244. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8245. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8246. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8247. // if hisAdvice.PrescribingNumber > num2 {
  8248. // num = hisAdvice.PrescribingNumber - num2
  8249. // drug.Total = drug.Total + num
  8250. // service.UpdateBaseDrugLib(&drug)
  8251. // } else if num2 < advice.PrescribingNumber {
  8252. // num = num2 - hisAdvice.PrescribingNumber
  8253. // drug.Total = drug.Total - num
  8254. // service.UpdateBaseDrugLib(&drug)
  8255. // }
  8256. //
  8257. // }
  8258. // }
  8259. // }
  8260. //}
  8261. //
  8262. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8263. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8264. // advice.ExecutionTime = execution_time
  8265. //}
  8266. //
  8267. //
  8268. //
  8269. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8270. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8271. // advice.ExecutionStaff = execution_staff
  8272. //}
  8273. //
  8274. //
  8275. //
  8276. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8277. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8278. // advice.ExecutionState = execution_state
  8279. //}
  8280. //
  8281. //
  8282. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8283. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8284. // advice.CheckTime = check_time
  8285. //}
  8286. //
  8287. //
  8288. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8289. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8290. // advice.CheckState = check_state
  8291. //}
  8292. //
  8293. //
  8294. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8295. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8296. // advice.Checker = checker
  8297. //}
  8298. //
  8299. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8300. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8301. // advice.StartTime = start_time
  8302. //}
  8303. return 0
  8304. }
  8305. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8306. project.ExecutionStaff = 0
  8307. project.ExecutionState = 2
  8308. project.ExecutionTime = 0
  8309. project.Checker = 0
  8310. project.CheckState = 2
  8311. project.CheckTime = 0
  8312. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8313. id := int64(json["id"].(float64))
  8314. project.ID = id
  8315. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8316. project.ExecutionStaff = temp_project.ExecutionStaff
  8317. project.ExecutionState = temp_project.ExecutionState
  8318. project.ExecutionTime = temp_project.ExecutionTime
  8319. project.Checker = temp_project.Checker
  8320. project.CheckState = temp_project.CheckState
  8321. project.CheckTime = temp_project.CheckTime
  8322. project.TeamId = temp_project.TeamId
  8323. }
  8324. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8325. types := int64(json["type"].(float64))
  8326. project.Type = types
  8327. }
  8328. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8329. project_id := int64(json["project_id"].(float64))
  8330. project.ProjectId = project_id
  8331. }
  8332. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8333. team_id := int64(json["team_id"].(float64))
  8334. project.TeamId = team_id
  8335. }
  8336. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8337. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8338. project.Price = price
  8339. }
  8340. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8341. total, _ := json["total"].(string)
  8342. //totals, _ := strconv.ParseInt(total, 10, 64)
  8343. project.Count = total
  8344. }
  8345. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8346. medical_code, _ := json["medical_code"].(string)
  8347. project.MedListCodg = medical_code
  8348. }
  8349. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8350. single_dose, _ := json["single_dose"].(string)
  8351. project.SingleDose = single_dose
  8352. }
  8353. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8354. delivery_way, _ := json["delivery_way"].(string)
  8355. project.DeliveryWay = delivery_way
  8356. }
  8357. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8358. execution_frequency, _ := json["execution_frequency"].(string)
  8359. project.ExecutionFrequency = execution_frequency
  8360. }
  8361. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8362. remark, _ := json["remark"].(string)
  8363. project.Remark = remark
  8364. }
  8365. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8366. day, _ := json["number_days"].(string)
  8367. project.Day = day
  8368. }
  8369. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8370. unit, _ := json["unit"].(string)
  8371. project.Unit = unit
  8372. }
  8373. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8374. // frequency_type := int64(json["frequency_type"].(float64))
  8375. // project.FrequencyType = frequency_type
  8376. //}
  8377. //
  8378. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8379. // day_count := int64(json["day_count"].(float64))
  8380. // project.DayCount = day_count
  8381. //}
  8382. //
  8383. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8384. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8385. // week_day, _ := json["week_day"].(string)
  8386. // project.WeekDay = week_day
  8387. //}
  8388. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8389. //
  8390. //if project.ID == 0 {
  8391. // if stockConfig.IsOpen == 1 {
  8392. // if project.Type == 3 {
  8393. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8394. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8395. // good.Total = good.Total - f_count
  8396. // service.UpdateGoodInfo(&good)
  8397. // }
  8398. // }
  8399. //
  8400. //} else {
  8401. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8402. //
  8403. // if stockConfig.IsOpen == 1 {
  8404. // if project.Type == 3 {
  8405. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8406. // if project.Count < temp_project.Count {
  8407. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8408. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8409. //
  8410. // other_count := f_count_two - f_count_one
  8411. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8412. // good.Total = good.Total + other_count_two
  8413. // service.UpdateGoodInfo(&good)
  8414. // } else if project.Count > temp_project.Count {
  8415. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8416. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8417. //
  8418. // other_count := f_count_one - f_count_two
  8419. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8420. // good.Total = good.Total - other_count_two
  8421. // service.UpdateGoodInfo(&good)
  8422. // }
  8423. //
  8424. // }
  8425. // }
  8426. //
  8427. //}
  8428. return 0
  8429. }
  8430. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8431. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8432. utils.ErrorLog("drug_name")
  8433. return enums.ErrorCodeParamWrong
  8434. }
  8435. adviceName, _ := json["drug_name"].(string)
  8436. if len(adviceName) == 0 {
  8437. utils.ErrorLog("len(advice_name) == 0")
  8438. return enums.ErrorCodeParamWrong
  8439. }
  8440. advice.AdviceName = adviceName
  8441. adviceDesc, _ := json["advice_desc"].(string)
  8442. advice.AdviceDesc = adviceDesc
  8443. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8444. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8445. advice.DrugSpec = drugSpec
  8446. }
  8447. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8448. remark, _ := json["remark"].(string)
  8449. advice.Remark = remark
  8450. }
  8451. if json["id"] == nil {
  8452. advice.DrugId = 0
  8453. } else {
  8454. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8455. drug_id := int64(json["id"].(float64))
  8456. advice.DrugId = drug_id
  8457. }
  8458. }
  8459. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8460. groupno := int64(json["groupno"].(float64))
  8461. advice.Groupno = groupno
  8462. }
  8463. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8464. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8465. advice.IsSelfDrug = is_self_drug
  8466. }
  8467. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8468. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8469. drug_way_count, _ := json["drug_way_count"].(string)
  8470. advice.DrugWayCount = drug_way_count
  8471. }
  8472. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8473. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8474. advice.HospApprFlag = hosp_appr_flag
  8475. }
  8476. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8477. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8478. advice.PrescribingNumber = prescribingNumber
  8479. }
  8480. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8481. // frequency_type := int64(json["frequency_type"].(float64))
  8482. // advice.FrequencyType = frequency_type
  8483. //}
  8484. //
  8485. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8486. // day_count := int64(json["day_count"].(float64))
  8487. // advice.DayCount = day_count
  8488. //}
  8489. //
  8490. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8491. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8492. // week_day, _ := json["week_day"].(string)
  8493. // advice.WeekDay = week_day
  8494. //}
  8495. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8496. drugSpecUnit, _ := json["min_unit"].(string)
  8497. advice.DrugSpecUnit = drugSpecUnit
  8498. }
  8499. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8500. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8501. advice.SingleDose = singleDose
  8502. }
  8503. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8504. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8505. advice.SingleDoseUnit = singleDoseUnit
  8506. }
  8507. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8508. deliveryWay, _ := json["delivery_way"].(string)
  8509. advice.DeliveryWay = deliveryWay
  8510. }
  8511. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8512. executionFrequency, _ := json["execution_frequency"].(string)
  8513. advice.ExecutionFrequency = executionFrequency
  8514. }
  8515. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8516. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8517. advice.Price = price
  8518. }
  8519. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8520. med_list_codg, _ := json["medical_insurance_number"].(string)
  8521. advice.MedListCodg = med_list_codg
  8522. }
  8523. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8524. day := int64(json["day"].(float64))
  8525. advice.Day = day
  8526. }
  8527. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8528. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8529. advice.PrescribingNumberUnit = prescribingNumberUnit
  8530. }
  8531. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8532. advice_id := int64(json["advice_id"].(float64))
  8533. advice.ID = advice_id
  8534. if advice.ID > 0 {
  8535. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8536. if err == nil {
  8537. if hisAdvice.ID > 0 {
  8538. advice.ExecutionTime = hisAdvice.ExecutionTime
  8539. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8540. advice.ExecutionState = hisAdvice.ExecutionState
  8541. advice.CheckTime = hisAdvice.CheckTime
  8542. advice.Checker = hisAdvice.Checker
  8543. advice.DrugCode = hisAdvice.DrugCode
  8544. advice.CheckState = hisAdvice.CheckState
  8545. advice.StartTime = hisAdvice.StartTime
  8546. advice.HospApprFlag = hisAdvice.HospApprFlag
  8547. advice.IsMedicine = hisAdvice.IsMedicine
  8548. if hisAdvice.UserOrgId == 10028 {
  8549. 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 {
  8550. advice.ExecutionTime = 0
  8551. advice.ExecutionStaff = 0
  8552. advice.ExecutionState = 2
  8553. advice.CheckTime = 0
  8554. advice.Checker = 0
  8555. advice.CheckState = 2
  8556. }
  8557. } else {
  8558. 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 {
  8559. advice.ExecutionTime = 0
  8560. advice.ExecutionStaff = 0
  8561. advice.ExecutionState = 2
  8562. advice.CheckTime = 0
  8563. advice.Checker = 0
  8564. advice.CheckState = 2
  8565. //advice.UpdatedTime = time.Now().Unix()
  8566. advice.CreatedTime = hisAdvice.CreatedTime
  8567. advice.UpdatedTime = time.Now().Unix()
  8568. } else {
  8569. advice.CreatedTime = hisAdvice.CreatedTime
  8570. advice.UpdatedTime = hisAdvice.UpdatedTime
  8571. }
  8572. }
  8573. //advice.Groupno = hisAdvice.Groupno
  8574. } else {
  8575. advice.IsMedicine = 0
  8576. ctime := time.Now().Unix()
  8577. advice.CreatedTime = ctime
  8578. advice.UpdatedTime = ctime
  8579. }
  8580. }
  8581. } else {
  8582. advice.IsMedicine = 0
  8583. ctime := time.Now().Unix()
  8584. advice.CreatedTime = ctime
  8585. advice.UpdatedTime = ctime
  8586. }
  8587. }
  8588. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8589. //
  8590. //if drugStockConfig.IsOpen == 1 {
  8591. //
  8592. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8593. // if advice.ID == 0 { //医嘱不存在
  8594. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8595. // drug.Total = drug.Total - advice.PrescribingNumber
  8596. // service.UpdateBaseDrugLib(&drug)
  8597. //
  8598. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8599. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8600. // drug.Total = drug.Total - num
  8601. // service.UpdateBaseDrugLib(&drug)
  8602. // }
  8603. //
  8604. // } else if advice.ID > 0 { //医嘱存在
  8605. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8606. // var num float64
  8607. //
  8608. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8609. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8610. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8611. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8612. // drug.Total = drug.Total + num
  8613. // service.UpdateBaseDrugLib(&drug)
  8614. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8615. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8616. // drug.Total = drug.Total - num
  8617. // service.UpdateBaseDrugLib(&drug)
  8618. // }
  8619. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8620. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8621. // if num2 > advice.PrescribingNumber {
  8622. // num = num2 - advice.PrescribingNumber
  8623. // drug.Total = drug.Total + num
  8624. // service.UpdateBaseDrugLib(&drug)
  8625. // } else if num2 < advice.PrescribingNumber {
  8626. // num = advice.PrescribingNumber - num2
  8627. // drug.Total = drug.Total - num
  8628. // service.UpdateBaseDrugLib(&drug)
  8629. // }
  8630. //
  8631. // }
  8632. //
  8633. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8634. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8635. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8636. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8637. // if num1 > num2 {
  8638. // num = num1 - num2
  8639. // drug.Total = drug.Total + num
  8640. // service.UpdateBaseDrugLib(&drug)
  8641. // } else if num1 < num2 {
  8642. // num = num2 - num1
  8643. // drug.Total = drug.Total - num
  8644. // service.UpdateBaseDrugLib(&drug)
  8645. // }
  8646. //
  8647. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8648. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8649. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8650. // if hisAdvice.PrescribingNumber > num2 {
  8651. // num = hisAdvice.PrescribingNumber - num2
  8652. // drug.Total = drug.Total + num
  8653. // service.UpdateBaseDrugLib(&drug)
  8654. // } else if num2 < advice.PrescribingNumber {
  8655. // num = num2 - hisAdvice.PrescribingNumber
  8656. // drug.Total = drug.Total - num
  8657. // service.UpdateBaseDrugLib(&drug)
  8658. // }
  8659. //
  8660. // }
  8661. // }
  8662. // }
  8663. //}
  8664. //
  8665. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8666. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8667. // advice.ExecutionTime = execution_time
  8668. //}
  8669. //
  8670. //
  8671. //
  8672. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8673. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8674. // advice.ExecutionStaff = execution_staff
  8675. //}
  8676. //
  8677. //
  8678. //
  8679. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8680. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8681. // advice.ExecutionState = execution_state
  8682. //}
  8683. //
  8684. //
  8685. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8686. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8687. // advice.CheckTime = check_time
  8688. //}
  8689. //
  8690. //
  8691. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8692. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8693. // advice.CheckState = check_state
  8694. //}
  8695. //
  8696. //
  8697. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8698. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8699. // advice.Checker = checker
  8700. //}
  8701. //
  8702. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8703. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8704. // advice.StartTime = start_time
  8705. //}
  8706. return 0
  8707. }
  8708. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8709. project.ExecutionStaff = 0
  8710. project.ExecutionState = 2
  8711. project.ExecutionTime = 0
  8712. project.Checker = 0
  8713. project.CheckState = 2
  8714. project.CheckTime = 0
  8715. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8716. id := int64(json["id"].(float64))
  8717. project.ID = id
  8718. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8719. project.ExecutionStaff = temp_project.ExecutionStaff
  8720. project.ExecutionState = temp_project.ExecutionState
  8721. project.ExecutionTime = temp_project.ExecutionTime
  8722. project.Checker = temp_project.Checker
  8723. project.CheckState = temp_project.CheckState
  8724. project.CheckTime = temp_project.CheckTime
  8725. project.TeamId = temp_project.TeamId
  8726. }
  8727. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8728. types := int64(json["type"].(float64))
  8729. project.Type = types
  8730. }
  8731. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8732. project_id := int64(json["project_id"].(float64))
  8733. project.ProjectId = project_id
  8734. }
  8735. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8736. team_id := int64(json["team_id"].(float64))
  8737. project.TeamId = team_id
  8738. }
  8739. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8740. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8741. project.Price = price
  8742. }
  8743. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8744. total, _ := json["total"].(string)
  8745. //totals, _ := strconv.ParseInt(total, 10, 64)
  8746. project.Count = total
  8747. }
  8748. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8749. medical_code, _ := json["medical_code"].(string)
  8750. project.MedListCodg = medical_code
  8751. }
  8752. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8753. single_dose, _ := json["single_dose"].(string)
  8754. project.SingleDose = single_dose
  8755. }
  8756. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8757. delivery_way, _ := json["delivery_way"].(string)
  8758. project.DeliveryWay = delivery_way
  8759. }
  8760. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8761. execution_frequency, _ := json["execution_frequency"].(string)
  8762. project.ExecutionFrequency = execution_frequency
  8763. }
  8764. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8765. remark, _ := json["remark"].(string)
  8766. project.Remark = remark
  8767. }
  8768. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8769. day, _ := json["number_days"].(string)
  8770. project.Day = day
  8771. }
  8772. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8773. unit, _ := json["unit"].(string)
  8774. project.Unit = unit
  8775. }
  8776. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8777. // frequency_type := int64(json["frequency_type"].(float64))
  8778. // project.FrequencyType = frequency_type
  8779. //}
  8780. //
  8781. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8782. // day_count := int64(json["day_count"].(float64))
  8783. // project.DayCount = day_count
  8784. //}
  8785. //
  8786. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8787. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8788. // week_day, _ := json["week_day"].(string)
  8789. // project.WeekDay = week_day
  8790. //}
  8791. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8792. //
  8793. //if project.ID == 0 {
  8794. // if stockConfig.IsOpen == 1 {
  8795. // if project.Type == 3 {
  8796. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8797. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8798. // good.Total = good.Total - f_count
  8799. // service.UpdateGoodInfo(&good)
  8800. // }
  8801. // }
  8802. //
  8803. //} else {
  8804. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8805. //
  8806. // if stockConfig.IsOpen == 1 {
  8807. // if project.Type == 3 {
  8808. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8809. // if project.Count < temp_project.Count {
  8810. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8811. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8812. //
  8813. // other_count := f_count_two - f_count_one
  8814. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8815. // good.Total = good.Total + other_count_two
  8816. // service.UpdateGoodInfo(&good)
  8817. // } else if project.Count > temp_project.Count {
  8818. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8819. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8820. //
  8821. // other_count := f_count_one - f_count_two
  8822. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8823. // good.Total = good.Total - other_count_two
  8824. // service.UpdateGoodInfo(&good)
  8825. // }
  8826. //
  8827. // }
  8828. // }
  8829. //
  8830. //}
  8831. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8832. id := int64(json["id"].(float64))
  8833. if id > 0 {
  8834. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8835. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8836. fmt.Println("666666")
  8837. project.Mtime = time.Now().Unix()
  8838. project.Ctime = temp_project.Ctime
  8839. } else {
  8840. project.Mtime = temp_project.Mtime
  8841. project.Ctime = temp_project.Ctime
  8842. }
  8843. } else {
  8844. ctime := time.Now().Unix()
  8845. project.Mtime = ctime
  8846. project.Ctime = ctime
  8847. }
  8848. }
  8849. return 0
  8850. }
  8851. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8852. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8853. id := int64(json["id"].(float64))
  8854. additionalCharge.ID = id
  8855. }
  8856. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8857. item_id := int64(json["item_id"].(float64))
  8858. additionalCharge.ItemId = item_id
  8859. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8860. if config.ID > 0 {
  8861. if len(config.Code) > 0 {
  8862. additionalCharge.MedListCodg = config.Code
  8863. }
  8864. }
  8865. }
  8866. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8867. // price := int64(json["price"].(float64))
  8868. // formatInt_price := strconv.FormatInt(price, 10)
  8869. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8870. // additionalCharge.Price = float_price
  8871. // }
  8872. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8873. // price := int64(json["price"].(float64))
  8874. // formatInt_price := strconv.FormatInt(price, 10)
  8875. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8876. // additionalCharge.Price = float_price
  8877. //}
  8878. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8879. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8880. additionalCharge.Price = price
  8881. }
  8882. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8883. count, _ := json["count"].(string)
  8884. counts, _ := strconv.ParseInt(count, 10, 64)
  8885. additionalCharge.Count = counts
  8886. }
  8887. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8888. item_name, _ := json["item_name"].(string)
  8889. additionalCharge.ItemName = item_name
  8890. }
  8891. return 0
  8892. }
  8893. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8894. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8895. utils.ErrorLog("drug_name")
  8896. return enums.ErrorCodeParamWrong
  8897. }
  8898. adviceName, _ := json["drug_name"].(string)
  8899. if len(adviceName) == 0 {
  8900. utils.ErrorLog("len(advice_name) == 0")
  8901. return enums.ErrorCodeParamWrong
  8902. }
  8903. advice.AdviceName = adviceName
  8904. adviceDesc, _ := json["advice_desc"].(string)
  8905. advice.AdviceDesc = adviceDesc
  8906. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8907. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8908. advice.DrugSpec = drugSpec
  8909. }
  8910. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8911. remark, _ := json["remark"].(string)
  8912. advice.Remark = remark
  8913. }
  8914. if json["id"] == nil {
  8915. advice.DrugId = 0
  8916. } else {
  8917. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8918. drug_id := int64(json["id"].(float64))
  8919. advice.DrugId = drug_id
  8920. }
  8921. }
  8922. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8923. groupno := int64(json["groupno"].(float64))
  8924. advice.Groupno = groupno
  8925. }
  8926. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8927. drugSpecUnit, _ := json["min_unit"].(string)
  8928. advice.DrugSpecUnit = drugSpecUnit
  8929. }
  8930. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8931. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8932. advice.SingleDose = singleDose
  8933. }
  8934. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8935. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8936. advice.SingleDoseUnit = singleDoseUnit
  8937. }
  8938. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8939. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8940. advice.PrescribingNumber = prescribingNumber
  8941. }
  8942. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8943. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8944. advice.PrescribingNumberUnit = prescribingNumberUnit
  8945. }
  8946. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8947. deliveryWay, _ := json["delivery_way"].(string)
  8948. advice.DeliveryWay = deliveryWay
  8949. }
  8950. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8951. executionFrequency, _ := json["execution_frequency"].(string)
  8952. advice.ExecutionFrequency = executionFrequency
  8953. }
  8954. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8955. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8956. advice.Price = price
  8957. }
  8958. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8959. med_list_codg, _ := json["medical_insurance_number"].(string)
  8960. advice.MedListCodg = med_list_codg
  8961. }
  8962. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8963. day := int64(json["day"].(float64))
  8964. advice.Day = day
  8965. }
  8966. advice.FrequencyType = 1
  8967. return 0
  8968. }
  8969. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8970. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8971. types := int64(json["type"].(float64))
  8972. project.Type = types
  8973. }
  8974. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8975. project_id := int64(json["project_id"].(float64))
  8976. project.ProjectId = project_id
  8977. }
  8978. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8979. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8980. project.Price = price
  8981. }
  8982. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8983. total, _ := json["total"].(string)
  8984. //totals, _ := strconv.ParseInt(total, 10, 64)
  8985. project.Count = total
  8986. }
  8987. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8988. medical_code, _ := json["medical_code"].(string)
  8989. project.MedListCodg = medical_code
  8990. }
  8991. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8992. single_dose, _ := json["single_dose"].(string)
  8993. project.SingleDose = single_dose
  8994. }
  8995. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8996. delivery_way, _ := json["delivery_way"].(string)
  8997. project.DeliveryWay = delivery_way
  8998. }
  8999. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  9000. execution_frequency, _ := json["execution_frequency"].(string)
  9001. project.ExecutionFrequency = execution_frequency
  9002. }
  9003. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  9004. remark, _ := json["remark"].(string)
  9005. project.Remark = remark
  9006. }
  9007. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  9008. day, _ := json["number_days"].(string)
  9009. project.Day = day
  9010. }
  9011. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  9012. unit, _ := json["unit"].(string)
  9013. project.Unit = unit
  9014. }
  9015. project.FrequencyType = 1
  9016. return 0
  9017. }
  9018. func (c *HisApiController) GetHisOrderListTwo() {
  9019. start_time := c.GetString("start_time")
  9020. end_time := c.GetString("end_time")
  9021. timeLayout := "2006-01-02"
  9022. loc, _ := time.LoadLocation("Local")
  9023. var startTime int64
  9024. if len(start_time) > 0 {
  9025. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9026. if err != nil {
  9027. //fmt.Println(err)
  9028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9029. return
  9030. }
  9031. startTime = theTime.Unix()
  9032. }
  9033. var endTime int64
  9034. if len(end_time) > 0 {
  9035. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9036. if err != nil {
  9037. utils.ErrorLog(err.Error())
  9038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9039. return
  9040. }
  9041. endTime = theTime.Unix()
  9042. }
  9043. adminUser := c.GetAdminUserInfo()
  9044. org_id := adminUser.CurrentOrgId
  9045. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  9046. if err == nil {
  9047. c.ServeSuccessJSON(map[string]interface{}{
  9048. "order2": order,
  9049. })
  9050. } else {
  9051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9052. return
  9053. }
  9054. }
  9055. func (c *HisApiController) GetHisOrderList() {
  9056. page, _ := c.GetInt64("page", -1)
  9057. limit, _ := c.GetInt64("limit", -1)
  9058. start_time := c.GetString("start_time")
  9059. end_time := c.GetString("end_time")
  9060. types, _ := c.GetInt64("type", 0)
  9061. keywords := c.GetString("keywords")
  9062. p_type, _ := c.GetInt64("p_type", 0)
  9063. sort_type, _ := c.GetInt64("sort_type", 0)
  9064. charge_type, _ := c.GetInt64("charge_type", 0)
  9065. sch_type, _ := c.GetInt64("sch_type", 0)
  9066. zone_type, _ := c.GetInt64("zone_type", 0)
  9067. med_type, _ := c.GetInt64("med_type", 0)
  9068. timeLayout := "2006-01-02"
  9069. loc, _ := time.LoadLocation("Local")
  9070. var startTime int64
  9071. if len(start_time) > 0 {
  9072. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9073. if err != nil {
  9074. //fmt.Println(err)
  9075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9076. return
  9077. }
  9078. startTime = theTime.Unix()
  9079. }
  9080. var endTime int64
  9081. if len(end_time) > 0 {
  9082. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9083. if err != nil {
  9084. utils.ErrorLog(err.Error())
  9085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9086. return
  9087. }
  9088. endTime = theTime.Unix()
  9089. }
  9090. adminUser := c.GetAdminUserInfo()
  9091. org_id := adminUser.CurrentOrgId
  9092. 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)
  9093. for _, item := range order {
  9094. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  9095. item.DoctorName = info.Doctor
  9096. item.DepartmentName = info.XtHisDepartment.Name
  9097. }
  9098. if err == nil {
  9099. c.ServeSuccessJSON(map[string]interface{}{
  9100. "order": order,
  9101. "total": total,
  9102. })
  9103. } else {
  9104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9105. return
  9106. }
  9107. }
  9108. func (c *HisApiController) GetHisOrder() {
  9109. patient_id, _ := c.GetInt64("patient_id", 0)
  9110. number := c.GetString("number")
  9111. adminInfo := c.GetAdminUserInfo()
  9112. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  9113. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  9114. if err == nil {
  9115. c.ServeSuccessJSON(map[string]interface{}{
  9116. "order": order,
  9117. "prescription": prescriptions,
  9118. })
  9119. } else {
  9120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9121. return
  9122. }
  9123. }
  9124. func (c *HisApiController) GetHisPrescriptionList() {
  9125. record_date := c.GetString("record_date")
  9126. keywords := c.GetString("keywords")
  9127. page, _ := c.GetInt64("page")
  9128. limit, _ := c.GetInt64("limit")
  9129. sch_type, _ := c.GetInt64("sch_type")
  9130. timeLayout := "2006-01-02"
  9131. loc, _ := time.LoadLocation("Local")
  9132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9133. if err != nil {
  9134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9135. return
  9136. }
  9137. recordDateTime := theTime.Unix()
  9138. adminInfo := c.GetAdminUserInfo()
  9139. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  9140. //adminInfo := c.GetAdminUserInfo()
  9141. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  9142. //fmt.Println(prescriptionOrder)
  9143. if err == nil {
  9144. c.ServeSuccessJSON(map[string]interface{}{
  9145. "order": prescriptionOrder,
  9146. "total": total,
  9147. })
  9148. } else {
  9149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9150. return
  9151. }
  9152. }
  9153. func (c *HisApiController) GetHisPrescriptionInfo() {
  9154. id, _ := c.GetInt64("id")
  9155. adminInfo := c.GetAdminUserInfo()
  9156. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  9157. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  9158. if err == nil {
  9159. c.ServeSuccessJSON(map[string]interface{}{
  9160. "order": prescriptionOrder,
  9161. "prescription": prescription,
  9162. })
  9163. } else {
  9164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9165. return
  9166. }
  9167. }
  9168. func (c *HisApiController) GetMedicalInsuranceConfig() {
  9169. adminUser := c.GetAdminUserInfo()
  9170. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  9171. c.ServeSuccessJSON(map[string]interface{}{
  9172. "config": config,
  9173. })
  9174. }
  9175. type ResultTwo struct {
  9176. ErrMsg interface{} `json:"err_msg"`
  9177. InfRefmsgid string `json:"inf_refmsgid"`
  9178. Infcode int64 `json:"infcode"`
  9179. Output struct {
  9180. Baseinfo struct {
  9181. Age float64 `json:"age"`
  9182. Brdy string `json:"brdy"`
  9183. Certno string `json:"certno"`
  9184. Gend string `json:"gend"`
  9185. Naty string `json:"naty"`
  9186. PsnCertType string `json:"psn_cert_type"`
  9187. PsnName string `json:"psn_name"`
  9188. PsnNo string `json:"psn_no"`
  9189. } `json:"baseinfo"`
  9190. Idetinfo []interface{} `json:"idetinfo"`
  9191. Iinfo []struct {
  9192. Balc float64 `json:"balc"`
  9193. CvlservFlag string `json:"cvlserv_flag"`
  9194. EmpName string `json:"emp_name"`
  9195. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  9196. Insutype string `json:"insutype"`
  9197. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  9198. PausInsuDate interface{} `json:"paus_insu_date"`
  9199. PsnInsuDate string `json:"psn_insu_date"`
  9200. PsnInsuStas string `json:"psn_insu_stas"`
  9201. PsnType string `json:"psn_type"`
  9202. } `json:"insuinfo"`
  9203. } `json:"output"`
  9204. RefmsgTime string `json:"refmsg_time"`
  9205. RespondTime string `json:"respond_time"`
  9206. Signtype interface{} `json:"signtype"`
  9207. WarnInfo interface{} `json:"warn_info"`
  9208. }
  9209. type ResultThree struct {
  9210. Cainfo interface{} `json:"cainfo"`
  9211. ErrMsg interface{} `json:"err_msg"`
  9212. InfRefmsgid string `json:"inf_refmsgid"`
  9213. Infcode int64 `json:"infcode"`
  9214. Output struct {
  9215. Data struct {
  9216. IptOtpNo string `json:"ipt_otp_no"`
  9217. MdtrtID string `json:"mdtrt_id"`
  9218. PsnNo string `json:"psn_no"`
  9219. } `json:"data"`
  9220. } `json:"output"`
  9221. RefmsgTime string `json:"refmsg_time"`
  9222. RespondTime string `json:"respond_time"`
  9223. Signtype interface{} `json:"signtype"`
  9224. WarnMsg interface{} `json:"warn_msg"`
  9225. }
  9226. type ResultFour struct {
  9227. Cainfo string `json:"cainfo"`
  9228. ErrMsg string `json:"err_msg"`
  9229. InfRefmsgid string `json:"inf_refmsgid"`
  9230. Infcode int64 `json:"infcode"`
  9231. Output struct {
  9232. Result []struct {
  9233. BasMednFlag string `json:"bas_medn_flag"`
  9234. ChldMedcFlag string `json:"chld_medc_flag"`
  9235. ChrgitmLv string `json:"chrgitm_lv"`
  9236. Cnt float64 `json:"cnt"`
  9237. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9238. DrtReimFlag string `json:"drt_reim_flag"`
  9239. FeedetlSn string `json:"feedetl_sn"`
  9240. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9241. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9242. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9243. ListSpItemFlag string `json:"list_sp_item_flag"`
  9244. LmtUsedFlag string `json:"lmt_used_flag"`
  9245. MedChrgitmType string `json:"med_chrgitm_type"`
  9246. Memo string `json:"memo"`
  9247. OverlmtAmt float64 `json:"overlmt_amt"`
  9248. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9249. Pric float64 `json:"pric"`
  9250. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9251. SelfpayProp float64 `json:"selfpay_prop"`
  9252. } `json:"result"`
  9253. } `json:"output"`
  9254. RefmsgTime string `json:"refmsg_time"`
  9255. RespondTime string `json:"respond_time"`
  9256. Signtype string `json:"signtype"`
  9257. WarnMsg string `json:"warn_msg"`
  9258. }
  9259. type ResultFive struct {
  9260. Insutype string `json:"insutype"`
  9261. }
  9262. type ResultSix struct {
  9263. Cainfo interface{} `json:"cainfo"`
  9264. ErrMsg interface{} `json:"err_msg"`
  9265. InfRefmsgid string `json:"inf_refmsgid"`
  9266. Infcode int64 `json:"infcode"`
  9267. Output struct {
  9268. } `json:"output"`
  9269. RefmsgTime string `json:"refmsg_time"`
  9270. RespondTime string `json:"respond_time"`
  9271. Signtype interface{} `json:"signtype"`
  9272. WarnMsg interface{} `json:"warn_msg"`
  9273. }
  9274. type ResultSeven struct {
  9275. Cainfo string `json:"cainfo"`
  9276. ErrMsg string `json:"err_msg"`
  9277. InfRefmsgid string `json:"inf_refmsgid"`
  9278. Infcode int64 `json:"infcode"`
  9279. Output struct {
  9280. Setldetail []interface{} `json:"setldetail"`
  9281. Setlinfo struct {
  9282. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9283. AcctPay float64 `json:"acct_pay"`
  9284. ActPayDedc float64 `json:"act_pay_dedc"`
  9285. Age float64 `json:"age"`
  9286. Balc float64 `json:"balc"`
  9287. Brdy string `json:"brdy"`
  9288. Certno string `json:"certno"`
  9289. ClrOptins string `json:"clr_optins"`
  9290. ClrType string `json:"clr_type"`
  9291. ClrWay string `json:"clr_way"`
  9292. CvlservFlag string `json:"cvlserv_flag"`
  9293. CvlservPay float64 `json:"cvlserv_pay"`
  9294. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9295. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9296. Gend string `json:"gend"`
  9297. HifesPay float64 `json:"hifes_pay"`
  9298. HifmiPay float64 `json:"hifmi_pay"`
  9299. HifobPay float64 `json:"hifob_pay"`
  9300. HifpPay float64 `json:"hifp_pay"`
  9301. HospPartAmt float64 `json:"hosp_part_amt"`
  9302. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9303. Insutype string `json:"insutype"`
  9304. MafPay float64 `json:"maf_pay"`
  9305. MdtrtCertType string `json:"mdtrt_cert_type"`
  9306. MdtrtID string `json:"mdtrt_id"`
  9307. MedType string `json:"med_type"`
  9308. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9309. MedinsSetlID string `json:"medins_setl_id"`
  9310. Naty string `json:"naty"`
  9311. OthPay float64 `json:"oth_pay"`
  9312. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9313. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9314. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9315. PsnCashPay float64 `json:"psn_cash_pay"`
  9316. PsnCertType string `json:"psn_cert_type"`
  9317. PsnName string `json:"psn_name"`
  9318. PsnNo string `json:"psn_no"`
  9319. PsnPartAmt float64 `json:"psn_part_amt"`
  9320. PsnType string `json:"psn_type"`
  9321. SetlID string `json:"setl_id"`
  9322. SetlTime string `json:"setl_time"`
  9323. } `json:"setlinfo"`
  9324. } `json:"output"`
  9325. RefmsgTime string `json:"refmsg_time"`
  9326. RespondTime string `json:"respond_time"`
  9327. Signtype interface{} `json:"signtype"`
  9328. WarnMsg interface{} `json:"warn_msg"`
  9329. }
  9330. type ResultEight struct {
  9331. Cainfo string `json:"cainfo"`
  9332. ErrMsg string `json:"err_msg"`
  9333. InfRefmsgid string `json:"inf_refmsgid"`
  9334. Infcode int64 `json:"infcode"`
  9335. Output struct {
  9336. Stmtinfo struct {
  9337. SetlOptins string `json:"setl_optins"`
  9338. StmtRslt string `json:"stmt_rslt"`
  9339. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9340. } `json:"stmtinfo"`
  9341. } `json:"output"`
  9342. RefmsgTime string `json:"refmsg_time"`
  9343. RespondTime string `json:"respond_time"`
  9344. Signtype interface{} `json:"signtype"`
  9345. WarnMsg interface{} `json:"warn_msg"`
  9346. }
  9347. type ResultNine struct {
  9348. Cainfo string `json:"cainfo"`
  9349. ErrMsg string `json:"err_msg"`
  9350. InfRefmsgid string `json:"inf_refmsgid"`
  9351. Infcode int64 `json:"infcode"`
  9352. Output struct {
  9353. FileQuryNo string `json:"file_qury_no"`
  9354. } `json:"output"`
  9355. RefmsgTime string `json:"refmsg_time"`
  9356. RespondTime string `json:"respond_time"`
  9357. Signtype interface{} `json:"signtype"`
  9358. WarnMsg interface{} `json:"warn_msg"`
  9359. }
  9360. type ResultTen struct {
  9361. Cainfo string `json:"cainfo"`
  9362. ErrMsg string `json:"err_msg"`
  9363. InfRefmsgid string `json:"inf_refmsgid"`
  9364. Infcode int64 `json:"infcode"`
  9365. Output struct {
  9366. DldEndtime string `json:"dld_endtime"`
  9367. FileQuryNo string `json:"file_qury_no"`
  9368. Filename string `json:"filename"`
  9369. } `json:"output"`
  9370. RefmsgTime string `json:"refmsg_time"`
  9371. RespondTime string `json:"respond_time"`
  9372. Signtype interface{} `json:"signtype"`
  9373. WarnMsg interface{} `json:"warn_msg"`
  9374. }
  9375. type ResultEleven struct {
  9376. Cainfo string `json:"cainfo"`
  9377. ErrMsg string `json:"err_msg"`
  9378. InfRefmsgid string `json:"inf_refmsgid"`
  9379. Infcode int64 `json:"infcode"`
  9380. Output struct {
  9381. Setlinfo struct {
  9382. FixmedinsName string `json:"fixmedins_name"`
  9383. FixmedinsCode string `json:"fixmedins_code"`
  9384. PsnNo string `json:"psn_no"`
  9385. PsnName string `json:"psn_name"`
  9386. HifobPay float64 `json:"hifob_pay"`
  9387. Gend string `json:"gend"`
  9388. Brdy string `json:"brdy"`
  9389. PsnCertType string `json:"psn_cert_type"`
  9390. PsnType string `json:"psn_type"`
  9391. EmpName string `json:"emp_name"`
  9392. Certno string `json:"certno"`
  9393. Insutype string `json:"insutype"`
  9394. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9395. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9396. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9397. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9398. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9399. ActPayDedc float64 `json:"act_pay_dedc"`
  9400. HifpPay float64 `json:"hifp_pay"`
  9401. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9402. CvlservPay float64 `json:"cvlserv_pay"`
  9403. HifesPay float64 `json:"hifes_pay"`
  9404. HifmiPay float64 `json:"hifmi_pay"`
  9405. MafPay float64 `json:"maf_pay"`
  9406. OthPay float64 `json:"oth_pay"`
  9407. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9408. PsnPay float64 `json:"psn_pay"`
  9409. AcctPay float64 `json:"acct_pay"`
  9410. CashPayamt float64 `json:"cash_payamt"`
  9411. Balc float64 `json:"balc"`
  9412. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9413. MedinsSetlId string `json:"medins_setl_id"`
  9414. RefdSetlFlag string `json:"refd_setl_flag"`
  9415. SetlTime string `json:"setl_time"`
  9416. MedType string `json:"med_type"`
  9417. } `json:"setlinfo"`
  9418. } `json:"output"`
  9419. RefmsgTime string `json:"refmsg_time"`
  9420. RespondTime string `json:"respond_time"`
  9421. Signtype interface{} `json:"signtype"`
  9422. WarnMsg interface{} `json:"warn_msg"`
  9423. }
  9424. type Custom struct {
  9425. DetItemFeeSumamt string
  9426. Cut string
  9427. FeedetlSn string
  9428. Price string
  9429. MedListCodg string
  9430. Type int64
  9431. AdviceId int64
  9432. ProjectId int64
  9433. ItemId int64
  9434. CostType int64
  9435. }
  9436. // 获取个人信息----挂号-----上传就诊信息
  9437. func (c *HisApiController) GetRegisterInfo() {
  9438. id, _ := c.GetInt64("id")
  9439. record_time := c.GetString("record_time")
  9440. settlementValue, _ := c.GetInt64("settlement_value")
  9441. medical_insurance_card := c.GetString("medical_insurance_card")
  9442. name := c.GetString("name")
  9443. id_card_type, _ := c.GetInt64("id_card_type")
  9444. certificates, _ := c.GetInt64("certificates")
  9445. medical_care, _ := c.GetInt64("medical_care")
  9446. birthday := c.GetString("birthday")
  9447. age, _ := c.GetInt64("age")
  9448. id_card := c.GetString("id_card")
  9449. register_type, _ := c.GetInt64("register")
  9450. doctor, _ := c.GetInt64("doctor")
  9451. department, _ := c.GetInt64("department")
  9452. gender, _ := c.GetInt64("sex")
  9453. phone := c.GetString("phone")
  9454. registration_fee, _ := c.GetFloat("registration_fee")
  9455. medical_expenses, _ := c.GetFloat("medical_expenses")
  9456. social_type, _ := c.GetInt64("social_type")
  9457. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9458. diagnosis_ids := c.GetString("diagnosis")
  9459. sick_type, _ := c.GetInt64("sick_type")
  9460. reg_type := c.GetString("p_type")
  9461. timeLayout := "2006-01-02"
  9462. loc, _ := time.LoadLocation("Local")
  9463. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9464. birthUnix := birthdays.Unix()
  9465. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9466. if err != nil {
  9467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9468. return
  9469. }
  9470. recordDateTime := theTime.Unix()
  9471. adminInfo := c.GetAdminUserInfo()
  9472. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9473. if tempPatient.ID == 0 {
  9474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9475. return
  9476. }
  9477. var patient service.Patients
  9478. if id == 0 {
  9479. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9480. } else {
  9481. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9482. }
  9483. if patient.ID == 0 {
  9484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9485. return
  9486. }
  9487. if len(patient.IdCardNo) == 0 {
  9488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9489. return
  9490. }
  9491. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9492. if len(his) >= 1 {
  9493. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9494. if len(his) >= 1 && order.ID == 0 {
  9495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9496. return
  9497. }
  9498. }
  9499. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9500. fmt.Println(timeStr)
  9501. timeArr := strings.Split(timeStr, " ")
  9502. fmt.Println(timeArr)
  9503. timeArrTwo := strings.Split(timeArr[0], "-")
  9504. timeArrThree := strings.Split(timeArr[1], ":")
  9505. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9506. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9507. if len(lists) == 0 {
  9508. var hisPatient models.XtHisPatient
  9509. hisPatient = models.XtHisPatient{
  9510. Name: name,
  9511. Age: age,
  9512. Gender: gender,
  9513. Birthday: birthUnix,
  9514. Phone: phone,
  9515. MedicalTreatmentType: medical_care,
  9516. IdType: certificates,
  9517. IdCardNo: id_card,
  9518. BalanceAccountsType: settlementValue,
  9519. SocialType: social_type,
  9520. MedicalInsuranceNumber: medical_insurance_card,
  9521. RegisterType: register_type,
  9522. RegisterCost: registration_fee,
  9523. TreatmentCost: medical_expenses,
  9524. AdminUserId: adminInfo.AdminUser.Id,
  9525. UserOrgId: adminInfo.CurrentOrgId,
  9526. Status: 1,
  9527. RecordDate: recordDateTime,
  9528. IsReturn: 1,
  9529. PatientId: patient.ID,
  9530. Ctime: time.Now().Unix(),
  9531. Mtime: time.Now().Unix(),
  9532. Number: str,
  9533. IdCardType: id_card_type,
  9534. Departments: department,
  9535. Doctor: doctor,
  9536. PType: reg_type,
  9537. Diagnosis: diagnosis_ids,
  9538. SickType: sick_type,
  9539. }
  9540. service.CreateHisPatient(&hisPatient)
  9541. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9542. c.ServeSuccessJSON(map[string]interface{}{
  9543. "his_info": hisPatient,
  9544. })
  9545. } else {
  9546. //chrgBchno := rand.Intn(1000000) + 10000
  9547. var hisPatient models.XtHisPatient
  9548. hisPatient = models.XtHisPatient{
  9549. Name: name,
  9550. Age: age,
  9551. Gender: gender,
  9552. Birthday: birthUnix,
  9553. Phone: phone,
  9554. MedicalTreatmentType: medical_care,
  9555. IdType: certificates,
  9556. IdCardNo: id_card,
  9557. BalanceAccountsType: settlementValue,
  9558. SocialType: social_type,
  9559. MedicalInsuranceNumber: medical_insurance_card,
  9560. RegisterType: register_type,
  9561. RegisterCost: registration_fee,
  9562. TreatmentCost: medical_expenses,
  9563. AdminUserId: adminInfo.AdminUser.Id,
  9564. UserOrgId: adminInfo.CurrentOrgId,
  9565. Status: 1,
  9566. RecordDate: recordDateTime,
  9567. IsReturn: 1,
  9568. PatientId: patient.ID,
  9569. Ctime: time.Now().Unix(),
  9570. Mtime: time.Now().Unix(),
  9571. Number: str,
  9572. IdCardType: id_card_type,
  9573. Departments: department,
  9574. Doctor: doctor,
  9575. PType: reg_type,
  9576. Diagnosis: diagnosis_ids,
  9577. SickType: sick_type,
  9578. }
  9579. service.CreateHisPatient(&hisPatient)
  9580. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9581. c.ServeSuccessJSON(map[string]interface{}{
  9582. "his_info": hisPatient,
  9583. })
  9584. }
  9585. }
  9586. // 上传明细----结算
  9587. func (c *HisApiController) GetUploadInfo() {
  9588. id, _ := c.GetInt64("id")
  9589. record_time := c.GetString("record_time")
  9590. his_patient_id, _ := c.GetInt64("his_patient_id")
  9591. oth_desc := c.GetString("oth_desc")
  9592. pay_way, _ := c.GetInt64("pay_way")
  9593. pay_ways := c.GetString("pay_ways")
  9594. pay_price, _ := c.GetFloat("pay_price")
  9595. pay_card_no := c.GetString("pay_card_no")
  9596. discount_price, _ := c.GetFloat("discount_price")
  9597. preferential_price, _ := c.GetFloat("preferential_price")
  9598. reality_price, _ := c.GetFloat("reality_price")
  9599. found_price, _ := c.GetFloat("found_price")
  9600. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9601. private_price, _ := c.GetFloat("private_price")
  9602. timeLayout := "2006-01-02"
  9603. loc, _ := time.LoadLocation("Local")
  9604. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9605. fapiao_code := c.GetString("fapiao_code")
  9606. fapiao_number := c.GetString("fapiao_number")
  9607. diagnosis_id := c.GetString("diagnosis")
  9608. sick_type, _ := c.GetInt64("sick_type")
  9609. reg_type, _ := c.GetInt64("p_type")
  9610. order_id, _ := c.GetInt64("order_id")
  9611. cash_pay := c.GetString("cash_pay")
  9612. wechat_pay := c.GetString("wechat_pay")
  9613. ali_pay := c.GetString("ali_pay")
  9614. jifen_pay := c.GetString("jifen_pay")
  9615. card_desc := c.GetString("card_desc")
  9616. band_card_pay := c.GetString("band_card_pay")
  9617. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9618. tmp_decimal := c.GetString("tmp_decimal")
  9619. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9620. var decimal float64 //本次使用的押金
  9621. var errmsg error
  9622. tx := service.XTWriteDB().Begin() //开了事务
  9623. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9624. defer func() {
  9625. if errmsg != nil {
  9626. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9627. tx.Rollback()
  9628. } else {
  9629. tx.Commit()
  9630. }
  9631. }()
  9632. fmt.Println("dec_way", dec_way)
  9633. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9634. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9635. return
  9636. }
  9637. if len(tmp_decimal) > 0 {
  9638. if tmp_decimal[0] == 45 {
  9639. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9640. return
  9641. }
  9642. }
  9643. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9644. fmt.Println(errs)
  9645. decimal = tt
  9646. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9647. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9648. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9649. if err != nil {
  9650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9651. return
  9652. }
  9653. recordDateTime := theTime.Unix()
  9654. adminUser := c.GetAdminUserInfo()
  9655. var prescriptions []*models.HisPrescription
  9656. var prescriptionsOne []*models.HisPrescription
  9657. var start_time int64
  9658. var end_time int64
  9659. ids_str := c.GetString("ids")
  9660. ids_arr := strings.Split(ids_str, ",")
  9661. if tempOrder.ID == 0 {
  9662. if settle_accounts_type == 1 { //日结
  9663. fmt.Println(reg_type)
  9664. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9665. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9666. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9667. } else {
  9668. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9669. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9670. }
  9671. } else { //月结
  9672. start_time_str := c.GetString("start_time")
  9673. end_time_str := c.GetString("end_time")
  9674. timeLayout := "2006-01-02"
  9675. loc, _ := time.LoadLocation("Local")
  9676. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9677. if err != nil {
  9678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9679. return
  9680. }
  9681. recordStartTime := theStartTime.Unix()
  9682. start_time = recordStartTime
  9683. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9684. if err != nil {
  9685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9686. return
  9687. }
  9688. recordEndTime := theEndTime.Unix()
  9689. end_time = recordEndTime
  9690. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9691. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9692. }
  9693. var goods []*models.DialysisBeforePrepareGoods
  9694. var newGoods []*models.NewDialysisBeforePrepareGoods
  9695. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9696. var infos []*models.HisDoctorAdviceInfo
  9697. var infoList []*models.HisDoctorAdviceInfo
  9698. var hisAdvice []*models.HisDoctorAdviceInfo
  9699. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9700. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9701. //判断库存不足
  9702. //结算出库开关
  9703. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9704. if settConfig.IsOpen == 1 {
  9705. //判断库存的地方
  9706. for _, info := range prescriptions {
  9707. if info.Type == 1 {
  9708. infos = append(infos, info.HisDoctorAdviceInfo...)
  9709. }
  9710. if info.Type == 2 {
  9711. for _, sumItem := range info.HisPrescriptionProject {
  9712. if sumItem.Type == 3 {
  9713. var good models.DialysisBeforePrepareGoods
  9714. var newGood models.NewDialysisBeforePrepareGoods
  9715. good.GoodId = sumItem.GoodInfo.ID
  9716. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9717. count, _ := strconv.Atoi(sumItem.Count)
  9718. good.Count = int64(count)
  9719. good.StorehouseId = houseConfig.StorehouseOutInfo
  9720. good.ProjectId = sumItem.ID
  9721. goods = append(goods, &good)
  9722. newGood.GoodId = sumItem.GoodInfo.ID
  9723. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9724. count2, _ := strconv.Atoi(sumItem.Count)
  9725. newGood.Count = int64(count2)
  9726. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9727. newGood.ProjectId = sumItem.ID
  9728. newGoods = append(newGoods, &newGood)
  9729. }
  9730. }
  9731. }
  9732. }
  9733. for _, info := range prescriptionsOne {
  9734. if info.Type == 1 {
  9735. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9736. }
  9737. if info.Type == 2 {
  9738. for _, sumItem := range info.HisPrescriptionProject {
  9739. if sumItem.Type == 3 {
  9740. var newGood models.NewDialysisBeforePrepareGoods
  9741. newGood.GoodId = sumItem.GoodInfo.ID
  9742. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9743. count2, _ := strconv.Atoi(sumItem.Count)
  9744. newGood.Count = int64(count2)
  9745. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9746. newGood.ProjectId = sumItem.ID
  9747. newGoodOne = append(newGoodOne, &newGood)
  9748. }
  9749. }
  9750. }
  9751. }
  9752. //判断
  9753. for _, itemOne := range infos {
  9754. for _, itemTwo := range hisAdvice {
  9755. if itemOne.DrugId == itemTwo.DrugId {
  9756. itemTwo.Child = append(itemTwo.Child, itemOne)
  9757. }
  9758. }
  9759. }
  9760. for _, itemTwo := range hisAdvice {
  9761. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9762. var sum_out_count int64
  9763. for _, itemThree := range itemTwo.Child {
  9764. var prescribing_number int64
  9765. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9766. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9767. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9768. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9769. }
  9770. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9771. prescribing_number = parseIntPrescribingNumber
  9772. }
  9773. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9774. prescribing_number = parseIntPrescribingNumber
  9775. }
  9776. sum_out_count += prescribing_number
  9777. }
  9778. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9779. if sum_out_count > drugStockOut.FlushCount {
  9780. c.ServeSuccessJSON(map[string]interface{}{
  9781. "msg": "2",
  9782. "drug": medical,
  9783. })
  9784. return
  9785. }
  9786. }
  9787. for _, itemOne := range newGoods {
  9788. for _, item := range newGoodOne {
  9789. if itemOne.GoodId == item.GoodId {
  9790. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9791. }
  9792. }
  9793. }
  9794. for _, item := range newGoodOne {
  9795. var sum_out_count_one int64
  9796. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9797. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9798. sum_out_count_one += itemOne.Count
  9799. }
  9800. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9801. fmt.Println("sum_out_count_one", sum_out_count_one)
  9802. fmt.Println("list.FlushCount", list.FlushCount)
  9803. if sum_out_count_one > list.FlushCount {
  9804. c.ServeSuccessJSON(map[string]interface{}{
  9805. "msg": "3",
  9806. "good": good,
  9807. })
  9808. return
  9809. }
  9810. }
  9811. }
  9812. timestamp := time.Now().Unix()
  9813. tempTime := time.Unix(timestamp, 0)
  9814. timeFormat := tempTime.Format("20060102150405")
  9815. chrgBchno := rand.Intn(100000) + 10000
  9816. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9817. strconv.FormatInt(his.PatientId, 10)
  9818. var ids []int64
  9819. for _, item := range prescriptions {
  9820. ids = append(ids, item.ID)
  9821. }
  9822. var total float64
  9823. for _, item := range prescriptions {
  9824. fmt.Println(item)
  9825. if item.Type == 1 { //药品
  9826. for _, subItem := range item.HisDoctorAdviceInfo {
  9827. if subItem.Drug.IsUser != 1 {
  9828. total = total + (subItem.Price * subItem.PrescribingNumber)
  9829. }
  9830. }
  9831. }
  9832. if item.Type == 2 { //项目
  9833. for _, subItem := range item.HisPrescriptionProject {
  9834. if subItem.Type == 2 {
  9835. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9836. total = total + (subItem.Price * cnt)
  9837. } else {
  9838. if subItem.GoodInfo.IsUser != 1 {
  9839. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9840. total = total + (subItem.Price * cnt)
  9841. }
  9842. }
  9843. }
  9844. }
  9845. for _, subItem := range item.HisAdditionalCharge {
  9846. total = total + (subItem.Price * float64(subItem.Count))
  9847. }
  9848. }
  9849. if reg_type == 1111 || reg_type == 1112 {
  9850. reg_type = 11
  9851. }
  9852. tm := time.Unix(time.Now().Unix(), 0)
  9853. allTotal := fmt.Sprintf("%.4f", total)
  9854. totals, _ := strconv.ParseFloat(allTotal, 64)
  9855. order := &models.HisOrder{
  9856. UserOrgId: adminUser.CurrentOrgId,
  9857. HisPatientId: his.ID,
  9858. PatientId: id,
  9859. SettleAccountsDate: recordDateTime,
  9860. Ctime: time.Now().Unix(),
  9861. Mtime: time.Now().Unix(),
  9862. Status: 1,
  9863. OrderStatus: 2,
  9864. MdtrtId: his.Number,
  9865. Number: chrg_bchno,
  9866. MedfeeSumamt: totals,
  9867. PayWay: pay_way,
  9868. PayWays: pay_ways,
  9869. PayPrice: pay_price,
  9870. MedType: strconv.Itoa(int(reg_type)),
  9871. PayCardNo: pay_card_no,
  9872. DiscountPrice: discount_price,
  9873. PreferentialPrice: preferential_price,
  9874. RealityPrice: reality_price,
  9875. FoundPrice: found_price,
  9876. MedicalInsurancePrice: medical_insurance_price,
  9877. PrivatePrice: private_price,
  9878. SettleEndTime: end_time,
  9879. SettleStartTime: start_time,
  9880. PsnPartAmt: totals,
  9881. PsnCashPay: totals,
  9882. SettleType: settle_accounts_type,
  9883. FaPiaoCode: fapiao_code,
  9884. FaPiaoNumber: fapiao_number,
  9885. Diagnosis: diagnosis_id,
  9886. PType: 2,
  9887. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9888. Decimal: decimal,
  9889. OthDesc: oth_desc,
  9890. CashPay: cash_pay,
  9891. WechatPay: wechat_pay,
  9892. AliPay: ali_pay,
  9893. JifenPay: jifen_pay,
  9894. BandCardPay: band_card_pay,
  9895. Creator: adminUser.AdminUser.Id,
  9896. CardDesc: card_desc,
  9897. }
  9898. err = service.CreateOrderTX(order, tx)
  9899. if err != nil {
  9900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9901. return
  9902. }
  9903. var customs []*Custom
  9904. for _, item := range prescriptions {
  9905. if item.Type == 1 { //药品a
  9906. for _, subItem := range item.HisDoctorAdviceInfo {
  9907. if subItem.Drug.IsUser != 1 {
  9908. cus := &Custom{
  9909. AdviceId: subItem.ID,
  9910. ProjectId: 0,
  9911. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9912. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9913. FeedetlSn: subItem.FeedetlSn,
  9914. Price: fmt.Sprintf("%.4f", subItem.Price),
  9915. MedListCodg: subItem.MedListCodg,
  9916. Type: 1,
  9917. CostType: 9,
  9918. }
  9919. customs = append(customs, cus)
  9920. }
  9921. }
  9922. }
  9923. if item.Type == 2 { //项目
  9924. for _, subItem := range item.HisPrescriptionProject {
  9925. if subItem.Type == 2 {
  9926. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9927. cus := &Custom{
  9928. AdviceId: 0,
  9929. ProjectId: subItem.ID,
  9930. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9931. Cut: fmt.Sprintf("%.4f", cnt),
  9932. FeedetlSn: subItem.FeedetlSn,
  9933. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9934. MedListCodg: subItem.MedListCodg,
  9935. Type: 2,
  9936. CostType: subItem.HisProject.CostClassify,
  9937. }
  9938. customs = append(customs, cus)
  9939. } else {
  9940. if subItem.GoodInfo.IsUser != 1 {
  9941. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9942. cus := &Custom{
  9943. AdviceId: 0,
  9944. ProjectId: subItem.ID,
  9945. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9946. Cut: fmt.Sprintf("%.4f", cnt),
  9947. FeedetlSn: subItem.FeedetlSn,
  9948. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9949. MedListCodg: subItem.MedListCodg,
  9950. Type: 2,
  9951. CostType: subItem.HisProject.CostClassify,
  9952. }
  9953. customs = append(customs, cus)
  9954. }
  9955. }
  9956. }
  9957. }
  9958. for _, item := range item.HisAdditionalCharge {
  9959. cus := &Custom{
  9960. ItemId: item.ID,
  9961. AdviceId: 0,
  9962. ProjectId: 0,
  9963. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9964. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9965. FeedetlSn: item.FeedetlSn,
  9966. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9967. MedListCodg: item.XtHisAddtionConfig.Code,
  9968. Type: 3,
  9969. CostType: 5,
  9970. }
  9971. customs = append(customs, cus)
  9972. }
  9973. }
  9974. for _, item := range customs {
  9975. var advice_id int64 = 0
  9976. var project_id int64 = 0
  9977. var item_id int64 = 0
  9978. var types int64 = 0
  9979. var med_chrgitm_type string
  9980. if item.Type == 1 {
  9981. advice_id = item.AdviceId
  9982. project_id = 0
  9983. item_id = 0
  9984. med_chrgitm_type = "09"
  9985. } else if item.Type == 2 {
  9986. med_chrgitm_type = "05"
  9987. if item.CostType == 3 {
  9988. med_chrgitm_type = "04"
  9989. }
  9990. if item.CostType == 8 {
  9991. med_chrgitm_type = "03"
  9992. }
  9993. advice_id = 0
  9994. item_id = 0
  9995. project_id = item.ProjectId
  9996. } else if item.Type == 3 {
  9997. advice_id = 0
  9998. item_id = item.ItemId
  9999. project_id = 0
  10000. med_chrgitm_type = "08"
  10001. }
  10002. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10003. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10004. pric, _ := strconv.ParseFloat(item.Price, 32)
  10005. info := &models.HisOrderInfo{
  10006. OrderNumber: order.Number,
  10007. UploadDate: time.Now().Unix(),
  10008. AdviceId: advice_id,
  10009. DetItemFeeSumamt: detItemFeeSumamt,
  10010. MedChrgitmType: med_chrgitm_type,
  10011. Cnt: cut,
  10012. Pric: pric,
  10013. PatientId: id,
  10014. Status: 1,
  10015. Mtime: time.Now().Unix(),
  10016. Ctime: time.Now().Unix(),
  10017. UserOrgId: adminUser.CurrentOrgId,
  10018. HisPatientId: his.ID,
  10019. OrderId: order.ID,
  10020. ProjectId: project_id,
  10021. Type: types,
  10022. ItemId: item_id,
  10023. }
  10024. service.CreateOrderInfoTX(info, tx)
  10025. }
  10026. his.Diagnosis = diagnosis_id
  10027. his.SickType = sick_type
  10028. his.RegisterType = reg_type
  10029. his.MedicalTreatmentType = reg_type
  10030. service.UpdataHisPateintTX(&his, tx)
  10031. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  10032. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  10033. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  10034. //判断是否使用了押金
  10035. if dec_way == "true" {
  10036. tmpstring := strconv.FormatInt(order.ID, 10)
  10037. //扣押金
  10038. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  10039. order.Decimal = decimal
  10040. service.UpDateOrderTwo(order, tx)
  10041. if errmsg != nil {
  10042. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  10043. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10044. return
  10045. }
  10046. }
  10047. if err == nil {
  10048. for _, info := range prescriptions {
  10049. if info.Type == 1 {
  10050. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  10051. }
  10052. if info.Type == 2 {
  10053. for _, sumItem := range info.HisPrescriptionProject {
  10054. if sumItem.Type == 3 {
  10055. var good models.DialysisBeforePrepareGoods
  10056. var newGood models.NewDialysisBeforePrepareGoods
  10057. var oldGood models.OldDialysisBeforePrepareGoods
  10058. good.GoodId = sumItem.GoodInfo.ID
  10059. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10060. count, _ := strconv.Atoi(sumItem.Count)
  10061. good.Count = int64(count)
  10062. good.StorehouseId = houseConfig.StorehouseOutInfo
  10063. good.ProjectId = sumItem.ID
  10064. good.PatientId = sumItem.PatientId
  10065. goods = append(goods, &good)
  10066. newGood.GoodId = sumItem.GoodInfo.ID
  10067. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10068. count2, _ := strconv.Atoi(sumItem.Count)
  10069. newGood.Count = int64(count2)
  10070. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10071. newGood.ProjectId = sumItem.ID
  10072. newGood.PatientId = sumItem.HisPatientId
  10073. newGoods = append(newGoods, &newGood)
  10074. oldGood.GoodId = sumItem.GoodInfo.ID
  10075. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10076. count3, _ := strconv.Atoi(sumItem.Count)
  10077. oldGood.Count = int64(count3)
  10078. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  10079. oldGood.ProjectId = sumItem.ID
  10080. oldGood.RecordDate = sumItem.RecordDate
  10081. oldGood.PatientId = sumItem.HisPatientId
  10082. oldGoods = append(oldGoods, &oldGood)
  10083. }
  10084. }
  10085. }
  10086. }
  10087. if settConfig.IsOpen == 1 {
  10088. for _, item := range infoList {
  10089. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  10090. if medical.IsUse == 2 {
  10091. //药品出库
  10092. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  10093. //查询默认仓库
  10094. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  10095. //查询默认仓库剩余多少库存
  10096. var sum_count int64
  10097. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  10098. for _, its := range stockInfo {
  10099. if its.MaxUnit == medical.MaxUnit {
  10100. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  10101. }
  10102. sum_count += its.StockMaxNumber + its.StockMinNumber
  10103. }
  10104. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  10105. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  10106. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  10107. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  10108. }
  10109. }
  10110. orgId := c.GetAdminUserInfo().CurrentOrgId
  10111. if len(oldGoods) > 0 {
  10112. timeStr := time.Now().Format("2006-01-02")
  10113. timeArr := strings.Split(timeStr, "-")
  10114. total, _ := service.FindAllWarehouseOut(orgId)
  10115. total = total + 1
  10116. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  10117. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  10118. number = number + total
  10119. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  10120. operation_time := time.Now().Unix()
  10121. creater := c.GetAdminUserInfo().AdminUser.Id
  10122. //查询默认出库仓库库存
  10123. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  10124. recordDateStr := time.Now().Format("2006-01-02")
  10125. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  10126. nowtime := recordDate.Unix()
  10127. warehouseOut := models.WarehouseOut{
  10128. WarehouseOutOrderNumber: warehousing_out_order,
  10129. OperationTime: operation_time,
  10130. OrgId: orgId,
  10131. Creater: creater,
  10132. Ctime: time.Now().Unix(),
  10133. Status: 1,
  10134. WarehouseOutTime: nowtime,
  10135. Type: 1,
  10136. StorehouseId: storeConfig.StorehouseOutInfo,
  10137. IsCheck: 1,
  10138. OrderId: order.ID,
  10139. IsSys: 5,
  10140. }
  10141. //查询是否生成出库单
  10142. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10143. if out.ID == 0 {
  10144. service.AddSigleWarehouseOutOne(&warehouseOut)
  10145. }
  10146. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10147. for _, item := range oldGoods {
  10148. dialyPrepareOne := models.DialysisBeforePrepare{
  10149. GoodTypeId: item.GoodTypeId,
  10150. GoodId: item.GoodId,
  10151. PatientId: his.PatientId,
  10152. RecordDate: item.RecordDate,
  10153. UserOrgId: adminUser.CurrentOrgId,
  10154. Count: item.Count,
  10155. Ctime: time.Now().Unix(),
  10156. Creater: adminUser.AdminUser.Id,
  10157. CommdityCode: item.CommdityCode,
  10158. Status: 1,
  10159. StorehouseId: houseConfig.StorehouseOutInfo,
  10160. }
  10161. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  10162. //非零用
  10163. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  10164. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10165. //查询剩余库存
  10166. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10167. var sum_count int64
  10168. for _, item := range goodList {
  10169. sum_count += item.StockCount
  10170. }
  10171. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10172. //耗材
  10173. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10174. }
  10175. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  10176. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10177. //查询剩余库存
  10178. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10179. var sum_count int64
  10180. for _, item := range goodList {
  10181. sum_count += item.StockCount
  10182. }
  10183. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10184. //耗材
  10185. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10186. }
  10187. }
  10188. }
  10189. }
  10190. c.ServeSuccessJSON(map[string]interface{}{
  10191. "msg": "结算成功",
  10192. })
  10193. }
  10194. }
  10195. }
  10196. // 退款
  10197. func (c *HisApiController) Refund() {
  10198. order_id, _ := c.GetInt64("order_id")
  10199. order, _ := service.GetHisOrderByID(order_id)
  10200. adminUser := c.GetAdminUserInfo()
  10201. orgid := c.GetAdminUserInfo().CurrentOrgId
  10202. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  10203. if err != nil {
  10204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10205. return
  10206. }
  10207. tmp := strconv.FormatInt(order.ID, 10)
  10208. //当押金不为零时产生退费记录
  10209. if order.Decimal != 0 {
  10210. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  10211. if err != nil {
  10212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10213. return
  10214. }
  10215. }
  10216. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  10217. if fapiao.ID > 0 {
  10218. c.ServeSuccessJSON(map[string]interface{}{
  10219. "failed_code": -10,
  10220. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  10221. })
  10222. return
  10223. }
  10224. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  10225. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  10226. var goods []*models.DialysisBeforePrepareGoods
  10227. var newGoods []*models.NewDialysisBeforePrepareGoods
  10228. var infos []*models.HisDoctorAdviceInfo
  10229. for _, info := range orders {
  10230. if info.AdviceId > 0 && info.ProjectId == 0 {
  10231. infos = append(infos, &info.HisDoctorAdviceInfo)
  10232. }
  10233. if info.ProjectId > 0 && info.AdviceId == 0 {
  10234. if info.HisPrescriptionProject.Type == 3 {
  10235. var good models.DialysisBeforePrepareGoods
  10236. var newGood models.NewDialysisBeforePrepareGoods
  10237. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10238. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10239. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10240. good.Count = int64(count)
  10241. good.StorehouseId = houseConfig.StorehouseOutInfo
  10242. good.ProjectId = info.HisPrescriptionProject.ID
  10243. good.PatientId = info.PatientId
  10244. good.OrderId = order_id
  10245. goods = append(goods, &good)
  10246. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10247. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10248. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10249. newGood.Count = int64(count2)
  10250. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10251. newGood.ProjectId = info.HisPrescriptionProject.ID
  10252. newGood.RecordDate = order.SettleAccountsDate
  10253. newGood.UserOrgId = order.UserOrgId
  10254. newGood.PatientId = info.PatientId
  10255. newGood.OrderId = order_id
  10256. newGoods = append(newGoods, &newGood)
  10257. }
  10258. }
  10259. }
  10260. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10261. if settConfig.IsOpen == 1 {
  10262. for _, item := range infos {
  10263. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10264. }
  10265. for _, item := range newGoods {
  10266. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10267. }
  10268. }
  10269. c.ServeSuccessJSON(map[string]interface{}{
  10270. "msg": "退费成功",
  10271. })
  10272. }
  10273. func (c *HisApiController) RefundNumber() {
  10274. his_patient_id, _ := c.GetInt64("id")
  10275. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10276. info.Status = 0
  10277. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10278. if count > 0 {
  10279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10280. return
  10281. }
  10282. err := service.SaveHisPatient(info)
  10283. if err == nil {
  10284. c.ServeSuccessJSON(map[string]interface{}{
  10285. "msg": "退号成功",
  10286. })
  10287. } else {
  10288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10289. return
  10290. }
  10291. }
  10292. func (this *HisApiController) AdditionalCharge() {
  10293. dataBody := make(map[string]interface{}, 0)
  10294. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10295. fmt.Println(err)
  10296. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10297. patient_id := int64(dataBody["patient_id"].(float64))
  10298. medicineData, _ := dataBody["medicineData"].([]interface{})
  10299. adminUserInfo := this.GetAdminUserInfo()
  10300. orgId := adminUserInfo.CurrentOrgId
  10301. admin_user_id := adminUserInfo.AdminUser.Id
  10302. timeStr := time.Now().Format("2006-01-02")
  10303. timeLayout := "2006-01-02 15:04:05"
  10304. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10305. timenow := timeStringToTime.Unix()
  10306. var additionalCharges []*models.HisAdditionalCharge
  10307. for _, item := range medicineData {
  10308. var randNum int
  10309. randNum = rand.Intn(10000) + 1000
  10310. timestamp := time.Now().Unix()
  10311. tempTime := time.Unix(timestamp, 0)
  10312. timeFormat := tempTime.Format("20060102150405")
  10313. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10314. items := item.(map[string]interface{})
  10315. money := items["price"].(string)
  10316. item_id_str := items["item_id"].(string)
  10317. name := items["name"].(string)
  10318. id_str := items["id"].(string)
  10319. moneys, _ := strconv.ParseInt(money, 10, 64)
  10320. monStr := strconv.FormatInt(moneys, 10)
  10321. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10322. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10323. id, _ := strconv.ParseInt(id_str, 10, 64)
  10324. additionalCharge := &models.HisAdditionalCharge{
  10325. ID: id,
  10326. HisPatientId: his_patient_id,
  10327. UserOrgId: orgId,
  10328. PatientId: patient_id,
  10329. RecordDate: timenow,
  10330. Price: monneyStr,
  10331. Status: 1,
  10332. ItemName: name,
  10333. ItemId: item_id,
  10334. AdminUserId: admin_user_id,
  10335. CreatedTime: time.Now().Unix(),
  10336. OrderStatus: 0,
  10337. PrescriptionNumber: "",
  10338. BatchNumber: "",
  10339. FeedetlSn: p_number,
  10340. }
  10341. service.CreateAdditionalCharge(additionalCharge)
  10342. additionalCharges = append(additionalCharges, additionalCharge)
  10343. }
  10344. this.ServeSuccessJSON(map[string]interface{}{
  10345. "msg": "添加成功",
  10346. "additional_charges": additionalCharges,
  10347. })
  10348. }
  10349. func (this *HisApiController) DeleteAddition() {
  10350. id, _ := this.GetInt64("id")
  10351. //TODO 需要判断是否已经结算
  10352. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10353. if err == nil {
  10354. this.ServeSuccessJSON(map[string]interface{}{
  10355. "msg": "删除成功",
  10356. })
  10357. return
  10358. } else {
  10359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10360. return
  10361. }
  10362. }
  10363. func (this *HisApiController) GetAdminUsers() {
  10364. adminUser := this.GetAdminUserInfo()
  10365. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10366. this.ServeSuccessJSON(map[string]interface{}{
  10367. "doctors": doctors,
  10368. })
  10369. }
  10370. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10371. change_type, _ := this.GetInt64("type", 0)
  10372. record_date := this.GetString("record_time")
  10373. patient_id, _ := this.GetInt64("patient_id", 0)
  10374. p_type, _ := this.GetInt64("p_type", 0)
  10375. timeLayout := "2006-01-02"
  10376. loc, _ := time.LoadLocation("Local")
  10377. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10378. record_time := theAdviceRecordTime.Unix()
  10379. adminUserInfo := this.GetAdminUserInfo()
  10380. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10381. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10382. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10383. if config.ID > 0 && config.IsOpen == 1 {
  10384. for _, subitems := range prescriptions {
  10385. for _, item := range subitems.VMHisPrescription {
  10386. for _, subItem := range item.HisDoctorAdviceInfo {
  10387. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10388. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10389. if info.RetailPrice > 0 {
  10390. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10391. subItem.Drug.RetailPrice = drug.RetailPrice
  10392. }
  10393. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10394. subItem.Drug.MinPrice = info.RetailPrice
  10395. subItem.Drug.RetailPrice = info.RetailPrice
  10396. }
  10397. }
  10398. }
  10399. }
  10400. }
  10401. }
  10402. if config.ID > 0 && config.IsOpen == 1 {
  10403. for _, subitems := range prescriptions {
  10404. for _, item := range subitems.VMHisPrescription {
  10405. for _, subItem := range item.HisPrescriptionProject {
  10406. if subItem.Type == 3 {
  10407. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10408. if info.Price > 0 {
  10409. subItem.GoodInfo.PackingPrice = info.Price
  10410. }
  10411. }
  10412. }
  10413. }
  10414. }
  10415. }
  10416. }
  10417. if err == nil {
  10418. if len(prescriptions) == 0 {
  10419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10420. return
  10421. } else {
  10422. this.ServeSuccessJSON(map[string]interface{}{
  10423. "prescriptions": prescriptions,
  10424. })
  10425. return
  10426. }
  10427. } else {
  10428. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10429. return
  10430. }
  10431. }
  10432. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10433. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10434. for i := 0; i < len(arr); i++ {
  10435. repeat := false
  10436. for j := i + 1; j < len(arr); j++ {
  10437. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10438. repeat = true
  10439. break
  10440. }
  10441. }
  10442. if !repeat {
  10443. newArr = append(newArr, arr[i])
  10444. }
  10445. }
  10446. return
  10447. }
  10448. func (this *HisApiController) GetCallHisPrescription() {
  10449. patient_id, _ := this.GetInt64("patient_id", 0)
  10450. timeLayout := "2006-01-02"
  10451. loc, _ := time.LoadLocation("Local")
  10452. start_time := this.GetString("start_time")
  10453. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10454. end_time := this.GetString("end_time")
  10455. p_type, _ := this.GetInt64("p_type")
  10456. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10457. adminUserInfo := this.GetAdminUserInfo()
  10458. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10459. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10460. //if
  10461. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10462. //
  10463. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10464. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10465. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10466. if config.ID > 0 && config.IsOpen == 1 {
  10467. for _, subitems := range prescriptions {
  10468. for _, item := range subitems.VMHisPrescription {
  10469. for _, subItem := range item.HisDoctorAdviceInfo {
  10470. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10471. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10472. if info.RetailPrice > 0 {
  10473. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10474. subItem.Drug.RetailPrice = drug.RetailPrice
  10475. }
  10476. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10477. subItem.Drug.MinPrice = info.RetailPrice
  10478. subItem.Drug.RetailPrice = info.RetailPrice
  10479. }
  10480. }
  10481. }
  10482. }
  10483. }
  10484. }
  10485. if config.ID > 0 && config.IsOpen == 1 {
  10486. for _, subitems := range prescriptions {
  10487. for _, item := range subitems.VMHisPrescription {
  10488. for _, subItem := range item.HisPrescriptionProject {
  10489. if subItem.Type == 3 {
  10490. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10491. if info.Price > 0 {
  10492. subItem.GoodInfo.PackingPrice = info.Price
  10493. }
  10494. }
  10495. }
  10496. }
  10497. }
  10498. }
  10499. }
  10500. if err == nil {
  10501. this.ServeSuccessJSON(map[string]interface{}{
  10502. "prescriptions": prescriptions,
  10503. })
  10504. return
  10505. } else {
  10506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10507. return
  10508. }
  10509. }
  10510. func (this *HisApiController) GetHisDayPrescription() {
  10511. timeLayout := "2006-01-02"
  10512. loc, _ := time.LoadLocation("Local")
  10513. start_time := this.GetString("start_time")
  10514. patient_id, _ := this.GetInt64("patient_id", 0)
  10515. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10516. end_time := this.GetString("end_time")
  10517. p_type, _ := this.GetInt64("p_type")
  10518. order_status, _ := this.GetInt64("type")
  10519. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10520. adminUserInfo := this.GetAdminUserInfo()
  10521. var dayHisPrescription []*models.HisPrescription
  10522. var err error
  10523. if order_status == 1 || order_status == 0 {
  10524. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10525. } else if order_status == 2 {
  10526. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10527. }
  10528. var settle_total float64
  10529. for _, item := range dayHisPrescription {
  10530. if len(item.HisPrescriptionProject) > 0 {
  10531. for _, subItem := range item.HisPrescriptionProject {
  10532. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10533. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10534. settle_total = settle_total + total
  10535. }
  10536. }
  10537. if len(item.HisDoctorAdviceInfo) > 0 {
  10538. for _, subItem := range item.HisDoctorAdviceInfo {
  10539. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10540. settle_total = settle_total + total
  10541. }
  10542. }
  10543. }
  10544. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10545. if err == nil {
  10546. this.ServeSuccessJSON(map[string]interface{}{
  10547. "day_prescription": dayHisPrescription,
  10548. "settle_total": settle_total,
  10549. })
  10550. return
  10551. } else {
  10552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10553. return
  10554. }
  10555. }
  10556. func (c *HisApiController) GetHisChargePatientList() {
  10557. record_date := c.GetString("record_date")
  10558. order_status, _ := c.GetInt64("type")
  10559. sch_type, _ := c.GetInt64("sch_type")
  10560. timeLayout := "2006-01-02"
  10561. loc, _ := time.LoadLocation("Local")
  10562. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10563. if err != nil {
  10564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10565. return
  10566. }
  10567. recordDateTime := theTime.Unix()
  10568. adminInfo := c.GetAdminUserInfo()
  10569. var tempPatients []*service.NewTempPatients
  10570. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10571. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10572. if order_status != 2 {
  10573. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10574. } else {
  10575. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10576. }
  10577. } else {
  10578. if order_status != 2 {
  10579. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10580. } else {
  10581. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10582. }
  10583. }
  10584. var patients []*service.NewTempPatients
  10585. var patients_two []*service.NewTempPatients
  10586. for _, item := range tempPatients {
  10587. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10588. //过滤掉没挂号的和没开处方的
  10589. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10590. patients = append(patients, item)
  10591. }
  10592. //过滤掉没挂号的
  10593. if len(item.HisPatient) > 0 {
  10594. patients_two = append(patients_two, item)
  10595. }
  10596. } else {
  10597. if len(item.HisPrescription) > 0 {
  10598. patients = append(patients, item)
  10599. }
  10600. }
  10601. }
  10602. c.ServeSuccessJSON(map[string]interface{}{
  10603. "list": patients,
  10604. "list_two": patients_two,
  10605. })
  10606. }
  10607. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10608. record_date := c.GetString("record_date")
  10609. timeLayout := "2006-01-02"
  10610. loc, _ := time.LoadLocation("Local")
  10611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10612. if err != nil {
  10613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10614. return
  10615. }
  10616. recordDateTime := theTime.Unix()
  10617. adminUser := c.GetAdminUserInfo()
  10618. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10619. var patients []*service.Patients
  10620. for _, item := range tempPatients {
  10621. if item.HisPatient.ID == 0 {
  10622. patients = append(patients, item)
  10623. }
  10624. }
  10625. c.ServeSuccessJSON(map[string]interface{}{
  10626. "list": patients,
  10627. //"list_two": patients_two,
  10628. })
  10629. }
  10630. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10631. newArr = make([]*service.Patients, 0)
  10632. for i := 0; i < len(patient); i++ {
  10633. repeat := false
  10634. for j := i + 1; j < len(patient); j++ {
  10635. if patient[i].ID == patient[j].ID {
  10636. repeat = true
  10637. break
  10638. }
  10639. }
  10640. if !repeat {
  10641. newArr = append(newArr, patient[i])
  10642. }
  10643. }
  10644. return
  10645. }
  10646. func (c *HisApiController) GetHisChargePatientInfo() {
  10647. patient_id, _ := c.GetInt64("patient_id")
  10648. his_patient_id, _ := c.GetInt64("his_patient_id")
  10649. record_date := c.GetString("record_date")
  10650. //start_time := c.GetString("start_time")
  10651. //end_time := c.GetString("end_time")
  10652. order_status, _ := c.GetInt64("type", 0)
  10653. p_type, _ := c.GetInt64("p_type", 0)
  10654. order_id, _ := c.GetInt64("order_id", 0)
  10655. timeLayout := "2006-01-02"
  10656. loc, _ := time.LoadLocation("Local")
  10657. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10658. if err != nil {
  10659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10660. return
  10661. }
  10662. recordDateTime := theTime.Unix()
  10663. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10664. //if err != nil {
  10665. //
  10666. //}
  10667. //startRecordDateTime := startTime.Unix()
  10668. //
  10669. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10670. //if err != nil {
  10671. //
  10672. //}
  10673. //endRecordDateTime := endTime.Unix()
  10674. admin := c.GetAdminUserInfo()
  10675. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10676. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10677. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10678. var prescriptions []*models.HisPrescription
  10679. //var unChargeMonthPrescriptions []*models.HisPrescription
  10680. order, _ := service.GetHisOrderByID(order_id)
  10681. if order_status == 1 || order_status == 0 {
  10682. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10683. } else if order_status == 2 {
  10684. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10685. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10686. }
  10687. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10688. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10689. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10690. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10691. //获取所有科室信息
  10692. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10693. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10694. c.ServeSuccessJSON(map[string]interface{}{
  10695. "his_info": his_patient_info,
  10696. "last_his_patient_info": last_his_patient_info,
  10697. "xt_info": xt_patient_info,
  10698. "prescription": prescriptions,
  10699. "case_history": case_history,
  10700. "info": patientPrescriptionInfo,
  10701. "last_info": lastPatientPrescriptionInfo,
  10702. "order": order,
  10703. "doctors": doctors,
  10704. "department": department,
  10705. "sch": sch,
  10706. })
  10707. return
  10708. }
  10709. func (c *HisApiController) GetAllOrderDetail() {
  10710. order_id, _ := c.GetInt64("id", 0)
  10711. order, _ := service.GetHisOrderByID(order_id)
  10712. if order.ID == 0 {
  10713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10714. return
  10715. }
  10716. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10717. org_id := c.GetAdminUserInfo().CurrentOrgId
  10718. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10719. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10720. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10721. c.ServeSuccessJSON(map[string]interface{}{
  10722. "order": order,
  10723. "order_info": order_info,
  10724. "patient": patient,
  10725. "admin_info": adminInfo,
  10726. "hospital_record": record,
  10727. })
  10728. return
  10729. }
  10730. func (c *HisApiController) GetAllOrderDetailCollect() {
  10731. order_id, _ := c.GetInt64("id", 0)
  10732. order, _ := service.GetHisOrderByID(order_id)
  10733. if order.ID == 0 {
  10734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10735. return
  10736. }
  10737. org_id := c.GetAdminUserInfo().CurrentOrgId
  10738. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10739. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10740. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10741. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10742. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10743. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10744. var bedCostTotal float64 = 0 //床位总费
  10745. //var bedCostSelfTotal float64 = 0 //床位自费
  10746. var operationCostTotal float64 = 0 //手术费
  10747. //var operationCostSelfTotal float64 = 0 //手术费
  10748. var otherCostTotal float64 = 0 //其他费用
  10749. //var otherCostSelfTotal float64 = 0 //其他费用
  10750. var materialCostTotal float64 = 0 //材料费
  10751. //var materialCostSelfTotal float64 = 0 //材料费
  10752. var westernMedicineCostTotal float64 = 0 //西药费
  10753. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10754. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10755. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10756. var checkCostTotal float64 = 0 //检查费
  10757. //var checkCostSelfTotal float64 = 0 //检查费
  10758. var laboratoryCostTotal float64 = 0 //化验费
  10759. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10760. var treatCostTotal float64 = 0 //治疗费用
  10761. //var treatCostSelfTotal float64 = 0 //治疗费用
  10762. var zhenChaCostTotal float64 = 0 //其他费用
  10763. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10764. decimal.DivisionPrecision = 2
  10765. var BalanceAccountsType int64
  10766. if his.ID > 0 {
  10767. BalanceAccountsType = his.BalanceAccountsType
  10768. } else {
  10769. BalanceAccountsType = record.BalanceAccountsType
  10770. }
  10771. if BalanceAccountsType != 2 {
  10772. for _, item := range order_info {
  10773. if org_id == 10215 {
  10774. if item.MedChrgitmType == "01" { //床位费
  10775. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10776. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10777. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10778. }
  10779. if item.MedChrgitmType == "02" { //诊察费
  10780. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10781. //zhenChaCostSelfTotal = zhenChaCostTotal
  10782. }
  10783. if item.MedChrgitmType == "03" { //检查费
  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 == "02" { //检查费
  10789. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10790. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10791. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10792. //}
  10793. if item.MedChrgitmType == "04" { //化验费
  10794. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10795. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10796. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10797. }
  10798. if item.MedChrgitmType == "05" { //治疗费
  10799. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10800. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10801. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10802. }
  10803. if item.MedChrgitmType == "06" { //手术费
  10804. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10805. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10806. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10807. }
  10808. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10809. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10810. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10811. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10812. }
  10813. if item.MedChrgitmType == "09" { //西药费
  10814. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10815. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10816. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10817. }
  10818. if item.MedChrgitmType == "11" { //中成费
  10819. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10820. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10821. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10822. }
  10823. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10824. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10825. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10826. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10827. }
  10828. } else if org_id == 10188 || org_id == 10217 {
  10829. if item.MedChrgitmType == "01" { //床位费
  10830. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10831. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10832. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10833. }
  10834. if item.MedChrgitmType == "02" { //诊察费
  10835. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10836. //zhenChaCostSelfTotal = zhenChaCostTotal
  10837. }
  10838. if item.MedChrgitmType == "03" { //检查费
  10839. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  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 == "02" { //检查费
  10845. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10846. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10847. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10848. //}
  10849. if item.MedChrgitmType == "04" { //化验费
  10850. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10851. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10852. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10853. }
  10854. if item.MedChrgitmType == "05" { //治疗费
  10855. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10856. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10857. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10858. }
  10859. if item.MedChrgitmType == "06" { //手术费
  10860. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10861. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10862. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10863. }
  10864. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10865. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10866. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10867. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10868. }
  10869. if item.MedChrgitmType == "09" { //西药费
  10870. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10871. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10872. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10873. }
  10874. if item.MedChrgitmType == "11" { //中成费
  10875. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10876. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10877. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10878. }
  10879. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10880. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10881. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10882. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10883. }
  10884. } else {
  10885. if item.MedChrgitmType == "01" { //床位费
  10886. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10887. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10888. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10889. }
  10890. //if item.MedChrgitmType == "02" { //诊察费
  10891. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10892. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10893. //}
  10894. if item.MedChrgitmType == "03" { //检查费
  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 == "02" { //检查费
  10900. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10901. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10902. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10903. //}
  10904. if item.MedChrgitmType == "04" { //化验费
  10905. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10906. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10907. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10908. }
  10909. if item.MedChrgitmType == "05" { //治疗费
  10910. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10911. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10912. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10913. }
  10914. if item.MedChrgitmType == "06" { //手术费
  10915. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10916. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10917. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10918. }
  10919. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10920. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10921. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10922. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10923. }
  10924. if item.MedChrgitmType == "09" { //西药费
  10925. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10926. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10927. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10928. }
  10929. if item.MedChrgitmType == "11" { //中成费
  10930. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10931. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10932. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10933. }
  10934. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10935. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10936. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10937. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10938. }
  10939. }
  10940. }
  10941. c.ServeSuccessJSON(map[string]interface{}{
  10942. "order": order,
  10943. "order_info": order_info,
  10944. "patient": patient,
  10945. "admin_info": adminInfo,
  10946. "his_hospital": record,
  10947. "bedCostTotal": bedCostTotal,
  10948. "operationCostTotal": operationCostTotal,
  10949. "otherCostTotal": otherCostTotal,
  10950. "materialCostTotal": materialCostTotal,
  10951. "westernMedicineCostTotal": westernMedicineCostTotal,
  10952. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10953. "checkCostTotal": checkCostTotal,
  10954. "zhenChaCostTotal": zhenChaCostTotal,
  10955. "laboratoryCostTotal": laboratoryCostTotal,
  10956. "treatCostTotal": treatCostTotal,
  10957. })
  10958. } else {
  10959. for _, item := range order_info {
  10960. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10961. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10962. item.MedChrgitmType = "09"
  10963. }
  10964. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10965. if item.HisPrescriptionProject.Type == 2 {
  10966. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10967. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10968. case 0:
  10969. item.MedChrgitmType = "0"
  10970. break
  10971. case 1:
  10972. item.MedChrgitmType = "14"
  10973. break
  10974. case 2:
  10975. item.MedChrgitmType = "05"
  10976. break
  10977. case 3:
  10978. item.MedChrgitmType = "03"
  10979. break
  10980. case 4:
  10981. item.MedChrgitmType = "03"
  10982. break
  10983. case 5:
  10984. item.MedChrgitmType = "08"
  10985. break
  10986. case 6:
  10987. item.MedChrgitmType = "14"
  10988. break
  10989. case 7:
  10990. item.MedChrgitmType = "14"
  10991. break
  10992. case 8:
  10993. item.MedChrgitmType = "03"
  10994. break
  10995. case 9:
  10996. item.MedChrgitmType = "14"
  10997. break
  10998. case 10:
  10999. item.MedChrgitmType = "14"
  11000. break
  11001. case 11:
  11002. item.MedChrgitmType = "06"
  11003. break
  11004. case 12:
  11005. item.MedChrgitmType = "12"
  11006. break
  11007. case 13:
  11008. item.MedChrgitmType = "01"
  11009. break
  11010. case 14:
  11011. item.MedChrgitmType = "04"
  11012. break
  11013. case 15:
  11014. item.MedChrgitmType = "14"
  11015. break
  11016. }
  11017. } else {
  11018. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11019. case 1:
  11020. item.MedChrgitmType = "14"
  11021. break
  11022. case 2:
  11023. item.MedChrgitmType = "05"
  11024. break
  11025. case 3:
  11026. item.MedChrgitmType = "04"
  11027. break
  11028. case 4:
  11029. item.MedChrgitmType = "14"
  11030. break
  11031. case 5:
  11032. item.MedChrgitmType = "08"
  11033. break
  11034. case 6:
  11035. item.MedChrgitmType = "14"
  11036. break
  11037. case 7:
  11038. item.MedChrgitmType = "14"
  11039. break
  11040. case 8:
  11041. item.MedChrgitmType = "03"
  11042. break
  11043. case 9:
  11044. item.MedChrgitmType = "14"
  11045. break
  11046. }
  11047. }
  11048. } else if item.HisPrescriptionProject.Type == 3 {
  11049. item.MedChrgitmType = "08"
  11050. }
  11051. }
  11052. }
  11053. for _, item := range order_info {
  11054. if org_id == 10215 {
  11055. if item.MedChrgitmType == "01" { //床位费
  11056. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11057. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11058. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11059. }
  11060. if item.MedChrgitmType == "02" { //诊察费
  11061. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11062. //zhenChaCostSelfTotal = zhenChaCostTotal
  11063. }
  11064. if item.MedChrgitmType == "03" { //检查费
  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 == "02" { //检查费
  11070. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11071. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11072. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11073. //}
  11074. if item.MedChrgitmType == "04" { //化验费
  11075. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11076. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11077. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11078. }
  11079. if item.MedChrgitmType == "05" { //治疗费
  11080. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11081. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11082. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11083. }
  11084. if item.MedChrgitmType == "06" { //手术费
  11085. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11086. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11087. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11088. }
  11089. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11090. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11091. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11092. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11093. }
  11094. if item.MedChrgitmType == "09" { //西药费
  11095. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11096. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11097. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11098. }
  11099. if item.MedChrgitmType == "11" { //中成费
  11100. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11101. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11102. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11103. }
  11104. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11105. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11106. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11107. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11108. }
  11109. } else {
  11110. if item.MedChrgitmType == "01" { //床位费
  11111. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11112. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11113. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11114. }
  11115. //if item.MedChrgitmType == "02" { //诊察费
  11116. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11117. // //zhenChaCostSelfTotal = zhenChaCostTotal
  11118. //}
  11119. if item.MedChrgitmType == "03" { //检查费
  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 == "02" { //检查费
  11125. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11126. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11127. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11128. //}
  11129. if item.MedChrgitmType == "04" { //化验费
  11130. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11131. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11132. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11133. }
  11134. if item.MedChrgitmType == "05" { //治疗费
  11135. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11136. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11137. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11138. }
  11139. if item.MedChrgitmType == "06" { //手术费
  11140. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11141. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11142. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11143. }
  11144. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11145. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11146. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11147. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11148. }
  11149. if item.MedChrgitmType == "09" { //西药费
  11150. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11151. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11152. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11153. }
  11154. if item.MedChrgitmType == "11" { //中成费
  11155. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11156. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11157. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11158. }
  11159. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11160. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11161. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11162. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11163. }
  11164. }
  11165. }
  11166. c.ServeSuccessJSON(map[string]interface{}{
  11167. "order": order,
  11168. "order_info": order_info,
  11169. "patient": patient,
  11170. "admin_info": adminInfo,
  11171. "his_hospital": record,
  11172. "bedCostTotal": bedCostTotal,
  11173. "operationCostTotal": operationCostTotal,
  11174. "otherCostTotal": otherCostTotal,
  11175. "materialCostTotal": materialCostTotal,
  11176. "westernMedicineCostTotal": westernMedicineCostTotal,
  11177. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11178. "checkCostTotal": checkCostTotal,
  11179. "zhenChaCostTotal": zhenChaCostTotal,
  11180. "laboratoryCostTotal": laboratoryCostTotal,
  11181. "treatCostTotal": treatCostTotal,
  11182. })
  11183. }
  11184. }
  11185. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  11186. page, _ := c.GetInt64("page")
  11187. limit, _ := c.GetInt64("limit")
  11188. keywords := c.GetString("keywords")
  11189. start_time := c.GetString("start_time")
  11190. end_time := c.GetString("end_time")
  11191. //clr_type := c.GetString("clr_type")
  11192. insutype := c.GetString("insutype")
  11193. timeLayout := "2006-01-02"
  11194. loc, _ := time.LoadLocation("Local")
  11195. var theStartTIme int64
  11196. if len(start_time) > 0 {
  11197. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11198. theStartTIme = theTime.Unix()
  11199. }
  11200. var theEndtTIme int64
  11201. if len(end_time) > 0 {
  11202. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11203. theEndtTIme = theTime.Unix()
  11204. }
  11205. if page <= 0 {
  11206. page = 1
  11207. }
  11208. if limit <= 0 {
  11209. limit = 10
  11210. }
  11211. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  11212. c.ServeSuccessJSON(map[string]interface{}{
  11213. "total": total,
  11214. "list": list,
  11215. })
  11216. return
  11217. }
  11218. func (c *HisApiController) GetPutOnRecordList() {
  11219. page, _ := c.GetInt64("page")
  11220. limit, _ := c.GetInt64("limit")
  11221. keywords := c.GetString("keywords")
  11222. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  11223. if page <= 0 {
  11224. page = 1
  11225. }
  11226. if limit <= 0 {
  11227. limit = 10
  11228. }
  11229. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  11230. c.ServeSuccessJSON(map[string]interface{}{
  11231. "total": total,
  11232. "list": list,
  11233. })
  11234. return
  11235. }
  11236. func (c *HisApiController) GetCompareData() {
  11237. start_time := c.GetString("start_time")
  11238. end_time := c.GetString("end_time")
  11239. insutype := c.GetString("insutype")
  11240. clr_type := c.GetString("clr_type")
  11241. timeLayout := "2006-01-02"
  11242. loc, _ := time.LoadLocation("Local")
  11243. var theStartTIme int64
  11244. if len(start_time) > 0 {
  11245. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11246. if err != nil {
  11247. theStartTIme = 0
  11248. }
  11249. theStartTIme = theTime.Unix()
  11250. }
  11251. var theEndtTIme int64
  11252. if len(end_time) > 0 {
  11253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11254. if err != nil {
  11255. theEndtTIme = 0
  11256. }
  11257. theEndtTIme = theTime.Unix()
  11258. }
  11259. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11260. fmt.Println(err)
  11261. if err == nil {
  11262. c.ServeSuccessJSON(map[string]interface{}{
  11263. "list": formData,
  11264. })
  11265. } else {
  11266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11267. return
  11268. }
  11269. }
  11270. func (c *HisApiController) GetFaPiaoData() {
  11271. order_id, _ := c.GetInt64("order_id")
  11272. patient_id, _ := c.GetInt64("patient_id")
  11273. //number := c.GetString("number")
  11274. adminUser := c.GetAdminUserInfo()
  11275. order, _ := service.GetHisOrderByID(order_id)
  11276. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11277. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11278. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11279. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11280. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11281. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11282. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11283. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11284. var bedCostTotal float64 = 0 //床位总费
  11285. var bedCostSelfTotal float64 = 0 //床位自费
  11286. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11287. var operationCostTotal float64 = 0 //手术费
  11288. var operationCostSelfTotal float64 = 0 //手术费
  11289. var operationCostPartSelfTotal float64 = 0 //手术费
  11290. var otherCostTotal float64 = 0 //其他费用
  11291. var otherCostSelfTotal float64 = 0 //其他费用
  11292. var otherCostPartSelfTotal float64 = 0 //其他费用
  11293. var materialCostTotal float64 = 0 //材料费
  11294. var materialCostSelfTotal float64 = 0 //材料费
  11295. var materialCostPartSelfTotal float64 = 0 //材料费
  11296. var westernMedicineCostTotal float64 = 0 //西药费
  11297. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11298. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11299. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11300. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11301. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11302. var checkCostTotal float64 = 0 //检查费
  11303. var checkCostSelfTotal float64 = 0 //检查费
  11304. var checkCostPartSelfTotal float64 = 0 //检查费
  11305. var hiliCostTotal float64 = 0 //护理费
  11306. var hiliCostSelfTotal float64 = 0 //护理费
  11307. var hiliCostPartSelfTotal float64 = 0 //护理费
  11308. var laboratoryCostTotal float64 = 0 //化验费
  11309. var laboratoryCostSelfTotal float64 = 0 //化验费
  11310. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11311. var treatCostTotal float64 = 0 //治疗费用
  11312. var treatCostSelfTotal float64 = 0 //治疗费用
  11313. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11314. var zhenChaCostTotal float64 = 0 //其他费用
  11315. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11316. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11317. decimal.DivisionPrecision = 2
  11318. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11319. var balanceAccountsType int64
  11320. if his.ID > 0 {
  11321. balanceAccountsType = his.BalanceAccountsType
  11322. } else {
  11323. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11324. }
  11325. if balanceAccountsType == 2 {
  11326. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11327. for _, item := range orderInfos_two {
  11328. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11329. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11330. item.MedChrgitmType = "09"
  11331. }
  11332. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11333. if item.HisPrescriptionProject.Type == 2 {
  11334. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11335. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11336. case 0:
  11337. item.MedChrgitmType = "0"
  11338. break
  11339. case 1:
  11340. item.MedChrgitmType = "14"
  11341. break
  11342. case 2:
  11343. item.MedChrgitmType = "05"
  11344. break
  11345. case 3:
  11346. item.MedChrgitmType = "03"
  11347. break
  11348. case 4:
  11349. item.MedChrgitmType = "03"
  11350. break
  11351. case 5:
  11352. item.MedChrgitmType = "08"
  11353. break
  11354. case 6:
  11355. item.MedChrgitmType = "14"
  11356. break
  11357. case 7:
  11358. item.MedChrgitmType = "14"
  11359. break
  11360. case 8:
  11361. item.MedChrgitmType = "03"
  11362. break
  11363. case 9:
  11364. item.MedChrgitmType = "14"
  11365. break
  11366. case 10:
  11367. item.MedChrgitmType = "14"
  11368. break
  11369. case 11:
  11370. item.MedChrgitmType = "06"
  11371. break
  11372. case 12:
  11373. item.MedChrgitmType = "12"
  11374. break
  11375. case 13:
  11376. item.MedChrgitmType = "01"
  11377. break
  11378. case 14:
  11379. item.MedChrgitmType = "04"
  11380. break
  11381. case 15:
  11382. item.MedChrgitmType = "02"
  11383. break
  11384. }
  11385. } else {
  11386. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11387. case 1:
  11388. item.MedChrgitmType = "14"
  11389. break
  11390. case 2:
  11391. item.MedChrgitmType = "05"
  11392. break
  11393. case 3:
  11394. item.MedChrgitmType = "04"
  11395. break
  11396. case 4:
  11397. item.MedChrgitmType = "03"
  11398. break
  11399. case 5:
  11400. item.MedChrgitmType = "08"
  11401. break
  11402. case 6:
  11403. item.MedChrgitmType = "14"
  11404. break
  11405. case 7:
  11406. item.MedChrgitmType = "14"
  11407. break
  11408. case 8:
  11409. item.MedChrgitmType = "03"
  11410. break
  11411. case 9:
  11412. item.MedChrgitmType = "14"
  11413. break
  11414. }
  11415. }
  11416. } else if item.HisPrescriptionProject.Type == 3 {
  11417. item.MedChrgitmType = "08"
  11418. }
  11419. }
  11420. }
  11421. for _, item := range orderInfos_two {
  11422. fmt.Println(item.MedChrgitmType)
  11423. if item.MedChrgitmType == "07" { //床位费
  11424. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11425. hiliCostSelfTotal = hiliCostTotal
  11426. }
  11427. if item.MedChrgitmType == "01" { //床位费
  11428. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11429. bedCostSelfTotal = bedCostTotal
  11430. }
  11431. if item.MedChrgitmType == "02" { //诊察费
  11432. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11433. zhenChaCostSelfTotal = zhenChaCostTotal
  11434. }
  11435. if item.MedChrgitmType == "03" { //检查费
  11436. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11437. checkCostSelfTotal = checkCostTotal
  11438. }
  11439. if item.MedChrgitmType == "04" { //化验费
  11440. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11441. laboratoryCostSelfTotal = laboratoryCostTotal
  11442. }
  11443. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11444. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11445. treatCostSelfTotal = treatCostTotal
  11446. }
  11447. if item.MedChrgitmType == "06" { //手术费
  11448. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11449. operationCostSelfTotal = treatCostTotal
  11450. }
  11451. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11452. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11453. materialCostSelfTotal = materialCostTotal
  11454. }
  11455. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11456. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11457. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11458. }
  11459. if item.MedChrgitmType == "11" { //中成费
  11460. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11461. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11462. }
  11463. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11464. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11465. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11466. otherCostSelfTotal = otherCostTotal
  11467. }
  11468. } else {
  11469. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11470. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11471. otherCostSelfTotal = otherCostTotal
  11472. }
  11473. }
  11474. }
  11475. } else {
  11476. for _, item := range orderInfos {
  11477. if item.MedChrgitmType == "01" { //床位费
  11478. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11479. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11480. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11481. }
  11482. if item.MedChrgitmType == "02" { //诊察费
  11483. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11484. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11485. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11486. }
  11487. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11488. if item.MedChrgitmType == "03" { //检查费
  11489. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11490. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11491. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11492. }
  11493. } else {
  11494. if item.MedChrgitmType == "03" { //检查费
  11495. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11496. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11497. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11498. }
  11499. }
  11500. if item.MedChrgitmType == "04" { //化验费
  11501. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11502. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11503. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11504. }
  11505. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11506. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11507. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11508. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11509. }
  11510. if item.MedChrgitmType == "06" { //手术费
  11511. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11512. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11513. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11514. }
  11515. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11516. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11517. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11518. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11519. }
  11520. if item.MedChrgitmType == "07" { //护理
  11521. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11522. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11523. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11524. }
  11525. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11526. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11527. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11528. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11529. }
  11530. if item.MedChrgitmType == "11" { //中成费
  11531. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11532. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11533. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11534. }
  11535. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11536. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11537. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11538. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11539. }
  11540. }
  11541. }
  11542. timeLayout := "2006-01-02"
  11543. loc, _ := time.LoadLocation("Local")
  11544. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11545. if err != nil {
  11546. }
  11547. startRecordDateTime := startTime.Unix()
  11548. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11549. if err != nil {
  11550. }
  11551. endRecordDateTime := endTime.Unix()
  11552. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11553. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11554. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11555. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11556. c.ServeSuccessJSON(map[string]interface{}{
  11557. "charge_admin_name": charge_admin.UserName,
  11558. "order_number": order.Number, //业务流水号
  11559. "id_card_no": his.IdCardNo, //社会保障号
  11560. "patient": patient,
  11561. "department_name": department.Name, //科室
  11562. "number": his.Number, //门诊号
  11563. "date": order.SettleAccountsDate, //结算日期
  11564. "name": order.PsnName, //姓名
  11565. "gender": patient.Gender, //性别
  11566. "psn_cash_money": order.PsnCashPay, //个人支付
  11567. "pay_way": "门诊", //结算方式
  11568. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11569. "admin_user_name": admin.UserName, //收款员
  11570. "order": order,
  11571. "order_info": orderInfos_two,
  11572. "his": his,
  11573. "bedCostTotal": bedCostTotal,
  11574. "bedCostSelfTotal": bedCostSelfTotal,
  11575. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11576. "operationCostTotal": operationCostTotal,
  11577. "operationCostSelfTotal": operationCostSelfTotal,
  11578. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11579. "otherCostTotal": otherCostTotal,
  11580. "otherCostSelfTotal": otherCostSelfTotal,
  11581. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11582. "materialCostTotal": materialCostTotal,
  11583. "materialCostSelfTotal": materialCostSelfTotal,
  11584. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11585. "westernMedicineCostTotal": westernMedicineCostTotal,
  11586. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11587. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11588. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11589. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11590. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11591. "checkCostTotal": checkCostTotal,
  11592. "checkCostSelfTotal": checkCostSelfTotal,
  11593. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11594. "laboratoryCostTotal": laboratoryCostTotal,
  11595. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11596. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11597. "treatCostTotal": treatCostTotal,
  11598. "treatCostSelfTotal": treatCostSelfTotal,
  11599. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11600. "zhenChaCostTotal": zhenChaCostTotal,
  11601. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11602. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11603. "his_hospital_record": his_hospital_record,
  11604. "pre_pay_money": pre_pay_money,
  11605. "refund_sum": sum,
  11606. "doctor_info": doctor_info,
  11607. "hiliCostTotal": hiliCostTotal,
  11608. "hiliCostSelfTotal": hiliCostSelfTotal,
  11609. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11610. })
  11611. }
  11612. //func (c *HisApiController) GetFaPiaoDatas() {
  11613. // order_ids := c.GetString("order_ids")
  11614. // patient_id, _ := c.GetInt64("patient_id")
  11615. // adminUser := c.GetAdminUserInfo()
  11616. //
  11617. // orders := strings.Split(order_ids, ",")
  11618. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11619. //
  11620. // for _, item := range orders {
  11621. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11622. // order, _ := service.GetHisOrderByID(order_id)
  11623. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11624. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11625. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11626. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11627. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11628. //
  11629. // }
  11630. //
  11631. // var bedCostTotal float64 = 0 //床位总费
  11632. // var bedCostSelfTotal float64 = 0 //床位自费
  11633. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11634. //
  11635. // var operationCostTotal float64 = 0 //手术费
  11636. // var operationCostSelfTotal float64 = 0 //手术费
  11637. // var operationCostPartSelfTotal float64 = 0 //手术费
  11638. //
  11639. // var otherCostTotal float64 = 0 //其他费用
  11640. // var otherCostSelfTotal float64 = 0 //其他费用
  11641. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11642. //
  11643. // var materialCostTotal float64 = 0 //材料费
  11644. // var materialCostSelfTotal float64 = 0 //材料费
  11645. // var materialCostPartSelfTotal float64 = 0 //材料费
  11646. //
  11647. // var westernMedicineCostTotal float64 = 0 //西药费
  11648. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11649. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11650. //
  11651. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11652. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11653. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11654. //
  11655. // var checkCostTotal float64 = 0 //检查费
  11656. // var checkCostSelfTotal float64 = 0 //检查费
  11657. // var checkCostPartSelfTotal float64 = 0 //检查费
  11658. //
  11659. // var laboratoryCostTotal float64 = 0 //化验费
  11660. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11661. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11662. //
  11663. // var treatCostTotal float64 = 0 //治疗费用
  11664. // var treatCostSelfTotal float64 = 0 //治疗费用
  11665. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11666. //
  11667. // var zhenChaCostTotal float64 = 0 //其他费用
  11668. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11669. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11670. //
  11671. // decimal.DivisionPrecision = 2
  11672. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11673. //
  11674. // var balanceAccountsType int64
  11675. // if his.ID > 0 {
  11676. // balanceAccountsType = his.BalanceAccountsType
  11677. // } else {
  11678. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11679. // }
  11680. // if balanceAccountsType == 2 {
  11681. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11682. // for _, item := range orderInfos_two {
  11683. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11684. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11685. // item.MedChrgitmType = "09"
  11686. // }
  11687. //
  11688. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11689. // if item.HisPrescriptionProject.Type == 2 {
  11690. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11691. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11692. // case 0:
  11693. // item.MedChrgitmType = "0"
  11694. // break
  11695. // case 1:
  11696. // item.MedChrgitmType = "14"
  11697. // break
  11698. // case 2:
  11699. // item.MedChrgitmType = "05"
  11700. //
  11701. // break
  11702. // case 3:
  11703. // item.MedChrgitmType = "03"
  11704. //
  11705. // break
  11706. // case 4:
  11707. // item.MedChrgitmType = "03"
  11708. //
  11709. // break
  11710. // case 5:
  11711. // item.MedChrgitmType = "08"
  11712. //
  11713. // break
  11714. // case 6:
  11715. // item.MedChrgitmType = "14"
  11716. //
  11717. // break
  11718. // case 7:
  11719. // item.MedChrgitmType = "14"
  11720. //
  11721. // break
  11722. // case 8:
  11723. // item.MedChrgitmType = "03"
  11724. // break
  11725. // case 9:
  11726. // item.MedChrgitmType = "14"
  11727. // break
  11728. // case 10:
  11729. // item.MedChrgitmType = "14"
  11730. // break
  11731. // case 11:
  11732. // item.MedChrgitmType = "06"
  11733. // break
  11734. // case 12:
  11735. // item.MedChrgitmType = "12"
  11736. // break
  11737. // case 13:
  11738. // item.MedChrgitmType = "01"
  11739. // break
  11740. // case 14:
  11741. // item.MedChrgitmType = "04"
  11742. // break
  11743. // case 15:
  11744. // item.MedChrgitmType = "02"
  11745. // break
  11746. //
  11747. // }
  11748. //
  11749. // } else {
  11750. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11751. //
  11752. // case 1:
  11753. // item.MedChrgitmType = "14"
  11754. // break
  11755. // case 2:
  11756. // item.MedChrgitmType = "05"
  11757. //
  11758. // break
  11759. // case 3:
  11760. // item.MedChrgitmType = "03"
  11761. //
  11762. // break
  11763. // case 4:
  11764. // item.MedChrgitmType = "03"
  11765. //
  11766. // break
  11767. // case 5:
  11768. // item.MedChrgitmType = "08"
  11769. //
  11770. // break
  11771. // case 6:
  11772. // item.MedChrgitmType = "14"
  11773. //
  11774. // break
  11775. // case 7:
  11776. // item.MedChrgitmType = "14"
  11777. //
  11778. // break
  11779. // case 8:
  11780. // item.MedChrgitmType = "03"
  11781. // break
  11782. // case 9:
  11783. // item.MedChrgitmType = "14"
  11784. // break
  11785. //
  11786. // }
  11787. //
  11788. // }
  11789. //
  11790. // } else if item.HisPrescriptionProject.Type == 3 {
  11791. // item.MedChrgitmType = "08"
  11792. // }
  11793. // }
  11794. // }
  11795. //
  11796. // for _, item := range orderInfos_two {
  11797. // fmt.Println(item.MedChrgitmType)
  11798. // if item.MedChrgitmType == "01" { //床位费
  11799. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11800. // bedCostSelfTotal = bedCostTotal
  11801. // }
  11802. //
  11803. // if item.MedChrgitmType == "02" { //诊察费
  11804. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11805. // zhenChaCostSelfTotal = zhenChaCostTotal
  11806. // }
  11807. //
  11808. // if item.MedChrgitmType == "03" { //检查费
  11809. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11810. // checkCostSelfTotal = checkCostTotal
  11811. // }
  11812. //
  11813. // if item.MedChrgitmType == "04" { //化验费
  11814. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11815. // laboratoryCostSelfTotal = laboratoryCostTotal
  11816. // }
  11817. //
  11818. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11819. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11820. // treatCostSelfTotal = treatCostTotal
  11821. // }
  11822. //
  11823. // if item.MedChrgitmType == "06" { //手术费
  11824. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11825. // operationCostSelfTotal = treatCostTotal
  11826. // }
  11827. //
  11828. // if item.MedChrgitmType == "08" { //材料费
  11829. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11830. // materialCostSelfTotal = materialCostTotal
  11831. // }
  11832. //
  11833. // if item.MedChrgitmType == "09" { //西药费
  11834. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11835. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11836. // }
  11837. //
  11838. // if item.MedChrgitmType == "11" { //中成费
  11839. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11840. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11841. // }
  11842. //
  11843. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11844. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11845. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11846. // otherCostSelfTotal = otherCostTotal
  11847. // }
  11848. // } else {
  11849. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11850. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11851. // otherCostSelfTotal = otherCostTotal
  11852. // }
  11853. //
  11854. // }
  11855. //
  11856. // }
  11857. //
  11858. // } else {
  11859. // for _, item := range orderInfos {
  11860. // if item.MedChrgitmType == "01" { //床位费
  11861. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11862. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11863. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11864. // }
  11865. //
  11866. // if item.MedChrgitmType == "02" { //诊察费
  11867. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11868. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11869. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11870. // }
  11871. //
  11872. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11873. // if item.MedChrgitmType == "03" { //检查费
  11874. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11875. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11876. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11877. //
  11878. // }
  11879. // } else {
  11880. // if item.MedChrgitmType == "03" { //检查费
  11881. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11882. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11883. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11884. // }
  11885. //
  11886. // }
  11887. //
  11888. // if item.MedChrgitmType == "04" { //化验费
  11889. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11890. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11891. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11892. //
  11893. // }
  11894. //
  11895. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11896. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11897. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11898. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11899. //
  11900. // }
  11901. //
  11902. // if item.MedChrgitmType == "06" { //手术费
  11903. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11904. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11905. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11906. // }
  11907. //
  11908. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11909. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11910. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11911. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11912. // }
  11913. //
  11914. // if item.MedChrgitmType == "09" { //西药费
  11915. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11916. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11917. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11918. // }
  11919. //
  11920. // if item.MedChrgitmType == "11" { //中成费
  11921. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11922. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11923. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11924. // }
  11925. //
  11926. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11927. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11928. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11929. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11930. // }
  11931. //
  11932. // }
  11933. // }
  11934. // timeLayout := "2006-01-02"
  11935. // loc, _ := time.LoadLocation("Local")
  11936. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11937. // if err != nil {
  11938. // }
  11939. // startRecordDateTime := startTime.Unix()
  11940. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11941. // if err != nil {
  11942. // }
  11943. // endRecordDateTime := endTime.Unix()
  11944. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11945. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11946. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11947. //
  11948. // c.ServeSuccessJSON(map[string]interface{}{
  11949. // "order_number": order.Number, //业务流水号
  11950. // "id_card_no": his.IdCardNo, //社会保障号
  11951. // "department_name": department.Name, //科室
  11952. // "number": his.Number, //门诊号
  11953. // "date": order.SettleAccountsDate, //结算日期
  11954. // "name": order.PsnName, //姓名
  11955. // "gender": patient.Gender, //性别
  11956. // "psn_cash_money": order.PsnCashPay, //个人支付
  11957. // "pay_way": "门诊", //结算方式
  11958. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11959. // "admin_user_name": admin.UserName, //收款员
  11960. // "order": order,
  11961. // "order_info": orderInfos_two,
  11962. // "his": his,
  11963. // "bedCostTotal": bedCostTotal,
  11964. // "bedCostSelfTotal": bedCostSelfTotal,
  11965. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11966. // "operationCostTotal": operationCostTotal,
  11967. // "operationCostSelfTotal": operationCostSelfTotal,
  11968. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11969. // "otherCostTotal": otherCostTotal,
  11970. // "otherCostSelfTotal": otherCostSelfTotal,
  11971. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11972. // "materialCostTotal": materialCostTotal,
  11973. // "materialCostSelfTotal": materialCostSelfTotal,
  11974. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11975. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11976. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11977. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11978. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11979. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11980. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11981. // "checkCostTotal": checkCostTotal,
  11982. // "checkCostSelfTotal": checkCostSelfTotal,
  11983. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11984. // "laboratoryCostTotal": laboratoryCostTotal,
  11985. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11986. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11987. // "treatCostTotal": treatCostTotal,
  11988. // "treatCostSelfTotal": treatCostSelfTotal,
  11989. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11990. // "zhenChaCostTotal": zhenChaCostTotal,
  11991. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11992. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11993. // "his_hospital_record": his_hospital_record,
  11994. // "pre_pay_money": pre_pay_money,
  11995. // "refund_sum": sum,
  11996. // })
  11997. //
  11998. //}
  11999. func (this *HisApiController) GetIncomeStatisticsData() {
  12000. start_time := this.GetString("start_time")
  12001. end_time := this.GetString("end_time")
  12002. key_words := this.GetString("key_words")
  12003. limit, _ := this.GetInt64("limit")
  12004. page, _ := this.GetInt64("page")
  12005. if page <= 0 {
  12006. page = 1
  12007. }
  12008. if limit <= 0 {
  12009. limit = 10
  12010. }
  12011. statistics_type, _ := this.GetInt64("statistics_type")
  12012. admin := this.GetAdminUserInfo()
  12013. timeLayout := "2006-01-02"
  12014. loc, _ := time.LoadLocation("Local")
  12015. var theStartTIme int64
  12016. if len(start_time) > 0 {
  12017. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12018. if err != nil {
  12019. theStartTIme = 0
  12020. }
  12021. theStartTIme = theTime.Unix()
  12022. }
  12023. var theEndtTIme int64
  12024. if len(end_time) > 0 {
  12025. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12026. if err != nil {
  12027. theEndtTIme = 0
  12028. }
  12029. theEndtTIme = theTime.Unix()
  12030. }
  12031. if statistics_type == 1 {
  12032. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12033. this.ServeSuccessJSON(map[string]interface{}{
  12034. "list": list,
  12035. "total": total,
  12036. })
  12037. } else {
  12038. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12039. this.ServeSuccessJSON(map[string]interface{}{
  12040. "list": list,
  12041. "total": total,
  12042. })
  12043. }
  12044. }
  12045. func (c *HisApiController) PostProjectInformation() {
  12046. adminUser := c.GetAdminUserInfo()
  12047. orgId := adminUser.CurrentOrgId
  12048. dataBody := make(map[string]interface{}, 0)
  12049. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12050. if err != nil {
  12051. utils.ErrorLog(err.Error())
  12052. return
  12053. }
  12054. utils.ErrorLog("%v", dataBody)
  12055. var projectList []*models.HisProject
  12056. var total_goods []interface{}
  12057. tempProjects := dataBody["projects"].([]interface{})
  12058. total_goods = tempProjects
  12059. for index, projectMap := range tempProjects {
  12060. projectM := projectMap.(map[string]interface{})
  12061. var project models.HisProject
  12062. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  12063. utils.ErrorLog("project_name")
  12064. return
  12065. }
  12066. project_name, _ := projectM["project_name"].(string)
  12067. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  12068. err_log := models.ExportErrLog{
  12069. LogType: 6,
  12070. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12071. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  12072. Status: 1,
  12073. CreateTime: time.Now().Unix(),
  12074. UpdateTime: time.Now().Unix(),
  12075. ExportTime: time.Now().Unix(),
  12076. }
  12077. service.CreateExportErrLog(&err_log)
  12078. continue
  12079. }
  12080. project.ProjectName = project_name
  12081. prices := projectM["price"].(string)
  12082. price, _ := strconv.ParseFloat(prices, 64)
  12083. if price <= 0 { //名字为空则生成一条导入错误日志
  12084. err_log := models.ExportErrLog{
  12085. LogType: 6,
  12086. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12087. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  12088. Status: 1,
  12089. CreateTime: time.Now().Unix(),
  12090. UpdateTime: time.Now().Unix(),
  12091. ExportTime: time.Now().Unix(),
  12092. }
  12093. service.CreateExportErrLog(&err_log)
  12094. continue
  12095. }
  12096. project.Price = price
  12097. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  12098. utils.ErrorLog("unit_id")
  12099. return
  12100. }
  12101. unit := projectM["unit"].(string)
  12102. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  12103. err_log := models.ExportErrLog{
  12104. LogType: 6,
  12105. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12106. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  12107. Status: 1,
  12108. CreateTime: time.Now().Unix(),
  12109. UpdateTime: time.Now().Unix(),
  12110. ExportTime: time.Now().Unix(),
  12111. }
  12112. service.CreateExportErrLog(&err_log)
  12113. continue
  12114. }
  12115. project.Unit = unit
  12116. cost_classify := projectM["cost_classify"].(string)
  12117. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  12118. err_log := models.ExportErrLog{
  12119. LogType: 6,
  12120. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12121. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12122. Status: 1,
  12123. CreateTime: time.Now().Unix(),
  12124. UpdateTime: time.Now().Unix(),
  12125. ExportTime: time.Now().Unix(),
  12126. }
  12127. service.CreateExportErrLog(&err_log)
  12128. continue
  12129. }
  12130. var costClassify = "费用类别"
  12131. var cost_classify_id int64
  12132. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  12133. if len(cost_classify) != 0 {
  12134. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  12135. if errcode == gorm.ErrRecordNotFound {
  12136. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  12137. dataconfig := models.DictDataconfig{
  12138. ParentId: costClassifyConfig.ID,
  12139. Module: "system",
  12140. OrgId: orgId,
  12141. Name: cost_classify,
  12142. FieldName: "",
  12143. Value: costConfig.Value + 1,
  12144. CreatedTime: "",
  12145. UpdatedTime: "",
  12146. CreateUserId: adminUser.AdminUser.Id,
  12147. Status: 1,
  12148. Remark: "",
  12149. DeleteIdSystem: 0,
  12150. Title: "",
  12151. Content: "",
  12152. Order: 0,
  12153. Code: "",
  12154. }
  12155. service.CreatedDicConfig(&dataconfig)
  12156. }
  12157. }
  12158. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  12159. for _, it := range costClassList {
  12160. if cost_classify == it.Name {
  12161. cost_classify_id = int64(it.Value)
  12162. }
  12163. }
  12164. project.CostClassify = cost_classify_id
  12165. executive_section := projectM["executive_section"].(string)
  12166. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  12167. err_log := models.ExportErrLog{
  12168. LogType: 6,
  12169. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12170. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  12171. Status: 1,
  12172. CreateTime: time.Now().Unix(),
  12173. UpdateTime: time.Now().Unix(),
  12174. ExportTime: time.Now().Unix(),
  12175. }
  12176. service.CreateExportErrLog(&err_log)
  12177. continue
  12178. }
  12179. if len(executive_section) != 0 {
  12180. //查找科室是否有内容
  12181. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  12182. if errcodedepart == gorm.ErrRecordNotFound {
  12183. department := models.XtHisDepartment{
  12184. Name: executive_section,
  12185. Status: 1,
  12186. UserOrgId: adminUser.CurrentOrgId,
  12187. CreatedTime: time.Now().Unix(),
  12188. }
  12189. service.CreateDePartment(&department)
  12190. }
  12191. }
  12192. var executive_section_id int64
  12193. departMentList, _ := service.GetAllDepartMent(orgId)
  12194. for _, it := range departMentList {
  12195. if executive_section == it.Name {
  12196. executive_section_id = it.ID
  12197. }
  12198. }
  12199. project.ExecutiveSection = executive_section_id
  12200. medical_coverage := projectM["medical_coverage"].(string)
  12201. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  12202. err_log := models.ExportErrLog{
  12203. LogType: 6,
  12204. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12205. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12206. Status: 1,
  12207. CreateTime: time.Now().Unix(),
  12208. UpdateTime: time.Now().Unix(),
  12209. ExportTime: time.Now().Unix(),
  12210. }
  12211. service.CreateExportErrLog(&err_log)
  12212. continue
  12213. }
  12214. var medicalCoverage = "医保等级"
  12215. var medical_coverage_id int64
  12216. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  12217. if len(medical_coverage) != 0 {
  12218. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  12219. if errormedicalcoverage == gorm.ErrRecordNotFound {
  12220. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  12221. dataconfig := models.DictDataconfig{
  12222. ParentId: medicalCoverageConfig.ID,
  12223. Module: "system",
  12224. OrgId: orgId,
  12225. Name: medical_coverage,
  12226. FieldName: "",
  12227. Value: medicalCoverageConfig.Value + 1,
  12228. CreatedTime: "",
  12229. UpdatedTime: "",
  12230. CreateUserId: adminUser.AdminUser.Id,
  12231. Status: 1,
  12232. Remark: "",
  12233. DeleteIdSystem: 0,
  12234. Title: "",
  12235. Content: "",
  12236. Order: 0,
  12237. Code: "",
  12238. }
  12239. service.CreatedDicConfig(&dataconfig)
  12240. }
  12241. }
  12242. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12243. for _, it := range medicalCoverageList {
  12244. if medical_coverage == it.Name {
  12245. medical_coverage_id = int64(it.Value)
  12246. }
  12247. }
  12248. project.MedicalCoverage = medical_coverage_id
  12249. pinyin := projectM["pinyin"].(string)
  12250. project.Pinyin = pinyin
  12251. wubi := projectM["wubi"].(string)
  12252. project.Wubi = wubi
  12253. statistical_classification := projectM["statistical_classification"].(string)
  12254. var statisticalClassification = "统计分类"
  12255. var statistical_classification_id int64
  12256. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12257. if len(statistical_classification) != 0 {
  12258. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12259. if classificationerrcodes == gorm.ErrRecordNotFound {
  12260. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12261. dataconfig := models.DictDataconfig{
  12262. ParentId: classiFication.ID,
  12263. Module: "system",
  12264. OrgId: orgId,
  12265. Name: statistical_classification,
  12266. FieldName: "",
  12267. Value: classiFicationConfig.Value + 1,
  12268. CreatedTime: "",
  12269. UpdatedTime: "",
  12270. CreateUserId: adminUser.AdminUser.Id,
  12271. Status: 1,
  12272. Remark: "",
  12273. DeleteIdSystem: 0,
  12274. Title: "",
  12275. Content: "",
  12276. Order: 0,
  12277. Code: "",
  12278. }
  12279. service.CreatedDicConfig(&dataconfig)
  12280. }
  12281. }
  12282. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12283. for _, it := range classiFicationList {
  12284. if statistical_classification == it.Name {
  12285. statistical_classification_id = int64(it.Value)
  12286. }
  12287. }
  12288. project.StatisticalClassification = statistical_classification_id
  12289. disease_directory := int64(projectM["disease_directory"].(float64))
  12290. project.DiseaseDirectory = disease_directory
  12291. is_record := int64(projectM["is_record"].(float64))
  12292. project.IsRecord = is_record
  12293. medical_code := projectM["medical_code"].(string)
  12294. project.MedicalCode = medical_code
  12295. tube_color := projectM["tube_color"].(string)
  12296. var tubeColor = "试管颜色"
  12297. var tube_color_id int64
  12298. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12299. if len(tube_color) != 0 {
  12300. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12301. if errcodetube == gorm.ErrRecordNotFound {
  12302. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12303. dataconfig := models.DictDataconfig{
  12304. ParentId: tubeColorConfig.ID,
  12305. Module: "system",
  12306. OrgId: orgId,
  12307. Name: tube_color,
  12308. FieldName: "",
  12309. Value: tubeConfig.Value + 1,
  12310. CreatedTime: "",
  12311. UpdatedTime: "",
  12312. CreateUserId: adminUser.AdminUser.Id,
  12313. Status: 1,
  12314. Remark: "",
  12315. DeleteIdSystem: 0,
  12316. Title: "",
  12317. Content: "",
  12318. Order: 0,
  12319. Code: "",
  12320. }
  12321. service.CreatedDicConfig(&dataconfig)
  12322. }
  12323. }
  12324. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12325. for _, it := range tubeColorList {
  12326. if tube_color == it.Name {
  12327. tube_color_id = int64(it.Value)
  12328. }
  12329. }
  12330. project.TubeColor = tube_color_id
  12331. single_dose := projectM["single_dose"].(string)
  12332. project.SingleDose = single_dose
  12333. execution_frequency := projectM["execution_frequency"].(string)
  12334. project.ExecutionFrequency = execution_frequency
  12335. delivery_way := projectM["delivery_way"].(string)
  12336. project.DeliveryWay = delivery_way
  12337. number_days := projectM["number_days"].(string)
  12338. project.NumberDays = number_days
  12339. total := projectM["total"].(string)
  12340. project.Total = total
  12341. medical_status := int64(projectM["medical_status"].(float64))
  12342. project.MedicalStatus = medical_status
  12343. category := int64(projectM["category"].(float64))
  12344. project.Category = category
  12345. specail_project := int64(projectM["specail_project"].(float64))
  12346. project.SpecailProject = specail_project
  12347. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12348. project.SocialSecurityDirectoryCode = social_security_directory_code
  12349. remark := projectM["remark"].(string)
  12350. project.Remark = remark
  12351. record_date := projectM["record_date"].(string)
  12352. timeLayout := "2006-01-02"
  12353. loc, _ := time.LoadLocation("Local")
  12354. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12355. project.RecordDate = theTime.Unix()
  12356. projectList = append(projectList, &project)
  12357. }
  12358. export_time := time.Now().Unix()
  12359. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12360. if len(projectList) > 0 {
  12361. for _, item := range projectList {
  12362. hans := item.ProjectName // 要转换的汉字字符串
  12363. // 创建一个拼音转换器
  12364. p := pinyin.NewArgs()
  12365. // 将汉字转为拼音
  12366. pinyinSlice := pinyin.Pinyin(hans, p)
  12367. // 输出拼音
  12368. fmt.Println("Pinyin:", pinyinSlice)
  12369. // 获取首字母
  12370. firstLetter := ""
  12371. for _, py := range pinyinSlice {
  12372. if len(py) > 0 {
  12373. firstLetter += string(py[0][0])
  12374. }
  12375. }
  12376. item.FirstLetter = firstLetter
  12377. project := models.HisProject{
  12378. ProjectName: item.ProjectName,
  12379. Price: item.Price,
  12380. Unit: item.Unit,
  12381. CostClassify: item.CostClassify,
  12382. ExecutiveSection: item.ExecutiveSection,
  12383. MedicalCoverage: item.MedicalCoverage,
  12384. UserOrgId: orgId,
  12385. Status: 1,
  12386. CreatedTime: time.Now().Unix(),
  12387. Pinyin: item.Pinyin,
  12388. Wubi: item.Wubi,
  12389. StatisticalClassification: item.StatisticalClassification,
  12390. DiseaseDirectory: item.DiseaseDirectory,
  12391. IsRecord: item.IsRecord,
  12392. MedicalCode: item.MedicalCode,
  12393. TubeColor: item.TubeColor,
  12394. SingleDose: item.SingleDose,
  12395. DeliveryWay: item.DeliveryWay,
  12396. NumberDays: item.NumberDays,
  12397. Total: item.Total,
  12398. Category: item.Category,
  12399. MedicalStatus: item.MedicalStatus,
  12400. SpecailProject: item.SpecailProject,
  12401. RecordDate: item.RecordDate,
  12402. Remark: item.Remark,
  12403. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12404. ExecutionFrequency: item.ExecutionFrequency,
  12405. FirstLetter: item.FirstLetter,
  12406. }
  12407. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12408. if errcodeproject == gorm.ErrRecordNotFound {
  12409. service.CreateProjectInfomation(&project)
  12410. } else if errcodeproject == nil {
  12411. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12412. }
  12413. log := models.ExportLog{
  12414. LogType: 6,
  12415. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12416. TotalNum: int64(len(total_goods)),
  12417. FailNum: int64(len(errLogs)),
  12418. SuccessNum: int64(len(projectList)),
  12419. CreateTime: time.Now().Unix(),
  12420. UpdateTime: time.Now().Unix(),
  12421. ExportTime: export_time,
  12422. Status: 1,
  12423. }
  12424. service.CreateExportLog(&log)
  12425. c.ServeSuccessJSON(map[string]interface{}{
  12426. "msg": "导入成功",
  12427. "total_num": len(total_goods),
  12428. "success_num": len(projectList),
  12429. "fail_num": int64(len(errLogs)),
  12430. })
  12431. }
  12432. } else {
  12433. log := models.ExportLog{
  12434. LogType: 6,
  12435. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12436. TotalNum: int64(len(total_goods)),
  12437. FailNum: int64(len(errLogs)),
  12438. SuccessNum: int64(len(projectList)),
  12439. CreateTime: time.Now().Unix(),
  12440. UpdateTime: time.Now().Unix(),
  12441. ExportTime: export_time,
  12442. Status: 1,
  12443. }
  12444. service.CreateExportLog(&log)
  12445. c.ServeSuccessJSON(map[string]interface{}{
  12446. "msg": "导入成功",
  12447. "total_num": len(total_goods),
  12448. "success_num": len(projectList),
  12449. "fail_num": int64(len(errLogs)),
  12450. })
  12451. }
  12452. }
  12453. //func (this *HisApiController) EditProjectInformation(){
  12454. //
  12455. // id, _ := this.GetInt64("id")
  12456. // project_team := this.GetString("project_team")
  12457. // price := this.GetString("price")
  12458. // price_float, _ := strconv.ParseFloat(price, 64)
  12459. // pinyin := this.GetString("pinyin")
  12460. // wubi := this.GetString("wubi")
  12461. // tube_color, _ := this.GetInt64("tube_color")
  12462. // team_type, _ := this.GetInt64("team_type")
  12463. // remark := this.GetString("remark")
  12464. // ids := this.GetString("ids")
  12465. // item_id := this.GetString("item_id")
  12466. // projectTeam := models.XtHisProjectTeam{
  12467. // ProjectTeam: project_team,
  12468. // Price: price_float,
  12469. // Pinyin: pinyin,
  12470. // Wubi: wubi,
  12471. // TubeColor: tube_color,
  12472. // TeamType: team_type,
  12473. // Remark: remark,
  12474. // ProjectId: ids,
  12475. // ItemId: item_id,
  12476. // }
  12477. //
  12478. //
  12479. // dataBody := make(map[string]interface{}, 0)
  12480. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12481. // if err != nil {
  12482. // utils.ErrorLog(err.Error())
  12483. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12484. // return
  12485. // }
  12486. //
  12487. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12488. //
  12489. //
  12490. // if err != nil {
  12491. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12492. // return
  12493. // }
  12494. //
  12495. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12496. // infos, _ := dataBody["info"].([]interface{})
  12497. // if len(infos) > 0 {
  12498. // var ids []string
  12499. //
  12500. // for _, item := range infos {
  12501. // items := item.(map[string]interface{})
  12502. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12503. // utils.ErrorLog("id")
  12504. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12505. // return
  12506. // }
  12507. // id := int64(items["id"].(float64))
  12508. //
  12509. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12510. // utils.ErrorLog("type")
  12511. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12512. // return
  12513. // }
  12514. // types := int64(items["type"].(float64))
  12515. //
  12516. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12517. // utils.ErrorLog("number")
  12518. // }
  12519. //
  12520. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12521. //
  12522. // projectList := models.XtHisProjectList{
  12523. // Number: number,
  12524. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12525. // ProjectId: id,
  12526. // Status: 1,
  12527. // CreatedTime: time.Now().Unix(),
  12528. // UpdatedTime: time.Now().Unix(),
  12529. // TeamId: projectTeam.ID,
  12530. // Type: types,
  12531. // }
  12532. // list := projectList
  12533. //
  12534. // service.CreateProjectList(&list)
  12535. //
  12536. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12537. //
  12538. // }
  12539. // ids_str := strings.Join(ids, ",")
  12540. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12541. // service.SaveProjectTeam(&projectTeam)
  12542. // this.ServeSuccessJSON(map[string]interface{}{
  12543. // "projectTeam": projectTeam,
  12544. // })
  12545. // }
  12546. // }
  12547. //}
  12548. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12549. name := c.GetString("name")
  12550. mode_id, _ := c.GetInt64("mode", 0)
  12551. types, _ := c.GetInt64("type", 0)
  12552. patient_id, _ := c.GetInt64("patient_id", 0)
  12553. types = 1
  12554. adminInfo := c.GetAdminUserInfo()
  12555. template := &models.HisPrescriptionTemplate{
  12556. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12557. PatientId: patient_id,
  12558. Type: types,
  12559. Status: 1,
  12560. Ctime: time.Now().Unix(),
  12561. Mtime: time.Now().Unix(),
  12562. Name: name,
  12563. Mode: mode_id,
  12564. }
  12565. dataBody := make(map[string]interface{}, 0)
  12566. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12567. if err != nil {
  12568. utils.ErrorLog(err.Error())
  12569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12570. return
  12571. }
  12572. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12573. //如果已经存在记录则删除处方
  12574. if template_one.ID > 0 {
  12575. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12576. var ids []int64
  12577. var org_id int64
  12578. for _, item := range ps {
  12579. org_id = c.GetAdminUserInfo().CurrentOrgId
  12580. ids = append(ids, item.ID)
  12581. }
  12582. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12583. if err2 == nil {
  12584. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12585. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12586. if len(prescriptions) > 0 {
  12587. for _, item := range prescriptions {
  12588. items := item.(map[string]interface{})
  12589. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12590. utils.ErrorLog("type")
  12591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12592. return
  12593. }
  12594. types := int64(items["type"].(float64))
  12595. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12596. utils.ErrorLog("med_type")
  12597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12598. return
  12599. }
  12600. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12601. ctime := time.Now().Unix()
  12602. prescription := &models.HisPrescriptionInfoTemplate{
  12603. PatientId: patient_id,
  12604. UserOrgId: adminInfo.CurrentOrgId,
  12605. Ctime: ctime,
  12606. Mtime: ctime,
  12607. Type: types,
  12608. Modifier: adminInfo.AdminUser.Id,
  12609. Creator: adminInfo.AdminUser.Id,
  12610. Status: 1,
  12611. PTemplateId: template_one.ID,
  12612. MedType: med_type,
  12613. }
  12614. service.CreateHisPrescriptionInfoTemplate(prescription)
  12615. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12616. advices := items["advices"].([]interface{})
  12617. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12618. ctime := time.Now().Unix()
  12619. mtime := ctime
  12620. if len(advices) > 0 {
  12621. for _, advice := range advices {
  12622. var s models.HisPrescriptionAdviceTemplate
  12623. s.PrescriptionId = prescription.ID
  12624. s.AdviceType = 2
  12625. s.StopState = 2
  12626. s.ExecutionState = 2
  12627. s.Status = 1
  12628. s.UserOrgId = adminInfo.CurrentOrgId
  12629. s.CreatedTime = ctime
  12630. s.UpdatedTime = mtime
  12631. s.PatientId = patient_id
  12632. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12633. if errcode > 0 {
  12634. c.ServeFailJSONWithSGJErrorCode(errcode)
  12635. return
  12636. }
  12637. service.CreateHisPrescriptionAdviceTemplate(&s)
  12638. }
  12639. }
  12640. }
  12641. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12642. projects := items["project"].([]interface{})
  12643. if len(projects) > 0 {
  12644. for _, project := range projects {
  12645. var p models.HisPrescriptionProjectTemplate
  12646. p.PrescriptionId = prescription.ID
  12647. p.Ctime = time.Now().Unix()
  12648. p.Mtime = time.Now().Unix()
  12649. p.PatientId = patient_id
  12650. p.UserOrgId = adminInfo.CurrentOrgId
  12651. p.Status = 1
  12652. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12653. if errcode > 0 {
  12654. c.ServeFailJSONWithSGJErrorCode(errcode)
  12655. return
  12656. }
  12657. service.CreateHisPrescriptionProjectTemplate(&p)
  12658. }
  12659. }
  12660. }
  12661. }
  12662. c.ServeSuccessJSON(map[string]interface{}{
  12663. "msg": "创建成功",
  12664. })
  12665. }
  12666. }
  12667. } else {
  12668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12669. return
  12670. }
  12671. } else {
  12672. err3 := service.CreateHisPrescriptionTemplate(template)
  12673. if err3 == nil {
  12674. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12675. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12676. if len(prescriptions) > 0 {
  12677. for _, item := range prescriptions {
  12678. items := item.(map[string]interface{})
  12679. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12680. utils.ErrorLog("type")
  12681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12682. return
  12683. }
  12684. types := int64(items["type"].(float64))
  12685. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12686. utils.ErrorLog("med_type")
  12687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12688. return
  12689. }
  12690. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12691. ctime := time.Now().Unix()
  12692. prescription := &models.HisPrescriptionInfoTemplate{
  12693. PatientId: patient_id,
  12694. UserOrgId: adminInfo.CurrentOrgId,
  12695. Ctime: ctime,
  12696. Mtime: ctime,
  12697. Type: types,
  12698. Modifier: adminInfo.AdminUser.Id,
  12699. Creator: adminInfo.AdminUser.Id,
  12700. Status: 1,
  12701. PTemplateId: template.ID,
  12702. MedType: med_type,
  12703. }
  12704. service.CreateHisPrescriptionInfoTemplate(prescription)
  12705. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12706. advices := items["advices"].([]interface{})
  12707. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12708. ctime := time.Now().Unix()
  12709. mtime := ctime
  12710. if len(advices) > 0 {
  12711. for _, advice := range advices {
  12712. var s models.HisPrescriptionAdviceTemplate
  12713. s.PrescriptionId = prescription.ID
  12714. s.AdviceType = 2
  12715. s.StopState = 2
  12716. s.ExecutionState = 2
  12717. s.Status = 1
  12718. s.UserOrgId = adminInfo.CurrentOrgId
  12719. s.CreatedTime = ctime
  12720. s.UpdatedTime = mtime
  12721. s.PatientId = patient_id
  12722. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12723. if errcode > 0 {
  12724. c.ServeFailJSONWithSGJErrorCode(errcode)
  12725. return
  12726. }
  12727. service.CreateHisPrescriptionAdviceTemplate(&s)
  12728. }
  12729. }
  12730. }
  12731. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12732. projects := items["project"].([]interface{})
  12733. if len(projects) > 0 {
  12734. for _, project := range projects {
  12735. var p models.HisPrescriptionProjectTemplate
  12736. p.PrescriptionId = prescription.ID
  12737. p.Ctime = time.Now().Unix()
  12738. p.Mtime = time.Now().Unix()
  12739. p.PatientId = patient_id
  12740. p.UserOrgId = adminInfo.CurrentOrgId
  12741. p.Status = 1
  12742. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12743. if errcode > 0 {
  12744. c.ServeFailJSONWithSGJErrorCode(errcode)
  12745. return
  12746. }
  12747. service.CreateHisPrescriptionProjectTemplate(&p)
  12748. }
  12749. }
  12750. }
  12751. }
  12752. c.ServeSuccessJSON(map[string]interface{}{
  12753. "msg": "创建成功",
  12754. })
  12755. }
  12756. }
  12757. } else {
  12758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12759. return
  12760. }
  12761. }
  12762. }
  12763. func (c *HisApiController) PreSettle() {
  12764. id, _ := c.GetInt64("id")
  12765. record_time := c.GetString("record_time")
  12766. his_patient_id, _ := c.GetInt64("his_patient_id")
  12767. timeLayout := "2006-01-02"
  12768. loc, _ := time.LoadLocation("Local")
  12769. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12770. diagnosis_id := c.GetString("diagnosis")
  12771. sick_type, _ := c.GetInt64("sick_type")
  12772. reg_type, _ := c.GetInt64("p_type")
  12773. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12774. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12775. if err != nil {
  12776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12777. return
  12778. }
  12779. recordDateTime := theTime.Unix()
  12780. adminUser := c.GetAdminUserInfo()
  12781. var prescriptions []*models.HisPrescription
  12782. var start_time int64
  12783. var end_time int64
  12784. ids_str := c.GetString("ids")
  12785. ids_arr := strings.Split(ids_str, ",")
  12786. fmt.Println(reg_type)
  12787. if settle_accounts_type == 1 { //日结
  12788. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12789. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12790. } else {
  12791. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12792. }
  12793. fmt.Println(prescriptions)
  12794. } else { //月结
  12795. start_time_str := c.GetString("start_time")
  12796. end_time_str := c.GetString("end_time")
  12797. timeLayout := "2006-01-02"
  12798. loc, _ := time.LoadLocation("Local")
  12799. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12800. if err != nil {
  12801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12802. return
  12803. }
  12804. recordStartTime := theStartTime.Unix()
  12805. start_time = recordStartTime
  12806. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12807. if err != nil {
  12808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12809. return
  12810. }
  12811. recordEndTime := theEndTime.Unix()
  12812. end_time = recordEndTime
  12813. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12814. }
  12815. if reg_type == 1111 || reg_type == 1112 {
  12816. reg_type = 11
  12817. }
  12818. timestamp := time.Now().Unix()
  12819. tempTime := time.Unix(timestamp, 0)
  12820. timeFormat := tempTime.Format("20060102150405")
  12821. chrgBchno := rand.Intn(100000) + 10000
  12822. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12823. strconv.FormatInt(his.PatientId, 10)
  12824. var ids []int64
  12825. for _, item := range prescriptions {
  12826. ids = append(ids, item.ID)
  12827. }
  12828. fmt.Println(ids)
  12829. var total float64
  12830. for _, item := range prescriptions {
  12831. fmt.Println(item)
  12832. if item.Type == 1 { //药品
  12833. for _, subItem := range item.HisDoctorAdviceInfo {
  12834. total = total + (subItem.Price * subItem.PrescribingNumber)
  12835. }
  12836. }
  12837. if item.Type == 2 { //项目
  12838. for _, subItem := range item.HisPrescriptionProject {
  12839. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12840. total = total + (subItem.Price * cnt)
  12841. }
  12842. }
  12843. for _, subItem := range item.HisAdditionalCharge {
  12844. total = total + (subItem.Price * float64(subItem.Count))
  12845. }
  12846. }
  12847. allTotal := fmt.Sprintf("%.2f", total)
  12848. totals, _ := strconv.ParseFloat(allTotal, 64)
  12849. order := &models.HisOrder{
  12850. UserOrgId: adminUser.CurrentOrgId,
  12851. HisPatientId: his.ID,
  12852. PatientId: id,
  12853. SettleAccountsDate: recordDateTime,
  12854. Ctime: time.Now().Unix(),
  12855. Mtime: time.Now().Unix(),
  12856. Status: 1,
  12857. OrderStatus: 1,
  12858. MdtrtId: his.Number,
  12859. Number: chrg_bchno,
  12860. MedfeeSumamt: totals,
  12861. SettleEndTime: end_time,
  12862. SettleStartTime: start_time,
  12863. SettleType: settle_accounts_type,
  12864. PsnPartAmt: totals,
  12865. PsnCashPay: totals,
  12866. PType: 2,
  12867. IsPre: 1,
  12868. MedType: strconv.Itoa(int(reg_type)),
  12869. Diagnosis: diagnosis_id,
  12870. }
  12871. err = service.CreateOrder(order)
  12872. if err != nil {
  12873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12874. return
  12875. }
  12876. var customs []*Custom
  12877. for _, item := range prescriptions {
  12878. fmt.Println(item.Type)
  12879. if item.Type == 1 { //药品
  12880. for _, subItem := range item.HisDoctorAdviceInfo {
  12881. cus := &Custom{
  12882. AdviceId: subItem.ID,
  12883. ProjectId: 0,
  12884. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12885. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12886. FeedetlSn: subItem.FeedetlSn,
  12887. Price: fmt.Sprintf("%.2f", subItem.Price),
  12888. MedListCodg: subItem.MedListCodg,
  12889. Type: 1,
  12890. }
  12891. customs = append(customs, cus)
  12892. }
  12893. }
  12894. if item.Type == 2 { //项目
  12895. for _, subItem := range item.HisPrescriptionProject {
  12896. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12897. cus := &Custom{
  12898. AdviceId: 0,
  12899. ProjectId: subItem.ID,
  12900. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12901. Cut: fmt.Sprintf("%.2f", cnt),
  12902. FeedetlSn: subItem.FeedetlSn,
  12903. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12904. MedListCodg: subItem.MedListCodg,
  12905. Type: 2,
  12906. }
  12907. customs = append(customs, cus)
  12908. }
  12909. }
  12910. for _, item := range item.HisAdditionalCharge {
  12911. cus := &Custom{
  12912. ItemId: item.ID,
  12913. AdviceId: 0,
  12914. ProjectId: 0,
  12915. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12916. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12917. FeedetlSn: item.FeedetlSn,
  12918. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12919. MedListCodg: item.XtHisAddtionConfig.Code,
  12920. Type: 3,
  12921. }
  12922. customs = append(customs, cus)
  12923. }
  12924. }
  12925. fmt.Println(customs)
  12926. for _, item := range customs {
  12927. var advice_id int64 = 0
  12928. var project_id int64 = 0
  12929. var item_id int64 = 0
  12930. var types int64 = 0
  12931. if item.Type == 1 {
  12932. advice_id = item.AdviceId
  12933. project_id = 0
  12934. item_id = 0
  12935. } else if item.Type == 2 {
  12936. advice_id = 0
  12937. item_id = 0
  12938. project_id = item.ProjectId
  12939. } else if item.Type == 3 {
  12940. advice_id = 0
  12941. item_id = item.ItemId
  12942. project_id = 0
  12943. }
  12944. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12945. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12946. pric, _ := strconv.ParseFloat(item.Price, 32)
  12947. info := &models.HisOrderInfo{
  12948. OrderNumber: order.Number,
  12949. UploadDate: time.Now().Unix(),
  12950. AdviceId: advice_id,
  12951. DetItemFeeSumamt: detItemFeeSumamt,
  12952. Cnt: cut,
  12953. Pric: pric,
  12954. PatientId: id,
  12955. Status: 1,
  12956. Mtime: time.Now().Unix(),
  12957. Ctime: time.Now().Unix(),
  12958. UserOrgId: adminUser.CurrentOrgId,
  12959. HisPatientId: his.ID,
  12960. OrderId: order.ID,
  12961. ProjectId: project_id,
  12962. Type: types,
  12963. ItemId: item_id,
  12964. }
  12965. service.CreateOrderInfo(info)
  12966. }
  12967. his.SickType = sick_type
  12968. service.UpdataHisPateint(&his)
  12969. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12970. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12971. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12972. if err == nil {
  12973. c.ServeSuccessJSON(map[string]interface{}{
  12974. "msg": "结算成功",
  12975. })
  12976. }
  12977. }
  12978. type CustomOrderInfo struct {
  12979. Name string
  12980. Spec string
  12981. Unit string
  12982. Count float64
  12983. Price float64
  12984. Total float64
  12985. }
  12986. func (c *HisApiController) GetPrivateExpensesInfo() {
  12987. order_id, _ := c.GetInt64("id", 0)
  12988. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12989. order, _ := service.GetHisOrderByID(order_id)
  12990. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12991. if order.ID == 0 {
  12992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12993. return
  12994. }
  12995. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12996. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12997. org_id := c.GetAdminUserInfo().CurrentOrgId
  12998. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12999. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  13000. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  13001. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  13002. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  13003. //var orderInfos_four []*models.HisOrderInfoTwo
  13004. //for _, item := range orderInfos_three {
  13005. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  13006. // item.HisPrescriptionProject.IsCheckTeam = 1
  13007. // orderInfos_four = append(orderInfos_four, item)
  13008. //
  13009. // }
  13010. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  13011. // item.HisPrescriptionProject.IsCheckTeam = 2
  13012. // orderInfos_two = append(orderInfos_two, item)
  13013. // }
  13014. //}
  13015. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  13016. //var cus_slice []CustomOrderInfo
  13017. //for _, item := range new_order_info {
  13018. // var cus CustomOrderInfo
  13019. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  13020. // cus.Unit = ""
  13021. // cus.Spec = ""
  13022. // var total float64
  13023. // for _, subItem := range orderInfos_four {
  13024. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  13025. // total = total + subItem.DetItemFeeSumamt
  13026. // fmt.Println(subItem.DetItemFeeSumamt)
  13027. // }
  13028. // }
  13029. // cus.Count = 1
  13030. // cus.Total = total
  13031. // cus_slice = append(cus_slice, cus)
  13032. //}
  13033. orderInfos = append(orderInfos, orderInfos_two...)
  13034. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  13035. //orderInfos = append(orderInfos, orderInfos_three...)
  13036. //}/**/
  13037. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  13038. c.ServeSuccessJSON(map[string]interface{}{
  13039. "order": order,
  13040. "order_info": orderInfos,
  13041. "patient": patient,
  13042. "admin_info": adminInfo,
  13043. "his": his,
  13044. "current_admin": role,
  13045. "org_config": miConfig,
  13046. //"new_order_info": cus_slice,
  13047. })
  13048. }
  13049. func (this *HisApiController) ChangeMedType() {
  13050. med_type := this.GetString("med_type")
  13051. old_med_type := this.GetString("old_med_type")
  13052. ids := this.GetString("ids")
  13053. settle_type, _ := this.GetInt64("settle_type")
  13054. start_time := this.GetString("start_time")
  13055. end_time := this.GetString("end_time")
  13056. ids_arr := strings.Split(ids, ",")
  13057. if settle_type == 1 { //日结
  13058. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  13059. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  13060. prescription.MedType = med_type
  13061. err := service.SaveHisPrescriptionTwo(&prescription)
  13062. if err == nil {
  13063. this.ServeSuccessJSON(map[string]interface{}{
  13064. "msg": "修改成功",
  13065. })
  13066. } else {
  13067. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13068. return
  13069. }
  13070. } else if settle_type == 2 {
  13071. timeLayout := "2006-01-02"
  13072. loc, _ := time.LoadLocation("Local")
  13073. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13074. if err != nil {
  13075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13076. return
  13077. }
  13078. recordStartTime := theStartTime.Unix()
  13079. start_time_timestamp := recordStartTime
  13080. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  13081. if err != nil {
  13082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13083. return
  13084. }
  13085. recordEndTime := theEndTime.Unix()
  13086. end_time_timestamp := recordEndTime
  13087. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  13088. if updateErr == nil {
  13089. this.ServeSuccessJSON(map[string]interface{}{
  13090. "msg": "修改成功",
  13091. })
  13092. } else {
  13093. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13094. return
  13095. }
  13096. }
  13097. }
  13098. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  13099. patient_id, _ := c.GetInt64("patient_id")
  13100. his_patient_id, _ := c.GetInt64("his_patient_id")
  13101. record_date := c.GetString("record_date")
  13102. start_time := c.GetString("start_time")
  13103. end_time := c.GetString("end_time")
  13104. order_status, _ := c.GetInt64("type", 0)
  13105. p_type, _ := c.GetInt64("p_type", 0)
  13106. order_id, _ := c.GetInt64("order_id", 0)
  13107. timeLayout := "2006-01-02"
  13108. loc, _ := time.LoadLocation("Local")
  13109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13110. if err != nil {
  13111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13112. return
  13113. }
  13114. recordDateTime := theTime.Unix()
  13115. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13116. if err != nil {
  13117. }
  13118. startRecordDateTime := startTime.Unix()
  13119. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13120. if err != nil {
  13121. }
  13122. endRecordDateTime := endTime.Unix()
  13123. admin := c.GetAdminUserInfo()
  13124. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  13125. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13126. order, _ := service.GetHisOrderByID(order_id)
  13127. var monthPrescriptions []*models.HisPrescription
  13128. if order_status == 1 || order_status == 0 {
  13129. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13130. } else if order_status == 2 {
  13131. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  13132. }
  13133. var settle_total float64
  13134. for _, item := range monthPrescriptions {
  13135. if len(item.HisPrescriptionProject) > 0 {
  13136. for _, subItem := range item.HisPrescriptionProject {
  13137. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13138. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13139. settle_total = settle_total + total
  13140. }
  13141. }
  13142. if len(item.HisDoctorAdviceInfo) > 0 {
  13143. for _, subItem := range item.HisDoctorAdviceInfo {
  13144. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13145. settle_total = settle_total + total
  13146. }
  13147. }
  13148. }
  13149. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13150. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13151. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13152. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13153. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13154. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13155. //获取所有科室信息
  13156. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13157. var dia string
  13158. for _, item := range month_p_info {
  13159. if len(dia) == 0 {
  13160. dia = item.Diagnosis
  13161. } else {
  13162. dia = dia + "," + item.Diagnosis
  13163. }
  13164. }
  13165. dia_arr := removeDuplicates(strings.Split(dia, ","))
  13166. dia_arr = removeEmptyStrings(dia_arr)
  13167. c.ServeSuccessJSON(map[string]interface{}{
  13168. "his_info": his_patient_info,
  13169. "xt_info": xt_patient_info,
  13170. "case_history": case_history,
  13171. "info": patientPrescriptionInfo,
  13172. "last_info": lastPatientPrescriptionInfo,
  13173. "month_prescriptions": monthPrescriptions,
  13174. "order": order,
  13175. "doctors": doctors,
  13176. "department": department,
  13177. "settle_total": settle_total,
  13178. "dia_arr": dia_arr,
  13179. })
  13180. return
  13181. }
  13182. func removeEmptyStrings(input []string) []string {
  13183. var output []string
  13184. for _, s := range input {
  13185. if s != "" {
  13186. output = append(output, s)
  13187. }
  13188. }
  13189. return output
  13190. }
  13191. func removeDuplicates(input []string) []string {
  13192. seen := make(map[string]bool)
  13193. output := []string{}
  13194. for _, s := range input {
  13195. if _, exists := seen[s]; !exists {
  13196. seen[s] = true
  13197. output = append(output, s)
  13198. }
  13199. }
  13200. return output
  13201. }
  13202. func (c *HisApiController) GetHisMonthPatientInfo() {
  13203. patient_id, _ := c.GetInt64("patient_id")
  13204. his_patient_id, _ := c.GetInt64("his_patient_id")
  13205. record_date := c.GetString("record_date")
  13206. number := c.GetString("number")
  13207. start_time := c.GetString("start_time")
  13208. end_time := c.GetString("end_time")
  13209. p_type, _ := c.GetInt64("p_type")
  13210. timeLayout := "2006-01-02"
  13211. loc, _ := time.LoadLocation("Local")
  13212. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13213. if err != nil {
  13214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13215. return
  13216. }
  13217. recordDateTime := theTime.Unix()
  13218. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13219. if err != nil {
  13220. }
  13221. startRecordDateTime := startTime.Unix()
  13222. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13223. if err != nil {
  13224. }
  13225. endRecordDateTime := endTime.Unix()
  13226. admin := c.GetAdminUserInfo()
  13227. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  13228. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13229. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  13230. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13231. var settle_total float64
  13232. for _, item := range monthPrescriptions {
  13233. if len(item.HisPrescriptionProject) > 0 {
  13234. for _, subItem := range item.HisPrescriptionProject {
  13235. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13236. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13237. settle_total = settle_total + total
  13238. }
  13239. }
  13240. if len(item.HisDoctorAdviceInfo) > 0 {
  13241. for _, subItem := range item.HisDoctorAdviceInfo {
  13242. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13243. settle_total = settle_total + total
  13244. }
  13245. }
  13246. }
  13247. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13248. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13249. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13250. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13251. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13252. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13253. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13254. //获取所有科室信息
  13255. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13256. c.ServeSuccessJSON(map[string]interface{}{
  13257. "his_info": his_patient_info,
  13258. "xt_info": xt_patient_info,
  13259. "case_history": case_history,
  13260. "info": patientPrescriptionInfo,
  13261. "month_prescriptions": monthPrescriptions,
  13262. "order": order,
  13263. "doctors": doctors,
  13264. "department": department,
  13265. "count": count,
  13266. "drugStockConfig": drugStockConfig,
  13267. "last_info": lastPatientPrescriptionInfo,
  13268. "settle_total": settle_total,
  13269. })
  13270. return
  13271. }
  13272. func (c *HisApiController) GetAllOrder() {
  13273. org_id := c.GetAdminUserInfo().CurrentOrgId
  13274. orders, _ := service.GetNewHisOrderList(org_id)
  13275. c.ServeSuccessJSON(map[string]interface{}{
  13276. "order": orders,
  13277. })
  13278. return
  13279. }
  13280. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13281. newArr = make([]*models.HisOrderInfoTwo, 0)
  13282. for i := 0; i < len(arr); i++ {
  13283. repeat := false
  13284. for j := i + 1; j < len(arr); j++ {
  13285. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13286. repeat = true
  13287. break
  13288. }
  13289. }
  13290. if !repeat {
  13291. newArr = append(newArr, arr[i])
  13292. }
  13293. }
  13294. return
  13295. }
  13296. // 修改处方退库操作 参数传修改之前的处方数据
  13297. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13298. if advice.ExecutionState == 1 {
  13299. //查询该病人该药品是否有库存记录
  13300. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13301. if errcode == gorm.ErrRecordNotFound {
  13302. } else {
  13303. //退库
  13304. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13305. if advice.PrescribingNumberUnit == drug.MinUnit {
  13306. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13307. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13308. //退库
  13309. warehouseInfo := models.DrugWarehouseInfo{
  13310. StockMinNumber: prescribingNumber,
  13311. }
  13312. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13313. operation_time := time.Now().Unix()
  13314. creater := advice.AdviceDoctor
  13315. ctime := time.Now().Unix()
  13316. timeStr := time.Now().Format("2006-01-02")
  13317. timeArr := strings.Split(timeStr, "-")
  13318. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13319. total = total + 1
  13320. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13321. cancelStock := models.DrugCancelStock{
  13322. OrderNumber: orderNumber,
  13323. OperaTime: operation_time,
  13324. OrgId: advice.UserOrgId,
  13325. Creater: creater,
  13326. Ctime: ctime,
  13327. Status: 1,
  13328. ReturnTime: advice.AdviceDate,
  13329. Dealer: info.Dealer,
  13330. Manufacturer: info.Manufacturer,
  13331. Type: 1,
  13332. }
  13333. service.AddSigleDrugCancelStock(&cancelStock)
  13334. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13335. dealer, _ := service.GetDealerById(info.Dealer)
  13336. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13337. cancelStockInfo := models.DrugCancelStockInfo{
  13338. OrderNumber: cancelInfo.OrderNumber,
  13339. CancelStockId: cancelInfo.ID,
  13340. DrugId: info.DrugId,
  13341. Count: info.Count,
  13342. Status: 1,
  13343. Ctime: ctime,
  13344. OrgId: advice.UserOrgId,
  13345. Type: 1,
  13346. Manufacturer: manufactureName.ManufacturerName,
  13347. Dealer: dealer.DealerName,
  13348. Total: 0,
  13349. RetailPrice: info.RetailPrice,
  13350. RetailTotalPrice: info.RetailTotalPrice,
  13351. Price: info.Price,
  13352. RegisterAccount: "",
  13353. Remark: info.Remark,
  13354. BatchNumber: info.BatchNumber,
  13355. MaxUnit: info.CountUnit,
  13356. ProductDate: info.ProductDate,
  13357. ExpiryDate: info.ExpiryDate,
  13358. BatchNumberId: info.WarehouseInfoId,
  13359. }
  13360. flow := models.DrugFlow{
  13361. WarehousingId: 0,
  13362. DrugId: info.DrugId,
  13363. Number: "",
  13364. BatchNumber: info.BatchNumber,
  13365. Count: info.Count,
  13366. UserOrgId: advice.UserOrgId,
  13367. PatientId: 0,
  13368. SystemTime: ctime,
  13369. ConsumableType: 4,
  13370. IsSys: 0,
  13371. WarehousingOrder: "",
  13372. WarehouseOutId: 0,
  13373. WarehouseOutOrderNumber: "",
  13374. IsEdit: 0,
  13375. CancelStockId: cancelStock.ID,
  13376. CancelOrderNumber: cancelStock.OrderNumber,
  13377. Manufacturer: info.Manufacturer,
  13378. Dealer: info.Dealer,
  13379. Creator: advice.UserOrgId,
  13380. UpdateCreator: 0,
  13381. Status: 1,
  13382. Ctime: time.Now().Unix(),
  13383. Mtime: 0,
  13384. Price: info.Price,
  13385. WarehousingDetailId: 0,
  13386. WarehouseOutDetailId: 0,
  13387. CancelOutDetailId: 0,
  13388. ExpireDate: info.ExpiryDate,
  13389. ProductDate: info.ProductDate,
  13390. MaxUnit: info.CountUnit,
  13391. MinUnit: "",
  13392. }
  13393. service.CreatedCancelStock(cancelStockInfo)
  13394. service.CreateDrugFlowOne(flow)
  13395. } else {
  13396. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13397. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13398. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13399. warehouseInfo := models.DrugWarehouseInfo{
  13400. StockMinNumber: prescribingNumber,
  13401. }
  13402. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13403. }
  13404. operation_time := time.Now().Unix()
  13405. creater := advice.AdviceDoctor
  13406. ctime := time.Now().Unix()
  13407. timeStr := time.Now().Format("2006-01-02")
  13408. timeArr := strings.Split(timeStr, "-")
  13409. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13410. total = total + 1
  13411. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13412. cancelStock := models.DrugCancelStock{
  13413. OrderNumber: orderNumber,
  13414. OperaTime: operation_time,
  13415. OrgId: advice.UserOrgId,
  13416. Creater: creater,
  13417. Ctime: ctime,
  13418. Status: 1,
  13419. ReturnTime: advice.AdviceDate,
  13420. Dealer: info.Dealer,
  13421. Manufacturer: info.Manufacturer,
  13422. Type: 1,
  13423. }
  13424. service.AddSigleDrugCancelStock(&cancelStock)
  13425. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13426. dealer, _ := service.GetDealerById(info.Dealer)
  13427. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13428. cancelStockInfo := models.DrugCancelStockInfo{
  13429. OrderNumber: cancelInfo.OrderNumber,
  13430. CancelStockId: cancelInfo.ID,
  13431. DrugId: info.DrugId,
  13432. Count: info.Count,
  13433. Status: 1,
  13434. Ctime: ctime,
  13435. OrgId: advice.UserOrgId,
  13436. Type: 1,
  13437. Manufacturer: manufactureName.ManufacturerName,
  13438. Dealer: dealer.DealerName,
  13439. Total: 0,
  13440. RetailPrice: info.RetailPrice,
  13441. RetailTotalPrice: info.RetailTotalPrice,
  13442. Price: info.Price,
  13443. RegisterAccount: "",
  13444. Remark: info.Remark,
  13445. BatchNumber: info.BatchNumber,
  13446. MaxUnit: info.CountUnit,
  13447. ProductDate: info.ProductDate,
  13448. ExpiryDate: info.ExpiryDate,
  13449. BatchNumberId: info.WarehouseInfoId,
  13450. }
  13451. flow := models.DrugFlow{
  13452. WarehousingId: 0,
  13453. DrugId: info.DrugId,
  13454. Number: "",
  13455. BatchNumber: info.BatchNumber,
  13456. Count: info.Count,
  13457. UserOrgId: advice.UserOrgId,
  13458. PatientId: 0,
  13459. SystemTime: ctime,
  13460. ConsumableType: 4,
  13461. IsSys: 0,
  13462. WarehousingOrder: "",
  13463. WarehouseOutId: 0,
  13464. WarehouseOutOrderNumber: "",
  13465. IsEdit: 0,
  13466. CancelStockId: cancelStock.ID,
  13467. CancelOrderNumber: cancelStock.OrderNumber,
  13468. Manufacturer: info.Manufacturer,
  13469. Dealer: info.Dealer,
  13470. Creator: advice.AdviceDoctor,
  13471. UpdateCreator: 0,
  13472. Status: 1,
  13473. Ctime: time.Now().Unix(),
  13474. Mtime: 0,
  13475. Price: info.Price,
  13476. WarehousingDetailId: 0,
  13477. WarehouseOutDetailId: 0,
  13478. CancelOutDetailId: 0,
  13479. ExpireDate: info.ExpiryDate,
  13480. ProductDate: info.ProductDate,
  13481. MaxUnit: info.CountUnit,
  13482. MinUnit: "",
  13483. }
  13484. service.CreatedCancelStock(cancelStockInfo)
  13485. service.CreateDrugFlowOne(flow)
  13486. }
  13487. }
  13488. }
  13489. return err
  13490. }
  13491. func (this *HisApiController) DeleteNCDS() {
  13492. id, _ := this.GetInt64("id", 0)
  13493. if id > 0 {
  13494. service.DeletePsnNCDSRecordById(id)
  13495. this.ServeSuccessJSON(map[string]interface{}{
  13496. "msg": "删除成功",
  13497. })
  13498. } else {
  13499. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13500. return
  13501. }
  13502. }
  13503. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13504. id, _ := c.GetInt64("id")
  13505. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13506. c.ServeSuccessJSON(map[string]interface{}{
  13507. "advice": advice,
  13508. })
  13509. return
  13510. }
  13511. func (c *HisApiController) GetHisMonthChargePatientList() {
  13512. record_date := c.GetString("record_date")
  13513. start_time := c.GetString("start_time")
  13514. end_time := c.GetString("end_time")
  13515. timeLayout := "2006-01-02"
  13516. loc, _ := time.LoadLocation("Local")
  13517. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13518. if err != nil {
  13519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13520. return
  13521. }
  13522. if err != nil {
  13523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13524. return
  13525. }
  13526. recordDateTime := theTime.Unix()
  13527. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13528. if err != nil {
  13529. }
  13530. startRecordDateTime := startTime.Unix()
  13531. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13532. if err != nil {
  13533. }
  13534. endRecordDateTime := endTime.Unix()
  13535. adminInfo := c.GetAdminUserInfo()
  13536. var tempMonthChargePatients []*service.MonthChargePatients
  13537. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13538. for _, item := range tempPatients {
  13539. //过滤没有处方的
  13540. if len(item.HisPrescription) == 0 {
  13541. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13542. }
  13543. }
  13544. c.ServeSuccessJSON(map[string]interface{}{
  13545. "list": tempMonthChargePatients,
  13546. })
  13547. }
  13548. // PrescriptionDifference 医嘱数量差值结构体
  13549. type PrescriptionDrugDifference struct {
  13550. DrugID int64 //基础库药品id
  13551. ID int64 //医嘱id
  13552. Difference float64 //差值
  13553. Unit string //单位
  13554. }
  13555. type PrescriptionGoodDifference struct {
  13556. GoodID int64 //基础库项目耗材id
  13557. ID int64 //医嘱id
  13558. Difference int64 //差值
  13559. Unit string //单位
  13560. Type int64 //类型
  13561. }
  13562. type EditCustomData struct {
  13563. adviceList []*models.HisDoctorAdviceInfo
  13564. projectList []*models.HisPrescriptionProject
  13565. }
  13566. type SrcCustomData struct {
  13567. adviceList []*models.HisDoctorAdviceInfo
  13568. projectList []*models.HisPrescriptionProject
  13569. }
  13570. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13571. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13572. differences := make([]*PrescriptionDrugDifference, 0)
  13573. // 创建一个 map 来存储第一个切片中的药品信息
  13574. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13575. for _, advice := range firstPrescription {
  13576. firstMap[advice.DrugId] = advice
  13577. }
  13578. // 遍历第二个切片中的药品信息,并比较数量差值
  13579. for _, advice := range secondPrescription {
  13580. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13581. diff := &PrescriptionDrugDifference{
  13582. DrugID: advice.DrugId,
  13583. ID: firstAdvice.ID,
  13584. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13585. Unit: firstAdvice.PrescribingNumberUnit,
  13586. }
  13587. differences = append(differences, diff)
  13588. }
  13589. }
  13590. return differences
  13591. }
  13592. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13593. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13594. differences := make([]*PrescriptionGoodDifference, 0)
  13595. // 创建一个 map 来存储第一个切片中的耗材信息
  13596. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13597. for _, good := range firstPrescription {
  13598. firstMap[good.ProjectId] = good
  13599. }
  13600. // 遍历第二个切片中的耗材信息,并比较数量差值
  13601. for _, good := range secondPrescription {
  13602. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13603. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13604. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13605. diff := &PrescriptionGoodDifference{
  13606. GoodID: good.ProjectId,
  13607. ID: firstGood.ID,
  13608. Difference: count - firstCount,
  13609. Unit: firstGood.Unit,
  13610. Type: firstGood.Type,
  13611. }
  13612. differences = append(differences, diff)
  13613. }
  13614. }
  13615. return differences
  13616. }
  13617. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13618. var adviceList []*models.HisDoctorAdviceInfo
  13619. var projectList []*models.HisPrescriptionProject
  13620. var advice_ids []int64
  13621. var project_ids []int64
  13622. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13623. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13624. //var tempPrescription *models.HisPrescriptionProjectscription
  13625. if len(prescriptions) > 0 {
  13626. for _, item := range prescriptions {
  13627. items := item.(map[string]interface{})
  13628. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13629. advices := items["advices"].([]interface{})
  13630. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13631. groupNo := int64(0)
  13632. ctime := time.Now().Unix()
  13633. mtime := ctime
  13634. if len(advices) > 0 {
  13635. for _, advice := range advices {
  13636. var s models.HisDoctorAdviceInfo
  13637. s.AdviceType = 2
  13638. s.StopState = 2
  13639. s.ExecutionState = 2
  13640. s.Status = 1
  13641. s.Groupno = groupNo
  13642. s.CreatedTime = ctime
  13643. s.UpdatedTime = mtime
  13644. s.IsSettle = 2
  13645. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13646. //存储切片中
  13647. if s.ID > 0 {
  13648. advice_ids = append(advice_ids, s.ID)
  13649. adviceList = append(adviceList, &s)
  13650. }
  13651. }
  13652. }
  13653. }
  13654. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13655. projects := items["project"].([]interface{})
  13656. if len(projects) > 0 {
  13657. for _, project := range projects {
  13658. var p models.HisPrescriptionProject
  13659. p.Ctime = time.Now().Unix()
  13660. p.Mtime = time.Now().Unix()
  13661. p.Status = 1
  13662. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13663. if p.ID > 0 {
  13664. project_ids = append(project_ids, p.ID)
  13665. projectList = append(projectList, &p)
  13666. }
  13667. }
  13668. }
  13669. }
  13670. }
  13671. }
  13672. }
  13673. editCustomData.projectList = projectList
  13674. editCustomData.adviceList = adviceList
  13675. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13676. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13677. srcCustomData.adviceList = list
  13678. srcCustomData.projectList = list2
  13679. return
  13680. }
  13681. func (c *HisApiController) GetAllGoodInforList() {
  13682. orgId := c.GetAdminUserInfo().CurrentOrgId
  13683. goodList, _ := service.GetAllGoodList(orgId)
  13684. c.ServeSuccessJSON(map[string]interface{}{
  13685. "goodList": goodList,
  13686. })
  13687. return
  13688. }
  13689. func (this *HisApiController) SaveGoodList() {
  13690. project_name := this.GetString("project_name")
  13691. sort, _ := this.GetInt64("sort")
  13692. orgId := this.GetAdminUserInfo().CurrentOrgId
  13693. dataBody := make(map[string]interface{}, 0)
  13694. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13695. if err != nil {
  13696. utils.ErrorLog(err.Error())
  13697. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13698. return
  13699. }
  13700. goodTeam := models.XtGoodTeam{
  13701. ProjectName: project_name,
  13702. Sort: sort,
  13703. UserOrgId: orgId,
  13704. Status: 1,
  13705. Ctime: time.Now().Unix(),
  13706. Mtime: time.Now().Unix(),
  13707. }
  13708. service.CreateGoodTeam(goodTeam)
  13709. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13710. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13711. infos, _ := dataBody["info"].([]interface{})
  13712. if len(infos) > 0 {
  13713. for _, item := range infos {
  13714. items := item.(map[string]interface{})
  13715. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13716. utils.ErrorLog("good_id")
  13717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13718. return
  13719. }
  13720. good_id := int64(items["good_id"].(float64))
  13721. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13722. utils.ErrorLog("number")
  13723. }
  13724. number := int64(items["number"].(float64))
  13725. xtGoodTeamList := models.XtGoodTeamList{
  13726. GoodId: good_id,
  13727. Count: number,
  13728. TeamId: lastGoodTeam.ID,
  13729. UserOrgId: orgId,
  13730. Status: 1,
  13731. Ctime: time.Now().Unix(),
  13732. Mtime: time.Now().Unix(),
  13733. }
  13734. service.CreateGoodList(xtGoodTeamList)
  13735. }
  13736. this.ServeSuccessJSON(map[string]interface{}{
  13737. "lastGoodTeam": lastGoodTeam,
  13738. })
  13739. }
  13740. }
  13741. return
  13742. }
  13743. func (this *HisApiController) GetGoodList() {
  13744. orgId := this.GetAdminUserInfo().CurrentOrgId
  13745. limit, _ := this.GetInt64("limit")
  13746. page, _ := this.GetInt64("page")
  13747. keyword := this.GetString("keyword")
  13748. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13749. this.ServeSuccessJSON(map[string]interface{}{
  13750. "list": list,
  13751. "total": total,
  13752. })
  13753. }
  13754. func (this *HisApiController) GetGoodNameDetail() {
  13755. id, _ := this.GetInt64("id")
  13756. orgId := this.GetAdminUserInfo().CurrentOrgId
  13757. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13758. goodList, _ := service.GetAllGoodList(orgId)
  13759. this.ServeSuccessJSON(map[string]interface{}{
  13760. "goodNameDetail": goodNameDetail,
  13761. "goodList": goodList,
  13762. })
  13763. }
  13764. func (this *HisApiController) UpdateGoodList() {
  13765. project_name := this.GetString("project_name")
  13766. sort, _ := this.GetInt64("sort")
  13767. id, _ := this.GetInt64("id")
  13768. orgId := this.GetAdminUserInfo().CurrentOrgId
  13769. dataBody := make(map[string]interface{}, 0)
  13770. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13771. if err != nil {
  13772. utils.ErrorLog(err.Error())
  13773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13774. return
  13775. }
  13776. goodTeam := models.XtGoodTeam{
  13777. ProjectName: project_name,
  13778. Sort: sort,
  13779. UserOrgId: orgId,
  13780. Status: 1,
  13781. Ctime: time.Now().Unix(),
  13782. Mtime: time.Now().Unix(),
  13783. ID: id,
  13784. }
  13785. service.SaveGoodTeam(goodTeam)
  13786. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13787. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13788. infos, _ := dataBody["info"].([]interface{})
  13789. if len(infos) > 0 {
  13790. for _, item := range infos {
  13791. items := item.(map[string]interface{})
  13792. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13793. utils.ErrorLog("good_id")
  13794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13795. return
  13796. }
  13797. good_id := int64(items["good_id"].(float64))
  13798. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13799. utils.ErrorLog("id")
  13800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13801. return
  13802. }
  13803. id := int64(items["id"].(float64))
  13804. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13805. utils.ErrorLog("number")
  13806. }
  13807. number := int64(items["number"].(float64))
  13808. xtGoodTeamList := models.XtGoodTeamList{
  13809. ID: id,
  13810. GoodId: good_id,
  13811. Count: number,
  13812. TeamId: lastGoodTeam.ID,
  13813. UserOrgId: orgId,
  13814. Status: 1,
  13815. Ctime: time.Now().Unix(),
  13816. Mtime: time.Now().Unix(),
  13817. }
  13818. service.SaveGoodList(xtGoodTeamList)
  13819. }
  13820. this.ServeSuccessJSON(map[string]interface{}{
  13821. "lastGoodTeam": lastGoodTeam,
  13822. })
  13823. }
  13824. }
  13825. return
  13826. }
  13827. func (this *HisApiController) DeleteGoodTeam() {
  13828. id, _ := this.GetInt64("id")
  13829. team, _ := service.DeleteGoodTeam(id)
  13830. this.ServeSuccessJSON(map[string]interface{}{
  13831. "team": team,
  13832. })
  13833. }
  13834. func (this *HisApiController) DeleteGood() {
  13835. id, _ := this.GetInt64("id")
  13836. good, _ := service.DeleteGood(id)
  13837. this.ServeSuccessJSON(map[string]interface{}{
  13838. "good": good,
  13839. })
  13840. }