his_api_controller.go 585KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074
  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 operationCostTotal float64 = 0 //手术费
  905. //var operationCostSelfTotal float64 = 0 //手术费
  906. var operationCostPartSelfTotal float64 = 0 //手术费
  907. var otherCostTotal float64 = 0 //其他费用
  908. //var otherCostSelfTotal float64 = 0 //其他费用
  909. var otherCostPartSelfTotal float64 = 0 //其他费用
  910. var materialCostTotal float64 = 0 //材料费
  911. //var materialCostSelfTotal float64 = 0 //材料费
  912. var materialCostPartSelfTotal float64 = 0 //材料费
  913. var westernMedicineCostTotal float64 = 0 //西药费
  914. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  915. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  916. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  917. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  918. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  919. var checkCostTotal float64 = 0 //检查费
  920. //var checkCostSelfTotal float64 = 0 //检查费
  921. var checkCostPartSelfTotal float64 = 0 //检查费
  922. var laboratoryCostTotal float64 = 0 //化验费
  923. //var laboratoryCostSelfTotal float64 = 0 //化验费
  924. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  925. var treatCostTotal float64 = 0 //治疗费用
  926. //var treatCostSelfTotal float64 = 0 //治疗费用
  927. var treatCostPartSelfTotal float64 = 0 //治疗费用
  928. var zhenChaCostTotal float64 = 0 //其他费用
  929. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  930. decimal.DivisionPrecision = 2
  931. for _, item := range orderInfos {
  932. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  933. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  934. item.MedChrgitmType = "09"
  935. }
  936. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  937. if item.HisPrescriptionProject.Type == 2 {
  938. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  939. fmt.Println("CostClassify")
  940. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  941. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  942. case 0:
  943. item.MedChrgitmType = "0"
  944. break
  945. case 1:
  946. item.MedChrgitmType = "14"
  947. break
  948. case 2:
  949. item.MedChrgitmType = "05"
  950. break
  951. case 3:
  952. item.MedChrgitmType = "03"
  953. break
  954. case 4:
  955. item.MedChrgitmType = "03"
  956. break
  957. case 5:
  958. item.MedChrgitmType = "08"
  959. break
  960. case 6:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 7:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 8:
  967. item.MedChrgitmType = "03"
  968. break
  969. case 9:
  970. item.MedChrgitmType = "14"
  971. break
  972. case 10:
  973. item.MedChrgitmType = "14"
  974. break
  975. case 11:
  976. item.MedChrgitmType = "06"
  977. break
  978. case 12:
  979. item.MedChrgitmType = "12"
  980. break
  981. case 13:
  982. item.MedChrgitmType = "01"
  983. break
  984. case 14:
  985. item.MedChrgitmType = "04"
  986. break
  987. case 15:
  988. item.MedChrgitmType = "14"
  989. break
  990. }
  991. } else {
  992. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  993. case 1:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 2:
  997. item.MedChrgitmType = "05"
  998. break
  999. case 3:
  1000. item.MedChrgitmType = "04"
  1001. break
  1002. case 4:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 5:
  1006. item.MedChrgitmType = "08"
  1007. break
  1008. case 6:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. case 7:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. case 8:
  1015. item.MedChrgitmType = "03"
  1016. break
  1017. case 9:
  1018. item.MedChrgitmType = "14"
  1019. break
  1020. default:
  1021. item.MedChrgitmType = "14"
  1022. break
  1023. }
  1024. }
  1025. } else if item.HisPrescriptionProject.Type == 3 {
  1026. item.MedChrgitmType = "08"
  1027. }
  1028. }
  1029. }
  1030. if order.IsMedicineInsurance != 1 {
  1031. order.PsnCashPay = order.MedfeeSumamt
  1032. }
  1033. for _, item := range orderInfos {
  1034. if item.MedChrgitmType == "01" { //床位费
  1035. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //诊察费
  1040. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //zhenChaCostSelfTotal = zhenChaCostTotal
  1042. }
  1043. if item.MedChrgitmType == "03" { //检查费
  1044. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1045. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1046. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1047. }
  1048. if item.MedChrgitmType == "02" { //检查费
  1049. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1050. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1051. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1052. }
  1053. if item.MedChrgitmType == "04" { //化验费
  1054. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1055. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1056. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1057. }
  1058. if item.MedChrgitmType == "05" { //治疗费
  1059. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1060. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1061. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1062. }
  1063. if item.MedChrgitmType == "06" { //手术费
  1064. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1065. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1066. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1067. }
  1068. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1069. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1070. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1071. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1072. }
  1073. if item.MedChrgitmType == "09" { //西药费
  1074. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1075. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1076. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1077. }
  1078. if item.MedChrgitmType == "11" { //中成费
  1079. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1080. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1081. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1082. }
  1083. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1084. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1085. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1086. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1087. }
  1088. }
  1089. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1090. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1091. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1092. var dia_config []*models.HisXtDiagnoseConfig
  1093. var diagnosis_ids []string
  1094. if his.ID > 0 {
  1095. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1096. } else {
  1097. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1098. }
  1099. for _, item := range diagnosis_ids {
  1100. id, _ := strconv.ParseInt(item, 10, 64)
  1101. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1102. dia_config = append(dia_config, diagnosisConfig)
  1103. }
  1104. var rf []CustomFundPay
  1105. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1106. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1107. c.ServeSuccessJSON(map[string]interface{}{
  1108. "patient": patient,
  1109. "order_infos": orderInfos,
  1110. "diagnosis": name,
  1111. "bedCostTotal": bedCostTotal,
  1112. "bedCostSelfTotal": bedCostTotal,
  1113. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1114. "operationCostTotal": operationCostTotal,
  1115. "operationCostSelfTotal": operationCostTotal,
  1116. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1117. "otherCostTotal": otherCostTotal,
  1118. "otherCostSelfTotal": otherCostTotal,
  1119. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1120. "materialCostTotal": materialCostTotal,
  1121. "materialCostSelfTotal": materialCostTotal,
  1122. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1123. "westernMedicineCostTotal": westernMedicineCostTotal,
  1124. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1125. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1126. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1127. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1128. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1129. "checkCostTotal": checkCostTotal,
  1130. "checkCostSelfTotal": checkCostTotal,
  1131. "zhenChaCostTotal": zhenChaCostTotal,
  1132. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1133. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1134. "laboratoryCostTotal": laboratoryCostTotal,
  1135. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1136. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1137. "treatCostTotal": treatCostTotal,
  1138. "treatCostSelfTotal": treatCostTotal,
  1139. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1140. "charge_admin": charge_admin,
  1141. "printor_admin": printor_admin,
  1142. "org_name": org.OrgName,
  1143. "org_code": miConfig.Code,
  1144. "name": patient.Name,
  1145. "number": order.MdtrtId,
  1146. "date": order.SettleAccountsDate,
  1147. "info": order,
  1148. "new_order": order,
  1149. "his_hospital": his_hospital,
  1150. "his": his,
  1151. "funds": rf,
  1152. "dia_config": dia_config,
  1153. })
  1154. }
  1155. func (c *HisApiController) RefudDetail() {
  1156. order_id, _ := c.GetInt64("order_id")
  1157. order, _ := service.GetHisOrderByID(order_id)
  1158. adminUser := c.GetAdminUserInfo()
  1159. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1160. c.ServeSuccessJSON(map[string]interface{}{
  1161. "msg": "撤销成功",
  1162. })
  1163. }
  1164. func (c *HisApiController) Sscard() {
  1165. //r := CardInit()
  1166. //if r == 0 {
  1167. // GetBaseInfo()
  1168. //}
  1169. //c.ServeSuccessJSON(map[string]interface{}{
  1170. // "list": "11",
  1171. //})
  1172. }
  1173. func GetBaseInfo() error {
  1174. //handle := syscall.MustLoadDLL("SSCard.dll")
  1175. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1176. //
  1177. //str := make([]byte, 256)
  1178. //str1 := make([]byte, 256)
  1179. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1180. //if ferr != nil {
  1181. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1182. // return ferr
  1183. //}
  1184. //
  1185. //fmt.Println(string(str))
  1186. //
  1187. //fmt.Println(r)
  1188. return nil
  1189. }
  1190. func CardInit() int {
  1191. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1192. //add := DllTestDef.MustFindProc("Init")
  1193. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1194. //if err != nil {
  1195. // fmt.Println("SSCard的运算结果为:", ret)
  1196. //}
  1197. //result := int(ret)
  1198. return 0
  1199. }
  1200. func IntPtr(n int) uintptr {
  1201. return uintptr(n)
  1202. }
  1203. func StrPtr(s string) uintptr {
  1204. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1205. }
  1206. func (c *HisApiController) GetHisPatientList() {
  1207. record_date := c.GetString("record_date")
  1208. sch_type, _ := c.GetInt64("sch_type")
  1209. patient_type, _ := c.GetInt64("patient_type")
  1210. fmt.Println("patient_type")
  1211. fmt.Println(patient_type)
  1212. timeLayout := "2006-01-02"
  1213. loc, _ := time.LoadLocation("Local")
  1214. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1215. if err != nil {
  1216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1217. return
  1218. }
  1219. recordDateTime := theTime.Unix()
  1220. adminInfo := c.GetAdminUserInfo()
  1221. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1222. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1223. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1224. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1225. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1226. fmt.Println(patients_three)
  1227. //获取当前用户的信息
  1228. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1229. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1230. //获取所有科室信息
  1231. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1232. //var aa []service.PatientThree
  1233. noElementsSlice := make([]service.PatientThree, 0)
  1234. c.ServeSuccessJSON(map[string]interface{}{
  1235. "list": patients_three,
  1236. "list_two": patients_four,
  1237. "list_three": noElementsSlice,
  1238. "info": adminUserInfo,
  1239. "doctors": doctors,
  1240. "department": department,
  1241. })
  1242. } else {
  1243. //获取当前用户的信息
  1244. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1245. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1246. //获取所有科室信息
  1247. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1248. //var aa []service.PatientThree
  1249. noElementsSlice := make([]service.PatientThree, 0)
  1250. c.ServeSuccessJSON(map[string]interface{}{
  1251. "list": patients,
  1252. "list_two": patients_two,
  1253. "list_three": noElementsSlice,
  1254. "info": adminUserInfo,
  1255. "doctors": doctors,
  1256. "department": department,
  1257. })
  1258. }
  1259. }
  1260. type CustomTemplate struct {
  1261. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1262. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1263. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1264. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1265. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1266. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1267. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1268. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1269. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1270. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1271. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1272. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1273. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1274. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1275. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1276. }
  1277. func (c *HisApiController) GetHisPatientInfo() {
  1278. patient_id, _ := c.GetInt64("patient_id")
  1279. his_patient_id, _ := c.GetInt64("his_patient_id")
  1280. record_date := c.GetString("record_date")
  1281. number := c.GetString("number")
  1282. //start_time := c.GetString("start_time")
  1283. //end_time := c.GetString("end_time")
  1284. p_type, _ := c.GetInt64("p_type")
  1285. timeLayout := "2006-01-02"
  1286. loc, _ := time.LoadLocation("Local")
  1287. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1288. if err != nil {
  1289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1290. return
  1291. }
  1292. recordDateTime := theTime.Unix()
  1293. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1294. //if err != nil {
  1295. //
  1296. //}
  1297. //startRecordDateTime := startTime.Unix()
  1298. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1299. //if err != nil {
  1300. //
  1301. //}
  1302. //endRecordDateTime := endTime.Unix()
  1303. admin := c.GetAdminUserInfo()
  1304. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1305. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1306. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1307. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1308. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1309. var prescriptions []*models.HisPrescription
  1310. var last_prescriptions []*models.HisPrescription
  1311. var sch_prescriptions []CustomTemplate
  1312. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1313. if p_type == 1 { //住院
  1314. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1315. for _, item := range prescriptions {
  1316. for _, subItem := range item.HisDoctorAdviceInfo {
  1317. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1318. if info.RetailPrice > 0 {
  1319. subItem.Drug.MinPrice = info.RetailPrice
  1320. }
  1321. }
  1322. }
  1323. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1324. } else { //门诊
  1325. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1326. for _, item := range prescriptions {
  1327. for _, subItem := range item.HisDoctorAdviceInfo {
  1328. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1329. if info.RetailPrice > 0 {
  1330. subItem.Drug.MinPrice = info.RetailPrice
  1331. }
  1332. }
  1333. }
  1334. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1335. }
  1336. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1337. if sch.ID > 0 {
  1338. var week string
  1339. t := time.Now()
  1340. switch t.Weekday().String() {
  1341. case "Monday":
  1342. week = "周一"
  1343. break
  1344. case "Tuesday":
  1345. week = "周二"
  1346. break
  1347. case "Wednesday":
  1348. week = "周三"
  1349. break
  1350. case "Thursday":
  1351. week = "周四"
  1352. break
  1353. case "Friday":
  1354. week = "周五"
  1355. break
  1356. case "Saturday":
  1357. week = "周六"
  1358. break
  1359. case "Sunday":
  1360. week = "周日"
  1361. break
  1362. }
  1363. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1364. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1365. //根据推送频率组装新的数组
  1366. for _, item := range temp_sch_prescriptions {
  1367. var cus CustomTemplate
  1368. cus.ID = item.ID
  1369. cus.UserOrgId = item.UserOrgId
  1370. cus.PatientId = item.PatientId
  1371. cus.MedType = item.MedType
  1372. cus.RecordDate = item.RecordDate
  1373. cus.Type = item.Type
  1374. cus.PType = item.PType
  1375. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1376. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1377. if subItem.FrequencyType == 1 { //每次必推
  1378. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1379. }
  1380. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1381. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1382. }
  1383. if subItem.FrequencyType == 2 { //按照天数频率
  1384. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1385. now := p.Unix()
  1386. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1387. dayStr2 := "-" + dayStr
  1388. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1389. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1390. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1391. if len(advices) == 0 {
  1392. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1393. }
  1394. }
  1395. }
  1396. }
  1397. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1398. if subItem.Type == 2 {
  1399. if subItem.XtHisProject.MedicalStatus != 1 {
  1400. if subItem.FrequencyType == 1 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1404. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1405. }
  1406. if subItem.FrequencyType == 2 {
  1407. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1408. now := p.Unix()
  1409. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1410. dayStr2 := "-" + dayStr
  1411. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1412. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1413. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1414. if len(projects) == 0 {
  1415. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1416. }
  1417. }
  1418. }
  1419. } else if subItem.Type == 3 {
  1420. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1421. if subItem.FrequencyType == 1 {
  1422. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1423. }
  1424. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1425. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1426. }
  1427. if subItem.FrequencyType == 2 {
  1428. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1429. now := p.Unix()
  1430. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1431. dayStr2 := "-" + dayStr
  1432. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1433. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1434. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1435. if len(projects) == 0 {
  1436. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1437. }
  1438. }
  1439. }
  1440. }
  1441. }
  1442. sch_prescriptions = append(sch_prescriptions, cus)
  1443. }
  1444. for _, item := range sch_prescriptions {
  1445. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1446. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1447. }
  1448. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1449. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1450. }
  1451. }
  1452. }
  1453. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1454. if config.ID > 0 && config.IsOpen == 1 {
  1455. for _, item := range sch_prescriptions {
  1456. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1457. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1458. if info.RetailPrice > 0 {
  1459. subItem.Drug.MinPrice = info.RetailPrice
  1460. if admin.CurrentOrgId != 10598 {
  1461. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1462. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1463. }
  1464. }
  1465. }
  1466. }
  1467. }
  1468. if config.ID > 0 && config.IsOpen == 1 {
  1469. for _, item := range sch_prescriptions {
  1470. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1471. if subItem.Type == 3 {
  1472. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1473. if info.Price > 0 {
  1474. subItem.GoodInfo.PackingPrice = info.Price
  1475. if admin.CurrentOrgId != 10598 {
  1476. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1477. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1478. }
  1479. }
  1480. }
  1481. }
  1482. }
  1483. }
  1484. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1485. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1486. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1487. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1488. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1489. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1490. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1491. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1492. //获取所有科室信息
  1493. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1494. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1495. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1496. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1497. fmt.Println(prescriptions)
  1498. fmt.Println(sch_prescriptions)
  1499. fmt.Println(last_prescriptions)
  1500. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1501. if len(sch_prescriptions) > 0 {
  1502. var index = 0
  1503. for subindex, item := range sch_prescriptions {
  1504. if item.Type == 2 {
  1505. index = subindex
  1506. }
  1507. }
  1508. fmt.Println(index)
  1509. fmt.Println(len(sch_prescriptions))
  1510. if index >= 0 && index < len(sch_prescriptions) {
  1511. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1512. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1513. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1514. if one.ID > 0 {
  1515. var hpt models.HisPrescriptionProjectTemplate
  1516. hpt.Type = 3
  1517. hpt.ID = 0
  1518. hpt.PatientId = sch_prescriptions[index].PatientId
  1519. hpt.Status = 1
  1520. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1521. hpt.Mtime = time.Now().Unix()
  1522. hpt.Ctime = time.Now().Unix()
  1523. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1524. hpt.Count = "1"
  1525. hpt.Price = one.RetailPrice
  1526. hpt.ProjectId = one.ID
  1527. hpt.FeedetlSn = ""
  1528. hpt.PrescriptionId = sch_prescriptions[index].ID
  1529. hpt.Unit = one.PackingUnit
  1530. hpt.Day = "1"
  1531. hpt.SingleDose = "1"
  1532. hpt.GoodInfo = one
  1533. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1534. }
  1535. if two.ID > 0 {
  1536. var hpt models.HisPrescriptionProjectTemplate
  1537. hpt.Type = 3
  1538. hpt.ID = 0
  1539. hpt.PatientId = sch_prescriptions[index].PatientId
  1540. hpt.Status = 1
  1541. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1542. hpt.Mtime = time.Now().Unix()
  1543. hpt.Ctime = time.Now().Unix()
  1544. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1545. hpt.Count = "1"
  1546. hpt.Price = two.RetailPrice
  1547. hpt.ProjectId = two.ID
  1548. hpt.FeedetlSn = ""
  1549. hpt.PrescriptionId = sch_prescriptions[index].ID
  1550. hpt.Unit = two.PackingUnit
  1551. hpt.Day = "1"
  1552. hpt.SingleDose = "1"
  1553. hpt.GoodInfo = two
  1554. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1555. }
  1556. //if three.ID > 0 {
  1557. // var hpt models.HisPrescriptionProjectTemplate
  1558. // hpt.Type = 3
  1559. // hpt.ID = 0
  1560. // hpt.PatientId = sch_prescriptions[index].PatientId
  1561. // hpt.Status = 1
  1562. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1563. // hpt.Mtime = time.Now().Unix()
  1564. // hpt.Ctime = time.Now().Unix()
  1565. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1566. // hpt.Count = "1"
  1567. // hpt.Price = three.RetailPrice
  1568. // hpt.ProjectId = three.ID
  1569. // hpt.FeedetlSn = ""
  1570. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1571. // hpt.Unit = three.PackingUnit
  1572. // hpt.Day = "1"
  1573. // hpt.SingleDose = "1"
  1574. // hpt.GoodInfo = three
  1575. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1576. //}
  1577. fmt.Println(sch_prescriptions)
  1578. }
  1579. } else {
  1580. if len(last_prescriptions) > 0 {
  1581. var index = 0
  1582. for subindex, item := range last_prescriptions {
  1583. if item.Type == 2 {
  1584. index = subindex
  1585. }
  1586. }
  1587. if index >= 0 && index < len(last_prescriptions) {
  1588. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1589. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1590. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1591. if one.ID > 0 {
  1592. var hpt models.HisPrescriptionProject
  1593. hpt.Type = 3
  1594. hpt.ID = 0
  1595. hpt.PatientId = last_prescriptions[index].PatientId
  1596. hpt.Status = 1
  1597. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1598. hpt.Mtime = time.Now().Unix()
  1599. hpt.Ctime = time.Now().Unix()
  1600. hpt.RecordDate = last_prescriptions[index].RecordDate
  1601. hpt.Count = "1"
  1602. hpt.Price = one.RetailPrice
  1603. hpt.ProjectId = one.ID
  1604. hpt.FeedetlSn = ""
  1605. hpt.PrescriptionId = last_prescriptions[index].ID
  1606. hpt.Unit = one.PackingUnit
  1607. hpt.Day = "1"
  1608. hpt.SingleDose = "1"
  1609. hpt.GoodInfo = one
  1610. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1611. }
  1612. if two.ID > 0 {
  1613. var hpt models.HisPrescriptionProject
  1614. hpt.Type = 3
  1615. hpt.ID = 0
  1616. hpt.PatientId = last_prescriptions[index].PatientId
  1617. hpt.Status = 1
  1618. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1619. hpt.Mtime = time.Now().Unix()
  1620. hpt.Ctime = time.Now().Unix()
  1621. hpt.RecordDate = last_prescriptions[index].RecordDate
  1622. hpt.Count = "1"
  1623. hpt.Price = two.RetailPrice
  1624. hpt.ProjectId = two.ID
  1625. hpt.FeedetlSn = ""
  1626. hpt.PrescriptionId = last_prescriptions[index].ID
  1627. hpt.Unit = two.PackingUnit
  1628. hpt.Day = "1"
  1629. hpt.SingleDose = "1"
  1630. hpt.GoodInfo = two
  1631. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1632. }
  1633. //if three.ID > 0 {
  1634. // var hpt models.HisPrescriptionProject
  1635. // hpt.Type = 3
  1636. // hpt.ID = 0
  1637. // hpt.PatientId = last_prescriptions[index].PatientId
  1638. // hpt.Status = 1
  1639. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1640. // hpt.Mtime = time.Now().Unix()
  1641. // hpt.Ctime = time.Now().Unix()
  1642. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1643. // hpt.Count = "1"
  1644. // hpt.Price = three.RetailPrice
  1645. // hpt.ProjectId = three.ID
  1646. // hpt.FeedetlSn = ""
  1647. // hpt.PrescriptionId = last_prescriptions[index].ID
  1648. // hpt.Unit = three.PackingUnit
  1649. // hpt.Day = "1"
  1650. // hpt.SingleDose = "1"
  1651. // hpt.GoodInfo = three
  1652. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1653. //}
  1654. }
  1655. }
  1656. }
  1657. }
  1658. c.ServeSuccessJSON(map[string]interface{}{
  1659. "his_info": his_patient_info,
  1660. "xt_info": xt_patient_info,
  1661. "prescription": prescriptions,
  1662. "case_history": case_history,
  1663. "info": patientPrescriptionInfo,
  1664. //"month_prescriptions": monthPrescriptions,
  1665. "order": order,
  1666. "doctors": doctors,
  1667. "department": department,
  1668. "sch_prescriptions": sch_prescriptions,
  1669. "last_prescriptions": last_prescriptions,
  1670. "schedule": sch,
  1671. "count": count,
  1672. "drugStockConfig": drugStockConfig,
  1673. "last_info": lastPatientPrescriptionInfo,
  1674. "befor": beforThrity,
  1675. "LastCaseHistory": LastCaseHistory,
  1676. "prescriptionInfo": prescriptionInfo,
  1677. })
  1678. return
  1679. }
  1680. func (c *HisApiController) GetHisPrescriptionConfig() {
  1681. adminInfo := c.GetAdminUserInfo()
  1682. //获取医嘱模版
  1683. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1684. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1685. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1686. //获取所有基础药
  1687. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1688. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1689. if config.ID > 0 && config.IsOpen == 1 {
  1690. for _, item := range drugs {
  1691. var index = 0
  1692. for _, subItem := range item.OtherDrugWarehouseInfo {
  1693. if index == 0 {
  1694. index = index + 1
  1695. if subItem.RetailPrice > 0 {
  1696. item.MinPrice = subItem.RetailPrice
  1697. }
  1698. }
  1699. }
  1700. }
  1701. }
  1702. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1703. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1704. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1705. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1706. //获取所有科室信息
  1707. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1708. //获取诊断信息
  1709. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1710. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1711. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1712. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1713. //获取是否开启保存耗材出库的开关
  1714. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1715. c.ServeSuccessJSON(map[string]interface{}{
  1716. "drugs": drugs,
  1717. "advices_template": advices,
  1718. "drugways": drugways,
  1719. "efs": efs,
  1720. "doctors": doctors,
  1721. "department": department,
  1722. "sick": sick,
  1723. "additions": additions,
  1724. "diagnose": diagnose,
  1725. "manufacturers": manufacturers,
  1726. "goodOutOpen": goodOutOpen,
  1727. "patientDiagnose": patientDiagnose,
  1728. })
  1729. }
  1730. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1731. //获取所有基础药
  1732. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1733. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1734. if config.ID > 0 && config.IsOpen == 1 {
  1735. for _, item := range drugs {
  1736. var index = 0
  1737. for _, subItem := range item.OtherDrugWarehouseInfo {
  1738. if index == 0 {
  1739. index = index + 1
  1740. if subItem.RetailPrice > 0 {
  1741. item.MinPrice = subItem.RetailPrice
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1748. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1749. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1750. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1751. //获取所有科室信息
  1752. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1753. //获取诊断信息
  1754. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1755. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1756. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1757. //获取是否开启保存耗材出库的开关
  1758. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1759. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1760. c.ServeSuccessJSON(map[string]interface{}{
  1761. "drugs": drugs,
  1762. "advices_template": advices,
  1763. "drugways": drugways,
  1764. "efs": efs,
  1765. "doctors": doctors,
  1766. "department": department,
  1767. "sick": sick,
  1768. "additions": additions,
  1769. "diagnose": diagnose,
  1770. "manufacturers": manufacturers,
  1771. "goodOutOpen": goodOutOpen,
  1772. "patientDiagnose": patientDiagnose,
  1773. })
  1774. }
  1775. }
  1776. func (c *HisApiController) CreateHisPrescription() {
  1777. record_date := c.GetString("record_date")
  1778. patient_id, _ := c.GetInt64("patient_id")
  1779. reg_type, _ := c.GetInt64("reg_type")
  1780. diagnose := c.GetString("diagnose")
  1781. sick_type, _ := c.GetInt64("sick_type")
  1782. sick_history := c.GetString("sick_history")
  1783. doctor_id, _ := c.GetInt64("doctor", 0)
  1784. department, _ := c.GetInt64("department", 0)
  1785. his_patient_id, _ := c.GetInt64("his_patient_id")
  1786. p_type, _ := c.GetInt64("p_type")
  1787. patient_diagnose := c.GetString("patient_diagnose")
  1788. dataBody := make(map[string]interface{}, 0)
  1789. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1790. if err != nil {
  1791. utils.ErrorLog(err.Error())
  1792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1793. return
  1794. }
  1795. //edit, src := GetCompareData(dataBody)
  1796. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1797. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1798. //fmt.Println(drugResult)
  1799. //fmt.Println(goodResult)
  1800. timeLayout := "2006-01-02"
  1801. loc, _ := time.LoadLocation("Local")
  1802. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1803. if err != nil {
  1804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1805. return
  1806. }
  1807. adminInfo := c.GetAdminUserInfo()
  1808. recordDateTime := theTime.Unix()
  1809. //查询默认出库仓库库存
  1810. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1811. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1812. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1813. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1814. if len(lists) == 1 {
  1815. his_patient_id = lists[0].ID
  1816. }
  1817. }
  1818. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1819. //自动出库的开关开启
  1820. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1821. //自动出库
  1822. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1823. //耗材保存处方出库
  1824. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1825. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1826. //已发药和已收费限制逻辑
  1827. isMidicine := false
  1828. isCharge := false
  1829. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1830. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1831. if len(prescriptions) > 0 {
  1832. for _, item := range prescriptions {
  1833. items := item.(map[string]interface{})
  1834. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1835. utils.ErrorLog("id")
  1836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1837. return
  1838. }
  1839. id := int64(items["id"].(float64))
  1840. if id > 0 {
  1841. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1842. if err != nil {
  1843. if new_prescription.OrderStatus == 4 {
  1844. isCharge = true
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. }
  1851. if isMidicine == true {
  1852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1853. return
  1854. }
  1855. if isCharge == true {
  1856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1857. return
  1858. }
  1859. // 开始主事务
  1860. db := service.XTWriteDB()
  1861. tx := db.Begin()
  1862. // 在函数结束时处理事务回滚
  1863. defer func() {
  1864. if r := recover(); r != nil {
  1865. tx.Rollback()
  1866. }
  1867. }()
  1868. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1869. //药品发药出库
  1870. if pharmacyConfig.IsOpen == 1 {
  1871. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1872. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1873. if len(prescriptions) > 0 {
  1874. for _, item := range prescriptions {
  1875. items := item.(map[string]interface{})
  1876. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1877. advices := items["advices"].([]interface{})
  1878. if len(advices) > 0 {
  1879. for _, advice := range advices {
  1880. var drug_id int64
  1881. var prescribing_number float64
  1882. var prescribingNumberUnit string
  1883. var adviceId int64
  1884. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1885. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1886. }
  1887. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1888. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1889. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1890. }
  1891. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1892. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1893. }
  1894. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1895. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1896. }
  1897. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1898. if drug.ID == 0 {
  1899. tx.Rollback()
  1900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1901. return
  1902. }
  1903. //查询药品的所有库存
  1904. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1905. var total_count int64
  1906. for _, it := range list {
  1907. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1908. }
  1909. totals := strconv.FormatInt(total_count, 10)
  1910. //查询该药品是否存在开药记录
  1911. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1912. //新增处方盘点库存是否充足
  1913. if advicelist.ID == 0 {
  1914. all_count, _ := strconv.ParseFloat(totals, 64)
  1915. if prescribingNumberUnit == drug.MinUnit {
  1916. if drug.IsUse != 1 {
  1917. if drug.IsProject == 0 || drug.IsProject == 2 {
  1918. if all_count == 0 {
  1919. tx.Rollback()
  1920. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1921. return
  1922. }
  1923. if prescribing_number > all_count {
  1924. tx.Rollback()
  1925. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1926. return
  1927. }
  1928. }
  1929. }
  1930. }
  1931. if prescribingNumberUnit == drug.MaxUnit {
  1932. num := prescribing_number * float64(drug.MinNumber)
  1933. if drug.IsUse != 1 {
  1934. if drug.IsProject == 0 || drug.IsProject == 2 {
  1935. if all_count == 0 {
  1936. tx.Rollback()
  1937. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1938. return
  1939. }
  1940. if num > all_count {
  1941. tx.Rollback()
  1942. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1943. return
  1944. }
  1945. }
  1946. }
  1947. }
  1948. }
  1949. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1950. //不使用保存处方出库
  1951. if drugOutConfig.IsOpen != 1 {
  1952. //修改处方
  1953. for _, advice := range advices {
  1954. var drug_id int64
  1955. var prescribing_number float64
  1956. var prescribingNumberUnit string
  1957. var prescribingNumber string
  1958. var adviceId int64
  1959. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1960. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1961. }
  1962. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1963. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1964. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1965. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1966. }
  1967. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1968. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1969. }
  1970. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1971. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1972. }
  1973. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1974. if drug.ID == 0 {
  1975. tx.Rollback()
  1976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1977. return
  1978. }
  1979. //查询药品的所有库存
  1980. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1981. var total_count int64
  1982. for _, it := range list {
  1983. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1984. }
  1985. totals := strconv.FormatInt(total_count, 10)
  1986. //查询该药品是否存在开药记录
  1987. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1988. //新增处方
  1989. if advicelist.ID == 0 {
  1990. all_count, _ := strconv.ParseFloat(totals, 64)
  1991. if prescribingNumberUnit == drug.MinUnit {
  1992. if drug.IsUse != 1 {
  1993. if drug.IsProject == 0 || drug.IsProject == 2 {
  1994. if all_count == 0 {
  1995. tx.Rollback()
  1996. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1997. return
  1998. }
  1999. if prescribing_number > all_count {
  2000. tx.Rollback()
  2001. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2002. return
  2003. }
  2004. }
  2005. }
  2006. } else {
  2007. if prescribingNumberUnit == drug.MaxUnit {
  2008. num := prescribing_number * float64(drug.MinNumber)
  2009. if drug.IsUse != 1 {
  2010. if drug.IsProject == 0 || drug.IsProject == 2 {
  2011. if all_count == 0 {
  2012. tx.Rollback()
  2013. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2014. return
  2015. }
  2016. if num > all_count {
  2017. tx.Rollback()
  2018. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2019. return
  2020. }
  2021. }
  2022. }
  2023. }
  2024. }
  2025. }
  2026. //修改处方
  2027. if advicelist.ID > 0 {
  2028. var device_number int64
  2029. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2030. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2031. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2032. device_number = prescribingNumberInt * drug.MinNumber
  2033. }
  2034. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2035. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2036. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2037. device_number = prescribingNumberInt
  2038. }
  2039. var number_count int64
  2040. if prescribingNumberUnit == drug.MaxUnit {
  2041. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2042. number_count = prescribingNumberInt * drug.MinNumber
  2043. }
  2044. if prescribingNumberUnit == drug.MinUnit {
  2045. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2046. number_count = prescribingNumberInt
  2047. }
  2048. //如果修改的数量大于之前修改的数量
  2049. if (number_count - device_number) > 0 {
  2050. //如果修改的差数量 大于库存数量
  2051. if drug.IsUse != 1 {
  2052. if (number_count - device_number) > total_count {
  2053. tx.Rollback()
  2054. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2055. return
  2056. }
  2057. }
  2058. }
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }
  2069. //已发药和已收费限制逻辑
  2070. //执行出库的逻辑
  2071. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2072. //校验库存总量
  2073. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2074. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2075. if len(prescriptions) > 0 {
  2076. for _, item := range prescriptions {
  2077. items := item.(map[string]interface{})
  2078. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2079. advices := items["advices"].([]interface{})
  2080. if len(advices) > 0 {
  2081. for _, advice := range advices {
  2082. var drug_id int64
  2083. var prescribing_number float64
  2084. var prescribingNumberUnit string
  2085. var adviceId int64
  2086. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2087. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2088. }
  2089. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2090. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2091. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2092. }
  2093. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2094. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2095. }
  2096. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2097. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2098. }
  2099. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2100. if drug.ID == 0 {
  2101. tx.Rollback()
  2102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2103. return
  2104. }
  2105. //查询药品的所有库存
  2106. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2107. var total_count int64
  2108. for _, it := range list {
  2109. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2110. }
  2111. totals := strconv.FormatInt(total_count, 10)
  2112. //查询该药品是否存在开药记录
  2113. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2114. //查询最新批次库存
  2115. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2116. var batch_number_count int64
  2117. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2118. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2119. //新增处方
  2120. if advicelist.ID == 0 {
  2121. all_count, _ := strconv.ParseFloat(totals, 64)
  2122. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2123. if prescribingNumberUnit == drug.MinUnit {
  2124. if drug.IsUse != 1 {
  2125. if drug.IsProject == 0 || drug.IsProject == 2 {
  2126. if all_count == 0 {
  2127. tx.Rollback()
  2128. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2129. return
  2130. }
  2131. if prescribing_number > all_count {
  2132. tx.Rollback()
  2133. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2134. return
  2135. }
  2136. }
  2137. if adminInfo.CurrentOrgId == 10215 {
  2138. if prescribing_number > batch_number_all_count {
  2139. tx.Rollback()
  2140. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2141. return
  2142. }
  2143. }
  2144. }
  2145. }
  2146. if prescribingNumberUnit == drug.MaxUnit {
  2147. num := prescribing_number * float64(drug.MinNumber)
  2148. if drug.IsUse != 1 {
  2149. if drug.IsProject == 0 || drug.IsProject == 2 {
  2150. if all_count == 0 {
  2151. tx.Rollback()
  2152. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2153. return
  2154. }
  2155. if num > all_count {
  2156. tx.Rollback()
  2157. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2158. return
  2159. }
  2160. }
  2161. if adminInfo.CurrentOrgId == 10215 {
  2162. if num > batch_number_all_count {
  2163. tx.Rollback()
  2164. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2165. return
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. //不是保存处方出库
  2172. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2173. if drugOutConfig.IsOpen != 1 {
  2174. //修改处方
  2175. for _, advice := range advices {
  2176. var drug_id int64
  2177. var prescribing_number float64
  2178. var prescribingNumberUnit string
  2179. var prescribingNumber string
  2180. var adviceId int64
  2181. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2182. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2183. }
  2184. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2185. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2186. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2187. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2188. }
  2189. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2190. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2191. }
  2192. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2193. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2194. }
  2195. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2196. if drug.ID == 0 {
  2197. tx.Rollback()
  2198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2199. return
  2200. }
  2201. //查询药品的所有库存
  2202. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2203. var total_count int64
  2204. for _, it := range list {
  2205. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2206. }
  2207. totals := strconv.FormatInt(total_count, 10)
  2208. //查询该药品是否存在开药记录
  2209. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2210. //新增处方
  2211. if advicelist.ID == 0 {
  2212. //查询最新批次库存
  2213. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2214. var batch_number_count int64
  2215. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2216. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2217. all_count, _ := strconv.ParseFloat(totals, 64)
  2218. if all_count == 0 {
  2219. tx.Rollback()
  2220. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2221. return
  2222. }
  2223. if prescribingNumberUnit == drug.MinUnit {
  2224. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2225. if drug.IsUse != 1 {
  2226. if drug.IsProject == 0 || drug.IsProject == 2 {
  2227. if all_count == 0 {
  2228. tx.Rollback()
  2229. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2230. return
  2231. }
  2232. if prescribing_number > all_count {
  2233. tx.Rollback()
  2234. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2235. return
  2236. }
  2237. }
  2238. if adminInfo.CurrentOrgId == 10215 {
  2239. if prescribing_number > batch_number_all_count {
  2240. tx.Rollback()
  2241. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2242. return
  2243. }
  2244. }
  2245. }
  2246. } else {
  2247. if prescribingNumberUnit == drug.MaxUnit {
  2248. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2249. num := prescribing_number * float64(drug.MinNumber)
  2250. if drug.IsUse != 1 {
  2251. if drug.IsProject == 0 || drug.IsProject == 2 {
  2252. if all_count == 0 {
  2253. tx.Rollback()
  2254. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2255. return
  2256. }
  2257. if num > all_count {
  2258. tx.Rollback()
  2259. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2260. return
  2261. }
  2262. }
  2263. if adminInfo.CurrentOrgId == 10215 {
  2264. if prescribing_number > batch_number_all_count {
  2265. tx.Rollback()
  2266. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2267. return
  2268. }
  2269. }
  2270. }
  2271. }
  2272. }
  2273. }
  2274. //修改处方
  2275. if advicelist.ID > 0 {
  2276. //查询最新批次库存
  2277. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2278. var batch_number_count int64
  2279. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2280. var device_number int64
  2281. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2282. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2283. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2284. device_number = prescribingNumberInt * drug.MinNumber
  2285. }
  2286. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2287. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2288. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2289. device_number = prescribingNumberInt
  2290. //回退库存
  2291. }
  2292. var number_count int64
  2293. if prescribingNumberUnit == drug.MaxUnit {
  2294. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2295. number_count = prescribingNumberInt * drug.MinNumber
  2296. //回退库存
  2297. }
  2298. if prescribingNumberUnit == drug.MinUnit {
  2299. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2300. number_count = prescribingNumberInt
  2301. //回退库存
  2302. }
  2303. //如果修改的数量大于之前修改的数量
  2304. if (number_count - device_number) > 0 {
  2305. //如果修改的差数量 大于库存数量
  2306. if drug.IsUse != 1 {
  2307. if drug.IsProject == 0 || drug.IsProject == 2 {
  2308. if total_count == 0 {
  2309. tx.Rollback()
  2310. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2311. return
  2312. }
  2313. if (number_count - device_number) > total_count {
  2314. tx.Rollback()
  2315. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2316. return
  2317. }
  2318. if (number_count - device_number) > batch_number_count {
  2319. tx.Rollback()
  2320. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2321. return
  2322. }
  2323. }
  2324. if adminInfo.CurrentOrgId == 10215 {
  2325. // 查询该药品最后一次出库记录
  2326. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2327. var out_count int64
  2328. var in_count int64
  2329. var stock_max_number int64
  2330. var stock_min_number int64
  2331. for _, it := range outInfo {
  2332. if it.CountUnit == drug.MaxUnit {
  2333. it.Count = it.Count * drug.MinNumber
  2334. }
  2335. out_count += it.Count
  2336. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2337. stock_max_number = warehouseInfoList.StockMaxNumber
  2338. stock_min_number = warehouseInfoList.StockMinNumber
  2339. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2340. }
  2341. if out_count > 0 {
  2342. if (number_count - device_number) > in_count {
  2343. tx.Rollback()
  2344. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2345. return
  2346. }
  2347. }
  2348. // 未出库
  2349. if out_count == 0 {
  2350. var sum_in_count int64
  2351. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2352. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2353. //如果修改的数量大于有库存的第一个批次
  2354. if number_count > sum_in_count {
  2355. tx.Rollback()
  2356. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2357. return
  2358. }
  2359. }
  2360. }
  2361. }
  2362. }
  2363. //药品发药
  2364. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2365. //不使用药品发药的功能
  2366. //if pharmacyConfig.IsOpen != 1 {
  2367. // if device_number != number_count {
  2368. //
  2369. // //查询该药品的出库记录
  2370. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2371. // if len(outListExport) > 0 {
  2372. // //
  2373. // for _, item := range outListExport {
  2374. // //回退库存
  2375. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2376. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2377. // }
  2378. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2379. // var stock_max_number int64
  2380. // var stock_min_number int64
  2381. //
  2382. // if number_count >= drug.MinNumber {
  2383. //
  2384. // stock_max_number = device_number / drug.MinNumber
  2385. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2386. //
  2387. // stock_min_number = device_number % drug.MinNumber
  2388. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2389. //
  2390. // } else {
  2391. //
  2392. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2393. //
  2394. // }
  2395. // }
  2396. //
  2397. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2398. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2399. // }
  2400. // }
  2401. // }
  2402. //
  2403. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2404. // var sum_count int64
  2405. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2406. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2407. // for _, its := range stockInfo {
  2408. // if its.MaxUnit == drug.MaxUnit {
  2409. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2410. // }
  2411. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2412. // }
  2413. // //更新字典里面的库存
  2414. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2415. //
  2416. // //剩余库存
  2417. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2418. //
  2419. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2420. // //减少出库数量
  2421. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2422. //
  2423. // }
  2424. //}
  2425. }
  2426. }
  2427. }
  2428. //保存处方开药
  2429. if drugOutConfig.IsOpen == 1 {
  2430. //修改处方
  2431. for _, advice := range advices {
  2432. var drug_id int64
  2433. var prescribing_number float64
  2434. var prescribingNumberUnit string
  2435. var prescribingNumber string
  2436. var adviceId int64
  2437. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2438. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2439. }
  2440. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2441. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2442. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2443. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2444. }
  2445. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2446. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2447. }
  2448. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2449. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2450. }
  2451. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2452. if drug.ID == 0 {
  2453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2454. return
  2455. }
  2456. //查询药品的所有库存
  2457. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2458. var total_count int64
  2459. for _, it := range list {
  2460. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2461. }
  2462. totals := strconv.FormatInt(total_count, 10)
  2463. //查询该药品是否存在开药记录
  2464. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2465. //新增处方
  2466. if advicelist.ID == 0 {
  2467. //查询最新批次库存
  2468. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2469. var batch_number_count int64
  2470. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2471. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2472. all_count, _ := strconv.ParseFloat(totals, 64)
  2473. if prescribingNumberUnit == drug.MinUnit {
  2474. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2475. if drug.IsUse != 1 {
  2476. if drug.IsProject == 0 || drug.IsProject == 2 {
  2477. if all_count == 0 {
  2478. tx.Rollback()
  2479. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2480. return
  2481. }
  2482. if prescribing_number > all_count {
  2483. tx.Rollback()
  2484. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2485. return
  2486. }
  2487. }
  2488. if adminInfo.CurrentOrgId == 10215 {
  2489. if prescribing_number > batch_number_all_count {
  2490. tx.Rollback()
  2491. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2492. return
  2493. }
  2494. }
  2495. }
  2496. } else {
  2497. if prescribingNumberUnit == drug.MaxUnit {
  2498. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2499. num := prescribing_number * float64(drug.MinNumber)
  2500. if drug.IsUse != 1 {
  2501. if drug.IsProject == 0 || drug.IsProject == 2 {
  2502. if all_count == 0 {
  2503. tx.Rollback()
  2504. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2505. return
  2506. }
  2507. if num > all_count {
  2508. tx.Rollback()
  2509. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2510. return
  2511. }
  2512. }
  2513. if adminInfo.CurrentOrgId == 10215 {
  2514. if prescribing_number > batch_number_all_count {
  2515. tx.Rollback()
  2516. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2517. return
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. }
  2524. //修改处方
  2525. if advicelist.ID > 0 {
  2526. //查询最新批次库存
  2527. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2528. var batch_number_count int64
  2529. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2530. var device_number int64
  2531. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2532. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2533. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2534. device_number = prescribingNumberInt * drug.MinNumber
  2535. }
  2536. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2537. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2538. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2539. device_number = prescribingNumberInt
  2540. }
  2541. var number_count int64
  2542. if prescribingNumberUnit == drug.MaxUnit {
  2543. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2544. number_count = prescribingNumberInt * drug.MinNumber
  2545. }
  2546. if prescribingNumberUnit == drug.MinUnit {
  2547. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2548. number_count = prescribingNumberInt
  2549. }
  2550. //如果修改的数量大于之前修改的数量
  2551. if (number_count - device_number) > 0 {
  2552. //如果修改的差数量 大于库存数量
  2553. if drug.IsUse != 1 {
  2554. if drug.IsProject == 0 || drug.IsProject == 2 {
  2555. if total_count == 0 {
  2556. tx.Rollback()
  2557. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2558. return
  2559. }
  2560. if (number_count - device_number) > total_count {
  2561. tx.Rollback()
  2562. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2563. return
  2564. }
  2565. }
  2566. if adminInfo.CurrentOrgId == 10215 {
  2567. if (number_count - device_number) > batch_number_count {
  2568. tx.Rollback()
  2569. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2570. return
  2571. }
  2572. }
  2573. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2574. //查询历史出库数据总批次
  2575. // 查询该药品最后一次出库记录
  2576. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2577. var out_count int64
  2578. var in_count int64
  2579. var stock_max_number int64
  2580. var stock_min_number int64
  2581. for _, it := range outInfo {
  2582. if it.CountUnit == drug.MaxUnit {
  2583. it.Count = it.Count * drug.MinNumber
  2584. }
  2585. out_count += it.Count
  2586. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2587. stock_max_number = warehouseInfoList.StockMaxNumber
  2588. stock_min_number = warehouseInfoList.StockMinNumber
  2589. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2590. }
  2591. if out_count > 0 {
  2592. if (number_count - device_number) > in_count {
  2593. tx.Rollback()
  2594. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2595. return
  2596. }
  2597. }
  2598. // 未出库
  2599. if out_count == 0 {
  2600. var sum_in_count int64
  2601. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2602. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2603. if sum_in_count == 0 {
  2604. tx.Rollback()
  2605. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2606. return
  2607. }
  2608. //如果修改的数量大于有库存的第一个批次
  2609. if number_count > sum_in_count {
  2610. tx.Rollback()
  2611. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2612. return
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. }
  2619. }
  2620. }
  2621. }
  2622. }
  2623. }
  2624. }
  2625. }
  2626. }
  2627. }
  2628. //校验耗材库存
  2629. if goodOutConfig.IsOpen == 1 {
  2630. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2631. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2632. if len(prescriptions) > 0 {
  2633. for _, item := range prescriptions {
  2634. items := item.(map[string]interface{})
  2635. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2636. projects := items["project"].([]interface{})
  2637. if len(projects) > 0 {
  2638. for _, project := range projects {
  2639. var project_id int64
  2640. var project_type int64
  2641. var totals float64
  2642. var project_name string
  2643. var parsetotal int64
  2644. var id int64
  2645. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2646. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2647. }
  2648. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2649. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2650. }
  2651. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2652. total, _ := project.(map[string]interface{})["total"].(string)
  2653. totals, _ = strconv.ParseFloat(total, 64)
  2654. }
  2655. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2656. project_name = project.(map[string]interface{})["project_name"].(string)
  2657. }
  2658. if project_type == 3 {
  2659. //查找该耗材的出库记录
  2660. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2661. if len(goodWarehouseInfo) == 0 {
  2662. //查询耗材库存
  2663. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2664. var stock_count int64
  2665. for _, it := range list {
  2666. stock_count += it.StockCount
  2667. }
  2668. stock_counts := strconv.FormatInt(stock_count, 10)
  2669. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2670. if stock_total_count == 0 {
  2671. tx.Rollback()
  2672. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2673. return
  2674. }
  2675. if totals > stock_total_count {
  2676. tx.Rollback()
  2677. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2678. return
  2679. }
  2680. }
  2681. if len(goodWarehouseInfo) > 0 {
  2682. //查询该患者耗材的历史数据
  2683. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2684. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2685. //数量发生改变
  2686. if parsetotal != count {
  2687. //如果现在的数量大于历史数量,就要看库存是否足够
  2688. if parsetotal > count {
  2689. //查询耗材所有库存
  2690. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2691. var stock_count int64
  2692. for _, it := range list {
  2693. stock_count += it.StockCount
  2694. }
  2695. //库存不足
  2696. if stock_count == 0 {
  2697. tx.Rollback()
  2698. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2699. return
  2700. }
  2701. if (parsetotal - count) > stock_count {
  2702. tx.Rollback()
  2703. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2704. return
  2705. }
  2706. }
  2707. }
  2708. }
  2709. }
  2710. }
  2711. }
  2712. }
  2713. }
  2714. }
  2715. }
  2716. }
  2717. //不使用耗材保存处方出库
  2718. if goodOutConfig.IsOpen != 1 {
  2719. if stockConfig.IsOpen == 1 {
  2720. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2721. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2722. if len(prescriptions) > 0 {
  2723. for _, item := range prescriptions {
  2724. items := item.(map[string]interface{})
  2725. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2726. projects := items["project"].([]interface{})
  2727. if len(projects) > 0 {
  2728. for _, project := range projects {
  2729. var project_id int64
  2730. var project_type int64
  2731. var totals float64
  2732. var project_name string
  2733. var parsetotal int64
  2734. var id int64
  2735. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2736. id = int64(project.(map[string]interface{})["id"].(float64))
  2737. }
  2738. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2739. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2740. }
  2741. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2742. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2743. }
  2744. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2745. total, _ := project.(map[string]interface{})["total"].(string)
  2746. totals, _ = strconv.ParseFloat(total, 64)
  2747. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2748. }
  2749. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2750. project_name = project.(map[string]interface{})["project_name"].(string)
  2751. }
  2752. if project_type == 3 {
  2753. //查找该耗材的出库记录
  2754. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2755. //没有出库记录
  2756. if len(goodWarehouseInfo) == 0 {
  2757. //查询耗材库存
  2758. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2759. var stock_count int64
  2760. for _, it := range list {
  2761. stock_count += it.StockCount
  2762. }
  2763. stock_counts := strconv.FormatInt(stock_count, 10)
  2764. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2765. if stock_total_count == 0 {
  2766. tx.Rollback()
  2767. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2768. return
  2769. }
  2770. if totals > stock_total_count {
  2771. tx.Rollback()
  2772. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2773. return
  2774. }
  2775. //查找今日该患者已经出库的所有耗材
  2776. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2777. for _, item := range goodList {
  2778. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2779. var flush_count int64
  2780. for _, it := range goodListSix {
  2781. flush_count += it.StockCount
  2782. }
  2783. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2784. creater := adminInfo.AdminUser.Id
  2785. if errs != nil {
  2786. goodErrcode := models.XtGoodErrcode{
  2787. UserOrgId: item.OrgId,
  2788. Errcode: "手动出库更新剩余出库失败",
  2789. GoodId: item.GoodId,
  2790. Status: 1,
  2791. Ctime: time.Now().Unix(),
  2792. Mtime: 0,
  2793. Count: 0,
  2794. StockCount: 0,
  2795. Creater: creater,
  2796. BatchNumberId: 0,
  2797. WarehouseOutId: 0,
  2798. }
  2799. service.CreateGoodErrcode(goodErrcode)
  2800. }
  2801. }
  2802. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2803. }
  2804. //有出库记录
  2805. if len(goodWarehouseInfo) > 0 {
  2806. //查询该患者耗材的历史数据
  2807. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2808. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2809. //数量发生改变
  2810. if parsetotal != count {
  2811. //查找今日该患者已经出库的所有耗材
  2812. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2813. for _, item := range goodList {
  2814. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2815. var flush_count int64
  2816. for _, it := range goodListSix {
  2817. flush_count += it.StockCount
  2818. }
  2819. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2820. //减少出库数量
  2821. creater := adminInfo.AdminUser.Id
  2822. if errs != nil {
  2823. goodErrcode := models.XtGoodErrcode{
  2824. UserOrgId: item.OrgId,
  2825. Errcode: "手动出库更新剩余出库失败",
  2826. GoodId: item.GoodId,
  2827. Status: 1,
  2828. Ctime: time.Now().Unix(),
  2829. Mtime: 0,
  2830. Count: 0,
  2831. StockCount: 0,
  2832. Creater: creater,
  2833. BatchNumberId: 0,
  2834. WarehouseOutId: 0,
  2835. }
  2836. service.CreateGoodErrcode(goodErrcode)
  2837. }
  2838. //查询默认仓库
  2839. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2840. var total_count int64
  2841. for _, it := range stockList {
  2842. total_count += it.StockCount
  2843. }
  2844. //基础库插入数据
  2845. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2846. }
  2847. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2848. }
  2849. }
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. }
  2857. }
  2858. }
  2859. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2860. var hpInfo models.HisPrescriptionInfo
  2861. if info.ID == 0 {
  2862. var randNum int
  2863. randNum = rand.Intn(10000) + 1000
  2864. timestamp := time.Now().Unix()
  2865. tempTime := time.Unix(timestamp, 0)
  2866. timeFormat := tempTime.Format("20060102150405")
  2867. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2868. hpInfo = models.HisPrescriptionInfo{
  2869. HisPatientId: his_patient_id,
  2870. UserOrgId: adminInfo.CurrentOrgId,
  2871. RecordDate: theTime.Unix(),
  2872. PatientId: patient_id,
  2873. Status: 1,
  2874. Ctime: time.Now().Unix(),
  2875. Mtime: time.Now().Unix(),
  2876. Creator: adminInfo.AdminUser.Id,
  2877. Modifier: adminInfo.AdminUser.Id,
  2878. Diagnosis: diagnose,
  2879. SickHistory: sick_history,
  2880. Departments: department,
  2881. RegisterType: reg_type,
  2882. PrescriptionNumber: p_number,
  2883. PrescriptionStatus: 1,
  2884. Doctor: role.UserName,
  2885. DoctorId: doctor_id,
  2886. SickType: sick_type,
  2887. PType: p_type,
  2888. PatientDiagnosis: patient_diagnose,
  2889. }
  2890. service.SavePatientPrescriptionInfo(hpInfo)
  2891. //创建步骤表
  2892. finish := models.XtDialysisFinish{
  2893. IsFinish: 1,
  2894. UserOrgId: adminInfo.CurrentOrgId,
  2895. Status: 1,
  2896. Ctime: time.Now().Unix(),
  2897. Mtime: 0,
  2898. Module: 4,
  2899. RecordDate: theTime.Unix(),
  2900. Sourse: 1,
  2901. PatientId: patient_id,
  2902. }
  2903. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2904. if dialysisFinish.ID == 0 {
  2905. service.CreateDialysisFinish(finish)
  2906. }
  2907. redis := service.RedisClient()
  2908. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2909. redis.Set(key, "", time.Second)
  2910. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2911. redis.Set(keyOne, "", time.Second)
  2912. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2913. redis.Set(keySeven, "", time.Second)
  2914. defer redis.Close()
  2915. } else {
  2916. hpInfo = models.HisPrescriptionInfo{
  2917. ID: info.ID,
  2918. UserOrgId: adminInfo.CurrentOrgId,
  2919. RecordDate: info.RecordDate,
  2920. PatientId: info.PatientId,
  2921. Status: 1,
  2922. Ctime: info.Ctime,
  2923. Mtime: time.Now().Unix(),
  2924. Creator: info.Creator,
  2925. Modifier: adminInfo.AdminUser.Id,
  2926. Diagnosis: diagnose,
  2927. SickHistory: sick_history,
  2928. Departments: department,
  2929. RegisterType: reg_type,
  2930. PrescriptionNumber: info.PrescriptionNumber,
  2931. Doctor: role.UserName,
  2932. PrescriptionStatus: info.PrescriptionStatus,
  2933. DoctorId: doctor_id,
  2934. SickType: sick_type,
  2935. PType: info.PType,
  2936. HisPatientId: info.HisPatientId,
  2937. PatientDiagnosis: patient_diagnose,
  2938. }
  2939. service.SavePatientPrescriptionInfo(hpInfo)
  2940. //创建步骤表
  2941. finish := models.XtDialysisFinish{
  2942. IsFinish: 1,
  2943. UserOrgId: adminInfo.CurrentOrgId,
  2944. Status: 1,
  2945. Ctime: time.Now().Unix(),
  2946. Mtime: 0,
  2947. Module: 4,
  2948. RecordDate: info.RecordDate,
  2949. Sourse: 1,
  2950. PatientId: info.PatientId,
  2951. }
  2952. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2953. if dialysisFinish.ID == 0 {
  2954. service.CreateDialysisFinish(finish)
  2955. }
  2956. redis := service.RedisClient()
  2957. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2958. redis.Set(key, "", time.Second)
  2959. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2960. redis.Set(keyOne, "", time.Second)
  2961. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2962. redis.Set(keySeven, "", time.Second)
  2963. defer redis.Close()
  2964. }
  2965. //定义切片
  2966. var adviceList []models.HisDoctorAdviceInfo
  2967. var projectList []models.HisPrescriptionProject
  2968. 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 {
  2969. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2970. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2971. var tempPrescription *models.HisPrescription
  2972. if len(prescriptions) > 0 {
  2973. for _, item := range prescriptions {
  2974. // 开始外部循环的事务
  2975. tx := db.Begin()
  2976. // 在函数结束时处理事务回滚
  2977. defer func() {
  2978. if r := recover(); r != nil {
  2979. tx.Rollback()
  2980. }
  2981. }()
  2982. items := item.(map[string]interface{})
  2983. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2984. utils.ErrorLog("id")
  2985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2986. return
  2987. }
  2988. id := int64(items["id"].(float64))
  2989. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2990. tempPrescription = &new_prescription
  2991. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2992. utils.ErrorLog("type")
  2993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2994. return
  2995. }
  2996. types := int64(items["type"].(float64))
  2997. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2998. utils.ErrorLog("med_type")
  2999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3000. return
  3001. }
  3002. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3003. if med_type == "0" {
  3004. med_type = "14"
  3005. }
  3006. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3007. // utils.ErrorLog("diagnoses")
  3008. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3009. // return
  3010. //}
  3011. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3012. diagnoses, _ := items["diagnoses"].(string)
  3013. //if order_status == 0 {
  3014. // order_status = 1
  3015. //}
  3016. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3017. utils.ErrorLog("pre_time")
  3018. }
  3019. preTime, _ := items["pre_time"].(string)
  3020. fmt.Println("preTime", preTime)
  3021. timeLayout := "2006-01-02"
  3022. loc, _ := time.LoadLocation("Local")
  3023. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3024. //result := strings.Split(preTime, " ")
  3025. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3026. if err != nil {
  3027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3028. return
  3029. }
  3030. pTime := theTime2.Unix()
  3031. ctime := time.Now().Unix()
  3032. if tempPrescription.ID == 0 {
  3033. prescription := &models.HisPrescription{
  3034. ID: 0,
  3035. PatientId: patient_id,
  3036. UserOrgId: adminInfo.CurrentOrgId,
  3037. RecordDate: recordDateTime,
  3038. Ctime: ctime,
  3039. Mtime: ctime,
  3040. Type: types,
  3041. Modifier: adminInfo.AdminUser.Id,
  3042. Creator: adminInfo.AdminUser.Id,
  3043. Status: 1,
  3044. Doctor: role.UserName,
  3045. HisPatientId: his_patient_id,
  3046. OrderStatus: 1,
  3047. BatchNumber: "",
  3048. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3049. PreTime: pTime,
  3050. PType: p_type,
  3051. MedType: med_type,
  3052. Diagnose: diagnoses,
  3053. }
  3054. tempPrescription = prescription
  3055. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3056. redis := service.RedisClient()
  3057. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3058. redis.Set(key, "", time.Second)
  3059. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3060. redis.Set(keyOne, "", time.Second)
  3061. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3062. redis.Set(keySeven, "", time.Second)
  3063. defer redis.Close()
  3064. } else {
  3065. tempPrescription.ID = id
  3066. tempPrescription.Type = types
  3067. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3068. tempPrescription.Mtime = time.Now().Unix()
  3069. tempPrescription.Doctor = role.UserName
  3070. //tempPrescription.OrderStatus = order_status
  3071. tempPrescription.PreTime = pTime
  3072. tempPrescription.MedType = med_type
  3073. tempPrescription.Diagnose = diagnoses
  3074. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3075. redis := service.RedisClient()
  3076. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3077. redis.Set(key, "", time.Second)
  3078. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3079. redis.Set(keyOne, "", time.Second)
  3080. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3081. redis.Set(keySeven, "", time.Second)
  3082. defer redis.Close()
  3083. }
  3084. //service.SaveHisPrescription(prescription)
  3085. //更改患者挂号状态
  3086. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3087. fmt.Println("更改失败", err2)
  3088. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3089. advices := items["advices"].([]interface{})
  3090. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3091. groupNo := int64(0)
  3092. if len(advices) > 0 {
  3093. for _, advice := range advices {
  3094. tx := db.Begin()
  3095. // 在函数结束时处理事务回滚
  3096. defer func() {
  3097. if r := recover(); r != nil {
  3098. tx.Rollback()
  3099. }
  3100. }()
  3101. var s models.HisDoctorAdviceInfo
  3102. s.PrescriptionId = tempPrescription.ID
  3103. s.AdviceType = 2
  3104. s.AdviceDoctor = doctor_id
  3105. s.StopState = 2
  3106. s.ExecutionState = 2
  3107. s.AdviceDate = theTime3.Unix()
  3108. s.Status = 1
  3109. s.UserOrgId = adminInfo.CurrentOrgId
  3110. s.RecordDate = theTime3.Unix()
  3111. s.StartTime = tempPrescription.PreTime
  3112. s.Groupno = groupNo
  3113. s.PatientId = patient_id
  3114. s.HisPatientId = his_patient_id
  3115. s.StartTime = pTime
  3116. s.IsSettle = 2
  3117. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3118. if errcode > 0 {
  3119. c.ServeFailJSONWithSGJErrorCode(errcode)
  3120. return
  3121. }
  3122. s.StartTime = pTime
  3123. var total_count int64 //处方总库存
  3124. //查询改药品信息
  3125. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3126. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3127. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3128. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3129. total_count += prescribingNumberSeven * medical.MinNumber
  3130. }
  3131. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3132. total_count += prescribingNumberSeven
  3133. }
  3134. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3135. total_count += prescribingNumberSeven
  3136. }
  3137. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3138. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3139. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3140. if s.Price != lastWarehouse.RetailPrice {
  3141. s.Price = lastWarehouse.RetailPrice
  3142. }
  3143. if s.Price == 0 {
  3144. if lastWarehouse.ID == 0 {
  3145. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3146. s.Price = lastWarehouseTwo.RetailPrice
  3147. }
  3148. }
  3149. }
  3150. //查询保存处方出库开关是否打开
  3151. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3152. if s.PatientId != 30038 {
  3153. if drugOutConfig.IsOpen == 1 {
  3154. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3155. // 查询该药品最后一次出库记录
  3156. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3157. var is_user_total int64
  3158. var no_user_total int64
  3159. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3160. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3161. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3162. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3163. }
  3164. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3165. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3166. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3167. no_user_total += prescribingNumberSevenTy
  3168. }
  3169. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3170. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3171. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3172. no_user_total += prescribingNumberSevenTy
  3173. }
  3174. if len(druginfo) > 0 {
  3175. for _, it := range druginfo {
  3176. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3177. it.Count = it.Count * drug.MinNumber
  3178. is_user_total += it.Count
  3179. }
  3180. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3181. is_user_total += it.Count
  3182. }
  3183. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3184. is_user_total += it.Count
  3185. }
  3186. }
  3187. }
  3188. //fmt.Println("药品名称----------------------", drug.DrugName)
  3189. //fmt.Println("药品名称----------------------", drug.IsUse)
  3190. //fmt.Println("is_user_total-------------------------", is_user_total)
  3191. //fmt.Println("no_user_total-------------------------", no_user_total)
  3192. if is_user_total != no_user_total {
  3193. //出库
  3194. if drug.IsUse == 2 {
  3195. creater := adminInfo.AdminUser.Id
  3196. newadviceInfo := &models.HisDoctorAdviceInfo{
  3197. ID: s.ID,
  3198. UserOrgId: s.UserOrgId,
  3199. PatientId: s.PatientId,
  3200. HisPatientId: s.HisPatientId,
  3201. AdviceType: s.AdviceType,
  3202. AdviceDate: s.AdviceDate,
  3203. StartTime: s.StartTime,
  3204. AdviceName: s.AdviceName,
  3205. AdviceDesc: s.AdviceDesc,
  3206. ReminderDate: s.ReminderDate,
  3207. SingleDose: s.SingleDose,
  3208. SingleDoseUnit: s.SingleDoseUnit,
  3209. PrescribingNumber: s.PrescribingNumber,
  3210. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3211. DeliveryWay: s.DeliveryWay,
  3212. ExecutionFrequency: s.ExecutionFrequency,
  3213. AdviceDoctor: s.AdviceDoctor,
  3214. Status: s.Status,
  3215. CreatedTime: s.CreatedTime,
  3216. UpdatedTime: s.UpdatedTime,
  3217. AdviceAffirm: s.AdviceAffirm,
  3218. Remark: s.Remark,
  3219. StopTime: s.StopTime,
  3220. StopReason: s.StopReason,
  3221. StopDoctor: s.StopDoctor,
  3222. StopState: s.StopState,
  3223. ParentId: s.ParentId,
  3224. ExecutionTime: s.ExecutionTime,
  3225. ExecutionStaff: s.ExecutionStaff,
  3226. ExecutionState: s.ExecutionState,
  3227. Checker: s.Checker,
  3228. RecordDate: s.RecordDate,
  3229. DialysisOrderId: s.DialysisOrderId,
  3230. CheckTime: s.CheckTime,
  3231. CheckState: s.CheckState,
  3232. DrugSpec: s.DrugSpec,
  3233. DrugSpecUnit: s.DrugSpecUnit,
  3234. Groupno: s.Groupno,
  3235. RemindType: s.RemindType,
  3236. FrequencyType: s.FrequencyType,
  3237. DayCount: s.DayCount,
  3238. WeekDay: s.WeekDay,
  3239. TemplateId: s.TemplateId,
  3240. Modifier: s.Modifier,
  3241. DrugId: s.DrugId,
  3242. Price: s.Price,
  3243. PrescriptionId: s.PrescriptionId,
  3244. MedListCodg: s.MedListCodg,
  3245. FeedetlSn: s.FeedetlSn,
  3246. Day: s.DayCount,
  3247. ChildDoctorAdvice: nil,
  3248. Drug: models.Drug{},
  3249. Diagnosis: s.Diagnosis,
  3250. Way: s.Way,
  3251. HospApprFlag: s.HospApprFlag,
  3252. LmtUsedFlag: s.LmtUsedFlag,
  3253. HisOrderInfo: models.HisOrderInfo{},
  3254. IsMedicine: s.IsMedicine,
  3255. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3256. Child: nil,
  3257. IsSettle: s.IsSettle,
  3258. IsMobile: s.IsMobile,
  3259. IsSelfDrug: s.IsSelfDrug,
  3260. DrugWayCount: s.DrugWayCount,
  3261. }
  3262. var history_count int64
  3263. var local_count int64
  3264. //查找已经开过的医嘱信息
  3265. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3266. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3267. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3268. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3269. local_count += prescribingNumberSevenTy * drug.MinNumber
  3270. }
  3271. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3272. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3273. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3274. local_count += prescribingNumberSevenTy
  3275. }
  3276. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3277. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3278. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3279. local_count += prescribingNumberSevenTy
  3280. }
  3281. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3282. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3283. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3284. history_count += prescribingNumberSevenTy * drug.MinNumber
  3285. }
  3286. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3287. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3288. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3289. history_count += prescribingNumberSevenTy
  3290. }
  3291. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3292. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3293. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3294. history_count += prescribingNumberSevenTy
  3295. }
  3296. //如果当前出库数量大于历史出库数量则需要出库
  3297. if local_count > history_count {
  3298. //按最小单位出库
  3299. var cha_count = local_count - history_count
  3300. newadviceInfo.PrescribingNumber = float64(cha_count)
  3301. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3302. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3303. }
  3304. //如果当前出库数量小于历史出库数量则需要退库
  3305. if local_count < history_count {
  3306. var cha_count = history_count - local_count
  3307. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3308. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3309. }
  3310. if local_count == history_count {
  3311. if is_user_total == 0 {
  3312. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3313. }
  3314. }
  3315. }
  3316. //更新字典里面的库存
  3317. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3318. var sum_count int64
  3319. for _, its := range stockInfo {
  3320. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3321. if its.MaxUnit == baseDrug.MaxUnit {
  3322. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3323. }
  3324. sum_count += its.StockMaxNumber + its.StockMinNumber
  3325. }
  3326. //更新基础库存
  3327. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3328. //剩余库存
  3329. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3330. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3331. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3332. //创建医嘱
  3333. service.CreateHisDoctorAdviceOne(&s, tx)
  3334. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3335. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3336. if len(outInfoTwo) > 0 {
  3337. for _, item := range outInfoTwo {
  3338. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3339. }
  3340. }
  3341. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3342. if len(drugAutoDetail) > 0 {
  3343. for _, item := range drugAutoDetail {
  3344. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3345. }
  3346. }
  3347. }
  3348. }
  3349. }
  3350. //记录日志
  3351. byterequest, _ := json.Marshal(s)
  3352. adviceLog := models.XtDoctorAdviceLog{
  3353. UserOrgId: s.UserOrgId,
  3354. PatientId: s.PatientId,
  3355. AdminUserId: adminInfo.AdminUser.Id,
  3356. Module: 1,
  3357. ErrLog: string(byterequest),
  3358. Status: 1,
  3359. Ctime: time.Now().Unix(),
  3360. Mtime: 0,
  3361. Source: "电脑端新建his医嘱",
  3362. RecordDate: s.AdviceDate,
  3363. }
  3364. service.CreateDoctorAdviceLog(adviceLog)
  3365. //存储切片中
  3366. adviceList = append(adviceList, s)
  3367. redis := service.RedisClient()
  3368. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3369. redis.Set(key, "", time.Second)
  3370. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3371. redis.Set(keyOne, "", time.Second)
  3372. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3373. redis.Set(keySeven, "", time.Second)
  3374. var randNum int
  3375. randNum = rand.Intn(10000) + 1000
  3376. timestamp := time.Now().Unix()
  3377. tempTime := time.Unix(timestamp, 0)
  3378. timeFormat := tempTime.Format("20060102150405")
  3379. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3380. if s.UserOrgId != 10206 {
  3381. if s.ID == 0 {
  3382. //查询改药品是否已经停用
  3383. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3384. if base.ID > 0 {
  3385. tx.Rollback()
  3386. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3387. return
  3388. }
  3389. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3390. if drugMedical.SumCount == 0 {
  3391. tx.Rollback()
  3392. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3393. return
  3394. }
  3395. }
  3396. if s.ID > 0 {
  3397. //查询改药品是否已经停用
  3398. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3399. if base.ID > 0 {
  3400. tx.Rollback()
  3401. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3402. return
  3403. }
  3404. }
  3405. }
  3406. //赤峰
  3407. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3408. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3409. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3410. if info.RetailPrice > 0 {
  3411. if s.DeliveryWay == "口服" {
  3412. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3413. s.Price = drug.RetailPrice
  3414. }
  3415. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3416. s.Price = info.RetailPrice
  3417. }
  3418. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3419. s.Price = info.RetailPrice
  3420. }
  3421. }
  3422. }
  3423. }
  3424. service.CreateHisDoctorAdviceOne(&s, tx)
  3425. tx.Commit()
  3426. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3427. redis.Set(keySix, "", time.Second)
  3428. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3429. redis.Set(keyFive, "", time.Second)
  3430. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3431. redis.Set(keyEight, "", time.Second)
  3432. defer redis.Close()
  3433. }
  3434. }
  3435. }
  3436. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3437. projects := items["project"].([]interface{})
  3438. if len(projects) > 0 {
  3439. for _, project := range projects {
  3440. tx := db.Begin()
  3441. // 在函数结束时处理事务回滚
  3442. defer func() {
  3443. if r := recover(); r != nil {
  3444. tx.Rollback()
  3445. }
  3446. }()
  3447. var p models.HisPrescriptionProject
  3448. p.PrescriptionId = tempPrescription.ID
  3449. p.PatientId = patient_id
  3450. p.RecordDate = theTime3.Unix()
  3451. p.Doctor = doctor_id
  3452. p.UserOrgId = adminInfo.CurrentOrgId
  3453. p.HisPatientId = his_patient_id
  3454. p.Status = 1
  3455. p.StartTime = pTime
  3456. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3457. if errcode > 0 {
  3458. tx.Rollback()
  3459. c.ServeFailJSONWithSGJErrorCode(errcode)
  3460. return
  3461. }
  3462. if p.ID == 0 {
  3463. p.IsOut = 2
  3464. }
  3465. if p.ID > 0 {
  3466. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3467. p.IsOut = projectDetail.IsOut
  3468. }
  3469. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3470. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3471. if p.Type == 3 {
  3472. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3473. if p.Price != lastWarehouse.PackingPrice {
  3474. p.Price = lastWarehouse.PackingPrice
  3475. }
  3476. if p.Price == 0 {
  3477. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3478. p.Price = lastWarehouseTwo.PackingPrice
  3479. }
  3480. if p.Unit == "" {
  3481. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3482. p.Unit = goodInfoOne.PackingUnit
  3483. }
  3484. }
  3485. }
  3486. if adminInfo.CurrentOrgId != 10206 {
  3487. if p.Type == 3 {
  3488. if p.ID == 0 {
  3489. //查询该耗材是否停用
  3490. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3491. //表示该耗材已经停用,不能保存
  3492. if goodInfoSeven.ID == 0 {
  3493. tx.Rollback()
  3494. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3495. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3496. return
  3497. }
  3498. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3499. if goodInfoOne.SumCount == 0 {
  3500. tx.Rollback()
  3501. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3502. return
  3503. }
  3504. }
  3505. if p.ID > 0 {
  3506. //查询该耗材是否停用
  3507. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3508. //表示该耗材已经停用,不能保存
  3509. if goodInfoSeven.ID == 0 {
  3510. tx.Rollback()
  3511. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3512. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3513. return
  3514. }
  3515. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3516. if goodInfoOne.SumCount == 0 {
  3517. tx.Rollback()
  3518. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3519. return
  3520. }
  3521. }
  3522. }
  3523. }
  3524. //查询保存耗材出库开关是否打开
  3525. if p.PatientId != 30038 {
  3526. //用机构ID区分
  3527. if adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10164 {
  3528. if goodOutConfig.IsOpen == 1 {
  3529. //耗材出库
  3530. if p.Type == 3 {
  3531. //对比当前数据和历史出库数据
  3532. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3533. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3534. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3535. //如果当前处方数量大于历史数据,则需要出库
  3536. if nowCount > historyCount {
  3537. var cha_count int64
  3538. cha_count = nowCount - historyCount
  3539. timeStr := time.Now().Format("2006-01-02")
  3540. timeArr := strings.Split(timeStr, "-")
  3541. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3542. total = total + 1
  3543. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3544. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3545. number = number + total
  3546. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3547. operation_time := time.Now().Unix()
  3548. creater := c.GetAdminUserInfo().AdminUser.Id
  3549. recordDateStr := time.Now().Format("2006-01-02")
  3550. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3551. nowtime := recordDate.Unix()
  3552. warehouseOut := models.WarehouseOut{
  3553. WarehouseOutOrderNumber: warehousing_out_order,
  3554. OperationTime: operation_time,
  3555. OrgId: adminInfo.CurrentOrgId,
  3556. Creater: creater,
  3557. Ctime: time.Now().Unix(),
  3558. Status: 1,
  3559. WarehouseOutTime: nowtime,
  3560. Type: 1,
  3561. StorehouseId: storeConfig.StorehouseOutInfo,
  3562. IsCheck: 1,
  3563. IsSys: 1,
  3564. }
  3565. //查询是否生成出库单
  3566. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3567. if out.ID == 0 {
  3568. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3569. }
  3570. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3571. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3572. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3573. dialyPrepareOne := models.DialysisBeforePrepare{
  3574. GoodTypeId: goodObj.GoodTypeId,
  3575. GoodId: p.ProjectId,
  3576. PatientId: p.PatientId,
  3577. RecordDate: p.RecordDate,
  3578. UserOrgId: adminInfo.CurrentOrgId,
  3579. Count: cha_count,
  3580. Ctime: time.Now().Unix(),
  3581. Creater: creater,
  3582. Status: 1,
  3583. StorehouseId: houseConfig.StorehouseOutInfo,
  3584. ProjectId: p.ID,
  3585. }
  3586. //出库
  3587. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3588. }
  3589. //如果当前处方数量小于历史数据,怎需要退库
  3590. if nowCount < historyCount {
  3591. var cha_count int64
  3592. cha_count = historyCount - nowCount
  3593. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3594. creater := c.GetAdminUserInfo().AdminUser.Id
  3595. newPrescriptionProject := &models.HisPrescriptionProject{
  3596. ID: p.ID,
  3597. ProjectId: p.ProjectId,
  3598. Price: p.Price,
  3599. UserOrgId: p.UserOrgId,
  3600. Status: 1,
  3601. Ctime: time.Now().Unix(),
  3602. Mtime: time.Now().Unix(),
  3603. PatientId: p.PatientId,
  3604. HisPatientId: p.HisPatientId,
  3605. RecordDate: p.RecordDate,
  3606. PrescriptionId: p.PrescriptionId,
  3607. Count: p.Count,
  3608. FeedetlSn: p.FeedetlSn,
  3609. MedListCodg: p.MedListCodg,
  3610. SingleDose: p.SingleDose,
  3611. DeliveryWay: p.DeliveryWay,
  3612. ExecutionFrequency: p.ExecutionFrequency,
  3613. Day: p.Day,
  3614. HisProject: models.HisProject{},
  3615. GoodInfo: models.GoodInfo{},
  3616. Remark: p.Remark,
  3617. Unit: p.Unit,
  3618. Type: p.Type,
  3619. Doctor: p.Doctor,
  3620. ExecutionTime: p.ExecutionTime,
  3621. ExecutionStaff: p.ExecutionStaff,
  3622. ExecutionState: p.ExecutionState,
  3623. CheckTime: p.CheckTime,
  3624. CheckState: p.CheckState,
  3625. Checker: p.Checker,
  3626. StartTime: p.StartTime,
  3627. TeamId: p.TeamId,
  3628. XtHisProjectTeam: models.XtHisProjectTeam{},
  3629. FrequencyType: p.FrequencyType,
  3630. DayCount: p.DayCount,
  3631. WeekDay: p.WeekDay,
  3632. IsCheckTeam: p.IsCheckTeam,
  3633. HisOrderInfo: models.HisOrderInfo{},
  3634. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3635. IsOut: p.IsOut,
  3636. YbSyncStatus: p.YbSyncStatus,
  3637. }
  3638. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3639. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3640. }
  3641. if nowCount == historyCount {
  3642. if historyCount == 0 {
  3643. recordDateStr := time.Now().Format("2006-01-02")
  3644. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3645. nowtime := recordDate.Unix()
  3646. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3647. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3648. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3649. creater := c.GetAdminUserInfo().AdminUser.Id
  3650. dialyPrepareOne := models.DialysisBeforePrepare{
  3651. GoodTypeId: goodObj.GoodTypeId,
  3652. GoodId: p.ProjectId,
  3653. PatientId: p.PatientId,
  3654. RecordDate: p.RecordDate,
  3655. UserOrgId: adminInfo.CurrentOrgId,
  3656. Count: nowCount,
  3657. Ctime: time.Now().Unix(),
  3658. Creater: creater,
  3659. Status: 1,
  3660. StorehouseId: houseConfig.StorehouseOutInfo,
  3661. ProjectId: p.ID,
  3662. }
  3663. //出库
  3664. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3665. }
  3666. }
  3667. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3668. //查询历史出库数据
  3669. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3670. var out_count_five int64
  3671. for _, item := range flowGood {
  3672. out_count_five += item.Count
  3673. }
  3674. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3675. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3676. if out_count_five != parseIntCount {
  3677. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3678. detail := models.AutomaticReduceDetail{
  3679. WarehouseOutId: 0,
  3680. WarehouseOutOrderNumber: "",
  3681. PatientId: p.PatientId,
  3682. Ctime: time.Now().Unix(),
  3683. Mtime: 0,
  3684. Status: 1,
  3685. RecordTime: p.RecordDate,
  3686. OrgId: p.UserOrgId,
  3687. GoodId: p.ProjectId,
  3688. GoodTypeId: 0,
  3689. Count: parseIntCount,
  3690. Type: 0,
  3691. ProjectId: lastHisProject.ID,
  3692. StorehouseId: 0,
  3693. }
  3694. service.CreateNewAutoDetail(detail, tx)
  3695. }
  3696. // //查询耗材最后一次出库记录
  3697. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3698. // //查询默认出库仓库库存
  3699. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3700. // if len(wareOut) > 0 {
  3701. //
  3702. // for _, it := range wareOut {
  3703. // //回退库存
  3704. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3705. //
  3706. // //删除出库记录
  3707. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3708. //
  3709. // }
  3710. // }
  3711. //
  3712. // timeStr := time.Now().Format("2006-01-02")
  3713. // timeArr := strings.Split(timeStr, "-")
  3714. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3715. //
  3716. // total = total + 1
  3717. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3718. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3719. // number = number + total
  3720. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3721. //
  3722. // operation_time := time.Now().Unix()
  3723. // creater := c.GetAdminUserInfo().AdminUser.Id
  3724. //
  3725. // recordDateStr := time.Now().Format("2006-01-02")
  3726. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3727. // nowtime := recordDate.Unix()
  3728. // warehouseOut := models.WarehouseOut{
  3729. // WarehouseOutOrderNumber: warehousing_out_order,
  3730. // OperationTime: operation_time,
  3731. // OrgId: adminInfo.CurrentOrgId,
  3732. // Creater: creater,
  3733. // Ctime: time.Now().Unix(),
  3734. // Status: 1,
  3735. // WarehouseOutTime: nowtime,
  3736. // Type: 1,
  3737. // StorehouseId: storeConfig.StorehouseOutInfo,
  3738. // IsCheck: 1,
  3739. // IsSys: 1,
  3740. // }
  3741. // //查询是否生成出库单
  3742. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3743. // if out.ID == 0 {
  3744. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3745. // }
  3746. //
  3747. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3748. //
  3749. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3750. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3751. //
  3752. // dialyPrepareOne := models.DialysisBeforePrepare{
  3753. // GoodTypeId: goodObj.GoodTypeId,
  3754. // GoodId: p.ProjectId,
  3755. // PatientId: p.PatientId,
  3756. // RecordDate: p.RecordDate,
  3757. // UserOrgId: adminInfo.CurrentOrgId,
  3758. // Count: parseIntCount,
  3759. // Ctime: time.Now().Unix(),
  3760. // Creater: creater,
  3761. // Status: 1,
  3762. // StorehouseId: houseConfig.StorehouseOutInfo,
  3763. // ProjectId: lastHisProject.ID,
  3764. // }
  3765. // //判断是否是零用耗材(非零用)
  3766. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3767. //
  3768. // //查询历史出库数据
  3769. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3770. // var out_count int64
  3771. // for _, item := range flowGood {
  3772. // out_count += item.Count
  3773. // }
  3774. // //如果历史数和当前数据不想等才进行退库出库
  3775. // if out_count != parseIntCount {
  3776. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3777. //
  3778. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3779. // detail := models.AutomaticReduceDetail{
  3780. // WarehouseOutId: 0,
  3781. // WarehouseOutOrderNumber: "",
  3782. // PatientId: p.PatientId,
  3783. // Ctime: time.Now().Unix(),
  3784. // Mtime: 0,
  3785. // Status: 1,
  3786. // RecordTime: p.RecordDate,
  3787. // OrgId: p.UserOrgId,
  3788. // GoodId: p.ProjectId,
  3789. // GoodTypeId: 0,
  3790. // Count: parseIntCount,
  3791. // Type: 0,
  3792. // ProjectId: lastHisProject.ID,
  3793. // StorehouseId: 0,
  3794. // }
  3795. //
  3796. // service.CreateNewAutoDetail(detail, tx)
  3797. //
  3798. // //查询剩余库存
  3799. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3800. // var sum_count int64
  3801. // for _, item := range goodList {
  3802. // sum_count += item.StockCount
  3803. // }
  3804. //
  3805. // //更新剩余库存
  3806. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3807. //
  3808. // //耗材
  3809. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3810. //
  3811. // }
  3812. // //判断是否是零用耗材(零用但是是出库耗材)
  3813. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3814. //
  3815. // //查询历史出库数据
  3816. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3817. // var out_count int64
  3818. // for _, item := range flowGood {
  3819. // out_count += item.Count
  3820. // }
  3821. // //如果历史数和当前数据不想等才进行退库出库
  3822. // if out_count != parseIntCount {
  3823. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3824. //
  3825. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3826. // detail := models.AutomaticReduceDetail{
  3827. // WarehouseOutId: 0,
  3828. // WarehouseOutOrderNumber: "",
  3829. // PatientId: p.PatientId,
  3830. // Ctime: time.Now().Unix(),
  3831. // Mtime: 0,
  3832. // Status: 1,
  3833. // RecordTime: p.RecordDate,
  3834. // OrgId: p.UserOrgId,
  3835. // GoodId: p.ProjectId,
  3836. // GoodTypeId: 0,
  3837. // Count: parseIntCount,
  3838. // Type: 0,
  3839. // ProjectId: p.ID,
  3840. // StorehouseId: 0,
  3841. // }
  3842. //
  3843. // service.CreateNewAutoDetail(detail, tx)
  3844. //
  3845. // //查询剩余库存
  3846. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3847. // var sum_count int64
  3848. // for _, item := range goodList {
  3849. // sum_count += item.StockCount
  3850. // }
  3851. //
  3852. // //更新剩余库存
  3853. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3854. //
  3855. // //耗材
  3856. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3857. // }
  3858. //
  3859. // }
  3860. //
  3861. // }
  3862. //
  3863. //}
  3864. //记录日志
  3865. byterequest, _ := json.Marshal(p)
  3866. adviceLog := models.XtDoctorAdviceLog{
  3867. UserOrgId: p.UserOrgId,
  3868. PatientId: p.PatientId,
  3869. AdminUserId: adminInfo.AdminUser.Id,
  3870. Module: 1,
  3871. ErrLog: string(byterequest),
  3872. Status: 1,
  3873. Ctime: time.Now().Unix(),
  3874. Mtime: 0,
  3875. Source: "电脑端新建his项目",
  3876. RecordDate: p.RecordDate,
  3877. }
  3878. service.CreateDoctorAdviceLog(adviceLog)
  3879. projectList = append(projectList, p)
  3880. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3881. //新增或者编辑项目,修改对应的标签数据
  3882. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3883. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3884. var label models.HisLabelPrintInfo
  3885. project, _ := service.GetProjectDetail(p.ProjectId)
  3886. if project.CostClassify == 3 { //类别为检验检查
  3887. if p.TeamId > 0 { //检验检查组套
  3888. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3889. if tempLabel.ID == 0 {
  3890. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3891. label.Number = tempPrescription.PrescriptionNumber
  3892. label.ProjectId = project.ID
  3893. label.Status = 1
  3894. label.IsPrint = 2
  3895. label.DoctorId = info.DoctorId
  3896. label.UserOrgId = p.UserOrgId
  3897. label.PatientId = patient_id
  3898. label.RecordDate = recordDateTime
  3899. label.Ctime = time.Now().Unix()
  3900. label.Mtime = time.Now().Unix()
  3901. label.ItemId = p.TeamId
  3902. label.FeedetlSn = p.FeedetlSn
  3903. label.PProjectId = p.ID
  3904. label.ProjectName = team.ProjectTeam
  3905. label.PatientName = patient.Name
  3906. service.CreateNewHisLabelRecord(&label, tx)
  3907. }
  3908. } else { //单条检验检查项目
  3909. label.Number = tempPrescription.PrescriptionNumber
  3910. label.ProjectId = project.ID
  3911. label.Status = 1
  3912. label.DoctorId = info.DoctorId
  3913. label.UserOrgId = p.UserOrgId
  3914. label.PatientId = patient_id
  3915. label.RecordDate = recordDateTime
  3916. label.IsPrint = 2
  3917. label.Ctime = time.Now().Unix()
  3918. label.Mtime = time.Now().Unix()
  3919. label.FeedetlSn = p.FeedetlSn
  3920. label.PProjectId = p.ID
  3921. label.ItemId = p.TeamId
  3922. label.ProjectName = project.ProjectName
  3923. label.PatientName = patient.Name
  3924. service.CreateNewHisLabelRecord(&label, tx)
  3925. }
  3926. }
  3927. }
  3928. }
  3929. }
  3930. }
  3931. }
  3932. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  3933. //耗材出库
  3934. if p.Type == 3 {
  3935. //对比当前数据和历史出库数据
  3936. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3937. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3938. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3939. //如果当前处方数量大于历史数据,则需要出库
  3940. if nowCount > historyCount {
  3941. var cha_count int64
  3942. cha_count = nowCount - historyCount
  3943. timeStr := time.Now().Format("2006-01-02")
  3944. timeArr := strings.Split(timeStr, "-")
  3945. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3946. total = total + 1
  3947. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3948. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3949. number = number + total
  3950. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3951. operation_time := time.Now().Unix()
  3952. creater := c.GetAdminUserInfo().AdminUser.Id
  3953. recordDateStr := time.Now().Format("2006-01-02")
  3954. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3955. nowtime := recordDate.Unix()
  3956. warehouseOut := models.WarehouseOut{
  3957. WarehouseOutOrderNumber: warehousing_out_order,
  3958. OperationTime: operation_time,
  3959. OrgId: adminInfo.CurrentOrgId,
  3960. Creater: creater,
  3961. Ctime: time.Now().Unix(),
  3962. Status: 1,
  3963. WarehouseOutTime: nowtime,
  3964. Type: 1,
  3965. StorehouseId: storeConfig.StorehouseOutInfo,
  3966. IsCheck: 1,
  3967. IsSys: 1,
  3968. }
  3969. //查询是否生成出库单
  3970. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3971. if out.ID == 0 {
  3972. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3973. }
  3974. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3975. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3976. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3977. dialyPrepareOne := models.DialysisBeforePrepare{
  3978. GoodTypeId: goodObj.GoodTypeId,
  3979. GoodId: p.ProjectId,
  3980. PatientId: p.PatientId,
  3981. RecordDate: p.RecordDate,
  3982. UserOrgId: adminInfo.CurrentOrgId,
  3983. Count: cha_count,
  3984. Ctime: time.Now().Unix(),
  3985. Creater: creater,
  3986. Status: 1,
  3987. StorehouseId: houseConfig.StorehouseOutInfo,
  3988. ProjectId: p.ID,
  3989. }
  3990. //出库
  3991. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3992. }
  3993. //如果当前处方数量小于历史数据,怎需要退库
  3994. if nowCount < historyCount {
  3995. var cha_count int64
  3996. cha_count = historyCount - nowCount
  3997. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3998. creater := c.GetAdminUserInfo().AdminUser.Id
  3999. newPrescriptionProject := &models.HisPrescriptionProject{
  4000. ID: p.ID,
  4001. ProjectId: p.ProjectId,
  4002. Price: p.Price,
  4003. UserOrgId: p.UserOrgId,
  4004. Status: 1,
  4005. Ctime: time.Now().Unix(),
  4006. Mtime: time.Now().Unix(),
  4007. PatientId: p.PatientId,
  4008. HisPatientId: p.HisPatientId,
  4009. RecordDate: p.RecordDate,
  4010. PrescriptionId: p.PrescriptionId,
  4011. Count: p.Count,
  4012. FeedetlSn: p.FeedetlSn,
  4013. MedListCodg: p.MedListCodg,
  4014. SingleDose: p.SingleDose,
  4015. DeliveryWay: p.DeliveryWay,
  4016. ExecutionFrequency: p.ExecutionFrequency,
  4017. Day: p.Day,
  4018. HisProject: models.HisProject{},
  4019. GoodInfo: models.GoodInfo{},
  4020. Remark: p.Remark,
  4021. Unit: p.Unit,
  4022. Type: p.Type,
  4023. Doctor: p.Doctor,
  4024. ExecutionTime: p.ExecutionTime,
  4025. ExecutionStaff: p.ExecutionStaff,
  4026. ExecutionState: p.ExecutionState,
  4027. CheckTime: p.CheckTime,
  4028. CheckState: p.CheckState,
  4029. Checker: p.Checker,
  4030. StartTime: p.StartTime,
  4031. TeamId: p.TeamId,
  4032. XtHisProjectTeam: models.XtHisProjectTeam{},
  4033. FrequencyType: p.FrequencyType,
  4034. DayCount: p.DayCount,
  4035. WeekDay: p.WeekDay,
  4036. IsCheckTeam: p.IsCheckTeam,
  4037. HisOrderInfo: models.HisOrderInfo{},
  4038. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4039. IsOut: p.IsOut,
  4040. YbSyncStatus: p.YbSyncStatus,
  4041. }
  4042. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4043. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4044. }
  4045. if nowCount == historyCount {
  4046. if historyCount == 0 {
  4047. recordDateStr := time.Now().Format("2006-01-02")
  4048. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4049. nowtime := recordDate.Unix()
  4050. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4051. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4052. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4053. creater := c.GetAdminUserInfo().AdminUser.Id
  4054. dialyPrepareOne := models.DialysisBeforePrepare{
  4055. GoodTypeId: goodObj.GoodTypeId,
  4056. GoodId: p.ProjectId,
  4057. PatientId: p.PatientId,
  4058. RecordDate: p.RecordDate,
  4059. UserOrgId: adminInfo.CurrentOrgId,
  4060. Count: nowCount,
  4061. Ctime: time.Now().Unix(),
  4062. Creater: creater,
  4063. Status: 1,
  4064. StorehouseId: houseConfig.StorehouseOutInfo,
  4065. ProjectId: p.ID,
  4066. }
  4067. //出库
  4068. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4069. }
  4070. }
  4071. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4072. //查询历史出库数据
  4073. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4074. var out_count_five int64
  4075. for _, item := range flowGood {
  4076. out_count_five += item.Count
  4077. }
  4078. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4079. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4080. if out_count_five != parseIntCount {
  4081. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4082. detail := models.AutomaticReduceDetail{
  4083. WarehouseOutId: 0,
  4084. WarehouseOutOrderNumber: "",
  4085. PatientId: p.PatientId,
  4086. Ctime: time.Now().Unix(),
  4087. Mtime: 0,
  4088. Status: 1,
  4089. RecordTime: p.RecordDate,
  4090. OrgId: p.UserOrgId,
  4091. GoodId: p.ProjectId,
  4092. GoodTypeId: 0,
  4093. Count: parseIntCount,
  4094. Type: 0,
  4095. ProjectId: lastHisProject.ID,
  4096. StorehouseId: 0,
  4097. }
  4098. service.CreateNewAutoDetail(detail, tx)
  4099. }
  4100. // //查询耗材最后一次出库记录
  4101. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4102. // //查询默认出库仓库库存
  4103. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4104. // if len(wareOut) > 0 {
  4105. //
  4106. // for _, it := range wareOut {
  4107. // //回退库存
  4108. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4109. //
  4110. // //删除出库记录
  4111. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4112. //
  4113. // }
  4114. // }
  4115. //
  4116. // timeStr := time.Now().Format("2006-01-02")
  4117. // timeArr := strings.Split(timeStr, "-")
  4118. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4119. //
  4120. // total = total + 1
  4121. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4122. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4123. // number = number + total
  4124. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4125. //
  4126. // operation_time := time.Now().Unix()
  4127. // creater := c.GetAdminUserInfo().AdminUser.Id
  4128. //
  4129. // recordDateStr := time.Now().Format("2006-01-02")
  4130. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4131. // nowtime := recordDate.Unix()
  4132. // warehouseOut := models.WarehouseOut{
  4133. // WarehouseOutOrderNumber: warehousing_out_order,
  4134. // OperationTime: operation_time,
  4135. // OrgId: adminInfo.CurrentOrgId,
  4136. // Creater: creater,
  4137. // Ctime: time.Now().Unix(),
  4138. // Status: 1,
  4139. // WarehouseOutTime: nowtime,
  4140. // Type: 1,
  4141. // StorehouseId: storeConfig.StorehouseOutInfo,
  4142. // IsCheck: 1,
  4143. // IsSys: 1,
  4144. // }
  4145. // //查询是否生成出库单
  4146. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4147. // if out.ID == 0 {
  4148. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4149. // }
  4150. //
  4151. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4152. //
  4153. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4154. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4155. //
  4156. // dialyPrepareOne := models.DialysisBeforePrepare{
  4157. // GoodTypeId: goodObj.GoodTypeId,
  4158. // GoodId: p.ProjectId,
  4159. // PatientId: p.PatientId,
  4160. // RecordDate: p.RecordDate,
  4161. // UserOrgId: adminInfo.CurrentOrgId,
  4162. // Count: parseIntCount,
  4163. // Ctime: time.Now().Unix(),
  4164. // Creater: creater,
  4165. // Status: 1,
  4166. // StorehouseId: houseConfig.StorehouseOutInfo,
  4167. // ProjectId: lastHisProject.ID,
  4168. // }
  4169. // //判断是否是零用耗材(非零用)
  4170. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4171. //
  4172. // //查询历史出库数据
  4173. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4174. // var out_count int64
  4175. // for _, item := range flowGood {
  4176. // out_count += item.Count
  4177. // }
  4178. // //如果历史数和当前数据不想等才进行退库出库
  4179. // if out_count != parseIntCount {
  4180. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4181. //
  4182. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4183. // detail := models.AutomaticReduceDetail{
  4184. // WarehouseOutId: 0,
  4185. // WarehouseOutOrderNumber: "",
  4186. // PatientId: p.PatientId,
  4187. // Ctime: time.Now().Unix(),
  4188. // Mtime: 0,
  4189. // Status: 1,
  4190. // RecordTime: p.RecordDate,
  4191. // OrgId: p.UserOrgId,
  4192. // GoodId: p.ProjectId,
  4193. // GoodTypeId: 0,
  4194. // Count: parseIntCount,
  4195. // Type: 0,
  4196. // ProjectId: lastHisProject.ID,
  4197. // StorehouseId: 0,
  4198. // }
  4199. //
  4200. // service.CreateNewAutoDetail(detail, tx)
  4201. //
  4202. // //查询剩余库存
  4203. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4204. // var sum_count int64
  4205. // for _, item := range goodList {
  4206. // sum_count += item.StockCount
  4207. // }
  4208. //
  4209. // //更新剩余库存
  4210. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4211. //
  4212. // //耗材
  4213. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4214. //
  4215. // }
  4216. // //判断是否是零用耗材(零用但是是出库耗材)
  4217. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4218. //
  4219. // //查询历史出库数据
  4220. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4221. // var out_count int64
  4222. // for _, item := range flowGood {
  4223. // out_count += item.Count
  4224. // }
  4225. // //如果历史数和当前数据不想等才进行退库出库
  4226. // if out_count != parseIntCount {
  4227. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4228. //
  4229. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4230. // detail := models.AutomaticReduceDetail{
  4231. // WarehouseOutId: 0,
  4232. // WarehouseOutOrderNumber: "",
  4233. // PatientId: p.PatientId,
  4234. // Ctime: time.Now().Unix(),
  4235. // Mtime: 0,
  4236. // Status: 1,
  4237. // RecordTime: p.RecordDate,
  4238. // OrgId: p.UserOrgId,
  4239. // GoodId: p.ProjectId,
  4240. // GoodTypeId: 0,
  4241. // Count: parseIntCount,
  4242. // Type: 0,
  4243. // ProjectId: p.ID,
  4244. // StorehouseId: 0,
  4245. // }
  4246. //
  4247. // service.CreateNewAutoDetail(detail, tx)
  4248. //
  4249. // //查询剩余库存
  4250. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4251. // var sum_count int64
  4252. // for _, item := range goodList {
  4253. // sum_count += item.StockCount
  4254. // }
  4255. //
  4256. // //更新剩余库存
  4257. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4258. //
  4259. // //耗材
  4260. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4261. // }
  4262. //
  4263. // }
  4264. //
  4265. // }
  4266. //
  4267. //}
  4268. //记录日志
  4269. byterequest, _ := json.Marshal(p)
  4270. adviceLog := models.XtDoctorAdviceLog{
  4271. UserOrgId: p.UserOrgId,
  4272. PatientId: p.PatientId,
  4273. AdminUserId: adminInfo.AdminUser.Id,
  4274. Module: 1,
  4275. ErrLog: string(byterequest),
  4276. Status: 1,
  4277. Ctime: time.Now().Unix(),
  4278. Mtime: 0,
  4279. Source: "电脑端新建his项目",
  4280. RecordDate: p.RecordDate,
  4281. }
  4282. service.CreateDoctorAdviceLog(adviceLog)
  4283. projectList = append(projectList, p)
  4284. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4285. //新增或者编辑项目,修改对应的标签数据
  4286. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4287. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4288. var label models.HisLabelPrintInfo
  4289. project, _ := service.GetProjectDetail(p.ProjectId)
  4290. if project.CostClassify == 3 { //类别为检验检查
  4291. if p.TeamId > 0 { //检验检查组套
  4292. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4293. if tempLabel.ID == 0 {
  4294. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4295. label.Number = tempPrescription.PrescriptionNumber
  4296. label.ProjectId = project.ID
  4297. label.Status = 1
  4298. label.IsPrint = 2
  4299. label.DoctorId = info.DoctorId
  4300. label.UserOrgId = p.UserOrgId
  4301. label.PatientId = patient_id
  4302. label.RecordDate = recordDateTime
  4303. label.Ctime = time.Now().Unix()
  4304. label.Mtime = time.Now().Unix()
  4305. label.ItemId = p.TeamId
  4306. label.FeedetlSn = p.FeedetlSn
  4307. label.PProjectId = p.ID
  4308. label.ProjectName = team.ProjectTeam
  4309. label.PatientName = patient.Name
  4310. service.CreateNewHisLabelRecord(&label, tx)
  4311. }
  4312. } else { //单条检验检查项目
  4313. label.Number = tempPrescription.PrescriptionNumber
  4314. label.ProjectId = project.ID
  4315. label.Status = 1
  4316. label.DoctorId = info.DoctorId
  4317. label.UserOrgId = p.UserOrgId
  4318. label.PatientId = patient_id
  4319. label.RecordDate = recordDateTime
  4320. label.IsPrint = 2
  4321. label.Ctime = time.Now().Unix()
  4322. label.Mtime = time.Now().Unix()
  4323. label.FeedetlSn = p.FeedetlSn
  4324. label.PProjectId = p.ID
  4325. label.ItemId = p.TeamId
  4326. label.ProjectName = project.ProjectName
  4327. label.PatientName = patient.Name
  4328. service.CreateNewHisLabelRecord(&label, tx)
  4329. }
  4330. }
  4331. }
  4332. }
  4333. }
  4334. }
  4335. }
  4336. //插入检验数据
  4337. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4338. //新增或者编辑项目,修改对应的标签数据
  4339. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4340. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4341. var label models.HisLabelPrintInfo
  4342. project, _ := service.GetProjectDetail(p.ProjectId)
  4343. if project.CostClassify == 3 { //类别为检验检查
  4344. if p.TeamId > 0 { //检验检查组套
  4345. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4346. if tempLabel.ID == 0 {
  4347. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4348. label.Number = tempPrescription.PrescriptionNumber
  4349. label.ProjectId = project.ID
  4350. label.Status = 1
  4351. label.IsPrint = 2
  4352. label.DoctorId = info.DoctorId
  4353. label.UserOrgId = p.UserOrgId
  4354. label.PatientId = patient_id
  4355. label.RecordDate = recordDateTime
  4356. label.Ctime = time.Now().Unix()
  4357. label.Mtime = time.Now().Unix()
  4358. label.ItemId = p.TeamId
  4359. label.FeedetlSn = p.FeedetlSn
  4360. label.PProjectId = p.ID
  4361. label.ProjectName = team.ProjectTeam
  4362. label.PatientName = patient.Name
  4363. service.CreateHisLabelRecord(&label)
  4364. }
  4365. } else { //单条检验检查项目
  4366. label.Number = tempPrescription.PrescriptionNumber
  4367. label.ProjectId = project.ID
  4368. label.Status = 1
  4369. label.DoctorId = info.DoctorId
  4370. label.UserOrgId = p.UserOrgId
  4371. label.PatientId = patient_id
  4372. label.RecordDate = recordDateTime
  4373. label.IsPrint = 2
  4374. label.Ctime = time.Now().Unix()
  4375. label.Mtime = time.Now().Unix()
  4376. label.FeedetlSn = p.FeedetlSn
  4377. label.PProjectId = p.ID
  4378. label.ItemId = p.TeamId
  4379. label.ProjectName = project.ProjectName
  4380. label.PatientName = patient.Name
  4381. service.CreateHisLabelRecord(&label)
  4382. }
  4383. }
  4384. }
  4385. }
  4386. service.CreateNewHisProjectTwo(&p, tx)
  4387. var randNum int
  4388. randNum = rand.Intn(10000) + 1000
  4389. timestamp := time.Now().Unix()
  4390. tempTime := time.Unix(timestamp, 0)
  4391. timeFormat := tempTime.Format("20060102150405")
  4392. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4393. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4394. if goodBase.ID > 0 {
  4395. tx.Rollback()
  4396. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4397. return
  4398. }
  4399. service.CreateNewHisProjectTwo(&p, tx)
  4400. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4401. //查询剩余库存
  4402. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4403. var sum_count int64
  4404. for _, item := range goodList {
  4405. sum_count += item.StockCount
  4406. }
  4407. //更新剩余库存
  4408. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4409. //耗材
  4410. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4411. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4412. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4413. if len(outInfoTwo) > 0 {
  4414. for _, item := range outInfoTwo {
  4415. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4416. }
  4417. }
  4418. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4419. if len(drugAutoDetail) > 0 {
  4420. for _, item := range drugAutoDetail {
  4421. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4422. }
  4423. }
  4424. tx.Commit()
  4425. }
  4426. }
  4427. }
  4428. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4429. // addition := items["addition"].([]interface{})
  4430. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4431. // ctime := time.Now().Unix()
  4432. // mtime := ctime
  4433. // if len(addition) > 0 {
  4434. // for _, item := range addition {
  4435. // var s models.HisAdditionalCharge
  4436. // s.PrescriptionId = tempPrescription.ID
  4437. // s.Status = 1
  4438. // s.UserOrgId = adminInfo.CurrentOrgId
  4439. // s.RecordDate = recordDateTime
  4440. // s.CreatedTime = ctime
  4441. // s.UpdatedTime = mtime
  4442. // s.PatientId = patient_id
  4443. // s.HisPatientId = his_patient_id
  4444. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4445. // if errcode > 0 {
  4446. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4447. // return
  4448. // }
  4449. // service.CreateAdditionalCharge(&s)
  4450. // var randNum int
  4451. // randNum = rand.Intn(10000) + 1000
  4452. // timestamp := time.Now().Unix()
  4453. // tempTime := time.Unix(timestamp, 0)
  4454. // timeFormat := tempTime.Format("20060102150405")
  4455. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4456. // service.CreateAdditionalCharge(&s)
  4457. //
  4458. // }
  4459. // }
  4460. //}
  4461. }
  4462. }
  4463. }
  4464. tx.Commit()
  4465. if err == nil {
  4466. c.ServeSuccessJSON(map[string]interface{}{
  4467. "msg": "保存成功",
  4468. })
  4469. return
  4470. } else {
  4471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4472. return
  4473. }
  4474. } else {
  4475. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4476. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4477. var tempPrescription *models.HisPrescription
  4478. if len(prescriptions) > 0 {
  4479. for _, item := range prescriptions {
  4480. items := item.(map[string]interface{})
  4481. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4482. utils.ErrorLog("id")
  4483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4484. return
  4485. }
  4486. id := int64(items["id"].(float64))
  4487. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4488. tempPrescription = &new_prescription
  4489. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4490. utils.ErrorLog("type")
  4491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4492. return
  4493. }
  4494. types := int64(items["type"].(float64))
  4495. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4496. utils.ErrorLog("med_type")
  4497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4498. return
  4499. }
  4500. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4501. if med_type == "0" {
  4502. med_type = "14"
  4503. }
  4504. //if order_status == 0 {
  4505. // order_status = 1
  4506. //}
  4507. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4508. // utils.ErrorLog("diagnoses")
  4509. //}
  4510. diagnoses, _ := items["diagnoses"].(string)
  4511. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4512. utils.ErrorLog("pre_time")
  4513. }
  4514. preTime, _ := items["pre_time"].(string)
  4515. timeLayout := "2006-01-02"
  4516. loc, _ := time.LoadLocation("Local")
  4517. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4518. //result := strings.Split(preTime, " ")
  4519. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4520. if err != nil {
  4521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4522. return
  4523. }
  4524. pTime := theTime2.Unix()
  4525. ctime := time.Now().Unix()
  4526. if tempPrescription.ID == 0 {
  4527. prescription := &models.HisPrescription{
  4528. ID: 0,
  4529. PatientId: patient_id,
  4530. UserOrgId: adminInfo.CurrentOrgId,
  4531. RecordDate: recordDateTime,
  4532. Ctime: ctime,
  4533. Mtime: ctime,
  4534. Type: types,
  4535. Modifier: adminInfo.AdminUser.Id,
  4536. Creator: adminInfo.AdminUser.Id,
  4537. Status: 1,
  4538. Doctor: role.UserName,
  4539. HisPatientId: his_patient_id,
  4540. OrderStatus: 1,
  4541. BatchNumber: "",
  4542. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4543. PreTime: pTime,
  4544. PType: p_type,
  4545. MedType: med_type,
  4546. Diagnose: diagnoses,
  4547. }
  4548. tempPrescription = prescription
  4549. service.SaveHisPrescription(tempPrescription)
  4550. redis := service.RedisClient()
  4551. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4552. redis.Set(key, "", time.Second)
  4553. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4554. redis.Set(keyOne, "", time.Second)
  4555. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4556. redis.Set(keySeven, "", time.Second)
  4557. defer redis.Close()
  4558. } else {
  4559. tempPrescription.ID = id
  4560. tempPrescription.Type = types
  4561. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4562. tempPrescription.Mtime = time.Now().Unix()
  4563. tempPrescription.Doctor = role.UserName
  4564. //tempPrescription.OrderStatus = order_status
  4565. tempPrescription.PreTime = pTime
  4566. tempPrescription.MedType = med_type
  4567. tempPrescription.Diagnose = diagnoses
  4568. service.SaveHisPrescription(tempPrescription)
  4569. redis := service.RedisClient()
  4570. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4571. redis.Set(key, "", time.Second)
  4572. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4573. redis.Set(keyOne, "", time.Second)
  4574. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4575. redis.Set(keySeven, "", time.Second)
  4576. defer redis.Close()
  4577. }
  4578. //service.SaveHisPrescription(prescription)
  4579. //更改患者挂号状态
  4580. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4581. fmt.Println("更改失败", err2)
  4582. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4583. advices := items["advices"].([]interface{})
  4584. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4585. groupNo := int64(0)
  4586. if len(advices) > 0 {
  4587. for _, advice := range advices {
  4588. var s models.HisDoctorAdviceInfo
  4589. s.PrescriptionId = tempPrescription.ID
  4590. s.AdviceType = 2
  4591. s.AdviceDoctor = doctor_id
  4592. s.StopState = 2
  4593. s.ExecutionState = 2
  4594. s.AdviceDate = theTime3.Unix()
  4595. s.Status = 1
  4596. s.UserOrgId = adminInfo.CurrentOrgId
  4597. s.RecordDate = theTime3.Unix()
  4598. s.StartTime = tempPrescription.PreTime
  4599. s.Groupno = groupNo
  4600. s.PatientId = patient_id
  4601. s.HisPatientId = his_patient_id
  4602. s.StartTime = pTime
  4603. s.IsSettle = 2
  4604. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4605. if errcode > 0 {
  4606. c.ServeFailJSONWithSGJErrorCode(errcode)
  4607. return
  4608. }
  4609. s.StartTime = pTime
  4610. var total_count int64 //处方总库存
  4611. //查询改药品信息
  4612. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4613. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4614. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4615. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4616. total_count += prescribingNumberSeven * medical.MinNumber
  4617. }
  4618. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4619. total_count += prescribingNumberSeven
  4620. }
  4621. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4622. total_count += prescribingNumberSeven
  4623. }
  4624. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4625. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4626. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4627. if s.Price != lastWarehouse.RetailPrice {
  4628. s.Price = lastWarehouse.RetailPrice
  4629. }
  4630. if s.Price == 0 {
  4631. if lastWarehouse.ID == 0 {
  4632. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4633. s.Price = lastWarehouseTwo.RetailPrice
  4634. }
  4635. }
  4636. }
  4637. if adminInfo.CurrentOrgId != 10206 {
  4638. if s.ID == 0 {
  4639. //查询改药品是否已经停用
  4640. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4641. if base.ID > 0 {
  4642. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4643. return
  4644. }
  4645. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4646. if drugMedical.SumCount == 0 {
  4647. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4648. return
  4649. }
  4650. }
  4651. }
  4652. //赤峰
  4653. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4654. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4655. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4656. if info.RetailPrice > 0 {
  4657. if s.DeliveryWay == "口服" {
  4658. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4659. s.Price = drug.RetailPrice
  4660. }
  4661. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4662. s.Price = info.RetailPrice
  4663. }
  4664. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4665. s.Price = info.RetailPrice
  4666. }
  4667. }
  4668. }
  4669. }
  4670. service.CreateHisDoctorAdvice(&s)
  4671. //记录日志
  4672. byterequest, _ := json.Marshal(s)
  4673. adviceLog := models.XtDoctorAdviceLog{
  4674. UserOrgId: s.UserOrgId,
  4675. PatientId: s.PatientId,
  4676. AdminUserId: adminInfo.AdminUser.Id,
  4677. Module: 1,
  4678. ErrLog: string(byterequest),
  4679. Status: 1,
  4680. Ctime: time.Now().Unix(),
  4681. Mtime: 0,
  4682. Source: "电脑端新建his医嘱",
  4683. RecordDate: s.AdviceDate,
  4684. }
  4685. service.CreateDoctorAdviceLog(adviceLog)
  4686. //存储切片中
  4687. adviceList = append(adviceList, s)
  4688. redis := service.RedisClient()
  4689. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4690. redis.Set(key, "", time.Second)
  4691. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4692. redis.Set(keyOne, "", time.Second)
  4693. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4694. redis.Set(keySeven, "", time.Second)
  4695. var randNum int
  4696. randNum = rand.Intn(10000) + 1000
  4697. timestamp := time.Now().Unix()
  4698. tempTime := time.Unix(timestamp, 0)
  4699. timeFormat := tempTime.Format("20060102150405")
  4700. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4701. service.CreateHisDoctorAdvice(&s)
  4702. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4703. redis.Set(keySix, "", time.Second)
  4704. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4705. redis.Set(keyFive, "", time.Second)
  4706. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4707. redis.Set(keyEight, "", time.Second)
  4708. defer redis.Close()
  4709. }
  4710. }
  4711. }
  4712. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4713. projects := items["project"].([]interface{})
  4714. if len(projects) > 0 {
  4715. for _, project := range projects {
  4716. var p models.HisPrescriptionProject
  4717. p.PrescriptionId = tempPrescription.ID
  4718. p.PatientId = patient_id
  4719. p.RecordDate = theTime3.Unix()
  4720. p.Doctor = doctor_id
  4721. p.UserOrgId = adminInfo.CurrentOrgId
  4722. p.HisPatientId = his_patient_id
  4723. p.Status = 1
  4724. p.StartTime = pTime
  4725. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4726. if errcode > 0 {
  4727. c.ServeFailJSONWithSGJErrorCode(errcode)
  4728. return
  4729. }
  4730. if p.ID == 0 {
  4731. p.IsOut = 2
  4732. }
  4733. if p.ID > 0 {
  4734. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4735. p.IsOut = projectDetail.IsOut
  4736. }
  4737. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4738. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4739. if p.Type == 3 {
  4740. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4741. if p.Price != lastWarehouse.PackingPrice {
  4742. p.Price = lastWarehouse.PackingPrice
  4743. }
  4744. if p.Price == 0 {
  4745. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4746. p.Price = lastWarehouseTwo.PackingPrice
  4747. }
  4748. if p.Unit == "" {
  4749. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4750. p.Unit = goodInfoOne.PackingUnit
  4751. }
  4752. }
  4753. }
  4754. if adminInfo.CurrentOrgId != 10206 {
  4755. if p.Type == 3 {
  4756. if p.ID == 0 {
  4757. //查询该耗材是否停用
  4758. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4759. //表示该耗材已经停用,不能保存
  4760. if goodInfoSeven.ID == 0 {
  4761. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4762. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4763. return
  4764. }
  4765. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4766. if goodInfoOne.SumCount == 0 {
  4767. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4768. return
  4769. }
  4770. }
  4771. }
  4772. }
  4773. service.CreateHisProjectTwo(&p)
  4774. //记录日志
  4775. byterequest, _ := json.Marshal(p)
  4776. adviceLog := models.XtDoctorAdviceLog{
  4777. UserOrgId: p.UserOrgId,
  4778. PatientId: p.PatientId,
  4779. AdminUserId: adminInfo.AdminUser.Id,
  4780. Module: 1,
  4781. ErrLog: string(byterequest),
  4782. Status: 1,
  4783. Ctime: time.Now().Unix(),
  4784. Mtime: 0,
  4785. Source: "电脑端新建his项目",
  4786. RecordDate: p.RecordDate,
  4787. }
  4788. service.CreateDoctorAdviceLog(adviceLog)
  4789. projectList = append(projectList, p)
  4790. var randNum int
  4791. randNum = rand.Intn(10000) + 1000
  4792. timestamp := time.Now().Unix()
  4793. tempTime := time.Unix(timestamp, 0)
  4794. timeFormat := tempTime.Format("20060102150405")
  4795. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4796. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4797. //新增或者编辑项目,修改对应的标签数据
  4798. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4799. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4800. var label models.HisLabelPrintInfo
  4801. project, _ := service.GetProjectDetail(p.ProjectId)
  4802. if project.CostClassify == 3 { //类别为检验检查
  4803. if p.TeamId > 0 { //检验检查组套
  4804. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4805. if tempLabel.ID == 0 {
  4806. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4807. label.Number = tempPrescription.PrescriptionNumber
  4808. label.ProjectId = project.ID
  4809. label.Status = 1
  4810. label.IsPrint = 2
  4811. label.DoctorId = info.DoctorId
  4812. label.UserOrgId = p.UserOrgId
  4813. label.PatientId = patient_id
  4814. label.RecordDate = recordDateTime
  4815. label.Ctime = time.Now().Unix()
  4816. label.Mtime = time.Now().Unix()
  4817. label.ItemId = p.TeamId
  4818. label.FeedetlSn = p.FeedetlSn
  4819. label.PProjectId = p.ID
  4820. label.ProjectName = team.ProjectTeam
  4821. label.PatientName = patient.Name
  4822. service.CreateHisLabelRecord(&label)
  4823. }
  4824. } else { //单条检验检查项目
  4825. label.Number = tempPrescription.PrescriptionNumber
  4826. label.ProjectId = project.ID
  4827. label.Status = 1
  4828. label.DoctorId = info.DoctorId
  4829. label.UserOrgId = p.UserOrgId
  4830. label.PatientId = patient_id
  4831. label.RecordDate = recordDateTime
  4832. label.IsPrint = 2
  4833. label.Ctime = time.Now().Unix()
  4834. label.Mtime = time.Now().Unix()
  4835. label.FeedetlSn = p.FeedetlSn
  4836. label.PProjectId = p.ID
  4837. label.ItemId = p.TeamId
  4838. label.ProjectName = project.ProjectName
  4839. label.PatientName = patient.Name
  4840. service.CreateHisLabelRecord(&label)
  4841. }
  4842. }
  4843. }
  4844. }
  4845. service.SaveHisProjectTwo(&p)
  4846. }
  4847. }
  4848. }
  4849. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4850. // addition := items["addition"].([]interface{})
  4851. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4852. // ctime := time.Now().Unix()
  4853. // mtime := ctime
  4854. // if len(addition) > 0 {
  4855. // for _, item := range addition {
  4856. // var s models.HisAdditionalCharge
  4857. // s.PrescriptionId = tempPrescription.ID
  4858. // s.Status = 1
  4859. // s.UserOrgId = adminInfo.CurrentOrgId
  4860. // s.RecordDate = recordDateTime
  4861. // s.CreatedTime = ctime
  4862. // s.UpdatedTime = mtime
  4863. // s.PatientId = patient_id
  4864. // s.HisPatientId = his_patient_id
  4865. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4866. // if errcode > 0 {
  4867. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4868. // return
  4869. // }
  4870. // service.CreateAdditionalCharge(&s)
  4871. // var randNum int
  4872. // randNum = rand.Intn(10000) + 1000
  4873. // timestamp := time.Now().Unix()
  4874. // tempTime := time.Unix(timestamp, 0)
  4875. // timeFormat := tempTime.Format("20060102150405")
  4876. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4877. // service.CreateAdditionalCharge(&s)
  4878. //
  4879. // }
  4880. // }
  4881. //}
  4882. }
  4883. }
  4884. //查询今日该患者开的药品处方
  4885. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4886. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4887. //药品出库
  4888. if drugOutConfig.IsOpen == 1 {
  4889. for _, item := range hisdoctorlist {
  4890. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4891. // 查询该药品最后一次出库记录
  4892. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4893. if len(druginfo) > 0 {
  4894. //回退库存
  4895. for _, it := range druginfo {
  4896. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4897. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4898. }
  4899. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4900. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4901. }
  4902. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4903. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4904. }
  4905. }
  4906. }
  4907. //删除记录
  4908. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4909. //查询最后一次数据
  4910. if drugOutConfig.IsOpen == 1 {
  4911. //出库
  4912. if drug.IsUse == 2 {
  4913. creater := adminInfo.AdminUser.Id
  4914. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4915. }
  4916. //更新字典里面的库存
  4917. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4918. var sum_count int64
  4919. for _, its := range stockInfo {
  4920. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4921. if its.MaxUnit == baseDrug.MaxUnit {
  4922. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4923. }
  4924. sum_count += its.StockMaxNumber + its.StockMinNumber
  4925. }
  4926. //更新基础库存
  4927. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4928. //剩余库存
  4929. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4930. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4931. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4932. }
  4933. }
  4934. }
  4935. //耗材保存处方出库
  4936. if goodOutConfig.IsOpen == 1 {
  4937. //查询今日耗材出库数量
  4938. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4939. for _, item := range hisgoodlist {
  4940. //查询历史出库数据
  4941. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4942. var out_count_five int64
  4943. for _, item := range flowGood {
  4944. out_count_five += item.Count
  4945. }
  4946. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4947. if out_count_five != parseIntCount {
  4948. //查询耗材最后一次出库记录
  4949. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4950. //查询默认出库仓库库存
  4951. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4952. if len(wareOut) > 0 {
  4953. for _, it := range wareOut {
  4954. //回退库存
  4955. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4956. //删除出库记录
  4957. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4958. }
  4959. }
  4960. timeStr := time.Now().Format("2006-01-02")
  4961. timeArr := strings.Split(timeStr, "-")
  4962. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4963. total = total + 1
  4964. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4965. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4966. number = number + total
  4967. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4968. operation_time := time.Now().Unix()
  4969. creater := c.GetAdminUserInfo().AdminUser.Id
  4970. recordDateStr := time.Now().Format("2006-01-02")
  4971. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4972. nowtime := recordDate.Unix()
  4973. warehouseOut := models.WarehouseOut{
  4974. WarehouseOutOrderNumber: warehousing_out_order,
  4975. OperationTime: operation_time,
  4976. OrgId: adminInfo.CurrentOrgId,
  4977. Creater: creater,
  4978. Ctime: time.Now().Unix(),
  4979. Status: 1,
  4980. WarehouseOutTime: nowtime,
  4981. Type: 1,
  4982. StorehouseId: storeConfig.StorehouseOutInfo,
  4983. IsCheck: 1,
  4984. IsSys: 1,
  4985. }
  4986. //查询是否生成出库单
  4987. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4988. if out.ID == 0 {
  4989. service.AddSigleWarehouseOut(&warehouseOut)
  4990. }
  4991. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4992. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4993. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4994. dialyPrepareOne := models.DialysisBeforePrepare{
  4995. GoodTypeId: goodObj.GoodTypeId,
  4996. GoodId: item.ProjectId,
  4997. PatientId: item.PatientId,
  4998. RecordDate: item.RecordDate,
  4999. UserOrgId: adminInfo.CurrentOrgId,
  5000. Count: parseIntCount,
  5001. Ctime: time.Now().Unix(),
  5002. Creater: creater,
  5003. Status: 1,
  5004. StorehouseId: houseConfig.StorehouseOutInfo,
  5005. ProjectId: item.ID,
  5006. }
  5007. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5008. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5009. //查询历史出库数据
  5010. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5011. var out_count int64
  5012. for _, item := range flowGood {
  5013. out_count += item.Count
  5014. }
  5015. //如果历史数和当前数据不想等才进行退库出库
  5016. if out_count != parseIntCount {
  5017. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5018. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5019. detail := models.AutomaticReduceDetail{
  5020. WarehouseOutId: 0,
  5021. WarehouseOutOrderNumber: "",
  5022. PatientId: item.PatientId,
  5023. Ctime: time.Now().Unix(),
  5024. Mtime: 0,
  5025. Status: 1,
  5026. RecordTime: item.RecordDate,
  5027. OrgId: item.UserOrgId,
  5028. GoodId: item.ProjectId,
  5029. GoodTypeId: 0,
  5030. Count: parseIntCount,
  5031. Type: 0,
  5032. ProjectId: item.ID,
  5033. StorehouseId: 0,
  5034. }
  5035. service.CreateAutoDetail(detail)
  5036. //查询剩余库存
  5037. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5038. var sum_count int64
  5039. for _, item := range goodList {
  5040. sum_count += item.StockCount
  5041. }
  5042. //更新剩余库存
  5043. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5044. //耗材
  5045. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5046. }
  5047. }
  5048. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5049. //查询历史出库数据
  5050. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5051. var out_count int64
  5052. for _, item := range flowGood {
  5053. out_count += item.Count
  5054. }
  5055. //如果历史数和当前数据不想等才进行退库出库
  5056. if out_count != parseIntCount {
  5057. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5058. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5059. detail := models.AutomaticReduceDetail{
  5060. WarehouseOutId: 0,
  5061. WarehouseOutOrderNumber: "",
  5062. PatientId: item.PatientId,
  5063. Ctime: time.Now().Unix(),
  5064. Mtime: 0,
  5065. Status: 1,
  5066. RecordTime: item.RecordDate,
  5067. OrgId: item.UserOrgId,
  5068. GoodId: item.ProjectId,
  5069. GoodTypeId: 0,
  5070. Count: parseIntCount,
  5071. Type: 0,
  5072. ProjectId: item.ID,
  5073. StorehouseId: 0,
  5074. }
  5075. service.CreateAutoDetail(detail)
  5076. //查询剩余库存
  5077. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5078. var sum_count int64
  5079. for _, item := range goodList {
  5080. sum_count += item.StockCount
  5081. }
  5082. //更新剩余库存
  5083. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5084. //耗材
  5085. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5086. }
  5087. }
  5088. }
  5089. }
  5090. }
  5091. ////同步到自备药
  5092. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5093. if selfPrescriptionOpen.IsOpen == 1 {
  5094. timeStr := time.Now().Format("2006-01-02")
  5095. timeArr := strings.Split(timeStr, "-")
  5096. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5097. total = total + 1
  5098. operation_time := time.Now().Unix()
  5099. creater := adminInfo.AdminUser.Id
  5100. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5101. warehousing := models.XtSelfDrugWarehouse{
  5102. WarehousingOrder: warehousing_order,
  5103. OperationTime: operation_time,
  5104. OrgId: adminInfo.CurrentOrgId,
  5105. Creater: creater,
  5106. Ctime: time.Now().Unix(),
  5107. Status: 1,
  5108. WarehousingTime: recordDateTime,
  5109. Type: 0,
  5110. StorehouseId: 0,
  5111. IsCheck: 1,
  5112. PatientId: patient_id,
  5113. IsSys: 1,
  5114. }
  5115. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5116. if selfDrugWarehouse.ID == 0 {
  5117. service.AddSelfDrugWarehouse(&warehousing, tx)
  5118. }
  5119. if selfDrugWarehouse.ID > 0 {
  5120. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5121. }
  5122. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5123. fmt.Println(info)
  5124. for _, item := range hisdoctorlist {
  5125. //查询该病人的该药品是否已经入库
  5126. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5127. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5128. var in_count int64
  5129. if len(selfdruginfo) > 0 {
  5130. for _, item := range selfdruginfo {
  5131. var in_count_one int64
  5132. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5133. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5134. }
  5135. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5136. in_count_one = item.WarehousingCount
  5137. }
  5138. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5139. in_count_one = item.WarehousingCount
  5140. }
  5141. in_count += in_count_one
  5142. }
  5143. }
  5144. if selfBasedrug.IsSelfDrug == 1 {
  5145. var total_count int64
  5146. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5147. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5148. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5149. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5150. }
  5151. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5152. total_count += prescribingNumberSeven
  5153. }
  5154. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5155. total_count += prescribingNumberSeven
  5156. }
  5157. //入库
  5158. if total_count > in_count {
  5159. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5160. WarehousingOrder: warehousing_order,
  5161. WarehousingId: info.ID,
  5162. DrugId: item.DrugId,
  5163. Number: "",
  5164. ProductDate: 0,
  5165. ExpiryDate: 0,
  5166. WarehousingCount: total_count - in_count,
  5167. WarehouseingUnit: selfBasedrug.MinUnit,
  5168. Price: 0,
  5169. TotalPrice: 0,
  5170. Status: 1,
  5171. Ctime: time.Now().Unix(),
  5172. Remark: "",
  5173. OrgId: adminInfo.CurrentOrgId,
  5174. Type: 0,
  5175. Manufacturer: selfBasedrug.Manufacturer,
  5176. Dealer: selfBasedrug.Dealer,
  5177. StockMaxNumber: total_count - in_count,
  5178. RetailTotalPrice: 0,
  5179. BatchNumber: "",
  5180. MaxUnit: selfBasedrug.MinUnit,
  5181. MinUnit: selfBasedrug.MinUnit,
  5182. RetailPrice: 0,
  5183. StorehouseId: 0,
  5184. IsCheck: 1,
  5185. StockMinNumber: 0,
  5186. PatientId: patient_id,
  5187. IsSys: 1,
  5188. RecordDate: item.RecordDate,
  5189. AdviceId: item.ID,
  5190. }
  5191. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5192. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5193. Creator := adminInfo.AdminUser.Id
  5194. //查询默认仓库剩余多少库存
  5195. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5196. var sum_count int64
  5197. for _, it := range list {
  5198. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5199. if it.MaxUnit == baseDrug.MaxUnit {
  5200. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5201. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5202. }
  5203. sum_count += it.StockMaxNumber + it.StockMinNumber
  5204. }
  5205. flow := &models.XtSelfDrugFlow{
  5206. WarehousingId: info.ID,
  5207. DrugId: item.DrugId,
  5208. Number: "",
  5209. BatchNumber: "",
  5210. Count: total_count - in_count,
  5211. UserOrgId: adminInfo.CurrentOrgId,
  5212. PatientId: item.PatientId,
  5213. SystemTime: time.Now().Unix(),
  5214. ConsumableType: 1,
  5215. IsSys: 1,
  5216. WarehousingOrder: warehousing_order,
  5217. WarehouseOutId: 0,
  5218. WarehouseOutOrderNumber: "",
  5219. IsEdit: 0,
  5220. CancelStockId: 0,
  5221. CancelOrderNumber: "",
  5222. Manufacturer: selfBasedrug.Manufacturer,
  5223. Dealer: selfBasedrug.Dealer,
  5224. Creator: Creator,
  5225. UpdateCreator: Creator,
  5226. Status: 1,
  5227. Ctime: item.AdviceDate,
  5228. Mtime: 0,
  5229. Price: item.Price,
  5230. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5231. WarehouseOutDetailId: 0,
  5232. CancelOutDetailId: 0,
  5233. ExpireDate: 0,
  5234. ProductDate: 0,
  5235. MaxUnit: selfBasedrug.MinUnit,
  5236. MinUnit: selfBasedrug.MinUnit,
  5237. StorehouseId: 0,
  5238. OverCount: sum_count,
  5239. OperateTime: time.Now().Unix(),
  5240. AdviceId: item.ID,
  5241. }
  5242. service.CreateSelfDrugFlow(flow, tx)
  5243. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5244. var total_count int64 // 入库总数量
  5245. var over_count int64 //剩余库存
  5246. for _, it := range drugInfolist {
  5247. if it.MaxUnit == selfBasedrug.MaxUnit {
  5248. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5249. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5250. }
  5251. }
  5252. for _, it := range drugInfolist {
  5253. total_count += it.WarehousingCount
  5254. over_count += it.StockMaxNumber + it.StockMinNumber
  5255. }
  5256. //查询该仓库是否有默认数据
  5257. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5258. if selfDrugStock.ID == 0 {
  5259. drugStock := models.XtSelfDrugStockCount{
  5260. UserOrgId: item.UserOrgId,
  5261. PatientId: item.PatientId,
  5262. SumInCount: total_count,
  5263. SumOutCount: 0,
  5264. SumCancelCount: 0,
  5265. DrugId: item.DrugId,
  5266. Ctime: time.Now().Unix(),
  5267. Mtime: 0,
  5268. Status: 1,
  5269. FlushCount: over_count,
  5270. SumActOutCount: 0,
  5271. }
  5272. service.CreateSelfDrugStockSum(drugStock, tx)
  5273. }
  5274. if selfDrugStock.ID > 0 {
  5275. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5276. }
  5277. }
  5278. //查询这个单据的出库数量
  5279. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5280. var his_out_count int64
  5281. for _, item := range drugFlowList {
  5282. his_out_count += item.Count
  5283. }
  5284. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5285. if (total_count + his_out_count) <= in_count {
  5286. // 出库
  5287. if total_count < in_count {
  5288. var cha_count int64
  5289. cha_count = in_count - total_count
  5290. var stock_number int64 = 0
  5291. //查询库存是否充足
  5292. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5293. // 将该批次的剩余库存数量转换为拆零数量
  5294. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5295. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5296. }
  5297. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5298. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5299. }
  5300. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5301. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5302. }
  5303. if stock_number >= cha_count {
  5304. var maxNumber int64 = 0
  5305. var minNumber int64 = 0
  5306. maxNumber = cha_count / selfBasedrug.MinNumber
  5307. minNumber = cha_count % selfBasedrug.MinNumber
  5308. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5309. minNumber = maxNumber
  5310. }
  5311. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5312. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5314. return
  5315. }
  5316. }
  5317. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5318. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5319. }
  5320. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5321. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5322. }
  5323. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5324. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5325. }
  5326. if warehouse.StockMaxNumber < 0 {
  5327. warehouse.StockMaxNumber = 0
  5328. }
  5329. if warehouse.StockMinNumber < 0 {
  5330. warehouse.StockMinNumber = 0
  5331. }
  5332. warehouse.Mtime = time.Now().Unix()
  5333. if warehouse.StockMinNumber < minNumber {
  5334. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5335. if warehouse.MaxUnit != warehouse.MinUnit {
  5336. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5337. }
  5338. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5339. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5340. }
  5341. } else {
  5342. if minNumber > 0 {
  5343. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5344. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5345. }
  5346. }
  5347. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5348. if warehouse.StockMinNumber > 0 {
  5349. if warehouse.StockMinNumber-cha_count >= 0 {
  5350. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5351. }
  5352. }
  5353. }
  5354. }
  5355. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5356. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5357. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5358. }
  5359. }
  5360. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5361. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5363. return
  5364. }
  5365. }
  5366. if warehouse.StockMinNumber <= 0 {
  5367. warehouse.StockMinNumber = 0
  5368. }
  5369. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5370. //查询该药品剩余库存
  5371. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5372. var over_count int64
  5373. for _, its := range infolist {
  5374. if its.MaxUnit == selfBasedrug.MaxUnit {
  5375. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5376. }
  5377. over_count += its.StockMaxNumber + its.StockMinNumber
  5378. }
  5379. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5380. drugflow := models.XtSelfDrugFlow{
  5381. WarehouseOutId: 0,
  5382. WarehouseOutOrderNumber: warehousing_order,
  5383. WarehousingOrder: warehousing_order,
  5384. DrugId: item.DrugId,
  5385. Number: warehouse.Number,
  5386. ProductDate: warehouse.ProductDate,
  5387. ExpireDate: warehouse.ExpiryDate,
  5388. Count: cha_count,
  5389. Price: warehouse.RetailPrice,
  5390. Status: 1,
  5391. Ctime: item.AdviceDate,
  5392. Mtime: time.Now().Unix(),
  5393. UserOrgId: item.UserOrgId,
  5394. Manufacturer: warehouse.Manufacturer,
  5395. Dealer: warehouse.Dealer,
  5396. BatchNumber: warehouse.BatchNumber,
  5397. MaxUnit: selfBasedrug.MinUnit,
  5398. ConsumableType: 20,
  5399. IsEdit: 1,
  5400. Creator: 0,
  5401. IsSys: 3,
  5402. WarehouseOutDetailId: drugWareInfo.ID,
  5403. AdviceId: item.ID,
  5404. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5405. StorehouseId: 0,
  5406. AdminUserId: creater,
  5407. LastPrice: warehouse.Price,
  5408. StockCount: "",
  5409. WarehousingDetailId: 0,
  5410. OverCount: over_count,
  5411. RetailPrice: item.Price, //手动出库出库价格
  5412. WarehousingId: warehouse.ID,
  5413. SystemTime: item.AdviceDate,
  5414. PatientId: item.PatientId,
  5415. Remark: "保存处方入库数据差",
  5416. OperateTime: time.Now().Unix(),
  5417. }
  5418. if warehouse.RetailPrice == 0 {
  5419. drugflow.Price = item.Price
  5420. }
  5421. service.CreateSelfDrugFlowOne(drugflow, tx)
  5422. var out_count int64
  5423. out_count = in_count - total_count
  5424. //
  5425. //fmt.Println("in_count------------------", in_count)
  5426. //fmt.Println("total_count------------------", total_count)
  5427. //添加出库数量
  5428. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5429. //查询剩余库存
  5430. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5431. var sum_count int64
  5432. for _, its := range stockInfo {
  5433. if its.MaxUnit == selfBasedrug.MaxUnit {
  5434. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5435. }
  5436. sum_count += its.StockMaxNumber + its.StockMinNumber
  5437. }
  5438. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5439. } else {
  5440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5441. return
  5442. }
  5443. }
  5444. }
  5445. }
  5446. }
  5447. }
  5448. }
  5449. tx.Commit()
  5450. if err == nil {
  5451. c.ServeSuccessJSON(map[string]interface{}{
  5452. "msg": "保存成功",
  5453. })
  5454. return
  5455. } else {
  5456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5457. return
  5458. }
  5459. }
  5460. }
  5461. //func (c *HisApiController) EditHisPrescription() {
  5462. // record_date := c.GetString("record_date")
  5463. // patient_id, _ := c.GetInt64("patient_id")
  5464. // reg_type, _ := c.GetInt64("reg_type")
  5465. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5466. // diagnose := c.GetString("diagnose")
  5467. // sick_type, _ := c.GetInt64("sick_type")
  5468. // sick_history := c.GetString("sick_history")
  5469. // doctor_id, _ := c.GetInt64("doctor", 0)
  5470. // department, _ := c.GetInt64("department", 0)
  5471. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5472. // p_type, _ := c.GetInt64("p_type")
  5473. //
  5474. // dataBody := make(map[string]interface{}, 0)
  5475. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5476. // if err != nil {
  5477. // utils.ErrorLog(err.Error())
  5478. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5479. // return
  5480. // }
  5481. //
  5482. // timeLayout := "2006-01-02"
  5483. // loc, _ := time.LoadLocation("Local")
  5484. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5485. // if err != nil {
  5486. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5487. // return
  5488. // }
  5489. // adminInfo := c.GetAdminUserInfo()
  5490. // recordDateTime := theTime.Unix()
  5491. //
  5492. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5493. //
  5494. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5495. // var hpInfo models.HisPrescriptionInfo
  5496. // if info.ID == 0 {
  5497. // var randNum int
  5498. // randNum = rand.Intn(10000) + 1000
  5499. // timestamp := time.Now().Unix()
  5500. // tempTime := time.Unix(timestamp, 0)
  5501. // timeFormat := tempTime.Format("20060102150405")
  5502. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5503. //
  5504. // hpInfo = models.HisPrescriptionInfo{
  5505. // UserOrgId: adminInfo.CurrentOrgId,
  5506. // RecordDate: theTime.Unix(),
  5507. // PatientId: patient_id,
  5508. // Status: 1,
  5509. // Ctime: time.Now().Unix(),
  5510. // Mtime: time.Now().Unix(),
  5511. // Creator: adminInfo.AdminUser.Id,
  5512. // Modifier: adminInfo.AdminUser.Id,
  5513. // Diagnosis: diagnose,
  5514. // SickHistory: sick_history,
  5515. // Departments: department,
  5516. // RegisterType: reg_type,
  5517. // PrescriptionNumber: p_number,
  5518. // PrescriptionStatus: 1,
  5519. // Doctor: role.UserName,
  5520. // DoctorId: doctor_id,
  5521. // SickType: sick_type,
  5522. // PType: p_type,
  5523. // }
  5524. // service.SavePatientPrescriptionInfo(hpInfo)
  5525. //
  5526. // } else {
  5527. // hpInfo = models.HisPrescriptionInfo{
  5528. // ID: info.ID,
  5529. // UserOrgId: adminInfo.CurrentOrgId,
  5530. // RecordDate: info.RecordDate,
  5531. // PatientId: info.PatientId,
  5532. // Status: 1,
  5533. // Ctime: info.Ctime,
  5534. // Mtime: time.Now().Unix(),
  5535. // Creator: info.Creator,
  5536. // Modifier: adminInfo.AdminUser.Id,
  5537. // Diagnosis: diagnose,
  5538. // SickHistory: sick_history,
  5539. // Departments: department,
  5540. // RegisterType: reg_type,
  5541. // PrescriptionNumber: info.PrescriptionNumber,
  5542. // Doctor: role.UserName,
  5543. // PrescriptionStatus: info.PrescriptionStatus,
  5544. // DoctorId: doctor_id,
  5545. // SickType: sick_type,
  5546. // PType: info.PType,
  5547. // }
  5548. // service.SavePatientPrescriptionInfo(hpInfo)
  5549. // }
  5550. //
  5551. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5552. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5553. //
  5554. // if len(prescriptions) > 0 {
  5555. // for _, item := range prescriptions {
  5556. // items := item.(map[string]interface{})
  5557. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5558. // utils.ErrorLog("id")
  5559. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5560. // return
  5561. // }
  5562. // id := int64(items["id"].(float64))
  5563. //
  5564. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5565. // utils.ErrorLog("type")
  5566. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5567. // return
  5568. // }
  5569. // types := int64(items["type"].(float64))
  5570. //
  5571. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5572. // utils.ErrorLog("med_type")
  5573. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5574. // return
  5575. // }
  5576. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5577. //
  5578. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5579. //
  5580. // ctime := time.Now().Unix()
  5581. //
  5582. // prescription := &models.HisPrescription{
  5583. // ID: id,
  5584. // PatientId: patient_id,
  5585. // UserOrgId: adminInfo.CurrentOrgId,
  5586. // RecordDate: recordDateTime,
  5587. // Ctime: ctime,
  5588. // Mtime: ctime,
  5589. // Type: types,
  5590. // Modifier: adminInfo.AdminUser.Id,
  5591. // Creator: adminInfo.AdminUser.Id,
  5592. // Status: 1,
  5593. // Doctor: role.UserName,
  5594. // HisPatientId: his_patient_id,
  5595. // OrderStatus: 1,
  5596. // BatchNumber: "",
  5597. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5598. // PType: hpInfo.PType,
  5599. // MedType: med_type,
  5600. // }
  5601. //
  5602. // if historyPrescription.ID > 0 {
  5603. // prescription.PreTime = historyPrescription.PreTime
  5604. //
  5605. // }
  5606. //
  5607. // service.SaveHisPrescription(prescription)
  5608. //
  5609. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5610. // advices := items["advices"].([]interface{})
  5611. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5612. // groupNo := int64(0)
  5613. // ctime := time.Now().Unix()
  5614. // mtime := ctime
  5615. // if len(advices) > 0 {
  5616. // for _, advice := range advices {
  5617. // var s models.HisDoctorAdviceInfo
  5618. // s.PrescriptionId = prescription.ID
  5619. // s.AdviceType = 2
  5620. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5621. // s.StopState = 2
  5622. // s.ExecutionState = 2
  5623. // s.AdviceDate = recordDateTime
  5624. // s.Status = 1
  5625. // s.UserOrgId = adminInfo.CurrentOrgId
  5626. // s.RecordDate = recordDateTime
  5627. // s.StartTime = prescription.PreTime
  5628. // s.Groupno = groupNo
  5629. // s.CreatedTime = ctime
  5630. // s.UpdatedTime = mtime
  5631. // s.PatientId = patient_id
  5632. // s.HisPatientId = his_patient_id
  5633. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5634. // if errcode > 0 {
  5635. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5636. // return
  5637. // }
  5638. //
  5639. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5640. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5641. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5642. // if s.Price == 0 {
  5643. // s.Price = lastWarehouse.RetailPrice
  5644. // }
  5645. // }
  5646. //
  5647. // service.CreateHisDoctorAdvice(&s)
  5648. // //记录日志
  5649. // byterequest, _ := json.Marshal(s)
  5650. // adviceLog := models.XtDoctorAdviceLog{
  5651. // UserOrgId: s.UserOrgId,
  5652. // PatientId: s.PatientId,
  5653. // AdminUserId: adminInfo.AdminUser.Id,
  5654. // Module: 1,
  5655. // ErrLog: string(byterequest),
  5656. // Status: 1,
  5657. // Ctime: time.Now().Unix(),
  5658. // Mtime: 0,
  5659. // Source: "电脑端his医嘱修改",
  5660. // RecordDate: s.AdviceDate,
  5661. // }
  5662. // service.CreateDoctorAdviceLog(adviceLog)
  5663. // redis := service.RedisClient()
  5664. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5665. // redis.Set(key, "", time.Second)
  5666. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5667. // fmt.Println("keyOne", keyOne)
  5668. // redis.Set(keyOne, "", time.Second)
  5669. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5670. // redis.Set(keySeven, "", time.Second)
  5671. // redis.Close()
  5672. //
  5673. // }
  5674. // }
  5675. // }
  5676. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5677. // projects := items["project"].([]interface{})
  5678. // if len(projects) > 0 {
  5679. // for _, project := range projects {
  5680. // var p models.HisPrescriptionProject
  5681. // p.PrescriptionId = prescription.ID
  5682. // p.Ctime = time.Now().Unix()
  5683. // p.Mtime = time.Now().Unix()
  5684. // p.PatientId = patient_id
  5685. // p.RecordDate = recordDateTime
  5686. // p.UserOrgId = adminInfo.CurrentOrgId
  5687. // p.HisPatientId = his_patient_id
  5688. // p.Status = 1
  5689. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5690. // if errcode > 0 {
  5691. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5692. // return
  5693. // }
  5694. // service.CreateHisProjectTwo(&p)
  5695. //
  5696. // //记录日志
  5697. // byterequest, _ := json.Marshal(p)
  5698. // adviceLog := models.XtDoctorAdviceLog{
  5699. // UserOrgId: p.UserOrgId,
  5700. // PatientId: p.PatientId,
  5701. // AdminUserId: adminInfo.AdminUser.Id,
  5702. // Module: 1,
  5703. // ErrLog: string(byterequest),
  5704. // Status: 1,
  5705. // Ctime: time.Now().Unix(),
  5706. // Mtime: 0,
  5707. // Source: "电脑端his项目修改",
  5708. // RecordDate: p.RecordDate,
  5709. // }
  5710. // service.CreateDoctorAdviceLog(adviceLog)
  5711. // }
  5712. // }
  5713. // }
  5714. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5715. // addition := items["addition"].([]interface{})
  5716. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5717. // ctime := time.Now().Unix()
  5718. // mtime := ctime
  5719. // if len(addition) > 0 {
  5720. // for _, item := range addition {
  5721. // var s models.HisAdditionalCharge
  5722. // s.PrescriptionId = prescription.ID
  5723. // s.Status = 1
  5724. // s.UserOrgId = adminInfo.CurrentOrgId
  5725. // s.RecordDate = recordDateTime
  5726. // s.CreatedTime = ctime
  5727. // s.UpdatedTime = mtime
  5728. // s.PatientId = patient_id
  5729. // s.HisPatientId = his_patient_id
  5730. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5731. // if errcode > 0 {
  5732. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5733. // return
  5734. // }
  5735. // service.CreateAdditionalCharge(&s)
  5736. // }
  5737. // }
  5738. // }
  5739. //
  5740. // }
  5741. // }
  5742. // }
  5743. // if err == nil {
  5744. // c.ServeSuccessJSON(map[string]interface{}{
  5745. // "msg": "保存成功",
  5746. // })
  5747. // return
  5748. //
  5749. // } else {
  5750. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5751. // return
  5752. // }
  5753. //}
  5754. func (c *HisApiController) DeletePrescription() {
  5755. prescription_id, _ := c.GetInt64("id")
  5756. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5757. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5758. ////同步到自备药
  5759. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5760. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5761. if selfPrescriptionOpen.IsOpen == 1 {
  5762. // 在函数结束时处理事务回滚
  5763. db := service.XTWriteDB()
  5764. tx := db.Begin()
  5765. defer func() {
  5766. if r := recover(); r != nil {
  5767. tx.Rollback()
  5768. } else {
  5769. tx.Commit()
  5770. }
  5771. }()
  5772. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5773. for _, item := range advicesList {
  5774. timeStr := time.Now().Format("2006-01-02")
  5775. timeArr := strings.Split(timeStr, "-")
  5776. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5777. total = total + 1
  5778. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5779. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5780. number = number + total
  5781. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5782. operation_time := time.Now().Unix()
  5783. creater := c.GetAdminUserInfo().AdminUser.Id
  5784. //创建一个出库单
  5785. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5786. WarehouseOutOrderNumber: warehousing_out_order,
  5787. OperationTime: operation_time,
  5788. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5789. Creater: creater,
  5790. Ctime: time.Now().Unix(),
  5791. Status: 1,
  5792. WarehouseOutTime: item.AdviceDate,
  5793. Type: 0,
  5794. PatientId: item.PatientId,
  5795. IsCheck: 1,
  5796. }
  5797. //查询今日是否有出库数据
  5798. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5799. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5800. if lastWarehouseOut.ID == 0 {
  5801. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5802. }
  5803. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5804. var total_count int64
  5805. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5806. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5807. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5808. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5809. }
  5810. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5811. total_count += prescribingNumberSeven
  5812. }
  5813. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5814. total_count += prescribingNumberSeven
  5815. }
  5816. //出库
  5817. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5818. WarehouseOutOrderNumber: warehousing_out_order,
  5819. WarehouseOutId: lastWarehouseOut.ID,
  5820. DrugId: item.DrugId,
  5821. Count: total_count,
  5822. Price: 0,
  5823. TotalPrice: 0,
  5824. Status: 1,
  5825. Ctime: item.AdviceDate,
  5826. Mtime: item.AdviceDate,
  5827. Remark: "",
  5828. OrgId: item.UserOrgId,
  5829. Type: 0,
  5830. Manufacturer: selfBasedrug.Manufacturer,
  5831. Dealer: selfBasedrug.Dealer,
  5832. RetailPrice: 0,
  5833. RetailTotalPrice: 0,
  5834. CountUnit: selfBasedrug.MinUnit,
  5835. ExpiryDate: 0,
  5836. ProductDate: 0,
  5837. Number: "",
  5838. BatchNumber: "",
  5839. IsSys: 1,
  5840. WarehouseInfoId: 0,
  5841. AdminUserId: 0,
  5842. StockCount: "",
  5843. IsCheck: 1,
  5844. SysRecordTime: item.AdviceDate,
  5845. PatientId: item.PatientId,
  5846. ClassType: "",
  5847. AdviceId: item.ID,
  5848. }
  5849. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5850. }
  5851. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5852. for _, it := range warehousingOutInfo {
  5853. //查询今日是否有出库数据
  5854. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5855. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5856. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5857. //出库逻辑
  5858. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5859. //查询剩余库存
  5860. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5861. var sum_count int64
  5862. for _, its := range stockInfo {
  5863. if its.MaxUnit == medical.MaxUnit {
  5864. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5865. }
  5866. sum_count += its.StockMaxNumber + its.StockMinNumber
  5867. }
  5868. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5869. }
  5870. }
  5871. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5872. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5873. //耗材保存处方出库
  5874. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5875. //已收费和已发药限制逻辑
  5876. isCharge := false
  5877. isMedicine := false
  5878. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5879. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5880. if new_prescription.IsMedicine == 1 {
  5881. isMedicine = true
  5882. }
  5883. for _, item := range new_prescriptions {
  5884. if item.OrderStatus == 4 {
  5885. isCharge = true
  5886. }
  5887. }
  5888. if p_err != nil {
  5889. if new_prescription.ID > 0 {
  5890. if new_prescription.OrderStatus == 2 {
  5891. isCharge = true
  5892. }
  5893. }
  5894. }
  5895. for _, item := range advices {
  5896. if item.IsMedicine == 1 {
  5897. isMedicine = true
  5898. }
  5899. }
  5900. if isCharge {
  5901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5902. return
  5903. }
  5904. if isMedicine {
  5905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5906. return
  5907. }
  5908. //已收费和已发药限制逻辑
  5909. if len(projects) > 0 {
  5910. for _, item := range projects {
  5911. service.DeletePrintInfo(item.ID) //删除打印信息
  5912. if goodOutConfig.IsOpen != 1 {
  5913. if stockConfig.IsOpen == 1 {
  5914. if item.Type == 3 && item.IsOut == 1 {
  5915. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5916. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5917. good.Total = good.Total + f_count
  5918. service.UpdateGoodInfo(&good)
  5919. operation_time := time.Now().Unix()
  5920. creater := c.GetAdminUserInfo().AdminUser.Id
  5921. //创建退库单
  5922. timeStr := time.Now().Format("2006-01-02")
  5923. timeArr := strings.Split(timeStr, "-")
  5924. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5925. total = total + 1
  5926. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5927. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5928. cancelStock := models.CancelStock{
  5929. OrderNumber: orderNumber,
  5930. OperaTime: operation_time,
  5931. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5932. Creater: creater,
  5933. Ctime: time.Now().Unix(),
  5934. Status: 1,
  5935. ReturnTime: item.RecordDate,
  5936. Type: 1,
  5937. StorehouseId: houseConfig.StorehouseOutInfo,
  5938. IsCheck: 1,
  5939. }
  5940. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5941. if msgerrkonde == gorm.ErrRecordNotFound {
  5942. service.AddSigleCancelStock(&cancelStock)
  5943. }
  5944. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5945. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5946. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5947. //查询该耗材是否出库
  5948. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5949. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5950. deaerler, _ := service.GetDealerById(info.Dealer)
  5951. var total_count int64
  5952. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5953. total_count += count
  5954. if info.ID > 0 {
  5955. if info.Count >= total_count {
  5956. //回退库存
  5957. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5958. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5959. var flush_count int64
  5960. for _, it := range goodList {
  5961. flush_count += it.StockCount
  5962. }
  5963. cancelStockInfo := models.CancelStockInfo{
  5964. GoodId: item.ProjectId,
  5965. CancelStockId: cancel.ID,
  5966. GoodTypeId: good.GoodTypeId,
  5967. Count: prescribingNumber,
  5968. Price: info.Price,
  5969. Total: 0,
  5970. ProductDate: info.ProductDate,
  5971. ExpiryDate: info.ExpiryDate,
  5972. Ctime: time.Now().Unix(),
  5973. Status: 1,
  5974. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5975. OrderNumber: cancel.OrderNumber,
  5976. Type: 0,
  5977. Dealer: deaerler.DealerName,
  5978. Manufacturer: manufacturer.ManufacturerName,
  5979. Number: info.Number,
  5980. RegisterAccount: "",
  5981. Remark: "",
  5982. WarehouseInfoId: info.WarehouseInfotId,
  5983. PatientId: info.PatientId,
  5984. RecordDate: info.SysRecordTime,
  5985. StorehouseId: houseConfig.StorehouseOutInfo,
  5986. IsCheck: 1,
  5987. }
  5988. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5989. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5990. flow := models.VmStockFlow{
  5991. WarehousingId: info.WarehouseInfotId,
  5992. GoodId: item.ProjectId,
  5993. Number: info.Number,
  5994. LicenseNumber: info.LicenseNumber,
  5995. Count: prescribingNumber,
  5996. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5997. PatientId: item.PatientId,
  5998. SystemTime: info.SysRecordTime,
  5999. ConsumableType: 7,
  6000. IsSys: 0,
  6001. WarehousingOrder: "",
  6002. WarehouseOutId: info.WarehouseOutId,
  6003. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6004. IsEdit: 0,
  6005. CancelStockId: cancel.ID,
  6006. CancelOrderNumber: cancel.OrderNumber,
  6007. Manufacturer: manufacturer.ID,
  6008. Dealer: 0,
  6009. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6010. UpdateCreator: 0,
  6011. Status: 1,
  6012. Ctime: time.Now().Unix(),
  6013. Mtime: 0,
  6014. Price: info.Price,
  6015. WarehousingDetailId: info.WarehouseInfotId,
  6016. WarehouseOutDetailId: info.ID,
  6017. CancelOutDetailId: cancelInfo.ID,
  6018. ProductDate: info.ProductDate,
  6019. ExpireDate: info.ExpiryDate,
  6020. StorehouseId: houseConfig.StorehouseOutInfo,
  6021. OverCount: flush_count,
  6022. OperateTime: time.Now().Unix(),
  6023. }
  6024. service.CreateStockFlowOne(flow)
  6025. //退库数量增加
  6026. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6027. //出库数量减少
  6028. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6029. }
  6030. if info.Count < total_count {
  6031. //回退库存
  6032. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6033. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6034. var flush_count int64
  6035. for _, it := range goodList {
  6036. flush_count += it.StockCount
  6037. }
  6038. cancelStockInfo := models.CancelStockInfo{
  6039. GoodId: item.ProjectId,
  6040. CancelStockId: cancel.ID,
  6041. GoodTypeId: good.GoodTypeId,
  6042. Count: info.Count,
  6043. Price: info.Price,
  6044. Total: 0,
  6045. ProductDate: info.ProductDate,
  6046. ExpiryDate: info.ExpiryDate,
  6047. Ctime: time.Now().Unix(),
  6048. Status: 1,
  6049. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6050. OrderNumber: cancel.OrderNumber,
  6051. Type: 0,
  6052. Dealer: deaerler.DealerName,
  6053. Manufacturer: manufacturer.ManufacturerName,
  6054. Number: info.Number,
  6055. RegisterAccount: "",
  6056. Remark: "",
  6057. WarehouseInfoId: info.WarehouseInfotId,
  6058. PatientId: info.PatientId,
  6059. RecordDate: info.SysRecordTime,
  6060. StorehouseId: houseConfig.StorehouseOutInfo,
  6061. IsCheck: 1,
  6062. }
  6063. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6064. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6065. flow := models.VmStockFlow{
  6066. WarehousingId: info.WarehouseInfotId,
  6067. GoodId: item.ProjectId,
  6068. Number: info.Number,
  6069. LicenseNumber: info.LicenseNumber,
  6070. Count: info.Count,
  6071. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6072. PatientId: item.PatientId,
  6073. SystemTime: info.SysRecordTime,
  6074. ConsumableType: 7,
  6075. IsSys: 0,
  6076. WarehousingOrder: "",
  6077. WarehouseOutId: info.WarehouseOutId,
  6078. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6079. IsEdit: 0,
  6080. CancelStockId: cancel.ID,
  6081. CancelOrderNumber: cancel.OrderNumber,
  6082. Manufacturer: manufacturer.ID,
  6083. Dealer: 0,
  6084. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6085. UpdateCreator: 0,
  6086. Status: 1,
  6087. Ctime: time.Now().Unix(),
  6088. Mtime: 0,
  6089. Price: info.Price,
  6090. WarehousingDetailId: info.WarehouseInfotId,
  6091. WarehouseOutDetailId: info.ID,
  6092. CancelOutDetailId: cancelInfo.ID,
  6093. ProductDate: info.ProductDate,
  6094. ExpireDate: info.ExpiryDate,
  6095. StorehouseId: houseConfig.StorehouseOutInfo,
  6096. OverCount: flush_count,
  6097. OperateTime: time.Now().Unix(),
  6098. }
  6099. service.CreateStockFlowOne(flow)
  6100. //退库数量增加
  6101. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6102. //出库数量减少
  6103. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6104. }
  6105. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6106. var flush_count int64
  6107. for _, it := range goodList {
  6108. flush_count += it.StockCount
  6109. }
  6110. //查询已出库数量
  6111. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6112. if prescribingNumber < dialysisInfo.Count {
  6113. //改变数量
  6114. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6115. }
  6116. if prescribingNumber >= dialysisInfo.Count {
  6117. //删除出库表
  6118. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6119. }
  6120. //更新库存
  6121. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6122. //更新基础库库存
  6123. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6124. }
  6125. }
  6126. }
  6127. }
  6128. //保存耗材出库
  6129. if goodOutConfig.IsOpen == 1 {
  6130. if item.Type == 3 {
  6131. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6132. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6133. good.Total = good.Total + f_count
  6134. service.UpdateGoodInfo(&good)
  6135. operation_time := time.Now().Unix()
  6136. creater := c.GetAdminUserInfo().AdminUser.Id
  6137. //创建退库单
  6138. timeStr := time.Now().Format("2006-01-02")
  6139. timeArr := strings.Split(timeStr, "-")
  6140. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6141. total = total + 1
  6142. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6143. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6144. cancelStock := models.CancelStock{
  6145. OrderNumber: orderNumber,
  6146. OperaTime: operation_time,
  6147. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6148. Creater: creater,
  6149. Ctime: time.Now().Unix(),
  6150. Status: 1,
  6151. ReturnTime: item.RecordDate,
  6152. Type: 1,
  6153. StorehouseId: houseConfig.StorehouseOutInfo,
  6154. IsCheck: 1,
  6155. }
  6156. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6157. if msgerrkonde == gorm.ErrRecordNotFound {
  6158. service.AddSigleCancelStock(&cancelStock)
  6159. }
  6160. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6161. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6162. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6163. //查询该耗材是否出库
  6164. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6165. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6166. deaerler, _ := service.GetDealerById(info.Dealer)
  6167. var total_count int64
  6168. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6169. total_count += count
  6170. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6171. var flush_count int64
  6172. for _, it := range goodList {
  6173. flush_count += it.StockCount
  6174. }
  6175. fmt.Println("历史出库数据", info.Count)
  6176. fmt.Println("出库数量", total_count)
  6177. if info.ID > 0 {
  6178. cancelStockInfo := models.CancelStockInfo{
  6179. GoodId: item.ProjectId,
  6180. CancelStockId: cancel.ID,
  6181. GoodTypeId: good.GoodTypeId,
  6182. Count: prescribingNumber,
  6183. Price: info.Price,
  6184. Total: 0,
  6185. ProductDate: info.ProductDate,
  6186. ExpiryDate: info.ExpiryDate,
  6187. Ctime: time.Now().Unix(),
  6188. Status: 1,
  6189. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6190. OrderNumber: cancel.OrderNumber,
  6191. Type: 0,
  6192. Dealer: deaerler.DealerName,
  6193. Manufacturer: manufacturer.ManufacturerName,
  6194. Number: info.Number,
  6195. RegisterAccount: "",
  6196. Remark: "",
  6197. WarehouseInfoId: info.WarehouseInfotId,
  6198. PatientId: info.PatientId,
  6199. RecordDate: info.SysRecordTime,
  6200. StorehouseId: houseConfig.StorehouseOutInfo,
  6201. IsCheck: 1,
  6202. }
  6203. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6204. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6205. //查询出库数量
  6206. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6207. //出库数据 大于 退库数量
  6208. if len(list) > 0 {
  6209. for _, it := range list {
  6210. //回退库存
  6211. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6212. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6213. var flush_count_one int64
  6214. for _, it := range goodList {
  6215. flush_count_one += it.StockCount
  6216. }
  6217. //查询该批次是否有退库数据
  6218. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6219. creater := c.GetAdminUserInfo().AdminUser.Id
  6220. flow := models.VmStockFlow{
  6221. WarehousingId: it.WarehouseInfotId,
  6222. GoodId: it.GoodId,
  6223. Number: it.Number,
  6224. LicenseNumber: it.LicenseNumber,
  6225. Count: it.Count,
  6226. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6227. PatientId: it.PatientId,
  6228. SystemTime: it.SysRecordTime,
  6229. ConsumableType: 7,
  6230. IsSys: 0,
  6231. WarehousingOrder: "",
  6232. WarehouseOutId: it.WarehouseOutId,
  6233. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6234. IsEdit: 0,
  6235. CancelStockId: cancel.ID,
  6236. CancelOrderNumber: cancel.OrderNumber,
  6237. Manufacturer: manufacturer.ID,
  6238. Dealer: 0,
  6239. Creator: creater,
  6240. UpdateCreator: 0,
  6241. Status: 1,
  6242. Ctime: time.Now().Unix(),
  6243. Mtime: 0,
  6244. Price: it.Price,
  6245. WarehousingDetailId: it.WarehouseInfotId,
  6246. WarehouseOutDetailId: it.ID,
  6247. CancelOutDetailId: cancelInfo.ID,
  6248. ProductDate: it.ProductDate,
  6249. ExpireDate: it.ExpiryDate,
  6250. StorehouseId: houseConfig.StorehouseOutInfo,
  6251. OverCount: flush_count_one,
  6252. OperateTime: time.Now().Unix(),
  6253. }
  6254. service.CreateStockFlowOne(flow)
  6255. //if flow.ID > 0 {
  6256. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6257. //}
  6258. }
  6259. }
  6260. //flow := models.VmStockFlow{
  6261. // WarehousingId: info.WarehouseInfotId,
  6262. // GoodId: item.ProjectId,
  6263. // Number: info.Number,
  6264. // LicenseNumber: info.LicenseNumber,
  6265. // Count: prescribingNumber,
  6266. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6267. // PatientId: item.PatientId,
  6268. // SystemTime: info.SysRecordTime,
  6269. // ConsumableType: 7,
  6270. // IsSys: 0,
  6271. // WarehousingOrder: "",
  6272. // WarehouseOutId: info.WarehouseOutId,
  6273. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6274. // IsEdit: 0,
  6275. // CancelStockId: cancel.ID,
  6276. // CancelOrderNumber: cancel.OrderNumber,
  6277. // Manufacturer: manufacturer.ID,
  6278. // Dealer: 0,
  6279. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6280. // UpdateCreator: 0,
  6281. // Status: 1,
  6282. // Ctime: time.Now().Unix(),
  6283. // Mtime: 0,
  6284. // Price: info.Price,
  6285. // WarehousingDetailId: info.WarehouseInfotId,
  6286. // WarehouseOutDetailId: info.ID,
  6287. // CancelOutDetailId: cancelInfo.ID,
  6288. // ProductDate: info.ProductDate,
  6289. // ExpireDate: info.ExpiryDate,
  6290. // StorehouseId: houseConfig.StorehouseOutInfo,
  6291. // OverCount: flush_count,
  6292. //}
  6293. //service.CreateStockFlowOne(flow)
  6294. //退库数量增加
  6295. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6296. //出库数量减少
  6297. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6298. //查询已出库数量
  6299. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6300. if prescribingNumber < dialysisInfo.Count {
  6301. //改变数量
  6302. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6303. }
  6304. if prescribingNumber >= dialysisInfo.Count {
  6305. //删除出库表
  6306. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6307. }
  6308. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6309. var flush_count_one int64
  6310. for _, it := range goodList {
  6311. flush_count_one += it.StockCount
  6312. }
  6313. //更新库存
  6314. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6315. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6316. //更新基础库库存
  6317. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6318. }
  6319. }
  6320. }
  6321. }
  6322. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6323. fmt.Println(err)
  6324. }
  6325. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6326. fmt.Println(err)
  6327. if len(advices) > 0 {
  6328. for _, item := range advices {
  6329. redis := service.RedisClient()
  6330. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6331. redis.Set(keyFive, "", time.Second)
  6332. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6333. redis.Set(keyOne, "", time.Second)
  6334. redis.Close()
  6335. }
  6336. }
  6337. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6338. if len(advices) > 0 {
  6339. for _, item := range advices {
  6340. creater := c.GetAdminUserInfo().AdminUser.Id
  6341. service.DrugAutoAddCancelInfo(item, creater)
  6342. }
  6343. }
  6344. } else {
  6345. if drugOutConfig.IsOpen == 1 {
  6346. if len(advices) > 0 {
  6347. for _, item := range advices {
  6348. creater := c.GetAdminUserInfo().AdminUser.Id
  6349. service.DrugAutoAddCancelInfo(item, creater)
  6350. }
  6351. }
  6352. } else {
  6353. if len(advices) > 0 {
  6354. for _, item := range advices {
  6355. creater := c.GetAdminUserInfo().AdminUser.Id
  6356. service.DrugAutoAddCancelInfo(item, creater)
  6357. }
  6358. }
  6359. }
  6360. }
  6361. c.ServeSuccessJSON(map[string]interface{}{
  6362. "msg": "删除成功",
  6363. })
  6364. return
  6365. }
  6366. func (c *HisApiController) DeleteDoctorAdvice() {
  6367. id, _ := c.GetInt64("id")
  6368. advice, _ := service.GetHisDoctorAdvicesById(id)
  6369. ////同步到自备药
  6370. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6371. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6372. if selfPrescriptionOpen.IsOpen == 1 {
  6373. db := service.XTWriteDB()
  6374. tx := db.Begin()
  6375. defer func() {
  6376. if r := recover(); r != nil {
  6377. tx.Rollback()
  6378. } else {
  6379. tx.Commit()
  6380. }
  6381. }()
  6382. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6383. var total_count int64
  6384. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6385. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6386. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6387. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6388. }
  6389. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6390. total_count += prescribingNumberSeven
  6391. }
  6392. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6393. total_count += prescribingNumberSeven
  6394. }
  6395. timeStr := time.Now().Format("2006-01-02")
  6396. timeArr := strings.Split(timeStr, "-")
  6397. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6398. total = total + 1
  6399. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6400. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6401. number = number + total
  6402. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6403. operation_time := time.Now().Unix()
  6404. creater := c.GetAdminUserInfo().AdminUser.Id
  6405. //创建一个出库单
  6406. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6407. WarehouseOutOrderNumber: warehousing_out_order,
  6408. OperationTime: operation_time,
  6409. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6410. Creater: creater,
  6411. Ctime: time.Now().Unix(),
  6412. Status: 1,
  6413. WarehouseOutTime: advice.AdviceDate,
  6414. Type: 0,
  6415. PatientId: advice.PatientId,
  6416. IsCheck: 1,
  6417. }
  6418. //查询今日是否有出库数据
  6419. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6420. if lastWarehouseOut.ID == 0 {
  6421. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6422. }
  6423. //出库
  6424. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6425. WarehouseOutId: lastWarehouseOut.ID,
  6426. WarehouseOutOrderNumber: warehousing_out_order,
  6427. DrugId: advice.DrugId,
  6428. Count: total_count,
  6429. Price: 0,
  6430. TotalPrice: 0,
  6431. Status: 1,
  6432. Ctime: advice.AdviceDate,
  6433. Mtime: advice.AdviceDate,
  6434. Remark: "",
  6435. OrgId: advice.UserOrgId,
  6436. Type: 0,
  6437. Manufacturer: selfBasedrug.Manufacturer,
  6438. Dealer: selfBasedrug.Dealer,
  6439. RetailPrice: 0,
  6440. RetailTotalPrice: 0,
  6441. CountUnit: advice.PrescribingNumberUnit,
  6442. ExpiryDate: 0,
  6443. ProductDate: 0,
  6444. Number: "",
  6445. BatchNumber: "",
  6446. IsSys: 0,
  6447. WarehouseInfoId: 0,
  6448. AdminUserId: 0,
  6449. StockCount: "",
  6450. IsCheck: 1,
  6451. SysRecordTime: advice.AdviceDate,
  6452. PatientId: advice.PatientId,
  6453. AdviceId: advice.ID,
  6454. ClassType: "",
  6455. }
  6456. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6457. for _, it := range warehousingOutInfo {
  6458. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6459. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6460. //出库逻辑
  6461. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6462. //查询剩余库存
  6463. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6464. var sum_count int64
  6465. for _, its := range stockInfo {
  6466. if its.MaxUnit == medical.MaxUnit {
  6467. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6468. }
  6469. sum_count += its.StockMaxNumber + its.StockMinNumber
  6470. }
  6471. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6472. }
  6473. }
  6474. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6475. //已收费和已发药的限制逻辑
  6476. isCharge := false
  6477. isMedicine := false
  6478. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6479. //获取今天该患者所有处方,判断是否发药或者收费
  6480. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6481. //for _, item := range new_prescriptions {
  6482. if new_prescription.IsMedicine == 1 {
  6483. isMedicine = true
  6484. }
  6485. //}
  6486. for _, item := range new_prescriptions {
  6487. if item.OrderStatus == 4 {
  6488. isCharge = true
  6489. }
  6490. }
  6491. if isMedicine {
  6492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6493. return
  6494. }
  6495. if isCharge {
  6496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6497. return
  6498. }
  6499. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6500. for _, item := range advices {
  6501. if item.IsMedicine == 1 {
  6502. isMedicine = true
  6503. }
  6504. }
  6505. if isMedicine {
  6506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6507. return
  6508. }
  6509. if new_prescription.ID > 0 {
  6510. if new_prescription.OrderStatus == 2 {
  6511. isCharge = true
  6512. }
  6513. }
  6514. if isCharge {
  6515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6516. return
  6517. }
  6518. //已收费和已发药的限制逻辑
  6519. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6520. redis := service.RedisClient()
  6521. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6522. redis.Set(keyFive, "", time.Second)
  6523. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6524. redis.Set(keyOne, "", time.Second)
  6525. defer redis.Close()
  6526. if err == nil {
  6527. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6528. //查询是否在处方中出库
  6529. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6530. if openConfig.IsOpen != 1 {
  6531. //判断该医嘱是否执行了
  6532. if advice.ExecutionState == 1 {
  6533. creater := c.GetAdminUserInfo().AdminUser.Id
  6534. service.DrugAutoAddCancelInfo(&advice, creater)
  6535. }
  6536. }
  6537. //开启保存处方扣减功能
  6538. if openConfig.IsOpen == 1 {
  6539. creater := c.GetAdminUserInfo().AdminUser.Id
  6540. service.DrugAutoAddCancelInfo(&advice, creater)
  6541. }
  6542. } else {
  6543. if drugOutConfig.IsOpen == 1 {
  6544. //查询是否在处方中出库
  6545. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6546. if openConfig.IsOpen != 1 {
  6547. //判断该医嘱是否执行了
  6548. if advice.ExecutionState == 1 {
  6549. creater := c.GetAdminUserInfo().AdminUser.Id
  6550. service.DrugAutoAddCancelInfo(&advice, creater)
  6551. }
  6552. }
  6553. //开启保存处方扣减功能
  6554. if openConfig.IsOpen == 1 {
  6555. creater := c.GetAdminUserInfo().AdminUser.Id
  6556. service.DrugAutoAddCancelInfo(&advice, creater)
  6557. }
  6558. } else {
  6559. //判断该医嘱是否执行了
  6560. if advice.ExecutionState == 1 {
  6561. creater := c.GetAdminUserInfo().AdminUser.Id
  6562. service.DrugAutoAddCancelInfo(&advice, creater)
  6563. }
  6564. }
  6565. }
  6566. c.ServeSuccessJSON(map[string]interface{}{
  6567. "msg": "删除成功",
  6568. })
  6569. return
  6570. } else {
  6571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6572. return
  6573. }
  6574. }
  6575. func (c *HisApiController) DeleteProject() {
  6576. id, _ := c.GetInt64("id")
  6577. adminInfo := c.GetAdminUserInfo()
  6578. project, _ := service.GetHisProjectByID(id)
  6579. // var consumable models.DialysisBeforePrepare
  6580. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6581. //耗材保存处方出库
  6582. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6583. isCharge := false
  6584. isMedicine := false
  6585. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6586. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6587. for _, item := range new_prescriptions {
  6588. if item.IsMedicine == 1 {
  6589. isMedicine = true
  6590. }
  6591. }
  6592. for _, item := range new_prescriptions {
  6593. if item.OrderStatus == 4 {
  6594. isCharge = true
  6595. }
  6596. }
  6597. if isMedicine {
  6598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6599. return
  6600. }
  6601. if isCharge {
  6602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6603. return
  6604. }
  6605. if new_prescription.ID > 0 {
  6606. if new_prescription.OrderStatus == 2 {
  6607. isCharge = true
  6608. }
  6609. }
  6610. if isCharge {
  6611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6612. return
  6613. }
  6614. service.DeletePrintInfo(id)
  6615. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6616. label.Status = 0
  6617. service.CreateHisLabelRecordTwo(&label)
  6618. fmt.Println(goodOutConfig.IsOpen)
  6619. if goodOutConfig.IsOpen != 1 {
  6620. if stockConfig.IsOpen == 1 {
  6621. if project.Type == 2 {
  6622. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6623. fmt.Println(err)
  6624. }
  6625. if project.Type == 3 && project.IsOut == 1 {
  6626. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6627. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6628. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6629. operation_time := time.Now().Unix()
  6630. creater := adminInfo.AdminUser.Id
  6631. //创建退库单
  6632. timeStr := time.Now().Format("2006-01-02")
  6633. timeArr := strings.Split(timeStr, "-")
  6634. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6635. total = total + 1
  6636. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6637. cancelStock := models.CancelStock{
  6638. OrderNumber: orderNumber,
  6639. OperaTime: operation_time,
  6640. OrgId: adminInfo.CurrentOrgId,
  6641. Creater: creater,
  6642. Ctime: time.Now().Unix(),
  6643. Status: 1,
  6644. ReturnTime: project.RecordDate,
  6645. Type: 1,
  6646. StorehouseId: houseConfig.StorehouseOutInfo,
  6647. IsCheck: 1,
  6648. }
  6649. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6650. if msgerrkonde == gorm.ErrRecordNotFound {
  6651. service.AddSigleCancelStock(&cancelStock)
  6652. }
  6653. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6654. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6655. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6656. //查询是否有出库
  6657. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6658. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6659. deaerler, _ := service.GetDealerById(info.Dealer)
  6660. if info.ID > 0 {
  6661. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6662. if info.Count >= prescribingNumber {
  6663. cancelStockInfo := models.CancelStockInfo{
  6664. GoodId: project.ProjectId,
  6665. CancelStockId: cancel.ID,
  6666. GoodTypeId: good.GoodTypeId,
  6667. Count: prescribingNumber,
  6668. Price: info.Price,
  6669. Total: 0,
  6670. ProductDate: info.ProductDate,
  6671. ExpiryDate: info.ExpiryDate,
  6672. Ctime: time.Now().Unix(),
  6673. Status: 1,
  6674. OrgId: adminInfo.CurrentOrgId,
  6675. OrderNumber: cancel.OrderNumber,
  6676. Type: 0,
  6677. Dealer: deaerler.DealerName,
  6678. Manufacturer: manufacturer.ManufacturerName,
  6679. Number: info.Number,
  6680. RegisterAccount: "",
  6681. Remark: "",
  6682. WarehouseInfoId: info.WarehouseInfotId,
  6683. PatientId: info.PatientId,
  6684. RecordDate: info.SysRecordTime,
  6685. StorehouseId: houseConfig.StorehouseOutInfo,
  6686. IsCheck: 1,
  6687. }
  6688. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6689. //回退库存
  6690. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6691. //退库数量增加
  6692. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6693. //出库数量减少
  6694. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6695. }
  6696. if info.Count < prescribingNumber {
  6697. cancelStockInfo := models.CancelStockInfo{
  6698. GoodId: project.ProjectId,
  6699. CancelStockId: cancel.ID,
  6700. GoodTypeId: good.GoodTypeId,
  6701. Count: info.Count,
  6702. Price: info.Price,
  6703. Total: 0,
  6704. ProductDate: info.ProductDate,
  6705. ExpiryDate: info.ExpiryDate,
  6706. Ctime: time.Now().Unix(),
  6707. Status: 1,
  6708. OrgId: adminInfo.CurrentOrgId,
  6709. OrderNumber: cancel.OrderNumber,
  6710. Type: 0,
  6711. Dealer: deaerler.DealerName,
  6712. Manufacturer: manufacturer.ManufacturerName,
  6713. Number: info.Number,
  6714. RegisterAccount: "",
  6715. Remark: "",
  6716. WarehouseInfoId: info.WarehouseInfotId,
  6717. PatientId: info.PatientId,
  6718. RecordDate: info.SysRecordTime,
  6719. StorehouseId: houseConfig.StorehouseOutInfo,
  6720. IsCheck: 1,
  6721. }
  6722. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6723. //回退库存
  6724. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6725. //退库数量增加
  6726. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6727. //出库数量减少
  6728. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6729. }
  6730. //查询剩余库存
  6731. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6732. var over_count int64
  6733. for _, it := range goodList {
  6734. over_count += it.StockCount
  6735. }
  6736. //出库数据 大于 退库数量
  6737. if info.Count >= prescribingNumber {
  6738. flow := models.VmStockFlow{
  6739. WarehousingId: info.WarehouseInfotId,
  6740. GoodId: project.ProjectId,
  6741. Number: info.Number,
  6742. LicenseNumber: info.LicenseNumber,
  6743. Count: prescribingNumber,
  6744. UserOrgId: adminInfo.CurrentOrgId,
  6745. PatientId: project.PatientId,
  6746. SystemTime: info.SysRecordTime,
  6747. ConsumableType: 7,
  6748. IsSys: 0,
  6749. WarehousingOrder: "",
  6750. WarehouseOutId: info.WarehouseOutId,
  6751. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6752. IsEdit: 0,
  6753. CancelStockId: cancel.ID,
  6754. CancelOrderNumber: cancel.OrderNumber,
  6755. Manufacturer: manufacturer.ID,
  6756. Dealer: 0,
  6757. Creator: adminInfo.AdminUser.Id,
  6758. UpdateCreator: 0,
  6759. Status: 1,
  6760. Ctime: time.Now().Unix(),
  6761. Mtime: 0,
  6762. Price: info.Price,
  6763. WarehousingDetailId: info.WarehouseInfotId,
  6764. WarehouseOutDetailId: info.ID,
  6765. CancelOutDetailId: cancelInfo.ID,
  6766. ProductDate: info.ProductDate,
  6767. ExpireDate: info.ExpiryDate,
  6768. StorehouseId: houseConfig.StorehouseOutInfo,
  6769. OverCount: over_count,
  6770. OperateTime: time.Now().Unix(),
  6771. }
  6772. service.CreateStockFlowOne(flow)
  6773. }
  6774. //出库数据小于退库数据
  6775. if info.Count < prescribingNumber {
  6776. flow := models.VmStockFlow{
  6777. WarehousingId: info.WarehouseInfotId,
  6778. GoodId: project.ProjectId,
  6779. Number: info.Number,
  6780. LicenseNumber: info.LicenseNumber,
  6781. Count: info.Count,
  6782. UserOrgId: adminInfo.CurrentOrgId,
  6783. PatientId: project.PatientId,
  6784. SystemTime: info.SysRecordTime,
  6785. ConsumableType: 7,
  6786. IsSys: 0,
  6787. WarehousingOrder: "",
  6788. WarehouseOutId: info.WarehouseOutId,
  6789. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6790. IsEdit: 0,
  6791. CancelStockId: cancel.ID,
  6792. CancelOrderNumber: cancel.OrderNumber,
  6793. Manufacturer: manufacturer.ID,
  6794. Dealer: 0,
  6795. Creator: adminInfo.AdminUser.Id,
  6796. UpdateCreator: 0,
  6797. Status: 1,
  6798. Ctime: time.Now().Unix(),
  6799. Mtime: 0,
  6800. Price: info.Price,
  6801. WarehousingDetailId: info.WarehouseInfotId,
  6802. WarehouseOutDetailId: info.ID,
  6803. CancelOutDetailId: cancelInfo.ID,
  6804. ProductDate: info.ProductDate,
  6805. ExpireDate: info.ExpiryDate,
  6806. StorehouseId: houseConfig.StorehouseOutInfo,
  6807. OverCount: over_count,
  6808. OperateTime: time.Now().Unix(),
  6809. }
  6810. service.CreateStockFlowOne(flow)
  6811. }
  6812. //查询已出库数量
  6813. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6814. if prescribingNumber < dialysisInfo.Count {
  6815. //改变数量
  6816. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6817. }
  6818. if prescribingNumber >= dialysisInfo.Count {
  6819. //删除出库表
  6820. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6821. }
  6822. //更新剩余库存
  6823. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6824. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6825. var total_count_one int64
  6826. for _, it := range stockList {
  6827. total_count_one += it.StockCount
  6828. }
  6829. //基础库插入数据
  6830. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6831. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6832. var flush_count int64
  6833. for _, it := range goodListOne {
  6834. flush_count += it.StockCount
  6835. }
  6836. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6837. if errs != nil {
  6838. goodErrcode := models.XtGoodErrcode{
  6839. UserOrgId: project.UserOrgId,
  6840. Errcode: "手动出库更新剩余出库失败",
  6841. GoodId: project.ProjectId,
  6842. Status: 1,
  6843. Ctime: time.Now().Unix(),
  6844. Mtime: 0,
  6845. Count: 0,
  6846. StockCount: 0,
  6847. Creater: creater,
  6848. BatchNumberId: 0,
  6849. WarehouseOutId: 0,
  6850. }
  6851. service.CreateGoodErrcode(goodErrcode)
  6852. }
  6853. }
  6854. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6855. fmt.Println(err)
  6856. } else {
  6857. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6858. fmt.Println(err)
  6859. }
  6860. } else {
  6861. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6862. fmt.Println(err)
  6863. }
  6864. }
  6865. //保存处方出库
  6866. if goodOutConfig.IsOpen == 1 {
  6867. if project.Type == 3 {
  6868. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6869. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6870. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6871. operation_time := time.Now().Unix()
  6872. creater := adminInfo.AdminUser.Id
  6873. //创建退库单
  6874. timeStr := time.Now().Format("2006-01-02")
  6875. timeArr := strings.Split(timeStr, "-")
  6876. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6877. total = total + 1
  6878. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6879. cancelStock := models.CancelStock{
  6880. OrderNumber: orderNumber,
  6881. OperaTime: operation_time,
  6882. OrgId: adminInfo.CurrentOrgId,
  6883. Creater: creater,
  6884. Ctime: time.Now().Unix(),
  6885. Status: 1,
  6886. ReturnTime: project.RecordDate,
  6887. Type: 1,
  6888. StorehouseId: houseConfig.StorehouseOutInfo,
  6889. IsCheck: 1,
  6890. }
  6891. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6892. if msgerrkonde == gorm.ErrRecordNotFound {
  6893. service.AddSigleCancelStock(&cancelStock)
  6894. }
  6895. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6896. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6897. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6898. //获取出库数据
  6899. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6900. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6901. deaerler, _ := service.GetDealerById(info.Dealer)
  6902. if info.ID > 0 {
  6903. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6904. if info.Count >= prescribingNumber {
  6905. cancelStockInfo := models.CancelStockInfo{
  6906. GoodId: project.ProjectId,
  6907. CancelStockId: cancel.ID,
  6908. GoodTypeId: good.GoodTypeId,
  6909. Count: prescribingNumber,
  6910. Price: info.Price,
  6911. Total: 0,
  6912. ProductDate: info.ProductDate,
  6913. ExpiryDate: info.ExpiryDate,
  6914. Ctime: time.Now().Unix(),
  6915. Status: 1,
  6916. OrgId: adminInfo.CurrentOrgId,
  6917. OrderNumber: cancel.OrderNumber,
  6918. Type: 0,
  6919. Dealer: deaerler.DealerName,
  6920. Manufacturer: manufacturer.ManufacturerName,
  6921. Number: info.Number,
  6922. RegisterAccount: "",
  6923. Remark: "",
  6924. WarehouseInfoId: info.WarehouseInfotId,
  6925. PatientId: info.PatientId,
  6926. RecordDate: info.SysRecordTime,
  6927. StorehouseId: houseConfig.StorehouseOutInfo,
  6928. IsCheck: 1,
  6929. }
  6930. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6931. //退库数量增加
  6932. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6933. //出库数量减少
  6934. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6935. }
  6936. if info.Count < prescribingNumber {
  6937. cancelStockInfo := models.CancelStockInfo{
  6938. GoodId: project.ProjectId,
  6939. CancelStockId: cancel.ID,
  6940. GoodTypeId: good.GoodTypeId,
  6941. Count: prescribingNumber,
  6942. Price: info.Price,
  6943. Total: 0,
  6944. ProductDate: info.ProductDate,
  6945. ExpiryDate: info.ExpiryDate,
  6946. Ctime: time.Now().Unix(),
  6947. Status: 1,
  6948. OrgId: adminInfo.CurrentOrgId,
  6949. OrderNumber: cancel.OrderNumber,
  6950. Type: 0,
  6951. Dealer: deaerler.DealerName,
  6952. Manufacturer: manufacturer.ManufacturerName,
  6953. Number: info.Number,
  6954. RegisterAccount: "",
  6955. Remark: "",
  6956. WarehouseInfoId: info.WarehouseInfotId,
  6957. PatientId: info.PatientId,
  6958. RecordDate: info.SysRecordTime,
  6959. StorehouseId: houseConfig.StorehouseOutInfo,
  6960. IsCheck: 1,
  6961. }
  6962. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6963. //回退库存
  6964. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6965. }
  6966. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6967. var over_count int64
  6968. for _, it := range goodList {
  6969. over_count += it.StockCount
  6970. }
  6971. //查询出库数量
  6972. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6973. //出库数据 大于 退库数量
  6974. if len(list) > 0 {
  6975. for _, it := range list {
  6976. //回退库存
  6977. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6978. //退库数量增加
  6979. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6980. //出库数量减少
  6981. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6982. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6983. var over_count_one int64
  6984. for _, it := range goodList {
  6985. over_count_one += it.StockCount
  6986. }
  6987. //查询该批次是否有退库数据
  6988. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6989. flow := models.VmStockFlow{
  6990. WarehousingId: it.WarehouseInfotId,
  6991. GoodId: it.GoodId,
  6992. Number: it.Number,
  6993. LicenseNumber: it.LicenseNumber,
  6994. Count: it.Count,
  6995. UserOrgId: adminInfo.CurrentOrgId,
  6996. PatientId: it.PatientId,
  6997. SystemTime: it.SysRecordTime,
  6998. ConsumableType: 7,
  6999. IsSys: 0,
  7000. WarehousingOrder: "",
  7001. WarehouseOutId: it.WarehouseOutId,
  7002. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7003. IsEdit: 0,
  7004. CancelStockId: cancel.ID,
  7005. CancelOrderNumber: cancel.OrderNumber,
  7006. Manufacturer: manufacturer.ID,
  7007. Dealer: 0,
  7008. Creator: adminInfo.AdminUser.Id,
  7009. UpdateCreator: 0,
  7010. Status: 1,
  7011. Ctime: time.Now().Unix(),
  7012. Mtime: 0,
  7013. Price: it.Price,
  7014. WarehousingDetailId: it.WarehouseInfotId,
  7015. WarehouseOutDetailId: it.ID,
  7016. CancelOutDetailId: cancelInfo.ID,
  7017. ProductDate: it.ProductDate,
  7018. ExpireDate: it.ExpiryDate,
  7019. StorehouseId: houseConfig.StorehouseOutInfo,
  7020. OverCount: over_count_one,
  7021. OperateTime: time.Now().Unix(),
  7022. }
  7023. service.CreateStockFlowOne(flow)
  7024. }
  7025. }
  7026. //查询已出库数量
  7027. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7028. if prescribingNumber < dialysisInfo.Count {
  7029. //改变数量
  7030. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7031. }
  7032. if prescribingNumber >= dialysisInfo.Count {
  7033. //删除出库表
  7034. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7035. }
  7036. //更新剩余库存
  7037. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7038. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7039. var total_count_one int64
  7040. for _, it := range stockList {
  7041. total_count_one += it.StockCount
  7042. }
  7043. //基础库插入数据
  7044. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7045. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7046. var flush_count int64
  7047. for _, it := range goodListOne {
  7048. flush_count += it.StockCount
  7049. }
  7050. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7051. if errs != nil {
  7052. goodErrcode := models.XtGoodErrcode{
  7053. UserOrgId: project.UserOrgId,
  7054. Errcode: "手动出库更新剩余出库失败",
  7055. GoodId: project.ProjectId,
  7056. Status: 1,
  7057. Ctime: time.Now().Unix(),
  7058. Mtime: 0,
  7059. Count: 0,
  7060. StockCount: 0,
  7061. Creater: creater,
  7062. BatchNumberId: 0,
  7063. WarehouseOutId: 0,
  7064. }
  7065. service.CreateGoodErrcode(goodErrcode)
  7066. }
  7067. }
  7068. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7069. fmt.Println(err)
  7070. } else {
  7071. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7072. fmt.Println(err)
  7073. }
  7074. }
  7075. c.ServeSuccessJSON(map[string]interface{}{
  7076. "msg": "删除成功",
  7077. })
  7078. return
  7079. }
  7080. func (c *HisApiController) CreateHisAdditionalCharge() {
  7081. his_patient_id, _ := c.GetInt64("his_patient_id")
  7082. patient_id, _ := c.GetInt64("patient_id")
  7083. record_date := c.GetString("record_date")
  7084. timeLayout := "2006-01-02"
  7085. loc, _ := time.LoadLocation("Local")
  7086. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7087. if err != nil {
  7088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7089. return
  7090. }
  7091. adminInfo := c.GetAdminUserInfo()
  7092. recordDateTime := theTime.Unix()
  7093. dataBody := make(map[string]interface{}, 0)
  7094. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7095. if err != nil {
  7096. utils.ErrorLog(err.Error())
  7097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7098. return
  7099. }
  7100. var additions []*models.HisAdditionalCharge
  7101. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7102. additions, _ := dataBody["addition"].([]interface{})
  7103. if len(additions) > 0 {
  7104. for _, item := range additions {
  7105. items := item.(map[string]interface{})
  7106. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7107. utils.ErrorLog("item_id")
  7108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7109. return
  7110. }
  7111. item_id := int64(items["item_id"].(float64))
  7112. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7113. utils.ErrorLog("item_name")
  7114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7115. return
  7116. }
  7117. item_name := items["item_name"].(string)
  7118. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7119. utils.ErrorLog("price")
  7120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7121. return
  7122. }
  7123. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7124. ctime := time.Now().Unix()
  7125. additional := &models.HisAdditionalCharge{
  7126. PatientId: patient_id,
  7127. HisPatientId: his_patient_id,
  7128. UserOrgId: adminInfo.CurrentOrgId,
  7129. RecordDate: recordDateTime,
  7130. CreatedTime: ctime,
  7131. UpdatedTime: ctime,
  7132. Modifier: adminInfo.AdminUser.Id,
  7133. Creator: adminInfo.AdminUser.Id,
  7134. Price: price,
  7135. ItemName: item_name,
  7136. ItemId: item_id,
  7137. Status: 1,
  7138. }
  7139. additions = append(additions, additional)
  7140. }
  7141. }
  7142. }
  7143. for _, item := range additions {
  7144. service.CreateAddtionalCharge(item)
  7145. }
  7146. c.ServeSuccessJSON(map[string]interface{}{
  7147. "msg": "创建成功",
  7148. })
  7149. }
  7150. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7151. blood_fat := c.GetString("blood_fat")
  7152. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7153. blood_sugar := c.GetString("blood_sugar")
  7154. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7155. chief_conplaint := c.GetString("chief_conplaint")
  7156. dbp := c.GetString("dbp")
  7157. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7158. delivery_way, _ := c.GetInt64("delivery_way")
  7159. diagnostic := c.GetString("diagnostic")
  7160. family_history := c.GetString("family_history")
  7161. height := c.GetString("height")
  7162. history_of_present_illness := c.GetString("history_of_present_illness")
  7163. is_infect, _ := c.GetInt64("is_infect")
  7164. past_history := c.GetString("past_history")
  7165. patient_id, _ := c.GetInt64("patient_id")
  7166. his_patient_id, _ := c.GetInt64("his_patient_id")
  7167. personal_history := c.GetString("personal_history")
  7168. pulse := c.GetString("pulse")
  7169. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7170. sbp := c.GetString("sbp")
  7171. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7172. heightfloat, _ := strconv.ParseFloat(height, 64)
  7173. sicktype := c.GetString("sick_type")
  7174. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7175. symptom := c.GetString("symptom")
  7176. sick_date := c.GetString("sick_date")
  7177. temperatures := c.GetString("temperature")
  7178. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7179. record_date := c.GetString("record_date")
  7180. breathing := c.GetString("breathing")
  7181. doctor_advice := c.GetString("doctor_advice")
  7182. remark := c.GetString("remark")
  7183. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7184. sick, _ := c.GetInt64("sick")
  7185. diagnose, _ := c.GetInt64("diagnose")
  7186. //id, _ := c.GetInt64("id")
  7187. timeLayout := "2006-01-02"
  7188. loc, _ := time.LoadLocation("Local")
  7189. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7190. allergic_history := c.GetString("allergic_history")
  7191. if err != nil {
  7192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7193. return
  7194. }
  7195. recordDateTime := theTime.Unix()
  7196. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7197. if err != nil {
  7198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7199. return
  7200. }
  7201. sickTimes := sickTime.Unix()
  7202. ctime := time.Now().Unix()
  7203. primary_disease := c.GetString("primary_disease")
  7204. confirm_failure_date := c.GetString("confirm_failure_date")
  7205. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7206. drug_allergy_history := c.GetString("drug_allergy_history")
  7207. physical_examination := c.GetString("physical_examination")
  7208. special_inspection := c.GetString("special_inspection")
  7209. lab_apparatus := c.GetString("lab_apparatus")
  7210. caseHistory := models.HisPatientCaseHistory{
  7211. HisPatientId: his_patient_id,
  7212. PatientId: patient_id,
  7213. Temperature: temperature,
  7214. BloodSugar: bloodsugarfloat,
  7215. Pulse: pulsefloat,
  7216. Sbp: sbpfloat,
  7217. Dbp: dbpfloat,
  7218. Height: heightfloat,
  7219. BloodFat: bloodfatfloat,
  7220. SickType: sick_type,
  7221. Symptom: symptom,
  7222. SickDate: sickTimes,
  7223. IsInfect: is_infect,
  7224. HistoryOfPresentIllness: history_of_present_illness,
  7225. PastHistory: past_history,
  7226. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7227. ChiefConplaint: chief_conplaint,
  7228. PersonalHistory: personal_history,
  7229. FamilyHistory: family_history,
  7230. Diagnostic: diagnostic,
  7231. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7232. Status: 1,
  7233. Ctime: ctime,
  7234. Mtime: ctime,
  7235. RecordDate: recordDateTime,
  7236. DeliveryWay: delivery_way,
  7237. Breathing: breathingfloat,
  7238. DoctorAdvice: doctor_advice,
  7239. Remark: remark,
  7240. Sick: sick,
  7241. Diagnose: diagnose,
  7242. AllergicHistory: allergic_history,
  7243. PrimaryDisease: primary_disease,
  7244. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7245. DrugAllergyHistory: drug_allergy_history,
  7246. PhysicalExamination: physical_examination,
  7247. SpecialInspection: special_inspection,
  7248. LabApparatus: lab_apparatus,
  7249. }
  7250. //查询该患者是否有病历
  7251. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7252. if errcodes == gorm.ErrRecordNotFound {
  7253. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7254. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7255. if err != nil {
  7256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7257. return
  7258. }
  7259. c.ServeSuccessJSON(map[string]interface{}{
  7260. "caseHistory": caseHistory,
  7261. "historyInfo": historyInfo,
  7262. })
  7263. return
  7264. } else if errcodes == nil {
  7265. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7266. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7267. if err != nil {
  7268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7269. return
  7270. }
  7271. c.ServeSuccessJSON(map[string]interface{}{
  7272. "caseHistory": caseHistory,
  7273. "historyInfo": historyInfo,
  7274. })
  7275. }
  7276. //查询该患者是否有病历
  7277. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7278. //if errcode == gorm.ErrRecordNotFound {
  7279. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7280. // if err != nil {
  7281. // c.ServeSuccessJSON(map[string]interface{}{
  7282. // "msg": "保存成功",
  7283. // })
  7284. // }
  7285. //} else if errcode == nil {
  7286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7287. // return
  7288. //}
  7289. }
  7290. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7291. patient_id, _ := c.GetInt64("patient_id", 0)
  7292. adminUser := c.GetAdminUserInfo()
  7293. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7294. c.ServeSuccessJSON(map[string]interface{}{
  7295. "list": caseHistorys,
  7296. })
  7297. }
  7298. func (c *HisApiController) GetHisPatientCaseHistory() {
  7299. record_date, _ := c.GetInt64("record_date", 0)
  7300. patient_id, _ := c.GetInt64("patient_id", 0)
  7301. admin := c.GetAdminUserInfo()
  7302. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7303. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7304. c.ServeSuccessJSON(map[string]interface{}{
  7305. "info": info,
  7306. "case_history": case_history,
  7307. })
  7308. }
  7309. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7310. template_name := c.GetString("template_name")
  7311. template_remark := c.GetString("template_remark")
  7312. doctor := c.GetAdminUserInfo().AdminUser.Id
  7313. diagnostic := c.GetString("diagnostic")
  7314. chief_conplaint := c.GetString("chief_conplain")
  7315. history_of_present_illness := c.GetString("history_of_present_illness")
  7316. past_history := c.GetString("past_history")
  7317. personal_history := c.GetString("personal_history")
  7318. family_history := c.GetString("family_history")
  7319. user_name := c.GetString("user_name")
  7320. doctor_advice := c.GetString("doctor_advice")
  7321. remark := c.GetString("remark")
  7322. //record_date := c.GetString("record_date")
  7323. //fmt.Println("record_date--------",record_date)
  7324. //timeLayout := "2006-01-02"
  7325. //loc, _ := time.LoadLocation("Local")
  7326. //
  7327. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7328. //if err != nil {
  7329. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7330. // return
  7331. //}
  7332. //recordDateTime := theTime.Unix()
  7333. ctime := time.Now().Unix()
  7334. template := models.HisCaseHistoryTemplate{
  7335. HistoryOfPresentIllness: history_of_present_illness,
  7336. PastHistory: past_history,
  7337. ChiefConplaint: chief_conplaint,
  7338. PersonalHistory: personal_history,
  7339. FamilyHistory: family_history,
  7340. Diagnostic: diagnostic,
  7341. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7342. Status: 1,
  7343. Ctime: ctime,
  7344. Mtime: ctime,
  7345. RecordDate: time.Now().Unix(),
  7346. TemplateName: template_name,
  7347. TemplateRemark: template_remark,
  7348. Creator: doctor,
  7349. Modifier: doctor,
  7350. UserName: user_name,
  7351. DoctorAdvice: doctor_advice,
  7352. Remark: remark,
  7353. }
  7354. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7355. if err == nil {
  7356. c.ServeSuccessJSON(map[string]interface{}{
  7357. "msg": "保存成功",
  7358. })
  7359. } else {
  7360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7361. return
  7362. }
  7363. }
  7364. func (c *HisApiController) GetCaseHistoryTemplate() {
  7365. timeLayout := "2006-01-02"
  7366. loc, _ := time.LoadLocation("Local")
  7367. keyword := c.GetString("keyword")
  7368. start_time := c.GetString("start_time")
  7369. end_time := c.GetString("end_time")
  7370. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7371. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7372. admin := c.GetAdminUserInfo()
  7373. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7374. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7375. c.ServeSuccessJSON(map[string]interface{}{
  7376. "template": template,
  7377. //"history": history,
  7378. })
  7379. }
  7380. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7381. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7382. utils.ErrorLog("drug_name")
  7383. return enums.ErrorCodeParamWrong
  7384. }
  7385. adviceName, _ := json["drug_name"].(string)
  7386. if len(adviceName) == 0 {
  7387. utils.ErrorLog("len(advice_name) == 0")
  7388. return enums.ErrorCodeParamWrong
  7389. }
  7390. advice.AdviceName = adviceName
  7391. adviceDesc, _ := json["advice_desc"].(string)
  7392. advice.AdviceDesc = adviceDesc
  7393. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7394. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7395. advice.DrugSpec = drugSpec
  7396. }
  7397. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7398. remark, _ := json["remark"].(string)
  7399. advice.Remark = remark
  7400. }
  7401. if json["id"] == nil {
  7402. advice.DrugId = 0
  7403. } else {
  7404. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7405. drug_id := int64(json["id"].(float64))
  7406. advice.DrugId = drug_id
  7407. }
  7408. }
  7409. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7410. advice_id := int64(json["advice_id"].(float64))
  7411. advice.ID = advice_id
  7412. if advice.ID > 0 {
  7413. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7414. if err == nil {
  7415. if hisAdvice.ID > 0 {
  7416. advice.ExecutionTime = hisAdvice.ExecutionTime
  7417. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7418. advice.ExecutionState = hisAdvice.ExecutionState
  7419. advice.CheckTime = hisAdvice.CheckTime
  7420. advice.Checker = hisAdvice.Checker
  7421. advice.CheckState = hisAdvice.CheckState
  7422. advice.StartTime = hisAdvice.StartTime
  7423. advice.FeedetlSn = hisAdvice.FeedetlSn
  7424. }
  7425. }
  7426. }
  7427. }
  7428. //
  7429. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7430. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7431. // advice.ExecutionTime = execution_time
  7432. //}
  7433. //
  7434. //
  7435. //
  7436. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7437. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7438. // advice.ExecutionStaff = execution_staff
  7439. //}
  7440. //
  7441. //
  7442. //
  7443. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7444. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7445. // advice.ExecutionState = execution_state
  7446. //}
  7447. //
  7448. //
  7449. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7450. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7451. // advice.CheckTime = check_time
  7452. //}
  7453. //
  7454. //
  7455. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7456. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7457. // advice.CheckState = check_state
  7458. //}
  7459. //
  7460. //
  7461. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7462. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7463. // advice.Checker = checker
  7464. //}
  7465. //
  7466. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7467. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7468. // advice.StartTime = start_time
  7469. //}
  7470. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7471. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7472. advice.IsSelfDrug = is_self_drug
  7473. }
  7474. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7475. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7476. drug_way_count, _ := json["drug_way_count"].(string)
  7477. advice.DrugWayCount = drug_way_count
  7478. }
  7479. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7480. drugSpecUnit, _ := json["min_unit"].(string)
  7481. advice.DrugSpecUnit = drugSpecUnit
  7482. }
  7483. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7484. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7485. advice.SingleDose = singleDose
  7486. }
  7487. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7488. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7489. advice.SingleDoseUnit = singleDoseUnit
  7490. }
  7491. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7492. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7493. advice.PrescribingNumber = prescribingNumber
  7494. }
  7495. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7496. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7497. advice.PrescribingNumberUnit = prescribingNumberUnit
  7498. }
  7499. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7500. deliveryWay, _ := json["delivery_way"].(string)
  7501. advice.DeliveryWay = deliveryWay
  7502. }
  7503. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7504. executionFrequency, _ := json["execution_frequency"].(string)
  7505. advice.ExecutionFrequency = executionFrequency
  7506. }
  7507. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7508. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7509. advice.Price = price
  7510. }
  7511. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7512. med_list_codg, _ := json["medical_insurance_number"].(string)
  7513. advice.MedListCodg = med_list_codg
  7514. }
  7515. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7516. day := int64(json["day"].(float64))
  7517. advice.Day = day
  7518. }
  7519. return 0
  7520. }
  7521. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7522. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7523. id := int64(json["id"].(float64))
  7524. project.ID = id
  7525. historyProject, _ := service.GetHisProjectByID(id)
  7526. project.FeedetlSn = historyProject.FeedetlSn
  7527. }
  7528. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7529. project_id := int64(json["project_id"].(float64))
  7530. project.ProjectId = project_id
  7531. }
  7532. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7533. // price := int64(json["price"].(float64))
  7534. // formatInt_price := strconv.FormatInt(price, 10)
  7535. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7536. // project.Price = float_price
  7537. // }
  7538. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7539. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7540. project.Price = price
  7541. }
  7542. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7543. total, _ := json["total"].(string)
  7544. project.Count = total
  7545. }
  7546. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7547. medical_code, _ := json["medical_code"].(string)
  7548. project.MedListCodg = medical_code
  7549. }
  7550. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7551. single_dose, _ := json["single_dose"].(string)
  7552. project.SingleDose = single_dose
  7553. }
  7554. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7555. delivery_way, _ := json["delivery_way"].(string)
  7556. project.DeliveryWay = delivery_way
  7557. }
  7558. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7559. execution_frequency, _ := json["execution_frequency"].(string)
  7560. project.ExecutionFrequency = execution_frequency
  7561. }
  7562. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7563. remark, _ := json["remark"].(string)
  7564. project.Remark = remark
  7565. }
  7566. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7567. day, _ := json["number_days"].(string)
  7568. project.Day = day
  7569. }
  7570. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7571. unit, _ := json["unit"].(string)
  7572. project.Unit = unit
  7573. }
  7574. return 0
  7575. }
  7576. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7577. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7578. id := int64(json["id"].(float64))
  7579. historyAddtions, _ := service.GetHisAdditionByID(id)
  7580. additionalCharge.ID = id
  7581. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7582. }
  7583. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7584. item_id := int64(json["item_id"].(float64))
  7585. additionalCharge.ItemId = item_id
  7586. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7587. if config.ID > 0 {
  7588. if len(config.Code) > 0 {
  7589. additionalCharge.MedListCodg = config.Code
  7590. }
  7591. }
  7592. }
  7593. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7594. // price := int64(json["price"].(float64))
  7595. // formatInt_price := strconv.FormatInt(price, 10)
  7596. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7597. // additionalCharge.Price = float_price
  7598. // }
  7599. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7600. // price := int64(json["price"].(float64))
  7601. // formatInt_price := strconv.FormatInt(price, 10)
  7602. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7603. // additionalCharge.Price = float_price
  7604. //}
  7605. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7606. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7607. additionalCharge.Price = price
  7608. }
  7609. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7610. count, _ := json["count"].(string)
  7611. counts, _ := strconv.ParseInt(count, 10, 64)
  7612. additionalCharge.Count = counts
  7613. }
  7614. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7615. item_name, _ := json["item_name"].(string)
  7616. additionalCharge.ItemName = item_name
  7617. }
  7618. return 0
  7619. }
  7620. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7621. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7622. utils.ErrorLog("drug_name")
  7623. return enums.ErrorCodeParamWrong
  7624. }
  7625. adviceName, _ := json["drug_name"].(string)
  7626. if len(adviceName) == 0 {
  7627. utils.ErrorLog("len(advice_name) == 0")
  7628. return enums.ErrorCodeParamWrong
  7629. }
  7630. advice.AdviceName = adviceName
  7631. adviceDesc, _ := json["advice_desc"].(string)
  7632. advice.AdviceDesc = adviceDesc
  7633. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7634. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7635. advice.DrugSpec = drugSpec
  7636. }
  7637. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7638. remark, _ := json["remark"].(string)
  7639. advice.Remark = remark
  7640. }
  7641. if json["id"] == nil {
  7642. advice.DrugId = 0
  7643. } else {
  7644. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7645. drug_id := int64(json["id"].(float64))
  7646. advice.DrugId = drug_id
  7647. }
  7648. }
  7649. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7650. groupno := int64(json["groupno"].(float64))
  7651. advice.Groupno = groupno
  7652. }
  7653. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7654. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7655. advice.IsSelfDrug = is_self_drug
  7656. }
  7657. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7658. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7659. drug_way_count, _ := json["drug_way_count"].(string)
  7660. advice.DrugWayCount = drug_way_count
  7661. }
  7662. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7663. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7664. advice.HospApprFlag = hosp_appr_flag
  7665. }
  7666. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7667. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7668. advice.PrescribingNumber = prescribingNumber
  7669. }
  7670. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7671. // frequency_type := int64(json["frequency_type"].(float64))
  7672. // advice.FrequencyType = frequency_type
  7673. //}
  7674. //
  7675. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7676. // day_count := int64(json["day_count"].(float64))
  7677. // advice.DayCount = day_count
  7678. //}
  7679. //
  7680. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7681. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7682. // week_day, _ := json["week_day"].(string)
  7683. // advice.WeekDay = week_day
  7684. //}
  7685. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7686. drugSpecUnit, _ := json["min_unit"].(string)
  7687. advice.DrugSpecUnit = drugSpecUnit
  7688. }
  7689. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7690. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7691. advice.SingleDose = singleDose
  7692. }
  7693. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7694. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7695. advice.SingleDoseUnit = singleDoseUnit
  7696. }
  7697. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7698. deliveryWay, _ := json["delivery_way"].(string)
  7699. advice.DeliveryWay = deliveryWay
  7700. }
  7701. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7702. executionFrequency, _ := json["execution_frequency"].(string)
  7703. advice.ExecutionFrequency = executionFrequency
  7704. }
  7705. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7706. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7707. advice.Price = price
  7708. }
  7709. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7710. med_list_codg, _ := json["medical_insurance_number"].(string)
  7711. advice.MedListCodg = med_list_codg
  7712. }
  7713. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7714. day := int64(json["day"].(float64))
  7715. advice.Day = day
  7716. }
  7717. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7718. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7719. advice.PrescribingNumberUnit = prescribingNumberUnit
  7720. }
  7721. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7722. advice_id := int64(json["advice_id"].(float64))
  7723. advice.ID = advice_id
  7724. if advice.ID > 0 {
  7725. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7726. if err == nil {
  7727. if hisAdvice.ID > 0 {
  7728. advice.ExecutionTime = hisAdvice.ExecutionTime
  7729. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7730. advice.ExecutionState = hisAdvice.ExecutionState
  7731. advice.CheckTime = hisAdvice.CheckTime
  7732. advice.Checker = hisAdvice.Checker
  7733. advice.CheckState = hisAdvice.CheckState
  7734. advice.StartTime = hisAdvice.StartTime
  7735. advice.HospApprFlag = hisAdvice.HospApprFlag
  7736. advice.IsMedicine = hisAdvice.IsMedicine
  7737. if hisAdvice.UserOrgId == 10028 {
  7738. 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 {
  7739. advice.ExecutionTime = 0
  7740. advice.ExecutionStaff = 0
  7741. advice.ExecutionState = 2
  7742. advice.CheckTime = 0
  7743. advice.Checker = 0
  7744. advice.CheckState = 2
  7745. }
  7746. } else {
  7747. 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 {
  7748. advice.ExecutionTime = 0
  7749. advice.ExecutionStaff = 0
  7750. advice.ExecutionState = 2
  7751. advice.CheckTime = 0
  7752. advice.Checker = 0
  7753. advice.CheckState = 2
  7754. advice.UpdatedTime = time.Now().Unix()
  7755. }
  7756. }
  7757. //advice.Groupno = hisAdvice.Groupno
  7758. }
  7759. }
  7760. }
  7761. }
  7762. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7763. //
  7764. //if drugStockConfig.IsOpen == 1 {
  7765. //
  7766. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7767. // if advice.ID == 0 { //医嘱不存在
  7768. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7769. // drug.Total = drug.Total - advice.PrescribingNumber
  7770. // service.UpdateBaseDrugLib(&drug)
  7771. //
  7772. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7773. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7774. // drug.Total = drug.Total - num
  7775. // service.UpdateBaseDrugLib(&drug)
  7776. // }
  7777. //
  7778. // } else if advice.ID > 0 { //医嘱存在
  7779. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7780. // var num float64
  7781. //
  7782. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7783. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7784. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7785. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7786. // drug.Total = drug.Total + num
  7787. // service.UpdateBaseDrugLib(&drug)
  7788. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7789. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7790. // drug.Total = drug.Total - num
  7791. // service.UpdateBaseDrugLib(&drug)
  7792. // }
  7793. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7794. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7795. // if num2 > advice.PrescribingNumber {
  7796. // num = num2 - advice.PrescribingNumber
  7797. // drug.Total = drug.Total + num
  7798. // service.UpdateBaseDrugLib(&drug)
  7799. // } else if num2 < advice.PrescribingNumber {
  7800. // num = advice.PrescribingNumber - num2
  7801. // drug.Total = drug.Total - num
  7802. // service.UpdateBaseDrugLib(&drug)
  7803. // }
  7804. //
  7805. // }
  7806. //
  7807. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7808. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7809. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7810. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7811. // if num1 > num2 {
  7812. // num = num1 - num2
  7813. // drug.Total = drug.Total + num
  7814. // service.UpdateBaseDrugLib(&drug)
  7815. // } else if num1 < num2 {
  7816. // num = num2 - num1
  7817. // drug.Total = drug.Total - num
  7818. // service.UpdateBaseDrugLib(&drug)
  7819. // }
  7820. //
  7821. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7822. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7823. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7824. // if hisAdvice.PrescribingNumber > num2 {
  7825. // num = hisAdvice.PrescribingNumber - num2
  7826. // drug.Total = drug.Total + num
  7827. // service.UpdateBaseDrugLib(&drug)
  7828. // } else if num2 < advice.PrescribingNumber {
  7829. // num = num2 - hisAdvice.PrescribingNumber
  7830. // drug.Total = drug.Total - num
  7831. // service.UpdateBaseDrugLib(&drug)
  7832. // }
  7833. //
  7834. // }
  7835. // }
  7836. // }
  7837. //}
  7838. //
  7839. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7840. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7841. // advice.ExecutionTime = execution_time
  7842. //}
  7843. //
  7844. //
  7845. //
  7846. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7847. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7848. // advice.ExecutionStaff = execution_staff
  7849. //}
  7850. //
  7851. //
  7852. //
  7853. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7854. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7855. // advice.ExecutionState = execution_state
  7856. //}
  7857. //
  7858. //
  7859. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7860. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7861. // advice.CheckTime = check_time
  7862. //}
  7863. //
  7864. //
  7865. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7866. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7867. // advice.CheckState = check_state
  7868. //}
  7869. //
  7870. //
  7871. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7872. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7873. // advice.Checker = checker
  7874. //}
  7875. //
  7876. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7877. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7878. // advice.StartTime = start_time
  7879. //}
  7880. return 0
  7881. }
  7882. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7883. project.ExecutionStaff = 0
  7884. project.ExecutionState = 2
  7885. project.ExecutionTime = 0
  7886. project.Checker = 0
  7887. project.CheckState = 2
  7888. project.CheckTime = 0
  7889. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7890. id := int64(json["id"].(float64))
  7891. project.ID = id
  7892. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7893. project.ExecutionStaff = temp_project.ExecutionStaff
  7894. project.ExecutionState = temp_project.ExecutionState
  7895. project.ExecutionTime = temp_project.ExecutionTime
  7896. project.Checker = temp_project.Checker
  7897. project.CheckState = temp_project.CheckState
  7898. project.CheckTime = temp_project.CheckTime
  7899. project.TeamId = temp_project.TeamId
  7900. }
  7901. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7902. types := int64(json["type"].(float64))
  7903. project.Type = types
  7904. }
  7905. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7906. project_id := int64(json["project_id"].(float64))
  7907. project.ProjectId = project_id
  7908. }
  7909. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7910. team_id := int64(json["team_id"].(float64))
  7911. project.TeamId = team_id
  7912. }
  7913. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7914. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7915. project.Price = price
  7916. }
  7917. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7918. total, _ := json["total"].(string)
  7919. //totals, _ := strconv.ParseInt(total, 10, 64)
  7920. project.Count = total
  7921. }
  7922. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7923. medical_code, _ := json["medical_code"].(string)
  7924. project.MedListCodg = medical_code
  7925. }
  7926. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7927. single_dose, _ := json["single_dose"].(string)
  7928. project.SingleDose = single_dose
  7929. }
  7930. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7931. delivery_way, _ := json["delivery_way"].(string)
  7932. project.DeliveryWay = delivery_way
  7933. }
  7934. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7935. execution_frequency, _ := json["execution_frequency"].(string)
  7936. project.ExecutionFrequency = execution_frequency
  7937. }
  7938. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7939. remark, _ := json["remark"].(string)
  7940. project.Remark = remark
  7941. }
  7942. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7943. day, _ := json["number_days"].(string)
  7944. project.Day = day
  7945. }
  7946. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7947. unit, _ := json["unit"].(string)
  7948. project.Unit = unit
  7949. }
  7950. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7951. // frequency_type := int64(json["frequency_type"].(float64))
  7952. // project.FrequencyType = frequency_type
  7953. //}
  7954. //
  7955. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7956. // day_count := int64(json["day_count"].(float64))
  7957. // project.DayCount = day_count
  7958. //}
  7959. //
  7960. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7961. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7962. // week_day, _ := json["week_day"].(string)
  7963. // project.WeekDay = week_day
  7964. //}
  7965. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7966. //
  7967. //if project.ID == 0 {
  7968. // if stockConfig.IsOpen == 1 {
  7969. // if project.Type == 3 {
  7970. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7971. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7972. // good.Total = good.Total - f_count
  7973. // service.UpdateGoodInfo(&good)
  7974. // }
  7975. // }
  7976. //
  7977. //} else {
  7978. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7979. //
  7980. // if stockConfig.IsOpen == 1 {
  7981. // if project.Type == 3 {
  7982. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7983. // if project.Count < temp_project.Count {
  7984. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7985. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7986. //
  7987. // other_count := f_count_two - f_count_one
  7988. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7989. // good.Total = good.Total + other_count_two
  7990. // service.UpdateGoodInfo(&good)
  7991. // } else if project.Count > temp_project.Count {
  7992. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7993. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7994. //
  7995. // other_count := f_count_one - f_count_two
  7996. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7997. // good.Total = good.Total - other_count_two
  7998. // service.UpdateGoodInfo(&good)
  7999. // }
  8000. //
  8001. // }
  8002. // }
  8003. //
  8004. //}
  8005. return 0
  8006. }
  8007. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8008. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8009. utils.ErrorLog("drug_name")
  8010. return enums.ErrorCodeParamWrong
  8011. }
  8012. adviceName, _ := json["drug_name"].(string)
  8013. if len(adviceName) == 0 {
  8014. utils.ErrorLog("len(advice_name) == 0")
  8015. return enums.ErrorCodeParamWrong
  8016. }
  8017. advice.AdviceName = adviceName
  8018. adviceDesc, _ := json["advice_desc"].(string)
  8019. advice.AdviceDesc = adviceDesc
  8020. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8021. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8022. advice.DrugSpec = drugSpec
  8023. }
  8024. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8025. remark, _ := json["remark"].(string)
  8026. advice.Remark = remark
  8027. }
  8028. if json["id"] == nil {
  8029. advice.DrugId = 0
  8030. } else {
  8031. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8032. drug_id := int64(json["id"].(float64))
  8033. advice.DrugId = drug_id
  8034. }
  8035. }
  8036. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8037. groupno := int64(json["groupno"].(float64))
  8038. advice.Groupno = groupno
  8039. }
  8040. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8041. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8042. advice.IsSelfDrug = is_self_drug
  8043. }
  8044. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8045. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8046. drug_way_count, _ := json["drug_way_count"].(string)
  8047. advice.DrugWayCount = drug_way_count
  8048. }
  8049. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8050. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8051. advice.HospApprFlag = hosp_appr_flag
  8052. }
  8053. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8054. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8055. advice.PrescribingNumber = prescribingNumber
  8056. }
  8057. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8058. // frequency_type := int64(json["frequency_type"].(float64))
  8059. // advice.FrequencyType = frequency_type
  8060. //}
  8061. //
  8062. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8063. // day_count := int64(json["day_count"].(float64))
  8064. // advice.DayCount = day_count
  8065. //}
  8066. //
  8067. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8068. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8069. // week_day, _ := json["week_day"].(string)
  8070. // advice.WeekDay = week_day
  8071. //}
  8072. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8073. drugSpecUnit, _ := json["min_unit"].(string)
  8074. advice.DrugSpecUnit = drugSpecUnit
  8075. }
  8076. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8077. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8078. advice.SingleDose = singleDose
  8079. }
  8080. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8081. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8082. advice.SingleDoseUnit = singleDoseUnit
  8083. }
  8084. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8085. deliveryWay, _ := json["delivery_way"].(string)
  8086. advice.DeliveryWay = deliveryWay
  8087. }
  8088. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8089. executionFrequency, _ := json["execution_frequency"].(string)
  8090. advice.ExecutionFrequency = executionFrequency
  8091. }
  8092. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8093. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8094. advice.Price = price
  8095. }
  8096. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8097. med_list_codg, _ := json["medical_insurance_number"].(string)
  8098. advice.MedListCodg = med_list_codg
  8099. }
  8100. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8101. day := int64(json["day"].(float64))
  8102. advice.Day = day
  8103. }
  8104. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8105. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8106. advice.PrescribingNumberUnit = prescribingNumberUnit
  8107. }
  8108. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8109. advice_id := int64(json["advice_id"].(float64))
  8110. advice.ID = advice_id
  8111. if advice.ID > 0 {
  8112. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8113. if err == nil {
  8114. if hisAdvice.ID > 0 {
  8115. advice.ExecutionTime = hisAdvice.ExecutionTime
  8116. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8117. advice.ExecutionState = hisAdvice.ExecutionState
  8118. advice.CheckTime = hisAdvice.CheckTime
  8119. advice.Checker = hisAdvice.Checker
  8120. advice.DrugCode = hisAdvice.DrugCode
  8121. advice.CheckState = hisAdvice.CheckState
  8122. advice.StartTime = hisAdvice.StartTime
  8123. advice.HospApprFlag = hisAdvice.HospApprFlag
  8124. advice.IsMedicine = hisAdvice.IsMedicine
  8125. if hisAdvice.UserOrgId == 10028 {
  8126. 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 {
  8127. advice.ExecutionTime = 0
  8128. advice.ExecutionStaff = 0
  8129. advice.ExecutionState = 2
  8130. advice.CheckTime = 0
  8131. advice.Checker = 0
  8132. advice.CheckState = 2
  8133. }
  8134. } else {
  8135. 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 {
  8136. advice.ExecutionTime = 0
  8137. advice.ExecutionStaff = 0
  8138. advice.ExecutionState = 2
  8139. advice.CheckTime = 0
  8140. advice.Checker = 0
  8141. advice.CheckState = 2
  8142. //advice.UpdatedTime = time.Now().Unix()
  8143. advice.CreatedTime = hisAdvice.CreatedTime
  8144. advice.UpdatedTime = time.Now().Unix()
  8145. } else {
  8146. advice.CreatedTime = hisAdvice.CreatedTime
  8147. advice.UpdatedTime = hisAdvice.UpdatedTime
  8148. }
  8149. }
  8150. //advice.Groupno = hisAdvice.Groupno
  8151. } else {
  8152. advice.IsMedicine = 0
  8153. ctime := time.Now().Unix()
  8154. advice.CreatedTime = ctime
  8155. advice.UpdatedTime = ctime
  8156. }
  8157. }
  8158. } else {
  8159. advice.IsMedicine = 0
  8160. ctime := time.Now().Unix()
  8161. advice.CreatedTime = ctime
  8162. advice.UpdatedTime = ctime
  8163. }
  8164. }
  8165. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8166. //
  8167. //if drugStockConfig.IsOpen == 1 {
  8168. //
  8169. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8170. // if advice.ID == 0 { //医嘱不存在
  8171. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8172. // drug.Total = drug.Total - advice.PrescribingNumber
  8173. // service.UpdateBaseDrugLib(&drug)
  8174. //
  8175. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8176. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8177. // drug.Total = drug.Total - num
  8178. // service.UpdateBaseDrugLib(&drug)
  8179. // }
  8180. //
  8181. // } else if advice.ID > 0 { //医嘱存在
  8182. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8183. // var num float64
  8184. //
  8185. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8186. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8187. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8188. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8189. // drug.Total = drug.Total + num
  8190. // service.UpdateBaseDrugLib(&drug)
  8191. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8192. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8193. // drug.Total = drug.Total - num
  8194. // service.UpdateBaseDrugLib(&drug)
  8195. // }
  8196. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8197. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8198. // if num2 > advice.PrescribingNumber {
  8199. // num = num2 - advice.PrescribingNumber
  8200. // drug.Total = drug.Total + num
  8201. // service.UpdateBaseDrugLib(&drug)
  8202. // } else if num2 < advice.PrescribingNumber {
  8203. // num = advice.PrescribingNumber - num2
  8204. // drug.Total = drug.Total - num
  8205. // service.UpdateBaseDrugLib(&drug)
  8206. // }
  8207. //
  8208. // }
  8209. //
  8210. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8211. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8212. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8213. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8214. // if num1 > num2 {
  8215. // num = num1 - num2
  8216. // drug.Total = drug.Total + num
  8217. // service.UpdateBaseDrugLib(&drug)
  8218. // } else if num1 < num2 {
  8219. // num = num2 - num1
  8220. // drug.Total = drug.Total - num
  8221. // service.UpdateBaseDrugLib(&drug)
  8222. // }
  8223. //
  8224. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8225. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8226. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8227. // if hisAdvice.PrescribingNumber > num2 {
  8228. // num = hisAdvice.PrescribingNumber - num2
  8229. // drug.Total = drug.Total + num
  8230. // service.UpdateBaseDrugLib(&drug)
  8231. // } else if num2 < advice.PrescribingNumber {
  8232. // num = num2 - hisAdvice.PrescribingNumber
  8233. // drug.Total = drug.Total - num
  8234. // service.UpdateBaseDrugLib(&drug)
  8235. // }
  8236. //
  8237. // }
  8238. // }
  8239. // }
  8240. //}
  8241. //
  8242. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8243. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8244. // advice.ExecutionTime = execution_time
  8245. //}
  8246. //
  8247. //
  8248. //
  8249. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8250. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8251. // advice.ExecutionStaff = execution_staff
  8252. //}
  8253. //
  8254. //
  8255. //
  8256. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8257. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8258. // advice.ExecutionState = execution_state
  8259. //}
  8260. //
  8261. //
  8262. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8263. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8264. // advice.CheckTime = check_time
  8265. //}
  8266. //
  8267. //
  8268. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8269. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8270. // advice.CheckState = check_state
  8271. //}
  8272. //
  8273. //
  8274. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8275. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8276. // advice.Checker = checker
  8277. //}
  8278. //
  8279. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8280. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8281. // advice.StartTime = start_time
  8282. //}
  8283. return 0
  8284. }
  8285. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8286. project.ExecutionStaff = 0
  8287. project.ExecutionState = 2
  8288. project.ExecutionTime = 0
  8289. project.Checker = 0
  8290. project.CheckState = 2
  8291. project.CheckTime = 0
  8292. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8293. id := int64(json["id"].(float64))
  8294. project.ID = id
  8295. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8296. project.ExecutionStaff = temp_project.ExecutionStaff
  8297. project.ExecutionState = temp_project.ExecutionState
  8298. project.ExecutionTime = temp_project.ExecutionTime
  8299. project.Checker = temp_project.Checker
  8300. project.CheckState = temp_project.CheckState
  8301. project.CheckTime = temp_project.CheckTime
  8302. project.TeamId = temp_project.TeamId
  8303. }
  8304. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8305. types := int64(json["type"].(float64))
  8306. project.Type = types
  8307. }
  8308. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8309. project_id := int64(json["project_id"].(float64))
  8310. project.ProjectId = project_id
  8311. }
  8312. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8313. team_id := int64(json["team_id"].(float64))
  8314. project.TeamId = team_id
  8315. }
  8316. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8317. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8318. project.Price = price
  8319. }
  8320. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8321. total, _ := json["total"].(string)
  8322. //totals, _ := strconv.ParseInt(total, 10, 64)
  8323. project.Count = total
  8324. }
  8325. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8326. medical_code, _ := json["medical_code"].(string)
  8327. project.MedListCodg = medical_code
  8328. }
  8329. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8330. single_dose, _ := json["single_dose"].(string)
  8331. project.SingleDose = single_dose
  8332. }
  8333. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8334. delivery_way, _ := json["delivery_way"].(string)
  8335. project.DeliveryWay = delivery_way
  8336. }
  8337. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8338. execution_frequency, _ := json["execution_frequency"].(string)
  8339. project.ExecutionFrequency = execution_frequency
  8340. }
  8341. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8342. remark, _ := json["remark"].(string)
  8343. project.Remark = remark
  8344. }
  8345. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8346. day, _ := json["number_days"].(string)
  8347. project.Day = day
  8348. }
  8349. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8350. unit, _ := json["unit"].(string)
  8351. project.Unit = unit
  8352. }
  8353. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8354. // frequency_type := int64(json["frequency_type"].(float64))
  8355. // project.FrequencyType = frequency_type
  8356. //}
  8357. //
  8358. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8359. // day_count := int64(json["day_count"].(float64))
  8360. // project.DayCount = day_count
  8361. //}
  8362. //
  8363. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8364. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8365. // week_day, _ := json["week_day"].(string)
  8366. // project.WeekDay = week_day
  8367. //}
  8368. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8369. //
  8370. //if project.ID == 0 {
  8371. // if stockConfig.IsOpen == 1 {
  8372. // if project.Type == 3 {
  8373. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8374. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8375. // good.Total = good.Total - f_count
  8376. // service.UpdateGoodInfo(&good)
  8377. // }
  8378. // }
  8379. //
  8380. //} else {
  8381. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8382. //
  8383. // if stockConfig.IsOpen == 1 {
  8384. // if project.Type == 3 {
  8385. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8386. // if project.Count < temp_project.Count {
  8387. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8388. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8389. //
  8390. // other_count := f_count_two - f_count_one
  8391. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8392. // good.Total = good.Total + other_count_two
  8393. // service.UpdateGoodInfo(&good)
  8394. // } else if project.Count > temp_project.Count {
  8395. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8396. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8397. //
  8398. // other_count := f_count_one - f_count_two
  8399. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8400. // good.Total = good.Total - other_count_two
  8401. // service.UpdateGoodInfo(&good)
  8402. // }
  8403. //
  8404. // }
  8405. // }
  8406. //
  8407. //}
  8408. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8409. id := int64(json["id"].(float64))
  8410. if id > 0 {
  8411. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8412. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8413. fmt.Println("666666")
  8414. project.Mtime = time.Now().Unix()
  8415. project.Ctime = temp_project.Ctime
  8416. } else {
  8417. project.Mtime = temp_project.Mtime
  8418. project.Ctime = temp_project.Ctime
  8419. }
  8420. } else {
  8421. ctime := time.Now().Unix()
  8422. project.Mtime = ctime
  8423. project.Ctime = ctime
  8424. }
  8425. }
  8426. return 0
  8427. }
  8428. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8429. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8430. id := int64(json["id"].(float64))
  8431. additionalCharge.ID = id
  8432. }
  8433. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8434. item_id := int64(json["item_id"].(float64))
  8435. additionalCharge.ItemId = item_id
  8436. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8437. if config.ID > 0 {
  8438. if len(config.Code) > 0 {
  8439. additionalCharge.MedListCodg = config.Code
  8440. }
  8441. }
  8442. }
  8443. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8444. // price := int64(json["price"].(float64))
  8445. // formatInt_price := strconv.FormatInt(price, 10)
  8446. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8447. // additionalCharge.Price = float_price
  8448. // }
  8449. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8450. // price := int64(json["price"].(float64))
  8451. // formatInt_price := strconv.FormatInt(price, 10)
  8452. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8453. // additionalCharge.Price = float_price
  8454. //}
  8455. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8456. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8457. additionalCharge.Price = price
  8458. }
  8459. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8460. count, _ := json["count"].(string)
  8461. counts, _ := strconv.ParseInt(count, 10, 64)
  8462. additionalCharge.Count = counts
  8463. }
  8464. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8465. item_name, _ := json["item_name"].(string)
  8466. additionalCharge.ItemName = item_name
  8467. }
  8468. return 0
  8469. }
  8470. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8471. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8472. utils.ErrorLog("drug_name")
  8473. return enums.ErrorCodeParamWrong
  8474. }
  8475. adviceName, _ := json["drug_name"].(string)
  8476. if len(adviceName) == 0 {
  8477. utils.ErrorLog("len(advice_name) == 0")
  8478. return enums.ErrorCodeParamWrong
  8479. }
  8480. advice.AdviceName = adviceName
  8481. adviceDesc, _ := json["advice_desc"].(string)
  8482. advice.AdviceDesc = adviceDesc
  8483. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8484. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8485. advice.DrugSpec = drugSpec
  8486. }
  8487. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8488. remark, _ := json["remark"].(string)
  8489. advice.Remark = remark
  8490. }
  8491. if json["id"] == nil {
  8492. advice.DrugId = 0
  8493. } else {
  8494. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8495. drug_id := int64(json["id"].(float64))
  8496. advice.DrugId = drug_id
  8497. }
  8498. }
  8499. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8500. groupno := int64(json["groupno"].(float64))
  8501. advice.Groupno = groupno
  8502. }
  8503. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8504. drugSpecUnit, _ := json["min_unit"].(string)
  8505. advice.DrugSpecUnit = drugSpecUnit
  8506. }
  8507. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8508. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8509. advice.SingleDose = singleDose
  8510. }
  8511. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8512. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8513. advice.SingleDoseUnit = singleDoseUnit
  8514. }
  8515. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8516. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8517. advice.PrescribingNumber = prescribingNumber
  8518. }
  8519. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8520. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8521. advice.PrescribingNumberUnit = prescribingNumberUnit
  8522. }
  8523. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8524. deliveryWay, _ := json["delivery_way"].(string)
  8525. advice.DeliveryWay = deliveryWay
  8526. }
  8527. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8528. executionFrequency, _ := json["execution_frequency"].(string)
  8529. advice.ExecutionFrequency = executionFrequency
  8530. }
  8531. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8532. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8533. advice.Price = price
  8534. }
  8535. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8536. med_list_codg, _ := json["medical_insurance_number"].(string)
  8537. advice.MedListCodg = med_list_codg
  8538. }
  8539. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8540. day := int64(json["day"].(float64))
  8541. advice.Day = day
  8542. }
  8543. advice.FrequencyType = 1
  8544. return 0
  8545. }
  8546. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8547. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8548. types := int64(json["type"].(float64))
  8549. project.Type = types
  8550. }
  8551. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8552. project_id := int64(json["project_id"].(float64))
  8553. project.ProjectId = project_id
  8554. }
  8555. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8556. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8557. project.Price = price
  8558. }
  8559. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8560. total, _ := json["total"].(string)
  8561. //totals, _ := strconv.ParseInt(total, 10, 64)
  8562. project.Count = total
  8563. }
  8564. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8565. medical_code, _ := json["medical_code"].(string)
  8566. project.MedListCodg = medical_code
  8567. }
  8568. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8569. single_dose, _ := json["single_dose"].(string)
  8570. project.SingleDose = single_dose
  8571. }
  8572. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8573. delivery_way, _ := json["delivery_way"].(string)
  8574. project.DeliveryWay = delivery_way
  8575. }
  8576. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8577. execution_frequency, _ := json["execution_frequency"].(string)
  8578. project.ExecutionFrequency = execution_frequency
  8579. }
  8580. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8581. remark, _ := json["remark"].(string)
  8582. project.Remark = remark
  8583. }
  8584. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8585. day, _ := json["number_days"].(string)
  8586. project.Day = day
  8587. }
  8588. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8589. unit, _ := json["unit"].(string)
  8590. project.Unit = unit
  8591. }
  8592. project.FrequencyType = 1
  8593. return 0
  8594. }
  8595. func (c *HisApiController) GetHisOrderListTwo() {
  8596. start_time := c.GetString("start_time")
  8597. end_time := c.GetString("end_time")
  8598. timeLayout := "2006-01-02"
  8599. loc, _ := time.LoadLocation("Local")
  8600. var startTime int64
  8601. if len(start_time) > 0 {
  8602. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8603. if err != nil {
  8604. //fmt.Println(err)
  8605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8606. return
  8607. }
  8608. startTime = theTime.Unix()
  8609. }
  8610. var endTime int64
  8611. if len(end_time) > 0 {
  8612. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8613. if err != nil {
  8614. utils.ErrorLog(err.Error())
  8615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8616. return
  8617. }
  8618. endTime = theTime.Unix()
  8619. }
  8620. adminUser := c.GetAdminUserInfo()
  8621. org_id := adminUser.CurrentOrgId
  8622. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8623. if err == nil {
  8624. c.ServeSuccessJSON(map[string]interface{}{
  8625. "order2": order,
  8626. })
  8627. } else {
  8628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8629. return
  8630. }
  8631. }
  8632. func (c *HisApiController) GetHisOrderList() {
  8633. page, _ := c.GetInt64("page", -1)
  8634. limit, _ := c.GetInt64("limit", -1)
  8635. start_time := c.GetString("start_time")
  8636. end_time := c.GetString("end_time")
  8637. types, _ := c.GetInt64("type", 0)
  8638. keywords := c.GetString("keywords")
  8639. p_type, _ := c.GetInt64("p_type", 0)
  8640. sort_type, _ := c.GetInt64("sort_type", 0)
  8641. charge_type, _ := c.GetInt64("charge_type", 0)
  8642. sch_type, _ := c.GetInt64("sch_type", 0)
  8643. zone_type, _ := c.GetInt64("zone_type", 0)
  8644. med_type, _ := c.GetInt64("med_type", 0)
  8645. timeLayout := "2006-01-02"
  8646. loc, _ := time.LoadLocation("Local")
  8647. var startTime int64
  8648. if len(start_time) > 0 {
  8649. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8650. if err != nil {
  8651. //fmt.Println(err)
  8652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8653. return
  8654. }
  8655. startTime = theTime.Unix()
  8656. }
  8657. var endTime int64
  8658. if len(end_time) > 0 {
  8659. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8660. if err != nil {
  8661. utils.ErrorLog(err.Error())
  8662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8663. return
  8664. }
  8665. endTime = theTime.Unix()
  8666. }
  8667. adminUser := c.GetAdminUserInfo()
  8668. org_id := adminUser.CurrentOrgId
  8669. 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)
  8670. for _, item := range order {
  8671. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8672. item.DoctorName = info.Doctor
  8673. item.DepartmentName = info.XtHisDepartment.Name
  8674. }
  8675. if err == nil {
  8676. c.ServeSuccessJSON(map[string]interface{}{
  8677. "order": order,
  8678. "total": total,
  8679. })
  8680. } else {
  8681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8682. return
  8683. }
  8684. }
  8685. func (c *HisApiController) GetHisOrder() {
  8686. patient_id, _ := c.GetInt64("patient_id", 0)
  8687. number := c.GetString("number")
  8688. adminInfo := c.GetAdminUserInfo()
  8689. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8690. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8691. if err == nil {
  8692. c.ServeSuccessJSON(map[string]interface{}{
  8693. "order": order,
  8694. "prescription": prescriptions,
  8695. })
  8696. } else {
  8697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8698. return
  8699. }
  8700. }
  8701. func (c *HisApiController) GetHisPrescriptionList() {
  8702. record_date := c.GetString("record_date")
  8703. keywords := c.GetString("keywords")
  8704. page, _ := c.GetInt64("page")
  8705. limit, _ := c.GetInt64("limit")
  8706. sch_type, _ := c.GetInt64("sch_type")
  8707. timeLayout := "2006-01-02"
  8708. loc, _ := time.LoadLocation("Local")
  8709. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8710. if err != nil {
  8711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8712. return
  8713. }
  8714. recordDateTime := theTime.Unix()
  8715. adminInfo := c.GetAdminUserInfo()
  8716. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8717. //adminInfo := c.GetAdminUserInfo()
  8718. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8719. //fmt.Println(prescriptionOrder)
  8720. if err == nil {
  8721. c.ServeSuccessJSON(map[string]interface{}{
  8722. "order": prescriptionOrder,
  8723. "total": total,
  8724. })
  8725. } else {
  8726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8727. return
  8728. }
  8729. }
  8730. func (c *HisApiController) GetHisPrescriptionInfo() {
  8731. id, _ := c.GetInt64("id")
  8732. adminInfo := c.GetAdminUserInfo()
  8733. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8734. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8735. if err == nil {
  8736. c.ServeSuccessJSON(map[string]interface{}{
  8737. "order": prescriptionOrder,
  8738. "prescription": prescription,
  8739. })
  8740. } else {
  8741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8742. return
  8743. }
  8744. }
  8745. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8746. adminUser := c.GetAdminUserInfo()
  8747. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8748. c.ServeSuccessJSON(map[string]interface{}{
  8749. "config": config,
  8750. })
  8751. }
  8752. type ResultTwo struct {
  8753. ErrMsg interface{} `json:"err_msg"`
  8754. InfRefmsgid string `json:"inf_refmsgid"`
  8755. Infcode int64 `json:"infcode"`
  8756. Output struct {
  8757. Baseinfo struct {
  8758. Age float64 `json:"age"`
  8759. Brdy string `json:"brdy"`
  8760. Certno string `json:"certno"`
  8761. Gend string `json:"gend"`
  8762. Naty string `json:"naty"`
  8763. PsnCertType string `json:"psn_cert_type"`
  8764. PsnName string `json:"psn_name"`
  8765. PsnNo string `json:"psn_no"`
  8766. } `json:"baseinfo"`
  8767. Idetinfo []interface{} `json:"idetinfo"`
  8768. Iinfo []struct {
  8769. Balc float64 `json:"balc"`
  8770. CvlservFlag string `json:"cvlserv_flag"`
  8771. EmpName string `json:"emp_name"`
  8772. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8773. Insutype string `json:"insutype"`
  8774. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8775. PausInsuDate interface{} `json:"paus_insu_date"`
  8776. PsnInsuDate string `json:"psn_insu_date"`
  8777. PsnInsuStas string `json:"psn_insu_stas"`
  8778. PsnType string `json:"psn_type"`
  8779. } `json:"insuinfo"`
  8780. } `json:"output"`
  8781. RefmsgTime string `json:"refmsg_time"`
  8782. RespondTime string `json:"respond_time"`
  8783. Signtype interface{} `json:"signtype"`
  8784. WarnInfo interface{} `json:"warn_info"`
  8785. }
  8786. type ResultThree struct {
  8787. Cainfo interface{} `json:"cainfo"`
  8788. ErrMsg interface{} `json:"err_msg"`
  8789. InfRefmsgid string `json:"inf_refmsgid"`
  8790. Infcode int64 `json:"infcode"`
  8791. Output struct {
  8792. Data struct {
  8793. IptOtpNo string `json:"ipt_otp_no"`
  8794. MdtrtID string `json:"mdtrt_id"`
  8795. PsnNo string `json:"psn_no"`
  8796. } `json:"data"`
  8797. } `json:"output"`
  8798. RefmsgTime string `json:"refmsg_time"`
  8799. RespondTime string `json:"respond_time"`
  8800. Signtype interface{} `json:"signtype"`
  8801. WarnMsg interface{} `json:"warn_msg"`
  8802. }
  8803. type ResultFour struct {
  8804. Cainfo string `json:"cainfo"`
  8805. ErrMsg string `json:"err_msg"`
  8806. InfRefmsgid string `json:"inf_refmsgid"`
  8807. Infcode int64 `json:"infcode"`
  8808. Output struct {
  8809. Result []struct {
  8810. BasMednFlag string `json:"bas_medn_flag"`
  8811. ChldMedcFlag string `json:"chld_medc_flag"`
  8812. ChrgitmLv string `json:"chrgitm_lv"`
  8813. Cnt float64 `json:"cnt"`
  8814. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8815. DrtReimFlag string `json:"drt_reim_flag"`
  8816. FeedetlSn string `json:"feedetl_sn"`
  8817. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8818. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8819. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8820. ListSpItemFlag string `json:"list_sp_item_flag"`
  8821. LmtUsedFlag string `json:"lmt_used_flag"`
  8822. MedChrgitmType string `json:"med_chrgitm_type"`
  8823. Memo string `json:"memo"`
  8824. OverlmtAmt float64 `json:"overlmt_amt"`
  8825. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8826. Pric float64 `json:"pric"`
  8827. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8828. SelfpayProp float64 `json:"selfpay_prop"`
  8829. } `json:"result"`
  8830. } `json:"output"`
  8831. RefmsgTime string `json:"refmsg_time"`
  8832. RespondTime string `json:"respond_time"`
  8833. Signtype string `json:"signtype"`
  8834. WarnMsg string `json:"warn_msg"`
  8835. }
  8836. type ResultFive struct {
  8837. Insutype string `json:"insutype"`
  8838. }
  8839. type ResultSix struct {
  8840. Cainfo interface{} `json:"cainfo"`
  8841. ErrMsg interface{} `json:"err_msg"`
  8842. InfRefmsgid string `json:"inf_refmsgid"`
  8843. Infcode int64 `json:"infcode"`
  8844. Output struct {
  8845. } `json:"output"`
  8846. RefmsgTime string `json:"refmsg_time"`
  8847. RespondTime string `json:"respond_time"`
  8848. Signtype interface{} `json:"signtype"`
  8849. WarnMsg interface{} `json:"warn_msg"`
  8850. }
  8851. type ResultSeven struct {
  8852. Cainfo string `json:"cainfo"`
  8853. ErrMsg string `json:"err_msg"`
  8854. InfRefmsgid string `json:"inf_refmsgid"`
  8855. Infcode int64 `json:"infcode"`
  8856. Output struct {
  8857. Setldetail []interface{} `json:"setldetail"`
  8858. Setlinfo struct {
  8859. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8860. AcctPay float64 `json:"acct_pay"`
  8861. ActPayDedc float64 `json:"act_pay_dedc"`
  8862. Age float64 `json:"age"`
  8863. Balc float64 `json:"balc"`
  8864. Brdy string `json:"brdy"`
  8865. Certno string `json:"certno"`
  8866. ClrOptins string `json:"clr_optins"`
  8867. ClrType string `json:"clr_type"`
  8868. ClrWay string `json:"clr_way"`
  8869. CvlservFlag string `json:"cvlserv_flag"`
  8870. CvlservPay float64 `json:"cvlserv_pay"`
  8871. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8872. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8873. Gend string `json:"gend"`
  8874. HifesPay float64 `json:"hifes_pay"`
  8875. HifmiPay float64 `json:"hifmi_pay"`
  8876. HifobPay float64 `json:"hifob_pay"`
  8877. HifpPay float64 `json:"hifp_pay"`
  8878. HospPartAmt float64 `json:"hosp_part_amt"`
  8879. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8880. Insutype string `json:"insutype"`
  8881. MafPay float64 `json:"maf_pay"`
  8882. MdtrtCertType string `json:"mdtrt_cert_type"`
  8883. MdtrtID string `json:"mdtrt_id"`
  8884. MedType string `json:"med_type"`
  8885. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8886. MedinsSetlID string `json:"medins_setl_id"`
  8887. Naty string `json:"naty"`
  8888. OthPay float64 `json:"oth_pay"`
  8889. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8890. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8891. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8892. PsnCashPay float64 `json:"psn_cash_pay"`
  8893. PsnCertType string `json:"psn_cert_type"`
  8894. PsnName string `json:"psn_name"`
  8895. PsnNo string `json:"psn_no"`
  8896. PsnPartAmt float64 `json:"psn_part_amt"`
  8897. PsnType string `json:"psn_type"`
  8898. SetlID string `json:"setl_id"`
  8899. SetlTime string `json:"setl_time"`
  8900. } `json:"setlinfo"`
  8901. } `json:"output"`
  8902. RefmsgTime string `json:"refmsg_time"`
  8903. RespondTime string `json:"respond_time"`
  8904. Signtype interface{} `json:"signtype"`
  8905. WarnMsg interface{} `json:"warn_msg"`
  8906. }
  8907. type ResultEight struct {
  8908. Cainfo string `json:"cainfo"`
  8909. ErrMsg string `json:"err_msg"`
  8910. InfRefmsgid string `json:"inf_refmsgid"`
  8911. Infcode int64 `json:"infcode"`
  8912. Output struct {
  8913. Stmtinfo struct {
  8914. SetlOptins string `json:"setl_optins"`
  8915. StmtRslt string `json:"stmt_rslt"`
  8916. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8917. } `json:"stmtinfo"`
  8918. } `json:"output"`
  8919. RefmsgTime string `json:"refmsg_time"`
  8920. RespondTime string `json:"respond_time"`
  8921. Signtype interface{} `json:"signtype"`
  8922. WarnMsg interface{} `json:"warn_msg"`
  8923. }
  8924. type ResultNine struct {
  8925. Cainfo string `json:"cainfo"`
  8926. ErrMsg string `json:"err_msg"`
  8927. InfRefmsgid string `json:"inf_refmsgid"`
  8928. Infcode int64 `json:"infcode"`
  8929. Output struct {
  8930. FileQuryNo string `json:"file_qury_no"`
  8931. } `json:"output"`
  8932. RefmsgTime string `json:"refmsg_time"`
  8933. RespondTime string `json:"respond_time"`
  8934. Signtype interface{} `json:"signtype"`
  8935. WarnMsg interface{} `json:"warn_msg"`
  8936. }
  8937. type ResultTen struct {
  8938. Cainfo string `json:"cainfo"`
  8939. ErrMsg string `json:"err_msg"`
  8940. InfRefmsgid string `json:"inf_refmsgid"`
  8941. Infcode int64 `json:"infcode"`
  8942. Output struct {
  8943. DldEndtime string `json:"dld_endtime"`
  8944. FileQuryNo string `json:"file_qury_no"`
  8945. Filename string `json:"filename"`
  8946. } `json:"output"`
  8947. RefmsgTime string `json:"refmsg_time"`
  8948. RespondTime string `json:"respond_time"`
  8949. Signtype interface{} `json:"signtype"`
  8950. WarnMsg interface{} `json:"warn_msg"`
  8951. }
  8952. type ResultEleven struct {
  8953. Cainfo string `json:"cainfo"`
  8954. ErrMsg string `json:"err_msg"`
  8955. InfRefmsgid string `json:"inf_refmsgid"`
  8956. Infcode int64 `json:"infcode"`
  8957. Output struct {
  8958. Setlinfo struct {
  8959. FixmedinsName string `json:"fixmedins_name"`
  8960. FixmedinsCode string `json:"fixmedins_code"`
  8961. PsnNo string `json:"psn_no"`
  8962. PsnName string `json:"psn_name"`
  8963. HifobPay float64 `json:"hifob_pay"`
  8964. Gend string `json:"gend"`
  8965. Brdy string `json:"brdy"`
  8966. PsnCertType string `json:"psn_cert_type"`
  8967. PsnType string `json:"psn_type"`
  8968. EmpName string `json:"emp_name"`
  8969. Certno string `json:"certno"`
  8970. Insutype string `json:"insutype"`
  8971. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8972. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8973. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8974. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8975. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8976. ActPayDedc float64 `json:"act_pay_dedc"`
  8977. HifpPay float64 `json:"hifp_pay"`
  8978. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8979. CvlservPay float64 `json:"cvlserv_pay"`
  8980. HifesPay float64 `json:"hifes_pay"`
  8981. HifmiPay float64 `json:"hifmi_pay"`
  8982. MafPay float64 `json:"maf_pay"`
  8983. OthPay float64 `json:"oth_pay"`
  8984. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8985. PsnPay float64 `json:"psn_pay"`
  8986. AcctPay float64 `json:"acct_pay"`
  8987. CashPayamt float64 `json:"cash_payamt"`
  8988. Balc float64 `json:"balc"`
  8989. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8990. MedinsSetlId string `json:"medins_setl_id"`
  8991. RefdSetlFlag string `json:"refd_setl_flag"`
  8992. SetlTime string `json:"setl_time"`
  8993. MedType string `json:"med_type"`
  8994. } `json:"setlinfo"`
  8995. } `json:"output"`
  8996. RefmsgTime string `json:"refmsg_time"`
  8997. RespondTime string `json:"respond_time"`
  8998. Signtype interface{} `json:"signtype"`
  8999. WarnMsg interface{} `json:"warn_msg"`
  9000. }
  9001. type Custom struct {
  9002. DetItemFeeSumamt string
  9003. Cut string
  9004. FeedetlSn string
  9005. Price string
  9006. MedListCodg string
  9007. Type int64
  9008. AdviceId int64
  9009. ProjectId int64
  9010. ItemId int64
  9011. CostType int64
  9012. }
  9013. // 获取个人信息----挂号-----上传就诊信息
  9014. func (c *HisApiController) GetRegisterInfo() {
  9015. id, _ := c.GetInt64("id")
  9016. record_time := c.GetString("record_time")
  9017. settlementValue, _ := c.GetInt64("settlement_value")
  9018. medical_insurance_card := c.GetString("medical_insurance_card")
  9019. name := c.GetString("name")
  9020. id_card_type, _ := c.GetInt64("id_card_type")
  9021. certificates, _ := c.GetInt64("certificates")
  9022. medical_care, _ := c.GetInt64("medical_care")
  9023. birthday := c.GetString("birthday")
  9024. age, _ := c.GetInt64("age")
  9025. id_card := c.GetString("id_card")
  9026. register_type, _ := c.GetInt64("register")
  9027. doctor, _ := c.GetInt64("doctor")
  9028. department, _ := c.GetInt64("department")
  9029. gender, _ := c.GetInt64("sex")
  9030. phone := c.GetString("phone")
  9031. registration_fee, _ := c.GetFloat("registration_fee")
  9032. medical_expenses, _ := c.GetFloat("medical_expenses")
  9033. social_type, _ := c.GetInt64("social_type")
  9034. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9035. diagnosis_ids := c.GetString("diagnosis")
  9036. sick_type, _ := c.GetInt64("sick_type")
  9037. reg_type := c.GetString("p_type")
  9038. timeLayout := "2006-01-02"
  9039. loc, _ := time.LoadLocation("Local")
  9040. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9041. birthUnix := birthdays.Unix()
  9042. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9043. if err != nil {
  9044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9045. return
  9046. }
  9047. recordDateTime := theTime.Unix()
  9048. adminInfo := c.GetAdminUserInfo()
  9049. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9050. if tempPatient.ID == 0 {
  9051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9052. return
  9053. }
  9054. var patient service.Patients
  9055. if id == 0 {
  9056. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9057. } else {
  9058. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9059. }
  9060. if patient.ID == 0 {
  9061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9062. return
  9063. }
  9064. if len(patient.IdCardNo) == 0 {
  9065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9066. return
  9067. }
  9068. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9069. if len(his) >= 1 {
  9070. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9071. if len(his) >= 1 && order.ID == 0 {
  9072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9073. return
  9074. }
  9075. }
  9076. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9077. fmt.Println(timeStr)
  9078. timeArr := strings.Split(timeStr, " ")
  9079. fmt.Println(timeArr)
  9080. timeArrTwo := strings.Split(timeArr[0], "-")
  9081. timeArrThree := strings.Split(timeArr[1], ":")
  9082. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9083. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9084. if len(lists) == 0 {
  9085. var hisPatient models.XtHisPatient
  9086. hisPatient = models.XtHisPatient{
  9087. Name: name,
  9088. Age: age,
  9089. Gender: gender,
  9090. Birthday: birthUnix,
  9091. Phone: phone,
  9092. MedicalTreatmentType: medical_care,
  9093. IdType: certificates,
  9094. IdCardNo: id_card,
  9095. BalanceAccountsType: settlementValue,
  9096. SocialType: social_type,
  9097. MedicalInsuranceNumber: medical_insurance_card,
  9098. RegisterType: register_type,
  9099. RegisterCost: registration_fee,
  9100. TreatmentCost: medical_expenses,
  9101. AdminUserId: adminInfo.AdminUser.Id,
  9102. UserOrgId: adminInfo.CurrentOrgId,
  9103. Status: 1,
  9104. RecordDate: recordDateTime,
  9105. IsReturn: 1,
  9106. PatientId: patient.ID,
  9107. Ctime: time.Now().Unix(),
  9108. Mtime: time.Now().Unix(),
  9109. Number: str,
  9110. IdCardType: id_card_type,
  9111. Departments: department,
  9112. Doctor: doctor,
  9113. PType: reg_type,
  9114. Diagnosis: diagnosis_ids,
  9115. SickType: sick_type,
  9116. }
  9117. service.CreateHisPatient(&hisPatient)
  9118. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9119. c.ServeSuccessJSON(map[string]interface{}{
  9120. "his_info": hisPatient,
  9121. })
  9122. } else {
  9123. //chrgBchno := rand.Intn(1000000) + 10000
  9124. var hisPatient models.XtHisPatient
  9125. hisPatient = models.XtHisPatient{
  9126. Name: name,
  9127. Age: age,
  9128. Gender: gender,
  9129. Birthday: birthUnix,
  9130. Phone: phone,
  9131. MedicalTreatmentType: medical_care,
  9132. IdType: certificates,
  9133. IdCardNo: id_card,
  9134. BalanceAccountsType: settlementValue,
  9135. SocialType: social_type,
  9136. MedicalInsuranceNumber: medical_insurance_card,
  9137. RegisterType: register_type,
  9138. RegisterCost: registration_fee,
  9139. TreatmentCost: medical_expenses,
  9140. AdminUserId: adminInfo.AdminUser.Id,
  9141. UserOrgId: adminInfo.CurrentOrgId,
  9142. Status: 1,
  9143. RecordDate: recordDateTime,
  9144. IsReturn: 1,
  9145. PatientId: patient.ID,
  9146. Ctime: time.Now().Unix(),
  9147. Mtime: time.Now().Unix(),
  9148. Number: str,
  9149. IdCardType: id_card_type,
  9150. Departments: department,
  9151. Doctor: doctor,
  9152. PType: reg_type,
  9153. Diagnosis: diagnosis_ids,
  9154. SickType: sick_type,
  9155. }
  9156. service.CreateHisPatient(&hisPatient)
  9157. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9158. c.ServeSuccessJSON(map[string]interface{}{
  9159. "his_info": hisPatient,
  9160. })
  9161. }
  9162. }
  9163. // 上传明细----结算
  9164. func (c *HisApiController) GetUploadInfo() {
  9165. id, _ := c.GetInt64("id")
  9166. record_time := c.GetString("record_time")
  9167. his_patient_id, _ := c.GetInt64("his_patient_id")
  9168. oth_desc := c.GetString("oth_desc")
  9169. pay_way, _ := c.GetInt64("pay_way")
  9170. pay_ways := c.GetString("pay_ways")
  9171. pay_price, _ := c.GetFloat("pay_price")
  9172. pay_card_no := c.GetString("pay_card_no")
  9173. discount_price, _ := c.GetFloat("discount_price")
  9174. preferential_price, _ := c.GetFloat("preferential_price")
  9175. reality_price, _ := c.GetFloat("reality_price")
  9176. found_price, _ := c.GetFloat("found_price")
  9177. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9178. private_price, _ := c.GetFloat("private_price")
  9179. timeLayout := "2006-01-02"
  9180. loc, _ := time.LoadLocation("Local")
  9181. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9182. fapiao_code := c.GetString("fapiao_code")
  9183. fapiao_number := c.GetString("fapiao_number")
  9184. diagnosis_id := c.GetString("diagnosis")
  9185. sick_type, _ := c.GetInt64("sick_type")
  9186. reg_type, _ := c.GetInt64("p_type")
  9187. order_id, _ := c.GetInt64("order_id")
  9188. cash_pay := c.GetString("cash_pay")
  9189. wechat_pay := c.GetString("wechat_pay")
  9190. ali_pay := c.GetString("ali_pay")
  9191. jifen_pay := c.GetString("jifen_pay")
  9192. card_desc := c.GetString("card_desc")
  9193. band_card_pay := c.GetString("band_card_pay")
  9194. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9195. tmp_decimal := c.GetString("tmp_decimal")
  9196. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9197. var decimal float64 //本次使用的押金
  9198. var errmsg error
  9199. tx := service.XTWriteDB().Begin() //开了事务
  9200. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9201. defer func() {
  9202. if errmsg != nil {
  9203. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9204. tx.Rollback()
  9205. } else {
  9206. tx.Commit()
  9207. }
  9208. }()
  9209. fmt.Println("dec_way", dec_way)
  9210. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9211. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9212. return
  9213. }
  9214. if len(tmp_decimal) > 0 {
  9215. if tmp_decimal[0] == 45 {
  9216. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9217. return
  9218. }
  9219. }
  9220. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9221. fmt.Println(errs)
  9222. decimal = tt
  9223. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9224. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9225. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9226. if err != nil {
  9227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9228. return
  9229. }
  9230. recordDateTime := theTime.Unix()
  9231. adminUser := c.GetAdminUserInfo()
  9232. var prescriptions []*models.HisPrescription
  9233. var prescriptionsOne []*models.HisPrescription
  9234. var start_time int64
  9235. var end_time int64
  9236. ids_str := c.GetString("ids")
  9237. ids_arr := strings.Split(ids_str, ",")
  9238. if tempOrder.ID == 0 {
  9239. if settle_accounts_type == 1 { //日结
  9240. fmt.Println(reg_type)
  9241. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9242. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9243. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9244. } else {
  9245. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9246. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9247. }
  9248. } else { //月结
  9249. start_time_str := c.GetString("start_time")
  9250. end_time_str := c.GetString("end_time")
  9251. timeLayout := "2006-01-02"
  9252. loc, _ := time.LoadLocation("Local")
  9253. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9254. if err != nil {
  9255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9256. return
  9257. }
  9258. recordStartTime := theStartTime.Unix()
  9259. start_time = recordStartTime
  9260. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9261. if err != nil {
  9262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9263. return
  9264. }
  9265. recordEndTime := theEndTime.Unix()
  9266. end_time = recordEndTime
  9267. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9268. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9269. }
  9270. var goods []*models.DialysisBeforePrepareGoods
  9271. var newGoods []*models.NewDialysisBeforePrepareGoods
  9272. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9273. var infos []*models.HisDoctorAdviceInfo
  9274. var infoList []*models.HisDoctorAdviceInfo
  9275. var hisAdvice []*models.HisDoctorAdviceInfo
  9276. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9277. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9278. //判断库存不足
  9279. //结算出库开关
  9280. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9281. if settConfig.IsOpen == 1 {
  9282. //判断库存的地方
  9283. for _, info := range prescriptions {
  9284. if info.Type == 1 {
  9285. infos = append(infos, info.HisDoctorAdviceInfo...)
  9286. }
  9287. if info.Type == 2 {
  9288. for _, sumItem := range info.HisPrescriptionProject {
  9289. if sumItem.Type == 3 {
  9290. var good models.DialysisBeforePrepareGoods
  9291. var newGood models.NewDialysisBeforePrepareGoods
  9292. good.GoodId = sumItem.GoodInfo.ID
  9293. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9294. count, _ := strconv.Atoi(sumItem.Count)
  9295. good.Count = int64(count)
  9296. good.StorehouseId = houseConfig.StorehouseOutInfo
  9297. good.ProjectId = sumItem.ID
  9298. goods = append(goods, &good)
  9299. newGood.GoodId = sumItem.GoodInfo.ID
  9300. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9301. count2, _ := strconv.Atoi(sumItem.Count)
  9302. newGood.Count = int64(count2)
  9303. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9304. newGood.ProjectId = sumItem.ID
  9305. newGoods = append(newGoods, &newGood)
  9306. }
  9307. }
  9308. }
  9309. }
  9310. for _, info := range prescriptionsOne {
  9311. if info.Type == 1 {
  9312. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9313. }
  9314. if info.Type == 2 {
  9315. for _, sumItem := range info.HisPrescriptionProject {
  9316. if sumItem.Type == 3 {
  9317. var newGood models.NewDialysisBeforePrepareGoods
  9318. newGood.GoodId = sumItem.GoodInfo.ID
  9319. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9320. count2, _ := strconv.Atoi(sumItem.Count)
  9321. newGood.Count = int64(count2)
  9322. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9323. newGood.ProjectId = sumItem.ID
  9324. newGoodOne = append(newGoodOne, &newGood)
  9325. }
  9326. }
  9327. }
  9328. }
  9329. //判断
  9330. for _, itemOne := range infos {
  9331. for _, itemTwo := range hisAdvice {
  9332. if itemOne.DrugId == itemTwo.DrugId {
  9333. itemTwo.Child = append(itemTwo.Child, itemOne)
  9334. }
  9335. }
  9336. }
  9337. for _, itemTwo := range hisAdvice {
  9338. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9339. var sum_out_count int64
  9340. for _, itemThree := range itemTwo.Child {
  9341. var prescribing_number int64
  9342. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9343. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9344. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9345. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9346. }
  9347. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9348. prescribing_number = parseIntPrescribingNumber
  9349. }
  9350. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9351. prescribing_number = parseIntPrescribingNumber
  9352. }
  9353. sum_out_count += prescribing_number
  9354. }
  9355. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9356. if sum_out_count > drugStockOut.FlushCount {
  9357. c.ServeSuccessJSON(map[string]interface{}{
  9358. "msg": "2",
  9359. "drug": medical,
  9360. })
  9361. return
  9362. }
  9363. }
  9364. for _, itemOne := range newGoods {
  9365. for _, item := range newGoodOne {
  9366. if itemOne.GoodId == item.GoodId {
  9367. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9368. }
  9369. }
  9370. }
  9371. for _, item := range newGoodOne {
  9372. var sum_out_count_one int64
  9373. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9374. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9375. sum_out_count_one += itemOne.Count
  9376. }
  9377. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9378. fmt.Println("sum_out_count_one", sum_out_count_one)
  9379. fmt.Println("list.FlushCount", list.FlushCount)
  9380. if sum_out_count_one > list.FlushCount {
  9381. c.ServeSuccessJSON(map[string]interface{}{
  9382. "msg": "3",
  9383. "good": good,
  9384. })
  9385. return
  9386. }
  9387. }
  9388. }
  9389. timestamp := time.Now().Unix()
  9390. tempTime := time.Unix(timestamp, 0)
  9391. timeFormat := tempTime.Format("20060102150405")
  9392. chrgBchno := rand.Intn(100000) + 10000
  9393. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9394. strconv.FormatInt(his.PatientId, 10)
  9395. var ids []int64
  9396. for _, item := range prescriptions {
  9397. ids = append(ids, item.ID)
  9398. }
  9399. var total float64
  9400. for _, item := range prescriptions {
  9401. fmt.Println(item)
  9402. if item.Type == 1 { //药品
  9403. for _, subItem := range item.HisDoctorAdviceInfo {
  9404. total = total + (subItem.Price * subItem.PrescribingNumber)
  9405. }
  9406. }
  9407. if item.Type == 2 { //项目
  9408. for _, subItem := range item.HisPrescriptionProject {
  9409. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9410. total = total + (subItem.Price * cnt)
  9411. }
  9412. }
  9413. for _, subItem := range item.HisAdditionalCharge {
  9414. total = total + (subItem.Price * float64(subItem.Count))
  9415. }
  9416. }
  9417. if reg_type == 1111 || reg_type == 1112 {
  9418. reg_type = 11
  9419. }
  9420. tm := time.Unix(time.Now().Unix(), 0)
  9421. allTotal := fmt.Sprintf("%.4f", total)
  9422. totals, _ := strconv.ParseFloat(allTotal, 64)
  9423. order := &models.HisOrder{
  9424. UserOrgId: adminUser.CurrentOrgId,
  9425. HisPatientId: his.ID,
  9426. PatientId: id,
  9427. SettleAccountsDate: recordDateTime,
  9428. Ctime: time.Now().Unix(),
  9429. Mtime: time.Now().Unix(),
  9430. Status: 1,
  9431. OrderStatus: 2,
  9432. MdtrtId: his.Number,
  9433. Number: chrg_bchno,
  9434. MedfeeSumamt: totals,
  9435. PayWay: pay_way,
  9436. PayWays: pay_ways,
  9437. PayPrice: pay_price,
  9438. MedType: strconv.Itoa(int(reg_type)),
  9439. PayCardNo: pay_card_no,
  9440. DiscountPrice: discount_price,
  9441. PreferentialPrice: preferential_price,
  9442. RealityPrice: reality_price,
  9443. FoundPrice: found_price,
  9444. MedicalInsurancePrice: medical_insurance_price,
  9445. PrivatePrice: private_price,
  9446. SettleEndTime: end_time,
  9447. SettleStartTime: start_time,
  9448. PsnPartAmt: totals,
  9449. PsnCashPay: totals,
  9450. SettleType: settle_accounts_type,
  9451. FaPiaoCode: fapiao_code,
  9452. FaPiaoNumber: fapiao_number,
  9453. Diagnosis: diagnosis_id,
  9454. PType: 2,
  9455. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9456. Decimal: decimal,
  9457. OthDesc: oth_desc,
  9458. CashPay: cash_pay,
  9459. WechatPay: wechat_pay,
  9460. AliPay: ali_pay,
  9461. JifenPay: jifen_pay,
  9462. BandCardPay: band_card_pay,
  9463. Creator: adminUser.AdminUser.Id,
  9464. CardDesc: card_desc,
  9465. }
  9466. err = service.CreateOrderTX(order, tx)
  9467. if err != nil {
  9468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9469. return
  9470. }
  9471. var customs []*Custom
  9472. for _, item := range prescriptions {
  9473. if item.Type == 1 { //药品a
  9474. for _, subItem := range item.HisDoctorAdviceInfo {
  9475. cus := &Custom{
  9476. AdviceId: subItem.ID,
  9477. ProjectId: 0,
  9478. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9479. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9480. FeedetlSn: subItem.FeedetlSn,
  9481. Price: fmt.Sprintf("%.4f", subItem.Price),
  9482. MedListCodg: subItem.MedListCodg,
  9483. Type: 1,
  9484. CostType: 9,
  9485. }
  9486. customs = append(customs, cus)
  9487. }
  9488. }
  9489. if item.Type == 2 { //项目
  9490. for _, subItem := range item.HisPrescriptionProject {
  9491. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9492. cus := &Custom{
  9493. AdviceId: 0,
  9494. ProjectId: subItem.ID,
  9495. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9496. Cut: fmt.Sprintf("%.4f", cnt),
  9497. FeedetlSn: subItem.FeedetlSn,
  9498. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9499. MedListCodg: subItem.MedListCodg,
  9500. Type: 2,
  9501. CostType: subItem.HisProject.CostClassify,
  9502. }
  9503. customs = append(customs, cus)
  9504. }
  9505. }
  9506. for _, item := range item.HisAdditionalCharge {
  9507. cus := &Custom{
  9508. ItemId: item.ID,
  9509. AdviceId: 0,
  9510. ProjectId: 0,
  9511. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9512. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9513. FeedetlSn: item.FeedetlSn,
  9514. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9515. MedListCodg: item.XtHisAddtionConfig.Code,
  9516. Type: 3,
  9517. CostType: 5,
  9518. }
  9519. customs = append(customs, cus)
  9520. }
  9521. }
  9522. for _, item := range customs {
  9523. var advice_id int64 = 0
  9524. var project_id int64 = 0
  9525. var item_id int64 = 0
  9526. var types int64 = 0
  9527. var med_chrgitm_type string
  9528. if item.Type == 1 {
  9529. advice_id = item.AdviceId
  9530. project_id = 0
  9531. item_id = 0
  9532. med_chrgitm_type = "09"
  9533. } else if item.Type == 2 {
  9534. med_chrgitm_type = "05"
  9535. if item.CostType == 3 {
  9536. med_chrgitm_type = "04"
  9537. }
  9538. if item.CostType == 8 {
  9539. med_chrgitm_type = "03"
  9540. }
  9541. advice_id = 0
  9542. item_id = 0
  9543. project_id = item.ProjectId
  9544. } else if item.Type == 3 {
  9545. advice_id = 0
  9546. item_id = item.ItemId
  9547. project_id = 0
  9548. med_chrgitm_type = "08"
  9549. }
  9550. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9551. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9552. pric, _ := strconv.ParseFloat(item.Price, 32)
  9553. info := &models.HisOrderInfo{
  9554. OrderNumber: order.Number,
  9555. UploadDate: time.Now().Unix(),
  9556. AdviceId: advice_id,
  9557. DetItemFeeSumamt: detItemFeeSumamt,
  9558. MedChrgitmType: med_chrgitm_type,
  9559. Cnt: cut,
  9560. Pric: pric,
  9561. PatientId: id,
  9562. Status: 1,
  9563. Mtime: time.Now().Unix(),
  9564. Ctime: time.Now().Unix(),
  9565. UserOrgId: adminUser.CurrentOrgId,
  9566. HisPatientId: his.ID,
  9567. OrderId: order.ID,
  9568. ProjectId: project_id,
  9569. Type: types,
  9570. ItemId: item_id,
  9571. }
  9572. service.CreateOrderInfoTX(info, tx)
  9573. }
  9574. his.Diagnosis = diagnosis_id
  9575. his.SickType = sick_type
  9576. his.RegisterType = reg_type
  9577. his.MedicalTreatmentType = reg_type
  9578. service.UpdataHisPateintTX(&his, tx)
  9579. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9580. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9581. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9582. //判断是否使用了押金
  9583. if dec_way == "true" {
  9584. tmpstring := strconv.FormatInt(order.ID, 10)
  9585. //扣押金
  9586. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9587. order.Decimal = decimal
  9588. service.UpDateOrderTwo(order, tx)
  9589. if errmsg != nil {
  9590. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9591. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9592. return
  9593. }
  9594. }
  9595. if err == nil {
  9596. for _, info := range prescriptions {
  9597. if info.Type == 1 {
  9598. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9599. }
  9600. if info.Type == 2 {
  9601. for _, sumItem := range info.HisPrescriptionProject {
  9602. if sumItem.Type == 3 {
  9603. var good models.DialysisBeforePrepareGoods
  9604. var newGood models.NewDialysisBeforePrepareGoods
  9605. var oldGood models.OldDialysisBeforePrepareGoods
  9606. good.GoodId = sumItem.GoodInfo.ID
  9607. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9608. count, _ := strconv.Atoi(sumItem.Count)
  9609. good.Count = int64(count)
  9610. good.StorehouseId = houseConfig.StorehouseOutInfo
  9611. good.ProjectId = sumItem.ID
  9612. good.PatientId = sumItem.PatientId
  9613. goods = append(goods, &good)
  9614. newGood.GoodId = sumItem.GoodInfo.ID
  9615. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9616. count2, _ := strconv.Atoi(sumItem.Count)
  9617. newGood.Count = int64(count2)
  9618. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9619. newGood.ProjectId = sumItem.ID
  9620. newGood.PatientId = sumItem.HisPatientId
  9621. newGoods = append(newGoods, &newGood)
  9622. oldGood.GoodId = sumItem.GoodInfo.ID
  9623. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9624. count3, _ := strconv.Atoi(sumItem.Count)
  9625. oldGood.Count = int64(count3)
  9626. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9627. oldGood.ProjectId = sumItem.ID
  9628. oldGood.RecordDate = sumItem.RecordDate
  9629. oldGood.PatientId = sumItem.HisPatientId
  9630. oldGoods = append(oldGoods, &oldGood)
  9631. }
  9632. }
  9633. }
  9634. }
  9635. if settConfig.IsOpen == 1 {
  9636. for _, item := range infoList {
  9637. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9638. if medical.IsUse == 2 {
  9639. //药品出库
  9640. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9641. //查询默认仓库
  9642. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9643. //查询默认仓库剩余多少库存
  9644. var sum_count int64
  9645. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9646. for _, its := range stockInfo {
  9647. if its.MaxUnit == medical.MaxUnit {
  9648. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9649. }
  9650. sum_count += its.StockMaxNumber + its.StockMinNumber
  9651. }
  9652. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9653. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9654. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9655. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9656. }
  9657. }
  9658. orgId := c.GetAdminUserInfo().CurrentOrgId
  9659. if len(oldGoods) > 0 {
  9660. timeStr := time.Now().Format("2006-01-02")
  9661. timeArr := strings.Split(timeStr, "-")
  9662. total, _ := service.FindAllWarehouseOut(orgId)
  9663. total = total + 1
  9664. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9665. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9666. number = number + total
  9667. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9668. operation_time := time.Now().Unix()
  9669. creater := c.GetAdminUserInfo().AdminUser.Id
  9670. //查询默认出库仓库库存
  9671. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9672. recordDateStr := time.Now().Format("2006-01-02")
  9673. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9674. nowtime := recordDate.Unix()
  9675. warehouseOut := models.WarehouseOut{
  9676. WarehouseOutOrderNumber: warehousing_out_order,
  9677. OperationTime: operation_time,
  9678. OrgId: orgId,
  9679. Creater: creater,
  9680. Ctime: time.Now().Unix(),
  9681. Status: 1,
  9682. WarehouseOutTime: nowtime,
  9683. Type: 1,
  9684. StorehouseId: storeConfig.StorehouseOutInfo,
  9685. IsCheck: 1,
  9686. OrderId: order.ID,
  9687. IsSys: 5,
  9688. }
  9689. //查询是否生成出库单
  9690. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9691. if out.ID == 0 {
  9692. service.AddSigleWarehouseOut(&warehouseOut)
  9693. }
  9694. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9695. for _, item := range oldGoods {
  9696. dialyPrepareOne := models.DialysisBeforePrepare{
  9697. GoodTypeId: item.GoodTypeId,
  9698. GoodId: item.GoodId,
  9699. PatientId: his.PatientId,
  9700. RecordDate: item.RecordDate,
  9701. UserOrgId: adminUser.CurrentOrgId,
  9702. Count: item.Count,
  9703. Ctime: time.Now().Unix(),
  9704. Creater: adminUser.AdminUser.Id,
  9705. CommdityCode: item.CommdityCode,
  9706. Status: 1,
  9707. StorehouseId: houseConfig.StorehouseOutInfo,
  9708. }
  9709. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9710. //非零用
  9711. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9712. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9713. //查询剩余库存
  9714. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9715. var sum_count int64
  9716. for _, item := range goodList {
  9717. sum_count += item.StockCount
  9718. }
  9719. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9720. //耗材
  9721. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9722. }
  9723. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9724. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9725. //查询剩余库存
  9726. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9727. var sum_count int64
  9728. for _, item := range goodList {
  9729. sum_count += item.StockCount
  9730. }
  9731. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9732. //耗材
  9733. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9734. }
  9735. }
  9736. }
  9737. }
  9738. c.ServeSuccessJSON(map[string]interface{}{
  9739. "msg": "结算成功",
  9740. })
  9741. }
  9742. }
  9743. }
  9744. // 退款
  9745. func (c *HisApiController) Refund() {
  9746. order_id, _ := c.GetInt64("order_id")
  9747. order, _ := service.GetHisOrderByID(order_id)
  9748. adminUser := c.GetAdminUserInfo()
  9749. orgid := c.GetAdminUserInfo().CurrentOrgId
  9750. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9751. if err != nil {
  9752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9753. return
  9754. }
  9755. tmp := strconv.FormatInt(order.ID, 10)
  9756. //当押金不为零时产生退费记录
  9757. if order.Decimal != 0 {
  9758. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9759. if err != nil {
  9760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9761. return
  9762. }
  9763. }
  9764. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9765. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9766. var goods []*models.DialysisBeforePrepareGoods
  9767. var newGoods []*models.NewDialysisBeforePrepareGoods
  9768. var infos []*models.HisDoctorAdviceInfo
  9769. for _, info := range orders {
  9770. if info.AdviceId > 0 && info.ProjectId == 0 {
  9771. infos = append(infos, &info.HisDoctorAdviceInfo)
  9772. }
  9773. if info.ProjectId > 0 && info.AdviceId == 0 {
  9774. if info.HisPrescriptionProject.Type == 3 {
  9775. var good models.DialysisBeforePrepareGoods
  9776. var newGood models.NewDialysisBeforePrepareGoods
  9777. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9778. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9779. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9780. good.Count = int64(count)
  9781. good.StorehouseId = houseConfig.StorehouseOutInfo
  9782. good.ProjectId = info.HisPrescriptionProject.ID
  9783. good.PatientId = info.PatientId
  9784. good.OrderId = order_id
  9785. goods = append(goods, &good)
  9786. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9787. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9788. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9789. newGood.Count = int64(count2)
  9790. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9791. newGood.ProjectId = info.HisPrescriptionProject.ID
  9792. newGood.RecordDate = order.SettleAccountsDate
  9793. newGood.UserOrgId = order.UserOrgId
  9794. newGood.PatientId = info.PatientId
  9795. newGood.OrderId = order_id
  9796. newGoods = append(newGoods, &newGood)
  9797. }
  9798. }
  9799. }
  9800. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9801. if settConfig.IsOpen == 1 {
  9802. for _, item := range infos {
  9803. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9804. }
  9805. for _, item := range newGoods {
  9806. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9807. }
  9808. }
  9809. c.ServeSuccessJSON(map[string]interface{}{
  9810. "msg": "退费成功",
  9811. })
  9812. }
  9813. func (c *HisApiController) RefundNumber() {
  9814. his_patient_id, _ := c.GetInt64("id")
  9815. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9816. info.Status = 0
  9817. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9818. if count > 0 {
  9819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9820. return
  9821. }
  9822. err := service.SaveHisPatient(info)
  9823. if err == nil {
  9824. c.ServeSuccessJSON(map[string]interface{}{
  9825. "msg": "退号成功",
  9826. })
  9827. } else {
  9828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9829. return
  9830. }
  9831. }
  9832. func (this *HisApiController) AdditionalCharge() {
  9833. dataBody := make(map[string]interface{}, 0)
  9834. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9835. fmt.Println(err)
  9836. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9837. patient_id := int64(dataBody["patient_id"].(float64))
  9838. medicineData, _ := dataBody["medicineData"].([]interface{})
  9839. adminUserInfo := this.GetAdminUserInfo()
  9840. orgId := adminUserInfo.CurrentOrgId
  9841. admin_user_id := adminUserInfo.AdminUser.Id
  9842. timeStr := time.Now().Format("2006-01-02")
  9843. timeLayout := "2006-01-02 15:04:05"
  9844. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9845. timenow := timeStringToTime.Unix()
  9846. var additionalCharges []*models.HisAdditionalCharge
  9847. for _, item := range medicineData {
  9848. var randNum int
  9849. randNum = rand.Intn(10000) + 1000
  9850. timestamp := time.Now().Unix()
  9851. tempTime := time.Unix(timestamp, 0)
  9852. timeFormat := tempTime.Format("20060102150405")
  9853. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9854. items := item.(map[string]interface{})
  9855. money := items["price"].(string)
  9856. item_id_str := items["item_id"].(string)
  9857. name := items["name"].(string)
  9858. id_str := items["id"].(string)
  9859. moneys, _ := strconv.ParseInt(money, 10, 64)
  9860. monStr := strconv.FormatInt(moneys, 10)
  9861. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9862. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9863. id, _ := strconv.ParseInt(id_str, 10, 64)
  9864. additionalCharge := &models.HisAdditionalCharge{
  9865. ID: id,
  9866. HisPatientId: his_patient_id,
  9867. UserOrgId: orgId,
  9868. PatientId: patient_id,
  9869. RecordDate: timenow,
  9870. Price: monneyStr,
  9871. Status: 1,
  9872. ItemName: name,
  9873. ItemId: item_id,
  9874. AdminUserId: admin_user_id,
  9875. CreatedTime: time.Now().Unix(),
  9876. OrderStatus: 0,
  9877. PrescriptionNumber: "",
  9878. BatchNumber: "",
  9879. FeedetlSn: p_number,
  9880. }
  9881. service.CreateAdditionalCharge(additionalCharge)
  9882. additionalCharges = append(additionalCharges, additionalCharge)
  9883. }
  9884. this.ServeSuccessJSON(map[string]interface{}{
  9885. "msg": "添加成功",
  9886. "additional_charges": additionalCharges,
  9887. })
  9888. }
  9889. func (this *HisApiController) DeleteAddition() {
  9890. id, _ := this.GetInt64("id")
  9891. //TODO 需要判断是否已经结算
  9892. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9893. if err == nil {
  9894. this.ServeSuccessJSON(map[string]interface{}{
  9895. "msg": "删除成功",
  9896. })
  9897. return
  9898. } else {
  9899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9900. return
  9901. }
  9902. }
  9903. func (this *HisApiController) GetAdminUsers() {
  9904. adminUser := this.GetAdminUserInfo()
  9905. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9906. this.ServeSuccessJSON(map[string]interface{}{
  9907. "doctors": doctors,
  9908. })
  9909. }
  9910. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9911. change_type, _ := this.GetInt64("type", 0)
  9912. record_date := this.GetString("record_time")
  9913. patient_id, _ := this.GetInt64("patient_id", 0)
  9914. p_type, _ := this.GetInt64("p_type", 0)
  9915. timeLayout := "2006-01-02"
  9916. loc, _ := time.LoadLocation("Local")
  9917. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9918. record_time := theAdviceRecordTime.Unix()
  9919. adminUserInfo := this.GetAdminUserInfo()
  9920. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9921. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9922. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9923. if config.ID > 0 && config.IsOpen == 1 {
  9924. for _, subitems := range prescriptions {
  9925. for _, item := range subitems.VMHisPrescription {
  9926. for _, subItem := range item.HisDoctorAdviceInfo {
  9927. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9928. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9929. if info.RetailPrice > 0 {
  9930. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9931. subItem.Drug.RetailPrice = drug.RetailPrice
  9932. }
  9933. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9934. subItem.Drug.MinPrice = info.RetailPrice
  9935. subItem.Drug.RetailPrice = info.RetailPrice
  9936. }
  9937. }
  9938. }
  9939. }
  9940. }
  9941. }
  9942. if config.ID > 0 && config.IsOpen == 1 {
  9943. for _, subitems := range prescriptions {
  9944. for _, item := range subitems.VMHisPrescription {
  9945. for _, subItem := range item.HisPrescriptionProject {
  9946. if subItem.Type == 3 {
  9947. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9948. if info.Price > 0 {
  9949. subItem.GoodInfo.PackingPrice = info.Price
  9950. }
  9951. }
  9952. }
  9953. }
  9954. }
  9955. }
  9956. }
  9957. if err == nil {
  9958. if len(prescriptions) == 0 {
  9959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9960. return
  9961. } else {
  9962. this.ServeSuccessJSON(map[string]interface{}{
  9963. "prescriptions": prescriptions,
  9964. })
  9965. return
  9966. }
  9967. } else {
  9968. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9969. return
  9970. }
  9971. }
  9972. func (this *HisApiController) GetCallHisPrescription() {
  9973. patient_id, _ := this.GetInt64("patient_id", 0)
  9974. timeLayout := "2006-01-02"
  9975. loc, _ := time.LoadLocation("Local")
  9976. start_time := this.GetString("start_time")
  9977. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9978. end_time := this.GetString("end_time")
  9979. p_type, _ := this.GetInt64("p_type")
  9980. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9981. adminUserInfo := this.GetAdminUserInfo()
  9982. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9983. //if
  9984. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9985. //
  9986. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9987. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9988. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9989. if config.ID > 0 && config.IsOpen == 1 {
  9990. for _, subitems := range prescriptions {
  9991. for _, item := range subitems.VMHisPrescription {
  9992. for _, subItem := range item.HisDoctorAdviceInfo {
  9993. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9994. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9995. if info.RetailPrice > 0 {
  9996. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9997. subItem.Drug.RetailPrice = drug.RetailPrice
  9998. }
  9999. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10000. subItem.Drug.MinPrice = info.RetailPrice
  10001. subItem.Drug.RetailPrice = info.RetailPrice
  10002. }
  10003. }
  10004. }
  10005. }
  10006. }
  10007. }
  10008. if config.ID > 0 && config.IsOpen == 1 {
  10009. for _, subitems := range prescriptions {
  10010. for _, item := range subitems.VMHisPrescription {
  10011. for _, subItem := range item.HisPrescriptionProject {
  10012. if subItem.Type == 3 {
  10013. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10014. if info.Price > 0 {
  10015. subItem.GoodInfo.PackingPrice = info.Price
  10016. }
  10017. }
  10018. }
  10019. }
  10020. }
  10021. }
  10022. }
  10023. if err == nil {
  10024. this.ServeSuccessJSON(map[string]interface{}{
  10025. "prescriptions": prescriptions,
  10026. })
  10027. return
  10028. } else {
  10029. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10030. return
  10031. }
  10032. }
  10033. func (this *HisApiController) GetHisDayPrescription() {
  10034. timeLayout := "2006-01-02"
  10035. loc, _ := time.LoadLocation("Local")
  10036. start_time := this.GetString("start_time")
  10037. patient_id, _ := this.GetInt64("patient_id", 0)
  10038. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10039. end_time := this.GetString("end_time")
  10040. p_type, _ := this.GetInt64("p_type")
  10041. order_status, _ := this.GetInt64("type")
  10042. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10043. adminUserInfo := this.GetAdminUserInfo()
  10044. var dayHisPrescription []*models.HisPrescription
  10045. var err error
  10046. if order_status == 1 || order_status == 0 {
  10047. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10048. } else if order_status == 2 {
  10049. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10050. }
  10051. var settle_total float64
  10052. for _, item := range dayHisPrescription {
  10053. if len(item.HisPrescriptionProject) > 0 {
  10054. for _, subItem := range item.HisPrescriptionProject {
  10055. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10056. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10057. settle_total = settle_total + total
  10058. }
  10059. }
  10060. if len(item.HisDoctorAdviceInfo) > 0 {
  10061. for _, subItem := range item.HisDoctorAdviceInfo {
  10062. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10063. settle_total = settle_total + total
  10064. }
  10065. }
  10066. }
  10067. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10068. if err == nil {
  10069. this.ServeSuccessJSON(map[string]interface{}{
  10070. "day_prescription": dayHisPrescription,
  10071. "settle_total": settle_total,
  10072. })
  10073. return
  10074. } else {
  10075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10076. return
  10077. }
  10078. }
  10079. func (c *HisApiController) GetHisChargePatientList() {
  10080. record_date := c.GetString("record_date")
  10081. order_status, _ := c.GetInt64("type")
  10082. sch_type, _ := c.GetInt64("sch_type")
  10083. timeLayout := "2006-01-02"
  10084. loc, _ := time.LoadLocation("Local")
  10085. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10086. if err != nil {
  10087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10088. return
  10089. }
  10090. recordDateTime := theTime.Unix()
  10091. adminInfo := c.GetAdminUserInfo()
  10092. var tempPatients []*service.NewTempPatients
  10093. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10094. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10095. if order_status != 2 {
  10096. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10097. } else {
  10098. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10099. }
  10100. } else {
  10101. if order_status != 2 {
  10102. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10103. } else {
  10104. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10105. }
  10106. }
  10107. var patients []*service.NewTempPatients
  10108. var patients_two []*service.NewTempPatients
  10109. for _, item := range tempPatients {
  10110. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10111. //过滤掉没挂号的和没开处方的
  10112. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10113. patients = append(patients, item)
  10114. }
  10115. //过滤掉没挂号的
  10116. if len(item.HisPatient) > 0 {
  10117. patients_two = append(patients_two, item)
  10118. }
  10119. } else {
  10120. if len(item.HisPrescription) > 0 {
  10121. patients = append(patients, item)
  10122. }
  10123. }
  10124. }
  10125. c.ServeSuccessJSON(map[string]interface{}{
  10126. "list": patients,
  10127. "list_two": patients_two,
  10128. })
  10129. }
  10130. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10131. record_date := c.GetString("record_date")
  10132. timeLayout := "2006-01-02"
  10133. loc, _ := time.LoadLocation("Local")
  10134. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10135. if err != nil {
  10136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10137. return
  10138. }
  10139. recordDateTime := theTime.Unix()
  10140. adminUser := c.GetAdminUserInfo()
  10141. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10142. var patients []*service.Patients
  10143. for _, item := range tempPatients {
  10144. if item.HisPatient.ID == 0 {
  10145. patients = append(patients, item)
  10146. }
  10147. }
  10148. c.ServeSuccessJSON(map[string]interface{}{
  10149. "list": patients,
  10150. //"list_two": patients_two,
  10151. })
  10152. }
  10153. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10154. newArr = make([]*service.Patients, 0)
  10155. for i := 0; i < len(patient); i++ {
  10156. repeat := false
  10157. for j := i + 1; j < len(patient); j++ {
  10158. if patient[i].ID == patient[j].ID {
  10159. repeat = true
  10160. break
  10161. }
  10162. }
  10163. if !repeat {
  10164. newArr = append(newArr, patient[i])
  10165. }
  10166. }
  10167. return
  10168. }
  10169. func (c *HisApiController) GetHisChargePatientInfo() {
  10170. patient_id, _ := c.GetInt64("patient_id")
  10171. his_patient_id, _ := c.GetInt64("his_patient_id")
  10172. record_date := c.GetString("record_date")
  10173. //start_time := c.GetString("start_time")
  10174. //end_time := c.GetString("end_time")
  10175. order_status, _ := c.GetInt64("type", 0)
  10176. p_type, _ := c.GetInt64("p_type", 0)
  10177. order_id, _ := c.GetInt64("order_id", 0)
  10178. timeLayout := "2006-01-02"
  10179. loc, _ := time.LoadLocation("Local")
  10180. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10181. if err != nil {
  10182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10183. return
  10184. }
  10185. recordDateTime := theTime.Unix()
  10186. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10187. //if err != nil {
  10188. //
  10189. //}
  10190. //startRecordDateTime := startTime.Unix()
  10191. //
  10192. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10193. //if err != nil {
  10194. //
  10195. //}
  10196. //endRecordDateTime := endTime.Unix()
  10197. admin := c.GetAdminUserInfo()
  10198. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10199. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10200. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10201. var prescriptions []*models.HisPrescription
  10202. //var unChargeMonthPrescriptions []*models.HisPrescription
  10203. order, _ := service.GetHisOrderByID(order_id)
  10204. if order_status == 1 || order_status == 0 {
  10205. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10206. } else if order_status == 2 {
  10207. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10208. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10209. }
  10210. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10211. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10212. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10213. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10214. //获取所有科室信息
  10215. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10216. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10217. c.ServeSuccessJSON(map[string]interface{}{
  10218. "his_info": his_patient_info,
  10219. "last_his_patient_info": last_his_patient_info,
  10220. "xt_info": xt_patient_info,
  10221. "prescription": prescriptions,
  10222. "case_history": case_history,
  10223. "info": patientPrescriptionInfo,
  10224. "last_info": lastPatientPrescriptionInfo,
  10225. "order": order,
  10226. "doctors": doctors,
  10227. "department": department,
  10228. "sch": sch,
  10229. })
  10230. return
  10231. }
  10232. func (c *HisApiController) GetAllOrderDetail() {
  10233. order_id, _ := c.GetInt64("id", 0)
  10234. order, _ := service.GetHisOrderByID(order_id)
  10235. if order.ID == 0 {
  10236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10237. return
  10238. }
  10239. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10240. org_id := c.GetAdminUserInfo().CurrentOrgId
  10241. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10242. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10243. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10244. c.ServeSuccessJSON(map[string]interface{}{
  10245. "order": order,
  10246. "order_info": order_info,
  10247. "patient": patient,
  10248. "admin_info": adminInfo,
  10249. "hospital_record": record,
  10250. })
  10251. return
  10252. }
  10253. func (c *HisApiController) GetAllOrderDetailCollect() {
  10254. order_id, _ := c.GetInt64("id", 0)
  10255. order, _ := service.GetHisOrderByID(order_id)
  10256. if order.ID == 0 {
  10257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10258. return
  10259. }
  10260. org_id := c.GetAdminUserInfo().CurrentOrgId
  10261. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10262. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10263. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10264. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10265. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10266. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10267. var bedCostTotal float64 = 0 //床位总费
  10268. //var bedCostSelfTotal float64 = 0 //床位自费
  10269. var operationCostTotal float64 = 0 //手术费
  10270. //var operationCostSelfTotal float64 = 0 //手术费
  10271. var otherCostTotal float64 = 0 //其他费用
  10272. //var otherCostSelfTotal float64 = 0 //其他费用
  10273. var materialCostTotal float64 = 0 //材料费
  10274. //var materialCostSelfTotal float64 = 0 //材料费
  10275. var westernMedicineCostTotal float64 = 0 //西药费
  10276. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10277. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10278. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10279. var checkCostTotal float64 = 0 //检查费
  10280. //var checkCostSelfTotal float64 = 0 //检查费
  10281. var laboratoryCostTotal float64 = 0 //化验费
  10282. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10283. var treatCostTotal float64 = 0 //治疗费用
  10284. //var treatCostSelfTotal float64 = 0 //治疗费用
  10285. var zhenChaCostTotal float64 = 0 //其他费用
  10286. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10287. decimal.DivisionPrecision = 2
  10288. var BalanceAccountsType int64
  10289. if his.ID > 0 {
  10290. BalanceAccountsType = his.BalanceAccountsType
  10291. } else {
  10292. BalanceAccountsType = record.BalanceAccountsType
  10293. }
  10294. if BalanceAccountsType != 2 {
  10295. for _, item := range order_info {
  10296. if org_id == 10215 {
  10297. if item.MedChrgitmType == "01" { //床位费
  10298. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10299. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10300. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10301. }
  10302. if item.MedChrgitmType == "02" { //诊察费
  10303. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10304. //zhenChaCostSelfTotal = zhenChaCostTotal
  10305. }
  10306. if item.MedChrgitmType == "03" { //检查费
  10307. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10308. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10309. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10310. }
  10311. //if item.MedChrgitmType == "02" { //检查费
  10312. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10313. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10314. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10315. //}
  10316. if item.MedChrgitmType == "04" { //化验费
  10317. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10318. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10319. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10320. }
  10321. if item.MedChrgitmType == "05" { //治疗费
  10322. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10323. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10324. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10325. }
  10326. if item.MedChrgitmType == "06" { //手术费
  10327. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10328. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10329. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10330. }
  10331. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10332. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10333. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10334. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10335. }
  10336. if item.MedChrgitmType == "09" { //西药费
  10337. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10338. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10339. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10340. }
  10341. if item.MedChrgitmType == "11" { //中成费
  10342. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10343. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10344. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10345. }
  10346. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10347. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10348. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10349. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10350. }
  10351. } else if org_id == 10188 || org_id == 10217 {
  10352. if item.MedChrgitmType == "01" { //床位费
  10353. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10354. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10355. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10356. }
  10357. if item.MedChrgitmType == "02" { //诊察费
  10358. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10359. //zhenChaCostSelfTotal = zhenChaCostTotal
  10360. }
  10361. if item.MedChrgitmType == "03" { //检查费
  10362. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10363. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10364. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10365. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10366. }
  10367. //if item.MedChrgitmType == "02" { //检查费
  10368. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10369. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10370. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10371. //}
  10372. if item.MedChrgitmType == "04" { //化验费
  10373. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10374. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10375. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10376. }
  10377. if item.MedChrgitmType == "05" { //治疗费
  10378. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10379. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10380. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10381. }
  10382. if item.MedChrgitmType == "06" { //手术费
  10383. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10384. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10385. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10386. }
  10387. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10388. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10389. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10390. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10391. }
  10392. if item.MedChrgitmType == "09" { //西药费
  10393. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10394. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10395. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10396. }
  10397. if item.MedChrgitmType == "11" { //中成费
  10398. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10399. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10400. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10401. }
  10402. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10403. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10404. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10405. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10406. }
  10407. } else {
  10408. if item.MedChrgitmType == "01" { //床位费
  10409. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10410. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10411. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10412. }
  10413. //if item.MedChrgitmType == "02" { //诊察费
  10414. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10415. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10416. //}
  10417. if item.MedChrgitmType == "03" { //检查费
  10418. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10419. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10420. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10421. }
  10422. //if item.MedChrgitmType == "02" { //检查费
  10423. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10424. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10425. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10426. //}
  10427. if item.MedChrgitmType == "04" { //化验费
  10428. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10429. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10430. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10431. }
  10432. if item.MedChrgitmType == "05" { //治疗费
  10433. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10434. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10435. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10436. }
  10437. if item.MedChrgitmType == "06" { //手术费
  10438. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10439. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10440. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10441. }
  10442. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10443. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10444. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10445. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10446. }
  10447. if item.MedChrgitmType == "09" { //西药费
  10448. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10449. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10450. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10451. }
  10452. if item.MedChrgitmType == "11" { //中成费
  10453. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10454. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10455. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10456. }
  10457. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10458. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10459. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10460. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10461. }
  10462. }
  10463. }
  10464. c.ServeSuccessJSON(map[string]interface{}{
  10465. "order": order,
  10466. "order_info": order_info,
  10467. "patient": patient,
  10468. "admin_info": adminInfo,
  10469. "his_hospital": record,
  10470. "bedCostTotal": bedCostTotal,
  10471. "operationCostTotal": operationCostTotal,
  10472. "otherCostTotal": otherCostTotal,
  10473. "materialCostTotal": materialCostTotal,
  10474. "westernMedicineCostTotal": westernMedicineCostTotal,
  10475. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10476. "checkCostTotal": checkCostTotal,
  10477. "zhenChaCostTotal": zhenChaCostTotal,
  10478. "laboratoryCostTotal": laboratoryCostTotal,
  10479. "treatCostTotal": treatCostTotal,
  10480. })
  10481. } else {
  10482. for _, item := range order_info {
  10483. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10484. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10485. item.MedChrgitmType = "09"
  10486. }
  10487. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10488. if item.HisPrescriptionProject.Type == 2 {
  10489. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10490. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10491. case 0:
  10492. item.MedChrgitmType = "0"
  10493. break
  10494. case 1:
  10495. item.MedChrgitmType = "14"
  10496. break
  10497. case 2:
  10498. item.MedChrgitmType = "05"
  10499. break
  10500. case 3:
  10501. item.MedChrgitmType = "03"
  10502. break
  10503. case 4:
  10504. item.MedChrgitmType = "03"
  10505. break
  10506. case 5:
  10507. item.MedChrgitmType = "08"
  10508. break
  10509. case 6:
  10510. item.MedChrgitmType = "14"
  10511. break
  10512. case 7:
  10513. item.MedChrgitmType = "14"
  10514. break
  10515. case 8:
  10516. item.MedChrgitmType = "03"
  10517. break
  10518. case 9:
  10519. item.MedChrgitmType = "14"
  10520. break
  10521. case 10:
  10522. item.MedChrgitmType = "14"
  10523. break
  10524. case 11:
  10525. item.MedChrgitmType = "06"
  10526. break
  10527. case 12:
  10528. item.MedChrgitmType = "12"
  10529. break
  10530. case 13:
  10531. item.MedChrgitmType = "01"
  10532. break
  10533. case 14:
  10534. item.MedChrgitmType = "04"
  10535. break
  10536. case 15:
  10537. item.MedChrgitmType = "14"
  10538. break
  10539. }
  10540. } else {
  10541. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10542. case 1:
  10543. item.MedChrgitmType = "14"
  10544. break
  10545. case 2:
  10546. item.MedChrgitmType = "05"
  10547. break
  10548. case 3:
  10549. item.MedChrgitmType = "04"
  10550. break
  10551. case 4:
  10552. item.MedChrgitmType = "14"
  10553. break
  10554. case 5:
  10555. item.MedChrgitmType = "08"
  10556. break
  10557. case 6:
  10558. item.MedChrgitmType = "14"
  10559. break
  10560. case 7:
  10561. item.MedChrgitmType = "14"
  10562. break
  10563. case 8:
  10564. item.MedChrgitmType = "03"
  10565. break
  10566. case 9:
  10567. item.MedChrgitmType = "14"
  10568. break
  10569. }
  10570. }
  10571. } else if item.HisPrescriptionProject.Type == 3 {
  10572. item.MedChrgitmType = "08"
  10573. }
  10574. }
  10575. }
  10576. for _, item := range order_info {
  10577. if org_id == 10215 {
  10578. if item.MedChrgitmType == "01" { //床位费
  10579. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10580. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10581. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10582. }
  10583. if item.MedChrgitmType == "02" { //诊察费
  10584. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10585. //zhenChaCostSelfTotal = zhenChaCostTotal
  10586. }
  10587. if item.MedChrgitmType == "03" { //检查费
  10588. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10589. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10590. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10591. }
  10592. //if item.MedChrgitmType == "02" { //检查费
  10593. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10594. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10595. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10596. //}
  10597. if item.MedChrgitmType == "04" { //化验费
  10598. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10599. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10600. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10601. }
  10602. if item.MedChrgitmType == "05" { //治疗费
  10603. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10604. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10605. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10606. }
  10607. if item.MedChrgitmType == "06" { //手术费
  10608. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10609. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10610. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10611. }
  10612. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10613. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10614. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10615. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10616. }
  10617. if item.MedChrgitmType == "09" { //西药费
  10618. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10619. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10620. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10621. }
  10622. if item.MedChrgitmType == "11" { //中成费
  10623. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10624. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10625. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10626. }
  10627. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10628. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10629. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10630. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10631. }
  10632. } else {
  10633. if item.MedChrgitmType == "01" { //床位费
  10634. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10635. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10636. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10637. }
  10638. //if item.MedChrgitmType == "02" { //诊察费
  10639. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10640. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10641. //}
  10642. if item.MedChrgitmType == "03" { //检查费
  10643. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10644. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10645. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10646. }
  10647. //if item.MedChrgitmType == "02" { //检查费
  10648. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10649. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10650. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10651. //}
  10652. if item.MedChrgitmType == "04" { //化验费
  10653. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10654. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10655. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10656. }
  10657. if item.MedChrgitmType == "05" { //治疗费
  10658. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10659. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10660. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10661. }
  10662. if item.MedChrgitmType == "06" { //手术费
  10663. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10664. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10665. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10666. }
  10667. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10668. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10669. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10670. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10671. }
  10672. if item.MedChrgitmType == "09" { //西药费
  10673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10674. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10675. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10676. }
  10677. if item.MedChrgitmType == "11" { //中成费
  10678. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10679. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10680. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10681. }
  10682. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10683. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10684. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10685. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10686. }
  10687. }
  10688. }
  10689. c.ServeSuccessJSON(map[string]interface{}{
  10690. "order": order,
  10691. "order_info": order_info,
  10692. "patient": patient,
  10693. "admin_info": adminInfo,
  10694. "his_hospital": record,
  10695. "bedCostTotal": bedCostTotal,
  10696. "operationCostTotal": operationCostTotal,
  10697. "otherCostTotal": otherCostTotal,
  10698. "materialCostTotal": materialCostTotal,
  10699. "westernMedicineCostTotal": westernMedicineCostTotal,
  10700. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10701. "checkCostTotal": checkCostTotal,
  10702. "zhenChaCostTotal": zhenChaCostTotal,
  10703. "laboratoryCostTotal": laboratoryCostTotal,
  10704. "treatCostTotal": treatCostTotal,
  10705. })
  10706. }
  10707. }
  10708. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10709. page, _ := c.GetInt64("page")
  10710. limit, _ := c.GetInt64("limit")
  10711. keywords := c.GetString("keywords")
  10712. start_time := c.GetString("start_time")
  10713. end_time := c.GetString("end_time")
  10714. //clr_type := c.GetString("clr_type")
  10715. insutype := c.GetString("insutype")
  10716. timeLayout := "2006-01-02"
  10717. loc, _ := time.LoadLocation("Local")
  10718. var theStartTIme int64
  10719. if len(start_time) > 0 {
  10720. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10721. theStartTIme = theTime.Unix()
  10722. }
  10723. var theEndtTIme int64
  10724. if len(end_time) > 0 {
  10725. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10726. theEndtTIme = theTime.Unix()
  10727. }
  10728. if page <= 0 {
  10729. page = 1
  10730. }
  10731. if limit <= 0 {
  10732. limit = 10
  10733. }
  10734. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10735. c.ServeSuccessJSON(map[string]interface{}{
  10736. "total": total,
  10737. "list": list,
  10738. })
  10739. return
  10740. }
  10741. func (c *HisApiController) GetPutOnRecordList() {
  10742. page, _ := c.GetInt64("page")
  10743. limit, _ := c.GetInt64("limit")
  10744. keywords := c.GetString("keywords")
  10745. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10746. if page <= 0 {
  10747. page = 1
  10748. }
  10749. if limit <= 0 {
  10750. limit = 10
  10751. }
  10752. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10753. c.ServeSuccessJSON(map[string]interface{}{
  10754. "total": total,
  10755. "list": list,
  10756. })
  10757. return
  10758. }
  10759. func (c *HisApiController) GetCompareData() {
  10760. start_time := c.GetString("start_time")
  10761. end_time := c.GetString("end_time")
  10762. insutype := c.GetString("insutype")
  10763. clr_type := c.GetString("clr_type")
  10764. timeLayout := "2006-01-02"
  10765. loc, _ := time.LoadLocation("Local")
  10766. var theStartTIme int64
  10767. if len(start_time) > 0 {
  10768. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10769. if err != nil {
  10770. theStartTIme = 0
  10771. }
  10772. theStartTIme = theTime.Unix()
  10773. }
  10774. var theEndtTIme int64
  10775. if len(end_time) > 0 {
  10776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10777. if err != nil {
  10778. theEndtTIme = 0
  10779. }
  10780. theEndtTIme = theTime.Unix()
  10781. }
  10782. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10783. fmt.Println(err)
  10784. if err == nil {
  10785. c.ServeSuccessJSON(map[string]interface{}{
  10786. "list": formData,
  10787. })
  10788. } else {
  10789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10790. return
  10791. }
  10792. }
  10793. func (c *HisApiController) GetFaPiaoData() {
  10794. order_id, _ := c.GetInt64("order_id")
  10795. patient_id, _ := c.GetInt64("patient_id")
  10796. //number := c.GetString("number")
  10797. adminUser := c.GetAdminUserInfo()
  10798. order, _ := service.GetHisOrderByID(order_id)
  10799. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10800. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10801. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10802. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10803. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10804. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10805. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10806. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10807. var bedCostTotal float64 = 0 //床位总费
  10808. var bedCostSelfTotal float64 = 0 //床位自费
  10809. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10810. var operationCostTotal float64 = 0 //手术费
  10811. var operationCostSelfTotal float64 = 0 //手术费
  10812. var operationCostPartSelfTotal float64 = 0 //手术费
  10813. var otherCostTotal float64 = 0 //其他费用
  10814. var otherCostSelfTotal float64 = 0 //其他费用
  10815. var otherCostPartSelfTotal float64 = 0 //其他费用
  10816. var materialCostTotal float64 = 0 //材料费
  10817. var materialCostSelfTotal float64 = 0 //材料费
  10818. var materialCostPartSelfTotal float64 = 0 //材料费
  10819. var westernMedicineCostTotal float64 = 0 //西药费
  10820. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10821. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10822. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10823. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10824. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10825. var checkCostTotal float64 = 0 //检查费
  10826. var checkCostSelfTotal float64 = 0 //检查费
  10827. var checkCostPartSelfTotal float64 = 0 //检查费
  10828. var hiliCostTotal float64 = 0 //护理费
  10829. var hiliCostSelfTotal float64 = 0 //护理费
  10830. var hiliCostPartSelfTotal float64 = 0 //护理费
  10831. var laboratoryCostTotal float64 = 0 //化验费
  10832. var laboratoryCostSelfTotal float64 = 0 //化验费
  10833. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10834. var treatCostTotal float64 = 0 //治疗费用
  10835. var treatCostSelfTotal float64 = 0 //治疗费用
  10836. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10837. var zhenChaCostTotal float64 = 0 //其他费用
  10838. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10839. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10840. decimal.DivisionPrecision = 2
  10841. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10842. var balanceAccountsType int64
  10843. if his.ID > 0 {
  10844. balanceAccountsType = his.BalanceAccountsType
  10845. } else {
  10846. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10847. }
  10848. if balanceAccountsType == 2 {
  10849. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10850. for _, item := range orderInfos_two {
  10851. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10852. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10853. item.MedChrgitmType = "09"
  10854. }
  10855. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10856. if item.HisPrescriptionProject.Type == 2 {
  10857. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10858. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10859. case 0:
  10860. item.MedChrgitmType = "0"
  10861. break
  10862. case 1:
  10863. item.MedChrgitmType = "14"
  10864. break
  10865. case 2:
  10866. item.MedChrgitmType = "05"
  10867. break
  10868. case 3:
  10869. item.MedChrgitmType = "03"
  10870. break
  10871. case 4:
  10872. item.MedChrgitmType = "03"
  10873. break
  10874. case 5:
  10875. item.MedChrgitmType = "08"
  10876. break
  10877. case 6:
  10878. item.MedChrgitmType = "14"
  10879. break
  10880. case 7:
  10881. item.MedChrgitmType = "14"
  10882. break
  10883. case 8:
  10884. item.MedChrgitmType = "03"
  10885. break
  10886. case 9:
  10887. item.MedChrgitmType = "14"
  10888. break
  10889. case 10:
  10890. item.MedChrgitmType = "14"
  10891. break
  10892. case 11:
  10893. item.MedChrgitmType = "06"
  10894. break
  10895. case 12:
  10896. item.MedChrgitmType = "12"
  10897. break
  10898. case 13:
  10899. item.MedChrgitmType = "01"
  10900. break
  10901. case 14:
  10902. item.MedChrgitmType = "04"
  10903. break
  10904. case 15:
  10905. item.MedChrgitmType = "02"
  10906. break
  10907. }
  10908. } else {
  10909. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10910. case 1:
  10911. item.MedChrgitmType = "14"
  10912. break
  10913. case 2:
  10914. item.MedChrgitmType = "05"
  10915. break
  10916. case 3:
  10917. item.MedChrgitmType = "04"
  10918. break
  10919. case 4:
  10920. item.MedChrgitmType = "03"
  10921. break
  10922. case 5:
  10923. item.MedChrgitmType = "08"
  10924. break
  10925. case 6:
  10926. item.MedChrgitmType = "14"
  10927. break
  10928. case 7:
  10929. item.MedChrgitmType = "14"
  10930. break
  10931. case 8:
  10932. item.MedChrgitmType = "03"
  10933. break
  10934. case 9:
  10935. item.MedChrgitmType = "14"
  10936. break
  10937. }
  10938. }
  10939. } else if item.HisPrescriptionProject.Type == 3 {
  10940. item.MedChrgitmType = "08"
  10941. }
  10942. }
  10943. }
  10944. for _, item := range orderInfos_two {
  10945. fmt.Println(item.MedChrgitmType)
  10946. if item.MedChrgitmType == "07" { //床位费
  10947. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10948. hiliCostSelfTotal = hiliCostTotal
  10949. }
  10950. if item.MedChrgitmType == "01" { //床位费
  10951. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10952. bedCostSelfTotal = bedCostTotal
  10953. }
  10954. if item.MedChrgitmType == "02" { //诊察费
  10955. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10956. zhenChaCostSelfTotal = zhenChaCostTotal
  10957. }
  10958. if item.MedChrgitmType == "03" { //检查费
  10959. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10960. checkCostSelfTotal = checkCostTotal
  10961. }
  10962. if item.MedChrgitmType == "04" { //化验费
  10963. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10964. laboratoryCostSelfTotal = laboratoryCostTotal
  10965. }
  10966. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10967. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10968. treatCostSelfTotal = treatCostTotal
  10969. }
  10970. if item.MedChrgitmType == "06" { //手术费
  10971. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10972. operationCostSelfTotal = treatCostTotal
  10973. }
  10974. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10975. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10976. materialCostSelfTotal = materialCostTotal
  10977. }
  10978. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10979. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10980. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10981. }
  10982. if item.MedChrgitmType == "11" { //中成费
  10983. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10984. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10985. }
  10986. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10987. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10988. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10989. otherCostSelfTotal = otherCostTotal
  10990. }
  10991. } else {
  10992. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10993. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10994. otherCostSelfTotal = otherCostTotal
  10995. }
  10996. }
  10997. }
  10998. } else {
  10999. for _, item := range orderInfos {
  11000. if item.MedChrgitmType == "01" { //床位费
  11001. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11002. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11003. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11004. }
  11005. if item.MedChrgitmType == "02" { //诊察费
  11006. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11007. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11008. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11009. }
  11010. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11011. if item.MedChrgitmType == "03" { //检查费
  11012. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11013. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11014. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11015. }
  11016. } else {
  11017. if item.MedChrgitmType == "03" { //检查费
  11018. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11019. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11020. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11021. }
  11022. }
  11023. if item.MedChrgitmType == "04" { //化验费
  11024. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11025. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11026. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11027. }
  11028. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11029. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11030. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11031. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11032. }
  11033. if item.MedChrgitmType == "06" { //手术费
  11034. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11035. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11036. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11037. }
  11038. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11039. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11040. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11041. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11042. }
  11043. if item.MedChrgitmType == "07" { //护理
  11044. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11045. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11046. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11047. }
  11048. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11049. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11050. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11051. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11052. }
  11053. if item.MedChrgitmType == "11" { //中成费
  11054. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11055. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11056. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11057. }
  11058. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11059. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11060. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11061. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11062. }
  11063. }
  11064. }
  11065. timeLayout := "2006-01-02"
  11066. loc, _ := time.LoadLocation("Local")
  11067. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11068. if err != nil {
  11069. }
  11070. startRecordDateTime := startTime.Unix()
  11071. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11072. if err != nil {
  11073. }
  11074. endRecordDateTime := endTime.Unix()
  11075. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11076. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11077. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11078. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11079. c.ServeSuccessJSON(map[string]interface{}{
  11080. "charge_admin_name": charge_admin.UserName,
  11081. "order_number": order.Number, //业务流水号
  11082. "id_card_no": his.IdCardNo, //社会保障号
  11083. "patient": patient,
  11084. "department_name": department.Name, //科室
  11085. "number": his.Number, //门诊号
  11086. "date": order.SettleAccountsDate, //结算日期
  11087. "name": order.PsnName, //姓名
  11088. "gender": patient.Gender, //性别
  11089. "psn_cash_money": order.PsnCashPay, //个人支付
  11090. "pay_way": "门诊", //结算方式
  11091. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11092. "admin_user_name": admin.UserName, //收款员
  11093. "order": order,
  11094. "order_info": orderInfos_two,
  11095. "his": his,
  11096. "bedCostTotal": bedCostTotal,
  11097. "bedCostSelfTotal": bedCostSelfTotal,
  11098. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11099. "operationCostTotal": operationCostTotal,
  11100. "operationCostSelfTotal": operationCostSelfTotal,
  11101. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11102. "otherCostTotal": otherCostTotal,
  11103. "otherCostSelfTotal": otherCostSelfTotal,
  11104. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11105. "materialCostTotal": materialCostTotal,
  11106. "materialCostSelfTotal": materialCostSelfTotal,
  11107. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11108. "westernMedicineCostTotal": westernMedicineCostTotal,
  11109. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11110. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11111. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11112. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11113. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11114. "checkCostTotal": checkCostTotal,
  11115. "checkCostSelfTotal": checkCostSelfTotal,
  11116. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11117. "laboratoryCostTotal": laboratoryCostTotal,
  11118. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11119. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11120. "treatCostTotal": treatCostTotal,
  11121. "treatCostSelfTotal": treatCostSelfTotal,
  11122. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11123. "zhenChaCostTotal": zhenChaCostTotal,
  11124. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11125. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11126. "his_hospital_record": his_hospital_record,
  11127. "pre_pay_money": pre_pay_money,
  11128. "refund_sum": sum,
  11129. "doctor_info": doctor_info,
  11130. "hiliCostTotal": hiliCostTotal,
  11131. "hiliCostSelfTotal": hiliCostSelfTotal,
  11132. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11133. })
  11134. }
  11135. //func (c *HisApiController) GetFaPiaoDatas() {
  11136. // order_ids := c.GetString("order_ids")
  11137. // patient_id, _ := c.GetInt64("patient_id")
  11138. // adminUser := c.GetAdminUserInfo()
  11139. //
  11140. // orders := strings.Split(order_ids, ",")
  11141. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11142. //
  11143. // for _, item := range orders {
  11144. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11145. // order, _ := service.GetHisOrderByID(order_id)
  11146. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11147. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11148. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11149. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11150. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11151. //
  11152. // }
  11153. //
  11154. // var bedCostTotal float64 = 0 //床位总费
  11155. // var bedCostSelfTotal float64 = 0 //床位自费
  11156. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11157. //
  11158. // var operationCostTotal float64 = 0 //手术费
  11159. // var operationCostSelfTotal float64 = 0 //手术费
  11160. // var operationCostPartSelfTotal float64 = 0 //手术费
  11161. //
  11162. // var otherCostTotal float64 = 0 //其他费用
  11163. // var otherCostSelfTotal float64 = 0 //其他费用
  11164. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11165. //
  11166. // var materialCostTotal float64 = 0 //材料费
  11167. // var materialCostSelfTotal float64 = 0 //材料费
  11168. // var materialCostPartSelfTotal float64 = 0 //材料费
  11169. //
  11170. // var westernMedicineCostTotal float64 = 0 //西药费
  11171. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11172. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11173. //
  11174. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11175. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11176. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11177. //
  11178. // var checkCostTotal float64 = 0 //检查费
  11179. // var checkCostSelfTotal float64 = 0 //检查费
  11180. // var checkCostPartSelfTotal float64 = 0 //检查费
  11181. //
  11182. // var laboratoryCostTotal float64 = 0 //化验费
  11183. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11184. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11185. //
  11186. // var treatCostTotal float64 = 0 //治疗费用
  11187. // var treatCostSelfTotal float64 = 0 //治疗费用
  11188. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11189. //
  11190. // var zhenChaCostTotal float64 = 0 //其他费用
  11191. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11192. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11193. //
  11194. // decimal.DivisionPrecision = 2
  11195. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11196. //
  11197. // var balanceAccountsType int64
  11198. // if his.ID > 0 {
  11199. // balanceAccountsType = his.BalanceAccountsType
  11200. // } else {
  11201. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11202. // }
  11203. // if balanceAccountsType == 2 {
  11204. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11205. // for _, item := range orderInfos_two {
  11206. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11207. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11208. // item.MedChrgitmType = "09"
  11209. // }
  11210. //
  11211. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11212. // if item.HisPrescriptionProject.Type == 2 {
  11213. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11214. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11215. // case 0:
  11216. // item.MedChrgitmType = "0"
  11217. // break
  11218. // case 1:
  11219. // item.MedChrgitmType = "14"
  11220. // break
  11221. // case 2:
  11222. // item.MedChrgitmType = "05"
  11223. //
  11224. // break
  11225. // case 3:
  11226. // item.MedChrgitmType = "03"
  11227. //
  11228. // break
  11229. // case 4:
  11230. // item.MedChrgitmType = "03"
  11231. //
  11232. // break
  11233. // case 5:
  11234. // item.MedChrgitmType = "08"
  11235. //
  11236. // break
  11237. // case 6:
  11238. // item.MedChrgitmType = "14"
  11239. //
  11240. // break
  11241. // case 7:
  11242. // item.MedChrgitmType = "14"
  11243. //
  11244. // break
  11245. // case 8:
  11246. // item.MedChrgitmType = "03"
  11247. // break
  11248. // case 9:
  11249. // item.MedChrgitmType = "14"
  11250. // break
  11251. // case 10:
  11252. // item.MedChrgitmType = "14"
  11253. // break
  11254. // case 11:
  11255. // item.MedChrgitmType = "06"
  11256. // break
  11257. // case 12:
  11258. // item.MedChrgitmType = "12"
  11259. // break
  11260. // case 13:
  11261. // item.MedChrgitmType = "01"
  11262. // break
  11263. // case 14:
  11264. // item.MedChrgitmType = "04"
  11265. // break
  11266. // case 15:
  11267. // item.MedChrgitmType = "02"
  11268. // break
  11269. //
  11270. // }
  11271. //
  11272. // } else {
  11273. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11274. //
  11275. // case 1:
  11276. // item.MedChrgitmType = "14"
  11277. // break
  11278. // case 2:
  11279. // item.MedChrgitmType = "05"
  11280. //
  11281. // break
  11282. // case 3:
  11283. // item.MedChrgitmType = "03"
  11284. //
  11285. // break
  11286. // case 4:
  11287. // item.MedChrgitmType = "03"
  11288. //
  11289. // break
  11290. // case 5:
  11291. // item.MedChrgitmType = "08"
  11292. //
  11293. // break
  11294. // case 6:
  11295. // item.MedChrgitmType = "14"
  11296. //
  11297. // break
  11298. // case 7:
  11299. // item.MedChrgitmType = "14"
  11300. //
  11301. // break
  11302. // case 8:
  11303. // item.MedChrgitmType = "03"
  11304. // break
  11305. // case 9:
  11306. // item.MedChrgitmType = "14"
  11307. // break
  11308. //
  11309. // }
  11310. //
  11311. // }
  11312. //
  11313. // } else if item.HisPrescriptionProject.Type == 3 {
  11314. // item.MedChrgitmType = "08"
  11315. // }
  11316. // }
  11317. // }
  11318. //
  11319. // for _, item := range orderInfos_two {
  11320. // fmt.Println(item.MedChrgitmType)
  11321. // if item.MedChrgitmType == "01" { //床位费
  11322. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11323. // bedCostSelfTotal = bedCostTotal
  11324. // }
  11325. //
  11326. // if item.MedChrgitmType == "02" { //诊察费
  11327. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11328. // zhenChaCostSelfTotal = zhenChaCostTotal
  11329. // }
  11330. //
  11331. // if item.MedChrgitmType == "03" { //检查费
  11332. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11333. // checkCostSelfTotal = checkCostTotal
  11334. // }
  11335. //
  11336. // if item.MedChrgitmType == "04" { //化验费
  11337. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11338. // laboratoryCostSelfTotal = laboratoryCostTotal
  11339. // }
  11340. //
  11341. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11342. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11343. // treatCostSelfTotal = treatCostTotal
  11344. // }
  11345. //
  11346. // if item.MedChrgitmType == "06" { //手术费
  11347. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11348. // operationCostSelfTotal = treatCostTotal
  11349. // }
  11350. //
  11351. // if item.MedChrgitmType == "08" { //材料费
  11352. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11353. // materialCostSelfTotal = materialCostTotal
  11354. // }
  11355. //
  11356. // if item.MedChrgitmType == "09" { //西药费
  11357. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11358. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11359. // }
  11360. //
  11361. // if item.MedChrgitmType == "11" { //中成费
  11362. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11363. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11364. // }
  11365. //
  11366. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11367. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11368. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11369. // otherCostSelfTotal = otherCostTotal
  11370. // }
  11371. // } else {
  11372. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11373. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11374. // otherCostSelfTotal = otherCostTotal
  11375. // }
  11376. //
  11377. // }
  11378. //
  11379. // }
  11380. //
  11381. // } else {
  11382. // for _, item := range orderInfos {
  11383. // if item.MedChrgitmType == "01" { //床位费
  11384. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11385. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11386. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11387. // }
  11388. //
  11389. // if item.MedChrgitmType == "02" { //诊察费
  11390. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11391. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11392. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11393. // }
  11394. //
  11395. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11396. // if item.MedChrgitmType == "03" { //检查费
  11397. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11398. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11399. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11400. //
  11401. // }
  11402. // } else {
  11403. // if item.MedChrgitmType == "03" { //检查费
  11404. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11405. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11406. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11407. // }
  11408. //
  11409. // }
  11410. //
  11411. // if item.MedChrgitmType == "04" { //化验费
  11412. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11413. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11414. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11415. //
  11416. // }
  11417. //
  11418. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11419. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11420. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11421. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11422. //
  11423. // }
  11424. //
  11425. // if item.MedChrgitmType == "06" { //手术费
  11426. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11427. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11428. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11429. // }
  11430. //
  11431. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11432. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11433. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11434. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11435. // }
  11436. //
  11437. // if item.MedChrgitmType == "09" { //西药费
  11438. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11439. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11440. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11441. // }
  11442. //
  11443. // if item.MedChrgitmType == "11" { //中成费
  11444. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11445. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11446. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11447. // }
  11448. //
  11449. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11450. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11451. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11452. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11453. // }
  11454. //
  11455. // }
  11456. // }
  11457. // timeLayout := "2006-01-02"
  11458. // loc, _ := time.LoadLocation("Local")
  11459. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11460. // if err != nil {
  11461. // }
  11462. // startRecordDateTime := startTime.Unix()
  11463. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11464. // if err != nil {
  11465. // }
  11466. // endRecordDateTime := endTime.Unix()
  11467. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11468. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11469. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11470. //
  11471. // c.ServeSuccessJSON(map[string]interface{}{
  11472. // "order_number": order.Number, //业务流水号
  11473. // "id_card_no": his.IdCardNo, //社会保障号
  11474. // "department_name": department.Name, //科室
  11475. // "number": his.Number, //门诊号
  11476. // "date": order.SettleAccountsDate, //结算日期
  11477. // "name": order.PsnName, //姓名
  11478. // "gender": patient.Gender, //性别
  11479. // "psn_cash_money": order.PsnCashPay, //个人支付
  11480. // "pay_way": "门诊", //结算方式
  11481. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11482. // "admin_user_name": admin.UserName, //收款员
  11483. // "order": order,
  11484. // "order_info": orderInfos_two,
  11485. // "his": his,
  11486. // "bedCostTotal": bedCostTotal,
  11487. // "bedCostSelfTotal": bedCostSelfTotal,
  11488. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11489. // "operationCostTotal": operationCostTotal,
  11490. // "operationCostSelfTotal": operationCostSelfTotal,
  11491. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11492. // "otherCostTotal": otherCostTotal,
  11493. // "otherCostSelfTotal": otherCostSelfTotal,
  11494. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11495. // "materialCostTotal": materialCostTotal,
  11496. // "materialCostSelfTotal": materialCostSelfTotal,
  11497. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11498. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11499. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11500. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11501. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11502. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11503. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11504. // "checkCostTotal": checkCostTotal,
  11505. // "checkCostSelfTotal": checkCostSelfTotal,
  11506. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11507. // "laboratoryCostTotal": laboratoryCostTotal,
  11508. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11509. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11510. // "treatCostTotal": treatCostTotal,
  11511. // "treatCostSelfTotal": treatCostSelfTotal,
  11512. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11513. // "zhenChaCostTotal": zhenChaCostTotal,
  11514. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11515. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11516. // "his_hospital_record": his_hospital_record,
  11517. // "pre_pay_money": pre_pay_money,
  11518. // "refund_sum": sum,
  11519. // })
  11520. //
  11521. //}
  11522. func (this *HisApiController) GetIncomeStatisticsData() {
  11523. start_time := this.GetString("start_time")
  11524. end_time := this.GetString("end_time")
  11525. key_words := this.GetString("key_words")
  11526. limit, _ := this.GetInt64("limit")
  11527. page, _ := this.GetInt64("page")
  11528. if page <= 0 {
  11529. page = 1
  11530. }
  11531. if limit <= 0 {
  11532. limit = 10
  11533. }
  11534. statistics_type, _ := this.GetInt64("statistics_type")
  11535. admin := this.GetAdminUserInfo()
  11536. timeLayout := "2006-01-02"
  11537. loc, _ := time.LoadLocation("Local")
  11538. var theStartTIme int64
  11539. if len(start_time) > 0 {
  11540. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11541. if err != nil {
  11542. theStartTIme = 0
  11543. }
  11544. theStartTIme = theTime.Unix()
  11545. }
  11546. var theEndtTIme int64
  11547. if len(end_time) > 0 {
  11548. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11549. if err != nil {
  11550. theEndtTIme = 0
  11551. }
  11552. theEndtTIme = theTime.Unix()
  11553. }
  11554. if statistics_type == 1 {
  11555. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11556. this.ServeSuccessJSON(map[string]interface{}{
  11557. "list": list,
  11558. "total": total,
  11559. })
  11560. } else {
  11561. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11562. this.ServeSuccessJSON(map[string]interface{}{
  11563. "list": list,
  11564. "total": total,
  11565. })
  11566. }
  11567. }
  11568. func (c *HisApiController) PostProjectInformation() {
  11569. adminUser := c.GetAdminUserInfo()
  11570. orgId := adminUser.CurrentOrgId
  11571. dataBody := make(map[string]interface{}, 0)
  11572. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11573. if err != nil {
  11574. utils.ErrorLog(err.Error())
  11575. return
  11576. }
  11577. utils.ErrorLog("%v", dataBody)
  11578. var projectList []*models.HisProject
  11579. var total_goods []interface{}
  11580. tempProjects := dataBody["projects"].([]interface{})
  11581. total_goods = tempProjects
  11582. for index, projectMap := range tempProjects {
  11583. projectM := projectMap.(map[string]interface{})
  11584. var project models.HisProject
  11585. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11586. utils.ErrorLog("project_name")
  11587. return
  11588. }
  11589. project_name, _ := projectM["project_name"].(string)
  11590. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11591. err_log := models.ExportErrLog{
  11592. LogType: 6,
  11593. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11594. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11595. Status: 1,
  11596. CreateTime: time.Now().Unix(),
  11597. UpdateTime: time.Now().Unix(),
  11598. ExportTime: time.Now().Unix(),
  11599. }
  11600. service.CreateExportErrLog(&err_log)
  11601. continue
  11602. }
  11603. project.ProjectName = project_name
  11604. prices := projectM["price"].(string)
  11605. price, _ := strconv.ParseFloat(prices, 64)
  11606. if price <= 0 { //名字为空则生成一条导入错误日志
  11607. err_log := models.ExportErrLog{
  11608. LogType: 6,
  11609. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11610. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11611. Status: 1,
  11612. CreateTime: time.Now().Unix(),
  11613. UpdateTime: time.Now().Unix(),
  11614. ExportTime: time.Now().Unix(),
  11615. }
  11616. service.CreateExportErrLog(&err_log)
  11617. continue
  11618. }
  11619. project.Price = price
  11620. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11621. utils.ErrorLog("unit_id")
  11622. return
  11623. }
  11624. unit := projectM["unit"].(string)
  11625. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11626. err_log := models.ExportErrLog{
  11627. LogType: 6,
  11628. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11629. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11630. Status: 1,
  11631. CreateTime: time.Now().Unix(),
  11632. UpdateTime: time.Now().Unix(),
  11633. ExportTime: time.Now().Unix(),
  11634. }
  11635. service.CreateExportErrLog(&err_log)
  11636. continue
  11637. }
  11638. project.Unit = unit
  11639. cost_classify := projectM["cost_classify"].(string)
  11640. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11641. err_log := models.ExportErrLog{
  11642. LogType: 6,
  11643. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11644. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11645. Status: 1,
  11646. CreateTime: time.Now().Unix(),
  11647. UpdateTime: time.Now().Unix(),
  11648. ExportTime: time.Now().Unix(),
  11649. }
  11650. service.CreateExportErrLog(&err_log)
  11651. continue
  11652. }
  11653. var costClassify = "费用类别"
  11654. var cost_classify_id int64
  11655. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11656. if len(cost_classify) != 0 {
  11657. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11658. if errcode == gorm.ErrRecordNotFound {
  11659. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11660. dataconfig := models.DictDataconfig{
  11661. ParentId: costClassifyConfig.ID,
  11662. Module: "system",
  11663. OrgId: orgId,
  11664. Name: cost_classify,
  11665. FieldName: "",
  11666. Value: costConfig.Value + 1,
  11667. CreatedTime: "",
  11668. UpdatedTime: "",
  11669. CreateUserId: adminUser.AdminUser.Id,
  11670. Status: 1,
  11671. Remark: "",
  11672. DeleteIdSystem: 0,
  11673. Title: "",
  11674. Content: "",
  11675. Order: 0,
  11676. Code: "",
  11677. }
  11678. service.CreatedDicConfig(&dataconfig)
  11679. }
  11680. }
  11681. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11682. for _, it := range costClassList {
  11683. if cost_classify == it.Name {
  11684. cost_classify_id = int64(it.Value)
  11685. }
  11686. }
  11687. project.CostClassify = cost_classify_id
  11688. executive_section := projectM["executive_section"].(string)
  11689. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11690. err_log := models.ExportErrLog{
  11691. LogType: 6,
  11692. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11693. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11694. Status: 1,
  11695. CreateTime: time.Now().Unix(),
  11696. UpdateTime: time.Now().Unix(),
  11697. ExportTime: time.Now().Unix(),
  11698. }
  11699. service.CreateExportErrLog(&err_log)
  11700. continue
  11701. }
  11702. if len(executive_section) != 0 {
  11703. //查找科室是否有内容
  11704. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11705. if errcodedepart == gorm.ErrRecordNotFound {
  11706. department := models.XtHisDepartment{
  11707. Name: executive_section,
  11708. Status: 1,
  11709. UserOrgId: adminUser.CurrentOrgId,
  11710. CreatedTime: time.Now().Unix(),
  11711. }
  11712. service.CreateDePartment(&department)
  11713. }
  11714. }
  11715. var executive_section_id int64
  11716. departMentList, _ := service.GetAllDepartMent(orgId)
  11717. for _, it := range departMentList {
  11718. if executive_section == it.Name {
  11719. executive_section_id = it.ID
  11720. }
  11721. }
  11722. project.ExecutiveSection = executive_section_id
  11723. medical_coverage := projectM["medical_coverage"].(string)
  11724. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11725. err_log := models.ExportErrLog{
  11726. LogType: 6,
  11727. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11728. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11729. Status: 1,
  11730. CreateTime: time.Now().Unix(),
  11731. UpdateTime: time.Now().Unix(),
  11732. ExportTime: time.Now().Unix(),
  11733. }
  11734. service.CreateExportErrLog(&err_log)
  11735. continue
  11736. }
  11737. var medicalCoverage = "医保等级"
  11738. var medical_coverage_id int64
  11739. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11740. if len(medical_coverage) != 0 {
  11741. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11742. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11743. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11744. dataconfig := models.DictDataconfig{
  11745. ParentId: medicalCoverageConfig.ID,
  11746. Module: "system",
  11747. OrgId: orgId,
  11748. Name: medical_coverage,
  11749. FieldName: "",
  11750. Value: medicalCoverageConfig.Value + 1,
  11751. CreatedTime: "",
  11752. UpdatedTime: "",
  11753. CreateUserId: adminUser.AdminUser.Id,
  11754. Status: 1,
  11755. Remark: "",
  11756. DeleteIdSystem: 0,
  11757. Title: "",
  11758. Content: "",
  11759. Order: 0,
  11760. Code: "",
  11761. }
  11762. service.CreatedDicConfig(&dataconfig)
  11763. }
  11764. }
  11765. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11766. for _, it := range medicalCoverageList {
  11767. if medical_coverage == it.Name {
  11768. medical_coverage_id = int64(it.Value)
  11769. }
  11770. }
  11771. project.MedicalCoverage = medical_coverage_id
  11772. pinyin := projectM["pinyin"].(string)
  11773. project.Pinyin = pinyin
  11774. wubi := projectM["wubi"].(string)
  11775. project.Wubi = wubi
  11776. statistical_classification := projectM["statistical_classification"].(string)
  11777. var statisticalClassification = "统计分类"
  11778. var statistical_classification_id int64
  11779. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11780. if len(statistical_classification) != 0 {
  11781. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11782. if classificationerrcodes == gorm.ErrRecordNotFound {
  11783. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11784. dataconfig := models.DictDataconfig{
  11785. ParentId: classiFication.ID,
  11786. Module: "system",
  11787. OrgId: orgId,
  11788. Name: statistical_classification,
  11789. FieldName: "",
  11790. Value: classiFicationConfig.Value + 1,
  11791. CreatedTime: "",
  11792. UpdatedTime: "",
  11793. CreateUserId: adminUser.AdminUser.Id,
  11794. Status: 1,
  11795. Remark: "",
  11796. DeleteIdSystem: 0,
  11797. Title: "",
  11798. Content: "",
  11799. Order: 0,
  11800. Code: "",
  11801. }
  11802. service.CreatedDicConfig(&dataconfig)
  11803. }
  11804. }
  11805. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11806. for _, it := range classiFicationList {
  11807. if statistical_classification == it.Name {
  11808. statistical_classification_id = int64(it.Value)
  11809. }
  11810. }
  11811. project.StatisticalClassification = statistical_classification_id
  11812. disease_directory := int64(projectM["disease_directory"].(float64))
  11813. project.DiseaseDirectory = disease_directory
  11814. is_record := int64(projectM["is_record"].(float64))
  11815. project.IsRecord = is_record
  11816. medical_code := projectM["medical_code"].(string)
  11817. project.MedicalCode = medical_code
  11818. tube_color := projectM["tube_color"].(string)
  11819. var tubeColor = "试管颜色"
  11820. var tube_color_id int64
  11821. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11822. if len(tube_color) != 0 {
  11823. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11824. if errcodetube == gorm.ErrRecordNotFound {
  11825. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11826. dataconfig := models.DictDataconfig{
  11827. ParentId: tubeColorConfig.ID,
  11828. Module: "system",
  11829. OrgId: orgId,
  11830. Name: tube_color,
  11831. FieldName: "",
  11832. Value: tubeConfig.Value + 1,
  11833. CreatedTime: "",
  11834. UpdatedTime: "",
  11835. CreateUserId: adminUser.AdminUser.Id,
  11836. Status: 1,
  11837. Remark: "",
  11838. DeleteIdSystem: 0,
  11839. Title: "",
  11840. Content: "",
  11841. Order: 0,
  11842. Code: "",
  11843. }
  11844. service.CreatedDicConfig(&dataconfig)
  11845. }
  11846. }
  11847. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11848. for _, it := range tubeColorList {
  11849. if tube_color == it.Name {
  11850. tube_color_id = int64(it.Value)
  11851. }
  11852. }
  11853. project.TubeColor = tube_color_id
  11854. single_dose := projectM["single_dose"].(string)
  11855. project.SingleDose = single_dose
  11856. execution_frequency := projectM["execution_frequency"].(string)
  11857. project.ExecutionFrequency = execution_frequency
  11858. delivery_way := projectM["delivery_way"].(string)
  11859. project.DeliveryWay = delivery_way
  11860. number_days := projectM["number_days"].(string)
  11861. project.NumberDays = number_days
  11862. total := projectM["total"].(string)
  11863. project.Total = total
  11864. medical_status := int64(projectM["medical_status"].(float64))
  11865. project.MedicalStatus = medical_status
  11866. category := int64(projectM["category"].(float64))
  11867. project.Category = category
  11868. specail_project := int64(projectM["specail_project"].(float64))
  11869. project.SpecailProject = specail_project
  11870. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11871. project.SocialSecurityDirectoryCode = social_security_directory_code
  11872. remark := projectM["remark"].(string)
  11873. project.Remark = remark
  11874. record_date := projectM["record_date"].(string)
  11875. timeLayout := "2006-01-02"
  11876. loc, _ := time.LoadLocation("Local")
  11877. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11878. project.RecordDate = theTime.Unix()
  11879. projectList = append(projectList, &project)
  11880. }
  11881. export_time := time.Now().Unix()
  11882. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11883. if len(projectList) > 0 {
  11884. for _, item := range projectList {
  11885. hans := item.ProjectName // 要转换的汉字字符串
  11886. // 创建一个拼音转换器
  11887. p := pinyin.NewArgs()
  11888. // 将汉字转为拼音
  11889. pinyinSlice := pinyin.Pinyin(hans, p)
  11890. // 输出拼音
  11891. fmt.Println("Pinyin:", pinyinSlice)
  11892. // 获取首字母
  11893. firstLetter := ""
  11894. for _, py := range pinyinSlice {
  11895. if len(py) > 0 {
  11896. firstLetter += string(py[0][0])
  11897. }
  11898. }
  11899. item.FirstLetter = firstLetter
  11900. project := models.HisProject{
  11901. ProjectName: item.ProjectName,
  11902. Price: item.Price,
  11903. Unit: item.Unit,
  11904. CostClassify: item.CostClassify,
  11905. ExecutiveSection: item.ExecutiveSection,
  11906. MedicalCoverage: item.MedicalCoverage,
  11907. UserOrgId: orgId,
  11908. Status: 1,
  11909. CreatedTime: time.Now().Unix(),
  11910. Pinyin: item.Pinyin,
  11911. Wubi: item.Wubi,
  11912. StatisticalClassification: item.StatisticalClassification,
  11913. DiseaseDirectory: item.DiseaseDirectory,
  11914. IsRecord: item.IsRecord,
  11915. MedicalCode: item.MedicalCode,
  11916. TubeColor: item.TubeColor,
  11917. SingleDose: item.SingleDose,
  11918. DeliveryWay: item.DeliveryWay,
  11919. NumberDays: item.NumberDays,
  11920. Total: item.Total,
  11921. Category: item.Category,
  11922. MedicalStatus: item.MedicalStatus,
  11923. SpecailProject: item.SpecailProject,
  11924. RecordDate: item.RecordDate,
  11925. Remark: item.Remark,
  11926. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11927. ExecutionFrequency: item.ExecutionFrequency,
  11928. FirstLetter: item.FirstLetter,
  11929. }
  11930. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11931. if errcodeproject == gorm.ErrRecordNotFound {
  11932. service.CreateProjectInfomation(&project)
  11933. } else if errcodeproject == nil {
  11934. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11935. }
  11936. log := models.ExportLog{
  11937. LogType: 6,
  11938. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11939. TotalNum: int64(len(total_goods)),
  11940. FailNum: int64(len(errLogs)),
  11941. SuccessNum: int64(len(projectList)),
  11942. CreateTime: time.Now().Unix(),
  11943. UpdateTime: time.Now().Unix(),
  11944. ExportTime: export_time,
  11945. Status: 1,
  11946. }
  11947. service.CreateExportLog(&log)
  11948. c.ServeSuccessJSON(map[string]interface{}{
  11949. "msg": "导入成功",
  11950. "total_num": len(total_goods),
  11951. "success_num": len(projectList),
  11952. "fail_num": int64(len(errLogs)),
  11953. })
  11954. }
  11955. } else {
  11956. log := models.ExportLog{
  11957. LogType: 6,
  11958. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11959. TotalNum: int64(len(total_goods)),
  11960. FailNum: int64(len(errLogs)),
  11961. SuccessNum: int64(len(projectList)),
  11962. CreateTime: time.Now().Unix(),
  11963. UpdateTime: time.Now().Unix(),
  11964. ExportTime: export_time,
  11965. Status: 1,
  11966. }
  11967. service.CreateExportLog(&log)
  11968. c.ServeSuccessJSON(map[string]interface{}{
  11969. "msg": "导入成功",
  11970. "total_num": len(total_goods),
  11971. "success_num": len(projectList),
  11972. "fail_num": int64(len(errLogs)),
  11973. })
  11974. }
  11975. }
  11976. //func (this *HisApiController) EditProjectInformation(){
  11977. //
  11978. // id, _ := this.GetInt64("id")
  11979. // project_team := this.GetString("project_team")
  11980. // price := this.GetString("price")
  11981. // price_float, _ := strconv.ParseFloat(price, 64)
  11982. // pinyin := this.GetString("pinyin")
  11983. // wubi := this.GetString("wubi")
  11984. // tube_color, _ := this.GetInt64("tube_color")
  11985. // team_type, _ := this.GetInt64("team_type")
  11986. // remark := this.GetString("remark")
  11987. // ids := this.GetString("ids")
  11988. // item_id := this.GetString("item_id")
  11989. // projectTeam := models.XtHisProjectTeam{
  11990. // ProjectTeam: project_team,
  11991. // Price: price_float,
  11992. // Pinyin: pinyin,
  11993. // Wubi: wubi,
  11994. // TubeColor: tube_color,
  11995. // TeamType: team_type,
  11996. // Remark: remark,
  11997. // ProjectId: ids,
  11998. // ItemId: item_id,
  11999. // }
  12000. //
  12001. //
  12002. // dataBody := make(map[string]interface{}, 0)
  12003. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12004. // if err != nil {
  12005. // utils.ErrorLog(err.Error())
  12006. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12007. // return
  12008. // }
  12009. //
  12010. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12011. //
  12012. //
  12013. // if err != nil {
  12014. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12015. // return
  12016. // }
  12017. //
  12018. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12019. // infos, _ := dataBody["info"].([]interface{})
  12020. // if len(infos) > 0 {
  12021. // var ids []string
  12022. //
  12023. // for _, item := range infos {
  12024. // items := item.(map[string]interface{})
  12025. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12026. // utils.ErrorLog("id")
  12027. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12028. // return
  12029. // }
  12030. // id := int64(items["id"].(float64))
  12031. //
  12032. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12033. // utils.ErrorLog("type")
  12034. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12035. // return
  12036. // }
  12037. // types := int64(items["type"].(float64))
  12038. //
  12039. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12040. // utils.ErrorLog("number")
  12041. // }
  12042. //
  12043. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12044. //
  12045. // projectList := models.XtHisProjectList{
  12046. // Number: number,
  12047. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12048. // ProjectId: id,
  12049. // Status: 1,
  12050. // CreatedTime: time.Now().Unix(),
  12051. // UpdatedTime: time.Now().Unix(),
  12052. // TeamId: projectTeam.ID,
  12053. // Type: types,
  12054. // }
  12055. // list := projectList
  12056. //
  12057. // service.CreateProjectList(&list)
  12058. //
  12059. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12060. //
  12061. // }
  12062. // ids_str := strings.Join(ids, ",")
  12063. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12064. // service.SaveProjectTeam(&projectTeam)
  12065. // this.ServeSuccessJSON(map[string]interface{}{
  12066. // "projectTeam": projectTeam,
  12067. // })
  12068. // }
  12069. // }
  12070. //}
  12071. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12072. name := c.GetString("name")
  12073. mode_id, _ := c.GetInt64("mode", 0)
  12074. types, _ := c.GetInt64("type", 0)
  12075. patient_id, _ := c.GetInt64("patient_id", 0)
  12076. types = 1
  12077. adminInfo := c.GetAdminUserInfo()
  12078. template := &models.HisPrescriptionTemplate{
  12079. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12080. PatientId: patient_id,
  12081. Type: types,
  12082. Status: 1,
  12083. Ctime: time.Now().Unix(),
  12084. Mtime: time.Now().Unix(),
  12085. Name: name,
  12086. Mode: mode_id,
  12087. }
  12088. dataBody := make(map[string]interface{}, 0)
  12089. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12090. if err != nil {
  12091. utils.ErrorLog(err.Error())
  12092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12093. return
  12094. }
  12095. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12096. //如果已经存在记录则删除处方
  12097. if template_one.ID > 0 {
  12098. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12099. var ids []int64
  12100. var org_id int64
  12101. for _, item := range ps {
  12102. org_id = c.GetAdminUserInfo().CurrentOrgId
  12103. ids = append(ids, item.ID)
  12104. }
  12105. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12106. if err2 == nil {
  12107. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12108. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12109. if len(prescriptions) > 0 {
  12110. for _, item := range prescriptions {
  12111. items := item.(map[string]interface{})
  12112. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12113. utils.ErrorLog("type")
  12114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12115. return
  12116. }
  12117. types := int64(items["type"].(float64))
  12118. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12119. utils.ErrorLog("med_type")
  12120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12121. return
  12122. }
  12123. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12124. ctime := time.Now().Unix()
  12125. prescription := &models.HisPrescriptionInfoTemplate{
  12126. PatientId: patient_id,
  12127. UserOrgId: adminInfo.CurrentOrgId,
  12128. Ctime: ctime,
  12129. Mtime: ctime,
  12130. Type: types,
  12131. Modifier: adminInfo.AdminUser.Id,
  12132. Creator: adminInfo.AdminUser.Id,
  12133. Status: 1,
  12134. PTemplateId: template_one.ID,
  12135. MedType: med_type,
  12136. }
  12137. service.CreateHisPrescriptionInfoTemplate(prescription)
  12138. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12139. advices := items["advices"].([]interface{})
  12140. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12141. ctime := time.Now().Unix()
  12142. mtime := ctime
  12143. if len(advices) > 0 {
  12144. for _, advice := range advices {
  12145. var s models.HisPrescriptionAdviceTemplate
  12146. s.PrescriptionId = prescription.ID
  12147. s.AdviceType = 2
  12148. s.StopState = 2
  12149. s.ExecutionState = 2
  12150. s.Status = 1
  12151. s.UserOrgId = adminInfo.CurrentOrgId
  12152. s.CreatedTime = ctime
  12153. s.UpdatedTime = mtime
  12154. s.PatientId = patient_id
  12155. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12156. if errcode > 0 {
  12157. c.ServeFailJSONWithSGJErrorCode(errcode)
  12158. return
  12159. }
  12160. service.CreateHisPrescriptionAdviceTemplate(&s)
  12161. }
  12162. }
  12163. }
  12164. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12165. projects := items["project"].([]interface{})
  12166. if len(projects) > 0 {
  12167. for _, project := range projects {
  12168. var p models.HisPrescriptionProjectTemplate
  12169. p.PrescriptionId = prescription.ID
  12170. p.Ctime = time.Now().Unix()
  12171. p.Mtime = time.Now().Unix()
  12172. p.PatientId = patient_id
  12173. p.UserOrgId = adminInfo.CurrentOrgId
  12174. p.Status = 1
  12175. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12176. if errcode > 0 {
  12177. c.ServeFailJSONWithSGJErrorCode(errcode)
  12178. return
  12179. }
  12180. service.CreateHisPrescriptionProjectTemplate(&p)
  12181. }
  12182. }
  12183. }
  12184. }
  12185. c.ServeSuccessJSON(map[string]interface{}{
  12186. "msg": "创建成功",
  12187. })
  12188. }
  12189. }
  12190. } else {
  12191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12192. return
  12193. }
  12194. } else {
  12195. err3 := service.CreateHisPrescriptionTemplate(template)
  12196. if err3 == nil {
  12197. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12198. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12199. if len(prescriptions) > 0 {
  12200. for _, item := range prescriptions {
  12201. items := item.(map[string]interface{})
  12202. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12203. utils.ErrorLog("type")
  12204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12205. return
  12206. }
  12207. types := int64(items["type"].(float64))
  12208. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12209. utils.ErrorLog("med_type")
  12210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12211. return
  12212. }
  12213. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12214. ctime := time.Now().Unix()
  12215. prescription := &models.HisPrescriptionInfoTemplate{
  12216. PatientId: patient_id,
  12217. UserOrgId: adminInfo.CurrentOrgId,
  12218. Ctime: ctime,
  12219. Mtime: ctime,
  12220. Type: types,
  12221. Modifier: adminInfo.AdminUser.Id,
  12222. Creator: adminInfo.AdminUser.Id,
  12223. Status: 1,
  12224. PTemplateId: template.ID,
  12225. MedType: med_type,
  12226. }
  12227. service.CreateHisPrescriptionInfoTemplate(prescription)
  12228. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12229. advices := items["advices"].([]interface{})
  12230. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12231. ctime := time.Now().Unix()
  12232. mtime := ctime
  12233. if len(advices) > 0 {
  12234. for _, advice := range advices {
  12235. var s models.HisPrescriptionAdviceTemplate
  12236. s.PrescriptionId = prescription.ID
  12237. s.AdviceType = 2
  12238. s.StopState = 2
  12239. s.ExecutionState = 2
  12240. s.Status = 1
  12241. s.UserOrgId = adminInfo.CurrentOrgId
  12242. s.CreatedTime = ctime
  12243. s.UpdatedTime = mtime
  12244. s.PatientId = patient_id
  12245. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12246. if errcode > 0 {
  12247. c.ServeFailJSONWithSGJErrorCode(errcode)
  12248. return
  12249. }
  12250. service.CreateHisPrescriptionAdviceTemplate(&s)
  12251. }
  12252. }
  12253. }
  12254. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12255. projects := items["project"].([]interface{})
  12256. if len(projects) > 0 {
  12257. for _, project := range projects {
  12258. var p models.HisPrescriptionProjectTemplate
  12259. p.PrescriptionId = prescription.ID
  12260. p.Ctime = time.Now().Unix()
  12261. p.Mtime = time.Now().Unix()
  12262. p.PatientId = patient_id
  12263. p.UserOrgId = adminInfo.CurrentOrgId
  12264. p.Status = 1
  12265. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12266. if errcode > 0 {
  12267. c.ServeFailJSONWithSGJErrorCode(errcode)
  12268. return
  12269. }
  12270. service.CreateHisPrescriptionProjectTemplate(&p)
  12271. }
  12272. }
  12273. }
  12274. }
  12275. c.ServeSuccessJSON(map[string]interface{}{
  12276. "msg": "创建成功",
  12277. })
  12278. }
  12279. }
  12280. } else {
  12281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12282. return
  12283. }
  12284. }
  12285. }
  12286. func (c *HisApiController) PreSettle() {
  12287. id, _ := c.GetInt64("id")
  12288. record_time := c.GetString("record_time")
  12289. his_patient_id, _ := c.GetInt64("his_patient_id")
  12290. timeLayout := "2006-01-02"
  12291. loc, _ := time.LoadLocation("Local")
  12292. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12293. diagnosis_id := c.GetString("diagnosis")
  12294. sick_type, _ := c.GetInt64("sick_type")
  12295. reg_type, _ := c.GetInt64("p_type")
  12296. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12297. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12298. if err != nil {
  12299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12300. return
  12301. }
  12302. recordDateTime := theTime.Unix()
  12303. adminUser := c.GetAdminUserInfo()
  12304. var prescriptions []*models.HisPrescription
  12305. var start_time int64
  12306. var end_time int64
  12307. ids_str := c.GetString("ids")
  12308. ids_arr := strings.Split(ids_str, ",")
  12309. fmt.Println(reg_type)
  12310. if settle_accounts_type == 1 { //日结
  12311. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12312. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12313. } else {
  12314. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12315. }
  12316. fmt.Println(prescriptions)
  12317. } else { //月结
  12318. start_time_str := c.GetString("start_time")
  12319. end_time_str := c.GetString("end_time")
  12320. timeLayout := "2006-01-02"
  12321. loc, _ := time.LoadLocation("Local")
  12322. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12323. if err != nil {
  12324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12325. return
  12326. }
  12327. recordStartTime := theStartTime.Unix()
  12328. start_time = recordStartTime
  12329. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12330. if err != nil {
  12331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12332. return
  12333. }
  12334. recordEndTime := theEndTime.Unix()
  12335. end_time = recordEndTime
  12336. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12337. }
  12338. if reg_type == 1111 || reg_type == 1112 {
  12339. reg_type = 11
  12340. }
  12341. timestamp := time.Now().Unix()
  12342. tempTime := time.Unix(timestamp, 0)
  12343. timeFormat := tempTime.Format("20060102150405")
  12344. chrgBchno := rand.Intn(100000) + 10000
  12345. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12346. strconv.FormatInt(his.PatientId, 10)
  12347. var ids []int64
  12348. for _, item := range prescriptions {
  12349. ids = append(ids, item.ID)
  12350. }
  12351. fmt.Println(ids)
  12352. var total float64
  12353. for _, item := range prescriptions {
  12354. fmt.Println(item)
  12355. if item.Type == 1 { //药品
  12356. for _, subItem := range item.HisDoctorAdviceInfo {
  12357. total = total + (subItem.Price * subItem.PrescribingNumber)
  12358. }
  12359. }
  12360. if item.Type == 2 { //项目
  12361. for _, subItem := range item.HisPrescriptionProject {
  12362. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12363. total = total + (subItem.Price * cnt)
  12364. }
  12365. }
  12366. for _, subItem := range item.HisAdditionalCharge {
  12367. total = total + (subItem.Price * float64(subItem.Count))
  12368. }
  12369. }
  12370. allTotal := fmt.Sprintf("%.2f", total)
  12371. totals, _ := strconv.ParseFloat(allTotal, 64)
  12372. order := &models.HisOrder{
  12373. UserOrgId: adminUser.CurrentOrgId,
  12374. HisPatientId: his.ID,
  12375. PatientId: id,
  12376. SettleAccountsDate: recordDateTime,
  12377. Ctime: time.Now().Unix(),
  12378. Mtime: time.Now().Unix(),
  12379. Status: 1,
  12380. OrderStatus: 1,
  12381. MdtrtId: his.Number,
  12382. Number: chrg_bchno,
  12383. MedfeeSumamt: totals,
  12384. SettleEndTime: end_time,
  12385. SettleStartTime: start_time,
  12386. SettleType: settle_accounts_type,
  12387. PsnPartAmt: totals,
  12388. PsnCashPay: totals,
  12389. PType: 2,
  12390. IsPre: 1,
  12391. MedType: strconv.Itoa(int(reg_type)),
  12392. Diagnosis: diagnosis_id,
  12393. }
  12394. err = service.CreateOrder(order)
  12395. if err != nil {
  12396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12397. return
  12398. }
  12399. var customs []*Custom
  12400. for _, item := range prescriptions {
  12401. fmt.Println(item.Type)
  12402. if item.Type == 1 { //药品
  12403. for _, subItem := range item.HisDoctorAdviceInfo {
  12404. cus := &Custom{
  12405. AdviceId: subItem.ID,
  12406. ProjectId: 0,
  12407. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12408. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12409. FeedetlSn: subItem.FeedetlSn,
  12410. Price: fmt.Sprintf("%.2f", subItem.Price),
  12411. MedListCodg: subItem.MedListCodg,
  12412. Type: 1,
  12413. }
  12414. customs = append(customs, cus)
  12415. }
  12416. }
  12417. if item.Type == 2 { //项目
  12418. for _, subItem := range item.HisPrescriptionProject {
  12419. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12420. cus := &Custom{
  12421. AdviceId: 0,
  12422. ProjectId: subItem.ID,
  12423. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12424. Cut: fmt.Sprintf("%.2f", cnt),
  12425. FeedetlSn: subItem.FeedetlSn,
  12426. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12427. MedListCodg: subItem.MedListCodg,
  12428. Type: 2,
  12429. }
  12430. customs = append(customs, cus)
  12431. }
  12432. }
  12433. for _, item := range item.HisAdditionalCharge {
  12434. cus := &Custom{
  12435. ItemId: item.ID,
  12436. AdviceId: 0,
  12437. ProjectId: 0,
  12438. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12439. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12440. FeedetlSn: item.FeedetlSn,
  12441. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12442. MedListCodg: item.XtHisAddtionConfig.Code,
  12443. Type: 3,
  12444. }
  12445. customs = append(customs, cus)
  12446. }
  12447. }
  12448. fmt.Println(customs)
  12449. for _, item := range customs {
  12450. var advice_id int64 = 0
  12451. var project_id int64 = 0
  12452. var item_id int64 = 0
  12453. var types int64 = 0
  12454. if item.Type == 1 {
  12455. advice_id = item.AdviceId
  12456. project_id = 0
  12457. item_id = 0
  12458. } else if item.Type == 2 {
  12459. advice_id = 0
  12460. item_id = 0
  12461. project_id = item.ProjectId
  12462. } else if item.Type == 3 {
  12463. advice_id = 0
  12464. item_id = item.ItemId
  12465. project_id = 0
  12466. }
  12467. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12468. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12469. pric, _ := strconv.ParseFloat(item.Price, 32)
  12470. info := &models.HisOrderInfo{
  12471. OrderNumber: order.Number,
  12472. UploadDate: time.Now().Unix(),
  12473. AdviceId: advice_id,
  12474. DetItemFeeSumamt: detItemFeeSumamt,
  12475. Cnt: cut,
  12476. Pric: pric,
  12477. PatientId: id,
  12478. Status: 1,
  12479. Mtime: time.Now().Unix(),
  12480. Ctime: time.Now().Unix(),
  12481. UserOrgId: adminUser.CurrentOrgId,
  12482. HisPatientId: his.ID,
  12483. OrderId: order.ID,
  12484. ProjectId: project_id,
  12485. Type: types,
  12486. ItemId: item_id,
  12487. }
  12488. service.CreateOrderInfo(info)
  12489. }
  12490. his.SickType = sick_type
  12491. service.UpdataHisPateint(&his)
  12492. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12493. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12494. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12495. if err == nil {
  12496. c.ServeSuccessJSON(map[string]interface{}{
  12497. "msg": "结算成功",
  12498. })
  12499. }
  12500. }
  12501. type CustomOrderInfo struct {
  12502. Name string
  12503. Spec string
  12504. Unit string
  12505. Count float64
  12506. Price float64
  12507. Total float64
  12508. }
  12509. func (c *HisApiController) GetPrivateExpensesInfo() {
  12510. order_id, _ := c.GetInt64("id", 0)
  12511. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12512. order, _ := service.GetHisOrderByID(order_id)
  12513. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12514. if order.ID == 0 {
  12515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12516. return
  12517. }
  12518. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12519. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12520. org_id := c.GetAdminUserInfo().CurrentOrgId
  12521. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12522. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12523. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12524. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12525. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12526. //var orderInfos_four []*models.HisOrderInfoTwo
  12527. //for _, item := range orderInfos_three {
  12528. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12529. // item.HisPrescriptionProject.IsCheckTeam = 1
  12530. // orderInfos_four = append(orderInfos_four, item)
  12531. //
  12532. // }
  12533. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12534. // item.HisPrescriptionProject.IsCheckTeam = 2
  12535. // orderInfos_two = append(orderInfos_two, item)
  12536. // }
  12537. //}
  12538. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12539. //var cus_slice []CustomOrderInfo
  12540. //for _, item := range new_order_info {
  12541. // var cus CustomOrderInfo
  12542. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12543. // cus.Unit = ""
  12544. // cus.Spec = ""
  12545. // var total float64
  12546. // for _, subItem := range orderInfos_four {
  12547. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12548. // total = total + subItem.DetItemFeeSumamt
  12549. // fmt.Println(subItem.DetItemFeeSumamt)
  12550. // }
  12551. // }
  12552. // cus.Count = 1
  12553. // cus.Total = total
  12554. // cus_slice = append(cus_slice, cus)
  12555. //}
  12556. orderInfos = append(orderInfos, orderInfos_two...)
  12557. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12558. //orderInfos = append(orderInfos, orderInfos_three...)
  12559. //}/**/
  12560. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12561. c.ServeSuccessJSON(map[string]interface{}{
  12562. "order": order,
  12563. "order_info": orderInfos,
  12564. "patient": patient,
  12565. "admin_info": adminInfo,
  12566. "his": his,
  12567. "current_admin": role,
  12568. "org_config": miConfig,
  12569. //"new_order_info": cus_slice,
  12570. })
  12571. }
  12572. func (this *HisApiController) ChangeMedType() {
  12573. med_type := this.GetString("med_type")
  12574. old_med_type := this.GetString("old_med_type")
  12575. ids := this.GetString("ids")
  12576. settle_type, _ := this.GetInt64("settle_type")
  12577. start_time := this.GetString("start_time")
  12578. end_time := this.GetString("end_time")
  12579. ids_arr := strings.Split(ids, ",")
  12580. if settle_type == 1 { //日结
  12581. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12582. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12583. prescription.MedType = med_type
  12584. err := service.SaveHisPrescriptionTwo(&prescription)
  12585. if err == nil {
  12586. this.ServeSuccessJSON(map[string]interface{}{
  12587. "msg": "修改成功",
  12588. })
  12589. } else {
  12590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12591. return
  12592. }
  12593. } else if settle_type == 2 {
  12594. timeLayout := "2006-01-02"
  12595. loc, _ := time.LoadLocation("Local")
  12596. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12597. if err != nil {
  12598. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12599. return
  12600. }
  12601. recordStartTime := theStartTime.Unix()
  12602. start_time_timestamp := recordStartTime
  12603. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12604. if err != nil {
  12605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12606. return
  12607. }
  12608. recordEndTime := theEndTime.Unix()
  12609. end_time_timestamp := recordEndTime
  12610. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12611. if updateErr == nil {
  12612. this.ServeSuccessJSON(map[string]interface{}{
  12613. "msg": "修改成功",
  12614. })
  12615. } else {
  12616. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12617. return
  12618. }
  12619. }
  12620. }
  12621. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12622. patient_id, _ := c.GetInt64("patient_id")
  12623. his_patient_id, _ := c.GetInt64("his_patient_id")
  12624. record_date := c.GetString("record_date")
  12625. start_time := c.GetString("start_time")
  12626. end_time := c.GetString("end_time")
  12627. order_status, _ := c.GetInt64("type", 0)
  12628. p_type, _ := c.GetInt64("p_type", 0)
  12629. order_id, _ := c.GetInt64("order_id", 0)
  12630. timeLayout := "2006-01-02"
  12631. loc, _ := time.LoadLocation("Local")
  12632. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12633. if err != nil {
  12634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12635. return
  12636. }
  12637. recordDateTime := theTime.Unix()
  12638. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12639. if err != nil {
  12640. }
  12641. startRecordDateTime := startTime.Unix()
  12642. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12643. if err != nil {
  12644. }
  12645. endRecordDateTime := endTime.Unix()
  12646. admin := c.GetAdminUserInfo()
  12647. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12648. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12649. order, _ := service.GetHisOrderByID(order_id)
  12650. var monthPrescriptions []*models.HisPrescription
  12651. if order_status == 1 || order_status == 0 {
  12652. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12653. } else if order_status == 2 {
  12654. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12655. }
  12656. var settle_total float64
  12657. for _, item := range monthPrescriptions {
  12658. if len(item.HisPrescriptionProject) > 0 {
  12659. for _, subItem := range item.HisPrescriptionProject {
  12660. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12661. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12662. settle_total = settle_total + total
  12663. }
  12664. }
  12665. if len(item.HisDoctorAdviceInfo) > 0 {
  12666. for _, subItem := range item.HisDoctorAdviceInfo {
  12667. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12668. settle_total = settle_total + total
  12669. }
  12670. }
  12671. }
  12672. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12673. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12674. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12675. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12676. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12677. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12678. //获取所有科室信息
  12679. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12680. var dia string
  12681. for _, item := range month_p_info {
  12682. if len(dia) == 0 {
  12683. dia = item.Diagnosis
  12684. } else {
  12685. dia = dia + "," + item.Diagnosis
  12686. }
  12687. }
  12688. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12689. dia_arr = removeEmptyStrings(dia_arr)
  12690. c.ServeSuccessJSON(map[string]interface{}{
  12691. "his_info": his_patient_info,
  12692. "xt_info": xt_patient_info,
  12693. "case_history": case_history,
  12694. "info": patientPrescriptionInfo,
  12695. "last_info": lastPatientPrescriptionInfo,
  12696. "month_prescriptions": monthPrescriptions,
  12697. "order": order,
  12698. "doctors": doctors,
  12699. "department": department,
  12700. "settle_total": settle_total,
  12701. "dia_arr": dia_arr,
  12702. })
  12703. return
  12704. }
  12705. func removeEmptyStrings(input []string) []string {
  12706. var output []string
  12707. for _, s := range input {
  12708. if s != "" {
  12709. output = append(output, s)
  12710. }
  12711. }
  12712. return output
  12713. }
  12714. func removeDuplicates(input []string) []string {
  12715. seen := make(map[string]bool)
  12716. output := []string{}
  12717. for _, s := range input {
  12718. if _, exists := seen[s]; !exists {
  12719. seen[s] = true
  12720. output = append(output, s)
  12721. }
  12722. }
  12723. return output
  12724. }
  12725. func (c *HisApiController) GetHisMonthPatientInfo() {
  12726. patient_id, _ := c.GetInt64("patient_id")
  12727. his_patient_id, _ := c.GetInt64("his_patient_id")
  12728. record_date := c.GetString("record_date")
  12729. number := c.GetString("number")
  12730. start_time := c.GetString("start_time")
  12731. end_time := c.GetString("end_time")
  12732. p_type, _ := c.GetInt64("p_type")
  12733. timeLayout := "2006-01-02"
  12734. loc, _ := time.LoadLocation("Local")
  12735. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12736. if err != nil {
  12737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12738. return
  12739. }
  12740. recordDateTime := theTime.Unix()
  12741. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12742. if err != nil {
  12743. }
  12744. startRecordDateTime := startTime.Unix()
  12745. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12746. if err != nil {
  12747. }
  12748. endRecordDateTime := endTime.Unix()
  12749. admin := c.GetAdminUserInfo()
  12750. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12751. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12752. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12753. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12754. var settle_total float64
  12755. for _, item := range monthPrescriptions {
  12756. if len(item.HisPrescriptionProject) > 0 {
  12757. for _, subItem := range item.HisPrescriptionProject {
  12758. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12759. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12760. settle_total = settle_total + total
  12761. }
  12762. }
  12763. if len(item.HisDoctorAdviceInfo) > 0 {
  12764. for _, subItem := range item.HisDoctorAdviceInfo {
  12765. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12766. settle_total = settle_total + total
  12767. }
  12768. }
  12769. }
  12770. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12771. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12772. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12773. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12774. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12775. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12776. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12777. //获取所有科室信息
  12778. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12779. c.ServeSuccessJSON(map[string]interface{}{
  12780. "his_info": his_patient_info,
  12781. "xt_info": xt_patient_info,
  12782. "case_history": case_history,
  12783. "info": patientPrescriptionInfo,
  12784. "month_prescriptions": monthPrescriptions,
  12785. "order": order,
  12786. "doctors": doctors,
  12787. "department": department,
  12788. "count": count,
  12789. "drugStockConfig": drugStockConfig,
  12790. "last_info": lastPatientPrescriptionInfo,
  12791. "settle_total": settle_total,
  12792. })
  12793. return
  12794. }
  12795. func (c *HisApiController) GetAllOrder() {
  12796. org_id := c.GetAdminUserInfo().CurrentOrgId
  12797. orders, _ := service.GetNewHisOrderList(org_id)
  12798. c.ServeSuccessJSON(map[string]interface{}{
  12799. "order": orders,
  12800. })
  12801. return
  12802. }
  12803. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12804. newArr = make([]*models.HisOrderInfoTwo, 0)
  12805. for i := 0; i < len(arr); i++ {
  12806. repeat := false
  12807. for j := i + 1; j < len(arr); j++ {
  12808. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12809. repeat = true
  12810. break
  12811. }
  12812. }
  12813. if !repeat {
  12814. newArr = append(newArr, arr[i])
  12815. }
  12816. }
  12817. return
  12818. }
  12819. // 修改处方退库操作 参数传修改之前的处方数据
  12820. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12821. if advice.ExecutionState == 1 {
  12822. //查询该病人该药品是否有库存记录
  12823. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12824. if errcode == gorm.ErrRecordNotFound {
  12825. } else {
  12826. //退库
  12827. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12828. if advice.PrescribingNumberUnit == drug.MinUnit {
  12829. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12830. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12831. //退库
  12832. warehouseInfo := models.DrugWarehouseInfo{
  12833. StockMinNumber: prescribingNumber,
  12834. }
  12835. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12836. operation_time := time.Now().Unix()
  12837. creater := advice.AdviceDoctor
  12838. ctime := time.Now().Unix()
  12839. timeStr := time.Now().Format("2006-01-02")
  12840. timeArr := strings.Split(timeStr, "-")
  12841. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12842. total = total + 1
  12843. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12844. cancelStock := models.DrugCancelStock{
  12845. OrderNumber: orderNumber,
  12846. OperaTime: operation_time,
  12847. OrgId: advice.UserOrgId,
  12848. Creater: creater,
  12849. Ctime: ctime,
  12850. Status: 1,
  12851. ReturnTime: advice.AdviceDate,
  12852. Dealer: info.Dealer,
  12853. Manufacturer: info.Manufacturer,
  12854. Type: 1,
  12855. }
  12856. service.AddSigleDrugCancelStock(&cancelStock)
  12857. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12858. dealer, _ := service.GetDealerById(info.Dealer)
  12859. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12860. cancelStockInfo := models.DrugCancelStockInfo{
  12861. OrderNumber: cancelInfo.OrderNumber,
  12862. CancelStockId: cancelInfo.ID,
  12863. DrugId: info.DrugId,
  12864. Count: info.Count,
  12865. Status: 1,
  12866. Ctime: ctime,
  12867. OrgId: advice.UserOrgId,
  12868. Type: 1,
  12869. Manufacturer: manufactureName.ManufacturerName,
  12870. Dealer: dealer.DealerName,
  12871. Total: 0,
  12872. RetailPrice: info.RetailPrice,
  12873. RetailTotalPrice: info.RetailTotalPrice,
  12874. Price: info.Price,
  12875. RegisterAccount: "",
  12876. Remark: info.Remark,
  12877. BatchNumber: info.BatchNumber,
  12878. MaxUnit: info.CountUnit,
  12879. ProductDate: info.ProductDate,
  12880. ExpiryDate: info.ExpiryDate,
  12881. BatchNumberId: info.WarehouseInfoId,
  12882. }
  12883. flow := models.DrugFlow{
  12884. WarehousingId: 0,
  12885. DrugId: info.DrugId,
  12886. Number: "",
  12887. BatchNumber: info.BatchNumber,
  12888. Count: info.Count,
  12889. UserOrgId: advice.UserOrgId,
  12890. PatientId: 0,
  12891. SystemTime: ctime,
  12892. ConsumableType: 4,
  12893. IsSys: 0,
  12894. WarehousingOrder: "",
  12895. WarehouseOutId: 0,
  12896. WarehouseOutOrderNumber: "",
  12897. IsEdit: 0,
  12898. CancelStockId: cancelStock.ID,
  12899. CancelOrderNumber: cancelStock.OrderNumber,
  12900. Manufacturer: info.Manufacturer,
  12901. Dealer: info.Dealer,
  12902. Creator: advice.UserOrgId,
  12903. UpdateCreator: 0,
  12904. Status: 1,
  12905. Ctime: time.Now().Unix(),
  12906. Mtime: 0,
  12907. Price: info.Price,
  12908. WarehousingDetailId: 0,
  12909. WarehouseOutDetailId: 0,
  12910. CancelOutDetailId: 0,
  12911. ExpireDate: info.ExpiryDate,
  12912. ProductDate: info.ProductDate,
  12913. MaxUnit: info.CountUnit,
  12914. MinUnit: "",
  12915. }
  12916. service.CreatedCancelStock(cancelStockInfo)
  12917. service.CreateDrugFlowOne(flow)
  12918. } else {
  12919. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12920. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12921. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12922. warehouseInfo := models.DrugWarehouseInfo{
  12923. StockMinNumber: prescribingNumber,
  12924. }
  12925. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12926. }
  12927. operation_time := time.Now().Unix()
  12928. creater := advice.AdviceDoctor
  12929. ctime := time.Now().Unix()
  12930. timeStr := time.Now().Format("2006-01-02")
  12931. timeArr := strings.Split(timeStr, "-")
  12932. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12933. total = total + 1
  12934. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12935. cancelStock := models.DrugCancelStock{
  12936. OrderNumber: orderNumber,
  12937. OperaTime: operation_time,
  12938. OrgId: advice.UserOrgId,
  12939. Creater: creater,
  12940. Ctime: ctime,
  12941. Status: 1,
  12942. ReturnTime: advice.AdviceDate,
  12943. Dealer: info.Dealer,
  12944. Manufacturer: info.Manufacturer,
  12945. Type: 1,
  12946. }
  12947. service.AddSigleDrugCancelStock(&cancelStock)
  12948. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12949. dealer, _ := service.GetDealerById(info.Dealer)
  12950. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12951. cancelStockInfo := models.DrugCancelStockInfo{
  12952. OrderNumber: cancelInfo.OrderNumber,
  12953. CancelStockId: cancelInfo.ID,
  12954. DrugId: info.DrugId,
  12955. Count: info.Count,
  12956. Status: 1,
  12957. Ctime: ctime,
  12958. OrgId: advice.UserOrgId,
  12959. Type: 1,
  12960. Manufacturer: manufactureName.ManufacturerName,
  12961. Dealer: dealer.DealerName,
  12962. Total: 0,
  12963. RetailPrice: info.RetailPrice,
  12964. RetailTotalPrice: info.RetailTotalPrice,
  12965. Price: info.Price,
  12966. RegisterAccount: "",
  12967. Remark: info.Remark,
  12968. BatchNumber: info.BatchNumber,
  12969. MaxUnit: info.CountUnit,
  12970. ProductDate: info.ProductDate,
  12971. ExpiryDate: info.ExpiryDate,
  12972. BatchNumberId: info.WarehouseInfoId,
  12973. }
  12974. flow := models.DrugFlow{
  12975. WarehousingId: 0,
  12976. DrugId: info.DrugId,
  12977. Number: "",
  12978. BatchNumber: info.BatchNumber,
  12979. Count: info.Count,
  12980. UserOrgId: advice.UserOrgId,
  12981. PatientId: 0,
  12982. SystemTime: ctime,
  12983. ConsumableType: 4,
  12984. IsSys: 0,
  12985. WarehousingOrder: "",
  12986. WarehouseOutId: 0,
  12987. WarehouseOutOrderNumber: "",
  12988. IsEdit: 0,
  12989. CancelStockId: cancelStock.ID,
  12990. CancelOrderNumber: cancelStock.OrderNumber,
  12991. Manufacturer: info.Manufacturer,
  12992. Dealer: info.Dealer,
  12993. Creator: advice.AdviceDoctor,
  12994. UpdateCreator: 0,
  12995. Status: 1,
  12996. Ctime: time.Now().Unix(),
  12997. Mtime: 0,
  12998. Price: info.Price,
  12999. WarehousingDetailId: 0,
  13000. WarehouseOutDetailId: 0,
  13001. CancelOutDetailId: 0,
  13002. ExpireDate: info.ExpiryDate,
  13003. ProductDate: info.ProductDate,
  13004. MaxUnit: info.CountUnit,
  13005. MinUnit: "",
  13006. }
  13007. service.CreatedCancelStock(cancelStockInfo)
  13008. service.CreateDrugFlowOne(flow)
  13009. }
  13010. }
  13011. }
  13012. return err
  13013. }
  13014. func (this *HisApiController) DeleteNCDS() {
  13015. id, _ := this.GetInt64("id", 0)
  13016. if id > 0 {
  13017. service.DeletePsnNCDSRecordById(id)
  13018. this.ServeSuccessJSON(map[string]interface{}{
  13019. "msg": "删除成功",
  13020. })
  13021. } else {
  13022. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13023. return
  13024. }
  13025. }
  13026. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13027. id, _ := c.GetInt64("id")
  13028. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13029. c.ServeSuccessJSON(map[string]interface{}{
  13030. "advice": advice,
  13031. })
  13032. return
  13033. }
  13034. func (c *HisApiController) GetHisMonthChargePatientList() {
  13035. record_date := c.GetString("record_date")
  13036. start_time := c.GetString("start_time")
  13037. end_time := c.GetString("end_time")
  13038. timeLayout := "2006-01-02"
  13039. loc, _ := time.LoadLocation("Local")
  13040. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13041. if err != nil {
  13042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13043. return
  13044. }
  13045. if err != nil {
  13046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13047. return
  13048. }
  13049. recordDateTime := theTime.Unix()
  13050. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13051. if err != nil {
  13052. }
  13053. startRecordDateTime := startTime.Unix()
  13054. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13055. if err != nil {
  13056. }
  13057. endRecordDateTime := endTime.Unix()
  13058. adminInfo := c.GetAdminUserInfo()
  13059. var tempMonthChargePatients []*service.MonthChargePatients
  13060. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13061. for _, item := range tempPatients {
  13062. //过滤没有处方的
  13063. if len(item.HisPrescription) == 0 {
  13064. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13065. }
  13066. }
  13067. c.ServeSuccessJSON(map[string]interface{}{
  13068. "list": tempMonthChargePatients,
  13069. })
  13070. }
  13071. // PrescriptionDifference 医嘱数量差值结构体
  13072. type PrescriptionDrugDifference struct {
  13073. DrugID int64 //基础库药品id
  13074. ID int64 //医嘱id
  13075. Difference float64 //差值
  13076. Unit string //单位
  13077. }
  13078. type PrescriptionGoodDifference struct {
  13079. GoodID int64 //基础库项目耗材id
  13080. ID int64 //医嘱id
  13081. Difference int64 //差值
  13082. Unit string //单位
  13083. Type int64 //类型
  13084. }
  13085. type EditCustomData struct {
  13086. adviceList []*models.HisDoctorAdviceInfo
  13087. projectList []*models.HisPrescriptionProject
  13088. }
  13089. type SrcCustomData struct {
  13090. adviceList []*models.HisDoctorAdviceInfo
  13091. projectList []*models.HisPrescriptionProject
  13092. }
  13093. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13094. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13095. differences := make([]*PrescriptionDrugDifference, 0)
  13096. // 创建一个 map 来存储第一个切片中的药品信息
  13097. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13098. for _, advice := range firstPrescription {
  13099. firstMap[advice.DrugId] = advice
  13100. }
  13101. // 遍历第二个切片中的药品信息,并比较数量差值
  13102. for _, advice := range secondPrescription {
  13103. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13104. diff := &PrescriptionDrugDifference{
  13105. DrugID: advice.DrugId,
  13106. ID: firstAdvice.ID,
  13107. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13108. Unit: firstAdvice.PrescribingNumberUnit,
  13109. }
  13110. differences = append(differences, diff)
  13111. }
  13112. }
  13113. return differences
  13114. }
  13115. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13116. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13117. differences := make([]*PrescriptionGoodDifference, 0)
  13118. // 创建一个 map 来存储第一个切片中的耗材信息
  13119. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13120. for _, good := range firstPrescription {
  13121. firstMap[good.ProjectId] = good
  13122. }
  13123. // 遍历第二个切片中的耗材信息,并比较数量差值
  13124. for _, good := range secondPrescription {
  13125. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13126. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13127. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13128. diff := &PrescriptionGoodDifference{
  13129. GoodID: good.ProjectId,
  13130. ID: firstGood.ID,
  13131. Difference: count - firstCount,
  13132. Unit: firstGood.Unit,
  13133. Type: firstGood.Type,
  13134. }
  13135. differences = append(differences, diff)
  13136. }
  13137. }
  13138. return differences
  13139. }
  13140. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13141. var adviceList []*models.HisDoctorAdviceInfo
  13142. var projectList []*models.HisPrescriptionProject
  13143. var advice_ids []int64
  13144. var project_ids []int64
  13145. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13146. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13147. //var tempPrescription *models.HisPrescriptionProjectscription
  13148. if len(prescriptions) > 0 {
  13149. for _, item := range prescriptions {
  13150. items := item.(map[string]interface{})
  13151. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13152. advices := items["advices"].([]interface{})
  13153. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13154. groupNo := int64(0)
  13155. ctime := time.Now().Unix()
  13156. mtime := ctime
  13157. if len(advices) > 0 {
  13158. for _, advice := range advices {
  13159. var s models.HisDoctorAdviceInfo
  13160. s.AdviceType = 2
  13161. s.StopState = 2
  13162. s.ExecutionState = 2
  13163. s.Status = 1
  13164. s.Groupno = groupNo
  13165. s.CreatedTime = ctime
  13166. s.UpdatedTime = mtime
  13167. s.IsSettle = 2
  13168. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13169. //存储切片中
  13170. if s.ID > 0 {
  13171. advice_ids = append(advice_ids, s.ID)
  13172. adviceList = append(adviceList, &s)
  13173. }
  13174. }
  13175. }
  13176. }
  13177. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13178. projects := items["project"].([]interface{})
  13179. if len(projects) > 0 {
  13180. for _, project := range projects {
  13181. var p models.HisPrescriptionProject
  13182. p.Ctime = time.Now().Unix()
  13183. p.Mtime = time.Now().Unix()
  13184. p.Status = 1
  13185. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13186. if p.ID > 0 {
  13187. project_ids = append(project_ids, p.ID)
  13188. projectList = append(projectList, &p)
  13189. }
  13190. }
  13191. }
  13192. }
  13193. }
  13194. }
  13195. }
  13196. editCustomData.projectList = projectList
  13197. editCustomData.adviceList = adviceList
  13198. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13199. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13200. srcCustomData.adviceList = list
  13201. srcCustomData.projectList = list2
  13202. return
  13203. }
  13204. func (c *HisApiController) GetAllGoodInforList() {
  13205. orgId := c.GetAdminUserInfo().CurrentOrgId
  13206. goodList, _ := service.GetAllGoodList(orgId)
  13207. c.ServeSuccessJSON(map[string]interface{}{
  13208. "goodList": goodList,
  13209. })
  13210. return
  13211. }
  13212. func (this *HisApiController) SaveGoodList() {
  13213. project_name := this.GetString("project_name")
  13214. sort, _ := this.GetInt64("sort")
  13215. orgId := this.GetAdminUserInfo().CurrentOrgId
  13216. dataBody := make(map[string]interface{}, 0)
  13217. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13218. if err != nil {
  13219. utils.ErrorLog(err.Error())
  13220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13221. return
  13222. }
  13223. goodTeam := models.XtGoodTeam{
  13224. ProjectName: project_name,
  13225. Sort: sort,
  13226. UserOrgId: orgId,
  13227. Status: 1,
  13228. Ctime: time.Now().Unix(),
  13229. Mtime: time.Now().Unix(),
  13230. }
  13231. service.CreateGoodTeam(goodTeam)
  13232. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13233. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13234. infos, _ := dataBody["info"].([]interface{})
  13235. if len(infos) > 0 {
  13236. for _, item := range infos {
  13237. items := item.(map[string]interface{})
  13238. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13239. utils.ErrorLog("good_id")
  13240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13241. return
  13242. }
  13243. good_id := int64(items["good_id"].(float64))
  13244. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13245. utils.ErrorLog("number")
  13246. }
  13247. number := int64(items["number"].(float64))
  13248. xtGoodTeamList := models.XtGoodTeamList{
  13249. GoodId: good_id,
  13250. Count: number,
  13251. TeamId: lastGoodTeam.ID,
  13252. UserOrgId: orgId,
  13253. Status: 1,
  13254. Ctime: time.Now().Unix(),
  13255. Mtime: time.Now().Unix(),
  13256. }
  13257. service.CreateGoodList(xtGoodTeamList)
  13258. }
  13259. this.ServeSuccessJSON(map[string]interface{}{
  13260. "lastGoodTeam": lastGoodTeam,
  13261. })
  13262. }
  13263. }
  13264. return
  13265. }
  13266. func (this *HisApiController) GetGoodList() {
  13267. orgId := this.GetAdminUserInfo().CurrentOrgId
  13268. limit, _ := this.GetInt64("limit")
  13269. page, _ := this.GetInt64("page")
  13270. keyword := this.GetString("keyword")
  13271. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13272. this.ServeSuccessJSON(map[string]interface{}{
  13273. "list": list,
  13274. "total": total,
  13275. })
  13276. }
  13277. func (this *HisApiController) GetGoodNameDetail() {
  13278. id, _ := this.GetInt64("id")
  13279. orgId := this.GetAdminUserInfo().CurrentOrgId
  13280. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13281. goodList, _ := service.GetAllGoodList(orgId)
  13282. this.ServeSuccessJSON(map[string]interface{}{
  13283. "goodNameDetail": goodNameDetail,
  13284. "goodList": goodList,
  13285. })
  13286. }
  13287. func (this *HisApiController) UpdateGoodList() {
  13288. project_name := this.GetString("project_name")
  13289. sort, _ := this.GetInt64("sort")
  13290. id, _ := this.GetInt64("id")
  13291. orgId := this.GetAdminUserInfo().CurrentOrgId
  13292. dataBody := make(map[string]interface{}, 0)
  13293. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13294. if err != nil {
  13295. utils.ErrorLog(err.Error())
  13296. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13297. return
  13298. }
  13299. goodTeam := models.XtGoodTeam{
  13300. ProjectName: project_name,
  13301. Sort: sort,
  13302. UserOrgId: orgId,
  13303. Status: 1,
  13304. Ctime: time.Now().Unix(),
  13305. Mtime: time.Now().Unix(),
  13306. ID: id,
  13307. }
  13308. service.SaveGoodTeam(goodTeam)
  13309. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13310. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13311. infos, _ := dataBody["info"].([]interface{})
  13312. if len(infos) > 0 {
  13313. for _, item := range infos {
  13314. items := item.(map[string]interface{})
  13315. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13316. utils.ErrorLog("good_id")
  13317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13318. return
  13319. }
  13320. good_id := int64(items["good_id"].(float64))
  13321. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13322. utils.ErrorLog("id")
  13323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13324. return
  13325. }
  13326. id := int64(items["id"].(float64))
  13327. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13328. utils.ErrorLog("number")
  13329. }
  13330. number := int64(items["number"].(float64))
  13331. xtGoodTeamList := models.XtGoodTeamList{
  13332. ID: id,
  13333. GoodId: good_id,
  13334. Count: number,
  13335. TeamId: lastGoodTeam.ID,
  13336. UserOrgId: orgId,
  13337. Status: 1,
  13338. Ctime: time.Now().Unix(),
  13339. Mtime: time.Now().Unix(),
  13340. }
  13341. service.SaveGoodList(xtGoodTeamList)
  13342. }
  13343. this.ServeSuccessJSON(map[string]interface{}{
  13344. "lastGoodTeam": lastGoodTeam,
  13345. })
  13346. }
  13347. }
  13348. return
  13349. }
  13350. func (this *HisApiController) DeleteGoodTeam() {
  13351. id, _ := this.GetInt64("id")
  13352. team, _ := service.DeleteGoodTeam(id)
  13353. this.ServeSuccessJSON(map[string]interface{}{
  13354. "team": team,
  13355. })
  13356. }
  13357. func (this *HisApiController) DeleteGood() {
  13358. id, _ := this.GetInt64("id")
  13359. good, _ := service.DeleteGood(id)
  13360. this.ServeSuccessJSON(map[string]interface{}{
  13361. "good": good,
  13362. })
  13363. }