his_api_controller.go 602KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "card_desc":
  229. order.CardDesc = desc
  230. break
  231. case "band_card_pay":
  232. order.BandCardPay = desc
  233. break
  234. case "ali_pay":
  235. order.AliPay = desc
  236. break
  237. case "wechat_pay":
  238. order.WechatPay = desc
  239. break
  240. case "fa_piao_number":
  241. order.FaPiaoNumber = desc
  242. break
  243. case "fa_piao_code":
  244. order.FaPiaoCode = desc
  245. break
  246. }
  247. err := service.SaveHisOrder(&order)
  248. if err == nil {
  249. c.ServeSuccessJSON(map[string]interface{}{
  250. "msg": "修改成功",
  251. })
  252. return
  253. } else {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  255. return
  256. }
  257. }
  258. func (c *HisApiController) GetMonthHisPatient() {
  259. record_date := c.GetString("record_date")
  260. //order_status, _ := c.GetInt64("type")
  261. timeLayout := "2006-01-02"
  262. loc, _ := time.LoadLocation("Local")
  263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  264. if err != nil {
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. recordDateTime := theTime.Unix()
  269. adminInfo := c.GetAdminUserInfo()
  270. var tempPatients []service.NewTempPatients
  271. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  272. // 获取当前时间
  273. now := time.Now()
  274. // 获取本月的第一天
  275. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  276. // 获取下个月的第一天
  277. nextMonth := firstDay.AddDate(0, 1, 0)
  278. // 获取本月的最后一天
  279. lastDay := nextMonth.Add(-time.Nanosecond)
  280. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  281. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  282. var patients []service.NewTempPatients
  283. var patients_two []service.NewTempPatients
  284. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. patients_two = append(patients_two, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. //}
  294. }
  295. } else {
  296. for _, item := range tempPatients {
  297. //过滤掉没挂号的和没开处方的
  298. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  299. patients = append(patients, item)
  300. }
  301. ////过滤掉没挂号的
  302. //if len(item.HisPatient) > 0 {
  303. // patients_two = append(patients_two, item)
  304. //}
  305. }
  306. }
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "list": patients,
  309. "list_two": patients_two,
  310. "chargePatients": chargePatients,
  311. })
  312. }
  313. func (c *HisApiController) GetBatchSettleAccounts() {
  314. order_ids := c.GetString("order_ids")
  315. admin_user_id, _ := c.GetInt64("admin_user_id")
  316. adminUser := c.GetAdminUserInfo()
  317. orders := strings.Split(order_ids, ",")
  318. var newOrders []models.Orders
  319. for _, item := range orders {
  320. order, _ := service.GetHisOrderByIDTenOne(item)
  321. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  322. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  323. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  324. orderInfos = append(orderInfos, orderInfos_two...)
  325. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  326. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  327. var diagnosis_ids []string
  328. if his.ID > 0 {
  329. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  330. } else {
  331. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  332. }
  333. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  334. var dia_config []*models.HisXtDiagnoseConfig
  335. var name string
  336. for _, item := range diagnosis_ids {
  337. id, _ := strconv.ParseInt(item, 10, 64)
  338. diagnosisConfig, _ := service.FindDiagnoseById(id)
  339. dia_config = append(dia_config, diagnosisConfig)
  340. if len(name) == 0 {
  341. name = diagnosisConfig.ClassName
  342. } else {
  343. name = name + "," + diagnosisConfig.ClassName
  344. }
  345. }
  346. var bedCostTotal float64 = 0 //床位总费
  347. var bedCostSelfTotal float64 = 0 //床位自费
  348. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  349. var bedSelfTotal float64 = 0 //床位部分项目自费
  350. var bedInscpTotal float64 = 0 //床位部分项目自费
  351. var operationCostTotal float64 = 0 //手术费
  352. var operationCostSelfTotal float64 = 0 //手术费
  353. var operationCostPartSelfTotal float64 = 0 //手术费
  354. var operationSelfTotal float64 = 0 //床位部分项目自费
  355. var operationInscpTotal float64 = 0 //床位部分项目自费
  356. var otherCostTotal float64 = 0 //其他费用
  357. var otherCostSelfTotal float64 = 0 //其他费用
  358. var otherCostPartSelfTotal float64 = 0 //其他费用
  359. var otherSelfTotal float64 = 0 //床位部分项目自费
  360. var otherInscpTotal float64 = 0 //床位部分项目自费
  361. var materialCostTotal float64 = 0 //材料费
  362. var materialCostSelfTotal float64 = 0 //材料费
  363. var materialCostPartSelfTotal float64 = 0 //材料费
  364. var materialSelfTotal float64 = 0 //床位部分项目自费
  365. var materialInscpTotal float64 = 0 //床位部分项目自费
  366. var westernMedicineCostTotal float64 = 0 //西药费
  367. var westernMedicineCostSelfTotal float64 = 0 //西药费
  368. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  369. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  370. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  371. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  372. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  373. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  374. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  375. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  376. var checkCostTotal float64 = 0 //检查费
  377. var checkCostSelfTotal float64 = 0 //检查费
  378. var checkCostPartSelfTotal float64 = 0 //检查费
  379. var checkSelfTotal float64 = 0 //床位部分项目自费
  380. var checkInscpTotal float64 = 0 //床位部分项目自费
  381. var laboratoryCostTotal float64 = 0 //化验费
  382. var laboratoryCostSelfTotal float64 = 0 //化验费
  383. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  384. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  385. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  386. var treatCostTotal float64 = 0 //治疗费用
  387. var treatCostSelfTotal float64 = 0 //治疗费用
  388. var treatCostPartSelfTotal float64 = 0 //治疗费用
  389. var treatSelfTotal float64 = 0 //床位部分项目自费
  390. var treatInscpTotal float64 = 0 //床位部分项目自费
  391. decimal.DivisionPrecision = 2
  392. for _, item := range orderInfos {
  393. if item.MedChrgitmType == "01" { //床位费
  394. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  395. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  396. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  397. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  398. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  399. }
  400. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  401. if item.MedChrgitmType == "03" { //检查费
  402. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  403. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  404. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  405. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  406. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  407. }
  408. } else {
  409. if item.MedChrgitmType == "03" { //检查费
  410. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  411. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  412. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  413. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  414. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  415. }
  416. }
  417. if item.MedChrgitmType == "04" { //化验费
  418. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  419. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  420. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  421. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  422. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  423. }
  424. if item.MedChrgitmType == "05" { //治疗费
  425. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  426. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  427. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  428. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  429. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  430. }
  431. if item.MedChrgitmType == "06" { //手术费
  432. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  433. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  434. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  435. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  436. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  437. }
  438. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  439. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  440. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  441. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  442. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  443. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  444. }
  445. if item.MedChrgitmType == "09" { //西药费
  446. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  447. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  448. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  449. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  450. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  451. }
  452. if item.MedChrgitmType == "11" { //中成费
  453. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  454. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  455. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  456. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  457. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  458. }
  459. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  461. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  462. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  463. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  464. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  465. }
  466. }
  467. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  468. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  470. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  471. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  472. var doctor_name string
  473. if roles.ID == 0 {
  474. doctor_name = "管理员"
  475. } else {
  476. doctor_name = roles.UserName
  477. }
  478. yiliao_leibie := ""
  479. switch order.MedType {
  480. case "11":
  481. yiliao_leibie = "普通门诊"
  482. break
  483. case "12":
  484. yiliao_leibie = "门诊挂号"
  485. break
  486. case "13":
  487. yiliao_leibie = "急诊"
  488. break
  489. case "14":
  490. yiliao_leibie = "门诊特殊病"
  491. break
  492. case "15":
  493. yiliao_leibie = "门诊统筹"
  494. break
  495. case "16":
  496. yiliao_leibie = "门诊慢性病"
  497. break
  498. case "21":
  499. yiliao_leibie = "普通住院"
  500. break
  501. }
  502. var newOrder models.Orders
  503. newOrder.Diagnosis = name
  504. newOrder.OrderInfos = orderInfos
  505. newOrder.Number = order.MdtrtId
  506. newOrder.Date = order.SettleAccountsDate
  507. newOrder.ChargeAdmin = charge_admin
  508. newOrder.PrintorAdmin = printor_admin
  509. newOrder.Order = order
  510. newOrder.BedCostTotal = bedCostTotal
  511. newOrder.BedCostSelfTotal = bedCostSelfTotal
  512. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  513. newOrder.BedSelfTotal = bedSelfTotal
  514. newOrder.BedInscpTotal = bedInscpTotal
  515. newOrder.OperationCostTotal = operationCostTotal
  516. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  517. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  518. newOrder.OperationSelfTotal = operationSelfTotal
  519. newOrder.OperationInscpTotal = operationInscpTotal
  520. newOrder.OtherCostTotal = otherCostTotal
  521. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  522. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  523. newOrder.OtherSelfTotal = otherSelfTotal
  524. newOrder.OtherInscpTotal = otherInscpTotal
  525. newOrder.MaterialCostTotal = materialCostTotal
  526. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  527. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  528. newOrder.MaterialSelfTotal = materialSelfTotal
  529. newOrder.MaterialInscpTotal = materialInscpTotal
  530. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  531. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  532. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  533. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  534. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  535. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  536. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  537. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  538. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  539. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  540. newOrder.CheckCostTotal = checkCostTotal
  541. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  542. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  543. newOrder.CheckSelfTotal = checkSelfTotal
  544. newOrder.CheckInscpTotal = checkInscpTotal
  545. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  546. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  547. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  548. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  549. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  550. newOrder.TreatCostTotal = treatCostTotal
  551. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  552. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  553. newOrder.TreatSelfTotal = treatSelfTotal
  554. newOrder.TreatInscpTotal = treatInscpTotal
  555. newOrder.DoctorInfo = doctor_info
  556. newOrder.DoctorName = doctor_name
  557. newOrder.HealthCardNo = order.PsnNo
  558. newOrder.YiliaoLeibie = yiliao_leibie
  559. newOrder.Patient = patient
  560. newOrder.OrgName = miConfig.OrgName
  561. newOrder.OrgCode = miConfig.Code
  562. newOrder.OrderNumber = order.Number
  563. newOrder.HisPatient = his
  564. newOrder.DiaConfig = dia_config
  565. newOrders = append(newOrders, newOrder)
  566. }
  567. c.ServeSuccessJSON(map[string]interface{}{
  568. "orders": newOrders,
  569. })
  570. }
  571. func (c *HisApiController) GetTestOrder() {
  572. order_id, _ := c.GetInt64("order_id")
  573. admin_user_id, _ := c.GetInt64("admin_user_id")
  574. adminUser := c.GetAdminUserInfo()
  575. order, _ := service.GetHisOrderByID(order_id)
  576. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  577. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  578. orderInfos = append(orderInfos, orderInfos_two...)
  579. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  580. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  581. var dia_config []*models.HisXtDiagnoseConfig
  582. var name string
  583. var bedCostTotal float64 = 0 //床位总费
  584. var bedCostSelfTotal float64 = 0 //床位自费
  585. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  586. var bedSelfTotal float64 = 0 //床位部分项目自费
  587. var bedInscpTotal float64 = 0 //床位部分项目自费
  588. var operationCostTotal float64 = 0 //手术费
  589. var operationCostSelfTotal float64 = 0 //手术费
  590. var operationCostPartSelfTotal float64 = 0 //手术费
  591. var operationSelfTotal float64 = 0 //床位部分项目自费
  592. var operationInscpTotal float64 = 0 //床位部分项目自费
  593. var otherCostTotal float64 = 0 //其他费用
  594. var otherCostSelfTotal float64 = 0 //其他费用
  595. var otherCostPartSelfTotal float64 = 0 //其他费用
  596. var otherSelfTotal float64 = 0 //床位部分项目自费
  597. var otherInscpTotal float64 = 0 //床位部分项目自费
  598. var materialCostTotal float64 = 0 //材料费
  599. var materialCostSelfTotal float64 = 0 //材料费
  600. var materialCostPartSelfTotal float64 = 0 //材料费
  601. var materialSelfTotal float64 = 0 //床位部分项目自费
  602. var materialInscpTotal float64 = 0 //床位部分项目自费
  603. var westernMedicineCostTotal float64 = 0 //西药费
  604. var westernMedicineCostSelfTotal float64 = 0 //西药费
  605. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  606. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  607. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  608. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  609. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  610. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  611. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  612. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  613. var checkCostTotal float64 = 0 //检查费
  614. var checkCostSelfTotal float64 = 0 //检查费
  615. var checkCostPartSelfTotal float64 = 0 //检查费
  616. var checkSelfTotal float64 = 0 //床位部分项目自费
  617. var checkInscpTotal float64 = 0 //床位部分项目自费
  618. var laboratoryCostTotal float64 = 0 //化验费
  619. var laboratoryCostSelfTotal float64 = 0 //化验费
  620. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  621. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  622. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  623. var treatCostTotal float64 = 0 //治疗费用
  624. var treatCostSelfTotal float64 = 0 //治疗费用
  625. var treatCostPartSelfTotal float64 = 0 //治疗费用
  626. var treatSelfTotal float64 = 0 //床位部分项目自费
  627. var treatInscpTotal float64 = 0 //床位部分项目自费
  628. decimal.DivisionPrecision = 2
  629. for _, item := range orderInfos {
  630. if item.MedChrgitmType == "01" { //床位费
  631. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  632. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  633. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  634. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  635. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  636. }
  637. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  638. if item.MedChrgitmType == "03" { //检查费
  639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  640. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  641. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  642. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  643. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  644. }
  645. } else {
  646. if item.MedChrgitmType == "03" { //检查费
  647. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  648. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  649. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  650. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  651. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  652. }
  653. }
  654. if item.MedChrgitmType == "04" { //化验费
  655. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  656. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  657. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  658. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  659. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  660. }
  661. if item.MedChrgitmType == "05" { //治疗费
  662. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  663. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  664. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  665. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  666. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  667. }
  668. if item.MedChrgitmType == "06" { //手术费
  669. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  670. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  671. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  672. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  673. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  674. }
  675. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  676. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  677. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  678. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  679. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  680. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  681. }
  682. if item.MedChrgitmType == "09" { //西药费
  683. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  684. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  685. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  686. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  687. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  688. }
  689. if item.MedChrgitmType == "11" { //中成费
  690. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  691. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  692. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  693. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  694. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  695. }
  696. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  698. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  699. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  700. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  701. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  702. }
  703. }
  704. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  705. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  707. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  708. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  709. var doctor_name string
  710. if roles.ID == 0 {
  711. doctor_name = "管理员"
  712. } else {
  713. doctor_name = roles.UserName
  714. }
  715. yiliao_leibie := ""
  716. switch order.MedType {
  717. case "11":
  718. yiliao_leibie = "普通门诊"
  719. break
  720. case "12":
  721. yiliao_leibie = "门诊挂号"
  722. break
  723. case "13":
  724. yiliao_leibie = "急诊"
  725. break
  726. case "14":
  727. yiliao_leibie = "门诊特殊病"
  728. break
  729. case "15":
  730. yiliao_leibie = "门诊统筹"
  731. break
  732. case "16":
  733. yiliao_leibie = "门诊慢性病"
  734. break
  735. case "21":
  736. yiliao_leibie = "普通住院"
  737. break
  738. }
  739. c.ServeSuccessJSON(map[string]interface{}{
  740. "diagnosis": name,
  741. "order_infos": orderInfos,
  742. "number": order.MdtrtId,
  743. "date": order.SettleAccountsDate,
  744. "charge_admin": charge_admin,
  745. "printor_admin": printor_admin,
  746. "info": order,
  747. "order": order,
  748. "bedCostTotal": bedCostTotal,
  749. "bedCostSelfTotal": bedCostSelfTotal,
  750. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  751. "bedSelfTotal": bedSelfTotal,
  752. "bedInscpTotal": bedInscpTotal,
  753. "operationCostTotal": operationCostTotal,
  754. "operationCostSelfTotal": operationCostSelfTotal,
  755. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  756. "operationSelfTotal": operationSelfTotal,
  757. "operationInscpTotal": operationInscpTotal,
  758. "otherCostTotal": otherCostTotal,
  759. "otherCostSelfTotal": otherCostSelfTotal,
  760. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  761. "otherSelfTotal": otherSelfTotal,
  762. "otherInscpTotal": otherInscpTotal,
  763. "materialCostTotal": materialCostTotal,
  764. "materialCostSelfTotal": materialCostSelfTotal,
  765. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  766. "materialSelfTotal": materialSelfTotal,
  767. "materialInscpTotal": materialInscpTotal,
  768. "westernMedicineCostTotal": westernMedicineCostTotal,
  769. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  770. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  771. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  772. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  773. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  774. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  775. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  776. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  777. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  778. "checkCostTotal": checkCostTotal,
  779. "checkCostSelfTotal": checkCostSelfTotal,
  780. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  781. "checkSelfTotal": checkSelfTotal,
  782. "checkInscpTotal": checkInscpTotal,
  783. "laboratoryCostTotal": laboratoryCostTotal,
  784. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  785. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  786. "laboratorySelfTotal": laboratorySelfTotal,
  787. "laboratoryInscpTotal": laboratoryInscpTotal,
  788. "treatCostTotal": treatCostTotal,
  789. "treatCostSelfTotal": treatCostSelfTotal,
  790. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  791. "treatSelfTotal": treatSelfTotal,
  792. "treatInscpTotal": treatInscpTotal,
  793. "doctor_info": doctor_info,
  794. "doctor_name": doctor_name,
  795. "health_card_no": order.PsnNo,
  796. "yiliao_leibie": yiliao_leibie,
  797. "patient": patient,
  798. "org_name": miConfig.OrgName,
  799. "org_code": miConfig.Code,
  800. "order_number": order.Number,
  801. "his_hospital": his_hospital,
  802. "dia_config": dia_config,
  803. })
  804. }
  805. type CustomFundPay struct {
  806. FundPayType string `json:"fund_pay_type"`
  807. FundPayamt float64 `json:"fund_payamt"`
  808. InscpScpAmt float64 `json:"inscp_scp_amt"`
  809. }
  810. func (c *PublicApiController) GetBaiLinExportData() {
  811. data := service.GetBaiLinOrderData()
  812. fmt.Println(len(data))
  813. var new_data []*models.NewCustomHisOrder
  814. for _, item := range data {
  815. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  816. new_data = append(new_data, item)
  817. }
  818. }
  819. fmt.Println(len(new_data))
  820. c.ServeSuccessJSON(map[string]interface{}{
  821. "list": new_data,
  822. })
  823. }
  824. func (c *HisApiController) GetHisUnChargePatientList() {
  825. record_date := c.GetString("record_date")
  826. sch_type, _ := c.GetInt64("sch_type")
  827. timeLayout := "2006-01-02"
  828. loc, _ := time.LoadLocation("Local")
  829. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  830. if err != nil {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. recordDateTime := theTime.Unix()
  835. adminInfo := c.GetAdminUserInfo()
  836. var tempPatients []*service.NewTempPatients
  837. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  838. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  839. var patients []*service.NewTempPatients
  840. var patients_two []*service.NewTempPatients
  841. for _, item := range tempPatients {
  842. //过滤掉没挂号的和没开处方的
  843. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  844. patients = append(patients, item)
  845. }
  846. //过滤掉没挂号的
  847. if len(item.HisPatient) > 0 {
  848. patients_two = append(patients_two, item)
  849. }
  850. }
  851. c.ServeSuccessJSON(map[string]interface{}{
  852. "list": patients,
  853. "list_two": patients_two,
  854. })
  855. }
  856. func (c *HisApiController) GetPrivateExpensesOrder() {
  857. //id, _ := c.GetInt64("id")
  858. //record_time := c.GetString("record_time")
  859. order_id, _ := c.GetInt64("order_id")
  860. admin_user_id, _ := c.GetInt64("admin_user_id")
  861. //timeLayout := "2006-01-02"
  862. //loc, _ := time.LoadLocation("Local")
  863. //
  864. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  865. //if err != nil {
  866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. // return
  868. //}
  869. //recordDateTime := theTime.Unix()
  870. adminUser := c.GetAdminUserInfo()
  871. order, _ := service.GetHisOrderByID(order_id)
  872. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  873. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  874. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  875. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  876. //var config []*models.HisXtDiagnoseConfig
  877. var name string
  878. if order.PType == 1 {
  879. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  880. for _, item := range diagnosis_ids {
  881. id, _ := strconv.ParseInt(item, 10, 64)
  882. diagnosisConfig, _ := service.FindDiagnoseById(id)
  883. if len(name) == 0 {
  884. name = diagnosisConfig.ClassName
  885. } else {
  886. name = name + "," + diagnosisConfig.ClassName
  887. }
  888. }
  889. } else {
  890. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  891. for _, item := range diagnosis_ids {
  892. id, _ := strconv.ParseInt(item, 10, 64)
  893. diagnosisConfig, _ := service.FindDiagnoseById(id)
  894. if len(name) == 0 {
  895. name = diagnosisConfig.ClassName
  896. } else {
  897. name = name + "," + diagnosisConfig.ClassName
  898. }
  899. }
  900. }
  901. var bedCostTotal float64 = 0 //床位总费
  902. var bedCostSelfTotal float64 = 0 //床位自费
  903. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  904. var bedSelfTotal float64 = 0 //床位部分项目自费
  905. var bedInscpTotal float64 = 0 //床位部分项目自费
  906. var operationCostTotal float64 = 0 //手术费
  907. var operationCostSelfTotal float64 = 0 //手术费
  908. var operationCostPartSelfTotal float64 = 0 //手术费
  909. var operationSelfTotal float64 = 0 //床位部分项目自费
  910. var operationInscpTotal float64 = 0 //床位部分项目自费
  911. var otherCostTotal float64 = 0 //其他费用
  912. //var otherCostSelfTotal float64 = 0 //其他费用
  913. var otherCostPartSelfTotal float64 = 0 //其他费用
  914. //var otherSelfTotal float64 = 0 //床位部分项目自费
  915. //var otherInscpTotal float64 = 0 //床位部分项目自费
  916. var materialCostTotal float64 = 0 //材料费
  917. var materialCostSelfTotal float64 = 0 //材料费
  918. var materialCostPartSelfTotal float64 = 0 //材料费
  919. var materialSelfTotal float64 = 0 //床位部分项目自费
  920. var materialInscpTotal float64 = 0 //床位部分项目自费
  921. var westernMedicineCostTotal float64 = 0 //西药费
  922. var westernMedicineCostSelfTotal float64 = 0 //西药费
  923. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  924. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  925. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  926. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  927. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  928. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  929. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  930. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  931. var checkCostTotal float64 = 0 //检查费
  932. var checkCostSelfTotal float64 = 0 //检查费
  933. var checkCostPartSelfTotal float64 = 0 //检查费
  934. var checkSelfTotal float64 = 0 //床位部分项目自费
  935. var checkInscpTotal float64 = 0 //床位部分项目自费
  936. var laboratoryCostTotal float64 = 0 //化验费
  937. var laboratoryCostSelfTotal float64 = 0 //化验费
  938. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  939. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  940. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  941. var treatCostTotal float64 = 0 //治疗费用
  942. var treatCostSelfTotal float64 = 0 //治疗费用
  943. var treatCostPartSelfTotal float64 = 0 //治疗费用
  944. var treatSelfTotal float64 = 0 //床位部分项目自费
  945. var treatInscpTotal float64 = 0 //床位部分项目自费
  946. var zhenChaCostTotal float64 = 0 //其他费用
  947. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  948. decimal.DivisionPrecision = 2
  949. for _, item := range orderInfos {
  950. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  951. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  952. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  953. item.MedChrgitmType = "09"
  954. }
  955. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  956. if item.HisPrescriptionProject.Type == 2 {
  957. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  958. fmt.Println("CostClassify")
  959. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  960. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  961. case 0:
  962. item.MedChrgitmType = "0"
  963. break
  964. case 1:
  965. item.MedChrgitmType = "14"
  966. break
  967. case 2:
  968. item.MedChrgitmType = "05"
  969. break
  970. case 3:
  971. item.MedChrgitmType = "03"
  972. break
  973. case 4:
  974. item.MedChrgitmType = "03"
  975. break
  976. case 5:
  977. item.MedChrgitmType = "08"
  978. break
  979. case 6:
  980. item.MedChrgitmType = "14"
  981. break
  982. case 7:
  983. item.MedChrgitmType = "14"
  984. break
  985. case 8:
  986. item.MedChrgitmType = "03"
  987. break
  988. case 9:
  989. item.MedChrgitmType = "14"
  990. break
  991. case 10:
  992. item.MedChrgitmType = "14"
  993. break
  994. case 11:
  995. item.MedChrgitmType = "06"
  996. break
  997. case 12:
  998. item.MedChrgitmType = "12"
  999. break
  1000. case 13:
  1001. item.MedChrgitmType = "01"
  1002. break
  1003. case 14:
  1004. item.MedChrgitmType = "04"
  1005. break
  1006. case 15:
  1007. item.MedChrgitmType = "14"
  1008. break
  1009. }
  1010. } else {
  1011. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1012. case 1:
  1013. item.MedChrgitmType = "14"
  1014. break
  1015. case 2:
  1016. item.MedChrgitmType = "05"
  1017. break
  1018. case 3:
  1019. item.MedChrgitmType = "04"
  1020. break
  1021. case 4:
  1022. item.MedChrgitmType = "14"
  1023. break
  1024. case 5:
  1025. item.MedChrgitmType = "08"
  1026. break
  1027. case 6:
  1028. item.MedChrgitmType = "14"
  1029. break
  1030. case 7:
  1031. item.MedChrgitmType = "14"
  1032. break
  1033. case 8:
  1034. item.MedChrgitmType = "03"
  1035. break
  1036. case 9:
  1037. item.MedChrgitmType = "14"
  1038. break
  1039. default:
  1040. item.MedChrgitmType = "14"
  1041. break
  1042. }
  1043. }
  1044. } else if item.HisPrescriptionProject.Type == 3 {
  1045. item.MedChrgitmType = "08"
  1046. }
  1047. }
  1048. }
  1049. }
  1050. if order.IsMedicineInsurance != 1 {
  1051. order.PsnCashPay = order.MedfeeSumamt
  1052. }
  1053. for _, item := range orderInfos {
  1054. if item.MedChrgitmType == "01" { //床位费
  1055. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1059. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "02" { //诊察费
  1062. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //zhenChaCostSelfTotal = zhenChaCostTotal
  1064. }
  1065. if item.MedChrgitmType == "03" { //检查费
  1066. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1070. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1071. }
  1072. if item.MedChrgitmType == "02" { //检查费
  1073. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1074. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1075. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1076. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1077. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1078. }
  1079. if item.MedChrgitmType == "04" { //化验费
  1080. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1081. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1082. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1083. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1084. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1085. }
  1086. if item.MedChrgitmType == "05" { //治疗费
  1087. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1088. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1089. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1090. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1091. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1092. }
  1093. if item.MedChrgitmType == "06" { //手术费
  1094. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1095. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1096. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1097. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1098. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1099. }
  1100. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1101. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1102. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1103. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1104. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1105. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1106. }
  1107. if item.MedChrgitmType == "09" { //西药费
  1108. fmt.Println("FulamtOwnpayAmt")
  1109. fmt.Println(item.FulamtOwnpayAmt)
  1110. fmt.Println("FulamtOwnpayAmt")
  1111. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1112. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1113. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1114. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1115. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1116. }
  1117. if item.MedChrgitmType == "11" { //中成费
  1118. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1119. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1120. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1121. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1122. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1123. }
  1124. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1125. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1126. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1127. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1128. }
  1129. }
  1130. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1131. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1132. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1133. var dia_config []*models.HisXtDiagnoseConfig
  1134. var diagnosis_ids []string
  1135. if his.ID > 0 {
  1136. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1137. } else {
  1138. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1139. }
  1140. for _, item := range diagnosis_ids {
  1141. id, _ := strconv.ParseInt(item, 10, 64)
  1142. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1143. dia_config = append(dia_config, diagnosisConfig)
  1144. }
  1145. var rf []CustomFundPay
  1146. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1147. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "patient": patient,
  1150. "order_infos": orderInfos,
  1151. "diagnosis": name,
  1152. "bedCostTotal": bedCostTotal,
  1153. "bedCostSelfTotal": bedCostSelfTotal,
  1154. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1155. "bedSelfTotal": bedSelfTotal,
  1156. "bedInscpTotal": bedInscpTotal,
  1157. "operationCostTotal": operationCostTotal,
  1158. "operationCostSelfTotal": operationCostSelfTotal,
  1159. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1160. "operationInscpTotal": operationInscpTotal,
  1161. "operationSelfTotal": operationSelfTotal,
  1162. "otherCostTotal": otherCostTotal,
  1163. //"otherCostSelfTotal": otherCostSelfTotal,
  1164. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1165. "materialCostTotal": materialCostTotal,
  1166. "materialCostSelfTotal": materialCostSelfTotal,
  1167. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1168. "materialSelfTotal": materialSelfTotal,
  1169. "materialInscpTotal": materialInscpTotal,
  1170. "westernMedicineCostTotal": westernMedicineCostTotal,
  1171. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1172. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1173. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1174. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1175. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1176. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1177. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1178. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1179. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1180. "checkCostTotal": checkCostTotal,
  1181. "checkCostSelfTotal": checkCostSelfTotal,
  1182. "checkSelfTotal": checkSelfTotal,
  1183. "checkInscpTotal": checkInscpTotal,
  1184. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1185. "zhenChaCostTotal": zhenChaCostTotal,
  1186. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1187. "laboratoryCostTotal": laboratoryCostTotal,
  1188. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1189. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1190. "laboratorySelfTotal": laboratorySelfTotal,
  1191. "laboratoryInscpTotal": laboratoryInscpTotal,
  1192. "treatCostTotal": treatCostTotal,
  1193. "treatCostSelfTotal": treatCostSelfTotal,
  1194. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1195. "treatSelfTotal": treatSelfTotal,
  1196. "treatInscpTotal": treatInscpTotal,
  1197. "charge_admin": charge_admin,
  1198. "printor_admin": printor_admin,
  1199. "org_name": org.OrgName,
  1200. "org_code": miConfig.Code,
  1201. "name": patient.Name,
  1202. "number": order.MdtrtId,
  1203. "date": order.SettleAccountsDate,
  1204. "info": order,
  1205. "new_order": order,
  1206. "his_hospital": his_hospital,
  1207. "his": his,
  1208. "funds": rf,
  1209. "dia_config": dia_config,
  1210. })
  1211. }
  1212. func (c *HisApiController) RefudDetail() {
  1213. order_id, _ := c.GetInt64("order_id")
  1214. order, _ := service.GetHisOrderByID(order_id)
  1215. adminUser := c.GetAdminUserInfo()
  1216. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1217. c.ServeSuccessJSON(map[string]interface{}{
  1218. "msg": "撤销成功",
  1219. })
  1220. }
  1221. func (c *HisApiController) Sscard() {
  1222. //r := CardInit()
  1223. //if r == 0 {
  1224. // GetBaseInfo()
  1225. //}
  1226. //c.ServeSuccessJSON(map[string]interface{}{
  1227. // "list": "11",
  1228. //})
  1229. }
  1230. func GetBaseInfo() error {
  1231. //handle := syscall.MustLoadDLL("SSCard.dll")
  1232. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1233. //
  1234. //str := make([]byte, 256)
  1235. //str1 := make([]byte, 256)
  1236. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1237. //if ferr != nil {
  1238. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1239. // return ferr
  1240. //}
  1241. //
  1242. //fmt.Println(string(str))
  1243. //
  1244. //fmt.Println(r)
  1245. return nil
  1246. }
  1247. func CardInit() int {
  1248. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1249. //add := DllTestDef.MustFindProc("Init")
  1250. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1251. //if err != nil {
  1252. // fmt.Println("SSCard的运算结果为:", ret)
  1253. //}
  1254. //result := int(ret)
  1255. return 0
  1256. }
  1257. func IntPtr(n int) uintptr {
  1258. return uintptr(n)
  1259. }
  1260. func StrPtr(s string) uintptr {
  1261. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1262. }
  1263. func (c *HisApiController) GetHisPatientList() {
  1264. record_date := c.GetString("record_date")
  1265. sch_type, _ := c.GetInt64("sch_type")
  1266. patient_type, _ := c.GetInt64("patient_type")
  1267. fmt.Println("patient_type")
  1268. fmt.Println(patient_type)
  1269. timeLayout := "2006-01-02"
  1270. loc, _ := time.LoadLocation("Local")
  1271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1272. if err != nil {
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1274. return
  1275. }
  1276. recordDateTime := theTime.Unix()
  1277. adminInfo := c.GetAdminUserInfo()
  1278. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1279. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1280. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1281. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1282. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1283. fmt.Println(patients_three)
  1284. //获取当前用户的信息
  1285. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1286. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1287. //获取所有科室信息
  1288. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1289. //var aa []service.PatientThree
  1290. noElementsSlice := make([]service.PatientThree, 0)
  1291. c.ServeSuccessJSON(map[string]interface{}{
  1292. "list": patients_three,
  1293. "list_two": patients_four,
  1294. "list_three": noElementsSlice,
  1295. "info": adminUserInfo,
  1296. "doctors": doctors,
  1297. "department": department,
  1298. })
  1299. } else {
  1300. //获取当前用户的信息
  1301. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1302. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1303. //获取所有科室信息
  1304. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1305. //var aa []service.PatientThree
  1306. noElementsSlice := make([]service.PatientThree, 0)
  1307. c.ServeSuccessJSON(map[string]interface{}{
  1308. "list": patients,
  1309. "list_two": patients_two,
  1310. "list_three": noElementsSlice,
  1311. "info": adminUserInfo,
  1312. "doctors": doctors,
  1313. "department": department,
  1314. })
  1315. }
  1316. }
  1317. type CustomTemplate struct {
  1318. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1319. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1320. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1321. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1322. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1323. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1324. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1325. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1326. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1327. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1328. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1329. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1330. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1331. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1332. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1333. }
  1334. func (c *HisApiController) GetHisPatientInfo() {
  1335. patient_id, _ := c.GetInt64("patient_id")
  1336. his_patient_id, _ := c.GetInt64("his_patient_id")
  1337. record_date := c.GetString("record_date")
  1338. number := c.GetString("number")
  1339. //start_time := c.GetString("start_time")
  1340. //end_time := c.GetString("end_time")
  1341. p_type, _ := c.GetInt64("p_type")
  1342. timeLayout := "2006-01-02"
  1343. loc, _ := time.LoadLocation("Local")
  1344. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1345. if err != nil {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1347. return
  1348. }
  1349. recordDateTime := theTime.Unix()
  1350. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1351. //if err != nil {
  1352. //
  1353. //}
  1354. //startRecordDateTime := startTime.Unix()
  1355. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1356. //if err != nil {
  1357. //
  1358. //}
  1359. //endRecordDateTime := endTime.Unix()
  1360. admin := c.GetAdminUserInfo()
  1361. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1362. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1363. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1364. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1365. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1366. var prescriptions []*models.HisPrescription
  1367. var last_prescriptions []*models.HisPrescription
  1368. var sch_prescriptions []CustomTemplate
  1369. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1370. if p_type == 1 { //住院
  1371. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1372. for _, item := range prescriptions {
  1373. for _, subItem := range item.HisDoctorAdviceInfo {
  1374. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1375. if info.RetailPrice > 0 {
  1376. subItem.Drug.MinPrice = info.RetailPrice
  1377. }
  1378. }
  1379. }
  1380. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1381. } else { //门诊
  1382. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1383. for _, item := range prescriptions {
  1384. for _, subItem := range item.HisDoctorAdviceInfo {
  1385. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1386. if info.RetailPrice > 0 {
  1387. subItem.Drug.MinPrice = info.RetailPrice
  1388. }
  1389. }
  1390. }
  1391. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1392. }
  1393. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1394. if sch.ID > 0 {
  1395. var week string
  1396. t := time.Now()
  1397. switch t.Weekday().String() {
  1398. case "Monday":
  1399. week = "周一"
  1400. break
  1401. case "Tuesday":
  1402. week = "周二"
  1403. break
  1404. case "Wednesday":
  1405. week = "周三"
  1406. break
  1407. case "Thursday":
  1408. week = "周四"
  1409. break
  1410. case "Friday":
  1411. week = "周五"
  1412. break
  1413. case "Saturday":
  1414. week = "周六"
  1415. break
  1416. case "Sunday":
  1417. week = "周日"
  1418. break
  1419. }
  1420. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1421. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1422. //根据推送频率组装新的数组
  1423. for _, item := range temp_sch_prescriptions {
  1424. var cus CustomTemplate
  1425. cus.ID = item.ID
  1426. cus.UserOrgId = item.UserOrgId
  1427. cus.PatientId = item.PatientId
  1428. cus.MedType = item.MedType
  1429. cus.RecordDate = item.RecordDate
  1430. cus.Type = item.Type
  1431. cus.PType = item.PType
  1432. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1433. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1434. if subItem.FrequencyType == 1 { //每次必推
  1435. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1436. }
  1437. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1438. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1439. }
  1440. if subItem.FrequencyType == 2 { //按照天数频率
  1441. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1442. now := p.Unix()
  1443. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1444. dayStr2 := "-" + dayStr
  1445. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1446. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1447. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1448. if len(advices) == 0 {
  1449. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1450. }
  1451. }
  1452. }
  1453. }
  1454. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1455. if subItem.Type == 2 {
  1456. if subItem.XtHisProject.MedicalStatus != 1 {
  1457. if subItem.FrequencyType == 1 {
  1458. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1459. }
  1460. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1461. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1462. }
  1463. if subItem.FrequencyType == 2 {
  1464. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1465. now := p.Unix()
  1466. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1467. dayStr2 := "-" + dayStr
  1468. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1469. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1470. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1471. if len(projects) == 0 {
  1472. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1473. }
  1474. }
  1475. }
  1476. } else if subItem.Type == 3 {
  1477. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1478. if subItem.FrequencyType == 1 {
  1479. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1480. }
  1481. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1482. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1483. }
  1484. if subItem.FrequencyType == 2 {
  1485. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1486. now := p.Unix()
  1487. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1488. dayStr2 := "-" + dayStr
  1489. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1490. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1491. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1492. if len(projects) == 0 {
  1493. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1494. }
  1495. }
  1496. }
  1497. }
  1498. }
  1499. sch_prescriptions = append(sch_prescriptions, cus)
  1500. }
  1501. for _, item := range sch_prescriptions {
  1502. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1503. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1504. }
  1505. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1506. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1507. }
  1508. }
  1509. }
  1510. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1511. if config.ID > 0 && config.IsOpen == 1 {
  1512. for _, item := range sch_prescriptions {
  1513. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1514. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1515. if info.RetailPrice > 0 {
  1516. subItem.Drug.MinPrice = info.RetailPrice
  1517. if admin.CurrentOrgId != 10598 {
  1518. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1519. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1520. }
  1521. }
  1522. }
  1523. }
  1524. }
  1525. if config.ID > 0 && config.IsOpen == 1 {
  1526. for _, item := range sch_prescriptions {
  1527. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1528. if subItem.Type == 3 {
  1529. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1530. if info.Price > 0 {
  1531. subItem.GoodInfo.PackingPrice = info.Price
  1532. if admin.CurrentOrgId != 10598 {
  1533. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1534. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1535. }
  1536. }
  1537. }
  1538. }
  1539. }
  1540. }
  1541. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1542. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1543. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1544. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1545. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1546. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1547. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1548. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1551. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1552. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1553. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1554. fmt.Println(prescriptions)
  1555. fmt.Println(sch_prescriptions)
  1556. fmt.Println(last_prescriptions)
  1557. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1558. if len(sch_prescriptions) > 0 {
  1559. var index = 0
  1560. for subindex, item := range sch_prescriptions {
  1561. if item.Type == 2 {
  1562. index = subindex
  1563. }
  1564. }
  1565. fmt.Println(index)
  1566. fmt.Println(len(sch_prescriptions))
  1567. if index >= 0 && index < len(sch_prescriptions) {
  1568. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1569. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1570. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1571. if one.ID > 0 {
  1572. var hpt models.HisPrescriptionProjectTemplate
  1573. hpt.Type = 3
  1574. hpt.ID = 0
  1575. hpt.PatientId = sch_prescriptions[index].PatientId
  1576. hpt.Status = 1
  1577. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1578. hpt.Mtime = time.Now().Unix()
  1579. hpt.Ctime = time.Now().Unix()
  1580. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1581. hpt.Count = "1"
  1582. hpt.Price = one.RetailPrice
  1583. hpt.ProjectId = one.ID
  1584. hpt.FeedetlSn = ""
  1585. hpt.PrescriptionId = sch_prescriptions[index].ID
  1586. hpt.Unit = one.PackingUnit
  1587. hpt.Day = "1"
  1588. hpt.SingleDose = "1"
  1589. hpt.GoodInfo = one
  1590. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1591. }
  1592. if two.ID > 0 {
  1593. var hpt models.HisPrescriptionProjectTemplate
  1594. hpt.Type = 3
  1595. hpt.ID = 0
  1596. hpt.PatientId = sch_prescriptions[index].PatientId
  1597. hpt.Status = 1
  1598. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1599. hpt.Mtime = time.Now().Unix()
  1600. hpt.Ctime = time.Now().Unix()
  1601. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1602. hpt.Count = "1"
  1603. hpt.Price = two.RetailPrice
  1604. hpt.ProjectId = two.ID
  1605. hpt.FeedetlSn = ""
  1606. hpt.PrescriptionId = sch_prescriptions[index].ID
  1607. hpt.Unit = two.PackingUnit
  1608. hpt.Day = "1"
  1609. hpt.SingleDose = "1"
  1610. hpt.GoodInfo = two
  1611. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1612. }
  1613. //if three.ID > 0 {
  1614. // var hpt models.HisPrescriptionProjectTemplate
  1615. // hpt.Type = 3
  1616. // hpt.ID = 0
  1617. // hpt.PatientId = sch_prescriptions[index].PatientId
  1618. // hpt.Status = 1
  1619. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1620. // hpt.Mtime = time.Now().Unix()
  1621. // hpt.Ctime = time.Now().Unix()
  1622. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1623. // hpt.Count = "1"
  1624. // hpt.Price = three.RetailPrice
  1625. // hpt.ProjectId = three.ID
  1626. // hpt.FeedetlSn = ""
  1627. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1628. // hpt.Unit = three.PackingUnit
  1629. // hpt.Day = "1"
  1630. // hpt.SingleDose = "1"
  1631. // hpt.GoodInfo = three
  1632. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1633. //}
  1634. fmt.Println(sch_prescriptions)
  1635. }
  1636. } else {
  1637. if len(last_prescriptions) > 0 {
  1638. var index = 0
  1639. for subindex, item := range last_prescriptions {
  1640. if item.Type == 2 {
  1641. index = subindex
  1642. }
  1643. }
  1644. if index >= 0 && index < len(last_prescriptions) {
  1645. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1646. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1647. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1648. if one.ID > 0 {
  1649. var hpt models.HisPrescriptionProject
  1650. hpt.Type = 3
  1651. hpt.ID = 0
  1652. hpt.PatientId = last_prescriptions[index].PatientId
  1653. hpt.Status = 1
  1654. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1655. hpt.Mtime = time.Now().Unix()
  1656. hpt.Ctime = time.Now().Unix()
  1657. hpt.RecordDate = last_prescriptions[index].RecordDate
  1658. hpt.Count = "1"
  1659. hpt.Price = one.RetailPrice
  1660. hpt.ProjectId = one.ID
  1661. hpt.FeedetlSn = ""
  1662. hpt.PrescriptionId = last_prescriptions[index].ID
  1663. hpt.Unit = one.PackingUnit
  1664. hpt.Day = "1"
  1665. hpt.SingleDose = "1"
  1666. hpt.GoodInfo = one
  1667. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1668. }
  1669. if two.ID > 0 {
  1670. var hpt models.HisPrescriptionProject
  1671. hpt.Type = 3
  1672. hpt.ID = 0
  1673. hpt.PatientId = last_prescriptions[index].PatientId
  1674. hpt.Status = 1
  1675. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1676. hpt.Mtime = time.Now().Unix()
  1677. hpt.Ctime = time.Now().Unix()
  1678. hpt.RecordDate = last_prescriptions[index].RecordDate
  1679. hpt.Count = "1"
  1680. hpt.Price = two.RetailPrice
  1681. hpt.ProjectId = two.ID
  1682. hpt.FeedetlSn = ""
  1683. hpt.PrescriptionId = last_prescriptions[index].ID
  1684. hpt.Unit = two.PackingUnit
  1685. hpt.Day = "1"
  1686. hpt.SingleDose = "1"
  1687. hpt.GoodInfo = two
  1688. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1689. }
  1690. //if three.ID > 0 {
  1691. // var hpt models.HisPrescriptionProject
  1692. // hpt.Type = 3
  1693. // hpt.ID = 0
  1694. // hpt.PatientId = last_prescriptions[index].PatientId
  1695. // hpt.Status = 1
  1696. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1697. // hpt.Mtime = time.Now().Unix()
  1698. // hpt.Ctime = time.Now().Unix()
  1699. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1700. // hpt.Count = "1"
  1701. // hpt.Price = three.RetailPrice
  1702. // hpt.ProjectId = three.ID
  1703. // hpt.FeedetlSn = ""
  1704. // hpt.PrescriptionId = last_prescriptions[index].ID
  1705. // hpt.Unit = three.PackingUnit
  1706. // hpt.Day = "1"
  1707. // hpt.SingleDose = "1"
  1708. // hpt.GoodInfo = three
  1709. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1710. //}
  1711. }
  1712. }
  1713. }
  1714. }
  1715. c.ServeSuccessJSON(map[string]interface{}{
  1716. "his_info": his_patient_info,
  1717. "xt_info": xt_patient_info,
  1718. "prescription": prescriptions,
  1719. "case_history": case_history,
  1720. "info": patientPrescriptionInfo,
  1721. //"month_prescriptions": monthPrescriptions,
  1722. "order": order,
  1723. "doctors": doctors,
  1724. "department": department,
  1725. "sch_prescriptions": sch_prescriptions,
  1726. "last_prescriptions": last_prescriptions,
  1727. "schedule": sch,
  1728. "count": count,
  1729. "drugStockConfig": drugStockConfig,
  1730. "last_info": lastPatientPrescriptionInfo,
  1731. "befor": beforThrity,
  1732. "LastCaseHistory": LastCaseHistory,
  1733. "prescriptionInfo": prescriptionInfo,
  1734. })
  1735. return
  1736. }
  1737. func (c *HisApiController) GetHisPrescriptionConfig() {
  1738. adminInfo := c.GetAdminUserInfo()
  1739. //获取医嘱模版
  1740. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1741. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1742. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1743. //获取所有基础药
  1744. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1745. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1746. if config.ID > 0 && config.IsOpen == 1 {
  1747. for _, item := range drugs {
  1748. var index = 0
  1749. for _, subItem := range item.OtherDrugWarehouseInfo {
  1750. if index == 0 {
  1751. index = index + 1
  1752. if subItem.RetailPrice > 0 {
  1753. item.MinPrice = subItem.RetailPrice
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1760. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1761. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1762. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1763. //获取所有科室信息
  1764. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1765. //获取诊断信息
  1766. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1767. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1768. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1769. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1770. //获取是否开启保存耗材出库的开关
  1771. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1772. c.ServeSuccessJSON(map[string]interface{}{
  1773. "drugs": drugs,
  1774. "advices_template": advices,
  1775. "drugways": drugways,
  1776. "efs": efs,
  1777. "doctors": doctors,
  1778. "department": department,
  1779. "sick": sick,
  1780. "additions": additions,
  1781. "diagnose": diagnose,
  1782. "manufacturers": manufacturers,
  1783. "goodOutOpen": goodOutOpen,
  1784. "patientDiagnose": patientDiagnose,
  1785. })
  1786. }
  1787. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1788. //获取所有基础药
  1789. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1790. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1791. if config.ID > 0 && config.IsOpen == 1 {
  1792. for _, item := range drugs {
  1793. var index = 0
  1794. for _, subItem := range item.OtherDrugWarehouseInfo {
  1795. if index == 0 {
  1796. index = index + 1
  1797. if subItem.RetailPrice > 0 {
  1798. item.MinPrice = subItem.RetailPrice
  1799. }
  1800. }
  1801. }
  1802. }
  1803. }
  1804. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1805. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1806. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1807. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1808. //获取所有科室信息
  1809. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1810. //获取诊断信息
  1811. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1812. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1813. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1814. //获取是否开启保存耗材出库的开关
  1815. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1816. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1817. c.ServeSuccessJSON(map[string]interface{}{
  1818. "drugs": drugs,
  1819. "advices_template": advices,
  1820. "drugways": drugways,
  1821. "efs": efs,
  1822. "doctors": doctors,
  1823. "department": department,
  1824. "sick": sick,
  1825. "additions": additions,
  1826. "diagnose": diagnose,
  1827. "manufacturers": manufacturers,
  1828. "goodOutOpen": goodOutOpen,
  1829. "patientDiagnose": patientDiagnose,
  1830. })
  1831. }
  1832. }
  1833. func (c *HisApiController) CreateHisPrescription() {
  1834. record_date := c.GetString("record_date")
  1835. patient_id, _ := c.GetInt64("patient_id")
  1836. reg_type, _ := c.GetInt64("reg_type")
  1837. diagnose := c.GetString("diagnose")
  1838. sick_type, _ := c.GetInt64("sick_type")
  1839. sick_history := c.GetString("sick_history")
  1840. doctor_id, _ := c.GetInt64("doctor", 0)
  1841. department, _ := c.GetInt64("department", 0)
  1842. his_patient_id, _ := c.GetInt64("his_patient_id")
  1843. p_type, _ := c.GetInt64("p_type")
  1844. patient_diagnose := c.GetString("patient_diagnose")
  1845. dataBody := make(map[string]interface{}, 0)
  1846. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1847. if err != nil {
  1848. utils.ErrorLog(err.Error())
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1850. return
  1851. }
  1852. //edit, src := GetCompareData(dataBody)
  1853. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1854. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1855. //fmt.Println(drugResult)
  1856. //fmt.Println(goodResult)
  1857. timeLayout := "2006-01-02"
  1858. loc, _ := time.LoadLocation("Local")
  1859. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1860. if err != nil {
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. adminInfo := c.GetAdminUserInfo()
  1865. recordDateTime := theTime.Unix()
  1866. //查询默认出库仓库库存
  1867. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1868. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1869. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1870. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1871. if len(lists) == 1 {
  1872. his_patient_id = lists[0].ID
  1873. }
  1874. }
  1875. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1876. //自动出库的开关开启
  1877. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1878. //自动出库
  1879. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1880. //耗材保存处方出库
  1881. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1882. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1883. //已发药和已收费限制逻辑
  1884. isMidicine := false
  1885. isCharge := false
  1886. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1887. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1888. if len(prescriptions) > 0 {
  1889. for _, item := range prescriptions {
  1890. items := item.(map[string]interface{})
  1891. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1892. utils.ErrorLog("id")
  1893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1894. return
  1895. }
  1896. id := int64(items["id"].(float64))
  1897. if id > 0 {
  1898. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1899. if err != nil {
  1900. if new_prescription.OrderStatus == 4 {
  1901. isCharge = true
  1902. }
  1903. }
  1904. }
  1905. }
  1906. }
  1907. }
  1908. if isMidicine == true {
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1910. return
  1911. }
  1912. if isCharge == true {
  1913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1914. return
  1915. }
  1916. // 开始主事务
  1917. db := service.XTWriteDB()
  1918. tx := db.Begin()
  1919. // 在函数结束时处理事务回滚
  1920. defer func() {
  1921. if r := recover(); r != nil {
  1922. tx.Rollback()
  1923. }
  1924. }()
  1925. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1926. //药品发药出库
  1927. if pharmacyConfig.IsOpen == 1 {
  1928. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1929. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1930. if len(prescriptions) > 0 {
  1931. for _, item := range prescriptions {
  1932. items := item.(map[string]interface{})
  1933. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1934. advices := items["advices"].([]interface{})
  1935. if len(advices) > 0 {
  1936. for _, advice := range advices {
  1937. var drug_id int64
  1938. var prescribing_number float64
  1939. var prescribingNumberUnit string
  1940. var adviceId int64
  1941. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1942. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1943. }
  1944. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1945. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1946. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1947. }
  1948. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1949. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1950. }
  1951. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1952. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1953. }
  1954. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1955. if drug.ID == 0 {
  1956. tx.Rollback()
  1957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1958. return
  1959. }
  1960. //查询药品的所有库存
  1961. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1962. var total_count int64
  1963. for _, it := range list {
  1964. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1965. }
  1966. totals := strconv.FormatInt(total_count, 10)
  1967. //查询该药品是否存在开药记录
  1968. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1969. //新增处方盘点库存是否充足
  1970. if advicelist.ID == 0 {
  1971. all_count, _ := strconv.ParseFloat(totals, 64)
  1972. if prescribingNumberUnit == drug.MinUnit {
  1973. if drug.IsUse != 1 {
  1974. if drug.IsProject == 0 || drug.IsProject == 2 {
  1975. if all_count == 0 {
  1976. tx.Rollback()
  1977. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1978. return
  1979. }
  1980. if prescribing_number > all_count {
  1981. tx.Rollback()
  1982. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1983. return
  1984. }
  1985. }
  1986. }
  1987. }
  1988. if prescribingNumberUnit == drug.MaxUnit {
  1989. num := prescribing_number * float64(drug.MinNumber)
  1990. if drug.IsUse != 1 {
  1991. if drug.IsProject == 0 || drug.IsProject == 2 {
  1992. if all_count == 0 {
  1993. tx.Rollback()
  1994. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1995. return
  1996. }
  1997. if num > all_count {
  1998. tx.Rollback()
  1999. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2000. return
  2001. }
  2002. }
  2003. }
  2004. }
  2005. }
  2006. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2007. //不使用保存处方出库
  2008. if drugOutConfig.IsOpen != 1 {
  2009. //修改处方
  2010. for _, advice := range advices {
  2011. var drug_id int64
  2012. var prescribing_number float64
  2013. var prescribingNumberUnit string
  2014. var prescribingNumber string
  2015. var adviceId int64
  2016. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2017. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2018. }
  2019. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2020. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2021. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2022. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2023. }
  2024. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2025. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2026. }
  2027. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2028. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2029. }
  2030. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2031. if drug.ID == 0 {
  2032. tx.Rollback()
  2033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2034. return
  2035. }
  2036. //查询药品的所有库存
  2037. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2038. var total_count int64
  2039. for _, it := range list {
  2040. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2041. }
  2042. totals := strconv.FormatInt(total_count, 10)
  2043. //查询该药品是否存在开药记录
  2044. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2045. //新增处方
  2046. if advicelist.ID == 0 {
  2047. all_count, _ := strconv.ParseFloat(totals, 64)
  2048. if prescribingNumberUnit == drug.MinUnit {
  2049. if drug.IsUse != 1 {
  2050. if drug.IsProject == 0 || drug.IsProject == 2 {
  2051. if all_count == 0 {
  2052. tx.Rollback()
  2053. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2054. return
  2055. }
  2056. if prescribing_number > all_count {
  2057. tx.Rollback()
  2058. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2059. return
  2060. }
  2061. }
  2062. }
  2063. } else {
  2064. if prescribingNumberUnit == drug.MaxUnit {
  2065. num := prescribing_number * float64(drug.MinNumber)
  2066. if drug.IsUse != 1 {
  2067. if drug.IsProject == 0 || drug.IsProject == 2 {
  2068. if all_count == 0 {
  2069. tx.Rollback()
  2070. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2071. return
  2072. }
  2073. if num > all_count {
  2074. tx.Rollback()
  2075. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2076. return
  2077. }
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. //修改处方
  2084. if advicelist.ID > 0 {
  2085. var device_number int64
  2086. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2087. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2088. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2089. device_number = prescribingNumberInt * drug.MinNumber
  2090. }
  2091. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2092. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2093. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2094. device_number = prescribingNumberInt
  2095. }
  2096. var number_count int64
  2097. if prescribingNumberUnit == drug.MaxUnit {
  2098. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2099. number_count = prescribingNumberInt * drug.MinNumber
  2100. }
  2101. if prescribingNumberUnit == drug.MinUnit {
  2102. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2103. number_count = prescribingNumberInt
  2104. }
  2105. //如果修改的数量大于之前修改的数量
  2106. if (number_count - device_number) > 0 {
  2107. //如果修改的差数量 大于库存数量
  2108. if drug.IsUse != 1 {
  2109. if (number_count - device_number) > total_count {
  2110. tx.Rollback()
  2111. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2112. return
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. }
  2119. }
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125. }
  2126. //已发药和已收费限制逻辑
  2127. //执行出库的逻辑
  2128. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2129. //校验库存总量
  2130. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2131. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2132. if len(prescriptions) > 0 {
  2133. for _, item := range prescriptions {
  2134. items := item.(map[string]interface{})
  2135. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2136. advices := items["advices"].([]interface{})
  2137. if len(advices) > 0 {
  2138. for _, advice := range advices {
  2139. var drug_id int64
  2140. var prescribing_number float64
  2141. var prescribingNumberUnit string
  2142. var adviceId int64
  2143. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2144. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2145. }
  2146. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2147. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2148. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2149. }
  2150. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2151. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2152. }
  2153. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2154. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2155. }
  2156. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2157. if drug.ID == 0 {
  2158. tx.Rollback()
  2159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2160. return
  2161. }
  2162. //查询药品的所有库存
  2163. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2164. var total_count int64
  2165. for _, it := range list {
  2166. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2167. }
  2168. totals := strconv.FormatInt(total_count, 10)
  2169. //查询该药品是否存在开药记录
  2170. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2171. //查询最新批次库存
  2172. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2173. var batch_number_count int64
  2174. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2175. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2176. //新增处方
  2177. if advicelist.ID == 0 {
  2178. all_count, _ := strconv.ParseFloat(totals, 64)
  2179. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2180. if prescribingNumberUnit == drug.MinUnit {
  2181. if drug.IsUse != 1 {
  2182. if drug.IsProject == 0 || drug.IsProject == 2 {
  2183. if all_count == 0 {
  2184. tx.Rollback()
  2185. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2186. return
  2187. }
  2188. if prescribing_number > all_count {
  2189. tx.Rollback()
  2190. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2191. return
  2192. }
  2193. }
  2194. if adminInfo.CurrentOrgId == 10215 {
  2195. if prescribing_number > batch_number_all_count {
  2196. tx.Rollback()
  2197. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2198. return
  2199. }
  2200. }
  2201. }
  2202. }
  2203. if prescribingNumberUnit == drug.MaxUnit {
  2204. num := prescribing_number * float64(drug.MinNumber)
  2205. if drug.IsUse != 1 {
  2206. if drug.IsProject == 0 || drug.IsProject == 2 {
  2207. if all_count == 0 {
  2208. tx.Rollback()
  2209. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2210. return
  2211. }
  2212. if num > all_count {
  2213. tx.Rollback()
  2214. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2215. return
  2216. }
  2217. }
  2218. if adminInfo.CurrentOrgId == 10215 {
  2219. if num > batch_number_all_count {
  2220. tx.Rollback()
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2222. return
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. //不是保存处方出库
  2229. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2230. if drugOutConfig.IsOpen != 1 {
  2231. //修改处方
  2232. for _, advice := range advices {
  2233. var drug_id int64
  2234. var prescribing_number float64
  2235. var prescribingNumberUnit string
  2236. var prescribingNumber string
  2237. var adviceId int64
  2238. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2239. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2240. }
  2241. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2242. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2243. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2244. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2245. }
  2246. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2247. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2248. }
  2249. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2250. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2251. }
  2252. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2253. if drug.ID == 0 {
  2254. tx.Rollback()
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2256. return
  2257. }
  2258. //查询药品的所有库存
  2259. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2260. var total_count int64
  2261. for _, it := range list {
  2262. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2263. }
  2264. totals := strconv.FormatInt(total_count, 10)
  2265. //查询该药品是否存在开药记录
  2266. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2267. //新增处方
  2268. if advicelist.ID == 0 {
  2269. //查询最新批次库存
  2270. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2271. var batch_number_count int64
  2272. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2273. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2274. all_count, _ := strconv.ParseFloat(totals, 64)
  2275. if all_count == 0 {
  2276. tx.Rollback()
  2277. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2278. return
  2279. }
  2280. if prescribingNumberUnit == drug.MinUnit {
  2281. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2282. if drug.IsUse != 1 {
  2283. if drug.IsProject == 0 || drug.IsProject == 2 {
  2284. if all_count == 0 {
  2285. tx.Rollback()
  2286. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2287. return
  2288. }
  2289. if prescribing_number > all_count {
  2290. tx.Rollback()
  2291. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2292. return
  2293. }
  2294. }
  2295. if adminInfo.CurrentOrgId == 10215 {
  2296. if prescribing_number > batch_number_all_count {
  2297. tx.Rollback()
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2299. return
  2300. }
  2301. }
  2302. }
  2303. } else {
  2304. if prescribingNumberUnit == drug.MaxUnit {
  2305. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2306. num := prescribing_number * float64(drug.MinNumber)
  2307. if drug.IsUse != 1 {
  2308. if drug.IsProject == 0 || drug.IsProject == 2 {
  2309. if all_count == 0 {
  2310. tx.Rollback()
  2311. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2312. return
  2313. }
  2314. if num > all_count {
  2315. tx.Rollback()
  2316. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2317. return
  2318. }
  2319. }
  2320. if adminInfo.CurrentOrgId == 10215 {
  2321. if prescribing_number > batch_number_all_count {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2324. return
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. //修改处方
  2332. if advicelist.ID > 0 {
  2333. //查询最新批次库存
  2334. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2335. var batch_number_count int64
  2336. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2337. var device_number int64
  2338. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2339. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2340. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2341. device_number = prescribingNumberInt * drug.MinNumber
  2342. }
  2343. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2344. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2345. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2346. device_number = prescribingNumberInt
  2347. //回退库存
  2348. }
  2349. var number_count int64
  2350. if prescribingNumberUnit == drug.MaxUnit {
  2351. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2352. number_count = prescribingNumberInt * drug.MinNumber
  2353. //回退库存
  2354. }
  2355. if prescribingNumberUnit == drug.MinUnit {
  2356. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2357. number_count = prescribingNumberInt
  2358. //回退库存
  2359. }
  2360. //如果修改的数量大于之前修改的数量
  2361. if (number_count - device_number) > 0 {
  2362. //如果修改的差数量 大于库存数量
  2363. if drug.IsUse != 1 {
  2364. if drug.IsProject == 0 || drug.IsProject == 2 {
  2365. if total_count == 0 {
  2366. tx.Rollback()
  2367. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2368. return
  2369. }
  2370. if (number_count - device_number) > total_count {
  2371. tx.Rollback()
  2372. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2373. return
  2374. }
  2375. if (number_count - device_number) > batch_number_count {
  2376. tx.Rollback()
  2377. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2378. return
  2379. }
  2380. }
  2381. if adminInfo.CurrentOrgId == 10215 {
  2382. // 查询该药品最后一次出库记录
  2383. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2384. var out_count int64
  2385. var in_count int64
  2386. var stock_max_number int64
  2387. var stock_min_number int64
  2388. for _, it := range outInfo {
  2389. if it.CountUnit == drug.MaxUnit {
  2390. it.Count = it.Count * drug.MinNumber
  2391. }
  2392. out_count += it.Count
  2393. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2394. stock_max_number = warehouseInfoList.StockMaxNumber
  2395. stock_min_number = warehouseInfoList.StockMinNumber
  2396. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2397. }
  2398. if out_count > 0 {
  2399. if (number_count - device_number) > in_count {
  2400. tx.Rollback()
  2401. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2402. return
  2403. }
  2404. }
  2405. // 未出库
  2406. if out_count == 0 {
  2407. var sum_in_count int64
  2408. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2409. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2410. //如果修改的数量大于有库存的第一个批次
  2411. if number_count > sum_in_count {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2414. return
  2415. }
  2416. }
  2417. }
  2418. }
  2419. }
  2420. //药品发药
  2421. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2422. //不使用药品发药的功能
  2423. //if pharmacyConfig.IsOpen != 1 {
  2424. // if device_number != number_count {
  2425. //
  2426. // //查询该药品的出库记录
  2427. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2428. // if len(outListExport) > 0 {
  2429. // //
  2430. // for _, item := range outListExport {
  2431. // //回退库存
  2432. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2433. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2434. // }
  2435. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2436. // var stock_max_number int64
  2437. // var stock_min_number int64
  2438. //
  2439. // if number_count >= drug.MinNumber {
  2440. //
  2441. // stock_max_number = device_number / drug.MinNumber
  2442. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2443. //
  2444. // stock_min_number = device_number % drug.MinNumber
  2445. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2446. //
  2447. // } else {
  2448. //
  2449. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2450. //
  2451. // }
  2452. // }
  2453. //
  2454. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2455. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2456. // }
  2457. // }
  2458. // }
  2459. //
  2460. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2461. // var sum_count int64
  2462. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2463. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2464. // for _, its := range stockInfo {
  2465. // if its.MaxUnit == drug.MaxUnit {
  2466. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2467. // }
  2468. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2469. // }
  2470. // //更新字典里面的库存
  2471. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2472. //
  2473. // //剩余库存
  2474. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2475. //
  2476. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2477. // //减少出库数量
  2478. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2479. //
  2480. // }
  2481. //}
  2482. }
  2483. }
  2484. }
  2485. //保存处方开药
  2486. if drugOutConfig.IsOpen == 1 {
  2487. //修改处方
  2488. for _, advice := range advices {
  2489. var drug_id int64
  2490. var prescribing_number float64
  2491. var prescribingNumberUnit string
  2492. var prescribingNumber string
  2493. var adviceId int64
  2494. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2495. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2496. }
  2497. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2498. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2499. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2500. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2501. }
  2502. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2503. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2504. }
  2505. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2506. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2507. }
  2508. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2509. if drug.ID == 0 {
  2510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2511. return
  2512. }
  2513. //查询药品的所有库存
  2514. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2515. var total_count int64
  2516. for _, it := range list {
  2517. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2518. }
  2519. totals := strconv.FormatInt(total_count, 10)
  2520. //查询该药品是否存在开药记录
  2521. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2522. //新增处方
  2523. if advicelist.ID == 0 {
  2524. //查询最新批次库存
  2525. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2526. var batch_number_count int64
  2527. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2528. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2529. all_count, _ := strconv.ParseFloat(totals, 64)
  2530. if prescribingNumberUnit == drug.MinUnit {
  2531. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2532. if drug.IsUse != 1 {
  2533. if drug.IsProject == 0 || drug.IsProject == 2 {
  2534. if all_count == 0 {
  2535. tx.Rollback()
  2536. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2537. return
  2538. }
  2539. if prescribing_number > all_count {
  2540. tx.Rollback()
  2541. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2542. return
  2543. }
  2544. }
  2545. if adminInfo.CurrentOrgId == 10215 {
  2546. if prescribing_number > batch_number_all_count {
  2547. tx.Rollback()
  2548. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2549. return
  2550. }
  2551. }
  2552. }
  2553. } else {
  2554. if prescribingNumberUnit == drug.MaxUnit {
  2555. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2556. num := prescribing_number * float64(drug.MinNumber)
  2557. if drug.IsUse != 1 {
  2558. if drug.IsProject == 0 || drug.IsProject == 2 {
  2559. if all_count == 0 {
  2560. tx.Rollback()
  2561. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2562. return
  2563. }
  2564. if num > all_count {
  2565. tx.Rollback()
  2566. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2567. return
  2568. }
  2569. }
  2570. if adminInfo.CurrentOrgId == 10215 {
  2571. if prescribing_number > batch_number_all_count {
  2572. tx.Rollback()
  2573. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2574. return
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. //修改处方
  2582. if advicelist.ID > 0 {
  2583. //查询最新批次库存
  2584. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2585. var batch_number_count int64
  2586. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2587. var device_number int64
  2588. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2589. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2590. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2591. device_number = prescribingNumberInt * drug.MinNumber
  2592. }
  2593. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2594. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2595. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2596. device_number = prescribingNumberInt
  2597. }
  2598. var number_count int64
  2599. if prescribingNumberUnit == drug.MaxUnit {
  2600. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2601. number_count = prescribingNumberInt * drug.MinNumber
  2602. }
  2603. if prescribingNumberUnit == drug.MinUnit {
  2604. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2605. number_count = prescribingNumberInt
  2606. }
  2607. //如果修改的数量大于之前修改的数量
  2608. if (number_count - device_number) > 0 {
  2609. //如果修改的差数量 大于库存数量
  2610. if drug.IsUse != 1 {
  2611. if drug.IsProject == 0 || drug.IsProject == 2 {
  2612. if total_count == 0 {
  2613. tx.Rollback()
  2614. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2615. return
  2616. }
  2617. if (number_count - device_number) > total_count {
  2618. tx.Rollback()
  2619. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2620. return
  2621. }
  2622. }
  2623. if adminInfo.CurrentOrgId == 10215 {
  2624. if (number_count - device_number) > batch_number_count {
  2625. tx.Rollback()
  2626. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2627. return
  2628. }
  2629. }
  2630. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2631. //查询历史出库数据总批次
  2632. // 查询该药品最后一次出库记录
  2633. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2634. var out_count int64
  2635. var in_count int64
  2636. var stock_max_number int64
  2637. var stock_min_number int64
  2638. for _, it := range outInfo {
  2639. if it.CountUnit == drug.MaxUnit {
  2640. it.Count = it.Count * drug.MinNumber
  2641. }
  2642. out_count += it.Count
  2643. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2644. stock_max_number = warehouseInfoList.StockMaxNumber
  2645. stock_min_number = warehouseInfoList.StockMinNumber
  2646. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2647. }
  2648. if out_count > 0 {
  2649. if (number_count - device_number) > in_count {
  2650. tx.Rollback()
  2651. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2652. return
  2653. }
  2654. }
  2655. // 未出库
  2656. if out_count == 0 {
  2657. var sum_in_count int64
  2658. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2659. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2660. if sum_in_count == 0 {
  2661. tx.Rollback()
  2662. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2663. return
  2664. }
  2665. //如果修改的数量大于有库存的第一个批次
  2666. if number_count > sum_in_count {
  2667. tx.Rollback()
  2668. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2669. return
  2670. }
  2671. }
  2672. }
  2673. }
  2674. }
  2675. }
  2676. }
  2677. }
  2678. }
  2679. }
  2680. }
  2681. }
  2682. }
  2683. }
  2684. }
  2685. //校验耗材库存
  2686. if goodOutConfig.IsOpen == 1 {
  2687. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2688. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2689. if len(prescriptions) > 0 {
  2690. for _, item := range prescriptions {
  2691. items := item.(map[string]interface{})
  2692. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2693. projects := items["project"].([]interface{})
  2694. if len(projects) > 0 {
  2695. for _, project := range projects {
  2696. var project_id int64
  2697. var project_type int64
  2698. var totals float64
  2699. var project_name string
  2700. var parsetotal int64
  2701. var id int64
  2702. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2703. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2704. }
  2705. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2706. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2707. }
  2708. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2709. total, _ := project.(map[string]interface{})["total"].(string)
  2710. totals, _ = strconv.ParseFloat(total, 64)
  2711. }
  2712. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2713. project_name = project.(map[string]interface{})["project_name"].(string)
  2714. }
  2715. if project_type == 3 {
  2716. //查找该耗材的出库记录
  2717. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2718. if len(goodWarehouseInfo) == 0 {
  2719. //查询耗材库存
  2720. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2721. var stock_count int64
  2722. for _, it := range list {
  2723. stock_count += it.StockCount
  2724. }
  2725. stock_counts := strconv.FormatInt(stock_count, 10)
  2726. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2727. if stock_total_count == 0 {
  2728. tx.Rollback()
  2729. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2730. return
  2731. }
  2732. if totals > stock_total_count {
  2733. tx.Rollback()
  2734. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2735. return
  2736. }
  2737. }
  2738. if len(goodWarehouseInfo) > 0 {
  2739. //查询该患者耗材的历史数据
  2740. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2741. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2742. //数量发生改变
  2743. if parsetotal != count {
  2744. //如果现在的数量大于历史数量,就要看库存是否足够
  2745. if parsetotal > count {
  2746. //查询耗材所有库存
  2747. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2748. var stock_count int64
  2749. for _, it := range list {
  2750. stock_count += it.StockCount
  2751. }
  2752. //库存不足
  2753. if stock_count == 0 {
  2754. tx.Rollback()
  2755. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2756. return
  2757. }
  2758. if (parsetotal - count) > stock_count {
  2759. tx.Rollback()
  2760. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2761. return
  2762. }
  2763. }
  2764. }
  2765. }
  2766. }
  2767. }
  2768. }
  2769. }
  2770. }
  2771. }
  2772. }
  2773. }
  2774. //不使用耗材保存处方出库
  2775. if goodOutConfig.IsOpen != 1 {
  2776. if stockConfig.IsOpen == 1 {
  2777. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2778. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2779. if len(prescriptions) > 0 {
  2780. for _, item := range prescriptions {
  2781. items := item.(map[string]interface{})
  2782. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2783. projects := items["project"].([]interface{})
  2784. if len(projects) > 0 {
  2785. for _, project := range projects {
  2786. var project_id int64
  2787. var project_type int64
  2788. var totals float64
  2789. var project_name string
  2790. var parsetotal int64
  2791. var id int64
  2792. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2793. id = int64(project.(map[string]interface{})["id"].(float64))
  2794. }
  2795. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2796. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2797. }
  2798. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2799. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2800. }
  2801. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2802. total, _ := project.(map[string]interface{})["total"].(string)
  2803. totals, _ = strconv.ParseFloat(total, 64)
  2804. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2805. }
  2806. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2807. project_name = project.(map[string]interface{})["project_name"].(string)
  2808. }
  2809. if project_type == 3 {
  2810. //查找该耗材的出库记录
  2811. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2812. //没有出库记录
  2813. if len(goodWarehouseInfo) == 0 {
  2814. //查询耗材库存
  2815. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2816. var stock_count int64
  2817. for _, it := range list {
  2818. stock_count += it.StockCount
  2819. }
  2820. stock_counts := strconv.FormatInt(stock_count, 10)
  2821. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2822. if stock_total_count == 0 {
  2823. tx.Rollback()
  2824. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2825. return
  2826. }
  2827. if totals > stock_total_count {
  2828. tx.Rollback()
  2829. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2830. return
  2831. }
  2832. //查找今日该患者已经出库的所有耗材
  2833. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2834. for _, item := range goodList {
  2835. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2836. var flush_count int64
  2837. for _, it := range goodListSix {
  2838. flush_count += it.StockCount
  2839. }
  2840. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2841. creater := adminInfo.AdminUser.Id
  2842. if errs != nil {
  2843. goodErrcode := models.XtGoodErrcode{
  2844. UserOrgId: item.OrgId,
  2845. Errcode: "手动出库更新剩余出库失败",
  2846. GoodId: item.GoodId,
  2847. Status: 1,
  2848. Ctime: time.Now().Unix(),
  2849. Mtime: 0,
  2850. Count: 0,
  2851. StockCount: 0,
  2852. Creater: creater,
  2853. BatchNumberId: 0,
  2854. WarehouseOutId: 0,
  2855. }
  2856. service.CreateGoodErrcode(goodErrcode)
  2857. }
  2858. }
  2859. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2860. }
  2861. //有出库记录
  2862. if len(goodWarehouseInfo) > 0 {
  2863. //查询该患者耗材的历史数据
  2864. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2865. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2866. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2867. //数量发生改变
  2868. if parsetotal != count {
  2869. //查找今日该患者已经出库的所有耗材
  2870. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2871. for _, item := range goodList {
  2872. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2873. var flush_count int64
  2874. for _, it := range goodListSix {
  2875. flush_count += it.StockCount
  2876. }
  2877. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2878. //减少出库数量
  2879. creater := adminInfo.AdminUser.Id
  2880. if errs != nil {
  2881. goodErrcode := models.XtGoodErrcode{
  2882. UserOrgId: item.OrgId,
  2883. Errcode: "手动出库更新剩余出库失败",
  2884. GoodId: item.GoodId,
  2885. Status: 1,
  2886. Ctime: time.Now().Unix(),
  2887. Mtime: 0,
  2888. Count: 0,
  2889. StockCount: 0,
  2890. Creater: creater,
  2891. BatchNumberId: 0,
  2892. WarehouseOutId: 0,
  2893. }
  2894. service.CreateGoodErrcode(goodErrcode)
  2895. }
  2896. //查询默认仓库
  2897. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2898. var total_count int64
  2899. for _, it := range stockList {
  2900. total_count += it.StockCount
  2901. }
  2902. //基础库插入数据
  2903. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2904. }
  2905. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2906. }
  2907. }
  2908. }
  2909. }
  2910. }
  2911. }
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2918. var hpInfo models.HisPrescriptionInfo
  2919. if info.ID == 0 {
  2920. var randNum int
  2921. randNum = rand.Intn(10000) + 1000
  2922. timestamp := time.Now().Unix()
  2923. tempTime := time.Unix(timestamp, 0)
  2924. timeFormat := tempTime.Format("20060102150405")
  2925. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2926. hpInfo = models.HisPrescriptionInfo{
  2927. HisPatientId: his_patient_id,
  2928. UserOrgId: adminInfo.CurrentOrgId,
  2929. RecordDate: theTime.Unix(),
  2930. PatientId: patient_id,
  2931. Status: 1,
  2932. Ctime: time.Now().Unix(),
  2933. Mtime: time.Now().Unix(),
  2934. Creator: adminInfo.AdminUser.Id,
  2935. Modifier: adminInfo.AdminUser.Id,
  2936. Diagnosis: diagnose,
  2937. SickHistory: sick_history,
  2938. Departments: department,
  2939. RegisterType: reg_type,
  2940. PrescriptionNumber: p_number,
  2941. PrescriptionStatus: 1,
  2942. Doctor: role.UserName,
  2943. DoctorId: doctor_id,
  2944. SickType: sick_type,
  2945. PType: p_type,
  2946. PatientDiagnosis: patient_diagnose,
  2947. }
  2948. service.SavePatientPrescriptionInfo(hpInfo)
  2949. //创建步骤表
  2950. finish := models.XtDialysisFinish{
  2951. IsFinish: 1,
  2952. UserOrgId: adminInfo.CurrentOrgId,
  2953. Status: 1,
  2954. Ctime: time.Now().Unix(),
  2955. Mtime: 0,
  2956. Module: 4,
  2957. RecordDate: theTime.Unix(),
  2958. Sourse: 1,
  2959. PatientId: patient_id,
  2960. }
  2961. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2962. if dialysisFinish.ID == 0 {
  2963. service.CreateDialysisFinish(finish)
  2964. }
  2965. redis := service.RedisClient()
  2966. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2967. redis.Set(key, "", time.Second)
  2968. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2969. redis.Set(keyOne, "", time.Second)
  2970. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2971. redis.Set(keySeven, "", time.Second)
  2972. defer redis.Close()
  2973. } else {
  2974. hpInfo = models.HisPrescriptionInfo{
  2975. ID: info.ID,
  2976. UserOrgId: adminInfo.CurrentOrgId,
  2977. RecordDate: info.RecordDate,
  2978. PatientId: info.PatientId,
  2979. Status: 1,
  2980. Ctime: info.Ctime,
  2981. Mtime: time.Now().Unix(),
  2982. Creator: info.Creator,
  2983. Modifier: adminInfo.AdminUser.Id,
  2984. Diagnosis: diagnose,
  2985. SickHistory: sick_history,
  2986. Departments: department,
  2987. RegisterType: reg_type,
  2988. PrescriptionNumber: info.PrescriptionNumber,
  2989. Doctor: role.UserName,
  2990. PrescriptionStatus: info.PrescriptionStatus,
  2991. DoctorId: doctor_id,
  2992. SickType: sick_type,
  2993. PType: info.PType,
  2994. HisPatientId: info.HisPatientId,
  2995. PatientDiagnosis: patient_diagnose,
  2996. }
  2997. service.SavePatientPrescriptionInfo(hpInfo)
  2998. //创建步骤表
  2999. finish := models.XtDialysisFinish{
  3000. IsFinish: 1,
  3001. UserOrgId: adminInfo.CurrentOrgId,
  3002. Status: 1,
  3003. Ctime: time.Now().Unix(),
  3004. Mtime: 0,
  3005. Module: 4,
  3006. RecordDate: info.RecordDate,
  3007. Sourse: 1,
  3008. PatientId: info.PatientId,
  3009. }
  3010. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3011. if dialysisFinish.ID == 0 {
  3012. service.CreateDialysisFinish(finish)
  3013. }
  3014. redis := service.RedisClient()
  3015. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3016. redis.Set(key, "", time.Second)
  3017. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3018. redis.Set(keyOne, "", time.Second)
  3019. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3020. redis.Set(keySeven, "", time.Second)
  3021. defer redis.Close()
  3022. }
  3023. //定义切片
  3024. var adviceList []models.HisDoctorAdviceInfo
  3025. var projectList []models.HisPrescriptionProject
  3026. 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 {
  3027. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3028. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3029. var tempPrescription *models.HisPrescription
  3030. if len(prescriptions) > 0 {
  3031. for _, item := range prescriptions {
  3032. // 开始外部循环的事务
  3033. tx := db.Begin()
  3034. // 在函数结束时处理事务回滚
  3035. defer func() {
  3036. if r := recover(); r != nil {
  3037. tx.Rollback()
  3038. }
  3039. }()
  3040. items := item.(map[string]interface{})
  3041. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3042. utils.ErrorLog("id")
  3043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3044. return
  3045. }
  3046. id := int64(items["id"].(float64))
  3047. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3048. tempPrescription = &new_prescription
  3049. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3050. utils.ErrorLog("type")
  3051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3052. return
  3053. }
  3054. types := int64(items["type"].(float64))
  3055. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3056. utils.ErrorLog("med_type")
  3057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3058. return
  3059. }
  3060. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3061. if med_type == "0" {
  3062. med_type = "14"
  3063. }
  3064. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3065. // utils.ErrorLog("diagnoses")
  3066. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3067. // return
  3068. //}
  3069. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3070. diagnoses, _ := items["diagnoses"].(string)
  3071. //if order_status == 0 {
  3072. // order_status = 1
  3073. //}
  3074. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3075. utils.ErrorLog("pre_time")
  3076. }
  3077. preTime, _ := items["pre_time"].(string)
  3078. fmt.Println("preTime", preTime)
  3079. timeLayout := "2006-01-02"
  3080. loc, _ := time.LoadLocation("Local")
  3081. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3082. //result := strings.Split(preTime, " ")
  3083. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3084. if err != nil {
  3085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3086. return
  3087. }
  3088. pTime := theTime2.Unix()
  3089. ctime := time.Now().Unix()
  3090. if tempPrescription.ID == 0 {
  3091. prescription := &models.HisPrescription{
  3092. ID: 0,
  3093. PatientId: patient_id,
  3094. UserOrgId: adminInfo.CurrentOrgId,
  3095. RecordDate: recordDateTime,
  3096. Ctime: ctime,
  3097. Mtime: ctime,
  3098. Type: types,
  3099. Modifier: adminInfo.AdminUser.Id,
  3100. Creator: adminInfo.AdminUser.Id,
  3101. Status: 1,
  3102. Doctor: role.UserName,
  3103. HisPatientId: his_patient_id,
  3104. OrderStatus: 1,
  3105. BatchNumber: "",
  3106. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3107. PreTime: pTime,
  3108. PType: p_type,
  3109. MedType: med_type,
  3110. Diagnose: diagnoses,
  3111. }
  3112. tempPrescription = prescription
  3113. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3114. redis := service.RedisClient()
  3115. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3116. redis.Set(key, "", time.Second)
  3117. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3118. redis.Set(keyOne, "", time.Second)
  3119. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3120. redis.Set(keySeven, "", time.Second)
  3121. defer redis.Close()
  3122. } else {
  3123. tempPrescription.ID = id
  3124. tempPrescription.Type = types
  3125. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3126. tempPrescription.Mtime = time.Now().Unix()
  3127. tempPrescription.Doctor = role.UserName
  3128. //tempPrescription.OrderStatus = order_status
  3129. tempPrescription.PreTime = pTime
  3130. tempPrescription.MedType = med_type
  3131. tempPrescription.Diagnose = diagnoses
  3132. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3133. redis := service.RedisClient()
  3134. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3135. redis.Set(key, "", time.Second)
  3136. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3137. redis.Set(keyOne, "", time.Second)
  3138. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3139. redis.Set(keySeven, "", time.Second)
  3140. defer redis.Close()
  3141. }
  3142. //service.SaveHisPrescription(prescription)
  3143. //更改患者挂号状态
  3144. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3145. fmt.Println("更改失败", err2)
  3146. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3147. advices := items["advices"].([]interface{})
  3148. groupNo := int64(0)
  3149. if len(advices) > 0 {
  3150. for _, advice := range advices {
  3151. tx := db.Begin()
  3152. // 在函数结束时处理事务回滚
  3153. defer func() {
  3154. if r := recover(); r != nil {
  3155. tx.Rollback()
  3156. }
  3157. }()
  3158. var s models.HisDoctorAdviceInfo
  3159. s.PrescriptionId = tempPrescription.ID
  3160. s.AdviceType = 2
  3161. s.AdviceDoctor = doctor_id
  3162. s.StopState = 2
  3163. s.ExecutionState = 2
  3164. s.AdviceDate = theTime3.Unix()
  3165. s.Status = 1
  3166. s.UserOrgId = adminInfo.CurrentOrgId
  3167. s.RecordDate = theTime3.Unix()
  3168. s.StartTime = tempPrescription.PreTime
  3169. s.Groupno = groupNo
  3170. s.PatientId = patient_id
  3171. s.HisPatientId = his_patient_id
  3172. s.StartTime = pTime
  3173. s.IsSettle = 2
  3174. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3175. if errcode > 0 {
  3176. c.ServeFailJSONWithSGJErrorCode(errcode)
  3177. return
  3178. }
  3179. s.StartTime = pTime
  3180. var total_count int64 //处方总库存
  3181. //查询改药品信息
  3182. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3183. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3184. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3185. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3186. total_count += prescribingNumberSeven * medical.MinNumber
  3187. }
  3188. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3189. total_count += prescribingNumberSeven
  3190. }
  3191. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3192. total_count += prescribingNumberSeven
  3193. }
  3194. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3195. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3196. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3197. if s.Price != lastWarehouse.RetailPrice {
  3198. s.Price = lastWarehouse.RetailPrice
  3199. }
  3200. if s.Price == 0 {
  3201. if lastWarehouse.ID == 0 {
  3202. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3203. s.Price = lastWarehouseTwo.RetailPrice
  3204. }
  3205. }
  3206. }
  3207. //查询保存处方出库开关是否打开
  3208. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3209. if s.PatientId != 30038 {
  3210. if drugOutConfig.IsOpen == 1 {
  3211. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3212. // 查询该药品最后一次出库记录
  3213. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3214. var is_user_total int64
  3215. var no_user_total int64
  3216. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3217. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3218. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3219. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3220. }
  3221. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3222. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3223. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3224. no_user_total += prescribingNumberSevenTy
  3225. }
  3226. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3227. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3228. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3229. no_user_total += prescribingNumberSevenTy
  3230. }
  3231. if len(druginfo) > 0 {
  3232. for _, it := range druginfo {
  3233. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3234. it.Count = it.Count * drug.MinNumber
  3235. is_user_total += it.Count
  3236. }
  3237. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3238. is_user_total += it.Count
  3239. }
  3240. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3241. is_user_total += it.Count
  3242. }
  3243. }
  3244. }
  3245. //库存不足
  3246. if s.UserOrgId != 10206 {
  3247. if s.ID == 0 {
  3248. //查询改药品是否已经停用
  3249. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3250. if base.ID > 0 {
  3251. tx.Rollback()
  3252. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3253. return
  3254. }
  3255. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3256. if drugMedical.SumCount == 0 {
  3257. tx.Rollback()
  3258. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3259. return
  3260. }
  3261. //针对康德
  3262. //if s.UserOrgId == 10402 || s.UserOrgId == 10164 {
  3263. // //获取该药品的总入库数量
  3264. // drugWarehouseinfo, _ := service.GetAllDrugInfoList(s.DrugId, s.UserOrgId)
  3265. //
  3266. // //获取该药品总共开了多少支医嘱
  3267. // hisDocInfoList, _ := service.GetHisDocInfoList(s.DrugId, s.UserOrgId)
  3268. // var in_count int64
  3269. // var in_prescription_number_total int64
  3270. // if len(drugWarehouseinfo) > 0 {
  3271. // for _, item := range drugWarehouseinfo {
  3272. // if item.MaxUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3273. //
  3274. // in_count += item.WarehousingCount * drugMedical.MinNumber
  3275. // }
  3276. //
  3277. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3278. //
  3279. // in_count += item.WarehousingCount
  3280. // }
  3281. //
  3282. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3283. //
  3284. // in_count += item.WarehousingCount
  3285. // }
  3286. //
  3287. // }
  3288. // }
  3289. //
  3290. // if len(hisDocInfoList) > 0 {
  3291. //
  3292. // for _, item := range hisDocInfoList {
  3293. // if item.PrescribingNumberUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3294. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3295. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3296. //
  3297. // in_prescription_number_total += prescribingNumberSevenTy * drug.MinNumber
  3298. // }
  3299. //
  3300. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3301. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3302. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3303. // in_prescription_number_total += prescribingNumberSevenTy
  3304. // }
  3305. //
  3306. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3307. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3308. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3309. // in_prescription_number_total += prescribingNumberSevenTy
  3310. // }
  3311. // }
  3312. // }
  3313. // //
  3314. // //fmt.Println("no_user_total------------------------------", no_user_total)
  3315. // //fmt.Println("in_prescription_number_total---------------------------", in_prescription_number_total)
  3316. // //fmt.Println("in_count----------------------------------", in_count)
  3317. //
  3318. // //如果已经开过的医嘱 加上未开的医嘱数量 大于 入库总数量则提示库存不足
  3319. // if no_user_total+in_prescription_number_total > in_count {
  3320. // tx.Rollback()
  3321. // c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3322. // return
  3323. // }
  3324. //
  3325. //}
  3326. //查询该药品所有入库数量
  3327. }
  3328. if s.ID > 0 {
  3329. //查询改药品是否已经停用
  3330. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3331. if base.ID > 0 {
  3332. tx.Rollback()
  3333. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3334. return
  3335. }
  3336. }
  3337. }
  3338. //fmt.Println("药品名称----------------------", drug.DrugName)
  3339. //fmt.Println("药品名称----------------------", drug.IsUse)
  3340. //fmt.Println("is_user_total-------------------------", is_user_total)
  3341. //fmt.Println("no_user_total-------------------------", no_user_total)
  3342. //fmt.Println("drug.IsUse---------------", drug.IsUse)
  3343. //fmt.Println("00000000000000000000", s.UserOrgId)
  3344. if is_user_total != no_user_total {
  3345. //出库
  3346. //针对御享天源
  3347. if drug.IsUse == 1 && s.UserOrgId == 10635 && s.UserOrgId == 9671 {
  3348. creater := adminInfo.AdminUser.Id
  3349. newadviceInfo := &models.HisDoctorAdviceInfo{
  3350. ID: s.ID,
  3351. UserOrgId: s.UserOrgId,
  3352. PatientId: s.PatientId,
  3353. HisPatientId: s.HisPatientId,
  3354. AdviceType: s.AdviceType,
  3355. AdviceDate: s.AdviceDate,
  3356. StartTime: s.StartTime,
  3357. AdviceName: s.AdviceName,
  3358. AdviceDesc: s.AdviceDesc,
  3359. ReminderDate: s.ReminderDate,
  3360. SingleDose: s.SingleDose,
  3361. SingleDoseUnit: s.SingleDoseUnit,
  3362. PrescribingNumber: s.PrescribingNumber,
  3363. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3364. DeliveryWay: s.DeliveryWay,
  3365. ExecutionFrequency: s.ExecutionFrequency,
  3366. AdviceDoctor: s.AdviceDoctor,
  3367. Status: s.Status,
  3368. CreatedTime: s.CreatedTime,
  3369. UpdatedTime: s.UpdatedTime,
  3370. AdviceAffirm: s.AdviceAffirm,
  3371. Remark: s.Remark,
  3372. StopTime: s.StopTime,
  3373. StopReason: s.StopReason,
  3374. StopDoctor: s.StopDoctor,
  3375. StopState: s.StopState,
  3376. ParentId: s.ParentId,
  3377. ExecutionTime: s.ExecutionTime,
  3378. ExecutionStaff: s.ExecutionStaff,
  3379. ExecutionState: s.ExecutionState,
  3380. Checker: s.Checker,
  3381. RecordDate: s.RecordDate,
  3382. DialysisOrderId: s.DialysisOrderId,
  3383. CheckTime: s.CheckTime,
  3384. CheckState: s.CheckState,
  3385. DrugSpec: s.DrugSpec,
  3386. DrugSpecUnit: s.DrugSpecUnit,
  3387. Groupno: s.Groupno,
  3388. RemindType: s.RemindType,
  3389. FrequencyType: s.FrequencyType,
  3390. DayCount: s.DayCount,
  3391. WeekDay: s.WeekDay,
  3392. TemplateId: s.TemplateId,
  3393. Modifier: s.Modifier,
  3394. DrugId: s.DrugId,
  3395. Price: s.Price,
  3396. PrescriptionId: s.PrescriptionId,
  3397. MedListCodg: s.MedListCodg,
  3398. FeedetlSn: s.FeedetlSn,
  3399. Day: s.DayCount,
  3400. ChildDoctorAdvice: nil,
  3401. Drug: models.Drug{},
  3402. Diagnosis: s.Diagnosis,
  3403. Way: s.Way,
  3404. HospApprFlag: s.HospApprFlag,
  3405. LmtUsedFlag: s.LmtUsedFlag,
  3406. HisOrderInfo: models.HisOrderInfo{},
  3407. IsMedicine: s.IsMedicine,
  3408. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3409. Child: nil,
  3410. IsSettle: s.IsSettle,
  3411. IsMobile: s.IsMobile,
  3412. IsSelfDrug: s.IsSelfDrug,
  3413. DrugWayCount: s.DrugWayCount,
  3414. }
  3415. var history_count int64
  3416. var local_count int64
  3417. //查找已经开过的医嘱信息
  3418. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3419. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3420. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3421. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3422. local_count += prescribingNumberSevenTy * drug.MinNumber
  3423. }
  3424. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3425. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3426. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3427. local_count += prescribingNumberSevenTy
  3428. }
  3429. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3430. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3431. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3432. local_count += prescribingNumberSevenTy
  3433. }
  3434. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3435. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3436. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3437. history_count += prescribingNumberSevenTy * drug.MinNumber
  3438. }
  3439. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3440. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3441. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3442. history_count += prescribingNumberSevenTy
  3443. }
  3444. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3445. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3446. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3447. history_count += prescribingNumberSevenTy
  3448. }
  3449. fmt.Println("local_count---------------", local_count)
  3450. fmt.Println("history_count---------------", history_count)
  3451. //如果当前出库数量大于历史出库数量则需要出库
  3452. if local_count > history_count {
  3453. //按最小单位出库
  3454. var cha_count = local_count - history_count
  3455. newadviceInfo.PrescribingNumber = float64(cha_count)
  3456. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3457. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3458. }
  3459. //如果当前出库数量小于历史出库数量则需要退库
  3460. if local_count < history_count {
  3461. var cha_count = history_count - local_count
  3462. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3463. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3464. }
  3465. if local_count == history_count {
  3466. if is_user_total == 0 {
  3467. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3468. }
  3469. }
  3470. }
  3471. if drug.IsUse == 2 {
  3472. creater := adminInfo.AdminUser.Id
  3473. newadviceInfo := &models.HisDoctorAdviceInfo{
  3474. ID: s.ID,
  3475. UserOrgId: s.UserOrgId,
  3476. PatientId: s.PatientId,
  3477. HisPatientId: s.HisPatientId,
  3478. AdviceType: s.AdviceType,
  3479. AdviceDate: s.AdviceDate,
  3480. StartTime: s.StartTime,
  3481. AdviceName: s.AdviceName,
  3482. AdviceDesc: s.AdviceDesc,
  3483. ReminderDate: s.ReminderDate,
  3484. SingleDose: s.SingleDose,
  3485. SingleDoseUnit: s.SingleDoseUnit,
  3486. PrescribingNumber: s.PrescribingNumber,
  3487. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3488. DeliveryWay: s.DeliveryWay,
  3489. ExecutionFrequency: s.ExecutionFrequency,
  3490. AdviceDoctor: s.AdviceDoctor,
  3491. Status: s.Status,
  3492. CreatedTime: s.CreatedTime,
  3493. UpdatedTime: s.UpdatedTime,
  3494. AdviceAffirm: s.AdviceAffirm,
  3495. Remark: s.Remark,
  3496. StopTime: s.StopTime,
  3497. StopReason: s.StopReason,
  3498. StopDoctor: s.StopDoctor,
  3499. StopState: s.StopState,
  3500. ParentId: s.ParentId,
  3501. ExecutionTime: s.ExecutionTime,
  3502. ExecutionStaff: s.ExecutionStaff,
  3503. ExecutionState: s.ExecutionState,
  3504. Checker: s.Checker,
  3505. RecordDate: s.RecordDate,
  3506. DialysisOrderId: s.DialysisOrderId,
  3507. CheckTime: s.CheckTime,
  3508. CheckState: s.CheckState,
  3509. DrugSpec: s.DrugSpec,
  3510. DrugSpecUnit: s.DrugSpecUnit,
  3511. Groupno: s.Groupno,
  3512. RemindType: s.RemindType,
  3513. FrequencyType: s.FrequencyType,
  3514. DayCount: s.DayCount,
  3515. WeekDay: s.WeekDay,
  3516. TemplateId: s.TemplateId,
  3517. Modifier: s.Modifier,
  3518. DrugId: s.DrugId,
  3519. Price: s.Price,
  3520. PrescriptionId: s.PrescriptionId,
  3521. MedListCodg: s.MedListCodg,
  3522. FeedetlSn: s.FeedetlSn,
  3523. Day: s.DayCount,
  3524. ChildDoctorAdvice: nil,
  3525. Drug: models.Drug{},
  3526. Diagnosis: s.Diagnosis,
  3527. Way: s.Way,
  3528. HospApprFlag: s.HospApprFlag,
  3529. LmtUsedFlag: s.LmtUsedFlag,
  3530. HisOrderInfo: models.HisOrderInfo{},
  3531. IsMedicine: s.IsMedicine,
  3532. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3533. Child: nil,
  3534. IsSettle: s.IsSettle,
  3535. IsMobile: s.IsMobile,
  3536. IsSelfDrug: s.IsSelfDrug,
  3537. DrugWayCount: s.DrugWayCount,
  3538. }
  3539. var history_count int64
  3540. var local_count int64
  3541. //查找已经开过的医嘱信息
  3542. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3543. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3544. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3545. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3546. local_count += prescribingNumberSevenTy * drug.MinNumber
  3547. }
  3548. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3549. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3550. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3551. local_count += prescribingNumberSevenTy
  3552. }
  3553. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3554. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3555. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3556. local_count += prescribingNumberSevenTy
  3557. }
  3558. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3559. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3560. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3561. history_count += prescribingNumberSevenTy * drug.MinNumber
  3562. }
  3563. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3564. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3565. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3566. history_count += prescribingNumberSevenTy
  3567. }
  3568. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3569. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3570. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3571. history_count += prescribingNumberSevenTy
  3572. }
  3573. fmt.Println("local_count---------------", local_count)
  3574. fmt.Println("history_count---------------", history_count)
  3575. //如果当前出库数量大于历史出库数量则需要出库
  3576. if local_count > history_count {
  3577. //按最小单位出库
  3578. var cha_count = local_count - history_count
  3579. newadviceInfo.PrescribingNumber = float64(cha_count)
  3580. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3581. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3582. }
  3583. //如果当前出库数量小于历史出库数量则需要退库
  3584. if local_count < history_count {
  3585. var cha_count = history_count - local_count
  3586. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3587. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3588. }
  3589. if local_count == history_count {
  3590. if is_user_total == 0 {
  3591. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3592. }
  3593. }
  3594. }
  3595. //更新字典里面的库存
  3596. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3597. var sum_count int64
  3598. for _, its := range stockInfo {
  3599. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3600. if its.MaxUnit == baseDrug.MaxUnit {
  3601. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3602. }
  3603. sum_count += its.StockMaxNumber + its.StockMinNumber
  3604. }
  3605. //更新基础库存
  3606. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3607. //剩余库存
  3608. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3609. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3610. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3611. //创建医嘱
  3612. service.CreateHisDoctorAdviceOne(&s, tx)
  3613. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3614. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3615. if len(outInfoTwo) > 0 {
  3616. for _, item := range outInfoTwo {
  3617. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3618. }
  3619. }
  3620. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3621. if len(drugAutoDetail) > 0 {
  3622. for _, item := range drugAutoDetail {
  3623. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3624. }
  3625. }
  3626. }
  3627. }
  3628. }
  3629. //记录日志
  3630. byterequest, _ := json.Marshal(s)
  3631. adviceLog := models.XtDoctorAdviceLog{
  3632. UserOrgId: s.UserOrgId,
  3633. PatientId: s.PatientId,
  3634. AdminUserId: adminInfo.AdminUser.Id,
  3635. Module: 1,
  3636. ErrLog: string(byterequest),
  3637. Status: 1,
  3638. Ctime: time.Now().Unix(),
  3639. Mtime: 0,
  3640. Source: "电脑端新建his医嘱",
  3641. RecordDate: s.AdviceDate,
  3642. }
  3643. service.CreateDoctorAdviceLog(adviceLog)
  3644. //存储切片中
  3645. adviceList = append(adviceList, s)
  3646. redis := service.RedisClient()
  3647. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3648. redis.Set(key, "", time.Second)
  3649. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3650. redis.Set(keyOne, "", time.Second)
  3651. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3652. redis.Set(keySeven, "", time.Second)
  3653. var randNum int
  3654. randNum = rand.Intn(10000) + 1000
  3655. timestamp := time.Now().Unix()
  3656. tempTime := time.Unix(timestamp, 0)
  3657. timeFormat := tempTime.Format("20060102150405")
  3658. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3659. //赤峰
  3660. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3661. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3662. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3663. if info.RetailPrice > 0 {
  3664. if s.DeliveryWay == "口服" {
  3665. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3666. s.Price = drug.RetailPrice
  3667. }
  3668. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3669. s.Price = info.RetailPrice
  3670. }
  3671. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3672. s.Price = info.RetailPrice
  3673. }
  3674. }
  3675. }
  3676. }
  3677. service.CreateHisDoctorAdviceOne(&s, tx)
  3678. tx.Commit()
  3679. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3680. redis.Set(keySix, "", time.Second)
  3681. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3682. redis.Set(keyFive, "", time.Second)
  3683. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3684. redis.Set(keyEight, "", time.Second)
  3685. defer redis.Close()
  3686. }
  3687. }
  3688. }
  3689. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3690. projects := items["project"].([]interface{})
  3691. if len(projects) > 0 {
  3692. for _, project := range projects {
  3693. tx := db.Begin()
  3694. // 在函数结束时处理事务回滚
  3695. defer func() {
  3696. if r := recover(); r != nil {
  3697. tx.Rollback()
  3698. }
  3699. }()
  3700. var p models.HisPrescriptionProject
  3701. p.PrescriptionId = tempPrescription.ID
  3702. p.PatientId = patient_id
  3703. p.RecordDate = theTime3.Unix()
  3704. p.Doctor = doctor_id
  3705. p.UserOrgId = adminInfo.CurrentOrgId
  3706. p.HisPatientId = his_patient_id
  3707. p.Status = 1
  3708. p.StartTime = pTime
  3709. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3710. if errcode > 0 {
  3711. tx.Rollback()
  3712. c.ServeFailJSONWithSGJErrorCode(errcode)
  3713. return
  3714. }
  3715. if p.ID == 0 {
  3716. p.IsOut = 2
  3717. }
  3718. if p.ID > 0 {
  3719. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3720. p.IsOut = projectDetail.IsOut
  3721. }
  3722. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3723. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3724. if p.Type == 3 {
  3725. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3726. if p.Price != lastWarehouse.PackingPrice {
  3727. p.Price = lastWarehouse.PackingPrice
  3728. }
  3729. if p.Price == 0 {
  3730. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3731. p.Price = lastWarehouseTwo.PackingPrice
  3732. }
  3733. if p.Unit == "" {
  3734. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3735. p.Unit = goodInfoOne.PackingUnit
  3736. }
  3737. }
  3738. }
  3739. if adminInfo.CurrentOrgId != 10206 {
  3740. if p.Type == 3 {
  3741. if p.ID == 0 {
  3742. //查询该耗材是否停用
  3743. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3744. //表示该耗材已经停用,不能保存
  3745. if goodInfoSeven.ID == 0 {
  3746. tx.Rollback()
  3747. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3748. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3749. return
  3750. }
  3751. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3752. if goodInfoOne.SumCount == 0 {
  3753. tx.Rollback()
  3754. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3755. return
  3756. }
  3757. }
  3758. if p.ID > 0 {
  3759. //查询该耗材是否停用
  3760. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3761. //表示该耗材已经停用,不能保存
  3762. if goodInfoSeven.ID == 0 {
  3763. tx.Rollback()
  3764. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3765. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3766. return
  3767. }
  3768. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3769. if goodInfoOne.SumCount == 0 {
  3770. tx.Rollback()
  3771. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3772. return
  3773. }
  3774. }
  3775. }
  3776. }
  3777. //查询保存耗材出库开关是否打开
  3778. if p.PatientId != 30038 {
  3779. //用机构ID区分
  3780. if adminInfo.CurrentOrgId != 9671 {
  3781. if goodOutConfig.IsOpen == 1 {
  3782. //耗材出库
  3783. if p.Type == 3 {
  3784. //对比当前数据和历史出库数据
  3785. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3786. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3787. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3788. ////针对康德
  3789. //if p.UserOrgId == 10164 || p.UserOrgId == 10402 {
  3790. //
  3791. // //查询耗材的总入库数量
  3792. // warehouseInfo, _ := service.GetAllWarehouseInfo(p.ProjectId, adminInfo.CurrentOrgId)
  3793. //
  3794. // //查询该耗材的总出库数量
  3795. // prescriptionGood, _ := service.GetHisPrescriptionByGoodId(p.ProjectId, adminInfo.CurrentOrgId)
  3796. //
  3797. // var all_good_count int64
  3798. //
  3799. // var prescription_count int64
  3800. // if len(warehouseInfo) > 0 {
  3801. //
  3802. // for _, item := range warehouseInfo {
  3803. // all_good_count += item.WarehousingCount
  3804. // }
  3805. // }
  3806. // if len(prescriptionGood) > 0 {
  3807. // for _, item := range prescriptionGood {
  3808. //
  3809. // hisCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3810. // prescription_count += hisCount
  3811. // }
  3812. // }
  3813. //
  3814. // //fmt.Println("prescription_count-------------------------", prescription_count)
  3815. // //fmt.Println("nowCount-------------------------", nowCount)
  3816. // //fmt.Println("all_good_count-------------------------", all_good_count)
  3817. //
  3818. // if prescription_count+nowCount > all_good_count {
  3819. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3820. // tx.Rollback()
  3821. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3822. // return
  3823. // }
  3824. //}
  3825. //如果当前处方数量大于历史数据,则需要出库
  3826. if nowCount > historyCount {
  3827. var cha_count int64
  3828. cha_count = nowCount - historyCount
  3829. timeStr := time.Now().Format("2006-01-02")
  3830. timeArr := strings.Split(timeStr, "-")
  3831. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3832. total = total + 1
  3833. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3834. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3835. number = number + total
  3836. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3837. operation_time := time.Now().Unix()
  3838. creater := c.GetAdminUserInfo().AdminUser.Id
  3839. recordDateStr := time.Now().Format("2006-01-02")
  3840. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3841. nowtime := recordDate.Unix()
  3842. warehouseOut := models.WarehouseOut{
  3843. WarehouseOutOrderNumber: warehousing_out_order,
  3844. OperationTime: operation_time,
  3845. OrgId: adminInfo.CurrentOrgId,
  3846. Creater: creater,
  3847. Ctime: time.Now().Unix(),
  3848. Status: 1,
  3849. WarehouseOutTime: nowtime,
  3850. Type: 1,
  3851. StorehouseId: storeConfig.StorehouseOutInfo,
  3852. IsCheck: 1,
  3853. IsSys: 1,
  3854. }
  3855. //查询是否生成出库单
  3856. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3857. if out.ID == 0 {
  3858. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3859. }
  3860. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3861. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3862. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3863. dialyPrepareOne := models.DialysisBeforePrepare{
  3864. GoodTypeId: goodObj.GoodTypeId,
  3865. GoodId: p.ProjectId,
  3866. PatientId: p.PatientId,
  3867. RecordDate: p.RecordDate,
  3868. UserOrgId: adminInfo.CurrentOrgId,
  3869. Count: cha_count,
  3870. Ctime: time.Now().Unix(),
  3871. Creater: creater,
  3872. Status: 1,
  3873. StorehouseId: houseConfig.StorehouseOutInfo,
  3874. ProjectId: p.ID,
  3875. }
  3876. //出库
  3877. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3878. }
  3879. //如果当前处方数量小于历史数据,怎需要退库
  3880. if nowCount < historyCount {
  3881. var cha_count int64
  3882. cha_count = historyCount - nowCount
  3883. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3884. creater := c.GetAdminUserInfo().AdminUser.Id
  3885. newPrescriptionProject := &models.HisPrescriptionProject{
  3886. ID: p.ID,
  3887. ProjectId: p.ProjectId,
  3888. Price: p.Price,
  3889. UserOrgId: p.UserOrgId,
  3890. Status: 1,
  3891. Ctime: time.Now().Unix(),
  3892. Mtime: time.Now().Unix(),
  3893. PatientId: p.PatientId,
  3894. HisPatientId: p.HisPatientId,
  3895. RecordDate: p.RecordDate,
  3896. PrescriptionId: p.PrescriptionId,
  3897. Count: p.Count,
  3898. FeedetlSn: p.FeedetlSn,
  3899. MedListCodg: p.MedListCodg,
  3900. SingleDose: p.SingleDose,
  3901. DeliveryWay: p.DeliveryWay,
  3902. ExecutionFrequency: p.ExecutionFrequency,
  3903. Day: p.Day,
  3904. HisProject: models.HisProject{},
  3905. GoodInfo: models.GoodInfo{},
  3906. Remark: p.Remark,
  3907. Unit: p.Unit,
  3908. Type: p.Type,
  3909. Doctor: p.Doctor,
  3910. ExecutionTime: p.ExecutionTime,
  3911. ExecutionStaff: p.ExecutionStaff,
  3912. ExecutionState: p.ExecutionState,
  3913. CheckTime: p.CheckTime,
  3914. CheckState: p.CheckState,
  3915. Checker: p.Checker,
  3916. StartTime: p.StartTime,
  3917. TeamId: p.TeamId,
  3918. XtHisProjectTeam: models.XtHisProjectTeam{},
  3919. FrequencyType: p.FrequencyType,
  3920. DayCount: p.DayCount,
  3921. WeekDay: p.WeekDay,
  3922. IsCheckTeam: p.IsCheckTeam,
  3923. HisOrderInfo: models.HisOrderInfo{},
  3924. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3925. IsOut: p.IsOut,
  3926. YbSyncStatus: p.YbSyncStatus,
  3927. }
  3928. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3929. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3930. }
  3931. if nowCount == historyCount {
  3932. if historyCount == 0 {
  3933. recordDateStr := time.Now().Format("2006-01-02")
  3934. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3935. nowtime := recordDate.Unix()
  3936. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3937. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3938. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3939. creater := c.GetAdminUserInfo().AdminUser.Id
  3940. dialyPrepareOne := models.DialysisBeforePrepare{
  3941. GoodTypeId: goodObj.GoodTypeId,
  3942. GoodId: p.ProjectId,
  3943. PatientId: p.PatientId,
  3944. RecordDate: p.RecordDate,
  3945. UserOrgId: adminInfo.CurrentOrgId,
  3946. Count: nowCount,
  3947. Ctime: time.Now().Unix(),
  3948. Creater: creater,
  3949. Status: 1,
  3950. StorehouseId: houseConfig.StorehouseOutInfo,
  3951. ProjectId: p.ID,
  3952. }
  3953. //出库
  3954. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3955. }
  3956. }
  3957. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3958. //查询历史出库数据
  3959. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3960. var out_count_five int64
  3961. for _, item := range flowGood {
  3962. out_count_five += item.Count
  3963. }
  3964. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3965. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3966. if out_count_five != parseIntCount {
  3967. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3968. detail := models.AutomaticReduceDetail{
  3969. WarehouseOutId: 0,
  3970. WarehouseOutOrderNumber: "",
  3971. PatientId: p.PatientId,
  3972. Ctime: time.Now().Unix(),
  3973. Mtime: 0,
  3974. Status: 1,
  3975. RecordTime: p.RecordDate,
  3976. OrgId: p.UserOrgId,
  3977. GoodId: p.ProjectId,
  3978. GoodTypeId: 0,
  3979. Count: parseIntCount,
  3980. Type: 0,
  3981. ProjectId: lastHisProject.ID,
  3982. StorehouseId: 0,
  3983. }
  3984. service.CreateNewAutoDetail(detail, tx)
  3985. }
  3986. // //查询耗材最后一次出库记录
  3987. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3988. // //查询默认出库仓库库存
  3989. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3990. // if len(wareOut) > 0 {
  3991. //
  3992. // for _, it := range wareOut {
  3993. // //回退库存
  3994. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3995. //
  3996. // //删除出库记录
  3997. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3998. //
  3999. // }
  4000. // }
  4001. //
  4002. // timeStr := time.Now().Format("2006-01-02")
  4003. // timeArr := strings.Split(timeStr, "-")
  4004. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4005. //
  4006. // total = total + 1
  4007. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4008. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4009. // number = number + total
  4010. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4011. //
  4012. // operation_time := time.Now().Unix()
  4013. // creater := c.GetAdminUserInfo().AdminUser.Id
  4014. //
  4015. // recordDateStr := time.Now().Format("2006-01-02")
  4016. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4017. // nowtime := recordDate.Unix()
  4018. // warehouseOut := models.WarehouseOut{
  4019. // WarehouseOutOrderNumber: warehousing_out_order,
  4020. // OperationTime: operation_time,
  4021. // OrgId: adminInfo.CurrentOrgId,
  4022. // Creater: creater,
  4023. // Ctime: time.Now().Unix(),
  4024. // Status: 1,
  4025. // WarehouseOutTime: nowtime,
  4026. // Type: 1,
  4027. // StorehouseId: storeConfig.StorehouseOutInfo,
  4028. // IsCheck: 1,
  4029. // IsSys: 1,
  4030. // }
  4031. // //查询是否生成出库单
  4032. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4033. // if out.ID == 0 {
  4034. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4035. // }
  4036. //
  4037. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4038. //
  4039. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4040. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4041. //
  4042. // dialyPrepareOne := models.DialysisBeforePrepare{
  4043. // GoodTypeId: goodObj.GoodTypeId,
  4044. // GoodId: p.ProjectId,
  4045. // PatientId: p.PatientId,
  4046. // RecordDate: p.RecordDate,
  4047. // UserOrgId: adminInfo.CurrentOrgId,
  4048. // Count: parseIntCount,
  4049. // Ctime: time.Now().Unix(),
  4050. // Creater: creater,
  4051. // Status: 1,
  4052. // StorehouseId: houseConfig.StorehouseOutInfo,
  4053. // ProjectId: lastHisProject.ID,
  4054. // }
  4055. // //判断是否是零用耗材(非零用)
  4056. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4057. //
  4058. // //查询历史出库数据
  4059. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4060. // var out_count int64
  4061. // for _, item := range flowGood {
  4062. // out_count += item.Count
  4063. // }
  4064. // //如果历史数和当前数据不想等才进行退库出库
  4065. // if out_count != parseIntCount {
  4066. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4067. //
  4068. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4069. // detail := models.AutomaticReduceDetail{
  4070. // WarehouseOutId: 0,
  4071. // WarehouseOutOrderNumber: "",
  4072. // PatientId: p.PatientId,
  4073. // Ctime: time.Now().Unix(),
  4074. // Mtime: 0,
  4075. // Status: 1,
  4076. // RecordTime: p.RecordDate,
  4077. // OrgId: p.UserOrgId,
  4078. // GoodId: p.ProjectId,
  4079. // GoodTypeId: 0,
  4080. // Count: parseIntCount,
  4081. // Type: 0,
  4082. // ProjectId: lastHisProject.ID,
  4083. // StorehouseId: 0,
  4084. // }
  4085. //
  4086. // service.CreateNewAutoDetail(detail, tx)
  4087. //
  4088. // //查询剩余库存
  4089. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4090. // var sum_count int64
  4091. // for _, item := range goodList {
  4092. // sum_count += item.StockCount
  4093. // }
  4094. //
  4095. // //更新剩余库存
  4096. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4097. //
  4098. // //耗材
  4099. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4100. //
  4101. // }
  4102. // //判断是否是零用耗材(零用但是是出库耗材)
  4103. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4104. //
  4105. // //查询历史出库数据
  4106. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4107. // var out_count int64
  4108. // for _, item := range flowGood {
  4109. // out_count += item.Count
  4110. // }
  4111. // //如果历史数和当前数据不想等才进行退库出库
  4112. // if out_count != parseIntCount {
  4113. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4114. //
  4115. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4116. // detail := models.AutomaticReduceDetail{
  4117. // WarehouseOutId: 0,
  4118. // WarehouseOutOrderNumber: "",
  4119. // PatientId: p.PatientId,
  4120. // Ctime: time.Now().Unix(),
  4121. // Mtime: 0,
  4122. // Status: 1,
  4123. // RecordTime: p.RecordDate,
  4124. // OrgId: p.UserOrgId,
  4125. // GoodId: p.ProjectId,
  4126. // GoodTypeId: 0,
  4127. // Count: parseIntCount,
  4128. // Type: 0,
  4129. // ProjectId: p.ID,
  4130. // StorehouseId: 0,
  4131. // }
  4132. //
  4133. // service.CreateNewAutoDetail(detail, tx)
  4134. //
  4135. // //查询剩余库存
  4136. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4137. // var sum_count int64
  4138. // for _, item := range goodList {
  4139. // sum_count += item.StockCount
  4140. // }
  4141. //
  4142. // //更新剩余库存
  4143. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4144. //
  4145. // //耗材
  4146. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4147. // }
  4148. //
  4149. // }
  4150. //
  4151. // }
  4152. //
  4153. //}
  4154. //记录日志
  4155. byterequest, _ := json.Marshal(p)
  4156. adviceLog := models.XtDoctorAdviceLog{
  4157. UserOrgId: p.UserOrgId,
  4158. PatientId: p.PatientId,
  4159. AdminUserId: adminInfo.AdminUser.Id,
  4160. Module: 1,
  4161. ErrLog: string(byterequest),
  4162. Status: 1,
  4163. Ctime: time.Now().Unix(),
  4164. Mtime: 0,
  4165. Source: "电脑端新建his项目",
  4166. RecordDate: p.RecordDate,
  4167. }
  4168. service.CreateDoctorAdviceLog(adviceLog)
  4169. projectList = append(projectList, p)
  4170. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4171. //新增或者编辑项目,修改对应的标签数据
  4172. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4173. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4174. var label models.HisLabelPrintInfo
  4175. project, _ := service.GetProjectDetail(p.ProjectId)
  4176. if project.CostClassify == 3 { //类别为检验检查
  4177. if p.TeamId > 0 { //检验检查组套
  4178. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4179. if tempLabel.ID == 0 {
  4180. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4181. label.Number = tempPrescription.PrescriptionNumber
  4182. label.ProjectId = project.ID
  4183. label.Status = 1
  4184. label.IsPrint = 2
  4185. label.DoctorId = info.DoctorId
  4186. label.UserOrgId = p.UserOrgId
  4187. label.PatientId = patient_id
  4188. label.RecordDate = recordDateTime
  4189. label.Ctime = time.Now().Unix()
  4190. label.Mtime = time.Now().Unix()
  4191. label.ItemId = p.TeamId
  4192. label.FeedetlSn = p.FeedetlSn
  4193. label.PProjectId = p.ID
  4194. label.ProjectName = team.ProjectTeam
  4195. label.PatientName = patient.Name
  4196. service.CreateNewHisLabelRecord(&label, tx)
  4197. }
  4198. } else { //单条检验检查项目
  4199. label.Number = tempPrescription.PrescriptionNumber
  4200. label.ProjectId = project.ID
  4201. label.Status = 1
  4202. label.DoctorId = info.DoctorId
  4203. label.UserOrgId = p.UserOrgId
  4204. label.PatientId = patient_id
  4205. label.RecordDate = recordDateTime
  4206. label.IsPrint = 2
  4207. label.Ctime = time.Now().Unix()
  4208. label.Mtime = time.Now().Unix()
  4209. label.FeedetlSn = p.FeedetlSn
  4210. label.PProjectId = p.ID
  4211. label.ItemId = p.TeamId
  4212. label.ProjectName = project.ProjectName
  4213. label.PatientName = patient.Name
  4214. service.CreateNewHisLabelRecord(&label, tx)
  4215. }
  4216. }
  4217. }
  4218. }
  4219. }
  4220. }
  4221. }
  4222. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4223. //耗材出库
  4224. if p.Type == 3 {
  4225. //对比当前数据和历史出库数据
  4226. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4227. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4228. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4229. //如果当前处方数量大于历史数据,则需要出库
  4230. if nowCount > historyCount {
  4231. var cha_count int64
  4232. cha_count = nowCount - historyCount
  4233. timeStr := time.Now().Format("2006-01-02")
  4234. timeArr := strings.Split(timeStr, "-")
  4235. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4236. total = total + 1
  4237. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4238. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4239. number = number + total
  4240. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4241. operation_time := time.Now().Unix()
  4242. creater := c.GetAdminUserInfo().AdminUser.Id
  4243. recordDateStr := time.Now().Format("2006-01-02")
  4244. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4245. nowtime := recordDate.Unix()
  4246. warehouseOut := models.WarehouseOut{
  4247. WarehouseOutOrderNumber: warehousing_out_order,
  4248. OperationTime: operation_time,
  4249. OrgId: adminInfo.CurrentOrgId,
  4250. Creater: creater,
  4251. Ctime: time.Now().Unix(),
  4252. Status: 1,
  4253. WarehouseOutTime: nowtime,
  4254. Type: 1,
  4255. StorehouseId: storeConfig.StorehouseOutInfo,
  4256. IsCheck: 1,
  4257. IsSys: 1,
  4258. }
  4259. //查询是否生成出库单
  4260. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4261. if out.ID == 0 {
  4262. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4263. }
  4264. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4265. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4266. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4267. dialyPrepareOne := models.DialysisBeforePrepare{
  4268. GoodTypeId: goodObj.GoodTypeId,
  4269. GoodId: p.ProjectId,
  4270. PatientId: p.PatientId,
  4271. RecordDate: p.RecordDate,
  4272. UserOrgId: adminInfo.CurrentOrgId,
  4273. Count: cha_count,
  4274. Ctime: time.Now().Unix(),
  4275. Creater: creater,
  4276. Status: 1,
  4277. StorehouseId: houseConfig.StorehouseOutInfo,
  4278. ProjectId: p.ID,
  4279. }
  4280. //出库
  4281. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4282. }
  4283. //如果当前处方数量小于历史数据,怎需要退库
  4284. if nowCount < historyCount {
  4285. var cha_count int64
  4286. cha_count = historyCount - nowCount
  4287. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4288. creater := c.GetAdminUserInfo().AdminUser.Id
  4289. newPrescriptionProject := &models.HisPrescriptionProject{
  4290. ID: p.ID,
  4291. ProjectId: p.ProjectId,
  4292. Price: p.Price,
  4293. UserOrgId: p.UserOrgId,
  4294. Status: 1,
  4295. Ctime: time.Now().Unix(),
  4296. Mtime: time.Now().Unix(),
  4297. PatientId: p.PatientId,
  4298. HisPatientId: p.HisPatientId,
  4299. RecordDate: p.RecordDate,
  4300. PrescriptionId: p.PrescriptionId,
  4301. Count: p.Count,
  4302. FeedetlSn: p.FeedetlSn,
  4303. MedListCodg: p.MedListCodg,
  4304. SingleDose: p.SingleDose,
  4305. DeliveryWay: p.DeliveryWay,
  4306. ExecutionFrequency: p.ExecutionFrequency,
  4307. Day: p.Day,
  4308. HisProject: models.HisProject{},
  4309. GoodInfo: models.GoodInfo{},
  4310. Remark: p.Remark,
  4311. Unit: p.Unit,
  4312. Type: p.Type,
  4313. Doctor: p.Doctor,
  4314. ExecutionTime: p.ExecutionTime,
  4315. ExecutionStaff: p.ExecutionStaff,
  4316. ExecutionState: p.ExecutionState,
  4317. CheckTime: p.CheckTime,
  4318. CheckState: p.CheckState,
  4319. Checker: p.Checker,
  4320. StartTime: p.StartTime,
  4321. TeamId: p.TeamId,
  4322. XtHisProjectTeam: models.XtHisProjectTeam{},
  4323. FrequencyType: p.FrequencyType,
  4324. DayCount: p.DayCount,
  4325. WeekDay: p.WeekDay,
  4326. IsCheckTeam: p.IsCheckTeam,
  4327. HisOrderInfo: models.HisOrderInfo{},
  4328. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4329. IsOut: p.IsOut,
  4330. YbSyncStatus: p.YbSyncStatus,
  4331. }
  4332. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4333. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4334. }
  4335. if nowCount == historyCount {
  4336. if historyCount == 0 {
  4337. recordDateStr := time.Now().Format("2006-01-02")
  4338. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4339. nowtime := recordDate.Unix()
  4340. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4341. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4342. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4343. creater := c.GetAdminUserInfo().AdminUser.Id
  4344. dialyPrepareOne := models.DialysisBeforePrepare{
  4345. GoodTypeId: goodObj.GoodTypeId,
  4346. GoodId: p.ProjectId,
  4347. PatientId: p.PatientId,
  4348. RecordDate: p.RecordDate,
  4349. UserOrgId: adminInfo.CurrentOrgId,
  4350. Count: nowCount,
  4351. Ctime: time.Now().Unix(),
  4352. Creater: creater,
  4353. Status: 1,
  4354. StorehouseId: houseConfig.StorehouseOutInfo,
  4355. ProjectId: p.ID,
  4356. }
  4357. //出库
  4358. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4359. }
  4360. }
  4361. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4362. //查询历史出库数据
  4363. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4364. var out_count_five int64
  4365. for _, item := range flowGood {
  4366. out_count_five += item.Count
  4367. }
  4368. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4369. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4370. if out_count_five != parseIntCount {
  4371. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4372. detail := models.AutomaticReduceDetail{
  4373. WarehouseOutId: 0,
  4374. WarehouseOutOrderNumber: "",
  4375. PatientId: p.PatientId,
  4376. Ctime: time.Now().Unix(),
  4377. Mtime: 0,
  4378. Status: 1,
  4379. RecordTime: p.RecordDate,
  4380. OrgId: p.UserOrgId,
  4381. GoodId: p.ProjectId,
  4382. GoodTypeId: 0,
  4383. Count: parseIntCount,
  4384. Type: 0,
  4385. ProjectId: lastHisProject.ID,
  4386. StorehouseId: 0,
  4387. }
  4388. service.CreateNewAutoDetail(detail, tx)
  4389. }
  4390. // //查询耗材最后一次出库记录
  4391. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4392. // //查询默认出库仓库库存
  4393. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4394. // if len(wareOut) > 0 {
  4395. //
  4396. // for _, it := range wareOut {
  4397. // //回退库存
  4398. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4399. //
  4400. // //删除出库记录
  4401. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4402. //
  4403. // }
  4404. // }
  4405. //
  4406. // timeStr := time.Now().Format("2006-01-02")
  4407. // timeArr := strings.Split(timeStr, "-")
  4408. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4409. //
  4410. // total = total + 1
  4411. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4412. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4413. // number = number + total
  4414. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4415. //
  4416. // operation_time := time.Now().Unix()
  4417. // creater := c.GetAdminUserInfo().AdminUser.Id
  4418. //
  4419. // recordDateStr := time.Now().Format("2006-01-02")
  4420. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4421. // nowtime := recordDate.Unix()
  4422. // warehouseOut := models.WarehouseOut{
  4423. // WarehouseOutOrderNumber: warehousing_out_order,
  4424. // OperationTime: operation_time,
  4425. // OrgId: adminInfo.CurrentOrgId,
  4426. // Creater: creater,
  4427. // Ctime: time.Now().Unix(),
  4428. // Status: 1,
  4429. // WarehouseOutTime: nowtime,
  4430. // Type: 1,
  4431. // StorehouseId: storeConfig.StorehouseOutInfo,
  4432. // IsCheck: 1,
  4433. // IsSys: 1,
  4434. // }
  4435. // //查询是否生成出库单
  4436. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4437. // if out.ID == 0 {
  4438. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4439. // }
  4440. //
  4441. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4442. //
  4443. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4444. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4445. //
  4446. // dialyPrepareOne := models.DialysisBeforePrepare{
  4447. // GoodTypeId: goodObj.GoodTypeId,
  4448. // GoodId: p.ProjectId,
  4449. // PatientId: p.PatientId,
  4450. // RecordDate: p.RecordDate,
  4451. // UserOrgId: adminInfo.CurrentOrgId,
  4452. // Count: parseIntCount,
  4453. // Ctime: time.Now().Unix(),
  4454. // Creater: creater,
  4455. // Status: 1,
  4456. // StorehouseId: houseConfig.StorehouseOutInfo,
  4457. // ProjectId: lastHisProject.ID,
  4458. // }
  4459. // //判断是否是零用耗材(非零用)
  4460. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4461. //
  4462. // //查询历史出库数据
  4463. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4464. // var out_count int64
  4465. // for _, item := range flowGood {
  4466. // out_count += item.Count
  4467. // }
  4468. // //如果历史数和当前数据不想等才进行退库出库
  4469. // if out_count != parseIntCount {
  4470. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4471. //
  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. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4494. // var sum_count int64
  4495. // for _, item := range goodList {
  4496. // sum_count += item.StockCount
  4497. // }
  4498. //
  4499. // //更新剩余库存
  4500. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4501. //
  4502. // //耗材
  4503. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4504. //
  4505. // }
  4506. // //判断是否是零用耗材(零用但是是出库耗材)
  4507. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4508. //
  4509. // //查询历史出库数据
  4510. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4511. // var out_count int64
  4512. // for _, item := range flowGood {
  4513. // out_count += item.Count
  4514. // }
  4515. // //如果历史数和当前数据不想等才进行退库出库
  4516. // if out_count != parseIntCount {
  4517. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4518. //
  4519. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4520. // detail := models.AutomaticReduceDetail{
  4521. // WarehouseOutId: 0,
  4522. // WarehouseOutOrderNumber: "",
  4523. // PatientId: p.PatientId,
  4524. // Ctime: time.Now().Unix(),
  4525. // Mtime: 0,
  4526. // Status: 1,
  4527. // RecordTime: p.RecordDate,
  4528. // OrgId: p.UserOrgId,
  4529. // GoodId: p.ProjectId,
  4530. // GoodTypeId: 0,
  4531. // Count: parseIntCount,
  4532. // Type: 0,
  4533. // ProjectId: p.ID,
  4534. // StorehouseId: 0,
  4535. // }
  4536. //
  4537. // service.CreateNewAutoDetail(detail, tx)
  4538. //
  4539. // //查询剩余库存
  4540. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4541. // var sum_count int64
  4542. // for _, item := range goodList {
  4543. // sum_count += item.StockCount
  4544. // }
  4545. //
  4546. // //更新剩余库存
  4547. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4548. //
  4549. // //耗材
  4550. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4551. // }
  4552. //
  4553. // }
  4554. //
  4555. // }
  4556. //
  4557. //}
  4558. //记录日志
  4559. byterequest, _ := json.Marshal(p)
  4560. adviceLog := models.XtDoctorAdviceLog{
  4561. UserOrgId: p.UserOrgId,
  4562. PatientId: p.PatientId,
  4563. AdminUserId: adminInfo.AdminUser.Id,
  4564. Module: 1,
  4565. ErrLog: string(byterequest),
  4566. Status: 1,
  4567. Ctime: time.Now().Unix(),
  4568. Mtime: 0,
  4569. Source: "电脑端新建his项目",
  4570. RecordDate: p.RecordDate,
  4571. }
  4572. service.CreateDoctorAdviceLog(adviceLog)
  4573. projectList = append(projectList, p)
  4574. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4575. //新增或者编辑项目,修改对应的标签数据
  4576. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4577. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4578. var label models.HisLabelPrintInfo
  4579. project, _ := service.GetProjectDetail(p.ProjectId)
  4580. if project.CostClassify == 3 { //类别为检验检查
  4581. if p.TeamId > 0 { //检验检查组套
  4582. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4583. if tempLabel.ID == 0 {
  4584. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4585. label.Number = tempPrescription.PrescriptionNumber
  4586. label.ProjectId = project.ID
  4587. label.Status = 1
  4588. label.IsPrint = 2
  4589. label.DoctorId = info.DoctorId
  4590. label.UserOrgId = p.UserOrgId
  4591. label.PatientId = patient_id
  4592. label.RecordDate = recordDateTime
  4593. label.Ctime = time.Now().Unix()
  4594. label.Mtime = time.Now().Unix()
  4595. label.ItemId = p.TeamId
  4596. label.FeedetlSn = p.FeedetlSn
  4597. label.PProjectId = p.ID
  4598. label.ProjectName = team.ProjectTeam
  4599. label.PatientName = patient.Name
  4600. service.CreateNewHisLabelRecord(&label, tx)
  4601. }
  4602. } else { //单条检验检查项目
  4603. label.Number = tempPrescription.PrescriptionNumber
  4604. label.ProjectId = project.ID
  4605. label.Status = 1
  4606. label.DoctorId = info.DoctorId
  4607. label.UserOrgId = p.UserOrgId
  4608. label.PatientId = patient_id
  4609. label.RecordDate = recordDateTime
  4610. label.IsPrint = 2
  4611. label.Ctime = time.Now().Unix()
  4612. label.Mtime = time.Now().Unix()
  4613. label.FeedetlSn = p.FeedetlSn
  4614. label.PProjectId = p.ID
  4615. label.ItemId = p.TeamId
  4616. label.ProjectName = project.ProjectName
  4617. label.PatientName = patient.Name
  4618. service.CreateNewHisLabelRecord(&label, tx)
  4619. }
  4620. }
  4621. }
  4622. }
  4623. }
  4624. }
  4625. }
  4626. //插入检验数据
  4627. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4628. //新增或者编辑项目,修改对应的标签数据
  4629. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4630. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4631. var label models.HisLabelPrintInfo
  4632. project, _ := service.GetProjectDetail(p.ProjectId)
  4633. if project.CostClassify == 3 { //类别为检验检查
  4634. if p.TeamId > 0 { //检验检查组套
  4635. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4636. if tempLabel.ID == 0 {
  4637. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4638. label.Number = tempPrescription.PrescriptionNumber
  4639. label.ProjectId = project.ID
  4640. label.Status = 1
  4641. label.IsPrint = 2
  4642. label.DoctorId = info.DoctorId
  4643. label.UserOrgId = p.UserOrgId
  4644. label.PatientId = patient_id
  4645. label.RecordDate = recordDateTime
  4646. label.Ctime = time.Now().Unix()
  4647. label.Mtime = time.Now().Unix()
  4648. label.ItemId = p.TeamId
  4649. label.FeedetlSn = p.FeedetlSn
  4650. label.PProjectId = p.ID
  4651. label.ProjectName = team.ProjectTeam
  4652. label.PatientName = patient.Name
  4653. service.CreateHisLabelRecord(&label)
  4654. }
  4655. } else { //单条检验检查项目
  4656. label.Number = tempPrescription.PrescriptionNumber
  4657. label.ProjectId = project.ID
  4658. label.Status = 1
  4659. label.DoctorId = info.DoctorId
  4660. label.UserOrgId = p.UserOrgId
  4661. label.PatientId = patient_id
  4662. label.RecordDate = recordDateTime
  4663. label.IsPrint = 2
  4664. label.Ctime = time.Now().Unix()
  4665. label.Mtime = time.Now().Unix()
  4666. label.FeedetlSn = p.FeedetlSn
  4667. label.PProjectId = p.ID
  4668. label.ItemId = p.TeamId
  4669. label.ProjectName = project.ProjectName
  4670. label.PatientName = patient.Name
  4671. service.CreateHisLabelRecord(&label)
  4672. }
  4673. }
  4674. }
  4675. }
  4676. service.CreateNewHisProjectTwo(&p, tx)
  4677. var randNum int
  4678. randNum = rand.Intn(10000) + 1000
  4679. timestamp := time.Now().Unix()
  4680. tempTime := time.Unix(timestamp, 0)
  4681. timeFormat := tempTime.Format("20060102150405")
  4682. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4683. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4684. if goodBase.ID > 0 {
  4685. tx.Rollback()
  4686. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4687. return
  4688. }
  4689. service.CreateNewHisProjectTwo(&p, tx)
  4690. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4691. //查询剩余库存
  4692. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4693. var sum_count int64
  4694. for _, item := range goodList {
  4695. sum_count += item.StockCount
  4696. }
  4697. //更新剩余库存
  4698. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4699. //耗材
  4700. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4701. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4702. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4703. if len(outInfoTwo) > 0 {
  4704. for _, item := range outInfoTwo {
  4705. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4706. }
  4707. }
  4708. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4709. if len(drugAutoDetail) > 0 {
  4710. for _, item := range drugAutoDetail {
  4711. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4712. }
  4713. }
  4714. tx.Commit()
  4715. }
  4716. }
  4717. }
  4718. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4719. // addition := items["addition"].([]interface{})
  4720. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4721. // ctime := time.Now().Unix()
  4722. // mtime := ctime
  4723. // if len(addition) > 0 {
  4724. // for _, item := range addition {
  4725. // var s models.HisAdditionalCharge
  4726. // s.PrescriptionId = tempPrescription.ID
  4727. // s.Status = 1
  4728. // s.UserOrgId = adminInfo.CurrentOrgId
  4729. // s.RecordDate = recordDateTime
  4730. // s.CreatedTime = ctime
  4731. // s.UpdatedTime = mtime
  4732. // s.PatientId = patient_id
  4733. // s.HisPatientId = his_patient_id
  4734. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4735. // if errcode > 0 {
  4736. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4737. // return
  4738. // }
  4739. // service.CreateAdditionalCharge(&s)
  4740. // var randNum int
  4741. // randNum = rand.Intn(10000) + 1000
  4742. // timestamp := time.Now().Unix()
  4743. // tempTime := time.Unix(timestamp, 0)
  4744. // timeFormat := tempTime.Format("20060102150405")
  4745. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4746. // service.CreateAdditionalCharge(&s)
  4747. //
  4748. // }
  4749. // }
  4750. //}
  4751. }
  4752. }
  4753. }
  4754. tx.Commit()
  4755. if err == nil {
  4756. c.ServeSuccessJSON(map[string]interface{}{
  4757. "msg": "保存成功",
  4758. })
  4759. return
  4760. } else {
  4761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4762. return
  4763. }
  4764. } else {
  4765. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4766. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4767. var tempPrescription *models.HisPrescription
  4768. if len(prescriptions) > 0 {
  4769. for _, item := range prescriptions {
  4770. items := item.(map[string]interface{})
  4771. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4772. utils.ErrorLog("id")
  4773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4774. return
  4775. }
  4776. id := int64(items["id"].(float64))
  4777. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4778. tempPrescription = &new_prescription
  4779. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4780. utils.ErrorLog("type")
  4781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4782. return
  4783. }
  4784. types := int64(items["type"].(float64))
  4785. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4786. utils.ErrorLog("med_type")
  4787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4788. return
  4789. }
  4790. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4791. if med_type == "0" {
  4792. med_type = "14"
  4793. }
  4794. //if order_status == 0 {
  4795. // order_status = 1
  4796. //}
  4797. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4798. // utils.ErrorLog("diagnoses")
  4799. //}
  4800. diagnoses, _ := items["diagnoses"].(string)
  4801. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4802. utils.ErrorLog("pre_time")
  4803. }
  4804. preTime, _ := items["pre_time"].(string)
  4805. timeLayout := "2006-01-02"
  4806. loc, _ := time.LoadLocation("Local")
  4807. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4808. //result := strings.Split(preTime, " ")
  4809. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4810. if err != nil {
  4811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4812. return
  4813. }
  4814. pTime := theTime2.Unix()
  4815. ctime := time.Now().Unix()
  4816. if tempPrescription.ID == 0 {
  4817. prescription := &models.HisPrescription{
  4818. ID: 0,
  4819. PatientId: patient_id,
  4820. UserOrgId: adminInfo.CurrentOrgId,
  4821. RecordDate: recordDateTime,
  4822. Ctime: ctime,
  4823. Mtime: ctime,
  4824. Type: types,
  4825. Modifier: adminInfo.AdminUser.Id,
  4826. Creator: adminInfo.AdminUser.Id,
  4827. Status: 1,
  4828. Doctor: role.UserName,
  4829. HisPatientId: his_patient_id,
  4830. OrderStatus: 1,
  4831. BatchNumber: "",
  4832. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4833. PreTime: pTime,
  4834. PType: p_type,
  4835. MedType: med_type,
  4836. Diagnose: diagnoses,
  4837. }
  4838. tempPrescription = prescription
  4839. service.SaveHisPrescription(tempPrescription)
  4840. redis := service.RedisClient()
  4841. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4842. redis.Set(key, "", time.Second)
  4843. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4844. redis.Set(keyOne, "", time.Second)
  4845. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4846. redis.Set(keySeven, "", time.Second)
  4847. defer redis.Close()
  4848. } else {
  4849. tempPrescription.ID = id
  4850. tempPrescription.Type = types
  4851. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4852. tempPrescription.Mtime = time.Now().Unix()
  4853. tempPrescription.Doctor = role.UserName
  4854. //tempPrescription.OrderStatus = order_status
  4855. tempPrescription.PreTime = pTime
  4856. tempPrescription.MedType = med_type
  4857. tempPrescription.Diagnose = diagnoses
  4858. service.SaveHisPrescription(tempPrescription)
  4859. redis := service.RedisClient()
  4860. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4861. redis.Set(key, "", time.Second)
  4862. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4863. redis.Set(keyOne, "", time.Second)
  4864. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4865. redis.Set(keySeven, "", time.Second)
  4866. defer redis.Close()
  4867. }
  4868. //service.SaveHisPrescription(prescription)
  4869. //更改患者挂号状态
  4870. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4871. fmt.Println("更改失败", err2)
  4872. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4873. advices := items["advices"].([]interface{})
  4874. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4875. groupNo := int64(0)
  4876. if len(advices) > 0 {
  4877. for _, advice := range advices {
  4878. var s models.HisDoctorAdviceInfo
  4879. s.PrescriptionId = tempPrescription.ID
  4880. s.AdviceType = 2
  4881. s.AdviceDoctor = doctor_id
  4882. s.StopState = 2
  4883. s.ExecutionState = 2
  4884. s.AdviceDate = theTime3.Unix()
  4885. s.Status = 1
  4886. s.UserOrgId = adminInfo.CurrentOrgId
  4887. s.RecordDate = theTime3.Unix()
  4888. s.StartTime = tempPrescription.PreTime
  4889. s.Groupno = groupNo
  4890. s.PatientId = patient_id
  4891. s.HisPatientId = his_patient_id
  4892. s.StartTime = pTime
  4893. s.IsSettle = 2
  4894. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4895. if errcode > 0 {
  4896. c.ServeFailJSONWithSGJErrorCode(errcode)
  4897. return
  4898. }
  4899. s.StartTime = pTime
  4900. var total_count int64 //处方总库存
  4901. //查询改药品信息
  4902. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4903. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4904. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4905. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4906. total_count += prescribingNumberSeven * medical.MinNumber
  4907. }
  4908. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4909. total_count += prescribingNumberSeven
  4910. }
  4911. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4912. total_count += prescribingNumberSeven
  4913. }
  4914. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4915. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4916. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4917. if s.Price != lastWarehouse.RetailPrice {
  4918. s.Price = lastWarehouse.RetailPrice
  4919. }
  4920. if s.Price == 0 {
  4921. if lastWarehouse.ID == 0 {
  4922. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4923. s.Price = lastWarehouseTwo.RetailPrice
  4924. }
  4925. }
  4926. }
  4927. if adminInfo.CurrentOrgId != 10206 {
  4928. if s.ID == 0 {
  4929. //查询改药品是否已经停用
  4930. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4931. if base.ID > 0 {
  4932. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4933. return
  4934. }
  4935. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4936. if drugMedical.SumCount == 0 {
  4937. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4938. return
  4939. }
  4940. }
  4941. }
  4942. //赤峰
  4943. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4944. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4945. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4946. if info.RetailPrice > 0 {
  4947. if s.DeliveryWay == "口服" {
  4948. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4949. s.Price = drug.RetailPrice
  4950. }
  4951. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4952. s.Price = info.RetailPrice
  4953. }
  4954. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4955. s.Price = info.RetailPrice
  4956. }
  4957. }
  4958. }
  4959. }
  4960. service.CreateHisDoctorAdvice(&s)
  4961. //记录日志
  4962. byterequest, _ := json.Marshal(s)
  4963. adviceLog := models.XtDoctorAdviceLog{
  4964. UserOrgId: s.UserOrgId,
  4965. PatientId: s.PatientId,
  4966. AdminUserId: adminInfo.AdminUser.Id,
  4967. Module: 1,
  4968. ErrLog: string(byterequest),
  4969. Status: 1,
  4970. Ctime: time.Now().Unix(),
  4971. Mtime: 0,
  4972. Source: "电脑端新建his医嘱",
  4973. RecordDate: s.AdviceDate,
  4974. }
  4975. service.CreateDoctorAdviceLog(adviceLog)
  4976. //存储切片中
  4977. adviceList = append(adviceList, s)
  4978. redis := service.RedisClient()
  4979. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4980. redis.Set(key, "", time.Second)
  4981. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4982. redis.Set(keyOne, "", time.Second)
  4983. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4984. redis.Set(keySeven, "", time.Second)
  4985. var randNum int
  4986. randNum = rand.Intn(10000) + 1000
  4987. timestamp := time.Now().Unix()
  4988. tempTime := time.Unix(timestamp, 0)
  4989. timeFormat := tempTime.Format("20060102150405")
  4990. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4991. service.CreateHisDoctorAdvice(&s)
  4992. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4993. redis.Set(keySix, "", time.Second)
  4994. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4995. redis.Set(keyFive, "", time.Second)
  4996. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4997. redis.Set(keyEight, "", time.Second)
  4998. defer redis.Close()
  4999. }
  5000. }
  5001. }
  5002. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5003. projects := items["project"].([]interface{})
  5004. if len(projects) > 0 {
  5005. for _, project := range projects {
  5006. var p models.HisPrescriptionProject
  5007. p.PrescriptionId = tempPrescription.ID
  5008. p.PatientId = patient_id
  5009. p.RecordDate = theTime3.Unix()
  5010. p.Doctor = doctor_id
  5011. p.UserOrgId = adminInfo.CurrentOrgId
  5012. p.HisPatientId = his_patient_id
  5013. p.Status = 1
  5014. p.StartTime = pTime
  5015. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  5016. if errcode > 0 {
  5017. c.ServeFailJSONWithSGJErrorCode(errcode)
  5018. return
  5019. }
  5020. if p.ID == 0 {
  5021. p.IsOut = 2
  5022. }
  5023. if p.ID > 0 {
  5024. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5025. p.IsOut = projectDetail.IsOut
  5026. }
  5027. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5028. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5029. if p.Type == 3 {
  5030. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5031. if p.Price != lastWarehouse.PackingPrice {
  5032. p.Price = lastWarehouse.PackingPrice
  5033. }
  5034. if p.Price == 0 {
  5035. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5036. p.Price = lastWarehouseTwo.PackingPrice
  5037. }
  5038. if p.Unit == "" {
  5039. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5040. p.Unit = goodInfoOne.PackingUnit
  5041. }
  5042. }
  5043. }
  5044. if adminInfo.CurrentOrgId != 10206 {
  5045. if p.Type == 3 {
  5046. if p.ID == 0 {
  5047. //查询该耗材是否停用
  5048. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5049. //表示该耗材已经停用,不能保存
  5050. if goodInfoSeven.ID == 0 {
  5051. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5052. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5053. return
  5054. }
  5055. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5056. if goodInfoOne.SumCount == 0 {
  5057. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5058. return
  5059. }
  5060. }
  5061. }
  5062. }
  5063. service.CreateHisProjectTwo(&p)
  5064. //记录日志
  5065. byterequest, _ := json.Marshal(p)
  5066. adviceLog := models.XtDoctorAdviceLog{
  5067. UserOrgId: p.UserOrgId,
  5068. PatientId: p.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: p.RecordDate,
  5077. }
  5078. service.CreateDoctorAdviceLog(adviceLog)
  5079. projectList = append(projectList, p)
  5080. var randNum int
  5081. randNum = rand.Intn(10000) + 1000
  5082. timestamp := time.Now().Unix()
  5083. tempTime := time.Unix(timestamp, 0)
  5084. timeFormat := tempTime.Format("20060102150405")
  5085. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  5086. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  5087. //新增或者编辑项目,修改对应的标签数据
  5088. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  5089. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  5090. var label models.HisLabelPrintInfo
  5091. project, _ := service.GetProjectDetail(p.ProjectId)
  5092. if project.CostClassify == 3 { //类别为检验检查
  5093. if p.TeamId > 0 { //检验检查组套
  5094. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  5095. if tempLabel.ID == 0 {
  5096. team, _ := service.GetProjectTeamDetail(p.TeamId)
  5097. label.Number = tempPrescription.PrescriptionNumber
  5098. label.ProjectId = project.ID
  5099. label.Status = 1
  5100. label.IsPrint = 2
  5101. label.DoctorId = info.DoctorId
  5102. label.UserOrgId = p.UserOrgId
  5103. label.PatientId = patient_id
  5104. label.RecordDate = recordDateTime
  5105. label.Ctime = time.Now().Unix()
  5106. label.Mtime = time.Now().Unix()
  5107. label.ItemId = p.TeamId
  5108. label.FeedetlSn = p.FeedetlSn
  5109. label.PProjectId = p.ID
  5110. label.ProjectName = team.ProjectTeam
  5111. label.PatientName = patient.Name
  5112. service.CreateHisLabelRecord(&label)
  5113. }
  5114. } else { //单条检验检查项目
  5115. label.Number = tempPrescription.PrescriptionNumber
  5116. label.ProjectId = project.ID
  5117. label.Status = 1
  5118. label.DoctorId = info.DoctorId
  5119. label.UserOrgId = p.UserOrgId
  5120. label.PatientId = patient_id
  5121. label.RecordDate = recordDateTime
  5122. label.IsPrint = 2
  5123. label.Ctime = time.Now().Unix()
  5124. label.Mtime = time.Now().Unix()
  5125. label.FeedetlSn = p.FeedetlSn
  5126. label.PProjectId = p.ID
  5127. label.ItemId = p.TeamId
  5128. label.ProjectName = project.ProjectName
  5129. label.PatientName = patient.Name
  5130. service.CreateHisLabelRecord(&label)
  5131. }
  5132. }
  5133. }
  5134. }
  5135. service.SaveHisProjectTwo(&p)
  5136. }
  5137. }
  5138. }
  5139. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5140. // addition := items["addition"].([]interface{})
  5141. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5142. // ctime := time.Now().Unix()
  5143. // mtime := ctime
  5144. // if len(addition) > 0 {
  5145. // for _, item := range addition {
  5146. // var s models.HisAdditionalCharge
  5147. // s.PrescriptionId = tempPrescription.ID
  5148. // s.Status = 1
  5149. // s.UserOrgId = adminInfo.CurrentOrgId
  5150. // s.RecordDate = recordDateTime
  5151. // s.CreatedTime = ctime
  5152. // s.UpdatedTime = mtime
  5153. // s.PatientId = patient_id
  5154. // s.HisPatientId = his_patient_id
  5155. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5156. // if errcode > 0 {
  5157. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5158. // return
  5159. // }
  5160. // service.CreateAdditionalCharge(&s)
  5161. // var randNum int
  5162. // randNum = rand.Intn(10000) + 1000
  5163. // timestamp := time.Now().Unix()
  5164. // tempTime := time.Unix(timestamp, 0)
  5165. // timeFormat := tempTime.Format("20060102150405")
  5166. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5167. // service.CreateAdditionalCharge(&s)
  5168. //
  5169. // }
  5170. // }
  5171. //}
  5172. }
  5173. }
  5174. //查询今日该患者开的药品处方
  5175. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5176. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5177. //药品出库
  5178. if drugOutConfig.IsOpen == 1 {
  5179. for _, item := range hisdoctorlist {
  5180. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5181. // 查询该药品最后一次出库记录
  5182. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5183. if len(druginfo) > 0 {
  5184. //回退库存
  5185. for _, it := range druginfo {
  5186. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5187. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5188. }
  5189. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5190. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5191. }
  5192. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5193. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5194. }
  5195. }
  5196. }
  5197. //删除记录
  5198. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5199. //查询最后一次数据
  5200. if drugOutConfig.IsOpen == 1 {
  5201. //出库
  5202. if drug.IsUse == 2 {
  5203. creater := adminInfo.AdminUser.Id
  5204. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5205. }
  5206. //更新字典里面的库存
  5207. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5208. var sum_count int64
  5209. for _, its := range stockInfo {
  5210. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5211. if its.MaxUnit == baseDrug.MaxUnit {
  5212. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5213. }
  5214. sum_count += its.StockMaxNumber + its.StockMinNumber
  5215. }
  5216. //更新基础库存
  5217. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5218. //剩余库存
  5219. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5220. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5221. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5222. }
  5223. }
  5224. }
  5225. //耗材保存处方出库
  5226. if goodOutConfig.IsOpen == 1 {
  5227. //查询今日耗材出库数量
  5228. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5229. for _, item := range hisgoodlist {
  5230. //查询历史出库数据
  5231. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5232. var out_count_five int64
  5233. for _, item := range flowGood {
  5234. out_count_five += item.Count
  5235. }
  5236. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5237. if out_count_five != parseIntCount {
  5238. //查询耗材最后一次出库记录
  5239. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5240. //查询默认出库仓库库存
  5241. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5242. if len(wareOut) > 0 {
  5243. for _, it := range wareOut {
  5244. //回退库存
  5245. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5246. //删除出库记录
  5247. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5248. }
  5249. }
  5250. timeStr := time.Now().Format("2006-01-02")
  5251. timeArr := strings.Split(timeStr, "-")
  5252. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5253. total = total + 1
  5254. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5255. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5256. number = number + total
  5257. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5258. operation_time := time.Now().Unix()
  5259. creater := c.GetAdminUserInfo().AdminUser.Id
  5260. recordDateStr := time.Now().Format("2006-01-02")
  5261. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5262. nowtime := recordDate.Unix()
  5263. warehouseOut := models.WarehouseOut{
  5264. WarehouseOutOrderNumber: warehousing_out_order,
  5265. OperationTime: operation_time,
  5266. OrgId: adminInfo.CurrentOrgId,
  5267. Creater: creater,
  5268. Ctime: time.Now().Unix(),
  5269. Status: 1,
  5270. WarehouseOutTime: nowtime,
  5271. Type: 1,
  5272. StorehouseId: storeConfig.StorehouseOutInfo,
  5273. IsCheck: 1,
  5274. IsSys: 1,
  5275. }
  5276. //查询是否生成出库单
  5277. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5278. if out.ID == 0 {
  5279. service.AddSigleWarehouseOutOne(&warehouseOut)
  5280. }
  5281. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5282. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5283. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5284. dialyPrepareOne := models.DialysisBeforePrepare{
  5285. GoodTypeId: goodObj.GoodTypeId,
  5286. GoodId: item.ProjectId,
  5287. PatientId: item.PatientId,
  5288. RecordDate: item.RecordDate,
  5289. UserOrgId: adminInfo.CurrentOrgId,
  5290. Count: parseIntCount,
  5291. Ctime: time.Now().Unix(),
  5292. Creater: creater,
  5293. Status: 1,
  5294. StorehouseId: houseConfig.StorehouseOutInfo,
  5295. ProjectId: item.ID,
  5296. }
  5297. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5298. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5299. //查询历史出库数据
  5300. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5301. var out_count int64
  5302. for _, item := range flowGood {
  5303. out_count += item.Count
  5304. }
  5305. //如果历史数和当前数据不想等才进行退库出库
  5306. if out_count != parseIntCount {
  5307. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5308. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5309. detail := models.AutomaticReduceDetail{
  5310. WarehouseOutId: 0,
  5311. WarehouseOutOrderNumber: "",
  5312. PatientId: item.PatientId,
  5313. Ctime: time.Now().Unix(),
  5314. Mtime: 0,
  5315. Status: 1,
  5316. RecordTime: item.RecordDate,
  5317. OrgId: item.UserOrgId,
  5318. GoodId: item.ProjectId,
  5319. GoodTypeId: 0,
  5320. Count: parseIntCount,
  5321. Type: 0,
  5322. ProjectId: item.ID,
  5323. StorehouseId: 0,
  5324. }
  5325. service.CreateAutoDetail(detail)
  5326. //查询剩余库存
  5327. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5328. var sum_count int64
  5329. for _, item := range goodList {
  5330. sum_count += item.StockCount
  5331. }
  5332. //更新剩余库存
  5333. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5334. //耗材
  5335. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5336. }
  5337. }
  5338. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5339. //查询历史出库数据
  5340. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5341. var out_count int64
  5342. for _, item := range flowGood {
  5343. out_count += item.Count
  5344. }
  5345. //如果历史数和当前数据不想等才进行退库出库
  5346. if out_count != parseIntCount {
  5347. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5348. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5349. detail := models.AutomaticReduceDetail{
  5350. WarehouseOutId: 0,
  5351. WarehouseOutOrderNumber: "",
  5352. PatientId: item.PatientId,
  5353. Ctime: time.Now().Unix(),
  5354. Mtime: 0,
  5355. Status: 1,
  5356. RecordTime: item.RecordDate,
  5357. OrgId: item.UserOrgId,
  5358. GoodId: item.ProjectId,
  5359. GoodTypeId: 0,
  5360. Count: parseIntCount,
  5361. Type: 0,
  5362. ProjectId: item.ID,
  5363. StorehouseId: 0,
  5364. }
  5365. service.CreateAutoDetail(detail)
  5366. //查询剩余库存
  5367. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5368. var sum_count int64
  5369. for _, item := range goodList {
  5370. sum_count += item.StockCount
  5371. }
  5372. //更新剩余库存
  5373. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5374. //耗材
  5375. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5376. }
  5377. }
  5378. }
  5379. }
  5380. }
  5381. ////同步到自备药
  5382. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5383. if selfPrescriptionOpen.IsOpen == 1 {
  5384. timeStr := time.Now().Format("2006-01-02")
  5385. timeArr := strings.Split(timeStr, "-")
  5386. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5387. total = total + 1
  5388. operation_time := time.Now().Unix()
  5389. creater := adminInfo.AdminUser.Id
  5390. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5391. warehousing := models.XtSelfDrugWarehouse{
  5392. WarehousingOrder: warehousing_order,
  5393. OperationTime: operation_time,
  5394. OrgId: adminInfo.CurrentOrgId,
  5395. Creater: creater,
  5396. Ctime: time.Now().Unix(),
  5397. Status: 1,
  5398. WarehousingTime: recordDateTime,
  5399. Type: 0,
  5400. StorehouseId: 0,
  5401. IsCheck: 1,
  5402. PatientId: patient_id,
  5403. IsSys: 1,
  5404. }
  5405. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5406. if selfDrugWarehouse.ID == 0 {
  5407. service.AddSelfDrugWarehouse(&warehousing, tx)
  5408. }
  5409. if selfDrugWarehouse.ID > 0 {
  5410. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5411. }
  5412. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5413. fmt.Println(info)
  5414. for _, item := range hisdoctorlist {
  5415. //查询该病人的该药品是否已经入库
  5416. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5417. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5418. var in_count int64
  5419. if len(selfdruginfo) > 0 {
  5420. for _, item := range selfdruginfo {
  5421. var in_count_one int64
  5422. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5423. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5424. }
  5425. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5426. in_count_one = item.WarehousingCount
  5427. }
  5428. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5429. in_count_one = item.WarehousingCount
  5430. }
  5431. in_count += in_count_one
  5432. }
  5433. }
  5434. if selfBasedrug.IsSelfDrug == 1 {
  5435. var total_count int64
  5436. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5437. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5438. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5439. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5440. }
  5441. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5442. total_count += prescribingNumberSeven
  5443. }
  5444. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5445. total_count += prescribingNumberSeven
  5446. }
  5447. //入库
  5448. if total_count > in_count {
  5449. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5450. WarehousingOrder: warehousing_order,
  5451. WarehousingId: info.ID,
  5452. DrugId: item.DrugId,
  5453. Number: "",
  5454. ProductDate: 0,
  5455. ExpiryDate: 0,
  5456. WarehousingCount: total_count - in_count,
  5457. WarehouseingUnit: selfBasedrug.MinUnit,
  5458. Price: 0,
  5459. TotalPrice: 0,
  5460. Status: 1,
  5461. Ctime: time.Now().Unix(),
  5462. Remark: "",
  5463. OrgId: adminInfo.CurrentOrgId,
  5464. Type: 0,
  5465. Manufacturer: selfBasedrug.Manufacturer,
  5466. Dealer: selfBasedrug.Dealer,
  5467. StockMaxNumber: total_count - in_count,
  5468. RetailTotalPrice: 0,
  5469. BatchNumber: "",
  5470. MaxUnit: selfBasedrug.MinUnit,
  5471. MinUnit: selfBasedrug.MinUnit,
  5472. RetailPrice: 0,
  5473. StorehouseId: 0,
  5474. IsCheck: 1,
  5475. StockMinNumber: 0,
  5476. PatientId: patient_id,
  5477. IsSys: 1,
  5478. RecordDate: item.RecordDate,
  5479. AdviceId: item.ID,
  5480. }
  5481. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5482. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5483. Creator := adminInfo.AdminUser.Id
  5484. //查询默认仓库剩余多少库存
  5485. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5486. var sum_count int64
  5487. for _, it := range list {
  5488. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5489. if it.MaxUnit == baseDrug.MaxUnit {
  5490. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5491. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5492. }
  5493. sum_count += it.StockMaxNumber + it.StockMinNumber
  5494. }
  5495. flow := &models.XtSelfDrugFlow{
  5496. WarehousingId: info.ID,
  5497. DrugId: item.DrugId,
  5498. Number: "",
  5499. BatchNumber: "",
  5500. Count: total_count - in_count,
  5501. UserOrgId: adminInfo.CurrentOrgId,
  5502. PatientId: item.PatientId,
  5503. SystemTime: time.Now().Unix(),
  5504. ConsumableType: 1,
  5505. IsSys: 1,
  5506. WarehousingOrder: warehousing_order,
  5507. WarehouseOutId: 0,
  5508. WarehouseOutOrderNumber: "",
  5509. IsEdit: 0,
  5510. CancelStockId: 0,
  5511. CancelOrderNumber: "",
  5512. Manufacturer: selfBasedrug.Manufacturer,
  5513. Dealer: selfBasedrug.Dealer,
  5514. Creator: Creator,
  5515. UpdateCreator: Creator,
  5516. Status: 1,
  5517. Ctime: item.AdviceDate,
  5518. Mtime: 0,
  5519. Price: item.Price,
  5520. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5521. WarehouseOutDetailId: 0,
  5522. CancelOutDetailId: 0,
  5523. ExpireDate: 0,
  5524. ProductDate: 0,
  5525. MaxUnit: selfBasedrug.MinUnit,
  5526. MinUnit: selfBasedrug.MinUnit,
  5527. StorehouseId: 0,
  5528. OverCount: sum_count,
  5529. OperateTime: time.Now().Unix(),
  5530. AdviceId: item.ID,
  5531. }
  5532. service.CreateSelfDrugFlow(flow, tx)
  5533. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5534. var total_count int64 // 入库总数量
  5535. var over_count int64 //剩余库存
  5536. for _, it := range drugInfolist {
  5537. if it.MaxUnit == selfBasedrug.MaxUnit {
  5538. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5539. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5540. }
  5541. }
  5542. for _, it := range drugInfolist {
  5543. total_count += it.WarehousingCount
  5544. over_count += it.StockMaxNumber + it.StockMinNumber
  5545. }
  5546. //查询该仓库是否有默认数据
  5547. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5548. if selfDrugStock.ID == 0 {
  5549. drugStock := models.XtSelfDrugStockCount{
  5550. UserOrgId: item.UserOrgId,
  5551. PatientId: item.PatientId,
  5552. SumInCount: total_count,
  5553. SumOutCount: 0,
  5554. SumCancelCount: 0,
  5555. DrugId: item.DrugId,
  5556. Ctime: time.Now().Unix(),
  5557. Mtime: 0,
  5558. Status: 1,
  5559. FlushCount: over_count,
  5560. SumActOutCount: 0,
  5561. }
  5562. service.CreateSelfDrugStockSum(drugStock, tx)
  5563. }
  5564. if selfDrugStock.ID > 0 {
  5565. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5566. }
  5567. }
  5568. //查询这个单据的出库数量
  5569. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5570. var his_out_count int64
  5571. for _, item := range drugFlowList {
  5572. his_out_count += item.Count
  5573. }
  5574. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5575. if (total_count + his_out_count) <= in_count {
  5576. // 出库
  5577. if total_count < in_count {
  5578. var cha_count int64
  5579. cha_count = in_count - total_count
  5580. var stock_number int64 = 0
  5581. //查询库存是否充足
  5582. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5583. // 将该批次的剩余库存数量转换为拆零数量
  5584. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5585. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5586. }
  5587. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5588. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5589. }
  5590. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5591. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5592. }
  5593. if stock_number >= cha_count {
  5594. var maxNumber int64 = 0
  5595. var minNumber int64 = 0
  5596. maxNumber = cha_count / selfBasedrug.MinNumber
  5597. minNumber = cha_count % selfBasedrug.MinNumber
  5598. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5599. minNumber = maxNumber
  5600. }
  5601. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5602. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5604. return
  5605. }
  5606. }
  5607. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5608. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5609. }
  5610. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5611. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5612. }
  5613. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5614. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5615. }
  5616. if warehouse.StockMaxNumber < 0 {
  5617. warehouse.StockMaxNumber = 0
  5618. }
  5619. if warehouse.StockMinNumber < 0 {
  5620. warehouse.StockMinNumber = 0
  5621. }
  5622. warehouse.Mtime = time.Now().Unix()
  5623. if warehouse.StockMinNumber < minNumber {
  5624. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5625. if warehouse.MaxUnit != warehouse.MinUnit {
  5626. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5627. }
  5628. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5629. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5630. }
  5631. } else {
  5632. if minNumber > 0 {
  5633. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5634. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5635. }
  5636. }
  5637. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5638. if warehouse.StockMinNumber > 0 {
  5639. if warehouse.StockMinNumber-cha_count >= 0 {
  5640. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5641. }
  5642. }
  5643. }
  5644. }
  5645. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5646. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5647. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5648. }
  5649. }
  5650. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5651. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5653. return
  5654. }
  5655. }
  5656. if warehouse.StockMinNumber <= 0 {
  5657. warehouse.StockMinNumber = 0
  5658. }
  5659. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5660. //查询该药品剩余库存
  5661. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5662. var over_count int64
  5663. for _, its := range infolist {
  5664. if its.MaxUnit == selfBasedrug.MaxUnit {
  5665. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5666. }
  5667. over_count += its.StockMaxNumber + its.StockMinNumber
  5668. }
  5669. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5670. drugflow := models.XtSelfDrugFlow{
  5671. WarehouseOutId: 0,
  5672. WarehouseOutOrderNumber: warehousing_order,
  5673. WarehousingOrder: warehousing_order,
  5674. DrugId: item.DrugId,
  5675. Number: warehouse.Number,
  5676. ProductDate: warehouse.ProductDate,
  5677. ExpireDate: warehouse.ExpiryDate,
  5678. Count: cha_count,
  5679. Price: warehouse.RetailPrice,
  5680. Status: 1,
  5681. Ctime: item.AdviceDate,
  5682. Mtime: time.Now().Unix(),
  5683. UserOrgId: item.UserOrgId,
  5684. Manufacturer: warehouse.Manufacturer,
  5685. Dealer: warehouse.Dealer,
  5686. BatchNumber: warehouse.BatchNumber,
  5687. MaxUnit: selfBasedrug.MinUnit,
  5688. ConsumableType: 20,
  5689. IsEdit: 1,
  5690. Creator: 0,
  5691. IsSys: 3,
  5692. WarehouseOutDetailId: drugWareInfo.ID,
  5693. AdviceId: item.ID,
  5694. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5695. StorehouseId: 0,
  5696. AdminUserId: creater,
  5697. LastPrice: warehouse.Price,
  5698. StockCount: "",
  5699. WarehousingDetailId: 0,
  5700. OverCount: over_count,
  5701. RetailPrice: item.Price, //手动出库出库价格
  5702. WarehousingId: warehouse.ID,
  5703. SystemTime: item.AdviceDate,
  5704. PatientId: item.PatientId,
  5705. Remark: "保存处方入库数据差",
  5706. OperateTime: time.Now().Unix(),
  5707. }
  5708. if warehouse.RetailPrice == 0 {
  5709. drugflow.Price = item.Price
  5710. }
  5711. service.CreateSelfDrugFlowOne(drugflow, tx)
  5712. var out_count int64
  5713. out_count = in_count - total_count
  5714. //
  5715. //fmt.Println("in_count------------------", in_count)
  5716. //fmt.Println("total_count------------------", total_count)
  5717. //添加出库数量
  5718. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5719. //查询剩余库存
  5720. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5721. var sum_count int64
  5722. for _, its := range stockInfo {
  5723. if its.MaxUnit == selfBasedrug.MaxUnit {
  5724. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5725. }
  5726. sum_count += its.StockMaxNumber + its.StockMinNumber
  5727. }
  5728. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5729. } else {
  5730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5731. return
  5732. }
  5733. }
  5734. }
  5735. }
  5736. }
  5737. }
  5738. }
  5739. tx.Commit()
  5740. if err == nil {
  5741. c.ServeSuccessJSON(map[string]interface{}{
  5742. "msg": "保存成功",
  5743. })
  5744. return
  5745. } else {
  5746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5747. return
  5748. }
  5749. }
  5750. }
  5751. //func (c *HisApiController) EditHisPrescription() {
  5752. // record_date := c.GetString("record_date")
  5753. // patient_id, _ := c.GetInt64("patient_id")
  5754. // reg_type, _ := c.GetInt64("reg_type")
  5755. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5756. // diagnose := c.GetString("diagnose")
  5757. // sick_type, _ := c.GetInt64("sick_type")
  5758. // sick_history := c.GetString("sick_history")
  5759. // doctor_id, _ := c.GetInt64("doctor", 0)
  5760. // department, _ := c.GetInt64("department", 0)
  5761. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5762. // p_type, _ := c.GetInt64("p_type")
  5763. //
  5764. // dataBody := make(map[string]interface{}, 0)
  5765. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5766. // if err != nil {
  5767. // utils.ErrorLog(err.Error())
  5768. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5769. // return
  5770. // }
  5771. //
  5772. // timeLayout := "2006-01-02"
  5773. // loc, _ := time.LoadLocation("Local")
  5774. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5775. // if err != nil {
  5776. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5777. // return
  5778. // }
  5779. // adminInfo := c.GetAdminUserInfo()
  5780. // recordDateTime := theTime.Unix()
  5781. //
  5782. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5783. //
  5784. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5785. // var hpInfo models.HisPrescriptionInfo
  5786. // if info.ID == 0 {
  5787. // var randNum int
  5788. // randNum = rand.Intn(10000) + 1000
  5789. // timestamp := time.Now().Unix()
  5790. // tempTime := time.Unix(timestamp, 0)
  5791. // timeFormat := tempTime.Format("20060102150405")
  5792. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5793. //
  5794. // hpInfo = models.HisPrescriptionInfo{
  5795. // UserOrgId: adminInfo.CurrentOrgId,
  5796. // RecordDate: theTime.Unix(),
  5797. // PatientId: patient_id,
  5798. // Status: 1,
  5799. // Ctime: time.Now().Unix(),
  5800. // Mtime: time.Now().Unix(),
  5801. // Creator: adminInfo.AdminUser.Id,
  5802. // Modifier: adminInfo.AdminUser.Id,
  5803. // Diagnosis: diagnose,
  5804. // SickHistory: sick_history,
  5805. // Departments: department,
  5806. // RegisterType: reg_type,
  5807. // PrescriptionNumber: p_number,
  5808. // PrescriptionStatus: 1,
  5809. // Doctor: role.UserName,
  5810. // DoctorId: doctor_id,
  5811. // SickType: sick_type,
  5812. // PType: p_type,
  5813. // }
  5814. // service.SavePatientPrescriptionInfo(hpInfo)
  5815. //
  5816. // } else {
  5817. // hpInfo = models.HisPrescriptionInfo{
  5818. // ID: info.ID,
  5819. // UserOrgId: adminInfo.CurrentOrgId,
  5820. // RecordDate: info.RecordDate,
  5821. // PatientId: info.PatientId,
  5822. // Status: 1,
  5823. // Ctime: info.Ctime,
  5824. // Mtime: time.Now().Unix(),
  5825. // Creator: info.Creator,
  5826. // Modifier: adminInfo.AdminUser.Id,
  5827. // Diagnosis: diagnose,
  5828. // SickHistory: sick_history,
  5829. // Departments: department,
  5830. // RegisterType: reg_type,
  5831. // PrescriptionNumber: info.PrescriptionNumber,
  5832. // Doctor: role.UserName,
  5833. // PrescriptionStatus: info.PrescriptionStatus,
  5834. // DoctorId: doctor_id,
  5835. // SickType: sick_type,
  5836. // PType: info.PType,
  5837. // }
  5838. // service.SavePatientPrescriptionInfo(hpInfo)
  5839. // }
  5840. //
  5841. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5842. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5843. //
  5844. // if len(prescriptions) > 0 {
  5845. // for _, item := range prescriptions {
  5846. // items := item.(map[string]interface{})
  5847. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5848. // utils.ErrorLog("id")
  5849. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5850. // return
  5851. // }
  5852. // id := int64(items["id"].(float64))
  5853. //
  5854. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5855. // utils.ErrorLog("type")
  5856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5857. // return
  5858. // }
  5859. // types := int64(items["type"].(float64))
  5860. //
  5861. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5862. // utils.ErrorLog("med_type")
  5863. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5864. // return
  5865. // }
  5866. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5867. //
  5868. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5869. //
  5870. // ctime := time.Now().Unix()
  5871. //
  5872. // prescription := &models.HisPrescription{
  5873. // ID: id,
  5874. // PatientId: patient_id,
  5875. // UserOrgId: adminInfo.CurrentOrgId,
  5876. // RecordDate: recordDateTime,
  5877. // Ctime: ctime,
  5878. // Mtime: ctime,
  5879. // Type: types,
  5880. // Modifier: adminInfo.AdminUser.Id,
  5881. // Creator: adminInfo.AdminUser.Id,
  5882. // Status: 1,
  5883. // Doctor: role.UserName,
  5884. // HisPatientId: his_patient_id,
  5885. // OrderStatus: 1,
  5886. // BatchNumber: "",
  5887. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5888. // PType: hpInfo.PType,
  5889. // MedType: med_type,
  5890. // }
  5891. //
  5892. // if historyPrescription.ID > 0 {
  5893. // prescription.PreTime = historyPrescription.PreTime
  5894. //
  5895. // }
  5896. //
  5897. // service.SaveHisPrescription(prescription)
  5898. //
  5899. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5900. // advices := items["advices"].([]interface{})
  5901. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5902. // groupNo := int64(0)
  5903. // ctime := time.Now().Unix()
  5904. // mtime := ctime
  5905. // if len(advices) > 0 {
  5906. // for _, advice := range advices {
  5907. // var s models.HisDoctorAdviceInfo
  5908. // s.PrescriptionId = prescription.ID
  5909. // s.AdviceType = 2
  5910. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5911. // s.StopState = 2
  5912. // s.ExecutionState = 2
  5913. // s.AdviceDate = recordDateTime
  5914. // s.Status = 1
  5915. // s.UserOrgId = adminInfo.CurrentOrgId
  5916. // s.RecordDate = recordDateTime
  5917. // s.StartTime = prescription.PreTime
  5918. // s.Groupno = groupNo
  5919. // s.CreatedTime = ctime
  5920. // s.UpdatedTime = mtime
  5921. // s.PatientId = patient_id
  5922. // s.HisPatientId = his_patient_id
  5923. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5924. // if errcode > 0 {
  5925. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5926. // return
  5927. // }
  5928. //
  5929. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5930. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5931. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5932. // if s.Price == 0 {
  5933. // s.Price = lastWarehouse.RetailPrice
  5934. // }
  5935. // }
  5936. //
  5937. // service.CreateHisDoctorAdvice(&s)
  5938. // //记录日志
  5939. // byterequest, _ := json.Marshal(s)
  5940. // adviceLog := models.XtDoctorAdviceLog{
  5941. // UserOrgId: s.UserOrgId,
  5942. // PatientId: s.PatientId,
  5943. // AdminUserId: adminInfo.AdminUser.Id,
  5944. // Module: 1,
  5945. // ErrLog: string(byterequest),
  5946. // Status: 1,
  5947. // Ctime: time.Now().Unix(),
  5948. // Mtime: 0,
  5949. // Source: "电脑端his医嘱修改",
  5950. // RecordDate: s.AdviceDate,
  5951. // }
  5952. // service.CreateDoctorAdviceLog(adviceLog)
  5953. // redis := service.RedisClient()
  5954. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5955. // redis.Set(key, "", time.Second)
  5956. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5957. // fmt.Println("keyOne", keyOne)
  5958. // redis.Set(keyOne, "", time.Second)
  5959. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5960. // redis.Set(keySeven, "", time.Second)
  5961. // redis.Close()
  5962. //
  5963. // }
  5964. // }
  5965. // }
  5966. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5967. // projects := items["project"].([]interface{})
  5968. // if len(projects) > 0 {
  5969. // for _, project := range projects {
  5970. // var p models.HisPrescriptionProject
  5971. // p.PrescriptionId = prescription.ID
  5972. // p.Ctime = time.Now().Unix()
  5973. // p.Mtime = time.Now().Unix()
  5974. // p.PatientId = patient_id
  5975. // p.RecordDate = recordDateTime
  5976. // p.UserOrgId = adminInfo.CurrentOrgId
  5977. // p.HisPatientId = his_patient_id
  5978. // p.Status = 1
  5979. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5980. // if errcode > 0 {
  5981. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5982. // return
  5983. // }
  5984. // service.CreateHisProjectTwo(&p)
  5985. //
  5986. // //记录日志
  5987. // byterequest, _ := json.Marshal(p)
  5988. // adviceLog := models.XtDoctorAdviceLog{
  5989. // UserOrgId: p.UserOrgId,
  5990. // PatientId: p.PatientId,
  5991. // AdminUserId: adminInfo.AdminUser.Id,
  5992. // Module: 1,
  5993. // ErrLog: string(byterequest),
  5994. // Status: 1,
  5995. // Ctime: time.Now().Unix(),
  5996. // Mtime: 0,
  5997. // Source: "电脑端his项目修改",
  5998. // RecordDate: p.RecordDate,
  5999. // }
  6000. // service.CreateDoctorAdviceLog(adviceLog)
  6001. // }
  6002. // }
  6003. // }
  6004. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  6005. // addition := items["addition"].([]interface{})
  6006. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6007. // ctime := time.Now().Unix()
  6008. // mtime := ctime
  6009. // if len(addition) > 0 {
  6010. // for _, item := range addition {
  6011. // var s models.HisAdditionalCharge
  6012. // s.PrescriptionId = prescription.ID
  6013. // s.Status = 1
  6014. // s.UserOrgId = adminInfo.CurrentOrgId
  6015. // s.RecordDate = recordDateTime
  6016. // s.CreatedTime = ctime
  6017. // s.UpdatedTime = mtime
  6018. // s.PatientId = patient_id
  6019. // s.HisPatientId = his_patient_id
  6020. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  6021. // if errcode > 0 {
  6022. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6023. // return
  6024. // }
  6025. // service.CreateAdditionalCharge(&s)
  6026. // }
  6027. // }
  6028. // }
  6029. //
  6030. // }
  6031. // }
  6032. // }
  6033. // if err == nil {
  6034. // c.ServeSuccessJSON(map[string]interface{}{
  6035. // "msg": "保存成功",
  6036. // })
  6037. // return
  6038. //
  6039. // } else {
  6040. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6041. // return
  6042. // }
  6043. //}
  6044. func (c *HisApiController) DeletePrescription() {
  6045. prescription_id, _ := c.GetInt64("id")
  6046. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  6047. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  6048. ////同步到自备药
  6049. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6050. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6051. if selfPrescriptionOpen.IsOpen == 1 {
  6052. // 在函数结束时处理事务回滚
  6053. db := service.XTWriteDB()
  6054. tx := db.Begin()
  6055. defer func() {
  6056. if r := recover(); r != nil {
  6057. tx.Rollback()
  6058. } else {
  6059. tx.Commit()
  6060. }
  6061. }()
  6062. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  6063. for _, item := range advicesList {
  6064. timeStr := time.Now().Format("2006-01-02")
  6065. timeArr := strings.Split(timeStr, "-")
  6066. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6067. total = total + 1
  6068. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6069. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6070. number = number + total
  6071. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6072. operation_time := time.Now().Unix()
  6073. creater := c.GetAdminUserInfo().AdminUser.Id
  6074. //创建一个出库单
  6075. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6076. WarehouseOutOrderNumber: warehousing_out_order,
  6077. OperationTime: operation_time,
  6078. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6079. Creater: creater,
  6080. Ctime: time.Now().Unix(),
  6081. Status: 1,
  6082. WarehouseOutTime: item.AdviceDate,
  6083. Type: 0,
  6084. PatientId: item.PatientId,
  6085. IsCheck: 1,
  6086. }
  6087. //查询今日是否有出库数据
  6088. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  6089. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  6090. if lastWarehouseOut.ID == 0 {
  6091. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6092. }
  6093. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  6094. var total_count int64
  6095. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  6096. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6097. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6098. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6099. }
  6100. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6101. total_count += prescribingNumberSeven
  6102. }
  6103. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6104. total_count += prescribingNumberSeven
  6105. }
  6106. //出库
  6107. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6108. WarehouseOutOrderNumber: warehousing_out_order,
  6109. WarehouseOutId: lastWarehouseOut.ID,
  6110. DrugId: item.DrugId,
  6111. Count: total_count,
  6112. Price: 0,
  6113. TotalPrice: 0,
  6114. Status: 1,
  6115. Ctime: item.AdviceDate,
  6116. Mtime: item.AdviceDate,
  6117. Remark: "",
  6118. OrgId: item.UserOrgId,
  6119. Type: 0,
  6120. Manufacturer: selfBasedrug.Manufacturer,
  6121. Dealer: selfBasedrug.Dealer,
  6122. RetailPrice: 0,
  6123. RetailTotalPrice: 0,
  6124. CountUnit: selfBasedrug.MinUnit,
  6125. ExpiryDate: 0,
  6126. ProductDate: 0,
  6127. Number: "",
  6128. BatchNumber: "",
  6129. IsSys: 1,
  6130. WarehouseInfoId: 0,
  6131. AdminUserId: 0,
  6132. StockCount: "",
  6133. IsCheck: 1,
  6134. SysRecordTime: item.AdviceDate,
  6135. PatientId: item.PatientId,
  6136. ClassType: "",
  6137. AdviceId: item.ID,
  6138. }
  6139. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6140. }
  6141. fmt.Println("长度-------------------------------", warehousingOutInfo)
  6142. for _, it := range warehousingOutInfo {
  6143. //查询今日是否有出库数据
  6144. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6145. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6146. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6147. //出库逻辑
  6148. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6149. //查询剩余库存
  6150. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6151. var sum_count int64
  6152. for _, its := range stockInfo {
  6153. if its.MaxUnit == medical.MaxUnit {
  6154. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6155. }
  6156. sum_count += its.StockMaxNumber + its.StockMinNumber
  6157. }
  6158. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6159. }
  6160. }
  6161. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6162. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6163. //耗材保存处方出库
  6164. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6165. //已收费和已发药限制逻辑
  6166. isCharge := false
  6167. isMedicine := false
  6168. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6169. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6170. if new_prescription.IsMedicine == 1 {
  6171. isMedicine = true
  6172. }
  6173. for _, item := range new_prescriptions {
  6174. if item.OrderStatus == 4 {
  6175. isCharge = true
  6176. }
  6177. }
  6178. if p_err != nil {
  6179. if new_prescription.ID > 0 {
  6180. if new_prescription.OrderStatus == 2 {
  6181. isCharge = true
  6182. }
  6183. }
  6184. }
  6185. for _, item := range advices {
  6186. if item.IsMedicine == 1 {
  6187. isMedicine = true
  6188. }
  6189. }
  6190. if isCharge {
  6191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6192. return
  6193. }
  6194. if isMedicine {
  6195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6196. return
  6197. }
  6198. //已收费和已发药限制逻辑
  6199. if len(projects) > 0 {
  6200. for _, item := range projects {
  6201. service.DeletePrintInfo(item.ID) //删除打印信息
  6202. if goodOutConfig.IsOpen != 1 {
  6203. if stockConfig.IsOpen == 1 {
  6204. if item.Type == 3 && item.IsOut == 1 {
  6205. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6206. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6207. good.Total = good.Total + f_count
  6208. service.UpdateGoodInfo(&good)
  6209. operation_time := time.Now().Unix()
  6210. creater := c.GetAdminUserInfo().AdminUser.Id
  6211. //创建退库单
  6212. timeStr := time.Now().Format("2006-01-02")
  6213. timeArr := strings.Split(timeStr, "-")
  6214. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6215. total = total + 1
  6216. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6217. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6218. cancelStock := models.CancelStock{
  6219. OrderNumber: orderNumber,
  6220. OperaTime: operation_time,
  6221. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6222. Creater: creater,
  6223. Ctime: time.Now().Unix(),
  6224. Status: 1,
  6225. ReturnTime: item.RecordDate,
  6226. Type: 1,
  6227. StorehouseId: houseConfig.StorehouseOutInfo,
  6228. IsCheck: 1,
  6229. }
  6230. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6231. if msgerrkonde == gorm.ErrRecordNotFound {
  6232. service.AddSigleCancelStock(&cancelStock)
  6233. }
  6234. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6235. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6236. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6237. //查询该耗材是否出库
  6238. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6239. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6240. deaerler, _ := service.GetDealerById(info.Dealer)
  6241. var total_count int64
  6242. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6243. total_count += count
  6244. if info.ID > 0 {
  6245. if info.Count >= total_count {
  6246. //回退库存
  6247. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6248. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6249. var flush_count int64
  6250. for _, it := range goodList {
  6251. flush_count += it.StockCount
  6252. }
  6253. cancelStockInfo := models.CancelStockInfo{
  6254. GoodId: item.ProjectId,
  6255. CancelStockId: cancel.ID,
  6256. GoodTypeId: good.GoodTypeId,
  6257. Count: prescribingNumber,
  6258. Price: info.Price,
  6259. Total: 0,
  6260. ProductDate: info.ProductDate,
  6261. ExpiryDate: info.ExpiryDate,
  6262. Ctime: time.Now().Unix(),
  6263. Status: 1,
  6264. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6265. OrderNumber: cancel.OrderNumber,
  6266. Type: 0,
  6267. Dealer: deaerler.DealerName,
  6268. Manufacturer: manufacturer.ManufacturerName,
  6269. Number: info.Number,
  6270. RegisterAccount: "",
  6271. Remark: "",
  6272. WarehouseInfoId: info.WarehouseInfotId,
  6273. PatientId: info.PatientId,
  6274. RecordDate: info.SysRecordTime,
  6275. StorehouseId: houseConfig.StorehouseOutInfo,
  6276. IsCheck: 1,
  6277. }
  6278. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6279. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6280. flow := models.VmStockFlow{
  6281. WarehousingId: info.WarehouseInfotId,
  6282. GoodId: item.ProjectId,
  6283. Number: info.Number,
  6284. LicenseNumber: info.LicenseNumber,
  6285. Count: prescribingNumber,
  6286. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6287. PatientId: item.PatientId,
  6288. SystemTime: info.SysRecordTime,
  6289. ConsumableType: 7,
  6290. IsSys: 0,
  6291. WarehousingOrder: "",
  6292. WarehouseOutId: info.WarehouseOutId,
  6293. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6294. IsEdit: 0,
  6295. CancelStockId: cancel.ID,
  6296. CancelOrderNumber: cancel.OrderNumber,
  6297. Manufacturer: manufacturer.ID,
  6298. Dealer: 0,
  6299. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6300. UpdateCreator: 0,
  6301. Status: 1,
  6302. Ctime: time.Now().Unix(),
  6303. Mtime: 0,
  6304. Price: info.Price,
  6305. WarehousingDetailId: info.WarehouseInfotId,
  6306. WarehouseOutDetailId: info.ID,
  6307. CancelOutDetailId: cancelInfo.ID,
  6308. ProductDate: info.ProductDate,
  6309. ExpireDate: info.ExpiryDate,
  6310. StorehouseId: houseConfig.StorehouseOutInfo,
  6311. OverCount: flush_count,
  6312. OperateTime: time.Now().Unix(),
  6313. }
  6314. service.CreateStockFlowOne(flow)
  6315. //退库数量增加
  6316. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6317. //出库数量减少
  6318. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6319. }
  6320. if info.Count < total_count {
  6321. //回退库存
  6322. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6323. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6324. var flush_count int64
  6325. for _, it := range goodList {
  6326. flush_count += it.StockCount
  6327. }
  6328. cancelStockInfo := models.CancelStockInfo{
  6329. GoodId: item.ProjectId,
  6330. CancelStockId: cancel.ID,
  6331. GoodTypeId: good.GoodTypeId,
  6332. Count: info.Count,
  6333. Price: info.Price,
  6334. Total: 0,
  6335. ProductDate: info.ProductDate,
  6336. ExpiryDate: info.ExpiryDate,
  6337. Ctime: time.Now().Unix(),
  6338. Status: 1,
  6339. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6340. OrderNumber: cancel.OrderNumber,
  6341. Type: 0,
  6342. Dealer: deaerler.DealerName,
  6343. Manufacturer: manufacturer.ManufacturerName,
  6344. Number: info.Number,
  6345. RegisterAccount: "",
  6346. Remark: "",
  6347. WarehouseInfoId: info.WarehouseInfotId,
  6348. PatientId: info.PatientId,
  6349. RecordDate: info.SysRecordTime,
  6350. StorehouseId: houseConfig.StorehouseOutInfo,
  6351. IsCheck: 1,
  6352. }
  6353. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6354. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6355. flow := models.VmStockFlow{
  6356. WarehousingId: info.WarehouseInfotId,
  6357. GoodId: item.ProjectId,
  6358. Number: info.Number,
  6359. LicenseNumber: info.LicenseNumber,
  6360. Count: info.Count,
  6361. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6362. PatientId: item.PatientId,
  6363. SystemTime: info.SysRecordTime,
  6364. ConsumableType: 7,
  6365. IsSys: 0,
  6366. WarehousingOrder: "",
  6367. WarehouseOutId: info.WarehouseOutId,
  6368. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6369. IsEdit: 0,
  6370. CancelStockId: cancel.ID,
  6371. CancelOrderNumber: cancel.OrderNumber,
  6372. Manufacturer: manufacturer.ID,
  6373. Dealer: 0,
  6374. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6375. UpdateCreator: 0,
  6376. Status: 1,
  6377. Ctime: time.Now().Unix(),
  6378. Mtime: 0,
  6379. Price: info.Price,
  6380. WarehousingDetailId: info.WarehouseInfotId,
  6381. WarehouseOutDetailId: info.ID,
  6382. CancelOutDetailId: cancelInfo.ID,
  6383. ProductDate: info.ProductDate,
  6384. ExpireDate: info.ExpiryDate,
  6385. StorehouseId: houseConfig.StorehouseOutInfo,
  6386. OverCount: flush_count,
  6387. OperateTime: time.Now().Unix(),
  6388. }
  6389. service.CreateStockFlowOne(flow)
  6390. //退库数量增加
  6391. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6392. //出库数量减少
  6393. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6394. }
  6395. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6396. var flush_count int64
  6397. for _, it := range goodList {
  6398. flush_count += it.StockCount
  6399. }
  6400. //查询已出库数量
  6401. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6402. if prescribingNumber < dialysisInfo.Count {
  6403. //改变数量
  6404. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6405. }
  6406. if prescribingNumber >= dialysisInfo.Count {
  6407. //删除出库表
  6408. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6409. }
  6410. //更新库存
  6411. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6412. //更新基础库库存
  6413. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6414. }
  6415. }
  6416. }
  6417. }
  6418. //保存耗材出库
  6419. if goodOutConfig.IsOpen == 1 {
  6420. if item.Type == 3 {
  6421. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6422. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6423. good.Total = good.Total + f_count
  6424. service.UpdateGoodInfo(&good)
  6425. operation_time := time.Now().Unix()
  6426. creater := c.GetAdminUserInfo().AdminUser.Id
  6427. //创建退库单
  6428. timeStr := time.Now().Format("2006-01-02")
  6429. timeArr := strings.Split(timeStr, "-")
  6430. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6431. total = total + 1
  6432. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6433. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6434. cancelStock := models.CancelStock{
  6435. OrderNumber: orderNumber,
  6436. OperaTime: operation_time,
  6437. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6438. Creater: creater,
  6439. Ctime: time.Now().Unix(),
  6440. Status: 1,
  6441. ReturnTime: item.RecordDate,
  6442. Type: 1,
  6443. StorehouseId: houseConfig.StorehouseOutInfo,
  6444. IsCheck: 1,
  6445. }
  6446. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6447. if msgerrkonde == gorm.ErrRecordNotFound {
  6448. service.AddSigleCancelStock(&cancelStock)
  6449. }
  6450. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6451. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6452. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6453. //查询该耗材是否出库
  6454. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6455. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6456. deaerler, _ := service.GetDealerById(info.Dealer)
  6457. var total_count int64
  6458. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6459. total_count += count
  6460. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6461. var flush_count int64
  6462. for _, it := range goodList {
  6463. flush_count += it.StockCount
  6464. }
  6465. fmt.Println("历史出库数据", info.Count)
  6466. fmt.Println("出库数量", total_count)
  6467. if info.ID > 0 {
  6468. cancelStockInfo := models.CancelStockInfo{
  6469. GoodId: item.ProjectId,
  6470. CancelStockId: cancel.ID,
  6471. GoodTypeId: good.GoodTypeId,
  6472. Count: prescribingNumber,
  6473. Price: info.Price,
  6474. Total: 0,
  6475. ProductDate: info.ProductDate,
  6476. ExpiryDate: info.ExpiryDate,
  6477. Ctime: time.Now().Unix(),
  6478. Status: 1,
  6479. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6480. OrderNumber: cancel.OrderNumber,
  6481. Type: 0,
  6482. Dealer: deaerler.DealerName,
  6483. Manufacturer: manufacturer.ManufacturerName,
  6484. Number: info.Number,
  6485. RegisterAccount: "",
  6486. Remark: "",
  6487. WarehouseInfoId: info.WarehouseInfotId,
  6488. PatientId: info.PatientId,
  6489. RecordDate: info.SysRecordTime,
  6490. StorehouseId: houseConfig.StorehouseOutInfo,
  6491. IsCheck: 1,
  6492. }
  6493. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6494. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6495. //查询出库数量
  6496. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6497. //出库数据 大于 退库数量
  6498. if len(list) > 0 {
  6499. for _, it := range list {
  6500. //回退库存
  6501. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6502. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6503. var flush_count_one int64
  6504. for _, it := range goodList {
  6505. flush_count_one += it.StockCount
  6506. }
  6507. //查询该批次是否有退库数据
  6508. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6509. creater := c.GetAdminUserInfo().AdminUser.Id
  6510. flow := models.VmStockFlow{
  6511. WarehousingId: it.WarehouseInfotId,
  6512. GoodId: it.GoodId,
  6513. Number: it.Number,
  6514. LicenseNumber: it.LicenseNumber,
  6515. Count: it.Count,
  6516. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6517. PatientId: it.PatientId,
  6518. SystemTime: it.SysRecordTime,
  6519. ConsumableType: 7,
  6520. IsSys: 0,
  6521. WarehousingOrder: "",
  6522. WarehouseOutId: it.WarehouseOutId,
  6523. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6524. IsEdit: 0,
  6525. CancelStockId: cancel.ID,
  6526. CancelOrderNumber: cancel.OrderNumber,
  6527. Manufacturer: manufacturer.ID,
  6528. Dealer: 0,
  6529. Creator: creater,
  6530. UpdateCreator: 0,
  6531. Status: 1,
  6532. Ctime: time.Now().Unix(),
  6533. Mtime: 0,
  6534. Price: it.Price,
  6535. WarehousingDetailId: it.WarehouseInfotId,
  6536. WarehouseOutDetailId: it.ID,
  6537. CancelOutDetailId: cancelInfo.ID,
  6538. ProductDate: it.ProductDate,
  6539. ExpireDate: it.ExpiryDate,
  6540. StorehouseId: houseConfig.StorehouseOutInfo,
  6541. OverCount: flush_count_one,
  6542. OperateTime: time.Now().Unix(),
  6543. }
  6544. service.CreateStockFlowOne(flow)
  6545. //if flow.ID > 0 {
  6546. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6547. //}
  6548. }
  6549. }
  6550. //flow := models.VmStockFlow{
  6551. // WarehousingId: info.WarehouseInfotId,
  6552. // GoodId: item.ProjectId,
  6553. // Number: info.Number,
  6554. // LicenseNumber: info.LicenseNumber,
  6555. // Count: prescribingNumber,
  6556. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6557. // PatientId: item.PatientId,
  6558. // SystemTime: info.SysRecordTime,
  6559. // ConsumableType: 7,
  6560. // IsSys: 0,
  6561. // WarehousingOrder: "",
  6562. // WarehouseOutId: info.WarehouseOutId,
  6563. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6564. // IsEdit: 0,
  6565. // CancelStockId: cancel.ID,
  6566. // CancelOrderNumber: cancel.OrderNumber,
  6567. // Manufacturer: manufacturer.ID,
  6568. // Dealer: 0,
  6569. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6570. // UpdateCreator: 0,
  6571. // Status: 1,
  6572. // Ctime: time.Now().Unix(),
  6573. // Mtime: 0,
  6574. // Price: info.Price,
  6575. // WarehousingDetailId: info.WarehouseInfotId,
  6576. // WarehouseOutDetailId: info.ID,
  6577. // CancelOutDetailId: cancelInfo.ID,
  6578. // ProductDate: info.ProductDate,
  6579. // ExpireDate: info.ExpiryDate,
  6580. // StorehouseId: houseConfig.StorehouseOutInfo,
  6581. // OverCount: flush_count,
  6582. //}
  6583. //service.CreateStockFlowOne(flow)
  6584. //退库数量增加
  6585. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6586. //出库数量减少
  6587. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6588. //查询已出库数量
  6589. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6590. if prescribingNumber < dialysisInfo.Count {
  6591. //改变数量
  6592. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6593. }
  6594. if prescribingNumber >= dialysisInfo.Count {
  6595. //删除出库表
  6596. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6597. }
  6598. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6599. var flush_count_one int64
  6600. for _, it := range goodList {
  6601. flush_count_one += it.StockCount
  6602. }
  6603. //更新库存
  6604. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6605. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6606. //更新基础库库存
  6607. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6608. }
  6609. }
  6610. }
  6611. }
  6612. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6613. fmt.Println(err)
  6614. }
  6615. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6616. fmt.Println(err)
  6617. if len(advices) > 0 {
  6618. for _, item := range advices {
  6619. redis := service.RedisClient()
  6620. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6621. redis.Set(keyFive, "", time.Second)
  6622. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6623. redis.Set(keyOne, "", time.Second)
  6624. redis.Close()
  6625. }
  6626. }
  6627. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6628. if len(advices) > 0 {
  6629. for _, item := range advices {
  6630. creater := c.GetAdminUserInfo().AdminUser.Id
  6631. service.DrugAutoAddCancelInfo(item, creater)
  6632. }
  6633. }
  6634. } else {
  6635. if drugOutConfig.IsOpen == 1 {
  6636. if len(advices) > 0 {
  6637. for _, item := range advices {
  6638. creater := c.GetAdminUserInfo().AdminUser.Id
  6639. service.DrugAutoAddCancelInfo(item, creater)
  6640. }
  6641. }
  6642. } else {
  6643. if len(advices) > 0 {
  6644. for _, item := range advices {
  6645. creater := c.GetAdminUserInfo().AdminUser.Id
  6646. service.DrugAutoAddCancelInfo(item, creater)
  6647. }
  6648. }
  6649. }
  6650. }
  6651. c.ServeSuccessJSON(map[string]interface{}{
  6652. "msg": "删除成功",
  6653. })
  6654. return
  6655. }
  6656. func (c *HisApiController) DeleteDoctorAdvice() {
  6657. id, _ := c.GetInt64("id")
  6658. advice, _ := service.GetHisDoctorAdvicesById(id)
  6659. ////同步到自备药
  6660. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6661. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6662. if selfPrescriptionOpen.IsOpen == 1 {
  6663. db := service.XTWriteDB()
  6664. tx := db.Begin()
  6665. defer func() {
  6666. if r := recover(); r != nil {
  6667. tx.Rollback()
  6668. } else {
  6669. tx.Commit()
  6670. }
  6671. }()
  6672. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6673. var total_count int64
  6674. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6675. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6676. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6677. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6678. }
  6679. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6680. total_count += prescribingNumberSeven
  6681. }
  6682. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6683. total_count += prescribingNumberSeven
  6684. }
  6685. timeStr := time.Now().Format("2006-01-02")
  6686. timeArr := strings.Split(timeStr, "-")
  6687. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6688. total = total + 1
  6689. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6690. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6691. number = number + total
  6692. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6693. operation_time := time.Now().Unix()
  6694. creater := c.GetAdminUserInfo().AdminUser.Id
  6695. //创建一个出库单
  6696. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6697. WarehouseOutOrderNumber: warehousing_out_order,
  6698. OperationTime: operation_time,
  6699. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6700. Creater: creater,
  6701. Ctime: time.Now().Unix(),
  6702. Status: 1,
  6703. WarehouseOutTime: advice.AdviceDate,
  6704. Type: 0,
  6705. PatientId: advice.PatientId,
  6706. IsCheck: 1,
  6707. }
  6708. //查询今日是否有出库数据
  6709. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6710. if lastWarehouseOut.ID == 0 {
  6711. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6712. }
  6713. //出库
  6714. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6715. WarehouseOutId: lastWarehouseOut.ID,
  6716. WarehouseOutOrderNumber: warehousing_out_order,
  6717. DrugId: advice.DrugId,
  6718. Count: total_count,
  6719. Price: 0,
  6720. TotalPrice: 0,
  6721. Status: 1,
  6722. Ctime: advice.AdviceDate,
  6723. Mtime: advice.AdviceDate,
  6724. Remark: "",
  6725. OrgId: advice.UserOrgId,
  6726. Type: 0,
  6727. Manufacturer: selfBasedrug.Manufacturer,
  6728. Dealer: selfBasedrug.Dealer,
  6729. RetailPrice: 0,
  6730. RetailTotalPrice: 0,
  6731. CountUnit: advice.PrescribingNumberUnit,
  6732. ExpiryDate: 0,
  6733. ProductDate: 0,
  6734. Number: "",
  6735. BatchNumber: "",
  6736. IsSys: 0,
  6737. WarehouseInfoId: 0,
  6738. AdminUserId: 0,
  6739. StockCount: "",
  6740. IsCheck: 1,
  6741. SysRecordTime: advice.AdviceDate,
  6742. PatientId: advice.PatientId,
  6743. AdviceId: advice.ID,
  6744. ClassType: "",
  6745. }
  6746. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6747. for _, it := range warehousingOutInfo {
  6748. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6749. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6750. //出库逻辑
  6751. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6752. //查询剩余库存
  6753. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6754. var sum_count int64
  6755. for _, its := range stockInfo {
  6756. if its.MaxUnit == medical.MaxUnit {
  6757. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6758. }
  6759. sum_count += its.StockMaxNumber + its.StockMinNumber
  6760. }
  6761. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6762. }
  6763. }
  6764. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6765. //已收费和已发药的限制逻辑
  6766. isCharge := false
  6767. isMedicine := false
  6768. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6769. //获取今天该患者所有处方,判断是否发药或者收费
  6770. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6771. //for _, item := range new_prescriptions {
  6772. if new_prescription.IsMedicine == 1 {
  6773. isMedicine = true
  6774. }
  6775. //}
  6776. for _, item := range new_prescriptions {
  6777. if item.OrderStatus == 4 {
  6778. isCharge = true
  6779. }
  6780. }
  6781. if isMedicine {
  6782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6783. return
  6784. }
  6785. if isCharge {
  6786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6787. return
  6788. }
  6789. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6790. for _, item := range advices {
  6791. if item.IsMedicine == 1 {
  6792. isMedicine = true
  6793. }
  6794. }
  6795. if isMedicine {
  6796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6797. return
  6798. }
  6799. if new_prescription.ID > 0 {
  6800. if new_prescription.OrderStatus == 2 {
  6801. isCharge = true
  6802. }
  6803. }
  6804. if isCharge {
  6805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6806. return
  6807. }
  6808. //已收费和已发药的限制逻辑
  6809. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6810. redis := service.RedisClient()
  6811. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6812. redis.Set(keyFive, "", time.Second)
  6813. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6814. redis.Set(keyOne, "", time.Second)
  6815. defer redis.Close()
  6816. if err == nil {
  6817. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6818. //查询是否在处方中出库
  6819. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6820. if openConfig.IsOpen != 1 {
  6821. //判断该医嘱是否执行了
  6822. if advice.ExecutionState == 1 {
  6823. creater := c.GetAdminUserInfo().AdminUser.Id
  6824. service.DrugAutoAddCancelInfo(&advice, creater)
  6825. }
  6826. }
  6827. //开启保存处方扣减功能
  6828. if openConfig.IsOpen == 1 {
  6829. creater := c.GetAdminUserInfo().AdminUser.Id
  6830. service.DrugAutoAddCancelInfo(&advice, creater)
  6831. }
  6832. } else {
  6833. if drugOutConfig.IsOpen == 1 {
  6834. //查询是否在处方中出库
  6835. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6836. if openConfig.IsOpen != 1 {
  6837. //判断该医嘱是否执行了
  6838. if advice.ExecutionState == 1 {
  6839. creater := c.GetAdminUserInfo().AdminUser.Id
  6840. service.DrugAutoAddCancelInfo(&advice, creater)
  6841. }
  6842. }
  6843. //开启保存处方扣减功能
  6844. if openConfig.IsOpen == 1 {
  6845. creater := c.GetAdminUserInfo().AdminUser.Id
  6846. service.DrugAutoAddCancelInfo(&advice, creater)
  6847. }
  6848. } else {
  6849. //判断该医嘱是否执行了
  6850. if advice.ExecutionState == 1 {
  6851. creater := c.GetAdminUserInfo().AdminUser.Id
  6852. service.DrugAutoAddCancelInfo(&advice, creater)
  6853. }
  6854. }
  6855. }
  6856. c.ServeSuccessJSON(map[string]interface{}{
  6857. "msg": "删除成功",
  6858. })
  6859. return
  6860. } else {
  6861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6862. return
  6863. }
  6864. }
  6865. func (c *HisApiController) DeleteProject() {
  6866. id, _ := c.GetInt64("id")
  6867. adminInfo := c.GetAdminUserInfo()
  6868. project, _ := service.GetHisProjectByID(id)
  6869. // var consumable models.DialysisBeforePrepare
  6870. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6871. //耗材保存处方出库
  6872. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6873. isCharge := false
  6874. isMedicine := false
  6875. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6876. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6877. for _, item := range new_prescriptions {
  6878. if item.IsMedicine == 1 {
  6879. isMedicine = true
  6880. }
  6881. }
  6882. for _, item := range new_prescriptions {
  6883. if item.OrderStatus == 4 {
  6884. isCharge = true
  6885. }
  6886. }
  6887. if isMedicine {
  6888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6889. return
  6890. }
  6891. if isCharge {
  6892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6893. return
  6894. }
  6895. if new_prescription.ID > 0 {
  6896. if new_prescription.OrderStatus == 2 {
  6897. isCharge = true
  6898. }
  6899. }
  6900. if isCharge {
  6901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6902. return
  6903. }
  6904. service.DeletePrintInfo(id)
  6905. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6906. label.Status = 0
  6907. service.CreateHisLabelRecordTwo(&label)
  6908. fmt.Println(goodOutConfig.IsOpen)
  6909. if goodOutConfig.IsOpen != 1 {
  6910. if stockConfig.IsOpen == 1 {
  6911. if project.Type == 2 {
  6912. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6913. fmt.Println(err)
  6914. }
  6915. if project.Type == 3 && project.IsOut == 1 {
  6916. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6917. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6918. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6919. operation_time := time.Now().Unix()
  6920. creater := adminInfo.AdminUser.Id
  6921. //创建退库单
  6922. timeStr := time.Now().Format("2006-01-02")
  6923. timeArr := strings.Split(timeStr, "-")
  6924. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6925. total = total + 1
  6926. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6927. cancelStock := models.CancelStock{
  6928. OrderNumber: orderNumber,
  6929. OperaTime: operation_time,
  6930. OrgId: adminInfo.CurrentOrgId,
  6931. Creater: creater,
  6932. Ctime: time.Now().Unix(),
  6933. Status: 1,
  6934. ReturnTime: project.RecordDate,
  6935. Type: 1,
  6936. StorehouseId: houseConfig.StorehouseOutInfo,
  6937. IsCheck: 1,
  6938. }
  6939. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6940. if msgerrkonde == gorm.ErrRecordNotFound {
  6941. service.AddSigleCancelStock(&cancelStock)
  6942. }
  6943. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6944. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6945. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6946. //查询是否有出库
  6947. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6948. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6949. deaerler, _ := service.GetDealerById(info.Dealer)
  6950. if info.ID > 0 {
  6951. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6952. if info.Count >= prescribingNumber {
  6953. cancelStockInfo := models.CancelStockInfo{
  6954. GoodId: project.ProjectId,
  6955. CancelStockId: cancel.ID,
  6956. GoodTypeId: good.GoodTypeId,
  6957. Count: prescribingNumber,
  6958. Price: info.Price,
  6959. Total: 0,
  6960. ProductDate: info.ProductDate,
  6961. ExpiryDate: info.ExpiryDate,
  6962. Ctime: time.Now().Unix(),
  6963. Status: 1,
  6964. OrgId: adminInfo.CurrentOrgId,
  6965. OrderNumber: cancel.OrderNumber,
  6966. Type: 0,
  6967. Dealer: deaerler.DealerName,
  6968. Manufacturer: manufacturer.ManufacturerName,
  6969. Number: info.Number,
  6970. RegisterAccount: "",
  6971. Remark: "",
  6972. WarehouseInfoId: info.WarehouseInfotId,
  6973. PatientId: info.PatientId,
  6974. RecordDate: info.SysRecordTime,
  6975. StorehouseId: houseConfig.StorehouseOutInfo,
  6976. IsCheck: 1,
  6977. }
  6978. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6979. //回退库存
  6980. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6981. //退库数量增加
  6982. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6983. //出库数量减少
  6984. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6985. }
  6986. if info.Count < prescribingNumber {
  6987. cancelStockInfo := models.CancelStockInfo{
  6988. GoodId: project.ProjectId,
  6989. CancelStockId: cancel.ID,
  6990. GoodTypeId: good.GoodTypeId,
  6991. Count: info.Count,
  6992. Price: info.Price,
  6993. Total: 0,
  6994. ProductDate: info.ProductDate,
  6995. ExpiryDate: info.ExpiryDate,
  6996. Ctime: time.Now().Unix(),
  6997. Status: 1,
  6998. OrgId: adminInfo.CurrentOrgId,
  6999. OrderNumber: cancel.OrderNumber,
  7000. Type: 0,
  7001. Dealer: deaerler.DealerName,
  7002. Manufacturer: manufacturer.ManufacturerName,
  7003. Number: info.Number,
  7004. RegisterAccount: "",
  7005. Remark: "",
  7006. WarehouseInfoId: info.WarehouseInfotId,
  7007. PatientId: info.PatientId,
  7008. RecordDate: info.SysRecordTime,
  7009. StorehouseId: houseConfig.StorehouseOutInfo,
  7010. IsCheck: 1,
  7011. }
  7012. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7013. //回退库存
  7014. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7015. //退库数量增加
  7016. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  7017. //出库数量减少
  7018. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  7019. }
  7020. //查询剩余库存
  7021. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7022. var over_count int64
  7023. for _, it := range goodList {
  7024. over_count += it.StockCount
  7025. }
  7026. //出库数据 大于 退库数量
  7027. if info.Count >= prescribingNumber {
  7028. flow := models.VmStockFlow{
  7029. WarehousingId: info.WarehouseInfotId,
  7030. GoodId: project.ProjectId,
  7031. Number: info.Number,
  7032. LicenseNumber: info.LicenseNumber,
  7033. Count: prescribingNumber,
  7034. UserOrgId: adminInfo.CurrentOrgId,
  7035. PatientId: project.PatientId,
  7036. SystemTime: info.SysRecordTime,
  7037. ConsumableType: 7,
  7038. IsSys: 0,
  7039. WarehousingOrder: "",
  7040. WarehouseOutId: info.WarehouseOutId,
  7041. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7042. IsEdit: 0,
  7043. CancelStockId: cancel.ID,
  7044. CancelOrderNumber: cancel.OrderNumber,
  7045. Manufacturer: manufacturer.ID,
  7046. Dealer: 0,
  7047. Creator: adminInfo.AdminUser.Id,
  7048. UpdateCreator: 0,
  7049. Status: 1,
  7050. Ctime: time.Now().Unix(),
  7051. Mtime: 0,
  7052. Price: info.Price,
  7053. WarehousingDetailId: info.WarehouseInfotId,
  7054. WarehouseOutDetailId: info.ID,
  7055. CancelOutDetailId: cancelInfo.ID,
  7056. ProductDate: info.ProductDate,
  7057. ExpireDate: info.ExpiryDate,
  7058. StorehouseId: houseConfig.StorehouseOutInfo,
  7059. OverCount: over_count,
  7060. OperateTime: time.Now().Unix(),
  7061. }
  7062. service.CreateStockFlowOne(flow)
  7063. }
  7064. //出库数据小于退库数据
  7065. if info.Count < prescribingNumber {
  7066. flow := models.VmStockFlow{
  7067. WarehousingId: info.WarehouseInfotId,
  7068. GoodId: project.ProjectId,
  7069. Number: info.Number,
  7070. LicenseNumber: info.LicenseNumber,
  7071. Count: info.Count,
  7072. UserOrgId: adminInfo.CurrentOrgId,
  7073. PatientId: project.PatientId,
  7074. SystemTime: info.SysRecordTime,
  7075. ConsumableType: 7,
  7076. IsSys: 0,
  7077. WarehousingOrder: "",
  7078. WarehouseOutId: info.WarehouseOutId,
  7079. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7080. IsEdit: 0,
  7081. CancelStockId: cancel.ID,
  7082. CancelOrderNumber: cancel.OrderNumber,
  7083. Manufacturer: manufacturer.ID,
  7084. Dealer: 0,
  7085. Creator: adminInfo.AdminUser.Id,
  7086. UpdateCreator: 0,
  7087. Status: 1,
  7088. Ctime: time.Now().Unix(),
  7089. Mtime: 0,
  7090. Price: info.Price,
  7091. WarehousingDetailId: info.WarehouseInfotId,
  7092. WarehouseOutDetailId: info.ID,
  7093. CancelOutDetailId: cancelInfo.ID,
  7094. ProductDate: info.ProductDate,
  7095. ExpireDate: info.ExpiryDate,
  7096. StorehouseId: houseConfig.StorehouseOutInfo,
  7097. OverCount: over_count,
  7098. OperateTime: time.Now().Unix(),
  7099. }
  7100. service.CreateStockFlowOne(flow)
  7101. }
  7102. //查询已出库数量
  7103. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7104. if prescribingNumber < dialysisInfo.Count {
  7105. //改变数量
  7106. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7107. }
  7108. if prescribingNumber >= dialysisInfo.Count {
  7109. //删除出库表
  7110. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7111. }
  7112. //更新剩余库存
  7113. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7114. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7115. var total_count_one int64
  7116. for _, it := range stockList {
  7117. total_count_one += it.StockCount
  7118. }
  7119. //基础库插入数据
  7120. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7121. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7122. var flush_count int64
  7123. for _, it := range goodListOne {
  7124. flush_count += it.StockCount
  7125. }
  7126. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7127. if errs != nil {
  7128. goodErrcode := models.XtGoodErrcode{
  7129. UserOrgId: project.UserOrgId,
  7130. Errcode: "手动出库更新剩余出库失败",
  7131. GoodId: project.ProjectId,
  7132. Status: 1,
  7133. Ctime: time.Now().Unix(),
  7134. Mtime: 0,
  7135. Count: 0,
  7136. StockCount: 0,
  7137. Creater: creater,
  7138. BatchNumberId: 0,
  7139. WarehouseOutId: 0,
  7140. }
  7141. service.CreateGoodErrcode(goodErrcode)
  7142. }
  7143. }
  7144. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7145. fmt.Println(err)
  7146. } else {
  7147. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7148. fmt.Println(err)
  7149. }
  7150. } else {
  7151. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7152. fmt.Println(err)
  7153. }
  7154. }
  7155. //保存处方出库
  7156. if goodOutConfig.IsOpen == 1 {
  7157. if project.Type == 3 {
  7158. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7159. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7160. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7161. operation_time := time.Now().Unix()
  7162. creater := adminInfo.AdminUser.Id
  7163. //创建退库单
  7164. timeStr := time.Now().Format("2006-01-02")
  7165. timeArr := strings.Split(timeStr, "-")
  7166. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7167. total = total + 1
  7168. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7169. cancelStock := models.CancelStock{
  7170. OrderNumber: orderNumber,
  7171. OperaTime: operation_time,
  7172. OrgId: adminInfo.CurrentOrgId,
  7173. Creater: creater,
  7174. Ctime: time.Now().Unix(),
  7175. Status: 1,
  7176. ReturnTime: project.RecordDate,
  7177. Type: 1,
  7178. StorehouseId: houseConfig.StorehouseOutInfo,
  7179. IsCheck: 1,
  7180. }
  7181. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7182. if msgerrkonde == gorm.ErrRecordNotFound {
  7183. service.AddSigleCancelStock(&cancelStock)
  7184. }
  7185. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7186. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7187. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7188. //获取出库数据
  7189. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7190. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7191. deaerler, _ := service.GetDealerById(info.Dealer)
  7192. if info.ID > 0 {
  7193. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7194. if info.Count >= prescribingNumber {
  7195. cancelStockInfo := models.CancelStockInfo{
  7196. GoodId: project.ProjectId,
  7197. CancelStockId: cancel.ID,
  7198. GoodTypeId: good.GoodTypeId,
  7199. Count: prescribingNumber,
  7200. Price: info.Price,
  7201. Total: 0,
  7202. ProductDate: info.ProductDate,
  7203. ExpiryDate: info.ExpiryDate,
  7204. Ctime: time.Now().Unix(),
  7205. Status: 1,
  7206. OrgId: adminInfo.CurrentOrgId,
  7207. OrderNumber: cancel.OrderNumber,
  7208. Type: 0,
  7209. Dealer: deaerler.DealerName,
  7210. Manufacturer: manufacturer.ManufacturerName,
  7211. Number: info.Number,
  7212. RegisterAccount: "",
  7213. Remark: "",
  7214. WarehouseInfoId: info.WarehouseInfotId,
  7215. PatientId: info.PatientId,
  7216. RecordDate: info.SysRecordTime,
  7217. StorehouseId: houseConfig.StorehouseOutInfo,
  7218. IsCheck: 1,
  7219. }
  7220. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7221. //退库数量增加
  7222. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7223. //出库数量减少
  7224. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7225. }
  7226. if info.Count < prescribingNumber {
  7227. cancelStockInfo := models.CancelStockInfo{
  7228. GoodId: project.ProjectId,
  7229. CancelStockId: cancel.ID,
  7230. GoodTypeId: good.GoodTypeId,
  7231. Count: prescribingNumber,
  7232. Price: info.Price,
  7233. Total: 0,
  7234. ProductDate: info.ProductDate,
  7235. ExpiryDate: info.ExpiryDate,
  7236. Ctime: time.Now().Unix(),
  7237. Status: 1,
  7238. OrgId: adminInfo.CurrentOrgId,
  7239. OrderNumber: cancel.OrderNumber,
  7240. Type: 0,
  7241. Dealer: deaerler.DealerName,
  7242. Manufacturer: manufacturer.ManufacturerName,
  7243. Number: info.Number,
  7244. RegisterAccount: "",
  7245. Remark: "",
  7246. WarehouseInfoId: info.WarehouseInfotId,
  7247. PatientId: info.PatientId,
  7248. RecordDate: info.SysRecordTime,
  7249. StorehouseId: houseConfig.StorehouseOutInfo,
  7250. IsCheck: 1,
  7251. }
  7252. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7253. //回退库存
  7254. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7255. }
  7256. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7257. var over_count int64
  7258. for _, it := range goodList {
  7259. over_count += it.StockCount
  7260. }
  7261. //查询出库数量
  7262. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7263. //出库数据 大于 退库数量
  7264. if len(list) > 0 {
  7265. for _, it := range list {
  7266. //回退库存
  7267. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7268. //退库数量增加
  7269. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7270. //出库数量减少
  7271. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7272. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7273. var over_count_one int64
  7274. for _, it := range goodList {
  7275. over_count_one += it.StockCount
  7276. }
  7277. //查询该批次是否有退库数据
  7278. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7279. flow := models.VmStockFlow{
  7280. WarehousingId: it.WarehouseInfotId,
  7281. GoodId: it.GoodId,
  7282. Number: it.Number,
  7283. LicenseNumber: it.LicenseNumber,
  7284. Count: it.Count,
  7285. UserOrgId: adminInfo.CurrentOrgId,
  7286. PatientId: it.PatientId,
  7287. SystemTime: it.SysRecordTime,
  7288. ConsumableType: 7,
  7289. IsSys: 0,
  7290. WarehousingOrder: "",
  7291. WarehouseOutId: it.WarehouseOutId,
  7292. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7293. IsEdit: 0,
  7294. CancelStockId: cancel.ID,
  7295. CancelOrderNumber: cancel.OrderNumber,
  7296. Manufacturer: manufacturer.ID,
  7297. Dealer: 0,
  7298. Creator: adminInfo.AdminUser.Id,
  7299. UpdateCreator: 0,
  7300. Status: 1,
  7301. Ctime: time.Now().Unix(),
  7302. Mtime: 0,
  7303. Price: it.Price,
  7304. WarehousingDetailId: it.WarehouseInfotId,
  7305. WarehouseOutDetailId: it.ID,
  7306. CancelOutDetailId: cancelInfo.ID,
  7307. ProductDate: it.ProductDate,
  7308. ExpireDate: it.ExpiryDate,
  7309. StorehouseId: houseConfig.StorehouseOutInfo,
  7310. OverCount: over_count_one,
  7311. OperateTime: time.Now().Unix(),
  7312. }
  7313. service.CreateStockFlowOne(flow)
  7314. }
  7315. }
  7316. //查询已出库数量
  7317. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7318. if prescribingNumber < dialysisInfo.Count {
  7319. //改变数量
  7320. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7321. }
  7322. if prescribingNumber >= dialysisInfo.Count {
  7323. //删除出库表
  7324. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7325. }
  7326. //更新剩余库存
  7327. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7328. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7329. var total_count_one int64
  7330. for _, it := range stockList {
  7331. total_count_one += it.StockCount
  7332. }
  7333. //基础库插入数据
  7334. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7335. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7336. var flush_count int64
  7337. for _, it := range goodListOne {
  7338. flush_count += it.StockCount
  7339. }
  7340. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7341. if errs != nil {
  7342. goodErrcode := models.XtGoodErrcode{
  7343. UserOrgId: project.UserOrgId,
  7344. Errcode: "手动出库更新剩余出库失败",
  7345. GoodId: project.ProjectId,
  7346. Status: 1,
  7347. Ctime: time.Now().Unix(),
  7348. Mtime: 0,
  7349. Count: 0,
  7350. StockCount: 0,
  7351. Creater: creater,
  7352. BatchNumberId: 0,
  7353. WarehouseOutId: 0,
  7354. }
  7355. service.CreateGoodErrcode(goodErrcode)
  7356. }
  7357. }
  7358. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7359. fmt.Println(err)
  7360. } else {
  7361. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7362. fmt.Println(err)
  7363. }
  7364. }
  7365. c.ServeSuccessJSON(map[string]interface{}{
  7366. "msg": "删除成功",
  7367. })
  7368. return
  7369. }
  7370. func (c *HisApiController) CreateHisAdditionalCharge() {
  7371. his_patient_id, _ := c.GetInt64("his_patient_id")
  7372. patient_id, _ := c.GetInt64("patient_id")
  7373. record_date := c.GetString("record_date")
  7374. timeLayout := "2006-01-02"
  7375. loc, _ := time.LoadLocation("Local")
  7376. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7377. if err != nil {
  7378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7379. return
  7380. }
  7381. adminInfo := c.GetAdminUserInfo()
  7382. recordDateTime := theTime.Unix()
  7383. dataBody := make(map[string]interface{}, 0)
  7384. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7385. if err != nil {
  7386. utils.ErrorLog(err.Error())
  7387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7388. return
  7389. }
  7390. var additions []*models.HisAdditionalCharge
  7391. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7392. additions, _ := dataBody["addition"].([]interface{})
  7393. if len(additions) > 0 {
  7394. for _, item := range additions {
  7395. items := item.(map[string]interface{})
  7396. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7397. utils.ErrorLog("item_id")
  7398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7399. return
  7400. }
  7401. item_id := int64(items["item_id"].(float64))
  7402. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7403. utils.ErrorLog("item_name")
  7404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7405. return
  7406. }
  7407. item_name := items["item_name"].(string)
  7408. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7409. utils.ErrorLog("price")
  7410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7411. return
  7412. }
  7413. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7414. ctime := time.Now().Unix()
  7415. additional := &models.HisAdditionalCharge{
  7416. PatientId: patient_id,
  7417. HisPatientId: his_patient_id,
  7418. UserOrgId: adminInfo.CurrentOrgId,
  7419. RecordDate: recordDateTime,
  7420. CreatedTime: ctime,
  7421. UpdatedTime: ctime,
  7422. Modifier: adminInfo.AdminUser.Id,
  7423. Creator: adminInfo.AdminUser.Id,
  7424. Price: price,
  7425. ItemName: item_name,
  7426. ItemId: item_id,
  7427. Status: 1,
  7428. }
  7429. additions = append(additions, additional)
  7430. }
  7431. }
  7432. }
  7433. for _, item := range additions {
  7434. service.CreateAddtionalCharge(item)
  7435. }
  7436. c.ServeSuccessJSON(map[string]interface{}{
  7437. "msg": "创建成功",
  7438. })
  7439. }
  7440. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7441. blood_fat := c.GetString("blood_fat")
  7442. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7443. blood_sugar := c.GetString("blood_sugar")
  7444. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7445. chief_conplaint := c.GetString("chief_conplaint")
  7446. dbp := c.GetString("dbp")
  7447. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7448. delivery_way, _ := c.GetInt64("delivery_way")
  7449. diagnostic := c.GetString("diagnostic")
  7450. family_history := c.GetString("family_history")
  7451. height := c.GetString("height")
  7452. history_of_present_illness := c.GetString("history_of_present_illness")
  7453. is_infect, _ := c.GetInt64("is_infect")
  7454. past_history := c.GetString("past_history")
  7455. patient_id, _ := c.GetInt64("patient_id")
  7456. his_patient_id, _ := c.GetInt64("his_patient_id")
  7457. personal_history := c.GetString("personal_history")
  7458. pulse := c.GetString("pulse")
  7459. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7460. sbp := c.GetString("sbp")
  7461. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7462. heightfloat, _ := strconv.ParseFloat(height, 64)
  7463. sicktype := c.GetString("sick_type")
  7464. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7465. symptom := c.GetString("symptom")
  7466. sick_date := c.GetString("sick_date")
  7467. temperatures := c.GetString("temperature")
  7468. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7469. record_date := c.GetString("record_date")
  7470. breathing := c.GetString("breathing")
  7471. doctor_advice := c.GetString("doctor_advice")
  7472. remark := c.GetString("remark")
  7473. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7474. sick, _ := c.GetInt64("sick")
  7475. diagnose, _ := c.GetInt64("diagnose")
  7476. //id, _ := c.GetInt64("id")
  7477. timeLayout := "2006-01-02"
  7478. loc, _ := time.LoadLocation("Local")
  7479. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7480. allergic_history := c.GetString("allergic_history")
  7481. if err != nil {
  7482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7483. return
  7484. }
  7485. recordDateTime := theTime.Unix()
  7486. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7487. if err != nil {
  7488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7489. return
  7490. }
  7491. sickTimes := sickTime.Unix()
  7492. ctime := time.Now().Unix()
  7493. primary_disease := c.GetString("primary_disease")
  7494. confirm_failure_date := c.GetString("confirm_failure_date")
  7495. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7496. drug_allergy_history := c.GetString("drug_allergy_history")
  7497. physical_examination := c.GetString("physical_examination")
  7498. special_inspection := c.GetString("special_inspection")
  7499. lab_apparatus := c.GetString("lab_apparatus")
  7500. caseHistory := models.HisPatientCaseHistory{
  7501. HisPatientId: his_patient_id,
  7502. PatientId: patient_id,
  7503. Temperature: temperature,
  7504. BloodSugar: bloodsugarfloat,
  7505. Pulse: pulsefloat,
  7506. Sbp: sbpfloat,
  7507. Dbp: dbpfloat,
  7508. Height: heightfloat,
  7509. BloodFat: bloodfatfloat,
  7510. SickType: sick_type,
  7511. Symptom: symptom,
  7512. SickDate: sickTimes,
  7513. IsInfect: is_infect,
  7514. HistoryOfPresentIllness: history_of_present_illness,
  7515. PastHistory: past_history,
  7516. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7517. ChiefConplaint: chief_conplaint,
  7518. PersonalHistory: personal_history,
  7519. FamilyHistory: family_history,
  7520. Diagnostic: diagnostic,
  7521. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7522. Status: 1,
  7523. Ctime: ctime,
  7524. Mtime: ctime,
  7525. RecordDate: recordDateTime,
  7526. DeliveryWay: delivery_way,
  7527. Breathing: breathingfloat,
  7528. DoctorAdvice: doctor_advice,
  7529. Remark: remark,
  7530. Sick: sick,
  7531. Diagnose: diagnose,
  7532. AllergicHistory: allergic_history,
  7533. PrimaryDisease: primary_disease,
  7534. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7535. DrugAllergyHistory: drug_allergy_history,
  7536. PhysicalExamination: physical_examination,
  7537. SpecialInspection: special_inspection,
  7538. LabApparatus: lab_apparatus,
  7539. }
  7540. //查询该患者是否有病历
  7541. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7542. if errcodes == gorm.ErrRecordNotFound {
  7543. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7544. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7545. if err != nil {
  7546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7547. return
  7548. }
  7549. c.ServeSuccessJSON(map[string]interface{}{
  7550. "caseHistory": caseHistory,
  7551. "historyInfo": historyInfo,
  7552. })
  7553. return
  7554. } else if errcodes == nil {
  7555. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7556. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7557. if err != nil {
  7558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7559. return
  7560. }
  7561. c.ServeSuccessJSON(map[string]interface{}{
  7562. "caseHistory": caseHistory,
  7563. "historyInfo": historyInfo,
  7564. })
  7565. }
  7566. //查询该患者是否有病历
  7567. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7568. //if errcode == gorm.ErrRecordNotFound {
  7569. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7570. // if err != nil {
  7571. // c.ServeSuccessJSON(map[string]interface{}{
  7572. // "msg": "保存成功",
  7573. // })
  7574. // }
  7575. //} else if errcode == nil {
  7576. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7577. // return
  7578. //}
  7579. }
  7580. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7581. patient_id, _ := c.GetInt64("patient_id", 0)
  7582. adminUser := c.GetAdminUserInfo()
  7583. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7584. c.ServeSuccessJSON(map[string]interface{}{
  7585. "list": caseHistorys,
  7586. })
  7587. }
  7588. func (c *HisApiController) GetHisPatientCaseHistory() {
  7589. record_date, _ := c.GetInt64("record_date", 0)
  7590. patient_id, _ := c.GetInt64("patient_id", 0)
  7591. admin := c.GetAdminUserInfo()
  7592. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7593. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7594. c.ServeSuccessJSON(map[string]interface{}{
  7595. "info": info,
  7596. "case_history": case_history,
  7597. })
  7598. }
  7599. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7600. template_name := c.GetString("template_name")
  7601. template_remark := c.GetString("template_remark")
  7602. doctor := c.GetAdminUserInfo().AdminUser.Id
  7603. diagnostic := c.GetString("diagnostic")
  7604. chief_conplaint := c.GetString("chief_conplain")
  7605. history_of_present_illness := c.GetString("history_of_present_illness")
  7606. past_history := c.GetString("past_history")
  7607. personal_history := c.GetString("personal_history")
  7608. family_history := c.GetString("family_history")
  7609. user_name := c.GetString("user_name")
  7610. doctor_advice := c.GetString("doctor_advice")
  7611. remark := c.GetString("remark")
  7612. //record_date := c.GetString("record_date")
  7613. //fmt.Println("record_date--------",record_date)
  7614. //timeLayout := "2006-01-02"
  7615. //loc, _ := time.LoadLocation("Local")
  7616. //
  7617. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7618. //if err != nil {
  7619. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7620. // return
  7621. //}
  7622. //recordDateTime := theTime.Unix()
  7623. ctime := time.Now().Unix()
  7624. template := models.HisCaseHistoryTemplate{
  7625. HistoryOfPresentIllness: history_of_present_illness,
  7626. PastHistory: past_history,
  7627. ChiefConplaint: chief_conplaint,
  7628. PersonalHistory: personal_history,
  7629. FamilyHistory: family_history,
  7630. Diagnostic: diagnostic,
  7631. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7632. Status: 1,
  7633. Ctime: ctime,
  7634. Mtime: ctime,
  7635. RecordDate: time.Now().Unix(),
  7636. TemplateName: template_name,
  7637. TemplateRemark: template_remark,
  7638. Creator: doctor,
  7639. Modifier: doctor,
  7640. UserName: user_name,
  7641. DoctorAdvice: doctor_advice,
  7642. Remark: remark,
  7643. }
  7644. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7645. if err == nil {
  7646. c.ServeSuccessJSON(map[string]interface{}{
  7647. "msg": "保存成功",
  7648. })
  7649. } else {
  7650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7651. return
  7652. }
  7653. }
  7654. func (c *HisApiController) GetCaseHistoryTemplate() {
  7655. timeLayout := "2006-01-02"
  7656. loc, _ := time.LoadLocation("Local")
  7657. keyword := c.GetString("keyword")
  7658. start_time := c.GetString("start_time")
  7659. end_time := c.GetString("end_time")
  7660. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7661. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7662. admin := c.GetAdminUserInfo()
  7663. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7664. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7665. c.ServeSuccessJSON(map[string]interface{}{
  7666. "template": template,
  7667. //"history": history,
  7668. })
  7669. }
  7670. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7671. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7672. utils.ErrorLog("drug_name")
  7673. return enums.ErrorCodeParamWrong
  7674. }
  7675. adviceName, _ := json["drug_name"].(string)
  7676. if len(adviceName) == 0 {
  7677. utils.ErrorLog("len(advice_name) == 0")
  7678. return enums.ErrorCodeParamWrong
  7679. }
  7680. advice.AdviceName = adviceName
  7681. adviceDesc, _ := json["advice_desc"].(string)
  7682. advice.AdviceDesc = adviceDesc
  7683. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7684. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7685. advice.DrugSpec = drugSpec
  7686. }
  7687. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7688. remark, _ := json["remark"].(string)
  7689. advice.Remark = remark
  7690. }
  7691. if json["id"] == nil {
  7692. advice.DrugId = 0
  7693. } else {
  7694. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7695. drug_id := int64(json["id"].(float64))
  7696. advice.DrugId = drug_id
  7697. }
  7698. }
  7699. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7700. advice_id := int64(json["advice_id"].(float64))
  7701. advice.ID = advice_id
  7702. if advice.ID > 0 {
  7703. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7704. if err == nil {
  7705. if hisAdvice.ID > 0 {
  7706. advice.ExecutionTime = hisAdvice.ExecutionTime
  7707. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7708. advice.ExecutionState = hisAdvice.ExecutionState
  7709. advice.CheckTime = hisAdvice.CheckTime
  7710. advice.Checker = hisAdvice.Checker
  7711. advice.CheckState = hisAdvice.CheckState
  7712. advice.StartTime = hisAdvice.StartTime
  7713. advice.FeedetlSn = hisAdvice.FeedetlSn
  7714. }
  7715. }
  7716. }
  7717. }
  7718. //
  7719. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7720. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7721. // advice.ExecutionTime = execution_time
  7722. //}
  7723. //
  7724. //
  7725. //
  7726. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7727. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7728. // advice.ExecutionStaff = execution_staff
  7729. //}
  7730. //
  7731. //
  7732. //
  7733. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7734. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7735. // advice.ExecutionState = execution_state
  7736. //}
  7737. //
  7738. //
  7739. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7740. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7741. // advice.CheckTime = check_time
  7742. //}
  7743. //
  7744. //
  7745. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7746. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7747. // advice.CheckState = check_state
  7748. //}
  7749. //
  7750. //
  7751. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7752. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7753. // advice.Checker = checker
  7754. //}
  7755. //
  7756. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7757. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7758. // advice.StartTime = start_time
  7759. //}
  7760. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7761. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7762. advice.IsSelfDrug = is_self_drug
  7763. }
  7764. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7765. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7766. drug_way_count, _ := json["drug_way_count"].(string)
  7767. advice.DrugWayCount = drug_way_count
  7768. }
  7769. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7770. drugSpecUnit, _ := json["min_unit"].(string)
  7771. advice.DrugSpecUnit = drugSpecUnit
  7772. }
  7773. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7774. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7775. advice.SingleDose = singleDose
  7776. }
  7777. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7778. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7779. advice.SingleDoseUnit = singleDoseUnit
  7780. }
  7781. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7782. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7783. advice.PrescribingNumber = prescribingNumber
  7784. }
  7785. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7786. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7787. advice.PrescribingNumberUnit = prescribingNumberUnit
  7788. }
  7789. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7790. deliveryWay, _ := json["delivery_way"].(string)
  7791. advice.DeliveryWay = deliveryWay
  7792. }
  7793. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7794. executionFrequency, _ := json["execution_frequency"].(string)
  7795. advice.ExecutionFrequency = executionFrequency
  7796. }
  7797. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7798. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7799. advice.Price = price
  7800. }
  7801. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7802. med_list_codg, _ := json["medical_insurance_number"].(string)
  7803. advice.MedListCodg = med_list_codg
  7804. }
  7805. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7806. day := int64(json["day"].(float64))
  7807. advice.Day = day
  7808. }
  7809. return 0
  7810. }
  7811. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7812. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7813. id := int64(json["id"].(float64))
  7814. project.ID = id
  7815. historyProject, _ := service.GetHisProjectByID(id)
  7816. project.FeedetlSn = historyProject.FeedetlSn
  7817. }
  7818. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7819. project_id := int64(json["project_id"].(float64))
  7820. project.ProjectId = project_id
  7821. }
  7822. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7823. // price := int64(json["price"].(float64))
  7824. // formatInt_price := strconv.FormatInt(price, 10)
  7825. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7826. // project.Price = float_price
  7827. // }
  7828. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7829. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7830. project.Price = price
  7831. }
  7832. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7833. total, _ := json["total"].(string)
  7834. project.Count = total
  7835. }
  7836. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7837. medical_code, _ := json["medical_code"].(string)
  7838. project.MedListCodg = medical_code
  7839. }
  7840. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7841. single_dose, _ := json["single_dose"].(string)
  7842. project.SingleDose = single_dose
  7843. }
  7844. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7845. delivery_way, _ := json["delivery_way"].(string)
  7846. project.DeliveryWay = delivery_way
  7847. }
  7848. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7849. execution_frequency, _ := json["execution_frequency"].(string)
  7850. project.ExecutionFrequency = execution_frequency
  7851. }
  7852. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7853. remark, _ := json["remark"].(string)
  7854. project.Remark = remark
  7855. }
  7856. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7857. day, _ := json["number_days"].(string)
  7858. project.Day = day
  7859. }
  7860. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7861. unit, _ := json["unit"].(string)
  7862. project.Unit = unit
  7863. }
  7864. return 0
  7865. }
  7866. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7867. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7868. id := int64(json["id"].(float64))
  7869. historyAddtions, _ := service.GetHisAdditionByID(id)
  7870. additionalCharge.ID = id
  7871. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7872. }
  7873. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7874. item_id := int64(json["item_id"].(float64))
  7875. additionalCharge.ItemId = item_id
  7876. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7877. if config.ID > 0 {
  7878. if len(config.Code) > 0 {
  7879. additionalCharge.MedListCodg = config.Code
  7880. }
  7881. }
  7882. }
  7883. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7884. // price := int64(json["price"].(float64))
  7885. // formatInt_price := strconv.FormatInt(price, 10)
  7886. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7887. // additionalCharge.Price = float_price
  7888. // }
  7889. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7890. // price := int64(json["price"].(float64))
  7891. // formatInt_price := strconv.FormatInt(price, 10)
  7892. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7893. // additionalCharge.Price = float_price
  7894. //}
  7895. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7896. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7897. additionalCharge.Price = price
  7898. }
  7899. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7900. count, _ := json["count"].(string)
  7901. counts, _ := strconv.ParseInt(count, 10, 64)
  7902. additionalCharge.Count = counts
  7903. }
  7904. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7905. item_name, _ := json["item_name"].(string)
  7906. additionalCharge.ItemName = item_name
  7907. }
  7908. return 0
  7909. }
  7910. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7911. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7912. utils.ErrorLog("drug_name")
  7913. return enums.ErrorCodeParamWrong
  7914. }
  7915. adviceName, _ := json["drug_name"].(string)
  7916. if len(adviceName) == 0 {
  7917. utils.ErrorLog("len(advice_name) == 0")
  7918. return enums.ErrorCodeParamWrong
  7919. }
  7920. advice.AdviceName = adviceName
  7921. adviceDesc, _ := json["advice_desc"].(string)
  7922. advice.AdviceDesc = adviceDesc
  7923. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7924. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7925. advice.DrugSpec = drugSpec
  7926. }
  7927. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7928. remark, _ := json["remark"].(string)
  7929. advice.Remark = remark
  7930. }
  7931. if json["id"] == nil {
  7932. advice.DrugId = 0
  7933. } else {
  7934. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7935. drug_id := int64(json["id"].(float64))
  7936. advice.DrugId = drug_id
  7937. }
  7938. }
  7939. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7940. groupno := int64(json["groupno"].(float64))
  7941. advice.Groupno = groupno
  7942. }
  7943. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7944. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7945. advice.IsSelfDrug = is_self_drug
  7946. }
  7947. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7948. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7949. drug_way_count, _ := json["drug_way_count"].(string)
  7950. advice.DrugWayCount = drug_way_count
  7951. }
  7952. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7953. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7954. advice.HospApprFlag = hosp_appr_flag
  7955. }
  7956. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7957. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7958. advice.PrescribingNumber = prescribingNumber
  7959. }
  7960. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7961. // frequency_type := int64(json["frequency_type"].(float64))
  7962. // advice.FrequencyType = frequency_type
  7963. //}
  7964. //
  7965. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7966. // day_count := int64(json["day_count"].(float64))
  7967. // advice.DayCount = day_count
  7968. //}
  7969. //
  7970. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7971. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7972. // week_day, _ := json["week_day"].(string)
  7973. // advice.WeekDay = week_day
  7974. //}
  7975. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7976. drugSpecUnit, _ := json["min_unit"].(string)
  7977. advice.DrugSpecUnit = drugSpecUnit
  7978. }
  7979. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7980. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7981. advice.SingleDose = singleDose
  7982. }
  7983. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7984. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7985. advice.SingleDoseUnit = singleDoseUnit
  7986. }
  7987. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7988. deliveryWay, _ := json["delivery_way"].(string)
  7989. advice.DeliveryWay = deliveryWay
  7990. }
  7991. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7992. executionFrequency, _ := json["execution_frequency"].(string)
  7993. advice.ExecutionFrequency = executionFrequency
  7994. }
  7995. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7996. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7997. advice.Price = price
  7998. }
  7999. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8000. med_list_codg, _ := json["medical_insurance_number"].(string)
  8001. advice.MedListCodg = med_list_codg
  8002. }
  8003. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8004. day := int64(json["day"].(float64))
  8005. advice.Day = day
  8006. }
  8007. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8008. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8009. advice.PrescribingNumberUnit = prescribingNumberUnit
  8010. }
  8011. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8012. advice_id := int64(json["advice_id"].(float64))
  8013. advice.ID = advice_id
  8014. if advice.ID > 0 {
  8015. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8016. if err == nil {
  8017. if hisAdvice.ID > 0 {
  8018. advice.ExecutionTime = hisAdvice.ExecutionTime
  8019. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8020. advice.ExecutionState = hisAdvice.ExecutionState
  8021. advice.CheckTime = hisAdvice.CheckTime
  8022. advice.Checker = hisAdvice.Checker
  8023. advice.CheckState = hisAdvice.CheckState
  8024. advice.StartTime = hisAdvice.StartTime
  8025. advice.HospApprFlag = hisAdvice.HospApprFlag
  8026. advice.IsMedicine = hisAdvice.IsMedicine
  8027. if hisAdvice.UserOrgId == 10028 {
  8028. 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 {
  8029. advice.ExecutionTime = 0
  8030. advice.ExecutionStaff = 0
  8031. advice.ExecutionState = 2
  8032. advice.CheckTime = 0
  8033. advice.Checker = 0
  8034. advice.CheckState = 2
  8035. }
  8036. } else {
  8037. 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 {
  8038. advice.ExecutionTime = 0
  8039. advice.ExecutionStaff = 0
  8040. advice.ExecutionState = 2
  8041. advice.CheckTime = 0
  8042. advice.Checker = 0
  8043. advice.CheckState = 2
  8044. advice.UpdatedTime = time.Now().Unix()
  8045. }
  8046. }
  8047. //advice.Groupno = hisAdvice.Groupno
  8048. }
  8049. }
  8050. }
  8051. }
  8052. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8053. //
  8054. //if drugStockConfig.IsOpen == 1 {
  8055. //
  8056. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8057. // if advice.ID == 0 { //医嘱不存在
  8058. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8059. // drug.Total = drug.Total - advice.PrescribingNumber
  8060. // service.UpdateBaseDrugLib(&drug)
  8061. //
  8062. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8063. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8064. // drug.Total = drug.Total - num
  8065. // service.UpdateBaseDrugLib(&drug)
  8066. // }
  8067. //
  8068. // } else if advice.ID > 0 { //医嘱存在
  8069. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8070. // var num float64
  8071. //
  8072. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8073. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8074. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8075. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8076. // drug.Total = drug.Total + num
  8077. // service.UpdateBaseDrugLib(&drug)
  8078. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8079. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8080. // drug.Total = drug.Total - num
  8081. // service.UpdateBaseDrugLib(&drug)
  8082. // }
  8083. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8084. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8085. // if num2 > advice.PrescribingNumber {
  8086. // num = num2 - advice.PrescribingNumber
  8087. // drug.Total = drug.Total + num
  8088. // service.UpdateBaseDrugLib(&drug)
  8089. // } else if num2 < advice.PrescribingNumber {
  8090. // num = advice.PrescribingNumber - num2
  8091. // drug.Total = drug.Total - num
  8092. // service.UpdateBaseDrugLib(&drug)
  8093. // }
  8094. //
  8095. // }
  8096. //
  8097. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8098. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8099. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8100. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8101. // if num1 > num2 {
  8102. // num = num1 - num2
  8103. // drug.Total = drug.Total + num
  8104. // service.UpdateBaseDrugLib(&drug)
  8105. // } else if num1 < num2 {
  8106. // num = num2 - num1
  8107. // drug.Total = drug.Total - num
  8108. // service.UpdateBaseDrugLib(&drug)
  8109. // }
  8110. //
  8111. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8112. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8113. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8114. // if hisAdvice.PrescribingNumber > num2 {
  8115. // num = hisAdvice.PrescribingNumber - num2
  8116. // drug.Total = drug.Total + num
  8117. // service.UpdateBaseDrugLib(&drug)
  8118. // } else if num2 < advice.PrescribingNumber {
  8119. // num = num2 - hisAdvice.PrescribingNumber
  8120. // drug.Total = drug.Total - num
  8121. // service.UpdateBaseDrugLib(&drug)
  8122. // }
  8123. //
  8124. // }
  8125. // }
  8126. // }
  8127. //}
  8128. //
  8129. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8130. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8131. // advice.ExecutionTime = execution_time
  8132. //}
  8133. //
  8134. //
  8135. //
  8136. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8137. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8138. // advice.ExecutionStaff = execution_staff
  8139. //}
  8140. //
  8141. //
  8142. //
  8143. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8144. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8145. // advice.ExecutionState = execution_state
  8146. //}
  8147. //
  8148. //
  8149. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8150. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8151. // advice.CheckTime = check_time
  8152. //}
  8153. //
  8154. //
  8155. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8156. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8157. // advice.CheckState = check_state
  8158. //}
  8159. //
  8160. //
  8161. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8162. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8163. // advice.Checker = checker
  8164. //}
  8165. //
  8166. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8167. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8168. // advice.StartTime = start_time
  8169. //}
  8170. return 0
  8171. }
  8172. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8173. project.ExecutionStaff = 0
  8174. project.ExecutionState = 2
  8175. project.ExecutionTime = 0
  8176. project.Checker = 0
  8177. project.CheckState = 2
  8178. project.CheckTime = 0
  8179. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8180. id := int64(json["id"].(float64))
  8181. project.ID = id
  8182. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8183. project.ExecutionStaff = temp_project.ExecutionStaff
  8184. project.ExecutionState = temp_project.ExecutionState
  8185. project.ExecutionTime = temp_project.ExecutionTime
  8186. project.Checker = temp_project.Checker
  8187. project.CheckState = temp_project.CheckState
  8188. project.CheckTime = temp_project.CheckTime
  8189. project.TeamId = temp_project.TeamId
  8190. }
  8191. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8192. types := int64(json["type"].(float64))
  8193. project.Type = types
  8194. }
  8195. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8196. project_id := int64(json["project_id"].(float64))
  8197. project.ProjectId = project_id
  8198. }
  8199. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8200. team_id := int64(json["team_id"].(float64))
  8201. project.TeamId = team_id
  8202. }
  8203. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8204. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8205. project.Price = price
  8206. }
  8207. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8208. total, _ := json["total"].(string)
  8209. //totals, _ := strconv.ParseInt(total, 10, 64)
  8210. project.Count = total
  8211. }
  8212. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8213. medical_code, _ := json["medical_code"].(string)
  8214. project.MedListCodg = medical_code
  8215. }
  8216. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8217. single_dose, _ := json["single_dose"].(string)
  8218. project.SingleDose = single_dose
  8219. }
  8220. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8221. delivery_way, _ := json["delivery_way"].(string)
  8222. project.DeliveryWay = delivery_way
  8223. }
  8224. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8225. execution_frequency, _ := json["execution_frequency"].(string)
  8226. project.ExecutionFrequency = execution_frequency
  8227. }
  8228. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8229. remark, _ := json["remark"].(string)
  8230. project.Remark = remark
  8231. }
  8232. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8233. day, _ := json["number_days"].(string)
  8234. project.Day = day
  8235. }
  8236. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8237. unit, _ := json["unit"].(string)
  8238. project.Unit = unit
  8239. }
  8240. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8241. // frequency_type := int64(json["frequency_type"].(float64))
  8242. // project.FrequencyType = frequency_type
  8243. //}
  8244. //
  8245. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8246. // day_count := int64(json["day_count"].(float64))
  8247. // project.DayCount = day_count
  8248. //}
  8249. //
  8250. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8251. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8252. // week_day, _ := json["week_day"].(string)
  8253. // project.WeekDay = week_day
  8254. //}
  8255. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8256. //
  8257. //if project.ID == 0 {
  8258. // if stockConfig.IsOpen == 1 {
  8259. // if project.Type == 3 {
  8260. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8261. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8262. // good.Total = good.Total - f_count
  8263. // service.UpdateGoodInfo(&good)
  8264. // }
  8265. // }
  8266. //
  8267. //} else {
  8268. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8269. //
  8270. // if stockConfig.IsOpen == 1 {
  8271. // if project.Type == 3 {
  8272. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8273. // if project.Count < temp_project.Count {
  8274. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8275. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8276. //
  8277. // other_count := f_count_two - f_count_one
  8278. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8279. // good.Total = good.Total + other_count_two
  8280. // service.UpdateGoodInfo(&good)
  8281. // } else if project.Count > temp_project.Count {
  8282. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8283. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8284. //
  8285. // other_count := f_count_one - f_count_two
  8286. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8287. // good.Total = good.Total - other_count_two
  8288. // service.UpdateGoodInfo(&good)
  8289. // }
  8290. //
  8291. // }
  8292. // }
  8293. //
  8294. //}
  8295. return 0
  8296. }
  8297. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8298. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8299. utils.ErrorLog("drug_name")
  8300. return enums.ErrorCodeParamWrong
  8301. }
  8302. adviceName, _ := json["drug_name"].(string)
  8303. if len(adviceName) == 0 {
  8304. utils.ErrorLog("len(advice_name) == 0")
  8305. return enums.ErrorCodeParamWrong
  8306. }
  8307. advice.AdviceName = adviceName
  8308. adviceDesc, _ := json["advice_desc"].(string)
  8309. advice.AdviceDesc = adviceDesc
  8310. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8311. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8312. advice.DrugSpec = drugSpec
  8313. }
  8314. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8315. remark, _ := json["remark"].(string)
  8316. advice.Remark = remark
  8317. }
  8318. if json["id"] == nil {
  8319. advice.DrugId = 0
  8320. } else {
  8321. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8322. drug_id := int64(json["id"].(float64))
  8323. advice.DrugId = drug_id
  8324. }
  8325. }
  8326. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8327. groupno := int64(json["groupno"].(float64))
  8328. advice.Groupno = groupno
  8329. }
  8330. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8331. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8332. advice.IsSelfDrug = is_self_drug
  8333. }
  8334. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8335. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8336. drug_way_count, _ := json["drug_way_count"].(string)
  8337. advice.DrugWayCount = drug_way_count
  8338. }
  8339. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8340. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8341. advice.HospApprFlag = hosp_appr_flag
  8342. }
  8343. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8344. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8345. advice.PrescribingNumber = prescribingNumber
  8346. }
  8347. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8348. // frequency_type := int64(json["frequency_type"].(float64))
  8349. // advice.FrequencyType = frequency_type
  8350. //}
  8351. //
  8352. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8353. // day_count := int64(json["day_count"].(float64))
  8354. // advice.DayCount = day_count
  8355. //}
  8356. //
  8357. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8358. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8359. // week_day, _ := json["week_day"].(string)
  8360. // advice.WeekDay = week_day
  8361. //}
  8362. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8363. drugSpecUnit, _ := json["min_unit"].(string)
  8364. advice.DrugSpecUnit = drugSpecUnit
  8365. }
  8366. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8367. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8368. advice.SingleDose = singleDose
  8369. }
  8370. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8371. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8372. advice.SingleDoseUnit = singleDoseUnit
  8373. }
  8374. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8375. deliveryWay, _ := json["delivery_way"].(string)
  8376. advice.DeliveryWay = deliveryWay
  8377. }
  8378. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8379. executionFrequency, _ := json["execution_frequency"].(string)
  8380. advice.ExecutionFrequency = executionFrequency
  8381. }
  8382. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8383. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8384. advice.Price = price
  8385. }
  8386. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8387. med_list_codg, _ := json["medical_insurance_number"].(string)
  8388. advice.MedListCodg = med_list_codg
  8389. }
  8390. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8391. day := int64(json["day"].(float64))
  8392. advice.Day = day
  8393. }
  8394. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8395. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8396. advice.PrescribingNumberUnit = prescribingNumberUnit
  8397. }
  8398. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8399. advice_id := int64(json["advice_id"].(float64))
  8400. advice.ID = advice_id
  8401. if advice.ID > 0 {
  8402. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8403. if err == nil {
  8404. if hisAdvice.ID > 0 {
  8405. advice.ExecutionTime = hisAdvice.ExecutionTime
  8406. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8407. advice.ExecutionState = hisAdvice.ExecutionState
  8408. advice.CheckTime = hisAdvice.CheckTime
  8409. advice.Checker = hisAdvice.Checker
  8410. advice.DrugCode = hisAdvice.DrugCode
  8411. advice.CheckState = hisAdvice.CheckState
  8412. advice.StartTime = hisAdvice.StartTime
  8413. advice.HospApprFlag = hisAdvice.HospApprFlag
  8414. advice.IsMedicine = hisAdvice.IsMedicine
  8415. if hisAdvice.UserOrgId == 10028 {
  8416. 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 {
  8417. advice.ExecutionTime = 0
  8418. advice.ExecutionStaff = 0
  8419. advice.ExecutionState = 2
  8420. advice.CheckTime = 0
  8421. advice.Checker = 0
  8422. advice.CheckState = 2
  8423. }
  8424. } else {
  8425. 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 {
  8426. advice.ExecutionTime = 0
  8427. advice.ExecutionStaff = 0
  8428. advice.ExecutionState = 2
  8429. advice.CheckTime = 0
  8430. advice.Checker = 0
  8431. advice.CheckState = 2
  8432. //advice.UpdatedTime = time.Now().Unix()
  8433. advice.CreatedTime = hisAdvice.CreatedTime
  8434. advice.UpdatedTime = time.Now().Unix()
  8435. } else {
  8436. advice.CreatedTime = hisAdvice.CreatedTime
  8437. advice.UpdatedTime = hisAdvice.UpdatedTime
  8438. }
  8439. }
  8440. //advice.Groupno = hisAdvice.Groupno
  8441. } else {
  8442. advice.IsMedicine = 0
  8443. ctime := time.Now().Unix()
  8444. advice.CreatedTime = ctime
  8445. advice.UpdatedTime = ctime
  8446. }
  8447. }
  8448. } else {
  8449. advice.IsMedicine = 0
  8450. ctime := time.Now().Unix()
  8451. advice.CreatedTime = ctime
  8452. advice.UpdatedTime = ctime
  8453. }
  8454. }
  8455. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8456. //
  8457. //if drugStockConfig.IsOpen == 1 {
  8458. //
  8459. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8460. // if advice.ID == 0 { //医嘱不存在
  8461. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8462. // drug.Total = drug.Total - advice.PrescribingNumber
  8463. // service.UpdateBaseDrugLib(&drug)
  8464. //
  8465. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8466. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8467. // drug.Total = drug.Total - num
  8468. // service.UpdateBaseDrugLib(&drug)
  8469. // }
  8470. //
  8471. // } else if advice.ID > 0 { //医嘱存在
  8472. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8473. // var num float64
  8474. //
  8475. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8476. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8477. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8478. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8479. // drug.Total = drug.Total + num
  8480. // service.UpdateBaseDrugLib(&drug)
  8481. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8482. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8483. // drug.Total = drug.Total - num
  8484. // service.UpdateBaseDrugLib(&drug)
  8485. // }
  8486. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8487. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8488. // if num2 > advice.PrescribingNumber {
  8489. // num = num2 - advice.PrescribingNumber
  8490. // drug.Total = drug.Total + num
  8491. // service.UpdateBaseDrugLib(&drug)
  8492. // } else if num2 < advice.PrescribingNumber {
  8493. // num = advice.PrescribingNumber - num2
  8494. // drug.Total = drug.Total - num
  8495. // service.UpdateBaseDrugLib(&drug)
  8496. // }
  8497. //
  8498. // }
  8499. //
  8500. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8501. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8502. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8503. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8504. // if num1 > num2 {
  8505. // num = num1 - num2
  8506. // drug.Total = drug.Total + num
  8507. // service.UpdateBaseDrugLib(&drug)
  8508. // } else if num1 < num2 {
  8509. // num = num2 - num1
  8510. // drug.Total = drug.Total - num
  8511. // service.UpdateBaseDrugLib(&drug)
  8512. // }
  8513. //
  8514. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8515. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8516. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8517. // if hisAdvice.PrescribingNumber > num2 {
  8518. // num = hisAdvice.PrescribingNumber - num2
  8519. // drug.Total = drug.Total + num
  8520. // service.UpdateBaseDrugLib(&drug)
  8521. // } else if num2 < advice.PrescribingNumber {
  8522. // num = num2 - hisAdvice.PrescribingNumber
  8523. // drug.Total = drug.Total - num
  8524. // service.UpdateBaseDrugLib(&drug)
  8525. // }
  8526. //
  8527. // }
  8528. // }
  8529. // }
  8530. //}
  8531. //
  8532. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8533. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8534. // advice.ExecutionTime = execution_time
  8535. //}
  8536. //
  8537. //
  8538. //
  8539. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8540. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8541. // advice.ExecutionStaff = execution_staff
  8542. //}
  8543. //
  8544. //
  8545. //
  8546. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8547. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8548. // advice.ExecutionState = execution_state
  8549. //}
  8550. //
  8551. //
  8552. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8553. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8554. // advice.CheckTime = check_time
  8555. //}
  8556. //
  8557. //
  8558. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8559. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8560. // advice.CheckState = check_state
  8561. //}
  8562. //
  8563. //
  8564. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8565. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8566. // advice.Checker = checker
  8567. //}
  8568. //
  8569. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8570. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8571. // advice.StartTime = start_time
  8572. //}
  8573. return 0
  8574. }
  8575. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8576. project.ExecutionStaff = 0
  8577. project.ExecutionState = 2
  8578. project.ExecutionTime = 0
  8579. project.Checker = 0
  8580. project.CheckState = 2
  8581. project.CheckTime = 0
  8582. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8583. id := int64(json["id"].(float64))
  8584. project.ID = id
  8585. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8586. project.ExecutionStaff = temp_project.ExecutionStaff
  8587. project.ExecutionState = temp_project.ExecutionState
  8588. project.ExecutionTime = temp_project.ExecutionTime
  8589. project.Checker = temp_project.Checker
  8590. project.CheckState = temp_project.CheckState
  8591. project.CheckTime = temp_project.CheckTime
  8592. project.TeamId = temp_project.TeamId
  8593. }
  8594. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8595. types := int64(json["type"].(float64))
  8596. project.Type = types
  8597. }
  8598. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8599. project_id := int64(json["project_id"].(float64))
  8600. project.ProjectId = project_id
  8601. }
  8602. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8603. team_id := int64(json["team_id"].(float64))
  8604. project.TeamId = team_id
  8605. }
  8606. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8607. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8608. project.Price = price
  8609. }
  8610. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8611. total, _ := json["total"].(string)
  8612. //totals, _ := strconv.ParseInt(total, 10, 64)
  8613. project.Count = total
  8614. }
  8615. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8616. medical_code, _ := json["medical_code"].(string)
  8617. project.MedListCodg = medical_code
  8618. }
  8619. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8620. single_dose, _ := json["single_dose"].(string)
  8621. project.SingleDose = single_dose
  8622. }
  8623. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8624. delivery_way, _ := json["delivery_way"].(string)
  8625. project.DeliveryWay = delivery_way
  8626. }
  8627. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8628. execution_frequency, _ := json["execution_frequency"].(string)
  8629. project.ExecutionFrequency = execution_frequency
  8630. }
  8631. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8632. remark, _ := json["remark"].(string)
  8633. project.Remark = remark
  8634. }
  8635. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8636. day, _ := json["number_days"].(string)
  8637. project.Day = day
  8638. }
  8639. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8640. unit, _ := json["unit"].(string)
  8641. project.Unit = unit
  8642. }
  8643. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8644. // frequency_type := int64(json["frequency_type"].(float64))
  8645. // project.FrequencyType = frequency_type
  8646. //}
  8647. //
  8648. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8649. // day_count := int64(json["day_count"].(float64))
  8650. // project.DayCount = day_count
  8651. //}
  8652. //
  8653. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8654. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8655. // week_day, _ := json["week_day"].(string)
  8656. // project.WeekDay = week_day
  8657. //}
  8658. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8659. //
  8660. //if project.ID == 0 {
  8661. // if stockConfig.IsOpen == 1 {
  8662. // if project.Type == 3 {
  8663. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8664. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8665. // good.Total = good.Total - f_count
  8666. // service.UpdateGoodInfo(&good)
  8667. // }
  8668. // }
  8669. //
  8670. //} else {
  8671. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8672. //
  8673. // if stockConfig.IsOpen == 1 {
  8674. // if project.Type == 3 {
  8675. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8676. // if project.Count < temp_project.Count {
  8677. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8678. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8679. //
  8680. // other_count := f_count_two - f_count_one
  8681. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8682. // good.Total = good.Total + other_count_two
  8683. // service.UpdateGoodInfo(&good)
  8684. // } else if project.Count > temp_project.Count {
  8685. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8686. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8687. //
  8688. // other_count := f_count_one - f_count_two
  8689. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8690. // good.Total = good.Total - other_count_two
  8691. // service.UpdateGoodInfo(&good)
  8692. // }
  8693. //
  8694. // }
  8695. // }
  8696. //
  8697. //}
  8698. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8699. id := int64(json["id"].(float64))
  8700. if id > 0 {
  8701. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8702. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8703. fmt.Println("666666")
  8704. project.Mtime = time.Now().Unix()
  8705. project.Ctime = temp_project.Ctime
  8706. } else {
  8707. project.Mtime = temp_project.Mtime
  8708. project.Ctime = temp_project.Ctime
  8709. }
  8710. } else {
  8711. ctime := time.Now().Unix()
  8712. project.Mtime = ctime
  8713. project.Ctime = ctime
  8714. }
  8715. }
  8716. return 0
  8717. }
  8718. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8719. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8720. id := int64(json["id"].(float64))
  8721. additionalCharge.ID = id
  8722. }
  8723. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8724. item_id := int64(json["item_id"].(float64))
  8725. additionalCharge.ItemId = item_id
  8726. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8727. if config.ID > 0 {
  8728. if len(config.Code) > 0 {
  8729. additionalCharge.MedListCodg = config.Code
  8730. }
  8731. }
  8732. }
  8733. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8734. // price := int64(json["price"].(float64))
  8735. // formatInt_price := strconv.FormatInt(price, 10)
  8736. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8737. // additionalCharge.Price = float_price
  8738. // }
  8739. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8740. // price := int64(json["price"].(float64))
  8741. // formatInt_price := strconv.FormatInt(price, 10)
  8742. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8743. // additionalCharge.Price = float_price
  8744. //}
  8745. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8746. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8747. additionalCharge.Price = price
  8748. }
  8749. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8750. count, _ := json["count"].(string)
  8751. counts, _ := strconv.ParseInt(count, 10, 64)
  8752. additionalCharge.Count = counts
  8753. }
  8754. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8755. item_name, _ := json["item_name"].(string)
  8756. additionalCharge.ItemName = item_name
  8757. }
  8758. return 0
  8759. }
  8760. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8761. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8762. utils.ErrorLog("drug_name")
  8763. return enums.ErrorCodeParamWrong
  8764. }
  8765. adviceName, _ := json["drug_name"].(string)
  8766. if len(adviceName) == 0 {
  8767. utils.ErrorLog("len(advice_name) == 0")
  8768. return enums.ErrorCodeParamWrong
  8769. }
  8770. advice.AdviceName = adviceName
  8771. adviceDesc, _ := json["advice_desc"].(string)
  8772. advice.AdviceDesc = adviceDesc
  8773. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8774. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8775. advice.DrugSpec = drugSpec
  8776. }
  8777. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8778. remark, _ := json["remark"].(string)
  8779. advice.Remark = remark
  8780. }
  8781. if json["id"] == nil {
  8782. advice.DrugId = 0
  8783. } else {
  8784. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8785. drug_id := int64(json["id"].(float64))
  8786. advice.DrugId = drug_id
  8787. }
  8788. }
  8789. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8790. groupno := int64(json["groupno"].(float64))
  8791. advice.Groupno = groupno
  8792. }
  8793. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8794. drugSpecUnit, _ := json["min_unit"].(string)
  8795. advice.DrugSpecUnit = drugSpecUnit
  8796. }
  8797. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8798. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8799. advice.SingleDose = singleDose
  8800. }
  8801. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8802. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8803. advice.SingleDoseUnit = singleDoseUnit
  8804. }
  8805. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8806. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8807. advice.PrescribingNumber = prescribingNumber
  8808. }
  8809. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8810. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8811. advice.PrescribingNumberUnit = prescribingNumberUnit
  8812. }
  8813. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8814. deliveryWay, _ := json["delivery_way"].(string)
  8815. advice.DeliveryWay = deliveryWay
  8816. }
  8817. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8818. executionFrequency, _ := json["execution_frequency"].(string)
  8819. advice.ExecutionFrequency = executionFrequency
  8820. }
  8821. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8822. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8823. advice.Price = price
  8824. }
  8825. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8826. med_list_codg, _ := json["medical_insurance_number"].(string)
  8827. advice.MedListCodg = med_list_codg
  8828. }
  8829. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8830. day := int64(json["day"].(float64))
  8831. advice.Day = day
  8832. }
  8833. advice.FrequencyType = 1
  8834. return 0
  8835. }
  8836. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8837. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8838. types := int64(json["type"].(float64))
  8839. project.Type = types
  8840. }
  8841. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8842. project_id := int64(json["project_id"].(float64))
  8843. project.ProjectId = project_id
  8844. }
  8845. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8846. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8847. project.Price = price
  8848. }
  8849. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8850. total, _ := json["total"].(string)
  8851. //totals, _ := strconv.ParseInt(total, 10, 64)
  8852. project.Count = total
  8853. }
  8854. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8855. medical_code, _ := json["medical_code"].(string)
  8856. project.MedListCodg = medical_code
  8857. }
  8858. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8859. single_dose, _ := json["single_dose"].(string)
  8860. project.SingleDose = single_dose
  8861. }
  8862. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8863. delivery_way, _ := json["delivery_way"].(string)
  8864. project.DeliveryWay = delivery_way
  8865. }
  8866. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8867. execution_frequency, _ := json["execution_frequency"].(string)
  8868. project.ExecutionFrequency = execution_frequency
  8869. }
  8870. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8871. remark, _ := json["remark"].(string)
  8872. project.Remark = remark
  8873. }
  8874. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8875. day, _ := json["number_days"].(string)
  8876. project.Day = day
  8877. }
  8878. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8879. unit, _ := json["unit"].(string)
  8880. project.Unit = unit
  8881. }
  8882. project.FrequencyType = 1
  8883. return 0
  8884. }
  8885. func (c *HisApiController) GetHisOrderListTwo() {
  8886. start_time := c.GetString("start_time")
  8887. end_time := c.GetString("end_time")
  8888. timeLayout := "2006-01-02"
  8889. loc, _ := time.LoadLocation("Local")
  8890. var startTime int64
  8891. if len(start_time) > 0 {
  8892. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8893. if err != nil {
  8894. //fmt.Println(err)
  8895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8896. return
  8897. }
  8898. startTime = theTime.Unix()
  8899. }
  8900. var endTime int64
  8901. if len(end_time) > 0 {
  8902. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8903. if err != nil {
  8904. utils.ErrorLog(err.Error())
  8905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8906. return
  8907. }
  8908. endTime = theTime.Unix()
  8909. }
  8910. adminUser := c.GetAdminUserInfo()
  8911. org_id := adminUser.CurrentOrgId
  8912. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8913. if err == nil {
  8914. c.ServeSuccessJSON(map[string]interface{}{
  8915. "order2": order,
  8916. })
  8917. } else {
  8918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8919. return
  8920. }
  8921. }
  8922. func (c *HisApiController) GetHisOrderList() {
  8923. page, _ := c.GetInt64("page", -1)
  8924. limit, _ := c.GetInt64("limit", -1)
  8925. start_time := c.GetString("start_time")
  8926. end_time := c.GetString("end_time")
  8927. types, _ := c.GetInt64("type", 0)
  8928. keywords := c.GetString("keywords")
  8929. p_type, _ := c.GetInt64("p_type", 0)
  8930. sort_type, _ := c.GetInt64("sort_type", 0)
  8931. charge_type, _ := c.GetInt64("charge_type", 0)
  8932. sch_type, _ := c.GetInt64("sch_type", 0)
  8933. zone_type, _ := c.GetInt64("zone_type", 0)
  8934. med_type, _ := c.GetInt64("med_type", 0)
  8935. timeLayout := "2006-01-02"
  8936. loc, _ := time.LoadLocation("Local")
  8937. var startTime int64
  8938. if len(start_time) > 0 {
  8939. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8940. if err != nil {
  8941. //fmt.Println(err)
  8942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8943. return
  8944. }
  8945. startTime = theTime.Unix()
  8946. }
  8947. var endTime int64
  8948. if len(end_time) > 0 {
  8949. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8950. if err != nil {
  8951. utils.ErrorLog(err.Error())
  8952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8953. return
  8954. }
  8955. endTime = theTime.Unix()
  8956. }
  8957. adminUser := c.GetAdminUserInfo()
  8958. org_id := adminUser.CurrentOrgId
  8959. 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)
  8960. for _, item := range order {
  8961. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8962. item.DoctorName = info.Doctor
  8963. item.DepartmentName = info.XtHisDepartment.Name
  8964. }
  8965. if err == nil {
  8966. c.ServeSuccessJSON(map[string]interface{}{
  8967. "order": order,
  8968. "total": total,
  8969. })
  8970. } else {
  8971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8972. return
  8973. }
  8974. }
  8975. func (c *HisApiController) GetHisOrder() {
  8976. patient_id, _ := c.GetInt64("patient_id", 0)
  8977. number := c.GetString("number")
  8978. adminInfo := c.GetAdminUserInfo()
  8979. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8980. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8981. if err == nil {
  8982. c.ServeSuccessJSON(map[string]interface{}{
  8983. "order": order,
  8984. "prescription": prescriptions,
  8985. })
  8986. } else {
  8987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8988. return
  8989. }
  8990. }
  8991. func (c *HisApiController) GetHisPrescriptionList() {
  8992. record_date := c.GetString("record_date")
  8993. keywords := c.GetString("keywords")
  8994. page, _ := c.GetInt64("page")
  8995. limit, _ := c.GetInt64("limit")
  8996. sch_type, _ := c.GetInt64("sch_type")
  8997. timeLayout := "2006-01-02"
  8998. loc, _ := time.LoadLocation("Local")
  8999. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9000. if err != nil {
  9001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9002. return
  9003. }
  9004. recordDateTime := theTime.Unix()
  9005. adminInfo := c.GetAdminUserInfo()
  9006. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  9007. //adminInfo := c.GetAdminUserInfo()
  9008. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  9009. //fmt.Println(prescriptionOrder)
  9010. if err == nil {
  9011. c.ServeSuccessJSON(map[string]interface{}{
  9012. "order": prescriptionOrder,
  9013. "total": total,
  9014. })
  9015. } else {
  9016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9017. return
  9018. }
  9019. }
  9020. func (c *HisApiController) GetHisPrescriptionInfo() {
  9021. id, _ := c.GetInt64("id")
  9022. adminInfo := c.GetAdminUserInfo()
  9023. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  9024. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  9025. if err == nil {
  9026. c.ServeSuccessJSON(map[string]interface{}{
  9027. "order": prescriptionOrder,
  9028. "prescription": prescription,
  9029. })
  9030. } else {
  9031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9032. return
  9033. }
  9034. }
  9035. func (c *HisApiController) GetMedicalInsuranceConfig() {
  9036. adminUser := c.GetAdminUserInfo()
  9037. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  9038. c.ServeSuccessJSON(map[string]interface{}{
  9039. "config": config,
  9040. })
  9041. }
  9042. type ResultTwo struct {
  9043. ErrMsg interface{} `json:"err_msg"`
  9044. InfRefmsgid string `json:"inf_refmsgid"`
  9045. Infcode int64 `json:"infcode"`
  9046. Output struct {
  9047. Baseinfo struct {
  9048. Age float64 `json:"age"`
  9049. Brdy string `json:"brdy"`
  9050. Certno string `json:"certno"`
  9051. Gend string `json:"gend"`
  9052. Naty string `json:"naty"`
  9053. PsnCertType string `json:"psn_cert_type"`
  9054. PsnName string `json:"psn_name"`
  9055. PsnNo string `json:"psn_no"`
  9056. } `json:"baseinfo"`
  9057. Idetinfo []interface{} `json:"idetinfo"`
  9058. Iinfo []struct {
  9059. Balc float64 `json:"balc"`
  9060. CvlservFlag string `json:"cvlserv_flag"`
  9061. EmpName string `json:"emp_name"`
  9062. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  9063. Insutype string `json:"insutype"`
  9064. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  9065. PausInsuDate interface{} `json:"paus_insu_date"`
  9066. PsnInsuDate string `json:"psn_insu_date"`
  9067. PsnInsuStas string `json:"psn_insu_stas"`
  9068. PsnType string `json:"psn_type"`
  9069. } `json:"insuinfo"`
  9070. } `json:"output"`
  9071. RefmsgTime string `json:"refmsg_time"`
  9072. RespondTime string `json:"respond_time"`
  9073. Signtype interface{} `json:"signtype"`
  9074. WarnInfo interface{} `json:"warn_info"`
  9075. }
  9076. type ResultThree struct {
  9077. Cainfo interface{} `json:"cainfo"`
  9078. ErrMsg interface{} `json:"err_msg"`
  9079. InfRefmsgid string `json:"inf_refmsgid"`
  9080. Infcode int64 `json:"infcode"`
  9081. Output struct {
  9082. Data struct {
  9083. IptOtpNo string `json:"ipt_otp_no"`
  9084. MdtrtID string `json:"mdtrt_id"`
  9085. PsnNo string `json:"psn_no"`
  9086. } `json:"data"`
  9087. } `json:"output"`
  9088. RefmsgTime string `json:"refmsg_time"`
  9089. RespondTime string `json:"respond_time"`
  9090. Signtype interface{} `json:"signtype"`
  9091. WarnMsg interface{} `json:"warn_msg"`
  9092. }
  9093. type ResultFour struct {
  9094. Cainfo string `json:"cainfo"`
  9095. ErrMsg string `json:"err_msg"`
  9096. InfRefmsgid string `json:"inf_refmsgid"`
  9097. Infcode int64 `json:"infcode"`
  9098. Output struct {
  9099. Result []struct {
  9100. BasMednFlag string `json:"bas_medn_flag"`
  9101. ChldMedcFlag string `json:"chld_medc_flag"`
  9102. ChrgitmLv string `json:"chrgitm_lv"`
  9103. Cnt float64 `json:"cnt"`
  9104. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9105. DrtReimFlag string `json:"drt_reim_flag"`
  9106. FeedetlSn string `json:"feedetl_sn"`
  9107. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9108. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9109. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9110. ListSpItemFlag string `json:"list_sp_item_flag"`
  9111. LmtUsedFlag string `json:"lmt_used_flag"`
  9112. MedChrgitmType string `json:"med_chrgitm_type"`
  9113. Memo string `json:"memo"`
  9114. OverlmtAmt float64 `json:"overlmt_amt"`
  9115. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9116. Pric float64 `json:"pric"`
  9117. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9118. SelfpayProp float64 `json:"selfpay_prop"`
  9119. } `json:"result"`
  9120. } `json:"output"`
  9121. RefmsgTime string `json:"refmsg_time"`
  9122. RespondTime string `json:"respond_time"`
  9123. Signtype string `json:"signtype"`
  9124. WarnMsg string `json:"warn_msg"`
  9125. }
  9126. type ResultFive struct {
  9127. Insutype string `json:"insutype"`
  9128. }
  9129. type ResultSix struct {
  9130. Cainfo interface{} `json:"cainfo"`
  9131. ErrMsg interface{} `json:"err_msg"`
  9132. InfRefmsgid string `json:"inf_refmsgid"`
  9133. Infcode int64 `json:"infcode"`
  9134. Output struct {
  9135. } `json:"output"`
  9136. RefmsgTime string `json:"refmsg_time"`
  9137. RespondTime string `json:"respond_time"`
  9138. Signtype interface{} `json:"signtype"`
  9139. WarnMsg interface{} `json:"warn_msg"`
  9140. }
  9141. type ResultSeven struct {
  9142. Cainfo string `json:"cainfo"`
  9143. ErrMsg string `json:"err_msg"`
  9144. InfRefmsgid string `json:"inf_refmsgid"`
  9145. Infcode int64 `json:"infcode"`
  9146. Output struct {
  9147. Setldetail []interface{} `json:"setldetail"`
  9148. Setlinfo struct {
  9149. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9150. AcctPay float64 `json:"acct_pay"`
  9151. ActPayDedc float64 `json:"act_pay_dedc"`
  9152. Age float64 `json:"age"`
  9153. Balc float64 `json:"balc"`
  9154. Brdy string `json:"brdy"`
  9155. Certno string `json:"certno"`
  9156. ClrOptins string `json:"clr_optins"`
  9157. ClrType string `json:"clr_type"`
  9158. ClrWay string `json:"clr_way"`
  9159. CvlservFlag string `json:"cvlserv_flag"`
  9160. CvlservPay float64 `json:"cvlserv_pay"`
  9161. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9162. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9163. Gend string `json:"gend"`
  9164. HifesPay float64 `json:"hifes_pay"`
  9165. HifmiPay float64 `json:"hifmi_pay"`
  9166. HifobPay float64 `json:"hifob_pay"`
  9167. HifpPay float64 `json:"hifp_pay"`
  9168. HospPartAmt float64 `json:"hosp_part_amt"`
  9169. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9170. Insutype string `json:"insutype"`
  9171. MafPay float64 `json:"maf_pay"`
  9172. MdtrtCertType string `json:"mdtrt_cert_type"`
  9173. MdtrtID string `json:"mdtrt_id"`
  9174. MedType string `json:"med_type"`
  9175. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9176. MedinsSetlID string `json:"medins_setl_id"`
  9177. Naty string `json:"naty"`
  9178. OthPay float64 `json:"oth_pay"`
  9179. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9180. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9181. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9182. PsnCashPay float64 `json:"psn_cash_pay"`
  9183. PsnCertType string `json:"psn_cert_type"`
  9184. PsnName string `json:"psn_name"`
  9185. PsnNo string `json:"psn_no"`
  9186. PsnPartAmt float64 `json:"psn_part_amt"`
  9187. PsnType string `json:"psn_type"`
  9188. SetlID string `json:"setl_id"`
  9189. SetlTime string `json:"setl_time"`
  9190. } `json:"setlinfo"`
  9191. } `json:"output"`
  9192. RefmsgTime string `json:"refmsg_time"`
  9193. RespondTime string `json:"respond_time"`
  9194. Signtype interface{} `json:"signtype"`
  9195. WarnMsg interface{} `json:"warn_msg"`
  9196. }
  9197. type ResultEight struct {
  9198. Cainfo string `json:"cainfo"`
  9199. ErrMsg string `json:"err_msg"`
  9200. InfRefmsgid string `json:"inf_refmsgid"`
  9201. Infcode int64 `json:"infcode"`
  9202. Output struct {
  9203. Stmtinfo struct {
  9204. SetlOptins string `json:"setl_optins"`
  9205. StmtRslt string `json:"stmt_rslt"`
  9206. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9207. } `json:"stmtinfo"`
  9208. } `json:"output"`
  9209. RefmsgTime string `json:"refmsg_time"`
  9210. RespondTime string `json:"respond_time"`
  9211. Signtype interface{} `json:"signtype"`
  9212. WarnMsg interface{} `json:"warn_msg"`
  9213. }
  9214. type ResultNine struct {
  9215. Cainfo string `json:"cainfo"`
  9216. ErrMsg string `json:"err_msg"`
  9217. InfRefmsgid string `json:"inf_refmsgid"`
  9218. Infcode int64 `json:"infcode"`
  9219. Output struct {
  9220. FileQuryNo string `json:"file_qury_no"`
  9221. } `json:"output"`
  9222. RefmsgTime string `json:"refmsg_time"`
  9223. RespondTime string `json:"respond_time"`
  9224. Signtype interface{} `json:"signtype"`
  9225. WarnMsg interface{} `json:"warn_msg"`
  9226. }
  9227. type ResultTen struct {
  9228. Cainfo string `json:"cainfo"`
  9229. ErrMsg string `json:"err_msg"`
  9230. InfRefmsgid string `json:"inf_refmsgid"`
  9231. Infcode int64 `json:"infcode"`
  9232. Output struct {
  9233. DldEndtime string `json:"dld_endtime"`
  9234. FileQuryNo string `json:"file_qury_no"`
  9235. Filename string `json:"filename"`
  9236. } `json:"output"`
  9237. RefmsgTime string `json:"refmsg_time"`
  9238. RespondTime string `json:"respond_time"`
  9239. Signtype interface{} `json:"signtype"`
  9240. WarnMsg interface{} `json:"warn_msg"`
  9241. }
  9242. type ResultEleven struct {
  9243. Cainfo string `json:"cainfo"`
  9244. ErrMsg string `json:"err_msg"`
  9245. InfRefmsgid string `json:"inf_refmsgid"`
  9246. Infcode int64 `json:"infcode"`
  9247. Output struct {
  9248. Setlinfo struct {
  9249. FixmedinsName string `json:"fixmedins_name"`
  9250. FixmedinsCode string `json:"fixmedins_code"`
  9251. PsnNo string `json:"psn_no"`
  9252. PsnName string `json:"psn_name"`
  9253. HifobPay float64 `json:"hifob_pay"`
  9254. Gend string `json:"gend"`
  9255. Brdy string `json:"brdy"`
  9256. PsnCertType string `json:"psn_cert_type"`
  9257. PsnType string `json:"psn_type"`
  9258. EmpName string `json:"emp_name"`
  9259. Certno string `json:"certno"`
  9260. Insutype string `json:"insutype"`
  9261. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9262. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9263. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9264. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9265. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9266. ActPayDedc float64 `json:"act_pay_dedc"`
  9267. HifpPay float64 `json:"hifp_pay"`
  9268. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9269. CvlservPay float64 `json:"cvlserv_pay"`
  9270. HifesPay float64 `json:"hifes_pay"`
  9271. HifmiPay float64 `json:"hifmi_pay"`
  9272. MafPay float64 `json:"maf_pay"`
  9273. OthPay float64 `json:"oth_pay"`
  9274. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9275. PsnPay float64 `json:"psn_pay"`
  9276. AcctPay float64 `json:"acct_pay"`
  9277. CashPayamt float64 `json:"cash_payamt"`
  9278. Balc float64 `json:"balc"`
  9279. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9280. MedinsSetlId string `json:"medins_setl_id"`
  9281. RefdSetlFlag string `json:"refd_setl_flag"`
  9282. SetlTime string `json:"setl_time"`
  9283. MedType string `json:"med_type"`
  9284. } `json:"setlinfo"`
  9285. } `json:"output"`
  9286. RefmsgTime string `json:"refmsg_time"`
  9287. RespondTime string `json:"respond_time"`
  9288. Signtype interface{} `json:"signtype"`
  9289. WarnMsg interface{} `json:"warn_msg"`
  9290. }
  9291. type Custom struct {
  9292. DetItemFeeSumamt string
  9293. Cut string
  9294. FeedetlSn string
  9295. Price string
  9296. MedListCodg string
  9297. Type int64
  9298. AdviceId int64
  9299. ProjectId int64
  9300. ItemId int64
  9301. CostType int64
  9302. }
  9303. // 获取个人信息----挂号-----上传就诊信息
  9304. func (c *HisApiController) GetRegisterInfo() {
  9305. id, _ := c.GetInt64("id")
  9306. record_time := c.GetString("record_time")
  9307. settlementValue, _ := c.GetInt64("settlement_value")
  9308. medical_insurance_card := c.GetString("medical_insurance_card")
  9309. name := c.GetString("name")
  9310. id_card_type, _ := c.GetInt64("id_card_type")
  9311. certificates, _ := c.GetInt64("certificates")
  9312. medical_care, _ := c.GetInt64("medical_care")
  9313. birthday := c.GetString("birthday")
  9314. age, _ := c.GetInt64("age")
  9315. id_card := c.GetString("id_card")
  9316. register_type, _ := c.GetInt64("register")
  9317. doctor, _ := c.GetInt64("doctor")
  9318. department, _ := c.GetInt64("department")
  9319. gender, _ := c.GetInt64("sex")
  9320. phone := c.GetString("phone")
  9321. registration_fee, _ := c.GetFloat("registration_fee")
  9322. medical_expenses, _ := c.GetFloat("medical_expenses")
  9323. social_type, _ := c.GetInt64("social_type")
  9324. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9325. diagnosis_ids := c.GetString("diagnosis")
  9326. sick_type, _ := c.GetInt64("sick_type")
  9327. reg_type := c.GetString("p_type")
  9328. timeLayout := "2006-01-02"
  9329. loc, _ := time.LoadLocation("Local")
  9330. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9331. birthUnix := birthdays.Unix()
  9332. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9333. if err != nil {
  9334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9335. return
  9336. }
  9337. recordDateTime := theTime.Unix()
  9338. adminInfo := c.GetAdminUserInfo()
  9339. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9340. if tempPatient.ID == 0 {
  9341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9342. return
  9343. }
  9344. var patient service.Patients
  9345. if id == 0 {
  9346. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9347. } else {
  9348. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9349. }
  9350. if patient.ID == 0 {
  9351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9352. return
  9353. }
  9354. if len(patient.IdCardNo) == 0 {
  9355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9356. return
  9357. }
  9358. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9359. if len(his) >= 1 {
  9360. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9361. if len(his) >= 1 && order.ID == 0 {
  9362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9363. return
  9364. }
  9365. }
  9366. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9367. fmt.Println(timeStr)
  9368. timeArr := strings.Split(timeStr, " ")
  9369. fmt.Println(timeArr)
  9370. timeArrTwo := strings.Split(timeArr[0], "-")
  9371. timeArrThree := strings.Split(timeArr[1], ":")
  9372. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9373. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9374. if len(lists) == 0 {
  9375. var hisPatient models.XtHisPatient
  9376. hisPatient = models.XtHisPatient{
  9377. Name: name,
  9378. Age: age,
  9379. Gender: gender,
  9380. Birthday: birthUnix,
  9381. Phone: phone,
  9382. MedicalTreatmentType: medical_care,
  9383. IdType: certificates,
  9384. IdCardNo: id_card,
  9385. BalanceAccountsType: settlementValue,
  9386. SocialType: social_type,
  9387. MedicalInsuranceNumber: medical_insurance_card,
  9388. RegisterType: register_type,
  9389. RegisterCost: registration_fee,
  9390. TreatmentCost: medical_expenses,
  9391. AdminUserId: adminInfo.AdminUser.Id,
  9392. UserOrgId: adminInfo.CurrentOrgId,
  9393. Status: 1,
  9394. RecordDate: recordDateTime,
  9395. IsReturn: 1,
  9396. PatientId: patient.ID,
  9397. Ctime: time.Now().Unix(),
  9398. Mtime: time.Now().Unix(),
  9399. Number: str,
  9400. IdCardType: id_card_type,
  9401. Departments: department,
  9402. Doctor: doctor,
  9403. PType: reg_type,
  9404. Diagnosis: diagnosis_ids,
  9405. SickType: sick_type,
  9406. }
  9407. service.CreateHisPatient(&hisPatient)
  9408. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9409. c.ServeSuccessJSON(map[string]interface{}{
  9410. "his_info": hisPatient,
  9411. })
  9412. } else {
  9413. //chrgBchno := rand.Intn(1000000) + 10000
  9414. var hisPatient models.XtHisPatient
  9415. hisPatient = models.XtHisPatient{
  9416. Name: name,
  9417. Age: age,
  9418. Gender: gender,
  9419. Birthday: birthUnix,
  9420. Phone: phone,
  9421. MedicalTreatmentType: medical_care,
  9422. IdType: certificates,
  9423. IdCardNo: id_card,
  9424. BalanceAccountsType: settlementValue,
  9425. SocialType: social_type,
  9426. MedicalInsuranceNumber: medical_insurance_card,
  9427. RegisterType: register_type,
  9428. RegisterCost: registration_fee,
  9429. TreatmentCost: medical_expenses,
  9430. AdminUserId: adminInfo.AdminUser.Id,
  9431. UserOrgId: adminInfo.CurrentOrgId,
  9432. Status: 1,
  9433. RecordDate: recordDateTime,
  9434. IsReturn: 1,
  9435. PatientId: patient.ID,
  9436. Ctime: time.Now().Unix(),
  9437. Mtime: time.Now().Unix(),
  9438. Number: str,
  9439. IdCardType: id_card_type,
  9440. Departments: department,
  9441. Doctor: doctor,
  9442. PType: reg_type,
  9443. Diagnosis: diagnosis_ids,
  9444. SickType: sick_type,
  9445. }
  9446. service.CreateHisPatient(&hisPatient)
  9447. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9448. c.ServeSuccessJSON(map[string]interface{}{
  9449. "his_info": hisPatient,
  9450. })
  9451. }
  9452. }
  9453. // 上传明细----结算
  9454. func (c *HisApiController) GetUploadInfo() {
  9455. id, _ := c.GetInt64("id")
  9456. record_time := c.GetString("record_time")
  9457. his_patient_id, _ := c.GetInt64("his_patient_id")
  9458. oth_desc := c.GetString("oth_desc")
  9459. pay_way, _ := c.GetInt64("pay_way")
  9460. pay_ways := c.GetString("pay_ways")
  9461. pay_price, _ := c.GetFloat("pay_price")
  9462. pay_card_no := c.GetString("pay_card_no")
  9463. discount_price, _ := c.GetFloat("discount_price")
  9464. preferential_price, _ := c.GetFloat("preferential_price")
  9465. reality_price, _ := c.GetFloat("reality_price")
  9466. found_price, _ := c.GetFloat("found_price")
  9467. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9468. private_price, _ := c.GetFloat("private_price")
  9469. timeLayout := "2006-01-02"
  9470. loc, _ := time.LoadLocation("Local")
  9471. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9472. fapiao_code := c.GetString("fapiao_code")
  9473. fapiao_number := c.GetString("fapiao_number")
  9474. diagnosis_id := c.GetString("diagnosis")
  9475. sick_type, _ := c.GetInt64("sick_type")
  9476. reg_type, _ := c.GetInt64("p_type")
  9477. order_id, _ := c.GetInt64("order_id")
  9478. cash_pay := c.GetString("cash_pay")
  9479. wechat_pay := c.GetString("wechat_pay")
  9480. ali_pay := c.GetString("ali_pay")
  9481. jifen_pay := c.GetString("jifen_pay")
  9482. card_desc := c.GetString("card_desc")
  9483. band_card_pay := c.GetString("band_card_pay")
  9484. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9485. tmp_decimal := c.GetString("tmp_decimal")
  9486. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9487. var decimal float64 //本次使用的押金
  9488. var errmsg error
  9489. tx := service.XTWriteDB().Begin() //开了事务
  9490. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9491. defer func() {
  9492. if errmsg != nil {
  9493. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9494. tx.Rollback()
  9495. } else {
  9496. tx.Commit()
  9497. }
  9498. }()
  9499. fmt.Println("dec_way", dec_way)
  9500. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9501. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9502. return
  9503. }
  9504. if len(tmp_decimal) > 0 {
  9505. if tmp_decimal[0] == 45 {
  9506. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9507. return
  9508. }
  9509. }
  9510. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9511. fmt.Println(errs)
  9512. decimal = tt
  9513. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9514. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9515. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9516. if err != nil {
  9517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9518. return
  9519. }
  9520. recordDateTime := theTime.Unix()
  9521. adminUser := c.GetAdminUserInfo()
  9522. var prescriptions []*models.HisPrescription
  9523. var prescriptionsOne []*models.HisPrescription
  9524. var start_time int64
  9525. var end_time int64
  9526. ids_str := c.GetString("ids")
  9527. ids_arr := strings.Split(ids_str, ",")
  9528. if tempOrder.ID == 0 {
  9529. if settle_accounts_type == 1 { //日结
  9530. fmt.Println(reg_type)
  9531. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9532. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9533. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9534. } else {
  9535. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9536. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9537. }
  9538. } else { //月结
  9539. start_time_str := c.GetString("start_time")
  9540. end_time_str := c.GetString("end_time")
  9541. timeLayout := "2006-01-02"
  9542. loc, _ := time.LoadLocation("Local")
  9543. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9544. if err != nil {
  9545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9546. return
  9547. }
  9548. recordStartTime := theStartTime.Unix()
  9549. start_time = recordStartTime
  9550. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9551. if err != nil {
  9552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9553. return
  9554. }
  9555. recordEndTime := theEndTime.Unix()
  9556. end_time = recordEndTime
  9557. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9558. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9559. }
  9560. var goods []*models.DialysisBeforePrepareGoods
  9561. var newGoods []*models.NewDialysisBeforePrepareGoods
  9562. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9563. var infos []*models.HisDoctorAdviceInfo
  9564. var infoList []*models.HisDoctorAdviceInfo
  9565. var hisAdvice []*models.HisDoctorAdviceInfo
  9566. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9567. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9568. //判断库存不足
  9569. //结算出库开关
  9570. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9571. if settConfig.IsOpen == 1 {
  9572. //判断库存的地方
  9573. for _, info := range prescriptions {
  9574. if info.Type == 1 {
  9575. infos = append(infos, info.HisDoctorAdviceInfo...)
  9576. }
  9577. if info.Type == 2 {
  9578. for _, sumItem := range info.HisPrescriptionProject {
  9579. if sumItem.Type == 3 {
  9580. var good models.DialysisBeforePrepareGoods
  9581. var newGood models.NewDialysisBeforePrepareGoods
  9582. good.GoodId = sumItem.GoodInfo.ID
  9583. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9584. count, _ := strconv.Atoi(sumItem.Count)
  9585. good.Count = int64(count)
  9586. good.StorehouseId = houseConfig.StorehouseOutInfo
  9587. good.ProjectId = sumItem.ID
  9588. goods = append(goods, &good)
  9589. newGood.GoodId = sumItem.GoodInfo.ID
  9590. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9591. count2, _ := strconv.Atoi(sumItem.Count)
  9592. newGood.Count = int64(count2)
  9593. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9594. newGood.ProjectId = sumItem.ID
  9595. newGoods = append(newGoods, &newGood)
  9596. }
  9597. }
  9598. }
  9599. }
  9600. for _, info := range prescriptionsOne {
  9601. if info.Type == 1 {
  9602. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9603. }
  9604. if info.Type == 2 {
  9605. for _, sumItem := range info.HisPrescriptionProject {
  9606. if sumItem.Type == 3 {
  9607. var newGood models.NewDialysisBeforePrepareGoods
  9608. newGood.GoodId = sumItem.GoodInfo.ID
  9609. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9610. count2, _ := strconv.Atoi(sumItem.Count)
  9611. newGood.Count = int64(count2)
  9612. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9613. newGood.ProjectId = sumItem.ID
  9614. newGoodOne = append(newGoodOne, &newGood)
  9615. }
  9616. }
  9617. }
  9618. }
  9619. //判断
  9620. for _, itemOne := range infos {
  9621. for _, itemTwo := range hisAdvice {
  9622. if itemOne.DrugId == itemTwo.DrugId {
  9623. itemTwo.Child = append(itemTwo.Child, itemOne)
  9624. }
  9625. }
  9626. }
  9627. for _, itemTwo := range hisAdvice {
  9628. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9629. var sum_out_count int64
  9630. for _, itemThree := range itemTwo.Child {
  9631. var prescribing_number int64
  9632. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9633. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9634. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9635. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9636. }
  9637. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9638. prescribing_number = parseIntPrescribingNumber
  9639. }
  9640. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9641. prescribing_number = parseIntPrescribingNumber
  9642. }
  9643. sum_out_count += prescribing_number
  9644. }
  9645. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9646. if sum_out_count > drugStockOut.FlushCount {
  9647. c.ServeSuccessJSON(map[string]interface{}{
  9648. "msg": "2",
  9649. "drug": medical,
  9650. })
  9651. return
  9652. }
  9653. }
  9654. for _, itemOne := range newGoods {
  9655. for _, item := range newGoodOne {
  9656. if itemOne.GoodId == item.GoodId {
  9657. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9658. }
  9659. }
  9660. }
  9661. for _, item := range newGoodOne {
  9662. var sum_out_count_one int64
  9663. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9664. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9665. sum_out_count_one += itemOne.Count
  9666. }
  9667. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9668. fmt.Println("sum_out_count_one", sum_out_count_one)
  9669. fmt.Println("list.FlushCount", list.FlushCount)
  9670. if sum_out_count_one > list.FlushCount {
  9671. c.ServeSuccessJSON(map[string]interface{}{
  9672. "msg": "3",
  9673. "good": good,
  9674. })
  9675. return
  9676. }
  9677. }
  9678. }
  9679. timestamp := time.Now().Unix()
  9680. tempTime := time.Unix(timestamp, 0)
  9681. timeFormat := tempTime.Format("20060102150405")
  9682. chrgBchno := rand.Intn(100000) + 10000
  9683. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9684. strconv.FormatInt(his.PatientId, 10)
  9685. var ids []int64
  9686. for _, item := range prescriptions {
  9687. ids = append(ids, item.ID)
  9688. }
  9689. var total float64
  9690. for _, item := range prescriptions {
  9691. fmt.Println(item)
  9692. if item.Type == 1 { //药品
  9693. for _, subItem := range item.HisDoctorAdviceInfo {
  9694. if subItem.Drug.IsUser != 1 {
  9695. total = total + (subItem.Price * subItem.PrescribingNumber)
  9696. }
  9697. }
  9698. }
  9699. if item.Type == 2 { //项目
  9700. for _, subItem := range item.HisPrescriptionProject {
  9701. if subItem.Type == 2 {
  9702. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9703. total = total + (subItem.Price * cnt)
  9704. } else {
  9705. if subItem.GoodInfo.IsUser != 1 {
  9706. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9707. total = total + (subItem.Price * cnt)
  9708. }
  9709. }
  9710. }
  9711. }
  9712. for _, subItem := range item.HisAdditionalCharge {
  9713. total = total + (subItem.Price * float64(subItem.Count))
  9714. }
  9715. }
  9716. if reg_type == 1111 || reg_type == 1112 {
  9717. reg_type = 11
  9718. }
  9719. tm := time.Unix(time.Now().Unix(), 0)
  9720. allTotal := fmt.Sprintf("%.4f", total)
  9721. totals, _ := strconv.ParseFloat(allTotal, 64)
  9722. order := &models.HisOrder{
  9723. UserOrgId: adminUser.CurrentOrgId,
  9724. HisPatientId: his.ID,
  9725. PatientId: id,
  9726. SettleAccountsDate: recordDateTime,
  9727. Ctime: time.Now().Unix(),
  9728. Mtime: time.Now().Unix(),
  9729. Status: 1,
  9730. OrderStatus: 2,
  9731. MdtrtId: his.Number,
  9732. Number: chrg_bchno,
  9733. MedfeeSumamt: totals,
  9734. PayWay: pay_way,
  9735. PayWays: pay_ways,
  9736. PayPrice: pay_price,
  9737. MedType: strconv.Itoa(int(reg_type)),
  9738. PayCardNo: pay_card_no,
  9739. DiscountPrice: discount_price,
  9740. PreferentialPrice: preferential_price,
  9741. RealityPrice: reality_price,
  9742. FoundPrice: found_price,
  9743. MedicalInsurancePrice: medical_insurance_price,
  9744. PrivatePrice: private_price,
  9745. SettleEndTime: end_time,
  9746. SettleStartTime: start_time,
  9747. PsnPartAmt: totals,
  9748. PsnCashPay: totals,
  9749. SettleType: settle_accounts_type,
  9750. FaPiaoCode: fapiao_code,
  9751. FaPiaoNumber: fapiao_number,
  9752. Diagnosis: diagnosis_id,
  9753. PType: 2,
  9754. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9755. Decimal: decimal,
  9756. OthDesc: oth_desc,
  9757. CashPay: cash_pay,
  9758. WechatPay: wechat_pay,
  9759. AliPay: ali_pay,
  9760. JifenPay: jifen_pay,
  9761. BandCardPay: band_card_pay,
  9762. Creator: adminUser.AdminUser.Id,
  9763. CardDesc: card_desc,
  9764. }
  9765. err = service.CreateOrderTX(order, tx)
  9766. if err != nil {
  9767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9768. return
  9769. }
  9770. var customs []*Custom
  9771. for _, item := range prescriptions {
  9772. if item.Type == 1 { //药品a
  9773. for _, subItem := range item.HisDoctorAdviceInfo {
  9774. if subItem.Drug.IsUser != 1 {
  9775. cus := &Custom{
  9776. AdviceId: subItem.ID,
  9777. ProjectId: 0,
  9778. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9779. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9780. FeedetlSn: subItem.FeedetlSn,
  9781. Price: fmt.Sprintf("%.4f", subItem.Price),
  9782. MedListCodg: subItem.MedListCodg,
  9783. Type: 1,
  9784. CostType: 9,
  9785. }
  9786. customs = append(customs, cus)
  9787. }
  9788. }
  9789. }
  9790. if item.Type == 2 { //项目
  9791. for _, subItem := range item.HisPrescriptionProject {
  9792. if subItem.Type == 2 {
  9793. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9794. cus := &Custom{
  9795. AdviceId: 0,
  9796. ProjectId: subItem.ID,
  9797. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9798. Cut: fmt.Sprintf("%.4f", cnt),
  9799. FeedetlSn: subItem.FeedetlSn,
  9800. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9801. MedListCodg: subItem.MedListCodg,
  9802. Type: 2,
  9803. CostType: subItem.HisProject.CostClassify,
  9804. }
  9805. customs = append(customs, cus)
  9806. } else {
  9807. if subItem.GoodInfo.IsUser != 1 {
  9808. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9809. cus := &Custom{
  9810. AdviceId: 0,
  9811. ProjectId: subItem.ID,
  9812. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9813. Cut: fmt.Sprintf("%.4f", cnt),
  9814. FeedetlSn: subItem.FeedetlSn,
  9815. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9816. MedListCodg: subItem.MedListCodg,
  9817. Type: 2,
  9818. CostType: subItem.HisProject.CostClassify,
  9819. }
  9820. customs = append(customs, cus)
  9821. }
  9822. }
  9823. }
  9824. }
  9825. for _, item := range item.HisAdditionalCharge {
  9826. cus := &Custom{
  9827. ItemId: item.ID,
  9828. AdviceId: 0,
  9829. ProjectId: 0,
  9830. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9831. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9832. FeedetlSn: item.FeedetlSn,
  9833. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9834. MedListCodg: item.XtHisAddtionConfig.Code,
  9835. Type: 3,
  9836. CostType: 5,
  9837. }
  9838. customs = append(customs, cus)
  9839. }
  9840. }
  9841. for _, item := range customs {
  9842. var advice_id int64 = 0
  9843. var project_id int64 = 0
  9844. var item_id int64 = 0
  9845. var types int64 = 0
  9846. var med_chrgitm_type string
  9847. if item.Type == 1 {
  9848. advice_id = item.AdviceId
  9849. project_id = 0
  9850. item_id = 0
  9851. med_chrgitm_type = "09"
  9852. } else if item.Type == 2 {
  9853. med_chrgitm_type = "05"
  9854. if item.CostType == 3 {
  9855. med_chrgitm_type = "04"
  9856. }
  9857. if item.CostType == 8 {
  9858. med_chrgitm_type = "03"
  9859. }
  9860. advice_id = 0
  9861. item_id = 0
  9862. project_id = item.ProjectId
  9863. } else if item.Type == 3 {
  9864. advice_id = 0
  9865. item_id = item.ItemId
  9866. project_id = 0
  9867. med_chrgitm_type = "08"
  9868. }
  9869. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9870. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9871. pric, _ := strconv.ParseFloat(item.Price, 32)
  9872. info := &models.HisOrderInfo{
  9873. OrderNumber: order.Number,
  9874. UploadDate: time.Now().Unix(),
  9875. AdviceId: advice_id,
  9876. DetItemFeeSumamt: detItemFeeSumamt,
  9877. MedChrgitmType: med_chrgitm_type,
  9878. Cnt: cut,
  9879. Pric: pric,
  9880. PatientId: id,
  9881. Status: 1,
  9882. Mtime: time.Now().Unix(),
  9883. Ctime: time.Now().Unix(),
  9884. UserOrgId: adminUser.CurrentOrgId,
  9885. HisPatientId: his.ID,
  9886. OrderId: order.ID,
  9887. ProjectId: project_id,
  9888. Type: types,
  9889. ItemId: item_id,
  9890. }
  9891. service.CreateOrderInfoTX(info, tx)
  9892. }
  9893. his.Diagnosis = diagnosis_id
  9894. his.SickType = sick_type
  9895. his.RegisterType = reg_type
  9896. his.MedicalTreatmentType = reg_type
  9897. service.UpdataHisPateintTX(&his, tx)
  9898. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9899. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9900. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9901. //判断是否使用了押金
  9902. if dec_way == "true" {
  9903. tmpstring := strconv.FormatInt(order.ID, 10)
  9904. //扣押金
  9905. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9906. order.Decimal = decimal
  9907. service.UpDateOrderTwo(order, tx)
  9908. if errmsg != nil {
  9909. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9910. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9911. return
  9912. }
  9913. }
  9914. if err == nil {
  9915. for _, info := range prescriptions {
  9916. if info.Type == 1 {
  9917. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9918. }
  9919. if info.Type == 2 {
  9920. for _, sumItem := range info.HisPrescriptionProject {
  9921. if sumItem.Type == 3 {
  9922. var good models.DialysisBeforePrepareGoods
  9923. var newGood models.NewDialysisBeforePrepareGoods
  9924. var oldGood models.OldDialysisBeforePrepareGoods
  9925. good.GoodId = sumItem.GoodInfo.ID
  9926. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9927. count, _ := strconv.Atoi(sumItem.Count)
  9928. good.Count = int64(count)
  9929. good.StorehouseId = houseConfig.StorehouseOutInfo
  9930. good.ProjectId = sumItem.ID
  9931. good.PatientId = sumItem.PatientId
  9932. goods = append(goods, &good)
  9933. newGood.GoodId = sumItem.GoodInfo.ID
  9934. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9935. count2, _ := strconv.Atoi(sumItem.Count)
  9936. newGood.Count = int64(count2)
  9937. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9938. newGood.ProjectId = sumItem.ID
  9939. newGood.PatientId = sumItem.HisPatientId
  9940. newGoods = append(newGoods, &newGood)
  9941. oldGood.GoodId = sumItem.GoodInfo.ID
  9942. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9943. count3, _ := strconv.Atoi(sumItem.Count)
  9944. oldGood.Count = int64(count3)
  9945. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9946. oldGood.ProjectId = sumItem.ID
  9947. oldGood.RecordDate = sumItem.RecordDate
  9948. oldGood.PatientId = sumItem.HisPatientId
  9949. oldGoods = append(oldGoods, &oldGood)
  9950. }
  9951. }
  9952. }
  9953. }
  9954. if settConfig.IsOpen == 1 {
  9955. for _, item := range infoList {
  9956. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9957. if medical.IsUse == 2 {
  9958. //药品出库
  9959. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9960. //查询默认仓库
  9961. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9962. //查询默认仓库剩余多少库存
  9963. var sum_count int64
  9964. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9965. for _, its := range stockInfo {
  9966. if its.MaxUnit == medical.MaxUnit {
  9967. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9968. }
  9969. sum_count += its.StockMaxNumber + its.StockMinNumber
  9970. }
  9971. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9972. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9973. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9974. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9975. }
  9976. }
  9977. orgId := c.GetAdminUserInfo().CurrentOrgId
  9978. if len(oldGoods) > 0 {
  9979. timeStr := time.Now().Format("2006-01-02")
  9980. timeArr := strings.Split(timeStr, "-")
  9981. total, _ := service.FindAllWarehouseOut(orgId)
  9982. total = total + 1
  9983. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9984. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9985. number = number + total
  9986. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9987. operation_time := time.Now().Unix()
  9988. creater := c.GetAdminUserInfo().AdminUser.Id
  9989. //查询默认出库仓库库存
  9990. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9991. recordDateStr := time.Now().Format("2006-01-02")
  9992. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9993. nowtime := recordDate.Unix()
  9994. warehouseOut := models.WarehouseOut{
  9995. WarehouseOutOrderNumber: warehousing_out_order,
  9996. OperationTime: operation_time,
  9997. OrgId: orgId,
  9998. Creater: creater,
  9999. Ctime: time.Now().Unix(),
  10000. Status: 1,
  10001. WarehouseOutTime: nowtime,
  10002. Type: 1,
  10003. StorehouseId: storeConfig.StorehouseOutInfo,
  10004. IsCheck: 1,
  10005. OrderId: order.ID,
  10006. IsSys: 5,
  10007. }
  10008. //查询是否生成出库单
  10009. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10010. if out.ID == 0 {
  10011. service.AddSigleWarehouseOutOne(&warehouseOut)
  10012. }
  10013. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10014. for _, item := range oldGoods {
  10015. dialyPrepareOne := models.DialysisBeforePrepare{
  10016. GoodTypeId: item.GoodTypeId,
  10017. GoodId: item.GoodId,
  10018. PatientId: his.PatientId,
  10019. RecordDate: item.RecordDate,
  10020. UserOrgId: adminUser.CurrentOrgId,
  10021. Count: item.Count,
  10022. Ctime: time.Now().Unix(),
  10023. Creater: adminUser.AdminUser.Id,
  10024. CommdityCode: item.CommdityCode,
  10025. Status: 1,
  10026. StorehouseId: houseConfig.StorehouseOutInfo,
  10027. }
  10028. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  10029. //非零用
  10030. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  10031. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10032. //查询剩余库存
  10033. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10034. var sum_count int64
  10035. for _, item := range goodList {
  10036. sum_count += item.StockCount
  10037. }
  10038. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10039. //耗材
  10040. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10041. }
  10042. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  10043. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10044. //查询剩余库存
  10045. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10046. var sum_count int64
  10047. for _, item := range goodList {
  10048. sum_count += item.StockCount
  10049. }
  10050. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10051. //耗材
  10052. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10053. }
  10054. }
  10055. }
  10056. }
  10057. c.ServeSuccessJSON(map[string]interface{}{
  10058. "msg": "结算成功",
  10059. })
  10060. }
  10061. }
  10062. }
  10063. // 退款
  10064. func (c *HisApiController) Refund() {
  10065. order_id, _ := c.GetInt64("order_id")
  10066. order, _ := service.GetHisOrderByID(order_id)
  10067. adminUser := c.GetAdminUserInfo()
  10068. orgid := c.GetAdminUserInfo().CurrentOrgId
  10069. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  10070. if err != nil {
  10071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10072. return
  10073. }
  10074. tmp := strconv.FormatInt(order.ID, 10)
  10075. //当押金不为零时产生退费记录
  10076. if order.Decimal != 0 {
  10077. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  10078. if err != nil {
  10079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10080. return
  10081. }
  10082. }
  10083. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  10084. if fapiao.ID > 0 {
  10085. c.ServeSuccessJSON(map[string]interface{}{
  10086. "failed_code": -10,
  10087. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  10088. })
  10089. return
  10090. }
  10091. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  10092. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  10093. var goods []*models.DialysisBeforePrepareGoods
  10094. var newGoods []*models.NewDialysisBeforePrepareGoods
  10095. var infos []*models.HisDoctorAdviceInfo
  10096. for _, info := range orders {
  10097. if info.AdviceId > 0 && info.ProjectId == 0 {
  10098. infos = append(infos, &info.HisDoctorAdviceInfo)
  10099. }
  10100. if info.ProjectId > 0 && info.AdviceId == 0 {
  10101. if info.HisPrescriptionProject.Type == 3 {
  10102. var good models.DialysisBeforePrepareGoods
  10103. var newGood models.NewDialysisBeforePrepareGoods
  10104. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10105. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10106. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10107. good.Count = int64(count)
  10108. good.StorehouseId = houseConfig.StorehouseOutInfo
  10109. good.ProjectId = info.HisPrescriptionProject.ID
  10110. good.PatientId = info.PatientId
  10111. good.OrderId = order_id
  10112. goods = append(goods, &good)
  10113. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10114. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10115. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10116. newGood.Count = int64(count2)
  10117. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10118. newGood.ProjectId = info.HisPrescriptionProject.ID
  10119. newGood.RecordDate = order.SettleAccountsDate
  10120. newGood.UserOrgId = order.UserOrgId
  10121. newGood.PatientId = info.PatientId
  10122. newGood.OrderId = order_id
  10123. newGoods = append(newGoods, &newGood)
  10124. }
  10125. }
  10126. }
  10127. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10128. if settConfig.IsOpen == 1 {
  10129. for _, item := range infos {
  10130. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10131. }
  10132. for _, item := range newGoods {
  10133. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10134. }
  10135. }
  10136. c.ServeSuccessJSON(map[string]interface{}{
  10137. "msg": "退费成功",
  10138. })
  10139. }
  10140. func (c *HisApiController) RefundNumber() {
  10141. his_patient_id, _ := c.GetInt64("id")
  10142. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10143. info.Status = 0
  10144. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10145. if count > 0 {
  10146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10147. return
  10148. }
  10149. err := service.SaveHisPatient(info)
  10150. if err == nil {
  10151. c.ServeSuccessJSON(map[string]interface{}{
  10152. "msg": "退号成功",
  10153. })
  10154. } else {
  10155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10156. return
  10157. }
  10158. }
  10159. func (this *HisApiController) AdditionalCharge() {
  10160. dataBody := make(map[string]interface{}, 0)
  10161. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10162. fmt.Println(err)
  10163. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10164. patient_id := int64(dataBody["patient_id"].(float64))
  10165. medicineData, _ := dataBody["medicineData"].([]interface{})
  10166. adminUserInfo := this.GetAdminUserInfo()
  10167. orgId := adminUserInfo.CurrentOrgId
  10168. admin_user_id := adminUserInfo.AdminUser.Id
  10169. timeStr := time.Now().Format("2006-01-02")
  10170. timeLayout := "2006-01-02 15:04:05"
  10171. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10172. timenow := timeStringToTime.Unix()
  10173. var additionalCharges []*models.HisAdditionalCharge
  10174. for _, item := range medicineData {
  10175. var randNum int
  10176. randNum = rand.Intn(10000) + 1000
  10177. timestamp := time.Now().Unix()
  10178. tempTime := time.Unix(timestamp, 0)
  10179. timeFormat := tempTime.Format("20060102150405")
  10180. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10181. items := item.(map[string]interface{})
  10182. money := items["price"].(string)
  10183. item_id_str := items["item_id"].(string)
  10184. name := items["name"].(string)
  10185. id_str := items["id"].(string)
  10186. moneys, _ := strconv.ParseInt(money, 10, 64)
  10187. monStr := strconv.FormatInt(moneys, 10)
  10188. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10189. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10190. id, _ := strconv.ParseInt(id_str, 10, 64)
  10191. additionalCharge := &models.HisAdditionalCharge{
  10192. ID: id,
  10193. HisPatientId: his_patient_id,
  10194. UserOrgId: orgId,
  10195. PatientId: patient_id,
  10196. RecordDate: timenow,
  10197. Price: monneyStr,
  10198. Status: 1,
  10199. ItemName: name,
  10200. ItemId: item_id,
  10201. AdminUserId: admin_user_id,
  10202. CreatedTime: time.Now().Unix(),
  10203. OrderStatus: 0,
  10204. PrescriptionNumber: "",
  10205. BatchNumber: "",
  10206. FeedetlSn: p_number,
  10207. }
  10208. service.CreateAdditionalCharge(additionalCharge)
  10209. additionalCharges = append(additionalCharges, additionalCharge)
  10210. }
  10211. this.ServeSuccessJSON(map[string]interface{}{
  10212. "msg": "添加成功",
  10213. "additional_charges": additionalCharges,
  10214. })
  10215. }
  10216. func (this *HisApiController) DeleteAddition() {
  10217. id, _ := this.GetInt64("id")
  10218. //TODO 需要判断是否已经结算
  10219. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10220. if err == nil {
  10221. this.ServeSuccessJSON(map[string]interface{}{
  10222. "msg": "删除成功",
  10223. })
  10224. return
  10225. } else {
  10226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10227. return
  10228. }
  10229. }
  10230. func (this *HisApiController) GetAdminUsers() {
  10231. adminUser := this.GetAdminUserInfo()
  10232. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10233. this.ServeSuccessJSON(map[string]interface{}{
  10234. "doctors": doctors,
  10235. })
  10236. }
  10237. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10238. change_type, _ := this.GetInt64("type", 0)
  10239. record_date := this.GetString("record_time")
  10240. patient_id, _ := this.GetInt64("patient_id", 0)
  10241. p_type, _ := this.GetInt64("p_type", 0)
  10242. timeLayout := "2006-01-02"
  10243. loc, _ := time.LoadLocation("Local")
  10244. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10245. record_time := theAdviceRecordTime.Unix()
  10246. adminUserInfo := this.GetAdminUserInfo()
  10247. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10248. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10249. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10250. if config.ID > 0 && config.IsOpen == 1 {
  10251. for _, subitems := range prescriptions {
  10252. for _, item := range subitems.VMHisPrescription {
  10253. for _, subItem := range item.HisDoctorAdviceInfo {
  10254. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10255. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10256. if info.RetailPrice > 0 {
  10257. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10258. subItem.Drug.RetailPrice = drug.RetailPrice
  10259. }
  10260. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10261. subItem.Drug.MinPrice = info.RetailPrice
  10262. subItem.Drug.RetailPrice = info.RetailPrice
  10263. }
  10264. }
  10265. }
  10266. }
  10267. }
  10268. }
  10269. if config.ID > 0 && config.IsOpen == 1 {
  10270. for _, subitems := range prescriptions {
  10271. for _, item := range subitems.VMHisPrescription {
  10272. for _, subItem := range item.HisPrescriptionProject {
  10273. if subItem.Type == 3 {
  10274. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10275. if info.Price > 0 {
  10276. subItem.GoodInfo.PackingPrice = info.Price
  10277. }
  10278. }
  10279. }
  10280. }
  10281. }
  10282. }
  10283. }
  10284. if err == nil {
  10285. if len(prescriptions) == 0 {
  10286. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10287. return
  10288. } else {
  10289. this.ServeSuccessJSON(map[string]interface{}{
  10290. "prescriptions": prescriptions,
  10291. })
  10292. return
  10293. }
  10294. } else {
  10295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10296. return
  10297. }
  10298. }
  10299. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10300. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10301. for i := 0; i < len(arr); i++ {
  10302. repeat := false
  10303. for j := i + 1; j < len(arr); j++ {
  10304. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10305. repeat = true
  10306. break
  10307. }
  10308. }
  10309. if !repeat {
  10310. newArr = append(newArr, arr[i])
  10311. }
  10312. }
  10313. return
  10314. }
  10315. func (this *HisApiController) GetCallHisPrescription() {
  10316. patient_id, _ := this.GetInt64("patient_id", 0)
  10317. timeLayout := "2006-01-02"
  10318. loc, _ := time.LoadLocation("Local")
  10319. start_time := this.GetString("start_time")
  10320. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10321. end_time := this.GetString("end_time")
  10322. p_type, _ := this.GetInt64("p_type")
  10323. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10324. adminUserInfo := this.GetAdminUserInfo()
  10325. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10326. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10327. //if
  10328. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10329. //
  10330. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10331. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10332. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10333. if config.ID > 0 && config.IsOpen == 1 {
  10334. for _, subitems := range prescriptions {
  10335. for _, item := range subitems.VMHisPrescription {
  10336. for _, subItem := range item.HisDoctorAdviceInfo {
  10337. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10338. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10339. if info.RetailPrice > 0 {
  10340. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10341. subItem.Drug.RetailPrice = drug.RetailPrice
  10342. }
  10343. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10344. subItem.Drug.MinPrice = info.RetailPrice
  10345. subItem.Drug.RetailPrice = info.RetailPrice
  10346. }
  10347. }
  10348. }
  10349. }
  10350. }
  10351. }
  10352. if config.ID > 0 && config.IsOpen == 1 {
  10353. for _, subitems := range prescriptions {
  10354. for _, item := range subitems.VMHisPrescription {
  10355. for _, subItem := range item.HisPrescriptionProject {
  10356. if subItem.Type == 3 {
  10357. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10358. if info.Price > 0 {
  10359. subItem.GoodInfo.PackingPrice = info.Price
  10360. }
  10361. }
  10362. }
  10363. }
  10364. }
  10365. }
  10366. }
  10367. if err == nil {
  10368. this.ServeSuccessJSON(map[string]interface{}{
  10369. "prescriptions": prescriptions,
  10370. })
  10371. return
  10372. } else {
  10373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10374. return
  10375. }
  10376. }
  10377. func (this *HisApiController) GetHisDayPrescription() {
  10378. timeLayout := "2006-01-02"
  10379. loc, _ := time.LoadLocation("Local")
  10380. start_time := this.GetString("start_time")
  10381. patient_id, _ := this.GetInt64("patient_id", 0)
  10382. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10383. end_time := this.GetString("end_time")
  10384. p_type, _ := this.GetInt64("p_type")
  10385. order_status, _ := this.GetInt64("type")
  10386. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10387. adminUserInfo := this.GetAdminUserInfo()
  10388. var dayHisPrescription []*models.HisPrescription
  10389. var err error
  10390. if order_status == 1 || order_status == 0 {
  10391. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10392. } else if order_status == 2 {
  10393. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10394. }
  10395. var settle_total float64
  10396. for _, item := range dayHisPrescription {
  10397. if len(item.HisPrescriptionProject) > 0 {
  10398. for _, subItem := range item.HisPrescriptionProject {
  10399. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10400. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10401. settle_total = settle_total + total
  10402. }
  10403. }
  10404. if len(item.HisDoctorAdviceInfo) > 0 {
  10405. for _, subItem := range item.HisDoctorAdviceInfo {
  10406. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10407. settle_total = settle_total + total
  10408. }
  10409. }
  10410. }
  10411. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10412. if err == nil {
  10413. this.ServeSuccessJSON(map[string]interface{}{
  10414. "day_prescription": dayHisPrescription,
  10415. "settle_total": settle_total,
  10416. })
  10417. return
  10418. } else {
  10419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10420. return
  10421. }
  10422. }
  10423. func (c *HisApiController) GetHisChargePatientList() {
  10424. record_date := c.GetString("record_date")
  10425. order_status, _ := c.GetInt64("type")
  10426. sch_type, _ := c.GetInt64("sch_type")
  10427. timeLayout := "2006-01-02"
  10428. loc, _ := time.LoadLocation("Local")
  10429. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10430. if err != nil {
  10431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10432. return
  10433. }
  10434. recordDateTime := theTime.Unix()
  10435. adminInfo := c.GetAdminUserInfo()
  10436. var tempPatients []*service.NewTempPatients
  10437. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10438. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10439. if order_status != 2 {
  10440. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10441. } else {
  10442. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10443. }
  10444. } else {
  10445. if order_status != 2 {
  10446. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10447. } else {
  10448. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10449. }
  10450. }
  10451. var patients []*service.NewTempPatients
  10452. var patients_two []*service.NewTempPatients
  10453. for _, item := range tempPatients {
  10454. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10455. //过滤掉没挂号的和没开处方的
  10456. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10457. patients = append(patients, item)
  10458. }
  10459. //过滤掉没挂号的
  10460. if len(item.HisPatient) > 0 {
  10461. patients_two = append(patients_two, item)
  10462. }
  10463. } else {
  10464. if len(item.HisPrescription) > 0 {
  10465. patients = append(patients, item)
  10466. }
  10467. }
  10468. }
  10469. c.ServeSuccessJSON(map[string]interface{}{
  10470. "list": patients,
  10471. "list_two": patients_two,
  10472. })
  10473. }
  10474. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10475. record_date := c.GetString("record_date")
  10476. timeLayout := "2006-01-02"
  10477. loc, _ := time.LoadLocation("Local")
  10478. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10479. if err != nil {
  10480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10481. return
  10482. }
  10483. recordDateTime := theTime.Unix()
  10484. adminUser := c.GetAdminUserInfo()
  10485. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10486. var patients []*service.Patients
  10487. for _, item := range tempPatients {
  10488. if item.HisPatient.ID == 0 {
  10489. patients = append(patients, item)
  10490. }
  10491. }
  10492. c.ServeSuccessJSON(map[string]interface{}{
  10493. "list": patients,
  10494. //"list_two": patients_two,
  10495. })
  10496. }
  10497. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10498. newArr = make([]*service.Patients, 0)
  10499. for i := 0; i < len(patient); i++ {
  10500. repeat := false
  10501. for j := i + 1; j < len(patient); j++ {
  10502. if patient[i].ID == patient[j].ID {
  10503. repeat = true
  10504. break
  10505. }
  10506. }
  10507. if !repeat {
  10508. newArr = append(newArr, patient[i])
  10509. }
  10510. }
  10511. return
  10512. }
  10513. func (c *HisApiController) GetHisChargePatientInfo() {
  10514. patient_id, _ := c.GetInt64("patient_id")
  10515. his_patient_id, _ := c.GetInt64("his_patient_id")
  10516. record_date := c.GetString("record_date")
  10517. //start_time := c.GetString("start_time")
  10518. //end_time := c.GetString("end_time")
  10519. order_status, _ := c.GetInt64("type", 0)
  10520. p_type, _ := c.GetInt64("p_type", 0)
  10521. order_id, _ := c.GetInt64("order_id", 0)
  10522. timeLayout := "2006-01-02"
  10523. loc, _ := time.LoadLocation("Local")
  10524. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10525. if err != nil {
  10526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10527. return
  10528. }
  10529. recordDateTime := theTime.Unix()
  10530. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10531. //if err != nil {
  10532. //
  10533. //}
  10534. //startRecordDateTime := startTime.Unix()
  10535. //
  10536. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10537. //if err != nil {
  10538. //
  10539. //}
  10540. //endRecordDateTime := endTime.Unix()
  10541. admin := c.GetAdminUserInfo()
  10542. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10543. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10544. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10545. var prescriptions []*models.HisPrescription
  10546. //var unChargeMonthPrescriptions []*models.HisPrescription
  10547. order, _ := service.GetHisOrderByID(order_id)
  10548. if order_status == 1 || order_status == 0 {
  10549. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10550. } else if order_status == 2 {
  10551. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10552. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10553. }
  10554. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10555. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10556. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10557. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10558. //获取所有科室信息
  10559. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10560. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10561. c.ServeSuccessJSON(map[string]interface{}{
  10562. "his_info": his_patient_info,
  10563. "last_his_patient_info": last_his_patient_info,
  10564. "xt_info": xt_patient_info,
  10565. "prescription": prescriptions,
  10566. "case_history": case_history,
  10567. "info": patientPrescriptionInfo,
  10568. "last_info": lastPatientPrescriptionInfo,
  10569. "order": order,
  10570. "doctors": doctors,
  10571. "department": department,
  10572. "sch": sch,
  10573. })
  10574. return
  10575. }
  10576. func (c *HisApiController) GetAllOrderDetail() {
  10577. order_id, _ := c.GetInt64("id", 0)
  10578. order, _ := service.GetHisOrderByID(order_id)
  10579. if order.ID == 0 {
  10580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10581. return
  10582. }
  10583. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10584. org_id := c.GetAdminUserInfo().CurrentOrgId
  10585. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10586. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10587. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10588. c.ServeSuccessJSON(map[string]interface{}{
  10589. "order": order,
  10590. "order_info": order_info,
  10591. "patient": patient,
  10592. "admin_info": adminInfo,
  10593. "hospital_record": record,
  10594. })
  10595. return
  10596. }
  10597. func (c *HisApiController) GetAllOrderDetailCollect() {
  10598. order_id, _ := c.GetInt64("id", 0)
  10599. order, _ := service.GetHisOrderByID(order_id)
  10600. if order.ID == 0 {
  10601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10602. return
  10603. }
  10604. org_id := c.GetAdminUserInfo().CurrentOrgId
  10605. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10606. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10607. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10608. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10609. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10610. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10611. var bedCostTotal float64 = 0 //床位总费
  10612. //var bedCostSelfTotal float64 = 0 //床位自费
  10613. var operationCostTotal float64 = 0 //手术费
  10614. //var operationCostSelfTotal float64 = 0 //手术费
  10615. var otherCostTotal float64 = 0 //其他费用
  10616. //var otherCostSelfTotal float64 = 0 //其他费用
  10617. var materialCostTotal float64 = 0 //材料费
  10618. //var materialCostSelfTotal float64 = 0 //材料费
  10619. var westernMedicineCostTotal float64 = 0 //西药费
  10620. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10621. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10622. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10623. var checkCostTotal float64 = 0 //检查费
  10624. //var checkCostSelfTotal float64 = 0 //检查费
  10625. var laboratoryCostTotal float64 = 0 //化验费
  10626. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10627. var treatCostTotal float64 = 0 //治疗费用
  10628. //var treatCostSelfTotal float64 = 0 //治疗费用
  10629. var zhenChaCostTotal float64 = 0 //其他费用
  10630. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10631. decimal.DivisionPrecision = 2
  10632. var BalanceAccountsType int64
  10633. if his.ID > 0 {
  10634. BalanceAccountsType = his.BalanceAccountsType
  10635. } else {
  10636. BalanceAccountsType = record.BalanceAccountsType
  10637. }
  10638. if BalanceAccountsType != 2 {
  10639. for _, item := range order_info {
  10640. if org_id == 10215 {
  10641. if item.MedChrgitmType == "01" { //床位费
  10642. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10643. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10644. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10645. }
  10646. if item.MedChrgitmType == "02" { //诊察费
  10647. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10648. //zhenChaCostSelfTotal = zhenChaCostTotal
  10649. }
  10650. if item.MedChrgitmType == "03" { //检查费
  10651. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10652. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10653. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10654. }
  10655. //if item.MedChrgitmType == "02" { //检查费
  10656. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10657. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10658. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10659. //}
  10660. if item.MedChrgitmType == "04" { //化验费
  10661. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10662. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10663. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10664. }
  10665. if item.MedChrgitmType == "05" { //治疗费
  10666. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10667. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10668. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10669. }
  10670. if item.MedChrgitmType == "06" { //手术费
  10671. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10672. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10673. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10674. }
  10675. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10676. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10677. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10678. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10679. }
  10680. if item.MedChrgitmType == "09" { //西药费
  10681. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10682. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10683. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10684. }
  10685. if item.MedChrgitmType == "11" { //中成费
  10686. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10687. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10688. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10689. }
  10690. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10691. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10692. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10693. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10694. }
  10695. } else if org_id == 10188 || org_id == 10217 {
  10696. if item.MedChrgitmType == "01" { //床位费
  10697. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10698. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10699. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10700. }
  10701. if item.MedChrgitmType == "02" { //诊察费
  10702. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10703. //zhenChaCostSelfTotal = zhenChaCostTotal
  10704. }
  10705. if item.MedChrgitmType == "03" { //检查费
  10706. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10707. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10708. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10709. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10710. }
  10711. //if item.MedChrgitmType == "02" { //检查费
  10712. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10713. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10714. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10715. //}
  10716. if item.MedChrgitmType == "04" { //化验费
  10717. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10718. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10719. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10720. }
  10721. if item.MedChrgitmType == "05" { //治疗费
  10722. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10723. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10724. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10725. }
  10726. if item.MedChrgitmType == "06" { //手术费
  10727. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10728. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10729. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10730. }
  10731. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10732. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10733. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10734. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10735. }
  10736. if item.MedChrgitmType == "09" { //西药费
  10737. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10738. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10739. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10740. }
  10741. if item.MedChrgitmType == "11" { //中成费
  10742. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10743. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10744. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10745. }
  10746. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10747. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10748. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10749. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10750. }
  10751. } else {
  10752. if item.MedChrgitmType == "01" { //床位费
  10753. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10754. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10755. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10756. }
  10757. //if item.MedChrgitmType == "02" { //诊察费
  10758. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10759. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10760. //}
  10761. if item.MedChrgitmType == "03" { //检查费
  10762. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10763. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10764. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10765. }
  10766. //if item.MedChrgitmType == "02" { //检查费
  10767. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10768. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10769. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10770. //}
  10771. if item.MedChrgitmType == "04" { //化验费
  10772. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10773. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10774. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10775. }
  10776. if item.MedChrgitmType == "05" { //治疗费
  10777. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10778. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10779. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10780. }
  10781. if item.MedChrgitmType == "06" { //手术费
  10782. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10783. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10784. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10785. }
  10786. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10787. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10788. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10789. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10790. }
  10791. if item.MedChrgitmType == "09" { //西药费
  10792. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10793. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10794. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10795. }
  10796. if item.MedChrgitmType == "11" { //中成费
  10797. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10798. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10799. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10800. }
  10801. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10802. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10803. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10804. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10805. }
  10806. }
  10807. }
  10808. c.ServeSuccessJSON(map[string]interface{}{
  10809. "order": order,
  10810. "order_info": order_info,
  10811. "patient": patient,
  10812. "admin_info": adminInfo,
  10813. "his_hospital": record,
  10814. "bedCostTotal": bedCostTotal,
  10815. "operationCostTotal": operationCostTotal,
  10816. "otherCostTotal": otherCostTotal,
  10817. "materialCostTotal": materialCostTotal,
  10818. "westernMedicineCostTotal": westernMedicineCostTotal,
  10819. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10820. "checkCostTotal": checkCostTotal,
  10821. "zhenChaCostTotal": zhenChaCostTotal,
  10822. "laboratoryCostTotal": laboratoryCostTotal,
  10823. "treatCostTotal": treatCostTotal,
  10824. })
  10825. } else {
  10826. for _, item := range order_info {
  10827. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10828. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10829. item.MedChrgitmType = "09"
  10830. }
  10831. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10832. if item.HisPrescriptionProject.Type == 2 {
  10833. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10834. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10835. case 0:
  10836. item.MedChrgitmType = "0"
  10837. break
  10838. case 1:
  10839. item.MedChrgitmType = "14"
  10840. break
  10841. case 2:
  10842. item.MedChrgitmType = "05"
  10843. break
  10844. case 3:
  10845. item.MedChrgitmType = "03"
  10846. break
  10847. case 4:
  10848. item.MedChrgitmType = "03"
  10849. break
  10850. case 5:
  10851. item.MedChrgitmType = "08"
  10852. break
  10853. case 6:
  10854. item.MedChrgitmType = "14"
  10855. break
  10856. case 7:
  10857. item.MedChrgitmType = "14"
  10858. break
  10859. case 8:
  10860. item.MedChrgitmType = "03"
  10861. break
  10862. case 9:
  10863. item.MedChrgitmType = "14"
  10864. break
  10865. case 10:
  10866. item.MedChrgitmType = "14"
  10867. break
  10868. case 11:
  10869. item.MedChrgitmType = "06"
  10870. break
  10871. case 12:
  10872. item.MedChrgitmType = "12"
  10873. break
  10874. case 13:
  10875. item.MedChrgitmType = "01"
  10876. break
  10877. case 14:
  10878. item.MedChrgitmType = "04"
  10879. break
  10880. case 15:
  10881. item.MedChrgitmType = "14"
  10882. break
  10883. }
  10884. } else {
  10885. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10886. case 1:
  10887. item.MedChrgitmType = "14"
  10888. break
  10889. case 2:
  10890. item.MedChrgitmType = "05"
  10891. break
  10892. case 3:
  10893. item.MedChrgitmType = "04"
  10894. break
  10895. case 4:
  10896. item.MedChrgitmType = "14"
  10897. break
  10898. case 5:
  10899. item.MedChrgitmType = "08"
  10900. break
  10901. case 6:
  10902. item.MedChrgitmType = "14"
  10903. break
  10904. case 7:
  10905. item.MedChrgitmType = "14"
  10906. break
  10907. case 8:
  10908. item.MedChrgitmType = "03"
  10909. break
  10910. case 9:
  10911. item.MedChrgitmType = "14"
  10912. break
  10913. }
  10914. }
  10915. } else if item.HisPrescriptionProject.Type == 3 {
  10916. item.MedChrgitmType = "08"
  10917. }
  10918. }
  10919. }
  10920. for _, item := range order_info {
  10921. if org_id == 10215 {
  10922. if item.MedChrgitmType == "01" { //床位费
  10923. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10924. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10925. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10926. }
  10927. if item.MedChrgitmType == "02" { //诊察费
  10928. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10929. //zhenChaCostSelfTotal = zhenChaCostTotal
  10930. }
  10931. if item.MedChrgitmType == "03" { //检查费
  10932. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10933. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10934. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10935. }
  10936. //if item.MedChrgitmType == "02" { //检查费
  10937. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10938. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10939. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10940. //}
  10941. if item.MedChrgitmType == "04" { //化验费
  10942. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10943. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10944. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10945. }
  10946. if item.MedChrgitmType == "05" { //治疗费
  10947. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10948. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10949. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10950. }
  10951. if item.MedChrgitmType == "06" { //手术费
  10952. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10953. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10954. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10955. }
  10956. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10957. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10958. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10959. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10960. }
  10961. if item.MedChrgitmType == "09" { //西药费
  10962. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10963. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10964. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10965. }
  10966. if item.MedChrgitmType == "11" { //中成费
  10967. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10968. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10969. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10970. }
  10971. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10972. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10973. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10974. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10975. }
  10976. } else {
  10977. if item.MedChrgitmType == "01" { //床位费
  10978. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10979. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10980. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10981. }
  10982. //if item.MedChrgitmType == "02" { //诊察费
  10983. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10984. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10985. //}
  10986. if item.MedChrgitmType == "03" { //检查费
  10987. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10988. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10989. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10990. }
  10991. //if item.MedChrgitmType == "02" { //检查费
  10992. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10993. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10994. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10995. //}
  10996. if item.MedChrgitmType == "04" { //化验费
  10997. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10998. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10999. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11000. }
  11001. if item.MedChrgitmType == "05" { //治疗费
  11002. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11003. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11004. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11005. }
  11006. if item.MedChrgitmType == "06" { //手术费
  11007. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11008. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11009. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11010. }
  11011. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11012. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11013. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11014. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11015. }
  11016. if item.MedChrgitmType == "09" { //西药费
  11017. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11018. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11019. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11020. }
  11021. if item.MedChrgitmType == "11" { //中成费
  11022. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11023. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11024. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11025. }
  11026. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11027. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11028. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11029. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11030. }
  11031. }
  11032. }
  11033. c.ServeSuccessJSON(map[string]interface{}{
  11034. "order": order,
  11035. "order_info": order_info,
  11036. "patient": patient,
  11037. "admin_info": adminInfo,
  11038. "his_hospital": record,
  11039. "bedCostTotal": bedCostTotal,
  11040. "operationCostTotal": operationCostTotal,
  11041. "otherCostTotal": otherCostTotal,
  11042. "materialCostTotal": materialCostTotal,
  11043. "westernMedicineCostTotal": westernMedicineCostTotal,
  11044. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11045. "checkCostTotal": checkCostTotal,
  11046. "zhenChaCostTotal": zhenChaCostTotal,
  11047. "laboratoryCostTotal": laboratoryCostTotal,
  11048. "treatCostTotal": treatCostTotal,
  11049. })
  11050. }
  11051. }
  11052. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  11053. page, _ := c.GetInt64("page")
  11054. limit, _ := c.GetInt64("limit")
  11055. keywords := c.GetString("keywords")
  11056. start_time := c.GetString("start_time")
  11057. end_time := c.GetString("end_time")
  11058. //clr_type := c.GetString("clr_type")
  11059. insutype := c.GetString("insutype")
  11060. timeLayout := "2006-01-02"
  11061. loc, _ := time.LoadLocation("Local")
  11062. var theStartTIme int64
  11063. if len(start_time) > 0 {
  11064. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11065. theStartTIme = theTime.Unix()
  11066. }
  11067. var theEndtTIme int64
  11068. if len(end_time) > 0 {
  11069. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11070. theEndtTIme = theTime.Unix()
  11071. }
  11072. if page <= 0 {
  11073. page = 1
  11074. }
  11075. if limit <= 0 {
  11076. limit = 10
  11077. }
  11078. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  11079. c.ServeSuccessJSON(map[string]interface{}{
  11080. "total": total,
  11081. "list": list,
  11082. })
  11083. return
  11084. }
  11085. func (c *HisApiController) GetPutOnRecordList() {
  11086. page, _ := c.GetInt64("page")
  11087. limit, _ := c.GetInt64("limit")
  11088. keywords := c.GetString("keywords")
  11089. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  11090. if page <= 0 {
  11091. page = 1
  11092. }
  11093. if limit <= 0 {
  11094. limit = 10
  11095. }
  11096. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  11097. c.ServeSuccessJSON(map[string]interface{}{
  11098. "total": total,
  11099. "list": list,
  11100. })
  11101. return
  11102. }
  11103. func (c *HisApiController) GetCompareData() {
  11104. start_time := c.GetString("start_time")
  11105. end_time := c.GetString("end_time")
  11106. insutype := c.GetString("insutype")
  11107. clr_type := c.GetString("clr_type")
  11108. timeLayout := "2006-01-02"
  11109. loc, _ := time.LoadLocation("Local")
  11110. var theStartTIme int64
  11111. if len(start_time) > 0 {
  11112. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11113. if err != nil {
  11114. theStartTIme = 0
  11115. }
  11116. theStartTIme = theTime.Unix()
  11117. }
  11118. var theEndtTIme int64
  11119. if len(end_time) > 0 {
  11120. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11121. if err != nil {
  11122. theEndtTIme = 0
  11123. }
  11124. theEndtTIme = theTime.Unix()
  11125. }
  11126. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11127. fmt.Println(err)
  11128. if err == nil {
  11129. c.ServeSuccessJSON(map[string]interface{}{
  11130. "list": formData,
  11131. })
  11132. } else {
  11133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11134. return
  11135. }
  11136. }
  11137. func (c *HisApiController) GetFaPiaoData() {
  11138. order_id, _ := c.GetInt64("order_id")
  11139. patient_id, _ := c.GetInt64("patient_id")
  11140. //number := c.GetString("number")
  11141. adminUser := c.GetAdminUserInfo()
  11142. order, _ := service.GetHisOrderByID(order_id)
  11143. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11144. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11145. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11146. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11147. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11148. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11149. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11150. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11151. var bedCostTotal float64 = 0 //床位总费
  11152. var bedCostSelfTotal float64 = 0 //床位自费
  11153. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11154. var operationCostTotal float64 = 0 //手术费
  11155. var operationCostSelfTotal float64 = 0 //手术费
  11156. var operationCostPartSelfTotal float64 = 0 //手术费
  11157. var otherCostTotal float64 = 0 //其他费用
  11158. var otherCostSelfTotal float64 = 0 //其他费用
  11159. var otherCostPartSelfTotal float64 = 0 //其他费用
  11160. var materialCostTotal float64 = 0 //材料费
  11161. var materialCostSelfTotal float64 = 0 //材料费
  11162. var materialCostPartSelfTotal float64 = 0 //材料费
  11163. var westernMedicineCostTotal float64 = 0 //西药费
  11164. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11165. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11166. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11167. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11168. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11169. var checkCostTotal float64 = 0 //检查费
  11170. var checkCostSelfTotal float64 = 0 //检查费
  11171. var checkCostPartSelfTotal float64 = 0 //检查费
  11172. var hiliCostTotal float64 = 0 //护理费
  11173. var hiliCostSelfTotal float64 = 0 //护理费
  11174. var hiliCostPartSelfTotal float64 = 0 //护理费
  11175. var laboratoryCostTotal float64 = 0 //化验费
  11176. var laboratoryCostSelfTotal float64 = 0 //化验费
  11177. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11178. var treatCostTotal float64 = 0 //治疗费用
  11179. var treatCostSelfTotal float64 = 0 //治疗费用
  11180. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11181. var zhenChaCostTotal float64 = 0 //其他费用
  11182. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11183. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11184. decimal.DivisionPrecision = 2
  11185. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11186. var balanceAccountsType int64
  11187. if his.ID > 0 {
  11188. balanceAccountsType = his.BalanceAccountsType
  11189. } else {
  11190. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11191. }
  11192. if balanceAccountsType == 2 {
  11193. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11194. for _, item := range orderInfos_two {
  11195. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11196. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11197. item.MedChrgitmType = "09"
  11198. }
  11199. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11200. if item.HisPrescriptionProject.Type == 2 {
  11201. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11202. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11203. case 0:
  11204. item.MedChrgitmType = "0"
  11205. break
  11206. case 1:
  11207. item.MedChrgitmType = "14"
  11208. break
  11209. case 2:
  11210. item.MedChrgitmType = "05"
  11211. break
  11212. case 3:
  11213. item.MedChrgitmType = "03"
  11214. break
  11215. case 4:
  11216. item.MedChrgitmType = "03"
  11217. break
  11218. case 5:
  11219. item.MedChrgitmType = "08"
  11220. break
  11221. case 6:
  11222. item.MedChrgitmType = "14"
  11223. break
  11224. case 7:
  11225. item.MedChrgitmType = "14"
  11226. break
  11227. case 8:
  11228. item.MedChrgitmType = "03"
  11229. break
  11230. case 9:
  11231. item.MedChrgitmType = "14"
  11232. break
  11233. case 10:
  11234. item.MedChrgitmType = "14"
  11235. break
  11236. case 11:
  11237. item.MedChrgitmType = "06"
  11238. break
  11239. case 12:
  11240. item.MedChrgitmType = "12"
  11241. break
  11242. case 13:
  11243. item.MedChrgitmType = "01"
  11244. break
  11245. case 14:
  11246. item.MedChrgitmType = "04"
  11247. break
  11248. case 15:
  11249. item.MedChrgitmType = "02"
  11250. break
  11251. }
  11252. } else {
  11253. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11254. case 1:
  11255. item.MedChrgitmType = "14"
  11256. break
  11257. case 2:
  11258. item.MedChrgitmType = "05"
  11259. break
  11260. case 3:
  11261. item.MedChrgitmType = "04"
  11262. break
  11263. case 4:
  11264. item.MedChrgitmType = "03"
  11265. break
  11266. case 5:
  11267. item.MedChrgitmType = "08"
  11268. break
  11269. case 6:
  11270. item.MedChrgitmType = "14"
  11271. break
  11272. case 7:
  11273. item.MedChrgitmType = "14"
  11274. break
  11275. case 8:
  11276. item.MedChrgitmType = "03"
  11277. break
  11278. case 9:
  11279. item.MedChrgitmType = "14"
  11280. break
  11281. }
  11282. }
  11283. } else if item.HisPrescriptionProject.Type == 3 {
  11284. item.MedChrgitmType = "08"
  11285. }
  11286. }
  11287. }
  11288. for _, item := range orderInfos_two {
  11289. fmt.Println(item.MedChrgitmType)
  11290. if item.MedChrgitmType == "07" { //床位费
  11291. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11292. hiliCostSelfTotal = hiliCostTotal
  11293. }
  11294. if item.MedChrgitmType == "01" { //床位费
  11295. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11296. bedCostSelfTotal = bedCostTotal
  11297. }
  11298. if item.MedChrgitmType == "02" { //诊察费
  11299. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11300. zhenChaCostSelfTotal = zhenChaCostTotal
  11301. }
  11302. if item.MedChrgitmType == "03" { //检查费
  11303. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11304. checkCostSelfTotal = checkCostTotal
  11305. }
  11306. if item.MedChrgitmType == "04" { //化验费
  11307. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11308. laboratoryCostSelfTotal = laboratoryCostTotal
  11309. }
  11310. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11311. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11312. treatCostSelfTotal = treatCostTotal
  11313. }
  11314. if item.MedChrgitmType == "06" { //手术费
  11315. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11316. operationCostSelfTotal = treatCostTotal
  11317. }
  11318. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11319. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11320. materialCostSelfTotal = materialCostTotal
  11321. }
  11322. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11323. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11324. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11325. }
  11326. if item.MedChrgitmType == "11" { //中成费
  11327. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11328. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11329. }
  11330. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11331. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11332. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11333. otherCostSelfTotal = otherCostTotal
  11334. }
  11335. } else {
  11336. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11337. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11338. otherCostSelfTotal = otherCostTotal
  11339. }
  11340. }
  11341. }
  11342. } else {
  11343. for _, item := range orderInfos {
  11344. if item.MedChrgitmType == "01" { //床位费
  11345. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11346. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11347. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11348. }
  11349. if item.MedChrgitmType == "02" { //诊察费
  11350. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11351. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11352. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11353. }
  11354. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11355. if item.MedChrgitmType == "03" { //检查费
  11356. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11357. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11358. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11359. }
  11360. } else {
  11361. if item.MedChrgitmType == "03" { //检查费
  11362. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11363. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11364. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11365. }
  11366. }
  11367. if item.MedChrgitmType == "04" { //化验费
  11368. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11369. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11370. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11371. }
  11372. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11373. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11374. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11375. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11376. }
  11377. if item.MedChrgitmType == "06" { //手术费
  11378. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11379. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11380. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11381. }
  11382. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11383. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11384. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11385. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11386. }
  11387. if item.MedChrgitmType == "07" { //护理
  11388. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11389. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11390. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11391. }
  11392. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11393. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11394. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11395. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11396. }
  11397. if item.MedChrgitmType == "11" { //中成费
  11398. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11399. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11400. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11401. }
  11402. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11403. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11404. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11405. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11406. }
  11407. }
  11408. }
  11409. timeLayout := "2006-01-02"
  11410. loc, _ := time.LoadLocation("Local")
  11411. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11412. if err != nil {
  11413. }
  11414. startRecordDateTime := startTime.Unix()
  11415. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11416. if err != nil {
  11417. }
  11418. endRecordDateTime := endTime.Unix()
  11419. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11420. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11421. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11422. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11423. c.ServeSuccessJSON(map[string]interface{}{
  11424. "charge_admin_name": charge_admin.UserName,
  11425. "order_number": order.Number, //业务流水号
  11426. "id_card_no": his.IdCardNo, //社会保障号
  11427. "patient": patient,
  11428. "department_name": department.Name, //科室
  11429. "number": his.Number, //门诊号
  11430. "date": order.SettleAccountsDate, //结算日期
  11431. "name": order.PsnName, //姓名
  11432. "gender": patient.Gender, //性别
  11433. "psn_cash_money": order.PsnCashPay, //个人支付
  11434. "pay_way": "门诊", //结算方式
  11435. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11436. "admin_user_name": admin.UserName, //收款员
  11437. "order": order,
  11438. "order_info": orderInfos_two,
  11439. "his": his,
  11440. "bedCostTotal": bedCostTotal,
  11441. "bedCostSelfTotal": bedCostSelfTotal,
  11442. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11443. "operationCostTotal": operationCostTotal,
  11444. "operationCostSelfTotal": operationCostSelfTotal,
  11445. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11446. "otherCostTotal": otherCostTotal,
  11447. "otherCostSelfTotal": otherCostSelfTotal,
  11448. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11449. "materialCostTotal": materialCostTotal,
  11450. "materialCostSelfTotal": materialCostSelfTotal,
  11451. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11452. "westernMedicineCostTotal": westernMedicineCostTotal,
  11453. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11454. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11455. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11456. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11457. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11458. "checkCostTotal": checkCostTotal,
  11459. "checkCostSelfTotal": checkCostSelfTotal,
  11460. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11461. "laboratoryCostTotal": laboratoryCostTotal,
  11462. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11463. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11464. "treatCostTotal": treatCostTotal,
  11465. "treatCostSelfTotal": treatCostSelfTotal,
  11466. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11467. "zhenChaCostTotal": zhenChaCostTotal,
  11468. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11469. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11470. "his_hospital_record": his_hospital_record,
  11471. "pre_pay_money": pre_pay_money,
  11472. "refund_sum": sum,
  11473. "doctor_info": doctor_info,
  11474. "hiliCostTotal": hiliCostTotal,
  11475. "hiliCostSelfTotal": hiliCostSelfTotal,
  11476. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11477. })
  11478. }
  11479. //func (c *HisApiController) GetFaPiaoDatas() {
  11480. // order_ids := c.GetString("order_ids")
  11481. // patient_id, _ := c.GetInt64("patient_id")
  11482. // adminUser := c.GetAdminUserInfo()
  11483. //
  11484. // orders := strings.Split(order_ids, ",")
  11485. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11486. //
  11487. // for _, item := range orders {
  11488. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11489. // order, _ := service.GetHisOrderByID(order_id)
  11490. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11491. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11492. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11493. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11494. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11495. //
  11496. // }
  11497. //
  11498. // var bedCostTotal float64 = 0 //床位总费
  11499. // var bedCostSelfTotal float64 = 0 //床位自费
  11500. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11501. //
  11502. // var operationCostTotal float64 = 0 //手术费
  11503. // var operationCostSelfTotal float64 = 0 //手术费
  11504. // var operationCostPartSelfTotal float64 = 0 //手术费
  11505. //
  11506. // var otherCostTotal float64 = 0 //其他费用
  11507. // var otherCostSelfTotal float64 = 0 //其他费用
  11508. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11509. //
  11510. // var materialCostTotal float64 = 0 //材料费
  11511. // var materialCostSelfTotal float64 = 0 //材料费
  11512. // var materialCostPartSelfTotal float64 = 0 //材料费
  11513. //
  11514. // var westernMedicineCostTotal float64 = 0 //西药费
  11515. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11516. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11517. //
  11518. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11519. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11520. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11521. //
  11522. // var checkCostTotal float64 = 0 //检查费
  11523. // var checkCostSelfTotal float64 = 0 //检查费
  11524. // var checkCostPartSelfTotal float64 = 0 //检查费
  11525. //
  11526. // var laboratoryCostTotal float64 = 0 //化验费
  11527. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11528. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11529. //
  11530. // var treatCostTotal float64 = 0 //治疗费用
  11531. // var treatCostSelfTotal float64 = 0 //治疗费用
  11532. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11533. //
  11534. // var zhenChaCostTotal float64 = 0 //其他费用
  11535. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11536. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11537. //
  11538. // decimal.DivisionPrecision = 2
  11539. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11540. //
  11541. // var balanceAccountsType int64
  11542. // if his.ID > 0 {
  11543. // balanceAccountsType = his.BalanceAccountsType
  11544. // } else {
  11545. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11546. // }
  11547. // if balanceAccountsType == 2 {
  11548. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11549. // for _, item := range orderInfos_two {
  11550. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11551. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11552. // item.MedChrgitmType = "09"
  11553. // }
  11554. //
  11555. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11556. // if item.HisPrescriptionProject.Type == 2 {
  11557. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11558. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11559. // case 0:
  11560. // item.MedChrgitmType = "0"
  11561. // break
  11562. // case 1:
  11563. // item.MedChrgitmType = "14"
  11564. // break
  11565. // case 2:
  11566. // item.MedChrgitmType = "05"
  11567. //
  11568. // break
  11569. // case 3:
  11570. // item.MedChrgitmType = "03"
  11571. //
  11572. // break
  11573. // case 4:
  11574. // item.MedChrgitmType = "03"
  11575. //
  11576. // break
  11577. // case 5:
  11578. // item.MedChrgitmType = "08"
  11579. //
  11580. // break
  11581. // case 6:
  11582. // item.MedChrgitmType = "14"
  11583. //
  11584. // break
  11585. // case 7:
  11586. // item.MedChrgitmType = "14"
  11587. //
  11588. // break
  11589. // case 8:
  11590. // item.MedChrgitmType = "03"
  11591. // break
  11592. // case 9:
  11593. // item.MedChrgitmType = "14"
  11594. // break
  11595. // case 10:
  11596. // item.MedChrgitmType = "14"
  11597. // break
  11598. // case 11:
  11599. // item.MedChrgitmType = "06"
  11600. // break
  11601. // case 12:
  11602. // item.MedChrgitmType = "12"
  11603. // break
  11604. // case 13:
  11605. // item.MedChrgitmType = "01"
  11606. // break
  11607. // case 14:
  11608. // item.MedChrgitmType = "04"
  11609. // break
  11610. // case 15:
  11611. // item.MedChrgitmType = "02"
  11612. // break
  11613. //
  11614. // }
  11615. //
  11616. // } else {
  11617. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11618. //
  11619. // case 1:
  11620. // item.MedChrgitmType = "14"
  11621. // break
  11622. // case 2:
  11623. // item.MedChrgitmType = "05"
  11624. //
  11625. // break
  11626. // case 3:
  11627. // item.MedChrgitmType = "03"
  11628. //
  11629. // break
  11630. // case 4:
  11631. // item.MedChrgitmType = "03"
  11632. //
  11633. // break
  11634. // case 5:
  11635. // item.MedChrgitmType = "08"
  11636. //
  11637. // break
  11638. // case 6:
  11639. // item.MedChrgitmType = "14"
  11640. //
  11641. // break
  11642. // case 7:
  11643. // item.MedChrgitmType = "14"
  11644. //
  11645. // break
  11646. // case 8:
  11647. // item.MedChrgitmType = "03"
  11648. // break
  11649. // case 9:
  11650. // item.MedChrgitmType = "14"
  11651. // break
  11652. //
  11653. // }
  11654. //
  11655. // }
  11656. //
  11657. // } else if item.HisPrescriptionProject.Type == 3 {
  11658. // item.MedChrgitmType = "08"
  11659. // }
  11660. // }
  11661. // }
  11662. //
  11663. // for _, item := range orderInfos_two {
  11664. // fmt.Println(item.MedChrgitmType)
  11665. // if item.MedChrgitmType == "01" { //床位费
  11666. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11667. // bedCostSelfTotal = bedCostTotal
  11668. // }
  11669. //
  11670. // if item.MedChrgitmType == "02" { //诊察费
  11671. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11672. // zhenChaCostSelfTotal = zhenChaCostTotal
  11673. // }
  11674. //
  11675. // if item.MedChrgitmType == "03" { //检查费
  11676. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11677. // checkCostSelfTotal = checkCostTotal
  11678. // }
  11679. //
  11680. // if item.MedChrgitmType == "04" { //化验费
  11681. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11682. // laboratoryCostSelfTotal = laboratoryCostTotal
  11683. // }
  11684. //
  11685. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11686. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11687. // treatCostSelfTotal = treatCostTotal
  11688. // }
  11689. //
  11690. // if item.MedChrgitmType == "06" { //手术费
  11691. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11692. // operationCostSelfTotal = treatCostTotal
  11693. // }
  11694. //
  11695. // if item.MedChrgitmType == "08" { //材料费
  11696. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11697. // materialCostSelfTotal = materialCostTotal
  11698. // }
  11699. //
  11700. // if item.MedChrgitmType == "09" { //西药费
  11701. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11702. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11703. // }
  11704. //
  11705. // if item.MedChrgitmType == "11" { //中成费
  11706. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11707. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11708. // }
  11709. //
  11710. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11711. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11712. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11713. // otherCostSelfTotal = otherCostTotal
  11714. // }
  11715. // } else {
  11716. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11717. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11718. // otherCostSelfTotal = otherCostTotal
  11719. // }
  11720. //
  11721. // }
  11722. //
  11723. // }
  11724. //
  11725. // } else {
  11726. // for _, item := range orderInfos {
  11727. // if item.MedChrgitmType == "01" { //床位费
  11728. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11729. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11730. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11731. // }
  11732. //
  11733. // if item.MedChrgitmType == "02" { //诊察费
  11734. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11735. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11736. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11737. // }
  11738. //
  11739. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11740. // if item.MedChrgitmType == "03" { //检查费
  11741. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11742. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11743. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11744. //
  11745. // }
  11746. // } else {
  11747. // if item.MedChrgitmType == "03" { //检查费
  11748. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11749. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11750. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11751. // }
  11752. //
  11753. // }
  11754. //
  11755. // if item.MedChrgitmType == "04" { //化验费
  11756. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11757. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11758. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11759. //
  11760. // }
  11761. //
  11762. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11763. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11764. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11765. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11766. //
  11767. // }
  11768. //
  11769. // if item.MedChrgitmType == "06" { //手术费
  11770. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11771. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11772. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11773. // }
  11774. //
  11775. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11776. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11777. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11778. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11779. // }
  11780. //
  11781. // if item.MedChrgitmType == "09" { //西药费
  11782. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11783. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11784. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11785. // }
  11786. //
  11787. // if item.MedChrgitmType == "11" { //中成费
  11788. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11789. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11790. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11791. // }
  11792. //
  11793. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11794. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11795. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11796. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11797. // }
  11798. //
  11799. // }
  11800. // }
  11801. // timeLayout := "2006-01-02"
  11802. // loc, _ := time.LoadLocation("Local")
  11803. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11804. // if err != nil {
  11805. // }
  11806. // startRecordDateTime := startTime.Unix()
  11807. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11808. // if err != nil {
  11809. // }
  11810. // endRecordDateTime := endTime.Unix()
  11811. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11812. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11813. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11814. //
  11815. // c.ServeSuccessJSON(map[string]interface{}{
  11816. // "order_number": order.Number, //业务流水号
  11817. // "id_card_no": his.IdCardNo, //社会保障号
  11818. // "department_name": department.Name, //科室
  11819. // "number": his.Number, //门诊号
  11820. // "date": order.SettleAccountsDate, //结算日期
  11821. // "name": order.PsnName, //姓名
  11822. // "gender": patient.Gender, //性别
  11823. // "psn_cash_money": order.PsnCashPay, //个人支付
  11824. // "pay_way": "门诊", //结算方式
  11825. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11826. // "admin_user_name": admin.UserName, //收款员
  11827. // "order": order,
  11828. // "order_info": orderInfos_two,
  11829. // "his": his,
  11830. // "bedCostTotal": bedCostTotal,
  11831. // "bedCostSelfTotal": bedCostSelfTotal,
  11832. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11833. // "operationCostTotal": operationCostTotal,
  11834. // "operationCostSelfTotal": operationCostSelfTotal,
  11835. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11836. // "otherCostTotal": otherCostTotal,
  11837. // "otherCostSelfTotal": otherCostSelfTotal,
  11838. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11839. // "materialCostTotal": materialCostTotal,
  11840. // "materialCostSelfTotal": materialCostSelfTotal,
  11841. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11842. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11843. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11844. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11845. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11846. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11847. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11848. // "checkCostTotal": checkCostTotal,
  11849. // "checkCostSelfTotal": checkCostSelfTotal,
  11850. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11851. // "laboratoryCostTotal": laboratoryCostTotal,
  11852. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11853. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11854. // "treatCostTotal": treatCostTotal,
  11855. // "treatCostSelfTotal": treatCostSelfTotal,
  11856. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11857. // "zhenChaCostTotal": zhenChaCostTotal,
  11858. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11859. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11860. // "his_hospital_record": his_hospital_record,
  11861. // "pre_pay_money": pre_pay_money,
  11862. // "refund_sum": sum,
  11863. // })
  11864. //
  11865. //}
  11866. func (this *HisApiController) GetIncomeStatisticsData() {
  11867. start_time := this.GetString("start_time")
  11868. end_time := this.GetString("end_time")
  11869. key_words := this.GetString("key_words")
  11870. limit, _ := this.GetInt64("limit")
  11871. page, _ := this.GetInt64("page")
  11872. if page <= 0 {
  11873. page = 1
  11874. }
  11875. if limit <= 0 {
  11876. limit = 10
  11877. }
  11878. statistics_type, _ := this.GetInt64("statistics_type")
  11879. admin := this.GetAdminUserInfo()
  11880. timeLayout := "2006-01-02"
  11881. loc, _ := time.LoadLocation("Local")
  11882. var theStartTIme int64
  11883. if len(start_time) > 0 {
  11884. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11885. if err != nil {
  11886. theStartTIme = 0
  11887. }
  11888. theStartTIme = theTime.Unix()
  11889. }
  11890. var theEndtTIme int64
  11891. if len(end_time) > 0 {
  11892. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11893. if err != nil {
  11894. theEndtTIme = 0
  11895. }
  11896. theEndtTIme = theTime.Unix()
  11897. }
  11898. if statistics_type == 1 {
  11899. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11900. this.ServeSuccessJSON(map[string]interface{}{
  11901. "list": list,
  11902. "total": total,
  11903. })
  11904. } else {
  11905. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11906. this.ServeSuccessJSON(map[string]interface{}{
  11907. "list": list,
  11908. "total": total,
  11909. })
  11910. }
  11911. }
  11912. func (c *HisApiController) PostProjectInformation() {
  11913. adminUser := c.GetAdminUserInfo()
  11914. orgId := adminUser.CurrentOrgId
  11915. dataBody := make(map[string]interface{}, 0)
  11916. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11917. if err != nil {
  11918. utils.ErrorLog(err.Error())
  11919. return
  11920. }
  11921. utils.ErrorLog("%v", dataBody)
  11922. var projectList []*models.HisProject
  11923. var total_goods []interface{}
  11924. tempProjects := dataBody["projects"].([]interface{})
  11925. total_goods = tempProjects
  11926. for index, projectMap := range tempProjects {
  11927. projectM := projectMap.(map[string]interface{})
  11928. var project models.HisProject
  11929. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11930. utils.ErrorLog("project_name")
  11931. return
  11932. }
  11933. project_name, _ := projectM["project_name"].(string)
  11934. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11935. err_log := models.ExportErrLog{
  11936. LogType: 6,
  11937. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11938. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11939. Status: 1,
  11940. CreateTime: time.Now().Unix(),
  11941. UpdateTime: time.Now().Unix(),
  11942. ExportTime: time.Now().Unix(),
  11943. }
  11944. service.CreateExportErrLog(&err_log)
  11945. continue
  11946. }
  11947. project.ProjectName = project_name
  11948. prices := projectM["price"].(string)
  11949. price, _ := strconv.ParseFloat(prices, 64)
  11950. if price <= 0 { //名字为空则生成一条导入错误日志
  11951. err_log := models.ExportErrLog{
  11952. LogType: 6,
  11953. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11954. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11955. Status: 1,
  11956. CreateTime: time.Now().Unix(),
  11957. UpdateTime: time.Now().Unix(),
  11958. ExportTime: time.Now().Unix(),
  11959. }
  11960. service.CreateExportErrLog(&err_log)
  11961. continue
  11962. }
  11963. project.Price = price
  11964. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11965. utils.ErrorLog("unit_id")
  11966. return
  11967. }
  11968. unit := projectM["unit"].(string)
  11969. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11970. err_log := models.ExportErrLog{
  11971. LogType: 6,
  11972. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11973. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11974. Status: 1,
  11975. CreateTime: time.Now().Unix(),
  11976. UpdateTime: time.Now().Unix(),
  11977. ExportTime: time.Now().Unix(),
  11978. }
  11979. service.CreateExportErrLog(&err_log)
  11980. continue
  11981. }
  11982. project.Unit = unit
  11983. cost_classify := projectM["cost_classify"].(string)
  11984. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11985. err_log := models.ExportErrLog{
  11986. LogType: 6,
  11987. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11988. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11989. Status: 1,
  11990. CreateTime: time.Now().Unix(),
  11991. UpdateTime: time.Now().Unix(),
  11992. ExportTime: time.Now().Unix(),
  11993. }
  11994. service.CreateExportErrLog(&err_log)
  11995. continue
  11996. }
  11997. var costClassify = "费用类别"
  11998. var cost_classify_id int64
  11999. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  12000. if len(cost_classify) != 0 {
  12001. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  12002. if errcode == gorm.ErrRecordNotFound {
  12003. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  12004. dataconfig := models.DictDataconfig{
  12005. ParentId: costClassifyConfig.ID,
  12006. Module: "system",
  12007. OrgId: orgId,
  12008. Name: cost_classify,
  12009. FieldName: "",
  12010. Value: costConfig.Value + 1,
  12011. CreatedTime: "",
  12012. UpdatedTime: "",
  12013. CreateUserId: adminUser.AdminUser.Id,
  12014. Status: 1,
  12015. Remark: "",
  12016. DeleteIdSystem: 0,
  12017. Title: "",
  12018. Content: "",
  12019. Order: 0,
  12020. Code: "",
  12021. }
  12022. service.CreatedDicConfig(&dataconfig)
  12023. }
  12024. }
  12025. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  12026. for _, it := range costClassList {
  12027. if cost_classify == it.Name {
  12028. cost_classify_id = int64(it.Value)
  12029. }
  12030. }
  12031. project.CostClassify = cost_classify_id
  12032. executive_section := projectM["executive_section"].(string)
  12033. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  12034. err_log := models.ExportErrLog{
  12035. LogType: 6,
  12036. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12037. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  12038. Status: 1,
  12039. CreateTime: time.Now().Unix(),
  12040. UpdateTime: time.Now().Unix(),
  12041. ExportTime: time.Now().Unix(),
  12042. }
  12043. service.CreateExportErrLog(&err_log)
  12044. continue
  12045. }
  12046. if len(executive_section) != 0 {
  12047. //查找科室是否有内容
  12048. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  12049. if errcodedepart == gorm.ErrRecordNotFound {
  12050. department := models.XtHisDepartment{
  12051. Name: executive_section,
  12052. Status: 1,
  12053. UserOrgId: adminUser.CurrentOrgId,
  12054. CreatedTime: time.Now().Unix(),
  12055. }
  12056. service.CreateDePartment(&department)
  12057. }
  12058. }
  12059. var executive_section_id int64
  12060. departMentList, _ := service.GetAllDepartMent(orgId)
  12061. for _, it := range departMentList {
  12062. if executive_section == it.Name {
  12063. executive_section_id = it.ID
  12064. }
  12065. }
  12066. project.ExecutiveSection = executive_section_id
  12067. medical_coverage := projectM["medical_coverage"].(string)
  12068. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  12069. err_log := models.ExportErrLog{
  12070. LogType: 6,
  12071. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12072. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12073. Status: 1,
  12074. CreateTime: time.Now().Unix(),
  12075. UpdateTime: time.Now().Unix(),
  12076. ExportTime: time.Now().Unix(),
  12077. }
  12078. service.CreateExportErrLog(&err_log)
  12079. continue
  12080. }
  12081. var medicalCoverage = "医保等级"
  12082. var medical_coverage_id int64
  12083. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  12084. if len(medical_coverage) != 0 {
  12085. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  12086. if errormedicalcoverage == gorm.ErrRecordNotFound {
  12087. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  12088. dataconfig := models.DictDataconfig{
  12089. ParentId: medicalCoverageConfig.ID,
  12090. Module: "system",
  12091. OrgId: orgId,
  12092. Name: medical_coverage,
  12093. FieldName: "",
  12094. Value: medicalCoverageConfig.Value + 1,
  12095. CreatedTime: "",
  12096. UpdatedTime: "",
  12097. CreateUserId: adminUser.AdminUser.Id,
  12098. Status: 1,
  12099. Remark: "",
  12100. DeleteIdSystem: 0,
  12101. Title: "",
  12102. Content: "",
  12103. Order: 0,
  12104. Code: "",
  12105. }
  12106. service.CreatedDicConfig(&dataconfig)
  12107. }
  12108. }
  12109. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12110. for _, it := range medicalCoverageList {
  12111. if medical_coverage == it.Name {
  12112. medical_coverage_id = int64(it.Value)
  12113. }
  12114. }
  12115. project.MedicalCoverage = medical_coverage_id
  12116. pinyin := projectM["pinyin"].(string)
  12117. project.Pinyin = pinyin
  12118. wubi := projectM["wubi"].(string)
  12119. project.Wubi = wubi
  12120. statistical_classification := projectM["statistical_classification"].(string)
  12121. var statisticalClassification = "统计分类"
  12122. var statistical_classification_id int64
  12123. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12124. if len(statistical_classification) != 0 {
  12125. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12126. if classificationerrcodes == gorm.ErrRecordNotFound {
  12127. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12128. dataconfig := models.DictDataconfig{
  12129. ParentId: classiFication.ID,
  12130. Module: "system",
  12131. OrgId: orgId,
  12132. Name: statistical_classification,
  12133. FieldName: "",
  12134. Value: classiFicationConfig.Value + 1,
  12135. CreatedTime: "",
  12136. UpdatedTime: "",
  12137. CreateUserId: adminUser.AdminUser.Id,
  12138. Status: 1,
  12139. Remark: "",
  12140. DeleteIdSystem: 0,
  12141. Title: "",
  12142. Content: "",
  12143. Order: 0,
  12144. Code: "",
  12145. }
  12146. service.CreatedDicConfig(&dataconfig)
  12147. }
  12148. }
  12149. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12150. for _, it := range classiFicationList {
  12151. if statistical_classification == it.Name {
  12152. statistical_classification_id = int64(it.Value)
  12153. }
  12154. }
  12155. project.StatisticalClassification = statistical_classification_id
  12156. disease_directory := int64(projectM["disease_directory"].(float64))
  12157. project.DiseaseDirectory = disease_directory
  12158. is_record := int64(projectM["is_record"].(float64))
  12159. project.IsRecord = is_record
  12160. medical_code := projectM["medical_code"].(string)
  12161. project.MedicalCode = medical_code
  12162. tube_color := projectM["tube_color"].(string)
  12163. var tubeColor = "试管颜色"
  12164. var tube_color_id int64
  12165. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12166. if len(tube_color) != 0 {
  12167. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12168. if errcodetube == gorm.ErrRecordNotFound {
  12169. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12170. dataconfig := models.DictDataconfig{
  12171. ParentId: tubeColorConfig.ID,
  12172. Module: "system",
  12173. OrgId: orgId,
  12174. Name: tube_color,
  12175. FieldName: "",
  12176. Value: tubeConfig.Value + 1,
  12177. CreatedTime: "",
  12178. UpdatedTime: "",
  12179. CreateUserId: adminUser.AdminUser.Id,
  12180. Status: 1,
  12181. Remark: "",
  12182. DeleteIdSystem: 0,
  12183. Title: "",
  12184. Content: "",
  12185. Order: 0,
  12186. Code: "",
  12187. }
  12188. service.CreatedDicConfig(&dataconfig)
  12189. }
  12190. }
  12191. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12192. for _, it := range tubeColorList {
  12193. if tube_color == it.Name {
  12194. tube_color_id = int64(it.Value)
  12195. }
  12196. }
  12197. project.TubeColor = tube_color_id
  12198. single_dose := projectM["single_dose"].(string)
  12199. project.SingleDose = single_dose
  12200. execution_frequency := projectM["execution_frequency"].(string)
  12201. project.ExecutionFrequency = execution_frequency
  12202. delivery_way := projectM["delivery_way"].(string)
  12203. project.DeliveryWay = delivery_way
  12204. number_days := projectM["number_days"].(string)
  12205. project.NumberDays = number_days
  12206. total := projectM["total"].(string)
  12207. project.Total = total
  12208. medical_status := int64(projectM["medical_status"].(float64))
  12209. project.MedicalStatus = medical_status
  12210. category := int64(projectM["category"].(float64))
  12211. project.Category = category
  12212. specail_project := int64(projectM["specail_project"].(float64))
  12213. project.SpecailProject = specail_project
  12214. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12215. project.SocialSecurityDirectoryCode = social_security_directory_code
  12216. remark := projectM["remark"].(string)
  12217. project.Remark = remark
  12218. record_date := projectM["record_date"].(string)
  12219. timeLayout := "2006-01-02"
  12220. loc, _ := time.LoadLocation("Local")
  12221. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12222. project.RecordDate = theTime.Unix()
  12223. projectList = append(projectList, &project)
  12224. }
  12225. export_time := time.Now().Unix()
  12226. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12227. if len(projectList) > 0 {
  12228. for _, item := range projectList {
  12229. hans := item.ProjectName // 要转换的汉字字符串
  12230. // 创建一个拼音转换器
  12231. p := pinyin.NewArgs()
  12232. // 将汉字转为拼音
  12233. pinyinSlice := pinyin.Pinyin(hans, p)
  12234. // 输出拼音
  12235. fmt.Println("Pinyin:", pinyinSlice)
  12236. // 获取首字母
  12237. firstLetter := ""
  12238. for _, py := range pinyinSlice {
  12239. if len(py) > 0 {
  12240. firstLetter += string(py[0][0])
  12241. }
  12242. }
  12243. item.FirstLetter = firstLetter
  12244. project := models.HisProject{
  12245. ProjectName: item.ProjectName,
  12246. Price: item.Price,
  12247. Unit: item.Unit,
  12248. CostClassify: item.CostClassify,
  12249. ExecutiveSection: item.ExecutiveSection,
  12250. MedicalCoverage: item.MedicalCoverage,
  12251. UserOrgId: orgId,
  12252. Status: 1,
  12253. CreatedTime: time.Now().Unix(),
  12254. Pinyin: item.Pinyin,
  12255. Wubi: item.Wubi,
  12256. StatisticalClassification: item.StatisticalClassification,
  12257. DiseaseDirectory: item.DiseaseDirectory,
  12258. IsRecord: item.IsRecord,
  12259. MedicalCode: item.MedicalCode,
  12260. TubeColor: item.TubeColor,
  12261. SingleDose: item.SingleDose,
  12262. DeliveryWay: item.DeliveryWay,
  12263. NumberDays: item.NumberDays,
  12264. Total: item.Total,
  12265. Category: item.Category,
  12266. MedicalStatus: item.MedicalStatus,
  12267. SpecailProject: item.SpecailProject,
  12268. RecordDate: item.RecordDate,
  12269. Remark: item.Remark,
  12270. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12271. ExecutionFrequency: item.ExecutionFrequency,
  12272. FirstLetter: item.FirstLetter,
  12273. }
  12274. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12275. if errcodeproject == gorm.ErrRecordNotFound {
  12276. service.CreateProjectInfomation(&project)
  12277. } else if errcodeproject == nil {
  12278. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12279. }
  12280. log := models.ExportLog{
  12281. LogType: 6,
  12282. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12283. TotalNum: int64(len(total_goods)),
  12284. FailNum: int64(len(errLogs)),
  12285. SuccessNum: int64(len(projectList)),
  12286. CreateTime: time.Now().Unix(),
  12287. UpdateTime: time.Now().Unix(),
  12288. ExportTime: export_time,
  12289. Status: 1,
  12290. }
  12291. service.CreateExportLog(&log)
  12292. c.ServeSuccessJSON(map[string]interface{}{
  12293. "msg": "导入成功",
  12294. "total_num": len(total_goods),
  12295. "success_num": len(projectList),
  12296. "fail_num": int64(len(errLogs)),
  12297. })
  12298. }
  12299. } else {
  12300. log := models.ExportLog{
  12301. LogType: 6,
  12302. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12303. TotalNum: int64(len(total_goods)),
  12304. FailNum: int64(len(errLogs)),
  12305. SuccessNum: int64(len(projectList)),
  12306. CreateTime: time.Now().Unix(),
  12307. UpdateTime: time.Now().Unix(),
  12308. ExportTime: export_time,
  12309. Status: 1,
  12310. }
  12311. service.CreateExportLog(&log)
  12312. c.ServeSuccessJSON(map[string]interface{}{
  12313. "msg": "导入成功",
  12314. "total_num": len(total_goods),
  12315. "success_num": len(projectList),
  12316. "fail_num": int64(len(errLogs)),
  12317. })
  12318. }
  12319. }
  12320. //func (this *HisApiController) EditProjectInformation(){
  12321. //
  12322. // id, _ := this.GetInt64("id")
  12323. // project_team := this.GetString("project_team")
  12324. // price := this.GetString("price")
  12325. // price_float, _ := strconv.ParseFloat(price, 64)
  12326. // pinyin := this.GetString("pinyin")
  12327. // wubi := this.GetString("wubi")
  12328. // tube_color, _ := this.GetInt64("tube_color")
  12329. // team_type, _ := this.GetInt64("team_type")
  12330. // remark := this.GetString("remark")
  12331. // ids := this.GetString("ids")
  12332. // item_id := this.GetString("item_id")
  12333. // projectTeam := models.XtHisProjectTeam{
  12334. // ProjectTeam: project_team,
  12335. // Price: price_float,
  12336. // Pinyin: pinyin,
  12337. // Wubi: wubi,
  12338. // TubeColor: tube_color,
  12339. // TeamType: team_type,
  12340. // Remark: remark,
  12341. // ProjectId: ids,
  12342. // ItemId: item_id,
  12343. // }
  12344. //
  12345. //
  12346. // dataBody := make(map[string]interface{}, 0)
  12347. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12348. // if err != nil {
  12349. // utils.ErrorLog(err.Error())
  12350. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12351. // return
  12352. // }
  12353. //
  12354. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12355. //
  12356. //
  12357. // if err != nil {
  12358. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12359. // return
  12360. // }
  12361. //
  12362. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12363. // infos, _ := dataBody["info"].([]interface{})
  12364. // if len(infos) > 0 {
  12365. // var ids []string
  12366. //
  12367. // for _, item := range infos {
  12368. // items := item.(map[string]interface{})
  12369. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12370. // utils.ErrorLog("id")
  12371. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12372. // return
  12373. // }
  12374. // id := int64(items["id"].(float64))
  12375. //
  12376. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12377. // utils.ErrorLog("type")
  12378. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12379. // return
  12380. // }
  12381. // types := int64(items["type"].(float64))
  12382. //
  12383. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12384. // utils.ErrorLog("number")
  12385. // }
  12386. //
  12387. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12388. //
  12389. // projectList := models.XtHisProjectList{
  12390. // Number: number,
  12391. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12392. // ProjectId: id,
  12393. // Status: 1,
  12394. // CreatedTime: time.Now().Unix(),
  12395. // UpdatedTime: time.Now().Unix(),
  12396. // TeamId: projectTeam.ID,
  12397. // Type: types,
  12398. // }
  12399. // list := projectList
  12400. //
  12401. // service.CreateProjectList(&list)
  12402. //
  12403. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12404. //
  12405. // }
  12406. // ids_str := strings.Join(ids, ",")
  12407. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12408. // service.SaveProjectTeam(&projectTeam)
  12409. // this.ServeSuccessJSON(map[string]interface{}{
  12410. // "projectTeam": projectTeam,
  12411. // })
  12412. // }
  12413. // }
  12414. //}
  12415. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12416. name := c.GetString("name")
  12417. mode_id, _ := c.GetInt64("mode", 0)
  12418. types, _ := c.GetInt64("type", 0)
  12419. patient_id, _ := c.GetInt64("patient_id", 0)
  12420. types = 1
  12421. adminInfo := c.GetAdminUserInfo()
  12422. template := &models.HisPrescriptionTemplate{
  12423. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12424. PatientId: patient_id,
  12425. Type: types,
  12426. Status: 1,
  12427. Ctime: time.Now().Unix(),
  12428. Mtime: time.Now().Unix(),
  12429. Name: name,
  12430. Mode: mode_id,
  12431. }
  12432. dataBody := make(map[string]interface{}, 0)
  12433. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12434. if err != nil {
  12435. utils.ErrorLog(err.Error())
  12436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12437. return
  12438. }
  12439. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12440. //如果已经存在记录则删除处方
  12441. if template_one.ID > 0 {
  12442. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12443. var ids []int64
  12444. var org_id int64
  12445. for _, item := range ps {
  12446. org_id = c.GetAdminUserInfo().CurrentOrgId
  12447. ids = append(ids, item.ID)
  12448. }
  12449. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12450. if err2 == nil {
  12451. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12452. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12453. if len(prescriptions) > 0 {
  12454. for _, item := range prescriptions {
  12455. items := item.(map[string]interface{})
  12456. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12457. utils.ErrorLog("type")
  12458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12459. return
  12460. }
  12461. types := int64(items["type"].(float64))
  12462. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12463. utils.ErrorLog("med_type")
  12464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12465. return
  12466. }
  12467. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12468. ctime := time.Now().Unix()
  12469. prescription := &models.HisPrescriptionInfoTemplate{
  12470. PatientId: patient_id,
  12471. UserOrgId: adminInfo.CurrentOrgId,
  12472. Ctime: ctime,
  12473. Mtime: ctime,
  12474. Type: types,
  12475. Modifier: adminInfo.AdminUser.Id,
  12476. Creator: adminInfo.AdminUser.Id,
  12477. Status: 1,
  12478. PTemplateId: template_one.ID,
  12479. MedType: med_type,
  12480. }
  12481. service.CreateHisPrescriptionInfoTemplate(prescription)
  12482. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12483. advices := items["advices"].([]interface{})
  12484. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12485. ctime := time.Now().Unix()
  12486. mtime := ctime
  12487. if len(advices) > 0 {
  12488. for _, advice := range advices {
  12489. var s models.HisPrescriptionAdviceTemplate
  12490. s.PrescriptionId = prescription.ID
  12491. s.AdviceType = 2
  12492. s.StopState = 2
  12493. s.ExecutionState = 2
  12494. s.Status = 1
  12495. s.UserOrgId = adminInfo.CurrentOrgId
  12496. s.CreatedTime = ctime
  12497. s.UpdatedTime = mtime
  12498. s.PatientId = patient_id
  12499. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12500. if errcode > 0 {
  12501. c.ServeFailJSONWithSGJErrorCode(errcode)
  12502. return
  12503. }
  12504. service.CreateHisPrescriptionAdviceTemplate(&s)
  12505. }
  12506. }
  12507. }
  12508. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12509. projects := items["project"].([]interface{})
  12510. if len(projects) > 0 {
  12511. for _, project := range projects {
  12512. var p models.HisPrescriptionProjectTemplate
  12513. p.PrescriptionId = prescription.ID
  12514. p.Ctime = time.Now().Unix()
  12515. p.Mtime = time.Now().Unix()
  12516. p.PatientId = patient_id
  12517. p.UserOrgId = adminInfo.CurrentOrgId
  12518. p.Status = 1
  12519. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12520. if errcode > 0 {
  12521. c.ServeFailJSONWithSGJErrorCode(errcode)
  12522. return
  12523. }
  12524. service.CreateHisPrescriptionProjectTemplate(&p)
  12525. }
  12526. }
  12527. }
  12528. }
  12529. c.ServeSuccessJSON(map[string]interface{}{
  12530. "msg": "创建成功",
  12531. })
  12532. }
  12533. }
  12534. } else {
  12535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12536. return
  12537. }
  12538. } else {
  12539. err3 := service.CreateHisPrescriptionTemplate(template)
  12540. if err3 == nil {
  12541. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12542. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12543. if len(prescriptions) > 0 {
  12544. for _, item := range prescriptions {
  12545. items := item.(map[string]interface{})
  12546. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12547. utils.ErrorLog("type")
  12548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12549. return
  12550. }
  12551. types := int64(items["type"].(float64))
  12552. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12553. utils.ErrorLog("med_type")
  12554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12555. return
  12556. }
  12557. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12558. ctime := time.Now().Unix()
  12559. prescription := &models.HisPrescriptionInfoTemplate{
  12560. PatientId: patient_id,
  12561. UserOrgId: adminInfo.CurrentOrgId,
  12562. Ctime: ctime,
  12563. Mtime: ctime,
  12564. Type: types,
  12565. Modifier: adminInfo.AdminUser.Id,
  12566. Creator: adminInfo.AdminUser.Id,
  12567. Status: 1,
  12568. PTemplateId: template.ID,
  12569. MedType: med_type,
  12570. }
  12571. service.CreateHisPrescriptionInfoTemplate(prescription)
  12572. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12573. advices := items["advices"].([]interface{})
  12574. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12575. ctime := time.Now().Unix()
  12576. mtime := ctime
  12577. if len(advices) > 0 {
  12578. for _, advice := range advices {
  12579. var s models.HisPrescriptionAdviceTemplate
  12580. s.PrescriptionId = prescription.ID
  12581. s.AdviceType = 2
  12582. s.StopState = 2
  12583. s.ExecutionState = 2
  12584. s.Status = 1
  12585. s.UserOrgId = adminInfo.CurrentOrgId
  12586. s.CreatedTime = ctime
  12587. s.UpdatedTime = mtime
  12588. s.PatientId = patient_id
  12589. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12590. if errcode > 0 {
  12591. c.ServeFailJSONWithSGJErrorCode(errcode)
  12592. return
  12593. }
  12594. service.CreateHisPrescriptionAdviceTemplate(&s)
  12595. }
  12596. }
  12597. }
  12598. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12599. projects := items["project"].([]interface{})
  12600. if len(projects) > 0 {
  12601. for _, project := range projects {
  12602. var p models.HisPrescriptionProjectTemplate
  12603. p.PrescriptionId = prescription.ID
  12604. p.Ctime = time.Now().Unix()
  12605. p.Mtime = time.Now().Unix()
  12606. p.PatientId = patient_id
  12607. p.UserOrgId = adminInfo.CurrentOrgId
  12608. p.Status = 1
  12609. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12610. if errcode > 0 {
  12611. c.ServeFailJSONWithSGJErrorCode(errcode)
  12612. return
  12613. }
  12614. service.CreateHisPrescriptionProjectTemplate(&p)
  12615. }
  12616. }
  12617. }
  12618. }
  12619. c.ServeSuccessJSON(map[string]interface{}{
  12620. "msg": "创建成功",
  12621. })
  12622. }
  12623. }
  12624. } else {
  12625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12626. return
  12627. }
  12628. }
  12629. }
  12630. func (c *HisApiController) PreSettle() {
  12631. id, _ := c.GetInt64("id")
  12632. record_time := c.GetString("record_time")
  12633. his_patient_id, _ := c.GetInt64("his_patient_id")
  12634. timeLayout := "2006-01-02"
  12635. loc, _ := time.LoadLocation("Local")
  12636. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12637. diagnosis_id := c.GetString("diagnosis")
  12638. sick_type, _ := c.GetInt64("sick_type")
  12639. reg_type, _ := c.GetInt64("p_type")
  12640. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12641. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12642. if err != nil {
  12643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12644. return
  12645. }
  12646. recordDateTime := theTime.Unix()
  12647. adminUser := c.GetAdminUserInfo()
  12648. var prescriptions []*models.HisPrescription
  12649. var start_time int64
  12650. var end_time int64
  12651. ids_str := c.GetString("ids")
  12652. ids_arr := strings.Split(ids_str, ",")
  12653. fmt.Println(reg_type)
  12654. if settle_accounts_type == 1 { //日结
  12655. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12656. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12657. } else {
  12658. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12659. }
  12660. fmt.Println(prescriptions)
  12661. } else { //月结
  12662. start_time_str := c.GetString("start_time")
  12663. end_time_str := c.GetString("end_time")
  12664. timeLayout := "2006-01-02"
  12665. loc, _ := time.LoadLocation("Local")
  12666. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12667. if err != nil {
  12668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12669. return
  12670. }
  12671. recordStartTime := theStartTime.Unix()
  12672. start_time = recordStartTime
  12673. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12674. if err != nil {
  12675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12676. return
  12677. }
  12678. recordEndTime := theEndTime.Unix()
  12679. end_time = recordEndTime
  12680. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12681. }
  12682. if reg_type == 1111 || reg_type == 1112 {
  12683. reg_type = 11
  12684. }
  12685. timestamp := time.Now().Unix()
  12686. tempTime := time.Unix(timestamp, 0)
  12687. timeFormat := tempTime.Format("20060102150405")
  12688. chrgBchno := rand.Intn(100000) + 10000
  12689. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12690. strconv.FormatInt(his.PatientId, 10)
  12691. var ids []int64
  12692. for _, item := range prescriptions {
  12693. ids = append(ids, item.ID)
  12694. }
  12695. fmt.Println(ids)
  12696. var total float64
  12697. for _, item := range prescriptions {
  12698. fmt.Println(item)
  12699. if item.Type == 1 { //药品
  12700. for _, subItem := range item.HisDoctorAdviceInfo {
  12701. total = total + (subItem.Price * subItem.PrescribingNumber)
  12702. }
  12703. }
  12704. if item.Type == 2 { //项目
  12705. for _, subItem := range item.HisPrescriptionProject {
  12706. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12707. total = total + (subItem.Price * cnt)
  12708. }
  12709. }
  12710. for _, subItem := range item.HisAdditionalCharge {
  12711. total = total + (subItem.Price * float64(subItem.Count))
  12712. }
  12713. }
  12714. allTotal := fmt.Sprintf("%.2f", total)
  12715. totals, _ := strconv.ParseFloat(allTotal, 64)
  12716. order := &models.HisOrder{
  12717. UserOrgId: adminUser.CurrentOrgId,
  12718. HisPatientId: his.ID,
  12719. PatientId: id,
  12720. SettleAccountsDate: recordDateTime,
  12721. Ctime: time.Now().Unix(),
  12722. Mtime: time.Now().Unix(),
  12723. Status: 1,
  12724. OrderStatus: 1,
  12725. MdtrtId: his.Number,
  12726. Number: chrg_bchno,
  12727. MedfeeSumamt: totals,
  12728. SettleEndTime: end_time,
  12729. SettleStartTime: start_time,
  12730. SettleType: settle_accounts_type,
  12731. PsnPartAmt: totals,
  12732. PsnCashPay: totals,
  12733. PType: 2,
  12734. IsPre: 1,
  12735. MedType: strconv.Itoa(int(reg_type)),
  12736. Diagnosis: diagnosis_id,
  12737. }
  12738. err = service.CreateOrder(order)
  12739. if err != nil {
  12740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12741. return
  12742. }
  12743. var customs []*Custom
  12744. for _, item := range prescriptions {
  12745. fmt.Println(item.Type)
  12746. if item.Type == 1 { //药品
  12747. for _, subItem := range item.HisDoctorAdviceInfo {
  12748. cus := &Custom{
  12749. AdviceId: subItem.ID,
  12750. ProjectId: 0,
  12751. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12752. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12753. FeedetlSn: subItem.FeedetlSn,
  12754. Price: fmt.Sprintf("%.2f", subItem.Price),
  12755. MedListCodg: subItem.MedListCodg,
  12756. Type: 1,
  12757. }
  12758. customs = append(customs, cus)
  12759. }
  12760. }
  12761. if item.Type == 2 { //项目
  12762. for _, subItem := range item.HisPrescriptionProject {
  12763. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12764. cus := &Custom{
  12765. AdviceId: 0,
  12766. ProjectId: subItem.ID,
  12767. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12768. Cut: fmt.Sprintf("%.2f", cnt),
  12769. FeedetlSn: subItem.FeedetlSn,
  12770. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12771. MedListCodg: subItem.MedListCodg,
  12772. Type: 2,
  12773. }
  12774. customs = append(customs, cus)
  12775. }
  12776. }
  12777. for _, item := range item.HisAdditionalCharge {
  12778. cus := &Custom{
  12779. ItemId: item.ID,
  12780. AdviceId: 0,
  12781. ProjectId: 0,
  12782. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12783. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12784. FeedetlSn: item.FeedetlSn,
  12785. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12786. MedListCodg: item.XtHisAddtionConfig.Code,
  12787. Type: 3,
  12788. }
  12789. customs = append(customs, cus)
  12790. }
  12791. }
  12792. fmt.Println(customs)
  12793. for _, item := range customs {
  12794. var advice_id int64 = 0
  12795. var project_id int64 = 0
  12796. var item_id int64 = 0
  12797. var types int64 = 0
  12798. if item.Type == 1 {
  12799. advice_id = item.AdviceId
  12800. project_id = 0
  12801. item_id = 0
  12802. } else if item.Type == 2 {
  12803. advice_id = 0
  12804. item_id = 0
  12805. project_id = item.ProjectId
  12806. } else if item.Type == 3 {
  12807. advice_id = 0
  12808. item_id = item.ItemId
  12809. project_id = 0
  12810. }
  12811. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12812. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12813. pric, _ := strconv.ParseFloat(item.Price, 32)
  12814. info := &models.HisOrderInfo{
  12815. OrderNumber: order.Number,
  12816. UploadDate: time.Now().Unix(),
  12817. AdviceId: advice_id,
  12818. DetItemFeeSumamt: detItemFeeSumamt,
  12819. Cnt: cut,
  12820. Pric: pric,
  12821. PatientId: id,
  12822. Status: 1,
  12823. Mtime: time.Now().Unix(),
  12824. Ctime: time.Now().Unix(),
  12825. UserOrgId: adminUser.CurrentOrgId,
  12826. HisPatientId: his.ID,
  12827. OrderId: order.ID,
  12828. ProjectId: project_id,
  12829. Type: types,
  12830. ItemId: item_id,
  12831. }
  12832. service.CreateOrderInfo(info)
  12833. }
  12834. his.SickType = sick_type
  12835. service.UpdataHisPateint(&his)
  12836. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12837. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12838. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12839. if err == nil {
  12840. c.ServeSuccessJSON(map[string]interface{}{
  12841. "msg": "结算成功",
  12842. })
  12843. }
  12844. }
  12845. type CustomOrderInfo struct {
  12846. Name string
  12847. Spec string
  12848. Unit string
  12849. Count float64
  12850. Price float64
  12851. Total float64
  12852. }
  12853. func (c *HisApiController) GetPrivateExpensesInfo() {
  12854. order_id, _ := c.GetInt64("id", 0)
  12855. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12856. order, _ := service.GetHisOrderByID(order_id)
  12857. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12858. if order.ID == 0 {
  12859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12860. return
  12861. }
  12862. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12863. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12864. org_id := c.GetAdminUserInfo().CurrentOrgId
  12865. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12866. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12867. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12868. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12869. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12870. //var orderInfos_four []*models.HisOrderInfoTwo
  12871. //for _, item := range orderInfos_three {
  12872. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12873. // item.HisPrescriptionProject.IsCheckTeam = 1
  12874. // orderInfos_four = append(orderInfos_four, item)
  12875. //
  12876. // }
  12877. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12878. // item.HisPrescriptionProject.IsCheckTeam = 2
  12879. // orderInfos_two = append(orderInfos_two, item)
  12880. // }
  12881. //}
  12882. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12883. //var cus_slice []CustomOrderInfo
  12884. //for _, item := range new_order_info {
  12885. // var cus CustomOrderInfo
  12886. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12887. // cus.Unit = ""
  12888. // cus.Spec = ""
  12889. // var total float64
  12890. // for _, subItem := range orderInfos_four {
  12891. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12892. // total = total + subItem.DetItemFeeSumamt
  12893. // fmt.Println(subItem.DetItemFeeSumamt)
  12894. // }
  12895. // }
  12896. // cus.Count = 1
  12897. // cus.Total = total
  12898. // cus_slice = append(cus_slice, cus)
  12899. //}
  12900. orderInfos = append(orderInfos, orderInfos_two...)
  12901. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12902. //orderInfos = append(orderInfos, orderInfos_three...)
  12903. //}/**/
  12904. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12905. c.ServeSuccessJSON(map[string]interface{}{
  12906. "order": order,
  12907. "order_info": orderInfos,
  12908. "patient": patient,
  12909. "admin_info": adminInfo,
  12910. "his": his,
  12911. "current_admin": role,
  12912. "org_config": miConfig,
  12913. //"new_order_info": cus_slice,
  12914. })
  12915. }
  12916. func (this *HisApiController) ChangeMedType() {
  12917. med_type := this.GetString("med_type")
  12918. old_med_type := this.GetString("old_med_type")
  12919. ids := this.GetString("ids")
  12920. settle_type, _ := this.GetInt64("settle_type")
  12921. start_time := this.GetString("start_time")
  12922. end_time := this.GetString("end_time")
  12923. ids_arr := strings.Split(ids, ",")
  12924. if settle_type == 1 { //日结
  12925. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12926. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12927. prescription.MedType = med_type
  12928. err := service.SaveHisPrescriptionTwo(&prescription)
  12929. if err == nil {
  12930. this.ServeSuccessJSON(map[string]interface{}{
  12931. "msg": "修改成功",
  12932. })
  12933. } else {
  12934. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12935. return
  12936. }
  12937. } else if settle_type == 2 {
  12938. timeLayout := "2006-01-02"
  12939. loc, _ := time.LoadLocation("Local")
  12940. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12941. if err != nil {
  12942. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12943. return
  12944. }
  12945. recordStartTime := theStartTime.Unix()
  12946. start_time_timestamp := recordStartTime
  12947. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12948. if err != nil {
  12949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12950. return
  12951. }
  12952. recordEndTime := theEndTime.Unix()
  12953. end_time_timestamp := recordEndTime
  12954. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12955. if updateErr == nil {
  12956. this.ServeSuccessJSON(map[string]interface{}{
  12957. "msg": "修改成功",
  12958. })
  12959. } else {
  12960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12961. return
  12962. }
  12963. }
  12964. }
  12965. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12966. patient_id, _ := c.GetInt64("patient_id")
  12967. his_patient_id, _ := c.GetInt64("his_patient_id")
  12968. record_date := c.GetString("record_date")
  12969. start_time := c.GetString("start_time")
  12970. end_time := c.GetString("end_time")
  12971. order_status, _ := c.GetInt64("type", 0)
  12972. p_type, _ := c.GetInt64("p_type", 0)
  12973. order_id, _ := c.GetInt64("order_id", 0)
  12974. timeLayout := "2006-01-02"
  12975. loc, _ := time.LoadLocation("Local")
  12976. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12977. if err != nil {
  12978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12979. return
  12980. }
  12981. recordDateTime := theTime.Unix()
  12982. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12983. if err != nil {
  12984. }
  12985. startRecordDateTime := startTime.Unix()
  12986. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12987. if err != nil {
  12988. }
  12989. endRecordDateTime := endTime.Unix()
  12990. admin := c.GetAdminUserInfo()
  12991. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12992. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12993. order, _ := service.GetHisOrderByID(order_id)
  12994. var monthPrescriptions []*models.HisPrescription
  12995. if order_status == 1 || order_status == 0 {
  12996. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12997. } else if order_status == 2 {
  12998. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12999. }
  13000. var settle_total float64
  13001. for _, item := range monthPrescriptions {
  13002. if len(item.HisPrescriptionProject) > 0 {
  13003. for _, subItem := range item.HisPrescriptionProject {
  13004. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13005. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13006. settle_total = settle_total + total
  13007. }
  13008. }
  13009. if len(item.HisDoctorAdviceInfo) > 0 {
  13010. for _, subItem := range item.HisDoctorAdviceInfo {
  13011. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13012. settle_total = settle_total + total
  13013. }
  13014. }
  13015. }
  13016. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13017. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13018. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13019. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13020. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13021. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13022. //获取所有科室信息
  13023. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13024. var dia string
  13025. for _, item := range month_p_info {
  13026. if len(dia) == 0 {
  13027. dia = item.Diagnosis
  13028. } else {
  13029. dia = dia + "," + item.Diagnosis
  13030. }
  13031. }
  13032. dia_arr := removeDuplicates(strings.Split(dia, ","))
  13033. dia_arr = removeEmptyStrings(dia_arr)
  13034. c.ServeSuccessJSON(map[string]interface{}{
  13035. "his_info": his_patient_info,
  13036. "xt_info": xt_patient_info,
  13037. "case_history": case_history,
  13038. "info": patientPrescriptionInfo,
  13039. "last_info": lastPatientPrescriptionInfo,
  13040. "month_prescriptions": monthPrescriptions,
  13041. "order": order,
  13042. "doctors": doctors,
  13043. "department": department,
  13044. "settle_total": settle_total,
  13045. "dia_arr": dia_arr,
  13046. })
  13047. return
  13048. }
  13049. func removeEmptyStrings(input []string) []string {
  13050. var output []string
  13051. for _, s := range input {
  13052. if s != "" {
  13053. output = append(output, s)
  13054. }
  13055. }
  13056. return output
  13057. }
  13058. func removeDuplicates(input []string) []string {
  13059. seen := make(map[string]bool)
  13060. output := []string{}
  13061. for _, s := range input {
  13062. if _, exists := seen[s]; !exists {
  13063. seen[s] = true
  13064. output = append(output, s)
  13065. }
  13066. }
  13067. return output
  13068. }
  13069. func (c *HisApiController) GetHisMonthPatientInfo() {
  13070. patient_id, _ := c.GetInt64("patient_id")
  13071. his_patient_id, _ := c.GetInt64("his_patient_id")
  13072. record_date := c.GetString("record_date")
  13073. number := c.GetString("number")
  13074. start_time := c.GetString("start_time")
  13075. end_time := c.GetString("end_time")
  13076. p_type, _ := c.GetInt64("p_type")
  13077. timeLayout := "2006-01-02"
  13078. loc, _ := time.LoadLocation("Local")
  13079. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13080. if err != nil {
  13081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13082. return
  13083. }
  13084. recordDateTime := theTime.Unix()
  13085. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13086. if err != nil {
  13087. }
  13088. startRecordDateTime := startTime.Unix()
  13089. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13090. if err != nil {
  13091. }
  13092. endRecordDateTime := endTime.Unix()
  13093. admin := c.GetAdminUserInfo()
  13094. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  13095. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13096. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  13097. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13098. var settle_total float64
  13099. for _, item := range monthPrescriptions {
  13100. if len(item.HisPrescriptionProject) > 0 {
  13101. for _, subItem := range item.HisPrescriptionProject {
  13102. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13103. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13104. settle_total = settle_total + total
  13105. }
  13106. }
  13107. if len(item.HisDoctorAdviceInfo) > 0 {
  13108. for _, subItem := range item.HisDoctorAdviceInfo {
  13109. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13110. settle_total = settle_total + total
  13111. }
  13112. }
  13113. }
  13114. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13115. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13116. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13117. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13118. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13119. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13120. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13121. //获取所有科室信息
  13122. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13123. c.ServeSuccessJSON(map[string]interface{}{
  13124. "his_info": his_patient_info,
  13125. "xt_info": xt_patient_info,
  13126. "case_history": case_history,
  13127. "info": patientPrescriptionInfo,
  13128. "month_prescriptions": monthPrescriptions,
  13129. "order": order,
  13130. "doctors": doctors,
  13131. "department": department,
  13132. "count": count,
  13133. "drugStockConfig": drugStockConfig,
  13134. "last_info": lastPatientPrescriptionInfo,
  13135. "settle_total": settle_total,
  13136. })
  13137. return
  13138. }
  13139. func (c *HisApiController) GetAllOrder() {
  13140. org_id := c.GetAdminUserInfo().CurrentOrgId
  13141. orders, _ := service.GetNewHisOrderList(org_id)
  13142. c.ServeSuccessJSON(map[string]interface{}{
  13143. "order": orders,
  13144. })
  13145. return
  13146. }
  13147. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13148. newArr = make([]*models.HisOrderInfoTwo, 0)
  13149. for i := 0; i < len(arr); i++ {
  13150. repeat := false
  13151. for j := i + 1; j < len(arr); j++ {
  13152. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13153. repeat = true
  13154. break
  13155. }
  13156. }
  13157. if !repeat {
  13158. newArr = append(newArr, arr[i])
  13159. }
  13160. }
  13161. return
  13162. }
  13163. // 修改处方退库操作 参数传修改之前的处方数据
  13164. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13165. if advice.ExecutionState == 1 {
  13166. //查询该病人该药品是否有库存记录
  13167. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13168. if errcode == gorm.ErrRecordNotFound {
  13169. } else {
  13170. //退库
  13171. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13172. if advice.PrescribingNumberUnit == drug.MinUnit {
  13173. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13174. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13175. //退库
  13176. warehouseInfo := models.DrugWarehouseInfo{
  13177. StockMinNumber: prescribingNumber,
  13178. }
  13179. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13180. operation_time := time.Now().Unix()
  13181. creater := advice.AdviceDoctor
  13182. ctime := time.Now().Unix()
  13183. timeStr := time.Now().Format("2006-01-02")
  13184. timeArr := strings.Split(timeStr, "-")
  13185. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13186. total = total + 1
  13187. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13188. cancelStock := models.DrugCancelStock{
  13189. OrderNumber: orderNumber,
  13190. OperaTime: operation_time,
  13191. OrgId: advice.UserOrgId,
  13192. Creater: creater,
  13193. Ctime: ctime,
  13194. Status: 1,
  13195. ReturnTime: advice.AdviceDate,
  13196. Dealer: info.Dealer,
  13197. Manufacturer: info.Manufacturer,
  13198. Type: 1,
  13199. }
  13200. service.AddSigleDrugCancelStock(&cancelStock)
  13201. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13202. dealer, _ := service.GetDealerById(info.Dealer)
  13203. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13204. cancelStockInfo := models.DrugCancelStockInfo{
  13205. OrderNumber: cancelInfo.OrderNumber,
  13206. CancelStockId: cancelInfo.ID,
  13207. DrugId: info.DrugId,
  13208. Count: info.Count,
  13209. Status: 1,
  13210. Ctime: ctime,
  13211. OrgId: advice.UserOrgId,
  13212. Type: 1,
  13213. Manufacturer: manufactureName.ManufacturerName,
  13214. Dealer: dealer.DealerName,
  13215. Total: 0,
  13216. RetailPrice: info.RetailPrice,
  13217. RetailTotalPrice: info.RetailTotalPrice,
  13218. Price: info.Price,
  13219. RegisterAccount: "",
  13220. Remark: info.Remark,
  13221. BatchNumber: info.BatchNumber,
  13222. MaxUnit: info.CountUnit,
  13223. ProductDate: info.ProductDate,
  13224. ExpiryDate: info.ExpiryDate,
  13225. BatchNumberId: info.WarehouseInfoId,
  13226. }
  13227. flow := models.DrugFlow{
  13228. WarehousingId: 0,
  13229. DrugId: info.DrugId,
  13230. Number: "",
  13231. BatchNumber: info.BatchNumber,
  13232. Count: info.Count,
  13233. UserOrgId: advice.UserOrgId,
  13234. PatientId: 0,
  13235. SystemTime: ctime,
  13236. ConsumableType: 4,
  13237. IsSys: 0,
  13238. WarehousingOrder: "",
  13239. WarehouseOutId: 0,
  13240. WarehouseOutOrderNumber: "",
  13241. IsEdit: 0,
  13242. CancelStockId: cancelStock.ID,
  13243. CancelOrderNumber: cancelStock.OrderNumber,
  13244. Manufacturer: info.Manufacturer,
  13245. Dealer: info.Dealer,
  13246. Creator: advice.UserOrgId,
  13247. UpdateCreator: 0,
  13248. Status: 1,
  13249. Ctime: time.Now().Unix(),
  13250. Mtime: 0,
  13251. Price: info.Price,
  13252. WarehousingDetailId: 0,
  13253. WarehouseOutDetailId: 0,
  13254. CancelOutDetailId: 0,
  13255. ExpireDate: info.ExpiryDate,
  13256. ProductDate: info.ProductDate,
  13257. MaxUnit: info.CountUnit,
  13258. MinUnit: "",
  13259. }
  13260. service.CreatedCancelStock(cancelStockInfo)
  13261. service.CreateDrugFlowOne(flow)
  13262. } else {
  13263. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13264. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13265. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13266. warehouseInfo := models.DrugWarehouseInfo{
  13267. StockMinNumber: prescribingNumber,
  13268. }
  13269. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13270. }
  13271. operation_time := time.Now().Unix()
  13272. creater := advice.AdviceDoctor
  13273. ctime := time.Now().Unix()
  13274. timeStr := time.Now().Format("2006-01-02")
  13275. timeArr := strings.Split(timeStr, "-")
  13276. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13277. total = total + 1
  13278. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13279. cancelStock := models.DrugCancelStock{
  13280. OrderNumber: orderNumber,
  13281. OperaTime: operation_time,
  13282. OrgId: advice.UserOrgId,
  13283. Creater: creater,
  13284. Ctime: ctime,
  13285. Status: 1,
  13286. ReturnTime: advice.AdviceDate,
  13287. Dealer: info.Dealer,
  13288. Manufacturer: info.Manufacturer,
  13289. Type: 1,
  13290. }
  13291. service.AddSigleDrugCancelStock(&cancelStock)
  13292. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13293. dealer, _ := service.GetDealerById(info.Dealer)
  13294. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13295. cancelStockInfo := models.DrugCancelStockInfo{
  13296. OrderNumber: cancelInfo.OrderNumber,
  13297. CancelStockId: cancelInfo.ID,
  13298. DrugId: info.DrugId,
  13299. Count: info.Count,
  13300. Status: 1,
  13301. Ctime: ctime,
  13302. OrgId: advice.UserOrgId,
  13303. Type: 1,
  13304. Manufacturer: manufactureName.ManufacturerName,
  13305. Dealer: dealer.DealerName,
  13306. Total: 0,
  13307. RetailPrice: info.RetailPrice,
  13308. RetailTotalPrice: info.RetailTotalPrice,
  13309. Price: info.Price,
  13310. RegisterAccount: "",
  13311. Remark: info.Remark,
  13312. BatchNumber: info.BatchNumber,
  13313. MaxUnit: info.CountUnit,
  13314. ProductDate: info.ProductDate,
  13315. ExpiryDate: info.ExpiryDate,
  13316. BatchNumberId: info.WarehouseInfoId,
  13317. }
  13318. flow := models.DrugFlow{
  13319. WarehousingId: 0,
  13320. DrugId: info.DrugId,
  13321. Number: "",
  13322. BatchNumber: info.BatchNumber,
  13323. Count: info.Count,
  13324. UserOrgId: advice.UserOrgId,
  13325. PatientId: 0,
  13326. SystemTime: ctime,
  13327. ConsumableType: 4,
  13328. IsSys: 0,
  13329. WarehousingOrder: "",
  13330. WarehouseOutId: 0,
  13331. WarehouseOutOrderNumber: "",
  13332. IsEdit: 0,
  13333. CancelStockId: cancelStock.ID,
  13334. CancelOrderNumber: cancelStock.OrderNumber,
  13335. Manufacturer: info.Manufacturer,
  13336. Dealer: info.Dealer,
  13337. Creator: advice.AdviceDoctor,
  13338. UpdateCreator: 0,
  13339. Status: 1,
  13340. Ctime: time.Now().Unix(),
  13341. Mtime: 0,
  13342. Price: info.Price,
  13343. WarehousingDetailId: 0,
  13344. WarehouseOutDetailId: 0,
  13345. CancelOutDetailId: 0,
  13346. ExpireDate: info.ExpiryDate,
  13347. ProductDate: info.ProductDate,
  13348. MaxUnit: info.CountUnit,
  13349. MinUnit: "",
  13350. }
  13351. service.CreatedCancelStock(cancelStockInfo)
  13352. service.CreateDrugFlowOne(flow)
  13353. }
  13354. }
  13355. }
  13356. return err
  13357. }
  13358. func (this *HisApiController) DeleteNCDS() {
  13359. id, _ := this.GetInt64("id", 0)
  13360. if id > 0 {
  13361. service.DeletePsnNCDSRecordById(id)
  13362. this.ServeSuccessJSON(map[string]interface{}{
  13363. "msg": "删除成功",
  13364. })
  13365. } else {
  13366. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13367. return
  13368. }
  13369. }
  13370. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13371. id, _ := c.GetInt64("id")
  13372. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13373. c.ServeSuccessJSON(map[string]interface{}{
  13374. "advice": advice,
  13375. })
  13376. return
  13377. }
  13378. func (c *HisApiController) GetHisMonthChargePatientList() {
  13379. record_date := c.GetString("record_date")
  13380. start_time := c.GetString("start_time")
  13381. end_time := c.GetString("end_time")
  13382. timeLayout := "2006-01-02"
  13383. loc, _ := time.LoadLocation("Local")
  13384. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13385. if err != nil {
  13386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13387. return
  13388. }
  13389. if err != nil {
  13390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13391. return
  13392. }
  13393. recordDateTime := theTime.Unix()
  13394. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13395. if err != nil {
  13396. }
  13397. startRecordDateTime := startTime.Unix()
  13398. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13399. if err != nil {
  13400. }
  13401. endRecordDateTime := endTime.Unix()
  13402. adminInfo := c.GetAdminUserInfo()
  13403. var tempMonthChargePatients []*service.MonthChargePatients
  13404. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13405. for _, item := range tempPatients {
  13406. //过滤没有处方的
  13407. if len(item.HisPrescription) == 0 {
  13408. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13409. }
  13410. }
  13411. c.ServeSuccessJSON(map[string]interface{}{
  13412. "list": tempMonthChargePatients,
  13413. })
  13414. }
  13415. // PrescriptionDifference 医嘱数量差值结构体
  13416. type PrescriptionDrugDifference struct {
  13417. DrugID int64 //基础库药品id
  13418. ID int64 //医嘱id
  13419. Difference float64 //差值
  13420. Unit string //单位
  13421. }
  13422. type PrescriptionGoodDifference struct {
  13423. GoodID int64 //基础库项目耗材id
  13424. ID int64 //医嘱id
  13425. Difference int64 //差值
  13426. Unit string //单位
  13427. Type int64 //类型
  13428. }
  13429. type EditCustomData struct {
  13430. adviceList []*models.HisDoctorAdviceInfo
  13431. projectList []*models.HisPrescriptionProject
  13432. }
  13433. type SrcCustomData struct {
  13434. adviceList []*models.HisDoctorAdviceInfo
  13435. projectList []*models.HisPrescriptionProject
  13436. }
  13437. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13438. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13439. differences := make([]*PrescriptionDrugDifference, 0)
  13440. // 创建一个 map 来存储第一个切片中的药品信息
  13441. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13442. for _, advice := range firstPrescription {
  13443. firstMap[advice.DrugId] = advice
  13444. }
  13445. // 遍历第二个切片中的药品信息,并比较数量差值
  13446. for _, advice := range secondPrescription {
  13447. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13448. diff := &PrescriptionDrugDifference{
  13449. DrugID: advice.DrugId,
  13450. ID: firstAdvice.ID,
  13451. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13452. Unit: firstAdvice.PrescribingNumberUnit,
  13453. }
  13454. differences = append(differences, diff)
  13455. }
  13456. }
  13457. return differences
  13458. }
  13459. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13460. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13461. differences := make([]*PrescriptionGoodDifference, 0)
  13462. // 创建一个 map 来存储第一个切片中的耗材信息
  13463. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13464. for _, good := range firstPrescription {
  13465. firstMap[good.ProjectId] = good
  13466. }
  13467. // 遍历第二个切片中的耗材信息,并比较数量差值
  13468. for _, good := range secondPrescription {
  13469. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13470. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13471. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13472. diff := &PrescriptionGoodDifference{
  13473. GoodID: good.ProjectId,
  13474. ID: firstGood.ID,
  13475. Difference: count - firstCount,
  13476. Unit: firstGood.Unit,
  13477. Type: firstGood.Type,
  13478. }
  13479. differences = append(differences, diff)
  13480. }
  13481. }
  13482. return differences
  13483. }
  13484. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13485. var adviceList []*models.HisDoctorAdviceInfo
  13486. var projectList []*models.HisPrescriptionProject
  13487. var advice_ids []int64
  13488. var project_ids []int64
  13489. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13490. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13491. //var tempPrescription *models.HisPrescriptionProjectscription
  13492. if len(prescriptions) > 0 {
  13493. for _, item := range prescriptions {
  13494. items := item.(map[string]interface{})
  13495. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13496. advices := items["advices"].([]interface{})
  13497. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13498. groupNo := int64(0)
  13499. ctime := time.Now().Unix()
  13500. mtime := ctime
  13501. if len(advices) > 0 {
  13502. for _, advice := range advices {
  13503. var s models.HisDoctorAdviceInfo
  13504. s.AdviceType = 2
  13505. s.StopState = 2
  13506. s.ExecutionState = 2
  13507. s.Status = 1
  13508. s.Groupno = groupNo
  13509. s.CreatedTime = ctime
  13510. s.UpdatedTime = mtime
  13511. s.IsSettle = 2
  13512. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13513. //存储切片中
  13514. if s.ID > 0 {
  13515. advice_ids = append(advice_ids, s.ID)
  13516. adviceList = append(adviceList, &s)
  13517. }
  13518. }
  13519. }
  13520. }
  13521. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13522. projects := items["project"].([]interface{})
  13523. if len(projects) > 0 {
  13524. for _, project := range projects {
  13525. var p models.HisPrescriptionProject
  13526. p.Ctime = time.Now().Unix()
  13527. p.Mtime = time.Now().Unix()
  13528. p.Status = 1
  13529. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13530. if p.ID > 0 {
  13531. project_ids = append(project_ids, p.ID)
  13532. projectList = append(projectList, &p)
  13533. }
  13534. }
  13535. }
  13536. }
  13537. }
  13538. }
  13539. }
  13540. editCustomData.projectList = projectList
  13541. editCustomData.adviceList = adviceList
  13542. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13543. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13544. srcCustomData.adviceList = list
  13545. srcCustomData.projectList = list2
  13546. return
  13547. }
  13548. func (c *HisApiController) GetAllGoodInforList() {
  13549. orgId := c.GetAdminUserInfo().CurrentOrgId
  13550. goodList, _ := service.GetAllGoodList(orgId)
  13551. c.ServeSuccessJSON(map[string]interface{}{
  13552. "goodList": goodList,
  13553. })
  13554. return
  13555. }
  13556. func (this *HisApiController) SaveGoodList() {
  13557. project_name := this.GetString("project_name")
  13558. sort, _ := this.GetInt64("sort")
  13559. orgId := this.GetAdminUserInfo().CurrentOrgId
  13560. dataBody := make(map[string]interface{}, 0)
  13561. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13562. if err != nil {
  13563. utils.ErrorLog(err.Error())
  13564. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13565. return
  13566. }
  13567. goodTeam := models.XtGoodTeam{
  13568. ProjectName: project_name,
  13569. Sort: sort,
  13570. UserOrgId: orgId,
  13571. Status: 1,
  13572. Ctime: time.Now().Unix(),
  13573. Mtime: time.Now().Unix(),
  13574. }
  13575. service.CreateGoodTeam(goodTeam)
  13576. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13577. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13578. infos, _ := dataBody["info"].([]interface{})
  13579. if len(infos) > 0 {
  13580. for _, item := range infos {
  13581. items := item.(map[string]interface{})
  13582. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13583. utils.ErrorLog("good_id")
  13584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13585. return
  13586. }
  13587. good_id := int64(items["good_id"].(float64))
  13588. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13589. utils.ErrorLog("number")
  13590. }
  13591. number := int64(items["number"].(float64))
  13592. xtGoodTeamList := models.XtGoodTeamList{
  13593. GoodId: good_id,
  13594. Count: number,
  13595. TeamId: lastGoodTeam.ID,
  13596. UserOrgId: orgId,
  13597. Status: 1,
  13598. Ctime: time.Now().Unix(),
  13599. Mtime: time.Now().Unix(),
  13600. }
  13601. service.CreateGoodList(xtGoodTeamList)
  13602. }
  13603. this.ServeSuccessJSON(map[string]interface{}{
  13604. "lastGoodTeam": lastGoodTeam,
  13605. })
  13606. }
  13607. }
  13608. return
  13609. }
  13610. func (this *HisApiController) GetGoodList() {
  13611. orgId := this.GetAdminUserInfo().CurrentOrgId
  13612. limit, _ := this.GetInt64("limit")
  13613. page, _ := this.GetInt64("page")
  13614. keyword := this.GetString("keyword")
  13615. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13616. this.ServeSuccessJSON(map[string]interface{}{
  13617. "list": list,
  13618. "total": total,
  13619. })
  13620. }
  13621. func (this *HisApiController) GetGoodNameDetail() {
  13622. id, _ := this.GetInt64("id")
  13623. orgId := this.GetAdminUserInfo().CurrentOrgId
  13624. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13625. goodList, _ := service.GetAllGoodList(orgId)
  13626. this.ServeSuccessJSON(map[string]interface{}{
  13627. "goodNameDetail": goodNameDetail,
  13628. "goodList": goodList,
  13629. })
  13630. }
  13631. func (this *HisApiController) UpdateGoodList() {
  13632. project_name := this.GetString("project_name")
  13633. sort, _ := this.GetInt64("sort")
  13634. id, _ := this.GetInt64("id")
  13635. orgId := this.GetAdminUserInfo().CurrentOrgId
  13636. dataBody := make(map[string]interface{}, 0)
  13637. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13638. if err != nil {
  13639. utils.ErrorLog(err.Error())
  13640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13641. return
  13642. }
  13643. goodTeam := models.XtGoodTeam{
  13644. ProjectName: project_name,
  13645. Sort: sort,
  13646. UserOrgId: orgId,
  13647. Status: 1,
  13648. Ctime: time.Now().Unix(),
  13649. Mtime: time.Now().Unix(),
  13650. ID: id,
  13651. }
  13652. service.SaveGoodTeam(goodTeam)
  13653. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13654. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13655. infos, _ := dataBody["info"].([]interface{})
  13656. if len(infos) > 0 {
  13657. for _, item := range infos {
  13658. items := item.(map[string]interface{})
  13659. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13660. utils.ErrorLog("good_id")
  13661. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13662. return
  13663. }
  13664. good_id := int64(items["good_id"].(float64))
  13665. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13666. utils.ErrorLog("id")
  13667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13668. return
  13669. }
  13670. id := int64(items["id"].(float64))
  13671. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13672. utils.ErrorLog("number")
  13673. }
  13674. number := int64(items["number"].(float64))
  13675. xtGoodTeamList := models.XtGoodTeamList{
  13676. ID: id,
  13677. GoodId: good_id,
  13678. Count: number,
  13679. TeamId: lastGoodTeam.ID,
  13680. UserOrgId: orgId,
  13681. Status: 1,
  13682. Ctime: time.Now().Unix(),
  13683. Mtime: time.Now().Unix(),
  13684. }
  13685. service.SaveGoodList(xtGoodTeamList)
  13686. }
  13687. this.ServeSuccessJSON(map[string]interface{}{
  13688. "lastGoodTeam": lastGoodTeam,
  13689. })
  13690. }
  13691. }
  13692. return
  13693. }
  13694. func (this *HisApiController) DeleteGoodTeam() {
  13695. id, _ := this.GetInt64("id")
  13696. team, _ := service.DeleteGoodTeam(id)
  13697. this.ServeSuccessJSON(map[string]interface{}{
  13698. "team": team,
  13699. })
  13700. }
  13701. func (this *HisApiController) DeleteGood() {
  13702. id, _ := this.GetInt64("id")
  13703. good, _ := service.DeleteGood(id)
  13704. this.ServeSuccessJSON(map[string]interface{}{
  13705. "good": good,
  13706. })
  13707. }