his_api_controller.go 609KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/test/net", &HisApiController{}, "get:TestNet")
  26. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  27. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  28. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  29. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  30. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  31. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  32. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  33. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  34. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  35. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  36. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  37. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  38. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  41. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  42. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  43. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  44. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  45. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  46. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  47. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  48. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  49. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  51. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  52. //新增附加费用
  53. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  54. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  55. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  56. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  57. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  58. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  59. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  60. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  61. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  62. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  63. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  64. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  65. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  66. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  67. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  68. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  92. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  93. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  94. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  95. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  96. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  97. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  98. }
  99. func (c *HisApiController) TestNet() {
  100. c.ServeSuccessJSON(map[string]interface{}{
  101. "msg": "成功",
  102. })
  103. }
  104. func (c *HisApiController) CheckHisPatient() {
  105. record_date := c.GetString("record_date")
  106. patient_id, _ := c.GetInt64("patient_id")
  107. timeLayout := "2006-01-02"
  108. loc, _ := time.LoadLocation("Local")
  109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  110. if err != nil {
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  112. return
  113. }
  114. recordDateTime := theTime.Unix()
  115. adminInfo := c.GetAdminUserInfo()
  116. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  117. if len(patients) > 1 {
  118. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  119. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  120. c.ServeSuccessJSON(map[string]interface{}{
  121. "status": 1,
  122. "msg": "关联",
  123. "ps": ps,
  124. "his_patient_id": patients[len(patients)-1].ID,
  125. "patient_id": patients[len(patients)-1].PatientId,
  126. })
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. }
  133. } else {
  134. c.ServeSuccessJSON(map[string]interface{}{
  135. "status": 0,
  136. "msg": "无需关联",
  137. })
  138. return
  139. }
  140. }
  141. func (c *HisApiController) AssociationHisPrescription() {
  142. record_date := c.GetString("record_date")
  143. his_patient_id, _ := c.GetInt64("his_patient_id")
  144. patient_id, _ := c.GetInt64("patient_id")
  145. p_ids := c.GetString("p_ids")
  146. p_ids_arr := strings.Split(p_ids, ",")
  147. timeLayout := "2006-01-02"
  148. loc, _ := time.LoadLocation("Local")
  149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  150. if err != nil {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. recordDateTime := theTime.Unix()
  155. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  156. if his_patient_id == 0 || his_patient.ID == 0 {
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  161. if err == nil {
  162. c.ServeSuccessJSON(map[string]interface{}{
  163. "msg": "关联处方成功",
  164. })
  165. return
  166. } else {
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  168. return
  169. }
  170. }
  171. //func (c *HisApiController) AssociationHisPrescription() {
  172. // record_date, _ := c.GetInt64("record_date")
  173. // his_patient_id, _ := c.GetInt64("his_patient_id")
  174. // patient_id, _ := c.GetInt64("patient_id")
  175. // p_ids := c.GetString("p_ids")
  176. // p_ids_arr := strings.Split(p_ids, ",")
  177. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  178. // if his_patient_id == 0 || his_patient.ID == 0 {
  179. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  180. // return
  181. // }
  182. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  183. // if err == nil {
  184. // c.ServeSuccessJSON(map[string]interface{}{
  185. // "msg": "关联处方成功",
  186. // })
  187. // return
  188. // } else {
  189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  190. // return
  191. // }
  192. //}
  193. func (c *HisApiController) GetFaPiaoNumber() {
  194. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  195. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  196. fmt.Println(count)
  197. var zero string
  198. number := count + 1
  199. //if number >= 1000 {
  200. // zero = "0000" + strconv.FormatInt(number, 10)
  201. //} else if number >= 10000 {
  202. // zero = "000" + strconv.FormatInt(number, 10)
  203. //} else if number >= 100000 {
  204. // zero = "00" + strconv.FormatInt(number, 10)
  205. //} else if number >= 1000000 {
  206. // zero = "0" + strconv.FormatInt(number, 10)
  207. //} else {
  208. zero = "0" + strconv.FormatInt(number, 10)
  209. //}
  210. c.ServeSuccessJSON(map[string]interface{}{
  211. "fapiao_number": zero,
  212. })
  213. return
  214. }
  215. func (c *HisApiController) ChangeOrderDesc() {
  216. id, _ := c.GetInt64("id")
  217. desc := c.GetString("desc")
  218. change_type := c.GetString("change_type")
  219. order, _ := service.GetHisOrderByID(id)
  220. if order.ID == 0 {
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  222. return
  223. }
  224. switch change_type {
  225. case "oth_desc":
  226. order.OthDesc = desc
  227. break
  228. case "cash_pay":
  229. order.CashPay = desc
  230. break
  231. case "jifen_pay":
  232. order.JifenPay = desc
  233. break
  234. case "card_desc":
  235. order.CardDesc = desc
  236. break
  237. case "band_card_pay":
  238. order.BandCardPay = desc
  239. break
  240. case "ali_pay":
  241. order.AliPay = desc
  242. break
  243. case "wechat_pay":
  244. order.WechatPay = desc
  245. break
  246. case "fa_piao_number":
  247. order.FaPiaoNumber = desc
  248. break
  249. case "fa_piao_code":
  250. order.FaPiaoCode = desc
  251. break
  252. }
  253. err := service.SaveHisOrder(&order)
  254. if err == nil {
  255. c.ServeSuccessJSON(map[string]interface{}{
  256. "msg": "修改成功",
  257. })
  258. return
  259. } else {
  260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  261. return
  262. }
  263. }
  264. func (c *HisApiController) GetMonthHisPatient() {
  265. record_date := c.GetString("record_date")
  266. //order_status, _ := c.GetInt64("type")
  267. timeLayout := "2006-01-02"
  268. loc, _ := time.LoadLocation("Local")
  269. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  270. if err != nil {
  271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  272. return
  273. }
  274. recordDateTime := theTime.Unix()
  275. adminInfo := c.GetAdminUserInfo()
  276. var tempPatients []service.NewTempPatients
  277. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  278. // 获取当前时间
  279. now := time.Now()
  280. // 获取本月的第一天
  281. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  282. // 获取下个月的第一天
  283. nextMonth := firstDay.AddDate(0, 1, 0)
  284. // 获取本月的最后一天
  285. lastDay := nextMonth.Add(-time.Nanosecond)
  286. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  287. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  288. var patients []service.NewTempPatients
  289. var patients_two []service.NewTempPatients
  290. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  291. for _, item := range tempPatients {
  292. //过滤掉没挂号的和没开处方的
  293. if len(item.HisPrescription) > 0 {
  294. patients = append(patients, item)
  295. patients_two = append(patients_two, item)
  296. }
  297. ////过滤掉没挂号的
  298. //if len(item.HisPatient) > 0 {
  299. //}
  300. }
  301. } else {
  302. for _, item := range tempPatients {
  303. //过滤掉没挂号的和没开处方的
  304. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  305. patients = append(patients, item)
  306. }
  307. ////过滤掉没挂号的
  308. //if len(item.HisPatient) > 0 {
  309. // patients_two = append(patients_two, item)
  310. //}
  311. }
  312. }
  313. c.ServeSuccessJSON(map[string]interface{}{
  314. "list": patients,
  315. "list_two": patients_two,
  316. "chargePatients": chargePatients,
  317. })
  318. }
  319. func (c *HisApiController) GetBatchSettleAccounts() {
  320. order_ids := c.GetString("order_ids")
  321. admin_user_id, _ := c.GetInt64("admin_user_id")
  322. adminUser := c.GetAdminUserInfo()
  323. orders := strings.Split(order_ids, ",")
  324. var newOrders []models.Orders
  325. for _, item := range orders {
  326. order, _ := service.GetHisOrderByIDTenOne(item)
  327. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  328. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  329. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  330. orderInfos = append(orderInfos, orderInfos_two...)
  331. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  332. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  333. var diagnosis_ids []string
  334. if his.ID > 0 {
  335. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  336. } else {
  337. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  338. }
  339. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  340. var dia_config []*models.HisXtDiagnoseConfig
  341. var name string
  342. for _, item := range diagnosis_ids {
  343. id, _ := strconv.ParseInt(item, 10, 64)
  344. diagnosisConfig, _ := service.FindDiagnoseById(id)
  345. dia_config = append(dia_config, diagnosisConfig)
  346. if len(name) == 0 {
  347. name = diagnosisConfig.ClassName
  348. } else {
  349. name = name + "," + diagnosisConfig.ClassName
  350. }
  351. }
  352. var bedCostTotal float64 = 0 //床位总费
  353. var bedCostSelfTotal float64 = 0 //床位自费
  354. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  355. var bedSelfTotal float64 = 0 //床位部分项目自费
  356. var bedInscpTotal float64 = 0 //床位部分项目自费
  357. var operationCostTotal float64 = 0 //手术费
  358. var operationCostSelfTotal float64 = 0 //手术费
  359. var operationCostPartSelfTotal float64 = 0 //手术费
  360. var operationSelfTotal float64 = 0 //床位部分项目自费
  361. var operationInscpTotal float64 = 0 //床位部分项目自费
  362. var otherCostTotal float64 = 0 //其他费用
  363. var otherCostSelfTotal float64 = 0 //其他费用
  364. var otherCostPartSelfTotal float64 = 0 //其他费用
  365. var otherSelfTotal float64 = 0 //床位部分项目自费
  366. var otherInscpTotal float64 = 0 //床位部分项目自费
  367. var materialCostTotal float64 = 0 //材料费
  368. var materialCostSelfTotal float64 = 0 //材料费
  369. var materialCostPartSelfTotal float64 = 0 //材料费
  370. var materialSelfTotal float64 = 0 //床位部分项目自费
  371. var materialInscpTotal float64 = 0 //床位部分项目自费
  372. var westernMedicineCostTotal float64 = 0 //西药费
  373. var westernMedicineCostSelfTotal float64 = 0 //西药费
  374. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  375. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  376. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  377. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  378. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  379. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  380. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  381. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  382. var checkCostTotal float64 = 0 //检查费
  383. var checkCostSelfTotal float64 = 0 //检查费
  384. var checkCostPartSelfTotal float64 = 0 //检查费
  385. var checkSelfTotal float64 = 0 //床位部分项目自费
  386. var checkInscpTotal float64 = 0 //床位部分项目自费
  387. var laboratoryCostTotal float64 = 0 //化验费
  388. var laboratoryCostSelfTotal float64 = 0 //化验费
  389. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  390. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  391. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  392. var treatCostTotal float64 = 0 //治疗费用
  393. var treatCostSelfTotal float64 = 0 //治疗费用
  394. var treatCostPartSelfTotal float64 = 0 //治疗费用
  395. var treatSelfTotal float64 = 0 //床位部分项目自费
  396. var treatInscpTotal float64 = 0 //床位部分项目自费
  397. decimal.DivisionPrecision = 2
  398. for _, item := range orderInfos {
  399. if item.MedChrgitmType == "01" { //床位费
  400. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  407. if item.MedChrgitmType == "03" { //检查费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. } else {
  415. if item.MedChrgitmType == "03" { //检查费
  416. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. }
  423. if item.MedChrgitmType == "04" { //化验费
  424. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  425. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  426. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  427. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  428. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  429. }
  430. if item.MedChrgitmType == "05" { //治疗费
  431. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  432. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  433. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  434. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  435. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  436. }
  437. if item.MedChrgitmType == "06" { //手术费
  438. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  439. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  440. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  441. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  442. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  443. }
  444. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  445. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  446. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  447. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  448. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  449. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  450. }
  451. if item.MedChrgitmType == "09" { //西药费
  452. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  453. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  454. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  455. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  456. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  457. }
  458. if item.MedChrgitmType == "11" { //中成费
  459. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  460. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  461. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  462. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  463. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  464. }
  465. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  466. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  467. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  468. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  469. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  470. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  471. }
  472. }
  473. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  474. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  475. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  476. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  477. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  478. var doctor_name string
  479. if roles.ID == 0 {
  480. doctor_name = "管理员"
  481. } else {
  482. doctor_name = roles.UserName
  483. }
  484. yiliao_leibie := ""
  485. switch order.MedType {
  486. case "11":
  487. yiliao_leibie = "普通门诊"
  488. break
  489. case "12":
  490. yiliao_leibie = "门诊挂号"
  491. break
  492. case "13":
  493. yiliao_leibie = "急诊"
  494. break
  495. case "14":
  496. yiliao_leibie = "门诊特殊病"
  497. break
  498. case "15":
  499. yiliao_leibie = "门诊统筹"
  500. break
  501. case "16":
  502. yiliao_leibie = "门诊慢性病"
  503. break
  504. case "21":
  505. yiliao_leibie = "普通住院"
  506. break
  507. }
  508. var newOrder models.Orders
  509. newOrder.Diagnosis = name
  510. newOrder.OrderInfos = orderInfos
  511. newOrder.Number = order.MdtrtId
  512. newOrder.Date = order.SettleAccountsDate
  513. newOrder.ChargeAdmin = charge_admin
  514. newOrder.PrintorAdmin = printor_admin
  515. newOrder.Order = order
  516. newOrder.BedCostTotal = bedCostTotal
  517. newOrder.BedCostSelfTotal = bedCostSelfTotal
  518. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  519. newOrder.BedSelfTotal = bedSelfTotal
  520. newOrder.BedInscpTotal = bedInscpTotal
  521. newOrder.OperationCostTotal = operationCostTotal
  522. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  523. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  524. newOrder.OperationSelfTotal = operationSelfTotal
  525. newOrder.OperationInscpTotal = operationInscpTotal
  526. newOrder.OtherCostTotal = otherCostTotal
  527. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  528. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  529. newOrder.OtherSelfTotal = otherSelfTotal
  530. newOrder.OtherInscpTotal = otherInscpTotal
  531. newOrder.MaterialCostTotal = materialCostTotal
  532. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  533. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  534. newOrder.MaterialSelfTotal = materialSelfTotal
  535. newOrder.MaterialInscpTotal = materialInscpTotal
  536. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  537. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  538. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  539. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  540. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  541. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  542. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  543. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  544. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  545. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  546. newOrder.CheckCostTotal = checkCostTotal
  547. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  548. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  549. newOrder.CheckSelfTotal = checkSelfTotal
  550. newOrder.CheckInscpTotal = checkInscpTotal
  551. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  552. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  553. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  554. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  555. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  556. newOrder.TreatCostTotal = treatCostTotal
  557. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  558. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  559. newOrder.TreatSelfTotal = treatSelfTotal
  560. newOrder.TreatInscpTotal = treatInscpTotal
  561. newOrder.DoctorInfo = doctor_info
  562. newOrder.DoctorName = doctor_name
  563. newOrder.HealthCardNo = order.PsnNo
  564. newOrder.YiliaoLeibie = yiliao_leibie
  565. newOrder.Patient = patient
  566. newOrder.OrgName = miConfig.OrgName
  567. newOrder.OrgCode = miConfig.Code
  568. newOrder.OrderNumber = order.Number
  569. newOrder.HisPatient = his
  570. newOrder.DiaConfig = dia_config
  571. newOrders = append(newOrders, newOrder)
  572. }
  573. c.ServeSuccessJSON(map[string]interface{}{
  574. "orders": newOrders,
  575. })
  576. }
  577. func (c *HisApiController) GetTestOrder() {
  578. order_id, _ := c.GetInt64("order_id")
  579. admin_user_id, _ := c.GetInt64("admin_user_id")
  580. adminUser := c.GetAdminUserInfo()
  581. order, _ := service.GetHisOrderByID(order_id)
  582. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  583. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  584. orderInfos = append(orderInfos, orderInfos_two...)
  585. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  586. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  587. var dia_config []*models.HisXtDiagnoseConfig
  588. var name string
  589. var bedCostTotal float64 = 0 //床位总费
  590. var bedCostSelfTotal float64 = 0 //床位自费
  591. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  592. var bedSelfTotal float64 = 0 //床位部分项目自费
  593. var bedInscpTotal float64 = 0 //床位部分项目自费
  594. var operationCostTotal float64 = 0 //手术费
  595. var operationCostSelfTotal float64 = 0 //手术费
  596. var operationCostPartSelfTotal float64 = 0 //手术费
  597. var operationSelfTotal float64 = 0 //床位部分项目自费
  598. var operationInscpTotal float64 = 0 //床位部分项目自费
  599. var otherCostTotal float64 = 0 //其他费用
  600. var otherCostSelfTotal float64 = 0 //其他费用
  601. var otherCostPartSelfTotal float64 = 0 //其他费用
  602. var otherSelfTotal float64 = 0 //床位部分项目自费
  603. var otherInscpTotal float64 = 0 //床位部分项目自费
  604. var materialCostTotal float64 = 0 //材料费
  605. var materialCostSelfTotal float64 = 0 //材料费
  606. var materialCostPartSelfTotal float64 = 0 //材料费
  607. var materialSelfTotal float64 = 0 //床位部分项目自费
  608. var materialInscpTotal float64 = 0 //床位部分项目自费
  609. var westernMedicineCostTotal float64 = 0 //西药费
  610. var westernMedicineCostSelfTotal float64 = 0 //西药费
  611. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  612. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  613. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  614. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  615. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  616. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  617. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  618. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  619. var checkCostTotal float64 = 0 //检查费
  620. var checkCostSelfTotal float64 = 0 //检查费
  621. var checkCostPartSelfTotal float64 = 0 //检查费
  622. var checkSelfTotal float64 = 0 //床位部分项目自费
  623. var checkInscpTotal float64 = 0 //床位部分项目自费
  624. var laboratoryCostTotal float64 = 0 //化验费
  625. var laboratoryCostSelfTotal float64 = 0 //化验费
  626. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  627. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  628. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  629. var treatCostTotal float64 = 0 //治疗费用
  630. var treatCostSelfTotal float64 = 0 //治疗费用
  631. var treatCostPartSelfTotal float64 = 0 //治疗费用
  632. var treatSelfTotal float64 = 0 //床位部分项目自费
  633. var treatInscpTotal float64 = 0 //床位部分项目自费
  634. decimal.DivisionPrecision = 2
  635. for _, item := range orderInfos {
  636. if item.MedChrgitmType == "01" { //床位费
  637. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  644. if item.MedChrgitmType == "03" { //检查费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. } else {
  652. if item.MedChrgitmType == "03" { //检查费
  653. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. }
  660. if item.MedChrgitmType == "04" { //化验费
  661. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  662. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  663. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  664. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  665. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  666. }
  667. if item.MedChrgitmType == "05" { //治疗费
  668. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  669. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  670. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  671. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  672. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  673. }
  674. if item.MedChrgitmType == "06" { //手术费
  675. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  676. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  677. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  678. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  679. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  680. }
  681. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  682. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  683. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  684. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  685. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  686. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  687. }
  688. if item.MedChrgitmType == "09" { //西药费
  689. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  690. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  691. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  692. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  693. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  694. }
  695. if item.MedChrgitmType == "11" { //中成费
  696. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  697. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  698. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  699. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  700. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  701. }
  702. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  703. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  704. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  705. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  706. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  707. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  708. }
  709. }
  710. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  711. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  712. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  713. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  714. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  715. var doctor_name string
  716. if roles.ID == 0 {
  717. doctor_name = "管理员"
  718. } else {
  719. doctor_name = roles.UserName
  720. }
  721. yiliao_leibie := ""
  722. switch order.MedType {
  723. case "11":
  724. yiliao_leibie = "普通门诊"
  725. break
  726. case "12":
  727. yiliao_leibie = "门诊挂号"
  728. break
  729. case "13":
  730. yiliao_leibie = "急诊"
  731. break
  732. case "14":
  733. yiliao_leibie = "门诊特殊病"
  734. break
  735. case "15":
  736. yiliao_leibie = "门诊统筹"
  737. break
  738. case "16":
  739. yiliao_leibie = "门诊慢性病"
  740. break
  741. case "21":
  742. yiliao_leibie = "普通住院"
  743. break
  744. }
  745. c.ServeSuccessJSON(map[string]interface{}{
  746. "diagnosis": name,
  747. "order_infos": orderInfos,
  748. "number": order.MdtrtId,
  749. "date": order.SettleAccountsDate,
  750. "charge_admin": charge_admin,
  751. "printor_admin": printor_admin,
  752. "info": order,
  753. "order": order,
  754. "bedCostTotal": bedCostTotal,
  755. "bedCostSelfTotal": bedCostSelfTotal,
  756. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  757. "bedSelfTotal": bedSelfTotal,
  758. "bedInscpTotal": bedInscpTotal,
  759. "operationCostTotal": operationCostTotal,
  760. "operationCostSelfTotal": operationCostSelfTotal,
  761. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  762. "operationSelfTotal": operationSelfTotal,
  763. "operationInscpTotal": operationInscpTotal,
  764. "otherCostTotal": otherCostTotal,
  765. "otherCostSelfTotal": otherCostSelfTotal,
  766. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  767. "otherSelfTotal": otherSelfTotal,
  768. "otherInscpTotal": otherInscpTotal,
  769. "materialCostTotal": materialCostTotal,
  770. "materialCostSelfTotal": materialCostSelfTotal,
  771. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  772. "materialSelfTotal": materialSelfTotal,
  773. "materialInscpTotal": materialInscpTotal,
  774. "westernMedicineCostTotal": westernMedicineCostTotal,
  775. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  776. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  777. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  778. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  779. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  780. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  781. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  782. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  783. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  784. "checkCostTotal": checkCostTotal,
  785. "checkCostSelfTotal": checkCostSelfTotal,
  786. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  787. "checkSelfTotal": checkSelfTotal,
  788. "checkInscpTotal": checkInscpTotal,
  789. "laboratoryCostTotal": laboratoryCostTotal,
  790. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  791. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  792. "laboratorySelfTotal": laboratorySelfTotal,
  793. "laboratoryInscpTotal": laboratoryInscpTotal,
  794. "treatCostTotal": treatCostTotal,
  795. "treatCostSelfTotal": treatCostSelfTotal,
  796. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  797. "treatSelfTotal": treatSelfTotal,
  798. "treatInscpTotal": treatInscpTotal,
  799. "doctor_info": doctor_info,
  800. "doctor_name": doctor_name,
  801. "health_card_no": order.PsnNo,
  802. "yiliao_leibie": yiliao_leibie,
  803. "patient": patient,
  804. "org_name": miConfig.OrgName,
  805. "org_code": miConfig.Code,
  806. "order_number": order.Number,
  807. "his_hospital": his_hospital,
  808. "dia_config": dia_config,
  809. })
  810. }
  811. type CustomFundPay struct {
  812. FundPayType string `json:"fund_pay_type"`
  813. FundPayamt float64 `json:"fund_payamt"`
  814. InscpScpAmt float64 `json:"inscp_scp_amt"`
  815. }
  816. func (c *PublicApiController) GetBaiLinExportData() {
  817. data := service.GetBaiLinOrderData()
  818. fmt.Println(len(data))
  819. var new_data []*models.NewCustomHisOrder
  820. for _, item := range data {
  821. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  822. new_data = append(new_data, item)
  823. }
  824. }
  825. fmt.Println(len(new_data))
  826. c.ServeSuccessJSON(map[string]interface{}{
  827. "list": new_data,
  828. })
  829. }
  830. func (c *HisApiController) GetHisUnChargePatientList() {
  831. record_date := c.GetString("record_date")
  832. sch_type, _ := c.GetInt64("sch_type")
  833. timeLayout := "2006-01-02"
  834. loc, _ := time.LoadLocation("Local")
  835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  836. if err != nil {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. recordDateTime := theTime.Unix()
  841. adminInfo := c.GetAdminUserInfo()
  842. var tempPatients []*service.NewTempPatients
  843. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  844. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  845. var patients []*service.NewTempPatients
  846. var patients_two []*service.NewTempPatients
  847. for _, item := range tempPatients {
  848. //过滤掉没挂号的和没开处方的
  849. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  850. patients = append(patients, item)
  851. }
  852. //过滤掉没挂号的
  853. if len(item.HisPatient) > 0 {
  854. patients_two = append(patients_two, item)
  855. }
  856. }
  857. c.ServeSuccessJSON(map[string]interface{}{
  858. "list": patients,
  859. "list_two": patients_two,
  860. })
  861. }
  862. func (c *HisApiController) GetPrivateExpensesOrder() {
  863. //id, _ := c.GetInt64("id")
  864. //record_time := c.GetString("record_time")
  865. order_id, _ := c.GetInt64("order_id")
  866. admin_user_id, _ := c.GetInt64("admin_user_id")
  867. //timeLayout := "2006-01-02"
  868. //loc, _ := time.LoadLocation("Local")
  869. //
  870. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  871. //if err != nil {
  872. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  873. // return
  874. //}
  875. //recordDateTime := theTime.Unix()
  876. adminUser := c.GetAdminUserInfo()
  877. order, _ := service.GetHisOrderByID(order_id)
  878. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  879. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  880. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  881. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  882. //var config []*models.HisXtDiagnoseConfig
  883. var name string
  884. if order.PType == 1 {
  885. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  886. for _, item := range diagnosis_ids {
  887. id, _ := strconv.ParseInt(item, 10, 64)
  888. diagnosisConfig, _ := service.FindDiagnoseById(id)
  889. if len(name) == 0 {
  890. name = diagnosisConfig.ClassName
  891. } else {
  892. name = name + "," + diagnosisConfig.ClassName
  893. }
  894. }
  895. } else {
  896. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  897. for _, item := range diagnosis_ids {
  898. id, _ := strconv.ParseInt(item, 10, 64)
  899. diagnosisConfig, _ := service.FindDiagnoseById(id)
  900. if len(name) == 0 {
  901. name = diagnosisConfig.ClassName
  902. } else {
  903. name = name + "," + diagnosisConfig.ClassName
  904. }
  905. }
  906. }
  907. var bedCostTotal float64 = 0 //床位总费
  908. var bedCostSelfTotal float64 = 0 //床位自费
  909. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  910. var bedSelfTotal float64 = 0 //床位部分项目自费
  911. var bedInscpTotal float64 = 0 //床位部分项目自费
  912. var operationCostTotal float64 = 0 //手术费
  913. var operationCostSelfTotal float64 = 0 //手术费
  914. var operationCostPartSelfTotal float64 = 0 //手术费
  915. var operationSelfTotal float64 = 0 //床位部分项目自费
  916. var operationInscpTotal float64 = 0 //床位部分项目自费
  917. var otherCostTotal float64 = 0 //其他费用
  918. var otherCostSelfTotal float64 = 0 //其他费用
  919. var otherCostPartSelfTotal float64 = 0 //其他费用
  920. //var otherSelfTotal float64 = 0 //床位部分项目自费
  921. //var otherInscpTotal float64 = 0 //床位部分项目自费
  922. var materialCostTotal float64 = 0 //材料费
  923. var materialCostSelfTotal float64 = 0 //材料费
  924. var materialCostPartSelfTotal float64 = 0 //材料费
  925. var materialSelfTotal float64 = 0 //床位部分项目自费
  926. var materialInscpTotal float64 = 0 //床位部分项目自费
  927. var westernMedicineCostTotal float64 = 0 //西药费
  928. var westernMedicineCostSelfTotal float64 = 0 //西药费
  929. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  930. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  931. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  932. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  933. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  934. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  935. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  936. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  937. var checkCostTotal float64 = 0 //检查费
  938. var checkCostSelfTotal float64 = 0 //检查费
  939. var checkCostPartSelfTotal float64 = 0 //检查费
  940. var checkSelfTotal float64 = 0 //床位部分项目自费
  941. var checkInscpTotal float64 = 0 //床位部分项目自费
  942. var laboratoryCostTotal float64 = 0 //化验费
  943. var laboratoryCostSelfTotal float64 = 0 //化验费
  944. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  945. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  946. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  947. var treatCostTotal float64 = 0 //治疗费用
  948. var treatCostSelfTotal float64 = 0 //治疗费用
  949. var treatCostPartSelfTotal float64 = 0 //治疗费用
  950. var treatSelfTotal float64 = 0 //床位部分项目自费
  951. var treatInscpTotal float64 = 0 //床位部分项目自费
  952. var huliCostTotal float64 = 0 //治疗费用
  953. var huliCostSelfTotal float64 = 0 //治疗费用
  954. var huliCostPartSelfTotal float64 = 0 //治疗费用
  955. var huliSelfTotal float64 = 0 //床位部分项目自费
  956. var huliInscpTotal float64 = 0 //床位部分项目自费
  957. var zcCostTotal float64 = 0 //治疗费用
  958. var zcCostSelfTotal float64 = 0 //治疗费用
  959. var zcCostPartSelfTotal float64 = 0 //治疗费用
  960. var zcSelfTotal float64 = 0 //床位部分项目自费
  961. var zcInscpTotal float64 = 0 //床位部分项目自费
  962. var zhenChaCostTotal float64 = 0 //其他费用
  963. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  964. decimal.DivisionPrecision = 2
  965. for _, item := range orderInfos {
  966. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  967. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  968. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  969. item.MedChrgitmType = "09"
  970. }
  971. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  972. if item.HisPrescriptionProject.Type == 2 {
  973. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  974. fmt.Println("CostClassify")
  975. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  976. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  977. case 0:
  978. item.MedChrgitmType = "0"
  979. break
  980. case 1:
  981. item.MedChrgitmType = "14"
  982. break
  983. case 2:
  984. item.MedChrgitmType = "05"
  985. break
  986. case 3:
  987. item.MedChrgitmType = "03"
  988. break
  989. case 4:
  990. item.MedChrgitmType = "03"
  991. break
  992. case 5:
  993. item.MedChrgitmType = "08"
  994. break
  995. case 6:
  996. item.MedChrgitmType = "14"
  997. break
  998. case 7:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 8:
  1002. item.MedChrgitmType = "03"
  1003. break
  1004. case 9:
  1005. item.MedChrgitmType = "14"
  1006. break
  1007. case 10:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. case 11:
  1011. item.MedChrgitmType = "06"
  1012. break
  1013. case 12:
  1014. item.MedChrgitmType = "12"
  1015. break
  1016. case 13:
  1017. item.MedChrgitmType = "01"
  1018. break
  1019. case 14:
  1020. item.MedChrgitmType = "04"
  1021. break
  1022. case 15:
  1023. item.MedChrgitmType = "14"
  1024. break
  1025. case 101:
  1026. item.MedChrgitmType = "04"
  1027. break
  1028. }
  1029. } else {
  1030. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1031. case 1:
  1032. item.MedChrgitmType = "14"
  1033. break
  1034. case 2:
  1035. item.MedChrgitmType = "05"
  1036. break
  1037. case 3:
  1038. item.MedChrgitmType = "04"
  1039. break
  1040. case 4:
  1041. item.MedChrgitmType = "14"
  1042. break
  1043. case 5:
  1044. item.MedChrgitmType = "08"
  1045. break
  1046. case 6:
  1047. item.MedChrgitmType = "14"
  1048. break
  1049. case 7:
  1050. item.MedChrgitmType = "14"
  1051. break
  1052. case 8:
  1053. item.MedChrgitmType = "03"
  1054. break
  1055. case 9:
  1056. item.MedChrgitmType = "14"
  1057. break
  1058. case 101:
  1059. item.MedChrgitmType = "04"
  1060. break
  1061. default:
  1062. item.MedChrgitmType = "14"
  1063. break
  1064. }
  1065. }
  1066. } else if item.HisPrescriptionProject.Type == 3 {
  1067. item.MedChrgitmType = "08"
  1068. }
  1069. }
  1070. }
  1071. }
  1072. if order.IsMedicineInsurance != 1 {
  1073. order.PsnCashPay = order.MedfeeSumamt
  1074. }
  1075. for _, item := range orderInfos {
  1076. if item.MedChrgitmType == "01" { //床位费
  1077. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1078. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1079. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1080. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1081. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1082. }
  1083. if item.MedChrgitmType == "02" { //诊察费
  1084. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1085. //zhenChaCostSelfTotal = zhenChaCostTotal
  1086. }
  1087. if item.MedChrgitmType == "03" { //检查费
  1088. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1089. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1090. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1091. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1092. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1093. }
  1094. if item.MedChrgitmType == "02" { //检查费
  1095. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1096. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1097. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1098. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1099. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1100. }
  1101. if item.MedChrgitmType == "04" { //化验费
  1102. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1103. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1104. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1105. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1106. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1107. }
  1108. if item.MedChrgitmType == "05" { //治疗费
  1109. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1110. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1111. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1112. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1113. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1114. }
  1115. if item.MedChrgitmType == "06" { //手术费
  1116. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1117. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1118. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1119. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1120. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1121. }
  1122. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1123. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1124. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1125. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1126. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1127. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1128. }
  1129. if item.MedChrgitmType == "09" { //西药费
  1130. fmt.Println("FulamtOwnpayAmt")
  1131. fmt.Println(item.FulamtOwnpayAmt)
  1132. fmt.Println("FulamtOwnpayAmt")
  1133. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1134. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1135. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1136. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1137. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1138. }
  1139. if item.MedChrgitmType == "11" { //中成费
  1140. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1141. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1142. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1143. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1144. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1145. }
  1146. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1147. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1148. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1149. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1150. }
  1151. if item.MedChrgitmType == "02" { //其他费
  1152. zcCostTotal, _ = decimal.NewFromFloat(zcCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1153. zcCostSelfTotal, _ = decimal.NewFromFloat(zcCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1154. zcCostPartSelfTotal, _ = decimal.NewFromFloat(zcCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1155. zcSelfTotal, _ = decimal.NewFromFloat(zcSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1156. zcInscpTotal, _ = decimal.NewFromFloat(zcInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1157. }
  1158. if item.MedChrgitmType == "07" { //其他费
  1159. huliCostTotal, _ = decimal.NewFromFloat(huliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1160. huliCostSelfTotal, _ = decimal.NewFromFloat(huliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1161. huliCostPartSelfTotal, _ = decimal.NewFromFloat(huliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1162. huliSelfTotal, _ = decimal.NewFromFloat(huliSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1163. huliInscpTotal, _ = decimal.NewFromFloat(huliInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1164. }
  1165. }
  1166. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1167. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1168. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1169. var dia_config []*models.HisXtDiagnoseConfig
  1170. var diagnosis_ids []string
  1171. if his.ID > 0 {
  1172. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1173. } else {
  1174. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1175. }
  1176. for _, item := range diagnosis_ids {
  1177. id, _ := strconv.ParseInt(item, 10, 64)
  1178. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1179. dia_config = append(dia_config, diagnosisConfig)
  1180. }
  1181. var rf []CustomFundPay
  1182. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1183. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "patient": patient,
  1186. "order_infos": orderInfos,
  1187. "diagnosis": name,
  1188. "bedCostTotal": bedCostTotal,
  1189. "bedCostSelfTotal": bedCostSelfTotal,
  1190. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1191. "bedSelfTotal": bedSelfTotal,
  1192. "bedInscpTotal": bedInscpTotal,
  1193. "operationCostTotal": operationCostTotal,
  1194. "operationCostSelfTotal": operationCostSelfTotal,
  1195. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1196. "operationInscpTotal": operationInscpTotal,
  1197. "operationSelfTotal": operationSelfTotal,
  1198. "otherCostTotal": otherCostTotal,
  1199. "otherCostSelfTotal": otherCostSelfTotal,
  1200. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1201. "materialCostTotal": materialCostTotal,
  1202. "materialCostSelfTotal": materialCostSelfTotal,
  1203. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1204. "materialSelfTotal": materialSelfTotal,
  1205. "materialInscpTotal": materialInscpTotal,
  1206. "westernMedicineCostTotal": westernMedicineCostTotal,
  1207. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1208. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1209. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1210. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1211. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1212. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1213. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1214. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1215. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1216. "checkCostTotal": checkCostTotal,
  1217. "checkCostSelfTotal": checkCostSelfTotal,
  1218. "checkSelfTotal": checkSelfTotal,
  1219. "checkInscpTotal": checkInscpTotal,
  1220. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1221. "zhenChaCostTotal": zhenChaCostTotal,
  1222. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1223. "laboratoryCostTotal": laboratoryCostTotal,
  1224. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1225. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1226. "laboratorySelfTotal": laboratorySelfTotal,
  1227. "laboratoryInscpTotal": laboratoryInscpTotal,
  1228. "treatCostTotal": treatCostTotal,
  1229. "treatCostSelfTotal": treatCostSelfTotal,
  1230. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1231. "treatSelfTotal": treatSelfTotal,
  1232. "treatInscpTotal": treatInscpTotal,
  1233. "charge_admin": charge_admin,
  1234. "printor_admin": printor_admin,
  1235. "org_name": org.OrgName,
  1236. "org_code": miConfig.Code,
  1237. "name": patient.Name,
  1238. "number": order.MdtrtId,
  1239. "date": order.SettleAccountsDate,
  1240. "info": order,
  1241. "new_order": order,
  1242. "his_hospital": his_hospital,
  1243. "his": his,
  1244. "funds": rf,
  1245. "dia_config": dia_config,
  1246. "huliCostTotal": huliCostTotal,
  1247. "huliCostSelfTotal": huliCostSelfTotal,
  1248. "huliCostPartSelfTotal": huliCostPartSelfTotal,
  1249. "huliSelfTotal": huliSelfTotal,
  1250. "huliInscpTotal": huliInscpTotal,
  1251. "zcCostTotal": zcCostTotal,
  1252. "zcCostSelfTotal": zcCostSelfTotal,
  1253. "zcCostPartSelfTotal": zcCostPartSelfTotal,
  1254. "zcSelfTotal": zcSelfTotal,
  1255. "zcInscpTotal": zcInscpTotal,
  1256. })
  1257. }
  1258. func (c *HisApiController) RefudDetail() {
  1259. order_id, _ := c.GetInt64("order_id")
  1260. order, _ := service.GetHisOrderByID(order_id)
  1261. adminUser := c.GetAdminUserInfo()
  1262. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1263. c.ServeSuccessJSON(map[string]interface{}{
  1264. "msg": "撤销成功",
  1265. })
  1266. }
  1267. func (c *HisApiController) Sscard() {
  1268. //r := CardInit()
  1269. //if r == 0 {
  1270. // GetBaseInfo()
  1271. //}
  1272. //c.ServeSuccessJSON(map[string]interface{}{
  1273. // "list": "11",
  1274. //})
  1275. }
  1276. func GetBaseInfo() error {
  1277. //handle := syscall.MustLoadDLL("SSCard.dll")
  1278. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1279. //
  1280. //str := make([]byte, 256)
  1281. //str1 := make([]byte, 256)
  1282. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1283. //if ferr != nil {
  1284. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1285. // return ferr
  1286. //}
  1287. //
  1288. //fmt.Println(string(str))
  1289. //
  1290. //fmt.Println(r)
  1291. return nil
  1292. }
  1293. func CardInit() int {
  1294. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1295. //add := DllTestDef.MustFindProc("Init")
  1296. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1297. //if err != nil {
  1298. // fmt.Println("SSCard的运算结果为:", ret)
  1299. //}
  1300. //result := int(ret)
  1301. return 0
  1302. }
  1303. func IntPtr(n int) uintptr {
  1304. return uintptr(n)
  1305. }
  1306. func StrPtr(s string) uintptr {
  1307. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1308. }
  1309. func (c *HisApiController) GetHisPatientList() {
  1310. record_date := c.GetString("record_date")
  1311. sch_type, _ := c.GetInt64("sch_type")
  1312. patient_type, _ := c.GetInt64("patient_type")
  1313. fmt.Println("patient_type")
  1314. fmt.Println(patient_type)
  1315. timeLayout := "2006-01-02"
  1316. loc, _ := time.LoadLocation("Local")
  1317. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1318. if err != nil {
  1319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1320. return
  1321. }
  1322. recordDateTime := theTime.Unix()
  1323. adminInfo := c.GetAdminUserInfo()
  1324. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1325. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1326. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1327. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1328. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1329. fmt.Println(patients_three)
  1330. //获取当前用户的信息
  1331. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1332. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1333. //获取所有科室信息
  1334. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1335. //var aa []service.PatientThree
  1336. noElementsSlice := make([]service.PatientThree, 0)
  1337. c.ServeSuccessJSON(map[string]interface{}{
  1338. "list": patients_three,
  1339. "list_two": patients_four,
  1340. "list_three": noElementsSlice,
  1341. "info": adminUserInfo,
  1342. "doctors": doctors,
  1343. "department": department,
  1344. })
  1345. } else {
  1346. //获取当前用户的信息
  1347. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1348. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1349. //获取所有科室信息
  1350. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1351. //var aa []service.PatientThree
  1352. noElementsSlice := make([]service.PatientThree, 0)
  1353. c.ServeSuccessJSON(map[string]interface{}{
  1354. "list": patients,
  1355. "list_two": patients_two,
  1356. "list_three": noElementsSlice,
  1357. "info": adminUserInfo,
  1358. "doctors": doctors,
  1359. "department": department,
  1360. })
  1361. }
  1362. }
  1363. type CustomTemplate struct {
  1364. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1365. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1366. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1367. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1368. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1369. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1370. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1371. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1372. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1373. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1374. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1375. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1376. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1377. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1378. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1379. }
  1380. func (c *HisApiController) GetHisPatientInfo() {
  1381. patient_id, _ := c.GetInt64("patient_id")
  1382. his_patient_id, _ := c.GetInt64("his_patient_id")
  1383. record_date := c.GetString("record_date")
  1384. number := c.GetString("number")
  1385. //start_time := c.GetString("start_time")
  1386. //end_time := c.GetString("end_time")
  1387. p_type, _ := c.GetInt64("p_type")
  1388. timeLayout := "2006-01-02"
  1389. loc, _ := time.LoadLocation("Local")
  1390. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1391. if err != nil {
  1392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1393. return
  1394. }
  1395. recordDateTime := theTime.Unix()
  1396. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1397. //if err != nil {
  1398. //
  1399. //}
  1400. //startRecordDateTime := startTime.Unix()
  1401. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1402. //if err != nil {
  1403. //
  1404. //}
  1405. //endRecordDateTime := endTime.Unix()
  1406. admin := c.GetAdminUserInfo()
  1407. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1408. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1409. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1410. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1411. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1412. var prescriptions []*models.HisPrescription
  1413. var last_prescriptions []*models.HisPrescription
  1414. var sch_prescriptions []CustomTemplate
  1415. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1416. if p_type == 1 { //住院
  1417. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1418. for _, item := range prescriptions {
  1419. for _, subItem := range item.HisDoctorAdviceInfo {
  1420. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1421. if info.RetailPrice > 0 {
  1422. subItem.Drug.MinPrice = info.RetailPrice
  1423. }
  1424. }
  1425. }
  1426. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1427. } else { //门诊
  1428. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1429. for _, item := range prescriptions {
  1430. for _, subItem := range item.HisDoctorAdviceInfo {
  1431. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1432. if info.RetailPrice > 0 {
  1433. subItem.Drug.MinPrice = info.RetailPrice
  1434. }
  1435. }
  1436. }
  1437. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1438. }
  1439. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1440. if sch.ID > 0 {
  1441. var week string
  1442. t := theTime
  1443. switch t.Weekday().String() {
  1444. case "Monday":
  1445. week = "周一"
  1446. break
  1447. case "Tuesday":
  1448. week = "周二"
  1449. break
  1450. case "Wednesday":
  1451. week = "周三"
  1452. break
  1453. case "Thursday":
  1454. week = "周四"
  1455. break
  1456. case "Friday":
  1457. week = "周五"
  1458. break
  1459. case "Saturday":
  1460. week = "周六"
  1461. break
  1462. case "Sunday":
  1463. week = "周日"
  1464. break
  1465. }
  1466. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1467. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1468. //根据推送频率组装新的数组
  1469. for _, item := range temp_sch_prescriptions {
  1470. var cus CustomTemplate
  1471. cus.ID = item.ID
  1472. cus.UserOrgId = item.UserOrgId
  1473. cus.PatientId = item.PatientId
  1474. cus.MedType = item.MedType
  1475. cus.RecordDate = item.RecordDate
  1476. cus.Type = item.Type
  1477. cus.PType = item.PType
  1478. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1479. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1480. if subItem.FrequencyType == 1 { //每次必推
  1481. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1482. }
  1483. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1484. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1485. }
  1486. if subItem.FrequencyType == 2 { //按照天数频率
  1487. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1488. now := p.Unix()
  1489. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1490. dayStr2 := "-" + dayStr
  1491. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1492. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1493. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1494. if len(advices) == 0 {
  1495. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1496. }
  1497. }
  1498. }
  1499. }
  1500. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1501. if subItem.Type == 2 {
  1502. if subItem.XtHisProject.MedicalStatus != 1 {
  1503. if subItem.FrequencyType == 1 {
  1504. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1505. }
  1506. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1507. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1508. }
  1509. if subItem.FrequencyType == 2 {
  1510. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1511. now := p.Unix()
  1512. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1513. dayStr2 := "-" + dayStr
  1514. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1515. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1516. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1517. if len(projects) == 0 {
  1518. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1519. }
  1520. }
  1521. }
  1522. } else if subItem.Type == 3 {
  1523. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1524. if subItem.FrequencyType == 1 {
  1525. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1526. }
  1527. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1528. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1529. }
  1530. if subItem.FrequencyType == 2 {
  1531. p, _ := time.Parse("2006-01-02", theTime.Format("2006-01-02"))
  1532. now := p.Unix()
  1533. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1534. dayStr2 := "-" + dayStr
  1535. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1536. oldTime := theTime.AddDate(0, 0, int(count)).Unix()
  1537. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1538. if len(projects) == 0 {
  1539. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. sch_prescriptions = append(sch_prescriptions, cus)
  1546. }
  1547. for _, item := range sch_prescriptions {
  1548. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1549. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1550. }
  1551. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1552. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1553. }
  1554. }
  1555. }
  1556. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1557. if config.ID > 0 && config.IsOpen == 1 {
  1558. for _, item := range sch_prescriptions {
  1559. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1560. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1561. if info.RetailPrice > 0 {
  1562. subItem.Drug.MinPrice = info.RetailPrice
  1563. if admin.CurrentOrgId != 10598 {
  1564. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1565. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1566. }
  1567. }
  1568. }
  1569. }
  1570. }
  1571. if config.ID > 0 && config.IsOpen == 1 {
  1572. for _, item := range sch_prescriptions {
  1573. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1574. if subItem.Type == 3 {
  1575. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1576. if info.Price > 0 {
  1577. subItem.GoodInfo.PackingPrice = info.Price
  1578. if admin.CurrentOrgId != 10598 {
  1579. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1580. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1581. }
  1582. }
  1583. }
  1584. }
  1585. }
  1586. }
  1587. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1588. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1589. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1590. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1591. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1592. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1593. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1594. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1595. //获取所有科室信息
  1596. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1597. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1598. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1599. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1600. fmt.Println(prescriptions)
  1601. fmt.Println(sch_prescriptions)
  1602. fmt.Println(last_prescriptions)
  1603. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1604. if len(sch_prescriptions) > 0 {
  1605. var index = 0
  1606. for subindex, item := range sch_prescriptions {
  1607. if item.Type == 2 {
  1608. index = subindex
  1609. }
  1610. }
  1611. fmt.Println(index)
  1612. fmt.Println(len(sch_prescriptions))
  1613. if index >= 0 && index < len(sch_prescriptions) {
  1614. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1615. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1616. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1617. if one.ID > 0 {
  1618. var hpt models.HisPrescriptionProjectTemplate
  1619. hpt.Type = 3
  1620. hpt.ID = 0
  1621. hpt.PatientId = sch_prescriptions[index].PatientId
  1622. hpt.Status = 1
  1623. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1624. hpt.Mtime = time.Now().Unix()
  1625. hpt.Ctime = time.Now().Unix()
  1626. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1627. hpt.Count = "1"
  1628. hpt.Price = one.RetailPrice
  1629. hpt.ProjectId = one.ID
  1630. hpt.FeedetlSn = ""
  1631. hpt.PrescriptionId = sch_prescriptions[index].ID
  1632. hpt.Unit = one.PackingUnit
  1633. hpt.Day = "1"
  1634. hpt.SingleDose = "1"
  1635. hpt.GoodInfo = one
  1636. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1637. }
  1638. if two.ID > 0 {
  1639. var hpt models.HisPrescriptionProjectTemplate
  1640. hpt.Type = 3
  1641. hpt.ID = 0
  1642. hpt.PatientId = sch_prescriptions[index].PatientId
  1643. hpt.Status = 1
  1644. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1645. hpt.Mtime = time.Now().Unix()
  1646. hpt.Ctime = time.Now().Unix()
  1647. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1648. hpt.Count = "1"
  1649. hpt.Price = two.RetailPrice
  1650. hpt.ProjectId = two.ID
  1651. hpt.FeedetlSn = ""
  1652. hpt.PrescriptionId = sch_prescriptions[index].ID
  1653. hpt.Unit = two.PackingUnit
  1654. hpt.Day = "1"
  1655. hpt.SingleDose = "1"
  1656. hpt.GoodInfo = two
  1657. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1658. }
  1659. //if three.ID > 0 {
  1660. // var hpt models.HisPrescriptionProjectTemplate
  1661. // hpt.Type = 3
  1662. // hpt.ID = 0
  1663. // hpt.PatientId = sch_prescriptions[index].PatientId
  1664. // hpt.Status = 1
  1665. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1666. // hpt.Mtime = time.Now().Unix()
  1667. // hpt.Ctime = time.Now().Unix()
  1668. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1669. // hpt.Count = "1"
  1670. // hpt.Price = three.RetailPrice
  1671. // hpt.ProjectId = three.ID
  1672. // hpt.FeedetlSn = ""
  1673. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1674. // hpt.Unit = three.PackingUnit
  1675. // hpt.Day = "1"
  1676. // hpt.SingleDose = "1"
  1677. // hpt.GoodInfo = three
  1678. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1679. //}
  1680. fmt.Println(sch_prescriptions)
  1681. }
  1682. } else {
  1683. if len(last_prescriptions) > 0 {
  1684. var index = 0
  1685. for subindex, item := range last_prescriptions {
  1686. if item.Type == 2 {
  1687. index = subindex
  1688. }
  1689. }
  1690. if index >= 0 && index < len(last_prescriptions) {
  1691. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1692. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1693. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1694. if one.ID > 0 {
  1695. var hpt models.HisPrescriptionProject
  1696. hpt.Type = 3
  1697. hpt.ID = 0
  1698. hpt.PatientId = last_prescriptions[index].PatientId
  1699. hpt.Status = 1
  1700. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1701. hpt.Mtime = time.Now().Unix()
  1702. hpt.Ctime = time.Now().Unix()
  1703. hpt.RecordDate = last_prescriptions[index].RecordDate
  1704. hpt.Count = "1"
  1705. hpt.Price = one.RetailPrice
  1706. hpt.ProjectId = one.ID
  1707. hpt.FeedetlSn = ""
  1708. hpt.PrescriptionId = last_prescriptions[index].ID
  1709. hpt.Unit = one.PackingUnit
  1710. hpt.Day = "1"
  1711. hpt.SingleDose = "1"
  1712. hpt.GoodInfo = one
  1713. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1714. }
  1715. if two.ID > 0 {
  1716. var hpt models.HisPrescriptionProject
  1717. hpt.Type = 3
  1718. hpt.ID = 0
  1719. hpt.PatientId = last_prescriptions[index].PatientId
  1720. hpt.Status = 1
  1721. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1722. hpt.Mtime = time.Now().Unix()
  1723. hpt.Ctime = time.Now().Unix()
  1724. hpt.RecordDate = last_prescriptions[index].RecordDate
  1725. hpt.Count = "1"
  1726. hpt.Price = two.RetailPrice
  1727. hpt.ProjectId = two.ID
  1728. hpt.FeedetlSn = ""
  1729. hpt.PrescriptionId = last_prescriptions[index].ID
  1730. hpt.Unit = two.PackingUnit
  1731. hpt.Day = "1"
  1732. hpt.SingleDose = "1"
  1733. hpt.GoodInfo = two
  1734. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1735. }
  1736. //if three.ID > 0 {
  1737. // var hpt models.HisPrescriptionProject
  1738. // hpt.Type = 3
  1739. // hpt.ID = 0
  1740. // hpt.PatientId = last_prescriptions[index].PatientId
  1741. // hpt.Status = 1
  1742. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1743. // hpt.Mtime = time.Now().Unix()
  1744. // hpt.Ctime = time.Now().Unix()
  1745. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1746. // hpt.Count = "1"
  1747. // hpt.Price = three.RetailPrice
  1748. // hpt.ProjectId = three.ID
  1749. // hpt.FeedetlSn = ""
  1750. // hpt.PrescriptionId = last_prescriptions[index].ID
  1751. // hpt.Unit = three.PackingUnit
  1752. // hpt.Day = "1"
  1753. // hpt.SingleDose = "1"
  1754. // hpt.GoodInfo = three
  1755. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1756. //}
  1757. }
  1758. }
  1759. }
  1760. }
  1761. c.ServeSuccessJSON(map[string]interface{}{
  1762. "his_info": his_patient_info,
  1763. "xt_info": xt_patient_info,
  1764. "prescription": prescriptions,
  1765. "case_history": case_history,
  1766. "info": patientPrescriptionInfo,
  1767. //"month_prescriptions": monthPrescriptions,
  1768. "order": order,
  1769. "doctors": doctors,
  1770. "department": department,
  1771. "sch_prescriptions": sch_prescriptions,
  1772. "last_prescriptions": last_prescriptions,
  1773. "schedule": sch,
  1774. "count": count,
  1775. "drugStockConfig": drugStockConfig,
  1776. "last_info": lastPatientPrescriptionInfo,
  1777. "befor": beforThrity,
  1778. "LastCaseHistory": LastCaseHistory,
  1779. "prescriptionInfo": prescriptionInfo,
  1780. })
  1781. return
  1782. }
  1783. func (c *HisApiController) GetHisPrescriptionConfig() {
  1784. adminInfo := c.GetAdminUserInfo()
  1785. //获取医嘱模版
  1786. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1787. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1788. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1789. //获取所有基础药
  1790. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1791. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1792. if config.ID > 0 && config.IsOpen == 1 {
  1793. for _, item := range drugs {
  1794. var index = 0
  1795. for _, subItem := range item.OtherDrugWarehouseInfo {
  1796. if index == 0 {
  1797. index = index + 1
  1798. if subItem.RetailPrice > 0 {
  1799. item.MinPrice = subItem.RetailPrice
  1800. }
  1801. }
  1802. }
  1803. }
  1804. }
  1805. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1806. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1807. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1808. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1809. //获取所有科室信息
  1810. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1811. //获取诊断信息
  1812. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1813. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1814. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1815. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1816. //获取是否开启保存耗材出库的开关
  1817. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1818. c.ServeSuccessJSON(map[string]interface{}{
  1819. "drugs": drugs,
  1820. "advices_template": advices,
  1821. "drugways": drugways,
  1822. "efs": efs,
  1823. "doctors": doctors,
  1824. "department": department,
  1825. "sick": sick,
  1826. "additions": additions,
  1827. "diagnose": diagnose,
  1828. "manufacturers": manufacturers,
  1829. "goodOutOpen": goodOutOpen,
  1830. "patientDiagnose": patientDiagnose,
  1831. })
  1832. }
  1833. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1834. //获取所有基础药
  1835. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1836. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1837. if config.ID > 0 && config.IsOpen == 1 {
  1838. for _, item := range drugs {
  1839. var index = 0
  1840. for _, subItem := range item.OtherDrugWarehouseInfo {
  1841. if index == 0 {
  1842. index = index + 1
  1843. if subItem.RetailPrice > 0 {
  1844. item.MinPrice = subItem.RetailPrice
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1851. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1852. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1853. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1854. //获取所有科室信息
  1855. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1856. //获取诊断信息
  1857. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1858. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1859. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1860. //获取是否开启保存耗材出库的开关
  1861. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1862. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1863. c.ServeSuccessJSON(map[string]interface{}{
  1864. "drugs": drugs,
  1865. "advices_template": advices,
  1866. "drugways": drugways,
  1867. "efs": efs,
  1868. "doctors": doctors,
  1869. "department": department,
  1870. "sick": sick,
  1871. "additions": additions,
  1872. "diagnose": diagnose,
  1873. "manufacturers": manufacturers,
  1874. "goodOutOpen": goodOutOpen,
  1875. "patientDiagnose": patientDiagnose,
  1876. })
  1877. }
  1878. }
  1879. func (c *HisApiController) CreateHisPrescription() {
  1880. record_date := c.GetString("record_date")
  1881. patient_id, _ := c.GetInt64("patient_id")
  1882. reg_type, _ := c.GetInt64("reg_type")
  1883. diagnose := c.GetString("diagnose")
  1884. sick_type, _ := c.GetInt64("sick_type")
  1885. sick_history := c.GetString("sick_history")
  1886. doctor_id, _ := c.GetInt64("doctor", 0)
  1887. department, _ := c.GetInt64("department", 0)
  1888. his_patient_id, _ := c.GetInt64("his_patient_id")
  1889. p_type, _ := c.GetInt64("p_type")
  1890. patient_diagnose := c.GetString("patient_diagnose")
  1891. dataBody := make(map[string]interface{}, 0)
  1892. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1893. if err != nil {
  1894. utils.ErrorLog(err.Error())
  1895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1896. return
  1897. }
  1898. //edit, src := GetCompareData(dataBody)
  1899. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1900. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1901. //fmt.Println(drugResult)
  1902. //fmt.Println(goodResult)
  1903. timeLayout := "2006-01-02"
  1904. loc, _ := time.LoadLocation("Local")
  1905. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1906. if err != nil {
  1907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1908. return
  1909. }
  1910. adminInfo := c.GetAdminUserInfo()
  1911. recordDateTime := theTime.Unix()
  1912. //查询默认出库仓库库存
  1913. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1914. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1915. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1916. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1917. if len(lists) == 1 {
  1918. his_patient_id = lists[0].ID
  1919. }
  1920. }
  1921. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1922. //自动出库的开关开启
  1923. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1924. //自动出库
  1925. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1926. //耗材保存处方出库
  1927. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1928. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1929. //已发药和已收费限制逻辑
  1930. isMidicine := false
  1931. isCharge := false
  1932. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1933. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1934. if len(prescriptions) > 0 {
  1935. for _, item := range prescriptions {
  1936. items := item.(map[string]interface{})
  1937. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1938. utils.ErrorLog("id")
  1939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1940. return
  1941. }
  1942. id := int64(items["id"].(float64))
  1943. if id > 0 {
  1944. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1945. if err != nil {
  1946. if new_prescription.OrderStatus == 4 {
  1947. isCharge = true
  1948. }
  1949. }
  1950. }
  1951. }
  1952. }
  1953. }
  1954. if isMidicine == true {
  1955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1956. return
  1957. }
  1958. if isCharge == true {
  1959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1960. return
  1961. }
  1962. // 开始主事务
  1963. db := service.XTWriteDB()
  1964. tx := db.Begin()
  1965. // 在函数结束时处理事务回滚
  1966. defer func() {
  1967. if r := recover(); r != nil {
  1968. tx.Rollback()
  1969. }
  1970. }()
  1971. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1972. //药品发药出库
  1973. if pharmacyConfig.IsOpen == 1 {
  1974. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1975. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1976. if len(prescriptions) > 0 {
  1977. for _, item := range prescriptions {
  1978. items := item.(map[string]interface{})
  1979. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1980. advices := items["advices"].([]interface{})
  1981. if len(advices) > 0 {
  1982. for _, advice := range advices {
  1983. var drug_id int64
  1984. var prescribing_number float64
  1985. var prescribingNumberUnit string
  1986. var adviceId int64
  1987. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1988. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1989. }
  1990. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1991. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1992. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1993. }
  1994. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1995. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1996. }
  1997. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1998. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1999. }
  2000. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2001. if drug.ID == 0 {
  2002. tx.Rollback()
  2003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2004. return
  2005. }
  2006. //查询药品的所有库存
  2007. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2008. var total_count int64
  2009. for _, it := range list {
  2010. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2011. }
  2012. totals := strconv.FormatInt(total_count, 10)
  2013. //查询该药品是否存在开药记录
  2014. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2015. //新增处方盘点库存是否充足
  2016. if advicelist.ID == 0 {
  2017. all_count, _ := strconv.ParseFloat(totals, 64)
  2018. if prescribingNumberUnit == drug.MinUnit {
  2019. if drug.IsUse != 1 {
  2020. if drug.IsProject == 0 || drug.IsProject == 2 {
  2021. if all_count == 0 {
  2022. tx.Rollback()
  2023. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2024. return
  2025. }
  2026. if prescribing_number > all_count {
  2027. tx.Rollback()
  2028. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2029. return
  2030. }
  2031. }
  2032. }
  2033. }
  2034. if prescribingNumberUnit == drug.MaxUnit {
  2035. num := prescribing_number * float64(drug.MinNumber)
  2036. if drug.IsUse != 1 {
  2037. if drug.IsProject == 0 || drug.IsProject == 2 {
  2038. if all_count == 0 {
  2039. tx.Rollback()
  2040. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2041. return
  2042. }
  2043. if num > all_count {
  2044. tx.Rollback()
  2045. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2046. return
  2047. }
  2048. }
  2049. }
  2050. }
  2051. }
  2052. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2053. //不使用保存处方出库
  2054. if drugOutConfig.IsOpen != 1 {
  2055. //修改处方
  2056. for _, advice := range advices {
  2057. var drug_id int64
  2058. var prescribing_number float64
  2059. var prescribingNumberUnit string
  2060. var prescribingNumber string
  2061. var adviceId int64
  2062. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2063. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2064. }
  2065. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2066. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2067. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2068. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2069. }
  2070. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2071. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2072. }
  2073. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2074. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2075. }
  2076. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2077. if drug.ID == 0 {
  2078. tx.Rollback()
  2079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2080. return
  2081. }
  2082. //查询药品的所有库存
  2083. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2084. var total_count int64
  2085. for _, it := range list {
  2086. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2087. }
  2088. totals := strconv.FormatInt(total_count, 10)
  2089. //查询该药品是否存在开药记录
  2090. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2091. //新增处方
  2092. if advicelist.ID == 0 {
  2093. all_count, _ := strconv.ParseFloat(totals, 64)
  2094. if prescribingNumberUnit == drug.MinUnit {
  2095. if drug.IsUse != 1 {
  2096. if drug.IsProject == 0 || drug.IsProject == 2 {
  2097. if all_count == 0 {
  2098. tx.Rollback()
  2099. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2100. return
  2101. }
  2102. if prescribing_number > all_count {
  2103. tx.Rollback()
  2104. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2105. return
  2106. }
  2107. }
  2108. }
  2109. } else {
  2110. if prescribingNumberUnit == drug.MaxUnit {
  2111. num := prescribing_number * float64(drug.MinNumber)
  2112. if drug.IsUse != 1 {
  2113. if drug.IsProject == 0 || drug.IsProject == 2 {
  2114. if all_count == 0 {
  2115. tx.Rollback()
  2116. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2117. return
  2118. }
  2119. if num > all_count {
  2120. tx.Rollback()
  2121. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2122. return
  2123. }
  2124. }
  2125. }
  2126. }
  2127. }
  2128. }
  2129. //修改处方
  2130. if advicelist.ID > 0 {
  2131. var device_number int64
  2132. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2133. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2134. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2135. device_number = prescribingNumberInt * drug.MinNumber
  2136. }
  2137. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2138. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2139. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2140. device_number = prescribingNumberInt
  2141. }
  2142. var number_count int64
  2143. if prescribingNumberUnit == drug.MaxUnit {
  2144. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2145. number_count = prescribingNumberInt * drug.MinNumber
  2146. }
  2147. if prescribingNumberUnit == drug.MinUnit {
  2148. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2149. number_count = prescribingNumberInt
  2150. }
  2151. //如果修改的数量大于之前修改的数量
  2152. if (number_count - device_number) > 0 {
  2153. //如果修改的差数量 大于库存数量
  2154. if drug.IsUse != 1 {
  2155. if (number_count - device_number) > total_count {
  2156. tx.Rollback()
  2157. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2158. return
  2159. }
  2160. }
  2161. }
  2162. }
  2163. }
  2164. }
  2165. }
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. }
  2172. //已发药和已收费限制逻辑
  2173. //执行出库的逻辑
  2174. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2175. //校验库存总量
  2176. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2177. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2178. if len(prescriptions) > 0 {
  2179. for _, item := range prescriptions {
  2180. items := item.(map[string]interface{})
  2181. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2182. advices := items["advices"].([]interface{})
  2183. if len(advices) > 0 {
  2184. for _, advice := range advices {
  2185. var drug_id int64
  2186. var prescribing_number float64
  2187. var prescribingNumberUnit string
  2188. var adviceId int64
  2189. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2190. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2191. }
  2192. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2193. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2194. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2195. }
  2196. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2197. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2198. }
  2199. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2200. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2201. }
  2202. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2203. if drug.ID == 0 {
  2204. tx.Rollback()
  2205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2206. return
  2207. }
  2208. //查询药品的所有库存
  2209. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2210. var total_count int64
  2211. for _, it := range list {
  2212. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2213. }
  2214. totals := strconv.FormatInt(total_count, 10)
  2215. //查询该药品是否存在开药记录
  2216. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2217. //查询最新批次库存
  2218. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2219. var batch_number_count int64
  2220. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2221. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2222. //新增处方
  2223. if advicelist.ID == 0 {
  2224. all_count, _ := strconv.ParseFloat(totals, 64)
  2225. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2226. if prescribingNumberUnit == drug.MinUnit {
  2227. if drug.IsUse != 1 {
  2228. if drug.IsProject == 0 || drug.IsProject == 2 {
  2229. if all_count == 0 {
  2230. tx.Rollback()
  2231. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2232. return
  2233. }
  2234. if prescribing_number > all_count {
  2235. tx.Rollback()
  2236. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2237. return
  2238. }
  2239. }
  2240. if adminInfo.CurrentOrgId == 10215 {
  2241. if prescribing_number > batch_number_all_count {
  2242. tx.Rollback()
  2243. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2244. return
  2245. }
  2246. }
  2247. }
  2248. }
  2249. if prescribingNumberUnit == drug.MaxUnit {
  2250. num := prescribing_number * float64(drug.MinNumber)
  2251. if drug.IsUse != 1 {
  2252. if drug.IsProject == 0 || drug.IsProject == 2 {
  2253. if all_count == 0 {
  2254. tx.Rollback()
  2255. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2256. return
  2257. }
  2258. if num > all_count {
  2259. tx.Rollback()
  2260. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2261. return
  2262. }
  2263. }
  2264. if adminInfo.CurrentOrgId == 10215 {
  2265. if num > batch_number_all_count {
  2266. tx.Rollback()
  2267. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2268. return
  2269. }
  2270. }
  2271. }
  2272. }
  2273. }
  2274. //不是保存处方出库
  2275. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2276. if drugOutConfig.IsOpen != 1 {
  2277. //修改处方
  2278. for _, advice := range advices {
  2279. var drug_id int64
  2280. var prescribing_number float64
  2281. var prescribingNumberUnit string
  2282. var prescribingNumber string
  2283. var adviceId int64
  2284. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2285. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2286. }
  2287. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2288. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2289. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2290. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2291. }
  2292. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2293. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2294. }
  2295. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2296. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2297. }
  2298. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2299. if drug.ID == 0 {
  2300. tx.Rollback()
  2301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2302. return
  2303. }
  2304. //查询药品的所有库存
  2305. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2306. var total_count int64
  2307. for _, it := range list {
  2308. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2309. }
  2310. totals := strconv.FormatInt(total_count, 10)
  2311. //查询该药品是否存在开药记录
  2312. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2313. //新增处方
  2314. if advicelist.ID == 0 {
  2315. //查询最新批次库存
  2316. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2317. var batch_number_count int64
  2318. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2319. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2320. all_count, _ := strconv.ParseFloat(totals, 64)
  2321. if all_count == 0 {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2324. return
  2325. }
  2326. if prescribingNumberUnit == drug.MinUnit {
  2327. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2328. if drug.IsUse != 1 {
  2329. if drug.IsProject == 0 || drug.IsProject == 2 {
  2330. if all_count == 0 {
  2331. tx.Rollback()
  2332. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2333. return
  2334. }
  2335. if prescribing_number > all_count {
  2336. tx.Rollback()
  2337. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2338. return
  2339. }
  2340. }
  2341. if adminInfo.CurrentOrgId == 10215 {
  2342. if prescribing_number > batch_number_all_count {
  2343. tx.Rollback()
  2344. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2345. return
  2346. }
  2347. }
  2348. }
  2349. } else {
  2350. if prescribingNumberUnit == drug.MaxUnit {
  2351. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2352. num := prescribing_number * float64(drug.MinNumber)
  2353. if drug.IsUse != 1 {
  2354. if drug.IsProject == 0 || drug.IsProject == 2 {
  2355. if all_count == 0 {
  2356. tx.Rollback()
  2357. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2358. return
  2359. }
  2360. if num > all_count {
  2361. tx.Rollback()
  2362. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2363. return
  2364. }
  2365. }
  2366. if adminInfo.CurrentOrgId == 10215 {
  2367. if prescribing_number > batch_number_all_count {
  2368. tx.Rollback()
  2369. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2370. return
  2371. }
  2372. }
  2373. }
  2374. }
  2375. }
  2376. }
  2377. //修改处方
  2378. if advicelist.ID > 0 {
  2379. //查询最新批次库存
  2380. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2381. var batch_number_count int64
  2382. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2383. var device_number int64
  2384. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2385. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2386. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2387. device_number = prescribingNumberInt * drug.MinNumber
  2388. }
  2389. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2390. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2391. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2392. device_number = prescribingNumberInt
  2393. //回退库存
  2394. }
  2395. var number_count int64
  2396. if prescribingNumberUnit == drug.MaxUnit {
  2397. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2398. number_count = prescribingNumberInt * drug.MinNumber
  2399. //回退库存
  2400. }
  2401. if prescribingNumberUnit == drug.MinUnit {
  2402. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2403. number_count = prescribingNumberInt
  2404. //回退库存
  2405. }
  2406. //如果修改的数量大于之前修改的数量
  2407. if (number_count - device_number) > 0 {
  2408. //如果修改的差数量 大于库存数量
  2409. if drug.IsUse != 1 {
  2410. if drug.IsProject == 0 || drug.IsProject == 2 {
  2411. if total_count == 0 {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2414. return
  2415. }
  2416. if (number_count - device_number) > total_count {
  2417. tx.Rollback()
  2418. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2419. return
  2420. }
  2421. if (number_count - device_number) > batch_number_count {
  2422. tx.Rollback()
  2423. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2424. return
  2425. }
  2426. }
  2427. if adminInfo.CurrentOrgId == 10215 {
  2428. // 查询该药品最后一次出库记录
  2429. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2430. var out_count int64
  2431. var in_count int64
  2432. var stock_max_number int64
  2433. var stock_min_number int64
  2434. for _, it := range outInfo {
  2435. if it.CountUnit == drug.MaxUnit {
  2436. it.Count = it.Count * drug.MinNumber
  2437. }
  2438. out_count += it.Count
  2439. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2440. stock_max_number = warehouseInfoList.StockMaxNumber
  2441. stock_min_number = warehouseInfoList.StockMinNumber
  2442. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2443. }
  2444. if out_count > 0 {
  2445. if (number_count - device_number) > in_count {
  2446. tx.Rollback()
  2447. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2448. return
  2449. }
  2450. }
  2451. // 未出库
  2452. if out_count == 0 {
  2453. var sum_in_count int64
  2454. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2455. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2456. //如果修改的数量大于有库存的第一个批次
  2457. if number_count > sum_in_count {
  2458. tx.Rollback()
  2459. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2460. return
  2461. }
  2462. }
  2463. }
  2464. }
  2465. }
  2466. //药品发药
  2467. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2468. //不使用药品发药的功能
  2469. //if pharmacyConfig.IsOpen != 1 {
  2470. // if device_number != number_count {
  2471. //
  2472. // //查询该药品的出库记录
  2473. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2474. // if len(outListExport) > 0 {
  2475. // //
  2476. // for _, item := range outListExport {
  2477. // //回退库存
  2478. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2479. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2480. // }
  2481. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2482. // var stock_max_number int64
  2483. // var stock_min_number int64
  2484. //
  2485. // if number_count >= drug.MinNumber {
  2486. //
  2487. // stock_max_number = device_number / drug.MinNumber
  2488. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2489. //
  2490. // stock_min_number = device_number % drug.MinNumber
  2491. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2492. //
  2493. // } else {
  2494. //
  2495. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2496. //
  2497. // }
  2498. // }
  2499. //
  2500. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2501. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2502. // }
  2503. // }
  2504. // }
  2505. //
  2506. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2507. // var sum_count int64
  2508. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2509. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2510. // for _, its := range stockInfo {
  2511. // if its.MaxUnit == drug.MaxUnit {
  2512. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2513. // }
  2514. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2515. // }
  2516. // //更新字典里面的库存
  2517. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2518. //
  2519. // //剩余库存
  2520. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2521. //
  2522. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2523. // //减少出库数量
  2524. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2525. //
  2526. // }
  2527. //}
  2528. }
  2529. }
  2530. }
  2531. //保存处方开药
  2532. if drugOutConfig.IsOpen == 1 {
  2533. //修改处方
  2534. for _, advice := range advices {
  2535. var drug_id int64
  2536. var prescribing_number float64
  2537. var prescribingNumberUnit string
  2538. var prescribingNumber string
  2539. var adviceId int64
  2540. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2541. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2542. }
  2543. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2544. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2545. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2546. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2547. }
  2548. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2549. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2550. }
  2551. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2552. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2553. }
  2554. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2555. if drug.ID == 0 {
  2556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2557. return
  2558. }
  2559. //查询药品的所有库存
  2560. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2561. var total_count int64
  2562. for _, it := range list {
  2563. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2564. }
  2565. totals := strconv.FormatInt(total_count, 10)
  2566. //查询该药品是否存在开药记录
  2567. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2568. //新增处方
  2569. if advicelist.ID == 0 {
  2570. //查询最新批次库存
  2571. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2572. var batch_number_count int64
  2573. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2574. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2575. all_count, _ := strconv.ParseFloat(totals, 64)
  2576. if prescribingNumberUnit == drug.MinUnit {
  2577. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2578. if drug.IsUse != 1 {
  2579. if drug.IsProject == 0 || drug.IsProject == 2 {
  2580. if all_count == 0 {
  2581. tx.Rollback()
  2582. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2583. return
  2584. }
  2585. if prescribing_number > all_count {
  2586. tx.Rollback()
  2587. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2588. return
  2589. }
  2590. }
  2591. if adminInfo.CurrentOrgId == 10215 {
  2592. if prescribing_number > batch_number_all_count {
  2593. tx.Rollback()
  2594. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2595. return
  2596. }
  2597. }
  2598. }
  2599. } else {
  2600. if prescribingNumberUnit == drug.MaxUnit {
  2601. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2602. num := prescribing_number * float64(drug.MinNumber)
  2603. if drug.IsUse != 1 {
  2604. if drug.IsProject == 0 || drug.IsProject == 2 {
  2605. if all_count == 0 {
  2606. tx.Rollback()
  2607. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2608. return
  2609. }
  2610. if num > all_count {
  2611. tx.Rollback()
  2612. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2613. return
  2614. }
  2615. }
  2616. if adminInfo.CurrentOrgId == 10215 {
  2617. if prescribing_number > batch_number_all_count {
  2618. tx.Rollback()
  2619. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2620. return
  2621. }
  2622. }
  2623. }
  2624. }
  2625. }
  2626. }
  2627. //修改处方
  2628. if advicelist.ID > 0 {
  2629. //查询最新批次库存
  2630. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2631. var batch_number_count int64
  2632. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2633. var device_number int64
  2634. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2635. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2636. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2637. device_number = prescribingNumberInt * drug.MinNumber
  2638. }
  2639. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2640. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2641. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2642. device_number = prescribingNumberInt
  2643. }
  2644. var number_count int64
  2645. if prescribingNumberUnit == drug.MaxUnit {
  2646. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2647. number_count = prescribingNumberInt * drug.MinNumber
  2648. }
  2649. if prescribingNumberUnit == drug.MinUnit {
  2650. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2651. number_count = prescribingNumberInt
  2652. }
  2653. //如果修改的数量大于之前修改的数量
  2654. if (number_count - device_number) > 0 {
  2655. //如果修改的差数量 大于库存数量
  2656. if drug.IsUse != 1 {
  2657. if drug.IsProject == 0 || drug.IsProject == 2 {
  2658. if total_count == 0 {
  2659. tx.Rollback()
  2660. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2661. return
  2662. }
  2663. if (number_count - device_number) > total_count {
  2664. tx.Rollback()
  2665. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2666. return
  2667. }
  2668. }
  2669. if adminInfo.CurrentOrgId == 10215 {
  2670. if (number_count - device_number) > batch_number_count {
  2671. tx.Rollback()
  2672. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2673. return
  2674. }
  2675. }
  2676. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2677. //查询历史出库数据总批次
  2678. // 查询该药品最后一次出库记录
  2679. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2680. var out_count int64
  2681. var in_count int64
  2682. var stock_max_number int64
  2683. var stock_min_number int64
  2684. for _, it := range outInfo {
  2685. if it.CountUnit == drug.MaxUnit {
  2686. it.Count = it.Count * drug.MinNumber
  2687. }
  2688. out_count += it.Count
  2689. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2690. stock_max_number = warehouseInfoList.StockMaxNumber
  2691. stock_min_number = warehouseInfoList.StockMinNumber
  2692. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2693. }
  2694. if out_count > 0 {
  2695. if (number_count - device_number) > in_count {
  2696. tx.Rollback()
  2697. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2698. return
  2699. }
  2700. }
  2701. // 未出库
  2702. if out_count == 0 {
  2703. var sum_in_count int64
  2704. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2705. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2706. if sum_in_count == 0 {
  2707. tx.Rollback()
  2708. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2709. return
  2710. }
  2711. //如果修改的数量大于有库存的第一个批次
  2712. if number_count > sum_in_count {
  2713. tx.Rollback()
  2714. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2715. return
  2716. }
  2717. }
  2718. }
  2719. }
  2720. }
  2721. }
  2722. }
  2723. }
  2724. }
  2725. }
  2726. }
  2727. }
  2728. }
  2729. }
  2730. }
  2731. //校验耗材库存
  2732. if goodOutConfig.IsOpen == 1 {
  2733. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2734. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2735. if len(prescriptions) > 0 {
  2736. for _, item := range prescriptions {
  2737. items := item.(map[string]interface{})
  2738. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2739. projects := items["project"].([]interface{})
  2740. if len(projects) > 0 {
  2741. for _, project := range projects {
  2742. var project_id int64
  2743. var project_type int64
  2744. var totals float64
  2745. var project_name string
  2746. var parsetotal int64
  2747. var id int64
  2748. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2749. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2750. }
  2751. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2752. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2753. }
  2754. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2755. total, _ := project.(map[string]interface{})["total"].(string)
  2756. totals, _ = strconv.ParseFloat(total, 64)
  2757. }
  2758. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2759. project_name = project.(map[string]interface{})["project_name"].(string)
  2760. }
  2761. if project_type == 3 {
  2762. //查找该耗材的出库记录
  2763. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2764. if len(goodWarehouseInfo) == 0 {
  2765. //查询耗材库存
  2766. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2767. var stock_count int64
  2768. for _, it := range list {
  2769. stock_count += it.StockCount
  2770. }
  2771. stock_counts := strconv.FormatInt(stock_count, 10)
  2772. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2773. if stock_total_count == 0 {
  2774. tx.Rollback()
  2775. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2776. return
  2777. }
  2778. if totals > stock_total_count {
  2779. tx.Rollback()
  2780. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2781. return
  2782. }
  2783. }
  2784. if len(goodWarehouseInfo) > 0 {
  2785. //查询该患者耗材的历史数据
  2786. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2787. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2788. //数量发生改变
  2789. if parsetotal != count {
  2790. //如果现在的数量大于历史数量,就要看库存是否足够
  2791. if parsetotal > count {
  2792. //查询耗材所有库存
  2793. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2794. var stock_count int64
  2795. for _, it := range list {
  2796. stock_count += it.StockCount
  2797. }
  2798. //库存不足
  2799. if stock_count == 0 {
  2800. tx.Rollback()
  2801. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2802. return
  2803. }
  2804. if (parsetotal - count) > stock_count {
  2805. tx.Rollback()
  2806. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2807. return
  2808. }
  2809. }
  2810. }
  2811. }
  2812. }
  2813. }
  2814. }
  2815. }
  2816. }
  2817. }
  2818. }
  2819. }
  2820. //不使用耗材保存处方出库
  2821. if goodOutConfig.IsOpen != 1 {
  2822. if stockConfig.IsOpen == 1 {
  2823. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2824. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2825. if len(prescriptions) > 0 {
  2826. for _, item := range prescriptions {
  2827. items := item.(map[string]interface{})
  2828. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2829. projects := items["project"].([]interface{})
  2830. if len(projects) > 0 {
  2831. for _, project := range projects {
  2832. var project_id int64
  2833. var project_type int64
  2834. var totals float64
  2835. var project_name string
  2836. var parsetotal int64
  2837. var id int64
  2838. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2839. id = int64(project.(map[string]interface{})["id"].(float64))
  2840. }
  2841. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2842. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2843. }
  2844. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2845. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2846. }
  2847. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2848. total, _ := project.(map[string]interface{})["total"].(string)
  2849. totals, _ = strconv.ParseFloat(total, 64)
  2850. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2851. }
  2852. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2853. project_name = project.(map[string]interface{})["project_name"].(string)
  2854. }
  2855. if project_type == 3 {
  2856. //查找该耗材的出库记录
  2857. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2858. //没有出库记录
  2859. if len(goodWarehouseInfo) == 0 {
  2860. //查询耗材库存
  2861. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2862. var stock_count int64
  2863. for _, it := range list {
  2864. stock_count += it.StockCount
  2865. }
  2866. stock_counts := strconv.FormatInt(stock_count, 10)
  2867. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2868. if stock_total_count == 0 {
  2869. tx.Rollback()
  2870. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2871. return
  2872. }
  2873. if totals > stock_total_count {
  2874. tx.Rollback()
  2875. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2876. return
  2877. }
  2878. //查找今日该患者已经出库的所有耗材
  2879. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2880. for _, item := range goodList {
  2881. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2882. var flush_count int64
  2883. for _, it := range goodListSix {
  2884. flush_count += it.StockCount
  2885. }
  2886. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2887. creater := adminInfo.AdminUser.Id
  2888. if errs != nil {
  2889. goodErrcode := models.XtGoodErrcode{
  2890. UserOrgId: item.OrgId,
  2891. Errcode: "手动出库更新剩余出库失败",
  2892. GoodId: item.GoodId,
  2893. Status: 1,
  2894. Ctime: time.Now().Unix(),
  2895. Mtime: 0,
  2896. Count: 0,
  2897. StockCount: 0,
  2898. Creater: creater,
  2899. BatchNumberId: 0,
  2900. WarehouseOutId: 0,
  2901. }
  2902. service.CreateGoodErrcode(goodErrcode)
  2903. }
  2904. }
  2905. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2906. }
  2907. //有出库记录
  2908. if len(goodWarehouseInfo) > 0 {
  2909. //查询该患者耗材的历史数据
  2910. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2911. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2912. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2913. //数量发生改变
  2914. if parsetotal != count {
  2915. //查找今日该患者已经出库的所有耗材
  2916. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2917. for _, item := range goodList {
  2918. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2919. var flush_count int64
  2920. for _, it := range goodListSix {
  2921. flush_count += it.StockCount
  2922. }
  2923. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2924. //减少出库数量
  2925. creater := adminInfo.AdminUser.Id
  2926. if errs != nil {
  2927. goodErrcode := models.XtGoodErrcode{
  2928. UserOrgId: item.OrgId,
  2929. Errcode: "手动出库更新剩余出库失败",
  2930. GoodId: item.GoodId,
  2931. Status: 1,
  2932. Ctime: time.Now().Unix(),
  2933. Mtime: 0,
  2934. Count: 0,
  2935. StockCount: 0,
  2936. Creater: creater,
  2937. BatchNumberId: 0,
  2938. WarehouseOutId: 0,
  2939. }
  2940. service.CreateGoodErrcode(goodErrcode)
  2941. }
  2942. //查询默认仓库
  2943. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2944. var total_count int64
  2945. for _, it := range stockList {
  2946. total_count += it.StockCount
  2947. }
  2948. //基础库插入数据
  2949. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2950. }
  2951. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2952. }
  2953. }
  2954. }
  2955. }
  2956. }
  2957. }
  2958. }
  2959. }
  2960. }
  2961. }
  2962. }
  2963. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2964. var hpInfo models.HisPrescriptionInfo
  2965. if info.ID == 0 {
  2966. var randNum int
  2967. randNum = rand.Intn(10000) + 1000
  2968. timestamp := time.Now().Unix()
  2969. tempTime := time.Unix(timestamp, 0)
  2970. timeFormat := tempTime.Format("20060102150405")
  2971. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2972. hpInfo = models.HisPrescriptionInfo{
  2973. HisPatientId: his_patient_id,
  2974. UserOrgId: adminInfo.CurrentOrgId,
  2975. RecordDate: theTime.Unix(),
  2976. PatientId: patient_id,
  2977. Status: 1,
  2978. Ctime: time.Now().Unix(),
  2979. Mtime: time.Now().Unix(),
  2980. Creator: adminInfo.AdminUser.Id,
  2981. Modifier: adminInfo.AdminUser.Id,
  2982. Diagnosis: diagnose,
  2983. SickHistory: sick_history,
  2984. Departments: department,
  2985. RegisterType: reg_type,
  2986. PrescriptionNumber: p_number,
  2987. PrescriptionStatus: 1,
  2988. Doctor: role.UserName,
  2989. DoctorId: doctor_id,
  2990. SickType: sick_type,
  2991. PType: p_type,
  2992. PatientDiagnosis: patient_diagnose,
  2993. }
  2994. service.SavePatientPrescriptionInfo(hpInfo)
  2995. //创建步骤表
  2996. finish := models.XtDialysisFinish{
  2997. IsFinish: 1,
  2998. UserOrgId: adminInfo.CurrentOrgId,
  2999. Status: 1,
  3000. Ctime: time.Now().Unix(),
  3001. Mtime: 0,
  3002. Module: 4,
  3003. RecordDate: theTime.Unix(),
  3004. Sourse: 1,
  3005. PatientId: patient_id,
  3006. }
  3007. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  3008. if dialysisFinish.ID == 0 {
  3009. service.CreateDialysisFinish(finish)
  3010. }
  3011. redis := service.RedisClient()
  3012. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3013. redis.Set(key, "", time.Second)
  3014. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3015. redis.Set(keyOne, "", time.Second)
  3016. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3017. redis.Set(keySeven, "", time.Second)
  3018. defer redis.Close()
  3019. } else {
  3020. hpInfo = models.HisPrescriptionInfo{
  3021. ID: info.ID,
  3022. UserOrgId: adminInfo.CurrentOrgId,
  3023. RecordDate: info.RecordDate,
  3024. PatientId: info.PatientId,
  3025. Status: 1,
  3026. Ctime: info.Ctime,
  3027. Mtime: time.Now().Unix(),
  3028. Creator: info.Creator,
  3029. Modifier: adminInfo.AdminUser.Id,
  3030. Diagnosis: diagnose,
  3031. SickHistory: sick_history,
  3032. Departments: department,
  3033. RegisterType: reg_type,
  3034. PrescriptionNumber: info.PrescriptionNumber,
  3035. Doctor: role.UserName,
  3036. PrescriptionStatus: info.PrescriptionStatus,
  3037. DoctorId: doctor_id,
  3038. SickType: sick_type,
  3039. PType: info.PType,
  3040. HisPatientId: info.HisPatientId,
  3041. PatientDiagnosis: patient_diagnose,
  3042. }
  3043. service.SavePatientPrescriptionInfo(hpInfo)
  3044. //创建步骤表
  3045. finish := models.XtDialysisFinish{
  3046. IsFinish: 1,
  3047. UserOrgId: adminInfo.CurrentOrgId,
  3048. Status: 1,
  3049. Ctime: time.Now().Unix(),
  3050. Mtime: 0,
  3051. Module: 4,
  3052. RecordDate: info.RecordDate,
  3053. Sourse: 1,
  3054. PatientId: info.PatientId,
  3055. }
  3056. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3057. if dialysisFinish.ID == 0 {
  3058. service.CreateDialysisFinish(finish)
  3059. }
  3060. redis := service.RedisClient()
  3061. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3062. redis.Set(key, "", time.Second)
  3063. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3064. redis.Set(keyOne, "", time.Second)
  3065. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3066. redis.Set(keySeven, "", time.Second)
  3067. defer redis.Close()
  3068. }
  3069. //定义切片
  3070. var adviceList []models.HisDoctorAdviceInfo
  3071. var projectList []models.HisPrescriptionProject
  3072. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10635 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 || adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10726 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10571 || adminInfo.CurrentOrgId == 10724 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10653 || adminInfo.CurrentOrgId == 10567 || adminInfo.CurrentOrgId == 10751 || adminInfo.CurrentOrgId == 10752 || adminInfo.CurrentOrgId == 9478 || adminInfo.CurrentOrgId == 10567 || adminInfo.CurrentOrgId == 10768 || adminInfo.CurrentOrgId == 10164 {
  3073. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3074. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3075. var tempPrescription *models.HisPrescription
  3076. if len(prescriptions) > 0 {
  3077. for _, item := range prescriptions {
  3078. // 开始外部循环的事务
  3079. tx := db.Begin()
  3080. // 在函数结束时处理事务回滚
  3081. defer func() {
  3082. if r := recover(); r != nil {
  3083. tx.Rollback()
  3084. }
  3085. }()
  3086. items := item.(map[string]interface{})
  3087. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3088. utils.ErrorLog("id")
  3089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3090. return
  3091. }
  3092. id := int64(items["id"].(float64))
  3093. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3094. tempPrescription = &new_prescription
  3095. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3096. utils.ErrorLog("type")
  3097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3098. return
  3099. }
  3100. types := int64(items["type"].(float64))
  3101. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3102. utils.ErrorLog("med_type")
  3103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3104. return
  3105. }
  3106. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3107. if med_type == "0" {
  3108. med_type = "14"
  3109. }
  3110. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3111. // utils.ErrorLog("diagnoses")
  3112. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3113. // return
  3114. //}
  3115. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3116. diagnoses, _ := items["diagnoses"].(string)
  3117. //if order_status == 0 {
  3118. // order_status = 1
  3119. //}
  3120. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3121. utils.ErrorLog("pre_time")
  3122. }
  3123. preTime, _ := items["pre_time"].(string)
  3124. fmt.Println("preTime", preTime)
  3125. timeLayout := "2006-01-02"
  3126. loc, _ := time.LoadLocation("Local")
  3127. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3128. //result := strings.Split(preTime, " ")
  3129. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3130. if err != nil {
  3131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3132. return
  3133. }
  3134. pTime := theTime2.Unix()
  3135. ctime := time.Now().Unix()
  3136. if tempPrescription.ID == 0 {
  3137. prescription := &models.HisPrescription{
  3138. ID: 0,
  3139. PatientId: patient_id,
  3140. UserOrgId: adminInfo.CurrentOrgId,
  3141. RecordDate: recordDateTime,
  3142. Ctime: ctime,
  3143. Mtime: ctime,
  3144. Type: types,
  3145. Modifier: adminInfo.AdminUser.Id,
  3146. Creator: adminInfo.AdminUser.Id,
  3147. Status: 1,
  3148. Doctor: role.UserName,
  3149. HisPatientId: his_patient_id,
  3150. OrderStatus: 1,
  3151. BatchNumber: "",
  3152. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3153. PreTime: pTime,
  3154. PType: p_type,
  3155. MedType: med_type,
  3156. Diagnose: diagnoses,
  3157. }
  3158. tempPrescription = prescription
  3159. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3160. redis := service.RedisClient()
  3161. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3162. redis.Set(key, "", time.Second)
  3163. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3164. redis.Set(keyOne, "", time.Second)
  3165. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3166. redis.Set(keySeven, "", time.Second)
  3167. defer redis.Close()
  3168. } else {
  3169. tempPrescription.ID = id
  3170. tempPrescription.Type = types
  3171. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3172. tempPrescription.Mtime = time.Now().Unix()
  3173. tempPrescription.Doctor = role.UserName
  3174. //tempPrescription.OrderStatus = order_status
  3175. tempPrescription.PreTime = pTime
  3176. tempPrescription.MedType = med_type
  3177. tempPrescription.Diagnose = diagnoses
  3178. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3179. redis := service.RedisClient()
  3180. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3181. redis.Set(key, "", time.Second)
  3182. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3183. redis.Set(keyOne, "", time.Second)
  3184. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3185. redis.Set(keySeven, "", time.Second)
  3186. defer redis.Close()
  3187. }
  3188. //service.SaveHisPrescription(prescription)
  3189. //更改患者挂号状态
  3190. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3191. fmt.Println("更改失败", err2)
  3192. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3193. advices := items["advices"].([]interface{})
  3194. groupNo := int64(0)
  3195. if len(advices) > 0 {
  3196. for _, advice := range advices {
  3197. tx := db.Begin()
  3198. // 在函数结束时处理事务回滚
  3199. defer func() {
  3200. if r := recover(); r != nil {
  3201. tx.Rollback()
  3202. }
  3203. }()
  3204. var s models.HisDoctorAdviceInfo
  3205. s.PrescriptionId = tempPrescription.ID
  3206. s.AdviceType = 2
  3207. s.AdviceDoctor = doctor_id
  3208. s.StopState = 2
  3209. s.ExecutionState = 2
  3210. s.AdviceDate = theTime3.Unix()
  3211. s.Status = 1
  3212. s.UserOrgId = adminInfo.CurrentOrgId
  3213. s.RecordDate = theTime3.Unix()
  3214. s.StartTime = tempPrescription.PreTime
  3215. s.Groupno = groupNo
  3216. s.PatientId = patient_id
  3217. s.HisPatientId = his_patient_id
  3218. s.StartTime = pTime
  3219. s.IsSettle = 2
  3220. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3221. if errcode > 0 {
  3222. c.ServeFailJSONWithSGJErrorCode(errcode)
  3223. return
  3224. }
  3225. s.StartTime = pTime
  3226. var total_count int64 //处方总库存
  3227. //查询改药品信息
  3228. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3229. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3230. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3231. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3232. total_count += prescribingNumberSeven * medical.MinNumber
  3233. }
  3234. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3235. total_count += prescribingNumberSeven
  3236. }
  3237. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3238. total_count += prescribingNumberSeven
  3239. }
  3240. //if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3241. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3242. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3243. // if s.Price != lastWarehouse.RetailPrice {
  3244. // s.Price = lastWarehouse.RetailPrice
  3245. // }
  3246. // if s.Price == 0 {
  3247. // if lastWarehouse.ID == 0 {
  3248. // lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3249. // s.Price = lastWarehouseTwo.RetailPrice
  3250. // }
  3251. //
  3252. // }
  3253. //}
  3254. //查询保存处方出库开关是否打开
  3255. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3256. if s.PatientId != 30038 {
  3257. if drugOutConfig.IsOpen == 1 {
  3258. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3259. // 查询该药品最后一次出库记录
  3260. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3261. var is_user_total int64
  3262. var no_user_total int64
  3263. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3264. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3265. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3266. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3267. }
  3268. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3269. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3270. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3271. no_user_total += prescribingNumberSevenTy
  3272. }
  3273. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3274. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3275. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3276. no_user_total += prescribingNumberSevenTy
  3277. }
  3278. if len(druginfo) > 0 {
  3279. for _, it := range druginfo {
  3280. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3281. it.Count = it.Count * drug.MinNumber
  3282. is_user_total += it.Count
  3283. }
  3284. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3285. is_user_total += it.Count
  3286. }
  3287. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3288. is_user_total += it.Count
  3289. }
  3290. }
  3291. }
  3292. //库存不足
  3293. if s.UserOrgId != 10206 {
  3294. //判断库存不足的地方
  3295. if s.ID == 0 {
  3296. //查询改药品是否已经停用
  3297. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3298. if base.ID > 0 {
  3299. tx.Rollback()
  3300. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3301. return
  3302. }
  3303. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3304. fmt.Println("0000000000000000000000", drugMedical.SumCount)
  3305. if drugMedical.SumCount == 0 {
  3306. tx.Rollback()
  3307. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3308. return
  3309. }
  3310. list, _ := service.GetLastDrugWarehouseInfoList(s.DrugId)
  3311. if len(list) == 0 {
  3312. tx.Rollback()
  3313. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3314. return
  3315. }
  3316. //针对康德
  3317. //if s.UserOrgId == 10402 || s.UserOrgId == 10164 {
  3318. // //获取该药品的总入库数量
  3319. // drugWarehouseinfo, _ := service.GetAllDrugInfoList(s.DrugId, s.UserOrgId)
  3320. //
  3321. // //获取该药品总共开了多少支医嘱
  3322. // hisDocInfoList, _ := service.GetHisDocInfoList(s.DrugId, s.UserOrgId)
  3323. // var in_count int64
  3324. // var in_prescription_number_total int64
  3325. // if len(drugWarehouseinfo) > 0 {
  3326. // for _, item := range drugWarehouseinfo {
  3327. // if item.MaxUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3328. //
  3329. // in_count += item.WarehousingCount * drugMedical.MinNumber
  3330. // }
  3331. //
  3332. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3333. //
  3334. // in_count += item.WarehousingCount
  3335. // }
  3336. //
  3337. // if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3338. //
  3339. // in_count += item.WarehousingCount
  3340. // }
  3341. //
  3342. // }
  3343. // }
  3344. //
  3345. // if len(hisDocInfoList) > 0 {
  3346. //
  3347. // for _, item := range hisDocInfoList {
  3348. // if item.PrescribingNumberUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3349. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3350. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3351. //
  3352. // in_prescription_number_total += prescribingNumberSevenTy * drug.MinNumber
  3353. // }
  3354. //
  3355. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3356. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3357. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3358. // in_prescription_number_total += prescribingNumberSevenTy
  3359. // }
  3360. //
  3361. // if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3362. // prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3363. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3364. // in_prescription_number_total += prescribingNumberSevenTy
  3365. // }
  3366. // }
  3367. // }
  3368. // //
  3369. // //fmt.Println("no_user_total------------------------------", no_user_total)
  3370. // //fmt.Println("in_prescription_number_total---------------------------", in_prescription_number_total)
  3371. // //fmt.Println("in_count----------------------------------", in_count)
  3372. //
  3373. // //如果已经开过的医嘱 加上未开的医嘱数量 大于 入库总数量则提示库存不足
  3374. // if no_user_total+in_prescription_number_total > in_count {
  3375. // tx.Rollback()
  3376. // c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3377. // return
  3378. // }
  3379. //
  3380. //}
  3381. //查询该药品所有入库数量
  3382. }
  3383. if s.ID > 0 {
  3384. //查询改药品是否已经停用
  3385. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3386. if base.ID > 0 {
  3387. tx.Rollback()
  3388. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3389. return
  3390. }
  3391. }
  3392. }
  3393. if is_user_total != no_user_total {
  3394. //出库
  3395. //针对御享天源
  3396. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  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. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3405. if drugMedical.SumCount == 0 {
  3406. tx.Rollback()
  3407. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3408. return
  3409. }
  3410. creater := adminInfo.AdminUser.Id
  3411. newadviceInfo := &models.HisDoctorAdviceInfo{
  3412. ID: s.ID,
  3413. UserOrgId: s.UserOrgId,
  3414. PatientId: s.PatientId,
  3415. HisPatientId: s.HisPatientId,
  3416. AdviceType: s.AdviceType,
  3417. AdviceDate: s.AdviceDate,
  3418. StartTime: s.StartTime,
  3419. AdviceName: s.AdviceName,
  3420. AdviceDesc: s.AdviceDesc,
  3421. ReminderDate: s.ReminderDate,
  3422. SingleDose: s.SingleDose,
  3423. SingleDoseUnit: s.SingleDoseUnit,
  3424. PrescribingNumber: s.PrescribingNumber,
  3425. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3426. DeliveryWay: s.DeliveryWay,
  3427. ExecutionFrequency: s.ExecutionFrequency,
  3428. AdviceDoctor: s.AdviceDoctor,
  3429. Status: s.Status,
  3430. CreatedTime: s.CreatedTime,
  3431. UpdatedTime: s.UpdatedTime,
  3432. AdviceAffirm: s.AdviceAffirm,
  3433. Remark: s.Remark,
  3434. StopTime: s.StopTime,
  3435. StopReason: s.StopReason,
  3436. StopDoctor: s.StopDoctor,
  3437. StopState: s.StopState,
  3438. ParentId: s.ParentId,
  3439. ExecutionTime: s.ExecutionTime,
  3440. ExecutionStaff: s.ExecutionStaff,
  3441. ExecutionState: s.ExecutionState,
  3442. Checker: s.Checker,
  3443. RecordDate: s.RecordDate,
  3444. DialysisOrderId: s.DialysisOrderId,
  3445. CheckTime: s.CheckTime,
  3446. CheckState: s.CheckState,
  3447. DrugSpec: s.DrugSpec,
  3448. DrugSpecUnit: s.DrugSpecUnit,
  3449. Groupno: s.Groupno,
  3450. RemindType: s.RemindType,
  3451. FrequencyType: s.FrequencyType,
  3452. DayCount: s.DayCount,
  3453. WeekDay: s.WeekDay,
  3454. TemplateId: s.TemplateId,
  3455. Modifier: s.Modifier,
  3456. DrugId: s.DrugId,
  3457. Price: s.Price,
  3458. PrescriptionId: s.PrescriptionId,
  3459. MedListCodg: s.MedListCodg,
  3460. FeedetlSn: s.FeedetlSn,
  3461. Day: s.DayCount,
  3462. ChildDoctorAdvice: nil,
  3463. Drug: models.Drug{},
  3464. Diagnosis: s.Diagnosis,
  3465. Way: s.Way,
  3466. HospApprFlag: s.HospApprFlag,
  3467. LmtUsedFlag: s.LmtUsedFlag,
  3468. HisOrderInfo: models.HisOrderInfo{},
  3469. IsMedicine: s.IsMedicine,
  3470. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3471. Child: nil,
  3472. IsSettle: s.IsSettle,
  3473. IsMobile: s.IsMobile,
  3474. IsSelfDrug: s.IsSelfDrug,
  3475. DrugWayCount: s.DrugWayCount,
  3476. }
  3477. var history_count int64
  3478. var local_count int64
  3479. //查找已经开过的医嘱信息
  3480. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3481. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3482. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3483. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3484. local_count += prescribingNumberSevenTy * drug.MinNumber
  3485. }
  3486. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3487. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3488. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3489. local_count += prescribingNumberSevenTy
  3490. }
  3491. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3492. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3493. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3494. local_count += prescribingNumberSevenTy
  3495. }
  3496. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3497. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3498. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3499. history_count += prescribingNumberSevenTy * drug.MinNumber
  3500. }
  3501. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3502. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3503. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3504. history_count += prescribingNumberSevenTy
  3505. }
  3506. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3507. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3508. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3509. history_count += prescribingNumberSevenTy
  3510. }
  3511. //fmt.Println("local_count---------------", local_count)
  3512. //fmt.Println("history_count---------------", history_count)
  3513. //如果当前出库数量大于历史出库数量则需要出库
  3514. if local_count > history_count {
  3515. //按最小单位出库
  3516. var cha_count = local_count - history_count
  3517. newadviceInfo.PrescribingNumber = float64(cha_count)
  3518. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3519. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3520. }
  3521. //如果当前出库数量小于历史出库数量则需要退库
  3522. if local_count < history_count {
  3523. var cha_count = history_count - local_count
  3524. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3525. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3526. }
  3527. if local_count == history_count {
  3528. if is_user_total == 0 {
  3529. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3530. }
  3531. }
  3532. }
  3533. if drug.IsUse == 2 {
  3534. creater := adminInfo.AdminUser.Id
  3535. newadviceInfo := &models.HisDoctorAdviceInfo{
  3536. ID: s.ID,
  3537. UserOrgId: s.UserOrgId,
  3538. PatientId: s.PatientId,
  3539. HisPatientId: s.HisPatientId,
  3540. AdviceType: s.AdviceType,
  3541. AdviceDate: s.AdviceDate,
  3542. StartTime: s.StartTime,
  3543. AdviceName: s.AdviceName,
  3544. AdviceDesc: s.AdviceDesc,
  3545. ReminderDate: s.ReminderDate,
  3546. SingleDose: s.SingleDose,
  3547. SingleDoseUnit: s.SingleDoseUnit,
  3548. PrescribingNumber: s.PrescribingNumber,
  3549. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3550. DeliveryWay: s.DeliveryWay,
  3551. ExecutionFrequency: s.ExecutionFrequency,
  3552. AdviceDoctor: s.AdviceDoctor,
  3553. Status: s.Status,
  3554. CreatedTime: s.CreatedTime,
  3555. UpdatedTime: s.UpdatedTime,
  3556. AdviceAffirm: s.AdviceAffirm,
  3557. Remark: s.Remark,
  3558. StopTime: s.StopTime,
  3559. StopReason: s.StopReason,
  3560. StopDoctor: s.StopDoctor,
  3561. StopState: s.StopState,
  3562. ParentId: s.ParentId,
  3563. ExecutionTime: s.ExecutionTime,
  3564. ExecutionStaff: s.ExecutionStaff,
  3565. ExecutionState: s.ExecutionState,
  3566. Checker: s.Checker,
  3567. RecordDate: s.RecordDate,
  3568. DialysisOrderId: s.DialysisOrderId,
  3569. CheckTime: s.CheckTime,
  3570. CheckState: s.CheckState,
  3571. DrugSpec: s.DrugSpec,
  3572. DrugSpecUnit: s.DrugSpecUnit,
  3573. Groupno: s.Groupno,
  3574. RemindType: s.RemindType,
  3575. FrequencyType: s.FrequencyType,
  3576. DayCount: s.DayCount,
  3577. WeekDay: s.WeekDay,
  3578. TemplateId: s.TemplateId,
  3579. Modifier: s.Modifier,
  3580. DrugId: s.DrugId,
  3581. Price: s.Price,
  3582. PrescriptionId: s.PrescriptionId,
  3583. MedListCodg: s.MedListCodg,
  3584. FeedetlSn: s.FeedetlSn,
  3585. Day: s.DayCount,
  3586. ChildDoctorAdvice: nil,
  3587. Drug: models.Drug{},
  3588. Diagnosis: s.Diagnosis,
  3589. Way: s.Way,
  3590. HospApprFlag: s.HospApprFlag,
  3591. LmtUsedFlag: s.LmtUsedFlag,
  3592. HisOrderInfo: models.HisOrderInfo{},
  3593. IsMedicine: s.IsMedicine,
  3594. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3595. Child: nil,
  3596. IsSettle: s.IsSettle,
  3597. IsMobile: s.IsMobile,
  3598. IsSelfDrug: s.IsSelfDrug,
  3599. DrugWayCount: s.DrugWayCount,
  3600. }
  3601. var history_count int64
  3602. var local_count int64
  3603. //查找已经开过的医嘱信息
  3604. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3605. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3606. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3607. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3608. local_count += prescribingNumberSevenTy * drug.MinNumber
  3609. }
  3610. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3611. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3612. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3613. local_count += prescribingNumberSevenTy
  3614. }
  3615. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3616. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3617. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3618. local_count += prescribingNumberSevenTy
  3619. }
  3620. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3621. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3622. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3623. history_count += prescribingNumberSevenTy * drug.MinNumber
  3624. }
  3625. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3626. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3627. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3628. history_count += prescribingNumberSevenTy
  3629. }
  3630. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3631. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3632. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3633. history_count += prescribingNumberSevenTy
  3634. }
  3635. fmt.Println("local_count---------------", local_count)
  3636. fmt.Println("history_count---------------", history_count)
  3637. //如果当前出库数量大于历史出库数量则需要出库
  3638. if local_count > history_count {
  3639. //按最小单位出库
  3640. var cha_count = local_count - history_count
  3641. newadviceInfo.PrescribingNumber = float64(cha_count)
  3642. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3643. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3644. }
  3645. //如果当前出库数量小于历史出库数量则需要退库
  3646. if local_count < history_count {
  3647. var cha_count = history_count - local_count
  3648. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3649. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3650. }
  3651. if local_count == history_count {
  3652. if is_user_total == 0 {
  3653. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3654. }
  3655. }
  3656. }
  3657. //更新字典里面的库存
  3658. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3659. var sum_count int64
  3660. for _, its := range stockInfo {
  3661. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3662. if its.MaxUnit == baseDrug.MaxUnit {
  3663. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3664. }
  3665. sum_count += its.StockMaxNumber + its.StockMinNumber
  3666. }
  3667. //更新基础库存
  3668. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3669. //剩余库存
  3670. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3671. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3672. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3673. //创建医嘱
  3674. service.CreateHisDoctorAdviceOne(&s, tx)
  3675. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3676. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3677. if len(outInfoTwo) > 0 {
  3678. for _, item := range outInfoTwo {
  3679. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3680. }
  3681. }
  3682. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3683. if len(drugAutoDetail) > 0 {
  3684. for _, item := range drugAutoDetail {
  3685. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3686. }
  3687. }
  3688. }
  3689. }
  3690. }
  3691. //记录日志
  3692. byterequest, _ := json.Marshal(s)
  3693. adviceLog := models.XtDoctorAdviceLog{
  3694. UserOrgId: s.UserOrgId,
  3695. PatientId: s.PatientId,
  3696. AdminUserId: adminInfo.AdminUser.Id,
  3697. Module: 1,
  3698. ErrLog: string(byterequest),
  3699. Status: 1,
  3700. Ctime: time.Now().Unix(),
  3701. Mtime: 0,
  3702. Source: "电脑端新建his医嘱",
  3703. RecordDate: s.AdviceDate,
  3704. }
  3705. service.CreateDoctorAdviceLog(adviceLog)
  3706. //存储切片中
  3707. adviceList = append(adviceList, s)
  3708. redis := service.RedisClient()
  3709. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3710. redis.Set(key, "", time.Second)
  3711. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3712. redis.Set(keyOne, "", time.Second)
  3713. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3714. redis.Set(keySeven, "", time.Second)
  3715. var randNum int
  3716. randNum = rand.Intn(1000) + 1000
  3717. //timestamp := time.Now().Unix()
  3718. //tempTime := time.Unix(timestamp, 0)
  3719. //timeFormat := tempTime.Format("20060102150405")
  3720. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3721. //赤峰
  3722. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3723. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3724. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3725. if info.RetailPrice > 0 {
  3726. if s.DeliveryWay == "口服" {
  3727. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3728. s.Price = drug.RetailPrice
  3729. }
  3730. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3731. s.Price = info.RetailPrice
  3732. }
  3733. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3734. s.Price = info.RetailPrice
  3735. }
  3736. }
  3737. }
  3738. }
  3739. service.CreateHisDoctorAdviceOne(&s, tx)
  3740. tx.Commit()
  3741. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3742. redis.Set(keySix, "", time.Second)
  3743. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3744. redis.Set(keyFive, "", time.Second)
  3745. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3746. redis.Set(keyEight, "", time.Second)
  3747. defer redis.Close()
  3748. }
  3749. }
  3750. }
  3751. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3752. projects := items["project"].([]interface{})
  3753. if len(projects) > 0 {
  3754. for _, project := range projects {
  3755. tx := db.Begin()
  3756. // 在函数结束时处理事务回滚
  3757. defer func() {
  3758. if r := recover(); r != nil {
  3759. tx.Rollback()
  3760. }
  3761. }()
  3762. var p models.HisPrescriptionProject
  3763. p.PrescriptionId = tempPrescription.ID
  3764. p.PatientId = patient_id
  3765. p.RecordDate = theTime3.Unix()
  3766. p.Doctor = doctor_id
  3767. p.UserOrgId = adminInfo.CurrentOrgId
  3768. p.HisPatientId = his_patient_id
  3769. p.Status = 1
  3770. p.StartTime = pTime
  3771. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3772. if errcode > 0 {
  3773. tx.Rollback()
  3774. c.ServeFailJSONWithSGJErrorCode(errcode)
  3775. return
  3776. }
  3777. if p.ID == 0 {
  3778. p.IsOut = 2
  3779. }
  3780. if p.ID > 0 {
  3781. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3782. p.IsOut = projectDetail.IsOut
  3783. }
  3784. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3785. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3786. if p.Type == 3 {
  3787. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3788. if p.Price != lastWarehouse.PackingPrice {
  3789. p.Price = lastWarehouse.PackingPrice
  3790. }
  3791. if p.Price == 0 {
  3792. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3793. p.Price = lastWarehouseTwo.PackingPrice
  3794. }
  3795. if p.Unit == "" {
  3796. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3797. p.Unit = goodInfoOne.PackingUnit
  3798. }
  3799. }
  3800. }
  3801. if adminInfo.CurrentOrgId != 10206 {
  3802. if p.Type == 3 {
  3803. //判断耗材库存充不充足
  3804. if p.ID == 0 {
  3805. //查询该耗材是否停用
  3806. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3807. //表示该耗材已经停用,不能保存
  3808. if goodInfoSeven.ID == 0 {
  3809. tx.Rollback()
  3810. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3811. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3812. return
  3813. }
  3814. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3815. if goodInfoOne.SumCount == 0 {
  3816. tx.Rollback()
  3817. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3818. return
  3819. }
  3820. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3821. if len(goodListOne) == 0 {
  3822. tx.Rollback()
  3823. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3824. return
  3825. }
  3826. }
  3827. if p.ID > 0 {
  3828. //查询该耗材是否停用
  3829. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3830. //表示该耗材已经停用,不能保存
  3831. if goodInfoSeven.ID == 0 {
  3832. tx.Rollback()
  3833. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3834. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3835. return
  3836. }
  3837. //查询该耗材今日是否已经出过库
  3838. goodOutList, _ := service.GetGoodWareHouseOutInfoByGood(p.ProjectId, p.RecordDate, p.UserOrgId)
  3839. var his_count int64
  3840. if len(goodOutList) > 0 {
  3841. for _, item := range goodOutList {
  3842. his_count += item.Count
  3843. }
  3844. }
  3845. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3846. //如果当前的处方数量大于 历史出库数量 要判断库存够不够
  3847. if nowCount > his_count {
  3848. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3849. if goodInfoOne.SumCount == 0 {
  3850. tx.Rollback()
  3851. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3852. return
  3853. }
  3854. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3855. if len(goodListOne) == 0 {
  3856. tx.Rollback()
  3857. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3858. return
  3859. }
  3860. }
  3861. if len(goodOutList) == 0 {
  3862. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3863. if goodInfoOne.SumCount == 0 {
  3864. tx.Rollback()
  3865. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3866. return
  3867. }
  3868. goodListOne, _ := service.GetGoodWarehouseInfoByGoodList(p.ProjectId)
  3869. if len(goodListOne) == 0 {
  3870. tx.Rollback()
  3871. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3872. return
  3873. }
  3874. }
  3875. }
  3876. }
  3877. }
  3878. //查询保存耗材出库开关是否打开
  3879. if p.PatientId != 30038 {
  3880. //用机构ID区分
  3881. if adminInfo.CurrentOrgId != 9671 {
  3882. if goodOutConfig.IsOpen == 1 {
  3883. //耗材出库
  3884. if p.Type == 3 {
  3885. //对比当前数据和历史出库数据
  3886. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3887. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3888. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3889. ////针对康德
  3890. //if p.UserOrgId == 10164 || p.UserOrgId == 10402 {
  3891. //
  3892. // //查询耗材的总入库数量
  3893. // warehouseInfo, _ := service.GetAllWarehouseInfo(p.ProjectId, adminInfo.CurrentOrgId)
  3894. //
  3895. // //查询该耗材的总出库数量
  3896. // prescriptionGood, _ := service.GetHisPrescriptionByGoodId(p.ProjectId, adminInfo.CurrentOrgId)
  3897. //
  3898. // var all_good_count int64
  3899. //
  3900. // var prescription_count int64
  3901. // if len(warehouseInfo) > 0 {
  3902. //
  3903. // for _, item := range warehouseInfo {
  3904. // all_good_count += item.WarehousingCount
  3905. // }
  3906. // }
  3907. // if len(prescriptionGood) > 0 {
  3908. // for _, item := range prescriptionGood {
  3909. //
  3910. // hisCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3911. // prescription_count += hisCount
  3912. // }
  3913. // }
  3914. //
  3915. // //fmt.Println("prescription_count-------------------------", prescription_count)
  3916. // //fmt.Println("nowCount-------------------------", nowCount)
  3917. // //fmt.Println("all_good_count-------------------------", all_good_count)
  3918. //
  3919. // if prescription_count+nowCount > all_good_count {
  3920. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3921. // tx.Rollback()
  3922. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3923. // return
  3924. // }
  3925. //}
  3926. fmt.Println("nowCount222=================", nowCount)
  3927. fmt.Println("historyCount-333----------------", historyCount)
  3928. //如果当前处方数量大于历史数据,则需要出库
  3929. if nowCount > historyCount {
  3930. var cha_count int64
  3931. cha_count = nowCount - historyCount
  3932. timeStr := time.Now().Format("2006-01-02")
  3933. timeArr := strings.Split(timeStr, "-")
  3934. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3935. total = total + 1
  3936. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3937. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3938. number = number + total
  3939. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3940. operation_time := time.Now().Unix()
  3941. creater := c.GetAdminUserInfo().AdminUser.Id
  3942. recordDateStr := time.Now().Format("2006-01-02")
  3943. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3944. nowtime := recordDate.Unix()
  3945. warehouseOut := models.WarehouseOut{
  3946. WarehouseOutOrderNumber: warehousing_out_order,
  3947. OperationTime: operation_time,
  3948. OrgId: adminInfo.CurrentOrgId,
  3949. Creater: creater,
  3950. Ctime: time.Now().Unix(),
  3951. Status: 1,
  3952. WarehouseOutTime: nowtime,
  3953. Type: 1,
  3954. StorehouseId: storeConfig.StorehouseOutInfo,
  3955. IsCheck: 1,
  3956. IsSys: 1,
  3957. }
  3958. //查询是否生成出库单
  3959. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3960. if out.ID == 0 {
  3961. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3962. }
  3963. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3964. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3965. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3966. dialyPrepareOne := models.DialysisBeforePrepare{
  3967. GoodTypeId: goodObj.GoodTypeId,
  3968. GoodId: p.ProjectId,
  3969. PatientId: p.PatientId,
  3970. RecordDate: p.RecordDate,
  3971. UserOrgId: adminInfo.CurrentOrgId,
  3972. Count: cha_count,
  3973. Ctime: time.Now().Unix(),
  3974. Creater: creater,
  3975. Status: 1,
  3976. StorehouseId: houseConfig.StorehouseOutInfo,
  3977. ProjectId: p.ID,
  3978. }
  3979. //出库
  3980. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3981. }
  3982. //如果当前处方数量小于历史数据,怎需要退库
  3983. if nowCount < historyCount {
  3984. var cha_count int64
  3985. cha_count = historyCount - nowCount
  3986. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3987. creater := c.GetAdminUserInfo().AdminUser.Id
  3988. newPrescriptionProject := &models.HisPrescriptionProject{
  3989. ID: p.ID,
  3990. ProjectId: p.ProjectId,
  3991. Price: p.Price,
  3992. UserOrgId: p.UserOrgId,
  3993. Status: 1,
  3994. Ctime: time.Now().Unix(),
  3995. Mtime: time.Now().Unix(),
  3996. PatientId: p.PatientId,
  3997. HisPatientId: p.HisPatientId,
  3998. RecordDate: p.RecordDate,
  3999. PrescriptionId: p.PrescriptionId,
  4000. Count: p.Count,
  4001. FeedetlSn: p.FeedetlSn,
  4002. MedListCodg: p.MedListCodg,
  4003. SingleDose: p.SingleDose,
  4004. DeliveryWay: p.DeliveryWay,
  4005. ExecutionFrequency: p.ExecutionFrequency,
  4006. Day: p.Day,
  4007. HisProject: models.HisProject{},
  4008. GoodInfo: models.GoodInfo{},
  4009. Remark: p.Remark,
  4010. Unit: p.Unit,
  4011. Type: p.Type,
  4012. Doctor: p.Doctor,
  4013. ExecutionTime: p.ExecutionTime,
  4014. ExecutionStaff: p.ExecutionStaff,
  4015. ExecutionState: p.ExecutionState,
  4016. CheckTime: p.CheckTime,
  4017. CheckState: p.CheckState,
  4018. Checker: p.Checker,
  4019. StartTime: p.StartTime,
  4020. TeamId: p.TeamId,
  4021. XtHisProjectTeam: models.XtHisProjectTeam{},
  4022. FrequencyType: p.FrequencyType,
  4023. DayCount: p.DayCount,
  4024. WeekDay: p.WeekDay,
  4025. IsCheckTeam: p.IsCheckTeam,
  4026. HisOrderInfo: models.HisOrderInfo{},
  4027. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4028. IsOut: p.IsOut,
  4029. YbSyncStatus: p.YbSyncStatus,
  4030. }
  4031. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4032. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4033. }
  4034. if nowCount == historyCount {
  4035. if historyCount == 0 {
  4036. recordDateStr := time.Now().Format("2006-01-02")
  4037. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4038. nowtime := recordDate.Unix()
  4039. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4040. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4041. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4042. creater := c.GetAdminUserInfo().AdminUser.Id
  4043. dialyPrepareOne := models.DialysisBeforePrepare{
  4044. GoodTypeId: goodObj.GoodTypeId,
  4045. GoodId: p.ProjectId,
  4046. PatientId: p.PatientId,
  4047. RecordDate: p.RecordDate,
  4048. UserOrgId: adminInfo.CurrentOrgId,
  4049. Count: nowCount,
  4050. Ctime: time.Now().Unix(),
  4051. Creater: creater,
  4052. Status: 1,
  4053. StorehouseId: houseConfig.StorehouseOutInfo,
  4054. ProjectId: p.ID,
  4055. }
  4056. //出库
  4057. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4058. }
  4059. }
  4060. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4061. //查询历史出库数据
  4062. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4063. var out_count_five int64
  4064. for _, item := range flowGood {
  4065. out_count_five += item.Count
  4066. }
  4067. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4068. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4069. if out_count_five != parseIntCount {
  4070. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4071. detail := models.AutomaticReduceDetail{
  4072. WarehouseOutId: 0,
  4073. WarehouseOutOrderNumber: "",
  4074. PatientId: p.PatientId,
  4075. Ctime: time.Now().Unix(),
  4076. Mtime: 0,
  4077. Status: 1,
  4078. RecordTime: p.RecordDate,
  4079. OrgId: p.UserOrgId,
  4080. GoodId: p.ProjectId,
  4081. GoodTypeId: 0,
  4082. Count: parseIntCount,
  4083. Type: 0,
  4084. ProjectId: lastHisProject.ID,
  4085. StorehouseId: 0,
  4086. }
  4087. service.CreateNewAutoDetail(detail, tx)
  4088. }
  4089. // //查询耗材最后一次出库记录
  4090. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4091. // //查询默认出库仓库库存
  4092. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4093. // if len(wareOut) > 0 {
  4094. //
  4095. // for _, it := range wareOut {
  4096. // //回退库存
  4097. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4098. //
  4099. // //删除出库记录
  4100. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4101. //
  4102. // }
  4103. // }
  4104. //
  4105. // timeStr := time.Now().Format("2006-01-02")
  4106. // timeArr := strings.Split(timeStr, "-")
  4107. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4108. //
  4109. // total = total + 1
  4110. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4111. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4112. // number = number + total
  4113. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4114. //
  4115. // operation_time := time.Now().Unix()
  4116. // creater := c.GetAdminUserInfo().AdminUser.Id
  4117. //
  4118. // recordDateStr := time.Now().Format("2006-01-02")
  4119. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4120. // nowtime := recordDate.Unix()
  4121. // warehouseOut := models.WarehouseOut{
  4122. // WarehouseOutOrderNumber: warehousing_out_order,
  4123. // OperationTime: operation_time,
  4124. // OrgId: adminInfo.CurrentOrgId,
  4125. // Creater: creater,
  4126. // Ctime: time.Now().Unix(),
  4127. // Status: 1,
  4128. // WarehouseOutTime: nowtime,
  4129. // Type: 1,
  4130. // StorehouseId: storeConfig.StorehouseOutInfo,
  4131. // IsCheck: 1,
  4132. // IsSys: 1,
  4133. // }
  4134. // //查询是否生成出库单
  4135. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4136. // if out.ID == 0 {
  4137. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4138. // }
  4139. //
  4140. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4141. //
  4142. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4143. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4144. //
  4145. // dialyPrepareOne := models.DialysisBeforePrepare{
  4146. // GoodTypeId: goodObj.GoodTypeId,
  4147. // GoodId: p.ProjectId,
  4148. // PatientId: p.PatientId,
  4149. // RecordDate: p.RecordDate,
  4150. // UserOrgId: adminInfo.CurrentOrgId,
  4151. // Count: parseIntCount,
  4152. // Ctime: time.Now().Unix(),
  4153. // Creater: creater,
  4154. // Status: 1,
  4155. // StorehouseId: houseConfig.StorehouseOutInfo,
  4156. // ProjectId: lastHisProject.ID,
  4157. // }
  4158. // //判断是否是零用耗材(非零用)
  4159. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4160. //
  4161. // //查询历史出库数据
  4162. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4163. // var out_count int64
  4164. // for _, item := range flowGood {
  4165. // out_count += item.Count
  4166. // }
  4167. // //如果历史数和当前数据不想等才进行退库出库
  4168. // if out_count != parseIntCount {
  4169. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4170. //
  4171. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4172. // detail := models.AutomaticReduceDetail{
  4173. // WarehouseOutId: 0,
  4174. // WarehouseOutOrderNumber: "",
  4175. // PatientId: p.PatientId,
  4176. // Ctime: time.Now().Unix(),
  4177. // Mtime: 0,
  4178. // Status: 1,
  4179. // RecordTime: p.RecordDate,
  4180. // OrgId: p.UserOrgId,
  4181. // GoodId: p.ProjectId,
  4182. // GoodTypeId: 0,
  4183. // Count: parseIntCount,
  4184. // Type: 0,
  4185. // ProjectId: lastHisProject.ID,
  4186. // StorehouseId: 0,
  4187. // }
  4188. //
  4189. // service.CreateNewAutoDetail(detail, tx)
  4190. //
  4191. // //查询剩余库存
  4192. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4193. // var sum_count int64
  4194. // for _, item := range goodList {
  4195. // sum_count += item.StockCount
  4196. // }
  4197. //
  4198. // //更新剩余库存
  4199. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4200. //
  4201. // //耗材
  4202. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4203. //
  4204. // }
  4205. // //判断是否是零用耗材(零用但是是出库耗材)
  4206. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4207. //
  4208. // //查询历史出库数据
  4209. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4210. // var out_count int64
  4211. // for _, item := range flowGood {
  4212. // out_count += item.Count
  4213. // }
  4214. // //如果历史数和当前数据不想等才进行退库出库
  4215. // if out_count != parseIntCount {
  4216. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4217. //
  4218. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4219. // detail := models.AutomaticReduceDetail{
  4220. // WarehouseOutId: 0,
  4221. // WarehouseOutOrderNumber: "",
  4222. // PatientId: p.PatientId,
  4223. // Ctime: time.Now().Unix(),
  4224. // Mtime: 0,
  4225. // Status: 1,
  4226. // RecordTime: p.RecordDate,
  4227. // OrgId: p.UserOrgId,
  4228. // GoodId: p.ProjectId,
  4229. // GoodTypeId: 0,
  4230. // Count: parseIntCount,
  4231. // Type: 0,
  4232. // ProjectId: p.ID,
  4233. // StorehouseId: 0,
  4234. // }
  4235. //
  4236. // service.CreateNewAutoDetail(detail, tx)
  4237. //
  4238. // //查询剩余库存
  4239. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4240. // var sum_count int64
  4241. // for _, item := range goodList {
  4242. // sum_count += item.StockCount
  4243. // }
  4244. //
  4245. // //更新剩余库存
  4246. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4247. //
  4248. // //耗材
  4249. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4250. // }
  4251. //
  4252. // }
  4253. //
  4254. // }
  4255. //
  4256. //}
  4257. //记录日志
  4258. byterequest, _ := json.Marshal(p)
  4259. adviceLog := models.XtDoctorAdviceLog{
  4260. UserOrgId: p.UserOrgId,
  4261. PatientId: p.PatientId,
  4262. AdminUserId: adminInfo.AdminUser.Id,
  4263. Module: 1,
  4264. ErrLog: string(byterequest),
  4265. Status: 1,
  4266. Ctime: time.Now().Unix(),
  4267. Mtime: 0,
  4268. Source: "电脑端新建his项目",
  4269. RecordDate: p.RecordDate,
  4270. }
  4271. service.CreateDoctorAdviceLog(adviceLog)
  4272. projectList = append(projectList, p)
  4273. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4274. //新增或者编辑项目,修改对应的标签数据
  4275. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4276. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4277. var label models.HisLabelPrintInfo
  4278. project, _ := service.GetProjectDetail(p.ProjectId)
  4279. if project.CostClassify == 3 { //类别为检验检查
  4280. if p.TeamId > 0 { //检验检查组套
  4281. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4282. if tempLabel.ID == 0 {
  4283. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4284. label.Number = tempPrescription.PrescriptionNumber
  4285. label.ProjectId = project.ID
  4286. label.Status = 1
  4287. label.IsPrint = 2
  4288. label.DoctorId = info.DoctorId
  4289. label.UserOrgId = p.UserOrgId
  4290. label.PatientId = patient_id
  4291. label.RecordDate = recordDateTime
  4292. label.Ctime = time.Now().Unix()
  4293. label.Mtime = time.Now().Unix()
  4294. label.ItemId = p.TeamId
  4295. label.FeedetlSn = p.FeedetlSn
  4296. label.PProjectId = p.ID
  4297. label.ProjectName = team.ProjectTeam
  4298. label.PatientName = patient.Name
  4299. service.CreateNewHisLabelRecord(&label, tx)
  4300. }
  4301. } else { //单条检验检查项目
  4302. label.Number = tempPrescription.PrescriptionNumber
  4303. label.ProjectId = project.ID
  4304. label.Status = 1
  4305. label.DoctorId = info.DoctorId
  4306. label.UserOrgId = p.UserOrgId
  4307. label.PatientId = patient_id
  4308. label.RecordDate = recordDateTime
  4309. label.IsPrint = 2
  4310. label.Ctime = time.Now().Unix()
  4311. label.Mtime = time.Now().Unix()
  4312. label.FeedetlSn = p.FeedetlSn
  4313. label.PProjectId = p.ID
  4314. label.ItemId = p.TeamId
  4315. label.ProjectName = project.ProjectName
  4316. label.PatientName = patient.Name
  4317. service.CreateNewHisLabelRecord(&label, tx)
  4318. }
  4319. }
  4320. }
  4321. }
  4322. }
  4323. }
  4324. }
  4325. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4326. //
  4327. // //耗材出库
  4328. // if p.Type == 3 {
  4329. //
  4330. // //对比当前数据和历史出库数据
  4331. //
  4332. // historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4333. //
  4334. // historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4335. //
  4336. // nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4337. //
  4338. // //如果当前处方数量大于历史数据,则需要出库
  4339. // if nowCount > historyCount {
  4340. //
  4341. // var cha_count int64
  4342. // cha_count = nowCount - historyCount
  4343. //
  4344. // timeStr := time.Now().Format("2006-01-02")
  4345. // timeArr := strings.Split(timeStr, "-")
  4346. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4347. //
  4348. // total = total + 1
  4349. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4350. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4351. // number = number + total
  4352. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4353. //
  4354. // operation_time := time.Now().Unix()
  4355. // creater := c.GetAdminUserInfo().AdminUser.Id
  4356. //
  4357. // recordDateStr := time.Now().Format("2006-01-02")
  4358. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4359. // nowtime := recordDate.Unix()
  4360. // warehouseOut := models.WarehouseOut{
  4361. // WarehouseOutOrderNumber: warehousing_out_order,
  4362. // OperationTime: operation_time,
  4363. // OrgId: adminInfo.CurrentOrgId,
  4364. // Creater: creater,
  4365. // Ctime: time.Now().Unix(),
  4366. // Status: 1,
  4367. // WarehouseOutTime: nowtime,
  4368. // Type: 1,
  4369. // StorehouseId: storeConfig.StorehouseOutInfo,
  4370. // IsCheck: 1,
  4371. // IsSys: 1,
  4372. // }
  4373. // //查询是否生成出库单
  4374. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4375. // if out.ID == 0 {
  4376. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4377. // }
  4378. //
  4379. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4380. //
  4381. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4382. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4383. //
  4384. // dialyPrepareOne := models.DialysisBeforePrepare{
  4385. // GoodTypeId: goodObj.GoodTypeId,
  4386. // GoodId: p.ProjectId,
  4387. // PatientId: p.PatientId,
  4388. // RecordDate: p.RecordDate,
  4389. // UserOrgId: adminInfo.CurrentOrgId,
  4390. // Count: cha_count,
  4391. // Ctime: time.Now().Unix(),
  4392. // Creater: creater,
  4393. // Status: 1,
  4394. // StorehouseId: houseConfig.StorehouseOutInfo,
  4395. // ProjectId: p.ID,
  4396. // }
  4397. // //出库
  4398. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4399. //
  4400. // }
  4401. //
  4402. // //如果当前处方数量小于历史数据,怎需要退库
  4403. // if nowCount < historyCount {
  4404. //
  4405. // var cha_count int64
  4406. // cha_count = historyCount - nowCount
  4407. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4408. // creater := c.GetAdminUserInfo().AdminUser.Id
  4409. //
  4410. // newPrescriptionProject := &models.HisPrescriptionProject{
  4411. // ID: p.ID,
  4412. // ProjectId: p.ProjectId,
  4413. // Price: p.Price,
  4414. // UserOrgId: p.UserOrgId,
  4415. // Status: 1,
  4416. // Ctime: time.Now().Unix(),
  4417. // Mtime: time.Now().Unix(),
  4418. // PatientId: p.PatientId,
  4419. // HisPatientId: p.HisPatientId,
  4420. // RecordDate: p.RecordDate,
  4421. // PrescriptionId: p.PrescriptionId,
  4422. // Count: p.Count,
  4423. // FeedetlSn: p.FeedetlSn,
  4424. // MedListCodg: p.MedListCodg,
  4425. // SingleDose: p.SingleDose,
  4426. // DeliveryWay: p.DeliveryWay,
  4427. // ExecutionFrequency: p.ExecutionFrequency,
  4428. // Day: p.Day,
  4429. // HisProject: models.HisProject{},
  4430. // GoodInfo: models.GoodInfo{},
  4431. // Remark: p.Remark,
  4432. // Unit: p.Unit,
  4433. // Type: p.Type,
  4434. // Doctor: p.Doctor,
  4435. // ExecutionTime: p.ExecutionTime,
  4436. // ExecutionStaff: p.ExecutionStaff,
  4437. // ExecutionState: p.ExecutionState,
  4438. // CheckTime: p.CheckTime,
  4439. // CheckState: p.CheckState,
  4440. // Checker: p.Checker,
  4441. // StartTime: p.StartTime,
  4442. // TeamId: p.TeamId,
  4443. // XtHisProjectTeam: models.XtHisProjectTeam{},
  4444. // FrequencyType: p.FrequencyType,
  4445. // DayCount: p.DayCount,
  4446. // WeekDay: p.WeekDay,
  4447. // IsCheckTeam: p.IsCheckTeam,
  4448. // HisOrderInfo: models.HisOrderInfo{},
  4449. // ExecutionFrequencyId: p.ExecutionFrequencyId,
  4450. // IsOut: p.IsOut,
  4451. // YbSyncStatus: p.YbSyncStatus,
  4452. // }
  4453. //
  4454. // service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4455. //
  4456. // service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4457. //
  4458. // }
  4459. //
  4460. // if nowCount == historyCount {
  4461. // if historyCount == 0 {
  4462. // recordDateStr := time.Now().Format("2006-01-02")
  4463. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4464. // nowtime := recordDate.Unix()
  4465. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4466. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4467. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4468. // creater := c.GetAdminUserInfo().AdminUser.Id
  4469. // dialyPrepareOne := models.DialysisBeforePrepare{
  4470. // GoodTypeId: goodObj.GoodTypeId,
  4471. // GoodId: p.ProjectId,
  4472. // PatientId: p.PatientId,
  4473. // RecordDate: p.RecordDate,
  4474. // UserOrgId: adminInfo.CurrentOrgId,
  4475. // Count: nowCount,
  4476. // Ctime: time.Now().Unix(),
  4477. // Creater: creater,
  4478. // Status: 1,
  4479. // StorehouseId: houseConfig.StorehouseOutInfo,
  4480. // ProjectId: p.ID,
  4481. // }
  4482. // //出库
  4483. // service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4484. // }
  4485. // }
  4486. //
  4487. // lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4488. // //查询历史出库数据
  4489. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4490. //
  4491. // var out_count_five int64
  4492. // for _, item := range flowGood {
  4493. // out_count_five += item.Count
  4494. // }
  4495. // parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4496. //
  4497. // //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4498. // if out_count_five != parseIntCount {
  4499. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4500. // detail := models.AutomaticReduceDetail{
  4501. // WarehouseOutId: 0,
  4502. // WarehouseOutOrderNumber: "",
  4503. // PatientId: p.PatientId,
  4504. // Ctime: time.Now().Unix(),
  4505. // Mtime: 0,
  4506. // Status: 1,
  4507. // RecordTime: p.RecordDate,
  4508. // OrgId: p.UserOrgId,
  4509. // GoodId: p.ProjectId,
  4510. // GoodTypeId: 0,
  4511. // Count: parseIntCount,
  4512. // Type: 0,
  4513. // ProjectId: lastHisProject.ID,
  4514. // StorehouseId: 0,
  4515. // }
  4516. //
  4517. // service.CreateNewAutoDetail(detail, tx)
  4518. // }
  4519. // // //查询耗材最后一次出库记录
  4520. // // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4521. // // //查询默认出库仓库库存
  4522. // // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4523. // // if len(wareOut) > 0 {
  4524. // //
  4525. // // for _, it := range wareOut {
  4526. // // //回退库存
  4527. // // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4528. // //
  4529. // // //删除出库记录
  4530. // // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4531. // //
  4532. // // }
  4533. // // }
  4534. // //
  4535. // // timeStr := time.Now().Format("2006-01-02")
  4536. // // timeArr := strings.Split(timeStr, "-")
  4537. // // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4538. // //
  4539. // // total = total + 1
  4540. // // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4541. // // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4542. // // number = number + total
  4543. // // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4544. // //
  4545. // // operation_time := time.Now().Unix()
  4546. // // creater := c.GetAdminUserInfo().AdminUser.Id
  4547. // //
  4548. // // recordDateStr := time.Now().Format("2006-01-02")
  4549. // // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4550. // // nowtime := recordDate.Unix()
  4551. // // warehouseOut := models.WarehouseOut{
  4552. // // WarehouseOutOrderNumber: warehousing_out_order,
  4553. // // OperationTime: operation_time,
  4554. // // OrgId: adminInfo.CurrentOrgId,
  4555. // // Creater: creater,
  4556. // // Ctime: time.Now().Unix(),
  4557. // // Status: 1,
  4558. // // WarehouseOutTime: nowtime,
  4559. // // Type: 1,
  4560. // // StorehouseId: storeConfig.StorehouseOutInfo,
  4561. // // IsCheck: 1,
  4562. // // IsSys: 1,
  4563. // // }
  4564. // // //查询是否生成出库单
  4565. // // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4566. // // if out.ID == 0 {
  4567. // // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4568. // // }
  4569. // //
  4570. // // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4571. // //
  4572. // // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4573. // // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4574. // //
  4575. // // dialyPrepareOne := models.DialysisBeforePrepare{
  4576. // // GoodTypeId: goodObj.GoodTypeId,
  4577. // // GoodId: p.ProjectId,
  4578. // // PatientId: p.PatientId,
  4579. // // RecordDate: p.RecordDate,
  4580. // // UserOrgId: adminInfo.CurrentOrgId,
  4581. // // Count: parseIntCount,
  4582. // // Ctime: time.Now().Unix(),
  4583. // // Creater: creater,
  4584. // // Status: 1,
  4585. // // StorehouseId: houseConfig.StorehouseOutInfo,
  4586. // // ProjectId: lastHisProject.ID,
  4587. // // }
  4588. // // //判断是否是零用耗材(非零用)
  4589. // // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4590. // //
  4591. // // //查询历史出库数据
  4592. // // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4593. // // var out_count int64
  4594. // // for _, item := range flowGood {
  4595. // // out_count += item.Count
  4596. // // }
  4597. // // //如果历史数和当前数据不想等才进行退库出库
  4598. // // if out_count != parseIntCount {
  4599. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4600. // //
  4601. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4602. // // detail := models.AutomaticReduceDetail{
  4603. // // WarehouseOutId: 0,
  4604. // // WarehouseOutOrderNumber: "",
  4605. // // PatientId: p.PatientId,
  4606. // // Ctime: time.Now().Unix(),
  4607. // // Mtime: 0,
  4608. // // Status: 1,
  4609. // // RecordTime: p.RecordDate,
  4610. // // OrgId: p.UserOrgId,
  4611. // // GoodId: p.ProjectId,
  4612. // // GoodTypeId: 0,
  4613. // // Count: parseIntCount,
  4614. // // Type: 0,
  4615. // // ProjectId: lastHisProject.ID,
  4616. // // StorehouseId: 0,
  4617. // // }
  4618. // //
  4619. // // service.CreateNewAutoDetail(detail, tx)
  4620. // //
  4621. // // //查询剩余库存
  4622. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4623. // // var sum_count int64
  4624. // // for _, item := range goodList {
  4625. // // sum_count += item.StockCount
  4626. // // }
  4627. // //
  4628. // // //更新剩余库存
  4629. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4630. // //
  4631. // // //耗材
  4632. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4633. // //
  4634. // // }
  4635. // // //判断是否是零用耗材(零用但是是出库耗材)
  4636. // // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4637. // //
  4638. // // //查询历史出库数据
  4639. // // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4640. // // var out_count int64
  4641. // // for _, item := range flowGood {
  4642. // // out_count += item.Count
  4643. // // }
  4644. // // //如果历史数和当前数据不想等才进行退库出库
  4645. // // if out_count != parseIntCount {
  4646. // // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4647. // //
  4648. // // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4649. // // detail := models.AutomaticReduceDetail{
  4650. // // WarehouseOutId: 0,
  4651. // // WarehouseOutOrderNumber: "",
  4652. // // PatientId: p.PatientId,
  4653. // // Ctime: time.Now().Unix(),
  4654. // // Mtime: 0,
  4655. // // Status: 1,
  4656. // // RecordTime: p.RecordDate,
  4657. // // OrgId: p.UserOrgId,
  4658. // // GoodId: p.ProjectId,
  4659. // // GoodTypeId: 0,
  4660. // // Count: parseIntCount,
  4661. // // Type: 0,
  4662. // // ProjectId: p.ID,
  4663. // // StorehouseId: 0,
  4664. // // }
  4665. // //
  4666. // // service.CreateNewAutoDetail(detail, tx)
  4667. // //
  4668. // // //查询剩余库存
  4669. // // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4670. // // var sum_count int64
  4671. // // for _, item := range goodList {
  4672. // // sum_count += item.StockCount
  4673. // // }
  4674. // //
  4675. // // //更新剩余库存
  4676. // // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4677. // //
  4678. // // //耗材
  4679. // // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4680. // // }
  4681. // //
  4682. // // }
  4683. // //
  4684. // // }
  4685. // //
  4686. // //}
  4687. //
  4688. // //记录日志
  4689. // byterequest, _ := json.Marshal(p)
  4690. // adviceLog := models.XtDoctorAdviceLog{
  4691. // UserOrgId: p.UserOrgId,
  4692. // PatientId: p.PatientId,
  4693. // AdminUserId: adminInfo.AdminUser.Id,
  4694. // Module: 1,
  4695. // ErrLog: string(byterequest),
  4696. // Status: 1,
  4697. // Ctime: time.Now().Unix(),
  4698. // Mtime: 0,
  4699. // Source: "电脑端新建his项目",
  4700. // RecordDate: p.RecordDate,
  4701. // }
  4702. // service.CreateDoctorAdviceLog(adviceLog)
  4703. //
  4704. // projectList = append(projectList, p)
  4705. //
  4706. // if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4707. // //新增或者编辑项目,修改对应的标签数据
  4708. // labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4709. // if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4710. // var label models.HisLabelPrintInfo
  4711. // project, _ := service.GetProjectDetail(p.ProjectId)
  4712. // if project.CostClassify == 3 { //类别为检验检查
  4713. // if p.TeamId > 0 { //检验检查组套
  4714. // tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4715. // if tempLabel.ID == 0 {
  4716. // team, _ := service.GetProjectTeamDetail(p.TeamId)
  4717. // label.Number = tempPrescription.PrescriptionNumber
  4718. // label.ProjectId = project.ID
  4719. // label.Status = 1
  4720. // label.IsPrint = 2
  4721. // label.DoctorId = info.DoctorId
  4722. // label.UserOrgId = p.UserOrgId
  4723. // label.PatientId = patient_id
  4724. // label.RecordDate = recordDateTime
  4725. // label.Ctime = time.Now().Unix()
  4726. // label.Mtime = time.Now().Unix()
  4727. // label.ItemId = p.TeamId
  4728. // label.FeedetlSn = p.FeedetlSn
  4729. // label.PProjectId = p.ID
  4730. // label.ProjectName = team.ProjectTeam
  4731. // label.PatientName = patient.Name
  4732. // service.CreateNewHisLabelRecord(&label, tx)
  4733. // }
  4734. // } else { //单条检验检查项目
  4735. // label.Number = tempPrescription.PrescriptionNumber
  4736. // label.ProjectId = project.ID
  4737. // label.Status = 1
  4738. // label.DoctorId = info.DoctorId
  4739. // label.UserOrgId = p.UserOrgId
  4740. // label.PatientId = patient_id
  4741. // label.RecordDate = recordDateTime
  4742. // label.IsPrint = 2
  4743. // label.Ctime = time.Now().Unix()
  4744. // label.Mtime = time.Now().Unix()
  4745. // label.FeedetlSn = p.FeedetlSn
  4746. // label.PProjectId = p.ID
  4747. // label.ItemId = p.TeamId
  4748. // label.ProjectName = project.ProjectName
  4749. // label.PatientName = patient.Name
  4750. // service.CreateNewHisLabelRecord(&label, tx)
  4751. // }
  4752. // }
  4753. // }
  4754. // }
  4755. //
  4756. // }
  4757. //}
  4758. }
  4759. //插入检验数据
  4760. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4761. //新增或者编辑项目,修改对应的标签数据
  4762. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4763. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4764. var label models.HisLabelPrintInfo
  4765. project, _ := service.GetProjectDetail(p.ProjectId)
  4766. if project.CostClassify == 3 { //类别为检验检查
  4767. if p.TeamId > 0 { //检验检查组套
  4768. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4769. if tempLabel.ID == 0 {
  4770. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4771. label.Number = tempPrescription.PrescriptionNumber
  4772. label.ProjectId = project.ID
  4773. label.Status = 1
  4774. label.IsPrint = 2
  4775. label.DoctorId = info.DoctorId
  4776. label.UserOrgId = p.UserOrgId
  4777. label.PatientId = patient_id
  4778. label.RecordDate = recordDateTime
  4779. label.Ctime = time.Now().Unix()
  4780. label.Mtime = time.Now().Unix()
  4781. label.ItemId = p.TeamId
  4782. label.FeedetlSn = p.FeedetlSn
  4783. label.PProjectId = p.ID
  4784. label.ProjectName = team.ProjectTeam
  4785. label.PatientName = patient.Name
  4786. service.CreateHisLabelRecord(&label)
  4787. }
  4788. } else { //单条检验检查项目
  4789. label.Number = tempPrescription.PrescriptionNumber
  4790. label.ProjectId = project.ID
  4791. label.Status = 1
  4792. label.DoctorId = info.DoctorId
  4793. label.UserOrgId = p.UserOrgId
  4794. label.PatientId = patient_id
  4795. label.RecordDate = recordDateTime
  4796. label.IsPrint = 2
  4797. label.Ctime = time.Now().Unix()
  4798. label.Mtime = time.Now().Unix()
  4799. label.FeedetlSn = p.FeedetlSn
  4800. label.PProjectId = p.ID
  4801. label.ItemId = p.TeamId
  4802. label.ProjectName = project.ProjectName
  4803. label.PatientName = patient.Name
  4804. service.CreateHisLabelRecord(&label)
  4805. }
  4806. }
  4807. }
  4808. }
  4809. service.CreateNewHisProjectTwo(&p, tx)
  4810. var randNum int
  4811. randNum = rand.Intn(1000) + 1000
  4812. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4813. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4814. if goodBase.ID > 0 {
  4815. tx.Rollback()
  4816. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4817. return
  4818. }
  4819. service.CreateNewHisProjectTwo(&p, tx)
  4820. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4821. //查询剩余库存
  4822. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4823. var sum_count int64
  4824. for _, item := range goodList {
  4825. sum_count += item.StockCount
  4826. }
  4827. //更新剩余库存
  4828. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4829. //耗材
  4830. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4831. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4832. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4833. if len(outInfoTwo) > 0 {
  4834. for _, item := range outInfoTwo {
  4835. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4836. }
  4837. }
  4838. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4839. if len(drugAutoDetail) > 0 {
  4840. for _, item := range drugAutoDetail {
  4841. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4842. }
  4843. }
  4844. tx.Commit()
  4845. }
  4846. }
  4847. }
  4848. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4849. // addition := items["addition"].([]interface{})
  4850. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4851. // ctime := time.Now().Unix()
  4852. // mtime := ctime
  4853. // if len(addition) > 0 {
  4854. // for _, item := range addition {
  4855. // var s models.HisAdditionalCharge
  4856. // s.PrescriptionId = tempPrescription.ID
  4857. // s.Status = 1
  4858. // s.UserOrgId = adminInfo.CurrentOrgId
  4859. // s.RecordDate = recordDateTime
  4860. // s.CreatedTime = ctime
  4861. // s.UpdatedTime = mtime
  4862. // s.PatientId = patient_id
  4863. // s.HisPatientId = his_patient_id
  4864. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4865. // if errcode > 0 {
  4866. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4867. // return
  4868. // }
  4869. // service.CreateAdditionalCharge(&s)
  4870. // var randNum int
  4871. // randNum = rand.Intn(10000) + 1000
  4872. // timestamp := time.Now().Unix()
  4873. // tempTime := time.Unix(timestamp, 0)
  4874. // timeFormat := tempTime.Format("20060102150405")
  4875. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4876. // service.CreateAdditionalCharge(&s)
  4877. //
  4878. // }
  4879. // }
  4880. //}
  4881. }
  4882. }
  4883. }
  4884. tx.Commit()
  4885. if err == nil {
  4886. c.ServeSuccessJSON(map[string]interface{}{
  4887. "msg": "保存成功",
  4888. })
  4889. return
  4890. } else {
  4891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4892. return
  4893. }
  4894. } else {
  4895. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4896. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4897. var tempPrescription *models.HisPrescription
  4898. if len(prescriptions) > 0 {
  4899. for _, item := range prescriptions {
  4900. items := item.(map[string]interface{})
  4901. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4902. utils.ErrorLog("id")
  4903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4904. return
  4905. }
  4906. id := int64(items["id"].(float64))
  4907. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4908. tempPrescription = &new_prescription
  4909. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4910. utils.ErrorLog("type")
  4911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4912. return
  4913. }
  4914. types := int64(items["type"].(float64))
  4915. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4916. utils.ErrorLog("med_type")
  4917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4918. return
  4919. }
  4920. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4921. if med_type == "0" {
  4922. med_type = "14"
  4923. }
  4924. //if order_status == 0 {
  4925. // order_status = 1
  4926. //}
  4927. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4928. // utils.ErrorLog("diagnoses")
  4929. //}
  4930. diagnoses, _ := items["diagnoses"].(string)
  4931. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4932. utils.ErrorLog("pre_time")
  4933. }
  4934. preTime, _ := items["pre_time"].(string)
  4935. timeLayout := "2006-01-02"
  4936. loc, _ := time.LoadLocation("Local")
  4937. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4938. //result := strings.Split(preTime, " ")
  4939. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4940. if err != nil {
  4941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4942. return
  4943. }
  4944. pTime := theTime2.Unix()
  4945. ctime := time.Now().Unix()
  4946. if tempPrescription.ID == 0 {
  4947. prescription := &models.HisPrescription{
  4948. ID: 0,
  4949. PatientId: patient_id,
  4950. UserOrgId: adminInfo.CurrentOrgId,
  4951. RecordDate: recordDateTime,
  4952. Ctime: ctime,
  4953. Mtime: ctime,
  4954. Type: types,
  4955. Modifier: adminInfo.AdminUser.Id,
  4956. Creator: adminInfo.AdminUser.Id,
  4957. Status: 1,
  4958. Doctor: role.UserName,
  4959. HisPatientId: his_patient_id,
  4960. OrderStatus: 1,
  4961. BatchNumber: "",
  4962. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4963. PreTime: pTime,
  4964. PType: p_type,
  4965. MedType: med_type,
  4966. Diagnose: diagnoses,
  4967. }
  4968. tempPrescription = prescription
  4969. service.SaveHisPrescription(tempPrescription)
  4970. redis := service.RedisClient()
  4971. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4972. redis.Set(key, "", time.Second)
  4973. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4974. redis.Set(keyOne, "", time.Second)
  4975. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4976. redis.Set(keySeven, "", time.Second)
  4977. defer redis.Close()
  4978. } else {
  4979. tempPrescription.ID = id
  4980. tempPrescription.Type = types
  4981. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4982. tempPrescription.Mtime = time.Now().Unix()
  4983. tempPrescription.Doctor = role.UserName
  4984. //tempPrescription.OrderStatus = order_status
  4985. tempPrescription.PreTime = pTime
  4986. tempPrescription.MedType = med_type
  4987. tempPrescription.Diagnose = diagnoses
  4988. service.SaveHisPrescription(tempPrescription)
  4989. redis := service.RedisClient()
  4990. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4991. redis.Set(key, "", time.Second)
  4992. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4993. redis.Set(keyOne, "", time.Second)
  4994. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4995. redis.Set(keySeven, "", time.Second)
  4996. defer redis.Close()
  4997. }
  4998. //service.SaveHisPrescription(prescription)
  4999. //更改患者挂号状态
  5000. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5001. fmt.Println("更改失败", err2)
  5002. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5003. advices := items["advices"].([]interface{})
  5004. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5005. groupNo := int64(0)
  5006. if len(advices) > 0 {
  5007. for _, advice := range advices {
  5008. var s models.HisDoctorAdviceInfo
  5009. s.PrescriptionId = tempPrescription.ID
  5010. s.AdviceType = 2
  5011. s.AdviceDoctor = doctor_id
  5012. s.StopState = 2
  5013. s.ExecutionState = 2
  5014. s.AdviceDate = theTime3.Unix()
  5015. s.Status = 1
  5016. s.UserOrgId = adminInfo.CurrentOrgId
  5017. s.RecordDate = theTime3.Unix()
  5018. s.StartTime = tempPrescription.PreTime
  5019. s.Groupno = groupNo
  5020. s.PatientId = patient_id
  5021. s.HisPatientId = his_patient_id
  5022. s.StartTime = pTime
  5023. s.IsSettle = 2
  5024. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  5025. if errcode > 0 {
  5026. c.ServeFailJSONWithSGJErrorCode(errcode)
  5027. return
  5028. }
  5029. s.StartTime = pTime
  5030. var total_count int64 //处方总库存
  5031. //查询改药品信息
  5032. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  5033. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  5034. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5035. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5036. total_count += prescribingNumberSeven * medical.MinNumber
  5037. }
  5038. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5039. total_count += prescribingNumberSeven
  5040. }
  5041. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  5042. total_count += prescribingNumberSeven
  5043. }
  5044. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5045. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5046. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5047. if s.Price != lastWarehouse.RetailPrice {
  5048. s.Price = lastWarehouse.RetailPrice
  5049. }
  5050. if s.Price == 0 {
  5051. if lastWarehouse.ID == 0 {
  5052. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  5053. s.Price = lastWarehouseTwo.RetailPrice
  5054. }
  5055. }
  5056. }
  5057. if adminInfo.CurrentOrgId != 10206 {
  5058. if s.ID == 0 {
  5059. //查询改药品是否已经停用
  5060. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  5061. if base.ID > 0 {
  5062. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  5063. return
  5064. }
  5065. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  5066. if drugMedical.SumCount == 0 {
  5067. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  5068. return
  5069. }
  5070. }
  5071. }
  5072. //赤峰
  5073. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  5074. drug, _ := service.GetDrugByGoodId(s.DrugId)
  5075. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  5076. if info.RetailPrice > 0 {
  5077. if s.DeliveryWay == "口服" {
  5078. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5079. s.Price = drug.RetailPrice
  5080. }
  5081. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5082. s.Price = info.RetailPrice
  5083. }
  5084. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5085. s.Price = info.RetailPrice
  5086. }
  5087. }
  5088. }
  5089. }
  5090. service.CreateHisDoctorAdvice(&s)
  5091. //记录日志
  5092. byterequest, _ := json.Marshal(s)
  5093. adviceLog := models.XtDoctorAdviceLog{
  5094. UserOrgId: s.UserOrgId,
  5095. PatientId: s.PatientId,
  5096. AdminUserId: adminInfo.AdminUser.Id,
  5097. Module: 1,
  5098. ErrLog: string(byterequest),
  5099. Status: 1,
  5100. Ctime: time.Now().Unix(),
  5101. Mtime: 0,
  5102. Source: "电脑端新建his医嘱",
  5103. RecordDate: s.AdviceDate,
  5104. }
  5105. service.CreateDoctorAdviceLog(adviceLog)
  5106. //存储切片中
  5107. adviceList = append(adviceList, s)
  5108. redis := service.RedisClient()
  5109. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5110. redis.Set(key, "", time.Second)
  5111. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5112. redis.Set(keyOne, "", time.Second)
  5113. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5114. redis.Set(keySeven, "", time.Second)
  5115. var randNum int
  5116. randNum = rand.Intn(1000) + 1000
  5117. //timestamp := time.Now().Unix()
  5118. //tempTime := time.Unix(timestamp, 0)
  5119. //timeFormat := tempTime.Format("20060102150405")
  5120. s.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  5121. service.CreateHisDoctorAdvice(&s)
  5122. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5123. redis.Set(keySix, "", time.Second)
  5124. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5125. redis.Set(keyFive, "", time.Second)
  5126. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5127. redis.Set(keyEight, "", time.Second)
  5128. defer redis.Close()
  5129. }
  5130. }
  5131. }
  5132. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5133. projects := items["project"].([]interface{})
  5134. if len(projects) > 0 {
  5135. for _, project := range projects {
  5136. var p models.HisPrescriptionProject
  5137. p.PrescriptionId = tempPrescription.ID
  5138. p.PatientId = patient_id
  5139. p.RecordDate = theTime3.Unix()
  5140. p.Doctor = doctor_id
  5141. p.UserOrgId = adminInfo.CurrentOrgId
  5142. p.HisPatientId = his_patient_id
  5143. p.Status = 1
  5144. p.StartTime = pTime
  5145. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  5146. if errcode > 0 {
  5147. c.ServeFailJSONWithSGJErrorCode(errcode)
  5148. return
  5149. }
  5150. if p.ID == 0 {
  5151. p.IsOut = 2
  5152. }
  5153. if p.ID > 0 {
  5154. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5155. p.IsOut = projectDetail.IsOut
  5156. }
  5157. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5158. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5159. if p.Type == 3 {
  5160. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5161. if p.Price != lastWarehouse.PackingPrice {
  5162. p.Price = lastWarehouse.PackingPrice
  5163. }
  5164. if p.Price == 0 {
  5165. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5166. p.Price = lastWarehouseTwo.PackingPrice
  5167. }
  5168. if p.Unit == "" {
  5169. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5170. p.Unit = goodInfoOne.PackingUnit
  5171. }
  5172. }
  5173. }
  5174. if adminInfo.CurrentOrgId != 10206 {
  5175. if p.Type == 3 {
  5176. if p.ID == 0 {
  5177. //查询该耗材是否停用
  5178. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5179. //表示该耗材已经停用,不能保存
  5180. if goodInfoSeven.ID == 0 {
  5181. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5182. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5183. return
  5184. }
  5185. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5186. if goodInfoOne.SumCount == 0 {
  5187. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5188. return
  5189. }
  5190. }
  5191. }
  5192. }
  5193. service.CreateHisProjectTwo(&p)
  5194. //记录日志
  5195. byterequest, _ := json.Marshal(p)
  5196. adviceLog := models.XtDoctorAdviceLog{
  5197. UserOrgId: p.UserOrgId,
  5198. PatientId: p.PatientId,
  5199. AdminUserId: adminInfo.AdminUser.Id,
  5200. Module: 1,
  5201. ErrLog: string(byterequest),
  5202. Status: 1,
  5203. Ctime: time.Now().Unix(),
  5204. Mtime: 0,
  5205. Source: "电脑端新建his项目",
  5206. RecordDate: p.RecordDate,
  5207. }
  5208. service.CreateDoctorAdviceLog(adviceLog)
  5209. projectList = append(projectList, p)
  5210. var randNum int
  5211. randNum = rand.Intn(1000) + 1000
  5212. p.FeedetlSn = strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  5213. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  5214. //新增或者编辑项目,修改对应的标签数据
  5215. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  5216. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  5217. var label models.HisLabelPrintInfo
  5218. project, _ := service.GetProjectDetail(p.ProjectId)
  5219. if project.CostClassify == 3 { //类别为检验检查
  5220. if p.TeamId > 0 { //检验检查组套
  5221. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  5222. if tempLabel.ID == 0 {
  5223. team, _ := service.GetProjectTeamDetail(p.TeamId)
  5224. label.Number = tempPrescription.PrescriptionNumber
  5225. label.ProjectId = project.ID
  5226. label.Status = 1
  5227. label.IsPrint = 2
  5228. label.DoctorId = info.DoctorId
  5229. label.UserOrgId = p.UserOrgId
  5230. label.PatientId = patient_id
  5231. label.RecordDate = recordDateTime
  5232. label.Ctime = time.Now().Unix()
  5233. label.Mtime = time.Now().Unix()
  5234. label.ItemId = p.TeamId
  5235. label.FeedetlSn = p.FeedetlSn
  5236. label.PProjectId = p.ID
  5237. label.ProjectName = team.ProjectTeam
  5238. label.PatientName = patient.Name
  5239. service.CreateHisLabelRecord(&label)
  5240. }
  5241. } else { //单条检验检查项目
  5242. label.Number = tempPrescription.PrescriptionNumber
  5243. label.ProjectId = project.ID
  5244. label.Status = 1
  5245. label.DoctorId = info.DoctorId
  5246. label.UserOrgId = p.UserOrgId
  5247. label.PatientId = patient_id
  5248. label.RecordDate = recordDateTime
  5249. label.IsPrint = 2
  5250. label.Ctime = time.Now().Unix()
  5251. label.Mtime = time.Now().Unix()
  5252. label.FeedetlSn = p.FeedetlSn
  5253. label.PProjectId = p.ID
  5254. label.ItemId = p.TeamId
  5255. label.ProjectName = project.ProjectName
  5256. label.PatientName = patient.Name
  5257. service.CreateHisLabelRecord(&label)
  5258. }
  5259. }
  5260. }
  5261. }
  5262. service.SaveHisProjectTwo(&p)
  5263. }
  5264. }
  5265. }
  5266. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5267. // addition := items["addition"].([]interface{})
  5268. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5269. // ctime := time.Now().Unix()
  5270. // mtime := ctime
  5271. // if len(addition) > 0 {
  5272. // for _, item := range addition {
  5273. // var s models.HisAdditionalCharge
  5274. // s.PrescriptionId = tempPrescription.ID
  5275. // s.Status = 1
  5276. // s.UserOrgId = adminInfo.CurrentOrgId
  5277. // s.RecordDate = recordDateTime
  5278. // s.CreatedTime = ctime
  5279. // s.UpdatedTime = mtime
  5280. // s.PatientId = patient_id
  5281. // s.HisPatientId = his_patient_id
  5282. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5283. // if errcode > 0 {
  5284. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5285. // return
  5286. // }
  5287. // service.CreateAdditionalCharge(&s)
  5288. // var randNum int
  5289. // randNum = rand.Intn(10000) + 1000
  5290. // timestamp := time.Now().Unix()
  5291. // tempTime := time.Unix(timestamp, 0)
  5292. // timeFormat := tempTime.Format("20060102150405")
  5293. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5294. // service.CreateAdditionalCharge(&s)
  5295. //
  5296. // }
  5297. // }
  5298. //}
  5299. }
  5300. }
  5301. //查询今日该患者开的药品处方
  5302. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5303. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5304. //药品出库
  5305. if drugOutConfig.IsOpen == 1 {
  5306. for _, item := range hisdoctorlist {
  5307. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5308. // 查询该药品最后一次出库记录
  5309. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5310. if len(druginfo) > 0 {
  5311. //回退库存
  5312. for _, it := range druginfo {
  5313. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5314. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5315. }
  5316. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5317. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5318. }
  5319. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5320. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5321. }
  5322. }
  5323. }
  5324. //删除记录
  5325. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5326. //查询最后一次数据
  5327. if drugOutConfig.IsOpen == 1 {
  5328. //出库
  5329. if drug.IsUse == 2 {
  5330. creater := adminInfo.AdminUser.Id
  5331. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5332. }
  5333. //更新字典里面的库存
  5334. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5335. var sum_count int64
  5336. for _, its := range stockInfo {
  5337. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5338. if its.MaxUnit == baseDrug.MaxUnit {
  5339. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5340. }
  5341. sum_count += its.StockMaxNumber + its.StockMinNumber
  5342. }
  5343. //更新基础库存
  5344. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5345. //剩余库存
  5346. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5347. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5348. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5349. }
  5350. }
  5351. }
  5352. //耗材保存处方出库
  5353. if goodOutConfig.IsOpen == 1 {
  5354. //查询今日耗材出库数量
  5355. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5356. for _, item := range hisgoodlist {
  5357. //查询历史出库数据
  5358. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5359. var out_count_five int64
  5360. for _, item := range flowGood {
  5361. out_count_five += item.Count
  5362. }
  5363. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5364. fmt.Println("out_count_five-------------------", out_count_five)
  5365. fmt.Println("parseIntCount---------------", parseIntCount)
  5366. if out_count_five != parseIntCount {
  5367. //查询耗材最后一次出库记录
  5368. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5369. //查询默认出库仓库库存
  5370. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5371. if len(wareOut) > 0 {
  5372. for _, it := range wareOut {
  5373. //回退库存
  5374. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5375. //删除出库记录
  5376. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5377. }
  5378. }
  5379. timeStr := time.Now().Format("2006-01-02")
  5380. timeArr := strings.Split(timeStr, "-")
  5381. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5382. total = total + 1
  5383. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5384. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5385. number = number + total
  5386. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5387. operation_time := time.Now().Unix()
  5388. creater := c.GetAdminUserInfo().AdminUser.Id
  5389. recordDateStr := time.Now().Format("2006-01-02")
  5390. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5391. nowtime := recordDate.Unix()
  5392. warehouseOut := models.WarehouseOut{
  5393. WarehouseOutOrderNumber: warehousing_out_order,
  5394. OperationTime: operation_time,
  5395. OrgId: adminInfo.CurrentOrgId,
  5396. Creater: creater,
  5397. Ctime: time.Now().Unix(),
  5398. Status: 1,
  5399. WarehouseOutTime: nowtime,
  5400. Type: 1,
  5401. StorehouseId: storeConfig.StorehouseOutInfo,
  5402. IsCheck: 1,
  5403. IsSys: 1,
  5404. }
  5405. //查询是否生成出库单
  5406. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5407. if out.ID == 0 {
  5408. service.AddSigleWarehouseOutOne(&warehouseOut)
  5409. }
  5410. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5411. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5412. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5413. dialyPrepareOne := models.DialysisBeforePrepare{
  5414. GoodTypeId: goodObj.GoodTypeId,
  5415. GoodId: item.ProjectId,
  5416. PatientId: item.PatientId,
  5417. RecordDate: item.RecordDate,
  5418. UserOrgId: adminInfo.CurrentOrgId,
  5419. Count: parseIntCount,
  5420. Ctime: time.Now().Unix(),
  5421. Creater: creater,
  5422. Status: 1,
  5423. StorehouseId: houseConfig.StorehouseOutInfo,
  5424. ProjectId: item.ID,
  5425. }
  5426. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5427. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5428. //查询历史出库数据
  5429. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5430. var out_count int64
  5431. for _, item := range flowGood {
  5432. out_count += item.Count
  5433. }
  5434. //如果历史数和当前数据不想等才进行退库出库
  5435. if out_count != parseIntCount {
  5436. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5437. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5438. detail := models.AutomaticReduceDetail{
  5439. WarehouseOutId: 0,
  5440. WarehouseOutOrderNumber: "",
  5441. PatientId: item.PatientId,
  5442. Ctime: time.Now().Unix(),
  5443. Mtime: 0,
  5444. Status: 1,
  5445. RecordTime: item.RecordDate,
  5446. OrgId: item.UserOrgId,
  5447. GoodId: item.ProjectId,
  5448. GoodTypeId: 0,
  5449. Count: parseIntCount,
  5450. Type: 0,
  5451. ProjectId: item.ID,
  5452. StorehouseId: 0,
  5453. }
  5454. service.CreateAutoDetail(detail)
  5455. //查询剩余库存
  5456. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5457. var sum_count int64
  5458. for _, item := range goodList {
  5459. sum_count += item.StockCount
  5460. }
  5461. //更新剩余库存
  5462. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5463. //耗材
  5464. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5465. }
  5466. }
  5467. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5468. //查询历史出库数据
  5469. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5470. var out_count int64
  5471. for _, item := range flowGood {
  5472. out_count += item.Count
  5473. }
  5474. //如果历史数和当前数据不想等才进行退库出库
  5475. if out_count != parseIntCount {
  5476. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5477. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5478. detail := models.AutomaticReduceDetail{
  5479. WarehouseOutId: 0,
  5480. WarehouseOutOrderNumber: "",
  5481. PatientId: item.PatientId,
  5482. Ctime: time.Now().Unix(),
  5483. Mtime: 0,
  5484. Status: 1,
  5485. RecordTime: item.RecordDate,
  5486. OrgId: item.UserOrgId,
  5487. GoodId: item.ProjectId,
  5488. GoodTypeId: 0,
  5489. Count: parseIntCount,
  5490. Type: 0,
  5491. ProjectId: item.ID,
  5492. StorehouseId: 0,
  5493. }
  5494. service.CreateAutoDetail(detail)
  5495. //查询剩余库存
  5496. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5497. var sum_count int64
  5498. for _, item := range goodList {
  5499. sum_count += item.StockCount
  5500. }
  5501. //更新剩余库存
  5502. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5503. //耗材
  5504. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5505. }
  5506. }
  5507. }
  5508. }
  5509. }
  5510. ////同步到自备药
  5511. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5512. if selfPrescriptionOpen.IsOpen == 1 {
  5513. timeStr := time.Now().Format("2006-01-02")
  5514. timeArr := strings.Split(timeStr, "-")
  5515. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5516. total = total + 1
  5517. operation_time := time.Now().Unix()
  5518. creater := adminInfo.AdminUser.Id
  5519. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5520. warehousing := models.XtSelfDrugWarehouse{
  5521. WarehousingOrder: warehousing_order,
  5522. OperationTime: operation_time,
  5523. OrgId: adminInfo.CurrentOrgId,
  5524. Creater: creater,
  5525. Ctime: time.Now().Unix(),
  5526. Status: 1,
  5527. WarehousingTime: recordDateTime,
  5528. Type: 0,
  5529. StorehouseId: 0,
  5530. IsCheck: 1,
  5531. PatientId: patient_id,
  5532. IsSys: 1,
  5533. }
  5534. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5535. if selfDrugWarehouse.ID == 0 {
  5536. service.AddSelfDrugWarehouse(&warehousing, tx)
  5537. }
  5538. if selfDrugWarehouse.ID > 0 {
  5539. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5540. }
  5541. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5542. fmt.Println(info)
  5543. for _, item := range hisdoctorlist {
  5544. //查询该病人的该药品是否已经入库
  5545. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5546. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5547. var in_count int64
  5548. if len(selfdruginfo) > 0 {
  5549. for _, item := range selfdruginfo {
  5550. var in_count_one int64
  5551. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5552. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5553. }
  5554. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5555. in_count_one = item.WarehousingCount
  5556. }
  5557. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5558. in_count_one = item.WarehousingCount
  5559. }
  5560. in_count += in_count_one
  5561. }
  5562. }
  5563. if selfBasedrug.IsSelfDrug == 1 {
  5564. var total_count int64
  5565. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5566. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5567. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5568. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5569. }
  5570. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5571. total_count += prescribingNumberSeven
  5572. }
  5573. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5574. total_count += prescribingNumberSeven
  5575. }
  5576. //入库
  5577. if total_count > in_count {
  5578. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5579. WarehousingOrder: warehousing_order,
  5580. WarehousingId: info.ID,
  5581. DrugId: item.DrugId,
  5582. Number: "",
  5583. ProductDate: 0,
  5584. ExpiryDate: 0,
  5585. WarehousingCount: total_count - in_count,
  5586. WarehouseingUnit: selfBasedrug.MinUnit,
  5587. Price: 0,
  5588. TotalPrice: 0,
  5589. Status: 1,
  5590. Ctime: time.Now().Unix(),
  5591. Remark: "",
  5592. OrgId: adminInfo.CurrentOrgId,
  5593. Type: 0,
  5594. Manufacturer: selfBasedrug.Manufacturer,
  5595. Dealer: selfBasedrug.Dealer,
  5596. StockMaxNumber: total_count - in_count,
  5597. RetailTotalPrice: 0,
  5598. BatchNumber: "",
  5599. MaxUnit: selfBasedrug.MinUnit,
  5600. MinUnit: selfBasedrug.MinUnit,
  5601. RetailPrice: 0,
  5602. StorehouseId: 0,
  5603. IsCheck: 1,
  5604. StockMinNumber: 0,
  5605. PatientId: patient_id,
  5606. IsSys: 1,
  5607. RecordDate: item.RecordDate,
  5608. AdviceId: item.ID,
  5609. }
  5610. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5611. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5612. Creator := adminInfo.AdminUser.Id
  5613. //查询默认仓库剩余多少库存
  5614. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5615. var sum_count int64
  5616. for _, it := range list {
  5617. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5618. if it.MaxUnit == baseDrug.MaxUnit {
  5619. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5620. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5621. }
  5622. sum_count += it.StockMaxNumber + it.StockMinNumber
  5623. }
  5624. flow := &models.XtSelfDrugFlow{
  5625. WarehousingId: info.ID,
  5626. DrugId: item.DrugId,
  5627. Number: "",
  5628. BatchNumber: "",
  5629. Count: total_count - in_count,
  5630. UserOrgId: adminInfo.CurrentOrgId,
  5631. PatientId: item.PatientId,
  5632. SystemTime: time.Now().Unix(),
  5633. ConsumableType: 1,
  5634. IsSys: 1,
  5635. WarehousingOrder: warehousing_order,
  5636. WarehouseOutId: 0,
  5637. WarehouseOutOrderNumber: "",
  5638. IsEdit: 0,
  5639. CancelStockId: 0,
  5640. CancelOrderNumber: "",
  5641. Manufacturer: selfBasedrug.Manufacturer,
  5642. Dealer: selfBasedrug.Dealer,
  5643. Creator: Creator,
  5644. UpdateCreator: Creator,
  5645. Status: 1,
  5646. Ctime: item.AdviceDate,
  5647. Mtime: 0,
  5648. Price: item.Price,
  5649. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5650. WarehouseOutDetailId: 0,
  5651. CancelOutDetailId: 0,
  5652. ExpireDate: 0,
  5653. ProductDate: 0,
  5654. MaxUnit: selfBasedrug.MinUnit,
  5655. MinUnit: selfBasedrug.MinUnit,
  5656. StorehouseId: 0,
  5657. OverCount: sum_count,
  5658. OperateTime: time.Now().Unix(),
  5659. AdviceId: item.ID,
  5660. }
  5661. service.CreateSelfDrugFlow(flow, tx)
  5662. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5663. var total_count int64 // 入库总数量
  5664. var over_count int64 //剩余库存
  5665. for _, it := range drugInfolist {
  5666. if it.MaxUnit == selfBasedrug.MaxUnit {
  5667. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5668. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5669. }
  5670. }
  5671. for _, it := range drugInfolist {
  5672. total_count += it.WarehousingCount
  5673. over_count += it.StockMaxNumber + it.StockMinNumber
  5674. }
  5675. //查询该仓库是否有默认数据
  5676. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5677. if selfDrugStock.ID == 0 {
  5678. drugStock := models.XtSelfDrugStockCount{
  5679. UserOrgId: item.UserOrgId,
  5680. PatientId: item.PatientId,
  5681. SumInCount: total_count,
  5682. SumOutCount: 0,
  5683. SumCancelCount: 0,
  5684. DrugId: item.DrugId,
  5685. Ctime: time.Now().Unix(),
  5686. Mtime: 0,
  5687. Status: 1,
  5688. FlushCount: over_count,
  5689. SumActOutCount: 0,
  5690. }
  5691. service.CreateSelfDrugStockSum(drugStock, tx)
  5692. }
  5693. if selfDrugStock.ID > 0 {
  5694. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5695. }
  5696. }
  5697. //查询这个单据的出库数量
  5698. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5699. var his_out_count int64
  5700. for _, item := range drugFlowList {
  5701. his_out_count += item.Count
  5702. }
  5703. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5704. if (total_count + his_out_count) <= in_count {
  5705. // 出库
  5706. if total_count < in_count {
  5707. var cha_count int64
  5708. cha_count = in_count - total_count
  5709. var stock_number int64 = 0
  5710. //查询库存是否充足
  5711. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5712. // 将该批次的剩余库存数量转换为拆零数量
  5713. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5714. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5715. }
  5716. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5717. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5718. }
  5719. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5720. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5721. }
  5722. if stock_number >= cha_count {
  5723. var maxNumber int64 = 0
  5724. var minNumber int64 = 0
  5725. maxNumber = cha_count / selfBasedrug.MinNumber
  5726. minNumber = cha_count % selfBasedrug.MinNumber
  5727. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5728. minNumber = maxNumber
  5729. }
  5730. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5731. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5733. return
  5734. }
  5735. }
  5736. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5737. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5738. }
  5739. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5740. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5741. }
  5742. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5743. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5744. }
  5745. if warehouse.StockMaxNumber < 0 {
  5746. warehouse.StockMaxNumber = 0
  5747. }
  5748. if warehouse.StockMinNumber < 0 {
  5749. warehouse.StockMinNumber = 0
  5750. }
  5751. warehouse.Mtime = time.Now().Unix()
  5752. if warehouse.StockMinNumber < minNumber {
  5753. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5754. if warehouse.MaxUnit != warehouse.MinUnit {
  5755. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5756. }
  5757. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5758. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5759. }
  5760. } else {
  5761. if minNumber > 0 {
  5762. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5763. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5764. }
  5765. }
  5766. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5767. if warehouse.StockMinNumber > 0 {
  5768. if warehouse.StockMinNumber-cha_count >= 0 {
  5769. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5770. }
  5771. }
  5772. }
  5773. }
  5774. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5775. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5776. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5777. }
  5778. }
  5779. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5780. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5782. return
  5783. }
  5784. }
  5785. if warehouse.StockMinNumber <= 0 {
  5786. warehouse.StockMinNumber = 0
  5787. }
  5788. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5789. //查询该药品剩余库存
  5790. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5791. var over_count int64
  5792. for _, its := range infolist {
  5793. if its.MaxUnit == selfBasedrug.MaxUnit {
  5794. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5795. }
  5796. over_count += its.StockMaxNumber + its.StockMinNumber
  5797. }
  5798. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5799. drugflow := models.XtSelfDrugFlow{
  5800. WarehouseOutId: 0,
  5801. WarehouseOutOrderNumber: warehousing_order,
  5802. WarehousingOrder: warehousing_order,
  5803. DrugId: item.DrugId,
  5804. Number: warehouse.Number,
  5805. ProductDate: warehouse.ProductDate,
  5806. ExpireDate: warehouse.ExpiryDate,
  5807. Count: cha_count,
  5808. Price: warehouse.RetailPrice,
  5809. Status: 1,
  5810. Ctime: item.AdviceDate,
  5811. Mtime: time.Now().Unix(),
  5812. UserOrgId: item.UserOrgId,
  5813. Manufacturer: warehouse.Manufacturer,
  5814. Dealer: warehouse.Dealer,
  5815. BatchNumber: warehouse.BatchNumber,
  5816. MaxUnit: selfBasedrug.MinUnit,
  5817. ConsumableType: 20,
  5818. IsEdit: 1,
  5819. Creator: 0,
  5820. IsSys: 3,
  5821. WarehouseOutDetailId: drugWareInfo.ID,
  5822. AdviceId: item.ID,
  5823. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5824. StorehouseId: 0,
  5825. AdminUserId: creater,
  5826. LastPrice: warehouse.Price,
  5827. StockCount: "",
  5828. WarehousingDetailId: 0,
  5829. OverCount: over_count,
  5830. RetailPrice: item.Price, //手动出库出库价格
  5831. WarehousingId: warehouse.ID,
  5832. SystemTime: item.AdviceDate,
  5833. PatientId: item.PatientId,
  5834. Remark: "保存处方入库数据差",
  5835. OperateTime: time.Now().Unix(),
  5836. }
  5837. if warehouse.RetailPrice == 0 {
  5838. drugflow.Price = item.Price
  5839. }
  5840. service.CreateSelfDrugFlowOne(drugflow, tx)
  5841. var out_count int64
  5842. out_count = in_count - total_count
  5843. //
  5844. //fmt.Println("in_count------------------", in_count)
  5845. //fmt.Println("total_count------------------", total_count)
  5846. //添加出库数量
  5847. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5848. //查询剩余库存
  5849. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5850. var sum_count int64
  5851. for _, its := range stockInfo {
  5852. if its.MaxUnit == selfBasedrug.MaxUnit {
  5853. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5854. }
  5855. sum_count += its.StockMaxNumber + its.StockMinNumber
  5856. }
  5857. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5858. } else {
  5859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5860. return
  5861. }
  5862. }
  5863. }
  5864. }
  5865. }
  5866. }
  5867. }
  5868. tx.Commit()
  5869. if err == nil {
  5870. c.ServeSuccessJSON(map[string]interface{}{
  5871. "msg": "保存成功",
  5872. })
  5873. return
  5874. } else {
  5875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5876. return
  5877. }
  5878. }
  5879. }
  5880. //func (c *HisApiController) EditHisPrescription() {
  5881. // record_date := c.GetString("record_date")
  5882. // patient_id, _ := c.GetInt64("patient_id")
  5883. // reg_type, _ := c.GetInt64("reg_type")
  5884. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5885. // diagnose := c.GetString("diagnose")
  5886. // sick_type, _ := c.GetInt64("sick_type")
  5887. // sick_history := c.GetString("sick_history")
  5888. // doctor_id, _ := c.GetInt64("doctor", 0)
  5889. // department, _ := c.GetInt64("department", 0)
  5890. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5891. // p_type, _ := c.GetInt64("p_type")
  5892. //
  5893. // dataBody := make(map[string]interface{}, 0)
  5894. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5895. // if err != nil {
  5896. // utils.ErrorLog(err.Error())
  5897. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5898. // return
  5899. // }
  5900. //
  5901. // timeLayout := "2006-01-02"
  5902. // loc, _ := time.LoadLocation("Local")
  5903. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5904. // if err != nil {
  5905. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5906. // return
  5907. // }
  5908. // adminInfo := c.GetAdminUserInfo()
  5909. // recordDateTime := theTime.Unix()
  5910. //
  5911. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5912. //
  5913. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5914. // var hpInfo models.HisPrescriptionInfo
  5915. // if info.ID == 0 {
  5916. // var randNum int
  5917. // randNum = rand.Intn(10000) + 1000
  5918. // timestamp := time.Now().Unix()
  5919. // tempTime := time.Unix(timestamp, 0)
  5920. // timeFormat := tempTime.Format("20060102150405")
  5921. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5922. //
  5923. // hpInfo = models.HisPrescriptionInfo{
  5924. // UserOrgId: adminInfo.CurrentOrgId,
  5925. // RecordDate: theTime.Unix(),
  5926. // PatientId: patient_id,
  5927. // Status: 1,
  5928. // Ctime: time.Now().Unix(),
  5929. // Mtime: time.Now().Unix(),
  5930. // Creator: adminInfo.AdminUser.Id,
  5931. // Modifier: adminInfo.AdminUser.Id,
  5932. // Diagnosis: diagnose,
  5933. // SickHistory: sick_history,
  5934. // Departments: department,
  5935. // RegisterType: reg_type,
  5936. // PrescriptionNumber: p_number,
  5937. // PrescriptionStatus: 1,
  5938. // Doctor: role.UserName,
  5939. // DoctorId: doctor_id,
  5940. // SickType: sick_type,
  5941. // PType: p_type,
  5942. // }
  5943. // service.SavePatientPrescriptionInfo(hpInfo)
  5944. //
  5945. // } else {
  5946. // hpInfo = models.HisPrescriptionInfo{
  5947. // ID: info.ID,
  5948. // UserOrgId: adminInfo.CurrentOrgId,
  5949. // RecordDate: info.RecordDate,
  5950. // PatientId: info.PatientId,
  5951. // Status: 1,
  5952. // Ctime: info.Ctime,
  5953. // Mtime: time.Now().Unix(),
  5954. // Creator: info.Creator,
  5955. // Modifier: adminInfo.AdminUser.Id,
  5956. // Diagnosis: diagnose,
  5957. // SickHistory: sick_history,
  5958. // Departments: department,
  5959. // RegisterType: reg_type,
  5960. // PrescriptionNumber: info.PrescriptionNumber,
  5961. // Doctor: role.UserName,
  5962. // PrescriptionStatus: info.PrescriptionStatus,
  5963. // DoctorId: doctor_id,
  5964. // SickType: sick_type,
  5965. // PType: info.PType,
  5966. // }
  5967. // service.SavePatientPrescriptionInfo(hpInfo)
  5968. // }
  5969. //
  5970. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5971. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5972. //
  5973. // if len(prescriptions) > 0 {
  5974. // for _, item := range prescriptions {
  5975. // items := item.(map[string]interface{})
  5976. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5977. // utils.ErrorLog("id")
  5978. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5979. // return
  5980. // }
  5981. // id := int64(items["id"].(float64))
  5982. //
  5983. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5984. // utils.ErrorLog("type")
  5985. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5986. // return
  5987. // }
  5988. // types := int64(items["type"].(float64))
  5989. //
  5990. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5991. // utils.ErrorLog("med_type")
  5992. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5993. // return
  5994. // }
  5995. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5996. //
  5997. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5998. //
  5999. // ctime := time.Now().Unix()
  6000. //
  6001. // prescription := &models.HisPrescription{
  6002. // ID: id,
  6003. // PatientId: patient_id,
  6004. // UserOrgId: adminInfo.CurrentOrgId,
  6005. // RecordDate: recordDateTime,
  6006. // Ctime: ctime,
  6007. // Mtime: ctime,
  6008. // Type: types,
  6009. // Modifier: adminInfo.AdminUser.Id,
  6010. // Creator: adminInfo.AdminUser.Id,
  6011. // Status: 1,
  6012. // Doctor: role.UserName,
  6013. // HisPatientId: his_patient_id,
  6014. // OrderStatus: 1,
  6015. // BatchNumber: "",
  6016. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  6017. // PType: hpInfo.PType,
  6018. // MedType: med_type,
  6019. // }
  6020. //
  6021. // if historyPrescription.ID > 0 {
  6022. // prescription.PreTime = historyPrescription.PreTime
  6023. //
  6024. // }
  6025. //
  6026. // service.SaveHisPrescription(prescription)
  6027. //
  6028. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6029. // advices := items["advices"].([]interface{})
  6030. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6031. // groupNo := int64(0)
  6032. // ctime := time.Now().Unix()
  6033. // mtime := ctime
  6034. // if len(advices) > 0 {
  6035. // for _, advice := range advices {
  6036. // var s models.HisDoctorAdviceInfo
  6037. // s.PrescriptionId = prescription.ID
  6038. // s.AdviceType = 2
  6039. // s.AdviceDoctor = adminInfo.AdminUser.Id
  6040. // s.StopState = 2
  6041. // s.ExecutionState = 2
  6042. // s.AdviceDate = recordDateTime
  6043. // s.Status = 1
  6044. // s.UserOrgId = adminInfo.CurrentOrgId
  6045. // s.RecordDate = recordDateTime
  6046. // s.StartTime = prescription.PreTime
  6047. // s.Groupno = groupNo
  6048. // s.CreatedTime = ctime
  6049. // s.UpdatedTime = mtime
  6050. // s.PatientId = patient_id
  6051. // s.HisPatientId = his_patient_id
  6052. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  6053. // if errcode > 0 {
  6054. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6055. // return
  6056. // }
  6057. //
  6058. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  6059. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  6060. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  6061. // if s.Price == 0 {
  6062. // s.Price = lastWarehouse.RetailPrice
  6063. // }
  6064. // }
  6065. //
  6066. // service.CreateHisDoctorAdvice(&s)
  6067. // //记录日志
  6068. // byterequest, _ := json.Marshal(s)
  6069. // adviceLog := models.XtDoctorAdviceLog{
  6070. // UserOrgId: s.UserOrgId,
  6071. // PatientId: s.PatientId,
  6072. // AdminUserId: adminInfo.AdminUser.Id,
  6073. // Module: 1,
  6074. // ErrLog: string(byterequest),
  6075. // Status: 1,
  6076. // Ctime: time.Now().Unix(),
  6077. // Mtime: 0,
  6078. // Source: "电脑端his医嘱修改",
  6079. // RecordDate: s.AdviceDate,
  6080. // }
  6081. // service.CreateDoctorAdviceLog(adviceLog)
  6082. // redis := service.RedisClient()
  6083. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  6084. // redis.Set(key, "", time.Second)
  6085. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  6086. // fmt.Println("keyOne", keyOne)
  6087. // redis.Set(keyOne, "", time.Second)
  6088. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  6089. // redis.Set(keySeven, "", time.Second)
  6090. // redis.Close()
  6091. //
  6092. // }
  6093. // }
  6094. // }
  6095. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6096. // projects := items["project"].([]interface{})
  6097. // if len(projects) > 0 {
  6098. // for _, project := range projects {
  6099. // var p models.HisPrescriptionProject
  6100. // p.PrescriptionId = prescription.ID
  6101. // p.Ctime = time.Now().Unix()
  6102. // p.Mtime = time.Now().Unix()
  6103. // p.PatientId = patient_id
  6104. // p.RecordDate = recordDateTime
  6105. // p.UserOrgId = adminInfo.CurrentOrgId
  6106. // p.HisPatientId = his_patient_id
  6107. // p.Status = 1
  6108. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  6109. // if errcode > 0 {
  6110. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6111. // return
  6112. // }
  6113. // service.CreateHisProjectTwo(&p)
  6114. //
  6115. // //记录日志
  6116. // byterequest, _ := json.Marshal(p)
  6117. // adviceLog := models.XtDoctorAdviceLog{
  6118. // UserOrgId: p.UserOrgId,
  6119. // PatientId: p.PatientId,
  6120. // AdminUserId: adminInfo.AdminUser.Id,
  6121. // Module: 1,
  6122. // ErrLog: string(byterequest),
  6123. // Status: 1,
  6124. // Ctime: time.Now().Unix(),
  6125. // Mtime: 0,
  6126. // Source: "电脑端his项目修改",
  6127. // RecordDate: p.RecordDate,
  6128. // }
  6129. // service.CreateDoctorAdviceLog(adviceLog)
  6130. // }
  6131. // }
  6132. // }
  6133. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  6134. // addition := items["addition"].([]interface{})
  6135. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6136. // ctime := time.Now().Unix()
  6137. // mtime := ctime
  6138. // if len(addition) > 0 {
  6139. // for _, item := range addition {
  6140. // var s models.HisAdditionalCharge
  6141. // s.PrescriptionId = prescription.ID
  6142. // s.Status = 1
  6143. // s.UserOrgId = adminInfo.CurrentOrgId
  6144. // s.RecordDate = recordDateTime
  6145. // s.CreatedTime = ctime
  6146. // s.UpdatedTime = mtime
  6147. // s.PatientId = patient_id
  6148. // s.HisPatientId = his_patient_id
  6149. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  6150. // if errcode > 0 {
  6151. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6152. // return
  6153. // }
  6154. // service.CreateAdditionalCharge(&s)
  6155. // }
  6156. // }
  6157. // }
  6158. //
  6159. // }
  6160. // }
  6161. // }
  6162. // if err == nil {
  6163. // c.ServeSuccessJSON(map[string]interface{}{
  6164. // "msg": "保存成功",
  6165. // })
  6166. // return
  6167. //
  6168. // } else {
  6169. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6170. // return
  6171. // }
  6172. //}
  6173. func (c *HisApiController) DeletePrescription() {
  6174. prescription_id, _ := c.GetInt64("id")
  6175. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  6176. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  6177. ////同步到自备药
  6178. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6179. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6180. if selfPrescriptionOpen.IsOpen == 1 {
  6181. // 在函数结束时处理事务回滚
  6182. db := service.XTWriteDB()
  6183. tx := db.Begin()
  6184. defer func() {
  6185. if r := recover(); r != nil {
  6186. tx.Rollback()
  6187. } else {
  6188. tx.Commit()
  6189. }
  6190. }()
  6191. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  6192. for _, item := range advicesList {
  6193. timeStr := time.Now().Format("2006-01-02")
  6194. timeArr := strings.Split(timeStr, "-")
  6195. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6196. total = total + 1
  6197. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6198. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6199. number = number + total
  6200. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6201. operation_time := time.Now().Unix()
  6202. creater := c.GetAdminUserInfo().AdminUser.Id
  6203. //创建一个出库单
  6204. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6205. WarehouseOutOrderNumber: warehousing_out_order,
  6206. OperationTime: operation_time,
  6207. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6208. Creater: creater,
  6209. Ctime: time.Now().Unix(),
  6210. Status: 1,
  6211. WarehouseOutTime: item.AdviceDate,
  6212. Type: 0,
  6213. PatientId: item.PatientId,
  6214. IsCheck: 1,
  6215. }
  6216. //查询今日是否有出库数据
  6217. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  6218. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  6219. if lastWarehouseOut.ID == 0 {
  6220. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6221. }
  6222. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  6223. var total_count int64
  6224. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  6225. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6226. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6227. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6228. }
  6229. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6230. total_count += prescribingNumberSeven
  6231. }
  6232. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6233. total_count += prescribingNumberSeven
  6234. }
  6235. //出库
  6236. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6237. WarehouseOutOrderNumber: warehousing_out_order,
  6238. WarehouseOutId: lastWarehouseOut.ID,
  6239. DrugId: item.DrugId,
  6240. Count: total_count,
  6241. Price: 0,
  6242. TotalPrice: 0,
  6243. Status: 1,
  6244. Ctime: item.AdviceDate,
  6245. Mtime: item.AdviceDate,
  6246. Remark: "",
  6247. OrgId: item.UserOrgId,
  6248. Type: 0,
  6249. Manufacturer: selfBasedrug.Manufacturer,
  6250. Dealer: selfBasedrug.Dealer,
  6251. RetailPrice: 0,
  6252. RetailTotalPrice: 0,
  6253. CountUnit: selfBasedrug.MinUnit,
  6254. ExpiryDate: 0,
  6255. ProductDate: 0,
  6256. Number: "",
  6257. BatchNumber: "",
  6258. IsSys: 1,
  6259. WarehouseInfoId: 0,
  6260. AdminUserId: 0,
  6261. StockCount: "",
  6262. IsCheck: 1,
  6263. SysRecordTime: item.AdviceDate,
  6264. PatientId: item.PatientId,
  6265. ClassType: "",
  6266. AdviceId: item.ID,
  6267. }
  6268. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6269. }
  6270. fmt.Println("长度-------------------------------", warehousingOutInfo)
  6271. for _, it := range warehousingOutInfo {
  6272. //查询今日是否有出库数据
  6273. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6274. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6275. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6276. //出库逻辑
  6277. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6278. //查询剩余库存
  6279. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6280. var sum_count int64
  6281. for _, its := range stockInfo {
  6282. if its.MaxUnit == medical.MaxUnit {
  6283. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6284. }
  6285. sum_count += its.StockMaxNumber + its.StockMinNumber
  6286. }
  6287. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6288. }
  6289. }
  6290. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6291. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6292. //耗材保存处方出库
  6293. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6294. //已收费和已发药限制逻辑
  6295. isCharge := false
  6296. isMedicine := false
  6297. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6298. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6299. if new_prescription.IsMedicine == 1 {
  6300. isMedicine = true
  6301. }
  6302. for _, item := range new_prescriptions {
  6303. if item.OrderStatus == 4 {
  6304. isCharge = true
  6305. }
  6306. }
  6307. if p_err != nil {
  6308. if new_prescription.ID > 0 {
  6309. if new_prescription.OrderStatus == 2 {
  6310. isCharge = true
  6311. }
  6312. }
  6313. }
  6314. for _, item := range advices {
  6315. if item.IsMedicine == 1 {
  6316. isMedicine = true
  6317. }
  6318. }
  6319. if isCharge {
  6320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6321. return
  6322. }
  6323. if isMedicine {
  6324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6325. return
  6326. }
  6327. //已收费和已发药限制逻辑
  6328. if len(projects) > 0 {
  6329. for _, item := range projects {
  6330. service.DeletePrintInfo(item.ID) //删除打印信息
  6331. if goodOutConfig.IsOpen != 1 {
  6332. if stockConfig.IsOpen == 1 {
  6333. if item.Type == 3 && item.IsOut == 1 {
  6334. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6335. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6336. good.Total = good.Total + f_count
  6337. service.UpdateGoodInfo(&good)
  6338. operation_time := time.Now().Unix()
  6339. creater := c.GetAdminUserInfo().AdminUser.Id
  6340. //创建退库单
  6341. timeStr := time.Now().Format("2006-01-02")
  6342. timeArr := strings.Split(timeStr, "-")
  6343. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6344. total = total + 1
  6345. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6346. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6347. cancelStock := models.CancelStock{
  6348. OrderNumber: orderNumber,
  6349. OperaTime: operation_time,
  6350. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6351. Creater: creater,
  6352. Ctime: time.Now().Unix(),
  6353. Status: 1,
  6354. ReturnTime: item.RecordDate,
  6355. Type: 1,
  6356. StorehouseId: houseConfig.StorehouseOutInfo,
  6357. IsCheck: 1,
  6358. }
  6359. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6360. if msgerrkonde == gorm.ErrRecordNotFound {
  6361. service.AddSigleCancelStock(&cancelStock)
  6362. }
  6363. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6364. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6365. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6366. //查询该耗材是否出库
  6367. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6368. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6369. deaerler, _ := service.GetDealerById(info.Dealer)
  6370. var total_count int64
  6371. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6372. total_count += count
  6373. if info.ID > 0 {
  6374. if info.Count >= total_count {
  6375. //回退库存
  6376. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6377. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6378. var flush_count int64
  6379. for _, it := range goodList {
  6380. flush_count += it.StockCount
  6381. }
  6382. cancelStockInfo := models.CancelStockInfo{
  6383. GoodId: item.ProjectId,
  6384. CancelStockId: cancel.ID,
  6385. GoodTypeId: good.GoodTypeId,
  6386. Count: prescribingNumber,
  6387. Price: info.Price,
  6388. Total: 0,
  6389. ProductDate: info.ProductDate,
  6390. ExpiryDate: info.ExpiryDate,
  6391. Ctime: time.Now().Unix(),
  6392. Status: 1,
  6393. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6394. OrderNumber: cancel.OrderNumber,
  6395. Type: 0,
  6396. Dealer: deaerler.DealerName,
  6397. Manufacturer: manufacturer.ManufacturerName,
  6398. Number: info.Number,
  6399. RegisterAccount: "",
  6400. Remark: "",
  6401. WarehouseInfoId: info.WarehouseInfotId,
  6402. PatientId: info.PatientId,
  6403. RecordDate: info.SysRecordTime,
  6404. StorehouseId: houseConfig.StorehouseOutInfo,
  6405. IsCheck: 1,
  6406. }
  6407. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6408. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6409. flow := models.VmStockFlow{
  6410. WarehousingId: info.WarehouseInfotId,
  6411. GoodId: item.ProjectId,
  6412. Number: info.Number,
  6413. LicenseNumber: info.LicenseNumber,
  6414. Count: prescribingNumber,
  6415. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6416. PatientId: item.PatientId,
  6417. SystemTime: info.SysRecordTime,
  6418. ConsumableType: 7,
  6419. IsSys: 0,
  6420. WarehousingOrder: "",
  6421. WarehouseOutId: info.WarehouseOutId,
  6422. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6423. IsEdit: 0,
  6424. CancelStockId: cancel.ID,
  6425. CancelOrderNumber: cancel.OrderNumber,
  6426. Manufacturer: manufacturer.ID,
  6427. Dealer: 0,
  6428. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6429. UpdateCreator: 0,
  6430. Status: 1,
  6431. Ctime: time.Now().Unix(),
  6432. Mtime: 0,
  6433. Price: info.Price,
  6434. WarehousingDetailId: info.WarehouseInfotId,
  6435. WarehouseOutDetailId: info.ID,
  6436. CancelOutDetailId: cancelInfo.ID,
  6437. ProductDate: info.ProductDate,
  6438. ExpireDate: info.ExpiryDate,
  6439. StorehouseId: houseConfig.StorehouseOutInfo,
  6440. OverCount: flush_count,
  6441. OperateTime: time.Now().Unix(),
  6442. }
  6443. service.CreateStockFlowOne(flow)
  6444. //退库数量增加
  6445. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6446. //出库数量减少
  6447. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6448. }
  6449. if info.Count < total_count {
  6450. //回退库存
  6451. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6452. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6453. var flush_count int64
  6454. for _, it := range goodList {
  6455. flush_count += it.StockCount
  6456. }
  6457. cancelStockInfo := models.CancelStockInfo{
  6458. GoodId: item.ProjectId,
  6459. CancelStockId: cancel.ID,
  6460. GoodTypeId: good.GoodTypeId,
  6461. Count: info.Count,
  6462. Price: info.Price,
  6463. Total: 0,
  6464. ProductDate: info.ProductDate,
  6465. ExpiryDate: info.ExpiryDate,
  6466. Ctime: time.Now().Unix(),
  6467. Status: 1,
  6468. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6469. OrderNumber: cancel.OrderNumber,
  6470. Type: 0,
  6471. Dealer: deaerler.DealerName,
  6472. Manufacturer: manufacturer.ManufacturerName,
  6473. Number: info.Number,
  6474. RegisterAccount: "",
  6475. Remark: "",
  6476. WarehouseInfoId: info.WarehouseInfotId,
  6477. PatientId: info.PatientId,
  6478. RecordDate: info.SysRecordTime,
  6479. StorehouseId: houseConfig.StorehouseOutInfo,
  6480. IsCheck: 1,
  6481. }
  6482. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6483. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6484. flow := models.VmStockFlow{
  6485. WarehousingId: info.WarehouseInfotId,
  6486. GoodId: item.ProjectId,
  6487. Number: info.Number,
  6488. LicenseNumber: info.LicenseNumber,
  6489. Count: info.Count,
  6490. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6491. PatientId: item.PatientId,
  6492. SystemTime: info.SysRecordTime,
  6493. ConsumableType: 7,
  6494. IsSys: 0,
  6495. WarehousingOrder: "",
  6496. WarehouseOutId: info.WarehouseOutId,
  6497. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6498. IsEdit: 0,
  6499. CancelStockId: cancel.ID,
  6500. CancelOrderNumber: cancel.OrderNumber,
  6501. Manufacturer: manufacturer.ID,
  6502. Dealer: 0,
  6503. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6504. UpdateCreator: 0,
  6505. Status: 1,
  6506. Ctime: time.Now().Unix(),
  6507. Mtime: 0,
  6508. Price: info.Price,
  6509. WarehousingDetailId: info.WarehouseInfotId,
  6510. WarehouseOutDetailId: info.ID,
  6511. CancelOutDetailId: cancelInfo.ID,
  6512. ProductDate: info.ProductDate,
  6513. ExpireDate: info.ExpiryDate,
  6514. StorehouseId: houseConfig.StorehouseOutInfo,
  6515. OverCount: flush_count,
  6516. OperateTime: time.Now().Unix(),
  6517. }
  6518. service.CreateStockFlowOne(flow)
  6519. //退库数量增加
  6520. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6521. //出库数量减少
  6522. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6523. }
  6524. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6525. var flush_count int64
  6526. for _, it := range goodList {
  6527. flush_count += it.StockCount
  6528. }
  6529. //查询已出库数量
  6530. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6531. if prescribingNumber < dialysisInfo.Count {
  6532. //改变数量
  6533. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6534. }
  6535. if prescribingNumber >= dialysisInfo.Count {
  6536. //删除出库表
  6537. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6538. }
  6539. //更新库存
  6540. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6541. //更新基础库库存
  6542. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6543. }
  6544. }
  6545. }
  6546. }
  6547. //保存耗材出库
  6548. if goodOutConfig.IsOpen == 1 {
  6549. if item.Type == 3 {
  6550. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6551. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6552. good.Total = good.Total + f_count
  6553. service.UpdateGoodInfo(&good)
  6554. operation_time := time.Now().Unix()
  6555. creater := c.GetAdminUserInfo().AdminUser.Id
  6556. //创建退库单
  6557. timeStr := time.Now().Format("2006-01-02")
  6558. timeArr := strings.Split(timeStr, "-")
  6559. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6560. total = total + 1
  6561. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6562. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6563. cancelStock := models.CancelStock{
  6564. OrderNumber: orderNumber,
  6565. OperaTime: operation_time,
  6566. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6567. Creater: creater,
  6568. Ctime: time.Now().Unix(),
  6569. Status: 1,
  6570. ReturnTime: item.RecordDate,
  6571. Type: 1,
  6572. StorehouseId: houseConfig.StorehouseOutInfo,
  6573. IsCheck: 1,
  6574. }
  6575. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6576. if msgerrkonde == gorm.ErrRecordNotFound {
  6577. service.AddSigleCancelStock(&cancelStock)
  6578. }
  6579. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6580. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6581. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6582. //查询该耗材是否出库
  6583. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6584. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6585. deaerler, _ := service.GetDealerById(info.Dealer)
  6586. var total_count int64
  6587. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6588. total_count += count
  6589. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6590. var flush_count int64
  6591. for _, it := range goodList {
  6592. flush_count += it.StockCount
  6593. }
  6594. fmt.Println("历史出库数据", info.Count)
  6595. fmt.Println("出库数量", total_count)
  6596. if info.ID > 0 {
  6597. cancelStockInfo := models.CancelStockInfo{
  6598. GoodId: item.ProjectId,
  6599. CancelStockId: cancel.ID,
  6600. GoodTypeId: good.GoodTypeId,
  6601. Count: prescribingNumber,
  6602. Price: info.Price,
  6603. Total: 0,
  6604. ProductDate: info.ProductDate,
  6605. ExpiryDate: info.ExpiryDate,
  6606. Ctime: time.Now().Unix(),
  6607. Status: 1,
  6608. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6609. OrderNumber: cancel.OrderNumber,
  6610. Type: 0,
  6611. Dealer: deaerler.DealerName,
  6612. Manufacturer: manufacturer.ManufacturerName,
  6613. Number: info.Number,
  6614. RegisterAccount: "",
  6615. Remark: "",
  6616. WarehouseInfoId: info.WarehouseInfotId,
  6617. PatientId: info.PatientId,
  6618. RecordDate: info.SysRecordTime,
  6619. StorehouseId: houseConfig.StorehouseOutInfo,
  6620. IsCheck: 1,
  6621. }
  6622. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6623. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6624. //查询出库数量
  6625. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6626. //出库数据 大于 退库数量
  6627. if len(list) > 0 {
  6628. for _, it := range list {
  6629. //回退库存
  6630. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6631. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6632. var flush_count_one int64
  6633. for _, it := range goodList {
  6634. flush_count_one += it.StockCount
  6635. }
  6636. //查询该批次是否有退库数据
  6637. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6638. creater := c.GetAdminUserInfo().AdminUser.Id
  6639. flow := models.VmStockFlow{
  6640. WarehousingId: it.WarehouseInfotId,
  6641. GoodId: it.GoodId,
  6642. Number: it.Number,
  6643. LicenseNumber: it.LicenseNumber,
  6644. Count: it.Count,
  6645. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6646. PatientId: it.PatientId,
  6647. SystemTime: it.SysRecordTime,
  6648. ConsumableType: 7,
  6649. IsSys: 0,
  6650. WarehousingOrder: "",
  6651. WarehouseOutId: it.WarehouseOutId,
  6652. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6653. IsEdit: 0,
  6654. CancelStockId: cancel.ID,
  6655. CancelOrderNumber: cancel.OrderNumber,
  6656. Manufacturer: manufacturer.ID,
  6657. Dealer: 0,
  6658. Creator: creater,
  6659. UpdateCreator: 0,
  6660. Status: 1,
  6661. Ctime: time.Now().Unix(),
  6662. Mtime: 0,
  6663. Price: it.Price,
  6664. WarehousingDetailId: it.WarehouseInfotId,
  6665. WarehouseOutDetailId: it.ID,
  6666. CancelOutDetailId: cancelInfo.ID,
  6667. ProductDate: it.ProductDate,
  6668. ExpireDate: it.ExpiryDate,
  6669. StorehouseId: houseConfig.StorehouseOutInfo,
  6670. OverCount: flush_count_one,
  6671. OperateTime: time.Now().Unix(),
  6672. }
  6673. service.CreateStockFlowOne(flow)
  6674. //if flow.ID > 0 {
  6675. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6676. //}
  6677. }
  6678. }
  6679. //flow := models.VmStockFlow{
  6680. // WarehousingId: info.WarehouseInfotId,
  6681. // GoodId: item.ProjectId,
  6682. // Number: info.Number,
  6683. // LicenseNumber: info.LicenseNumber,
  6684. // Count: prescribingNumber,
  6685. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6686. // PatientId: item.PatientId,
  6687. // SystemTime: info.SysRecordTime,
  6688. // ConsumableType: 7,
  6689. // IsSys: 0,
  6690. // WarehousingOrder: "",
  6691. // WarehouseOutId: info.WarehouseOutId,
  6692. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6693. // IsEdit: 0,
  6694. // CancelStockId: cancel.ID,
  6695. // CancelOrderNumber: cancel.OrderNumber,
  6696. // Manufacturer: manufacturer.ID,
  6697. // Dealer: 0,
  6698. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6699. // UpdateCreator: 0,
  6700. // Status: 1,
  6701. // Ctime: time.Now().Unix(),
  6702. // Mtime: 0,
  6703. // Price: info.Price,
  6704. // WarehousingDetailId: info.WarehouseInfotId,
  6705. // WarehouseOutDetailId: info.ID,
  6706. // CancelOutDetailId: cancelInfo.ID,
  6707. // ProductDate: info.ProductDate,
  6708. // ExpireDate: info.ExpiryDate,
  6709. // StorehouseId: houseConfig.StorehouseOutInfo,
  6710. // OverCount: flush_count,
  6711. //}
  6712. //service.CreateStockFlowOne(flow)
  6713. //退库数量增加
  6714. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6715. //出库数量减少
  6716. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6717. //查询已出库数量
  6718. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6719. if prescribingNumber < dialysisInfo.Count {
  6720. //改变数量
  6721. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6722. }
  6723. if prescribingNumber >= dialysisInfo.Count {
  6724. //删除出库表
  6725. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6726. }
  6727. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6728. var flush_count_one int64
  6729. for _, it := range goodList {
  6730. flush_count_one += it.StockCount
  6731. }
  6732. //更新库存
  6733. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6734. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6735. //更新基础库库存
  6736. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6737. }
  6738. }
  6739. }
  6740. }
  6741. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6742. fmt.Println(err)
  6743. }
  6744. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6745. fmt.Println(err)
  6746. if len(advices) > 0 {
  6747. for _, item := range advices {
  6748. redis := service.RedisClient()
  6749. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6750. redis.Set(keyFive, "", time.Second)
  6751. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6752. redis.Set(keyOne, "", time.Second)
  6753. redis.Close()
  6754. }
  6755. }
  6756. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6757. if len(advices) > 0 {
  6758. for _, item := range advices {
  6759. creater := c.GetAdminUserInfo().AdminUser.Id
  6760. service.DrugAutoAddCancelInfo(item, creater)
  6761. }
  6762. }
  6763. } else {
  6764. if drugOutConfig.IsOpen == 1 {
  6765. if len(advices) > 0 {
  6766. for _, item := range advices {
  6767. creater := c.GetAdminUserInfo().AdminUser.Id
  6768. service.DrugAutoAddCancelInfo(item, creater)
  6769. }
  6770. }
  6771. } else {
  6772. if len(advices) > 0 {
  6773. for _, item := range advices {
  6774. creater := c.GetAdminUserInfo().AdminUser.Id
  6775. service.DrugAutoAddCancelInfo(item, creater)
  6776. }
  6777. }
  6778. }
  6779. }
  6780. c.ServeSuccessJSON(map[string]interface{}{
  6781. "msg": "删除成功",
  6782. })
  6783. return
  6784. }
  6785. func (c *HisApiController) DeleteDoctorAdvice() {
  6786. id, _ := c.GetInt64("id")
  6787. advice, _ := service.GetHisDoctorAdvicesById(id)
  6788. ////同步到自备药
  6789. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6790. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6791. if selfPrescriptionOpen.IsOpen == 1 {
  6792. db := service.XTWriteDB()
  6793. tx := db.Begin()
  6794. defer func() {
  6795. if r := recover(); r != nil {
  6796. tx.Rollback()
  6797. } else {
  6798. tx.Commit()
  6799. }
  6800. }()
  6801. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6802. var total_count int64
  6803. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6804. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6805. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6806. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6807. }
  6808. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6809. total_count += prescribingNumberSeven
  6810. }
  6811. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6812. total_count += prescribingNumberSeven
  6813. }
  6814. timeStr := time.Now().Format("2006-01-02")
  6815. timeArr := strings.Split(timeStr, "-")
  6816. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6817. total = total + 1
  6818. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6819. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6820. number = number + total
  6821. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6822. operation_time := time.Now().Unix()
  6823. creater := c.GetAdminUserInfo().AdminUser.Id
  6824. //创建一个出库单
  6825. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6826. WarehouseOutOrderNumber: warehousing_out_order,
  6827. OperationTime: operation_time,
  6828. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6829. Creater: creater,
  6830. Ctime: time.Now().Unix(),
  6831. Status: 1,
  6832. WarehouseOutTime: advice.AdviceDate,
  6833. Type: 0,
  6834. PatientId: advice.PatientId,
  6835. IsCheck: 1,
  6836. }
  6837. //查询今日是否有出库数据
  6838. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6839. if lastWarehouseOut.ID == 0 {
  6840. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6841. }
  6842. //出库
  6843. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6844. WarehouseOutId: lastWarehouseOut.ID,
  6845. WarehouseOutOrderNumber: warehousing_out_order,
  6846. DrugId: advice.DrugId,
  6847. Count: total_count,
  6848. Price: 0,
  6849. TotalPrice: 0,
  6850. Status: 1,
  6851. Ctime: advice.AdviceDate,
  6852. Mtime: advice.AdviceDate,
  6853. Remark: "",
  6854. OrgId: advice.UserOrgId,
  6855. Type: 0,
  6856. Manufacturer: selfBasedrug.Manufacturer,
  6857. Dealer: selfBasedrug.Dealer,
  6858. RetailPrice: 0,
  6859. RetailTotalPrice: 0,
  6860. CountUnit: advice.PrescribingNumberUnit,
  6861. ExpiryDate: 0,
  6862. ProductDate: 0,
  6863. Number: "",
  6864. BatchNumber: "",
  6865. IsSys: 0,
  6866. WarehouseInfoId: 0,
  6867. AdminUserId: 0,
  6868. StockCount: "",
  6869. IsCheck: 1,
  6870. SysRecordTime: advice.AdviceDate,
  6871. PatientId: advice.PatientId,
  6872. AdviceId: advice.ID,
  6873. ClassType: "",
  6874. }
  6875. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6876. for _, it := range warehousingOutInfo {
  6877. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6878. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6879. //出库逻辑
  6880. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6881. //查询剩余库存
  6882. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6883. var sum_count int64
  6884. for _, its := range stockInfo {
  6885. if its.MaxUnit == medical.MaxUnit {
  6886. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6887. }
  6888. sum_count += its.StockMaxNumber + its.StockMinNumber
  6889. }
  6890. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6891. }
  6892. }
  6893. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6894. //已收费和已发药的限制逻辑
  6895. isCharge := false
  6896. isMedicine := false
  6897. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6898. //获取今天该患者所有处方,判断是否发药或者收费
  6899. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6900. //for _, item := range new_prescriptions {
  6901. if new_prescription.IsMedicine == 1 {
  6902. isMedicine = true
  6903. }
  6904. //}
  6905. for _, item := range new_prescriptions {
  6906. if item.OrderStatus == 4 {
  6907. isCharge = true
  6908. }
  6909. }
  6910. if isMedicine {
  6911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6912. return
  6913. }
  6914. if isCharge {
  6915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6916. return
  6917. }
  6918. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6919. creater := c.GetAdminUserInfo().AdminUser.Id
  6920. for _, item := range advices {
  6921. if item.IsMedicine == 1 {
  6922. isMedicine = true
  6923. }
  6924. byterequest, _ := json.Marshal(item)
  6925. adviceLog := models.XtDoctorAdviceLog{
  6926. UserOrgId: item.UserOrgId,
  6927. PatientId: item.PatientId,
  6928. AdminUserId: creater,
  6929. Module: 1,
  6930. ErrLog: string(byterequest),
  6931. Status: 1,
  6932. Ctime: time.Now().Unix(),
  6933. Mtime: 0,
  6934. Source: "电脑端删除医嘱",
  6935. RecordDate: item.AdviceDate,
  6936. }
  6937. service.CreateDoctorAdviceLog(adviceLog)
  6938. }
  6939. if isMedicine {
  6940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6941. return
  6942. }
  6943. if new_prescription.ID > 0 {
  6944. if new_prescription.OrderStatus == 2 {
  6945. isCharge = true
  6946. }
  6947. }
  6948. if isCharge {
  6949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6950. return
  6951. }
  6952. //已收费和已发药的限制逻辑
  6953. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6954. redis := service.RedisClient()
  6955. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6956. redis.Set(keyFive, "", time.Second)
  6957. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6958. redis.Set(keyOne, "", time.Second)
  6959. defer redis.Close()
  6960. if err == nil {
  6961. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6962. //查询是否在处方中出库
  6963. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6964. if openConfig.IsOpen != 1 {
  6965. //判断该医嘱是否执行了
  6966. if advice.ExecutionState == 1 {
  6967. creater := c.GetAdminUserInfo().AdminUser.Id
  6968. service.DrugAutoAddCancelInfo(&advice, creater)
  6969. }
  6970. }
  6971. //开启保存处方扣减功能
  6972. if openConfig.IsOpen == 1 {
  6973. creater := c.GetAdminUserInfo().AdminUser.Id
  6974. service.DrugAutoAddCancelInfo(&advice, creater)
  6975. }
  6976. } else {
  6977. if drugOutConfig.IsOpen == 1 {
  6978. //查询是否在处方中出库
  6979. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6980. if openConfig.IsOpen != 1 {
  6981. //判断该医嘱是否执行了
  6982. if advice.ExecutionState == 1 {
  6983. creater := c.GetAdminUserInfo().AdminUser.Id
  6984. service.DrugAutoAddCancelInfo(&advice, creater)
  6985. }
  6986. }
  6987. //开启保存处方扣减功能
  6988. if openConfig.IsOpen == 1 {
  6989. creater := c.GetAdminUserInfo().AdminUser.Id
  6990. service.DrugAutoAddCancelInfo(&advice, creater)
  6991. }
  6992. } else {
  6993. //判断该医嘱是否执行了
  6994. if advice.ExecutionState == 1 {
  6995. creater := c.GetAdminUserInfo().AdminUser.Id
  6996. service.DrugAutoAddCancelInfo(&advice, creater)
  6997. }
  6998. }
  6999. }
  7000. c.ServeSuccessJSON(map[string]interface{}{
  7001. "msg": "删除成功",
  7002. })
  7003. return
  7004. } else {
  7005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7006. return
  7007. }
  7008. }
  7009. func (c *HisApiController) DeleteProject() {
  7010. id, _ := c.GetInt64("id")
  7011. adminInfo := c.GetAdminUserInfo()
  7012. project, _ := service.GetHisProjectByID(id)
  7013. // var consumable models.DialysisBeforePrepare
  7014. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  7015. //耗材保存处方出库
  7016. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  7017. isCharge := false
  7018. isMedicine := false
  7019. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  7020. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  7021. creater := c.GetAdminUserInfo().AdminUser.Id
  7022. for _, item := range new_prescriptions {
  7023. if item.IsMedicine == 1 {
  7024. isMedicine = true
  7025. }
  7026. byterequest, _ := json.Marshal(item)
  7027. adviceLog := models.XtDoctorAdviceLog{
  7028. UserOrgId: item.UserOrgId,
  7029. PatientId: item.PatientId,
  7030. AdminUserId: creater,
  7031. Module: 1,
  7032. ErrLog: string(byterequest),
  7033. Status: 1,
  7034. Ctime: time.Now().Unix(),
  7035. Mtime: 0,
  7036. Source: "电脑端删除医嘱",
  7037. RecordDate: item.RecordDate,
  7038. }
  7039. service.CreateDoctorAdviceLog(adviceLog)
  7040. }
  7041. for _, item := range new_prescriptions {
  7042. if item.OrderStatus == 4 {
  7043. isCharge = true
  7044. }
  7045. }
  7046. if isMedicine {
  7047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  7048. return
  7049. }
  7050. if isCharge {
  7051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  7052. return
  7053. }
  7054. if new_prescription.ID > 0 {
  7055. if new_prescription.OrderStatus == 2 {
  7056. isCharge = true
  7057. }
  7058. }
  7059. if isCharge {
  7060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  7061. return
  7062. }
  7063. service.DeletePrintInfo(id)
  7064. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  7065. label.Status = 0
  7066. service.CreateHisLabelRecordTwo(&label)
  7067. fmt.Println(goodOutConfig.IsOpen)
  7068. if goodOutConfig.IsOpen != 1 {
  7069. if stockConfig.IsOpen == 1 {
  7070. if project.Type == 2 {
  7071. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7072. fmt.Println(err)
  7073. }
  7074. if project.Type == 3 && project.IsOut == 1 {
  7075. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7076. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7077. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7078. operation_time := time.Now().Unix()
  7079. creater := adminInfo.AdminUser.Id
  7080. //创建退库单
  7081. timeStr := time.Now().Format("2006-01-02")
  7082. timeArr := strings.Split(timeStr, "-")
  7083. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7084. total = total + 1
  7085. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7086. cancelStock := models.CancelStock{
  7087. OrderNumber: orderNumber,
  7088. OperaTime: operation_time,
  7089. OrgId: adminInfo.CurrentOrgId,
  7090. Creater: creater,
  7091. Ctime: time.Now().Unix(),
  7092. Status: 1,
  7093. ReturnTime: project.RecordDate,
  7094. Type: 1,
  7095. StorehouseId: houseConfig.StorehouseOutInfo,
  7096. IsCheck: 1,
  7097. }
  7098. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7099. if msgerrkonde == gorm.ErrRecordNotFound {
  7100. service.AddSigleCancelStock(&cancelStock)
  7101. }
  7102. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7103. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7104. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7105. //查询是否有出库
  7106. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7107. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7108. deaerler, _ := service.GetDealerById(info.Dealer)
  7109. if info.ID > 0 {
  7110. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7111. if info.Count >= prescribingNumber {
  7112. cancelStockInfo := models.CancelStockInfo{
  7113. GoodId: project.ProjectId,
  7114. CancelStockId: cancel.ID,
  7115. GoodTypeId: good.GoodTypeId,
  7116. Count: prescribingNumber,
  7117. Price: info.Price,
  7118. Total: 0,
  7119. ProductDate: info.ProductDate,
  7120. ExpiryDate: info.ExpiryDate,
  7121. Ctime: time.Now().Unix(),
  7122. Status: 1,
  7123. OrgId: adminInfo.CurrentOrgId,
  7124. OrderNumber: cancel.OrderNumber,
  7125. Type: 0,
  7126. Dealer: deaerler.DealerName,
  7127. Manufacturer: manufacturer.ManufacturerName,
  7128. Number: info.Number,
  7129. RegisterAccount: "",
  7130. Remark: "",
  7131. WarehouseInfoId: info.WarehouseInfotId,
  7132. PatientId: info.PatientId,
  7133. RecordDate: info.SysRecordTime,
  7134. StorehouseId: houseConfig.StorehouseOutInfo,
  7135. IsCheck: 1,
  7136. }
  7137. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7138. //回退库存
  7139. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  7140. //退库数量增加
  7141. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7142. //出库数量减少
  7143. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7144. }
  7145. if info.Count < prescribingNumber {
  7146. cancelStockInfo := models.CancelStockInfo{
  7147. GoodId: project.ProjectId,
  7148. CancelStockId: cancel.ID,
  7149. GoodTypeId: good.GoodTypeId,
  7150. Count: info.Count,
  7151. Price: info.Price,
  7152. Total: 0,
  7153. ProductDate: info.ProductDate,
  7154. ExpiryDate: info.ExpiryDate,
  7155. Ctime: time.Now().Unix(),
  7156. Status: 1,
  7157. OrgId: adminInfo.CurrentOrgId,
  7158. OrderNumber: cancel.OrderNumber,
  7159. Type: 0,
  7160. Dealer: deaerler.DealerName,
  7161. Manufacturer: manufacturer.ManufacturerName,
  7162. Number: info.Number,
  7163. RegisterAccount: "",
  7164. Remark: "",
  7165. WarehouseInfoId: info.WarehouseInfotId,
  7166. PatientId: info.PatientId,
  7167. RecordDate: info.SysRecordTime,
  7168. StorehouseId: houseConfig.StorehouseOutInfo,
  7169. IsCheck: 1,
  7170. }
  7171. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7172. //回退库存
  7173. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7174. //退库数量增加
  7175. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  7176. //出库数量减少
  7177. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  7178. }
  7179. //查询剩余库存
  7180. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7181. var over_count int64
  7182. for _, it := range goodList {
  7183. over_count += it.StockCount
  7184. }
  7185. //出库数据 大于 退库数量
  7186. if info.Count >= prescribingNumber {
  7187. flow := models.VmStockFlow{
  7188. WarehousingId: info.WarehouseInfotId,
  7189. GoodId: project.ProjectId,
  7190. Number: info.Number,
  7191. LicenseNumber: info.LicenseNumber,
  7192. Count: prescribingNumber,
  7193. UserOrgId: adminInfo.CurrentOrgId,
  7194. PatientId: project.PatientId,
  7195. SystemTime: info.SysRecordTime,
  7196. ConsumableType: 7,
  7197. IsSys: 0,
  7198. WarehousingOrder: "",
  7199. WarehouseOutId: info.WarehouseOutId,
  7200. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7201. IsEdit: 0,
  7202. CancelStockId: cancel.ID,
  7203. CancelOrderNumber: cancel.OrderNumber,
  7204. Manufacturer: manufacturer.ID,
  7205. Dealer: 0,
  7206. Creator: adminInfo.AdminUser.Id,
  7207. UpdateCreator: 0,
  7208. Status: 1,
  7209. Ctime: time.Now().Unix(),
  7210. Mtime: 0,
  7211. Price: info.Price,
  7212. WarehousingDetailId: info.WarehouseInfotId,
  7213. WarehouseOutDetailId: info.ID,
  7214. CancelOutDetailId: cancelInfo.ID,
  7215. ProductDate: info.ProductDate,
  7216. ExpireDate: info.ExpiryDate,
  7217. StorehouseId: houseConfig.StorehouseOutInfo,
  7218. OverCount: over_count,
  7219. OperateTime: time.Now().Unix(),
  7220. }
  7221. service.CreateStockFlowOne(flow)
  7222. }
  7223. //出库数据小于退库数据
  7224. if info.Count < prescribingNumber {
  7225. flow := models.VmStockFlow{
  7226. WarehousingId: info.WarehouseInfotId,
  7227. GoodId: project.ProjectId,
  7228. Number: info.Number,
  7229. LicenseNumber: info.LicenseNumber,
  7230. Count: info.Count,
  7231. UserOrgId: adminInfo.CurrentOrgId,
  7232. PatientId: project.PatientId,
  7233. SystemTime: info.SysRecordTime,
  7234. ConsumableType: 7,
  7235. IsSys: 0,
  7236. WarehousingOrder: "",
  7237. WarehouseOutId: info.WarehouseOutId,
  7238. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7239. IsEdit: 0,
  7240. CancelStockId: cancel.ID,
  7241. CancelOrderNumber: cancel.OrderNumber,
  7242. Manufacturer: manufacturer.ID,
  7243. Dealer: 0,
  7244. Creator: adminInfo.AdminUser.Id,
  7245. UpdateCreator: 0,
  7246. Status: 1,
  7247. Ctime: time.Now().Unix(),
  7248. Mtime: 0,
  7249. Price: info.Price,
  7250. WarehousingDetailId: info.WarehouseInfotId,
  7251. WarehouseOutDetailId: info.ID,
  7252. CancelOutDetailId: cancelInfo.ID,
  7253. ProductDate: info.ProductDate,
  7254. ExpireDate: info.ExpiryDate,
  7255. StorehouseId: houseConfig.StorehouseOutInfo,
  7256. OverCount: over_count,
  7257. OperateTime: time.Now().Unix(),
  7258. }
  7259. service.CreateStockFlowOne(flow)
  7260. }
  7261. //查询已出库数量
  7262. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7263. if prescribingNumber < dialysisInfo.Count {
  7264. //改变数量
  7265. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7266. }
  7267. if prescribingNumber >= dialysisInfo.Count {
  7268. //删除出库表
  7269. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7270. }
  7271. //更新剩余库存
  7272. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7273. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7274. var total_count_one int64
  7275. for _, it := range stockList {
  7276. total_count_one += it.StockCount
  7277. }
  7278. //基础库插入数据
  7279. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7280. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7281. var flush_count int64
  7282. for _, it := range goodListOne {
  7283. flush_count += it.StockCount
  7284. }
  7285. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7286. if errs != nil {
  7287. goodErrcode := models.XtGoodErrcode{
  7288. UserOrgId: project.UserOrgId,
  7289. Errcode: "手动出库更新剩余出库失败",
  7290. GoodId: project.ProjectId,
  7291. Status: 1,
  7292. Ctime: time.Now().Unix(),
  7293. Mtime: 0,
  7294. Count: 0,
  7295. StockCount: 0,
  7296. Creater: creater,
  7297. BatchNumberId: 0,
  7298. WarehouseOutId: 0,
  7299. }
  7300. service.CreateGoodErrcode(goodErrcode)
  7301. }
  7302. }
  7303. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7304. fmt.Println(err)
  7305. } else {
  7306. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7307. fmt.Println(err)
  7308. }
  7309. } else {
  7310. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7311. fmt.Println(err)
  7312. }
  7313. }
  7314. //保存处方出库
  7315. if goodOutConfig.IsOpen == 1 {
  7316. if project.Type == 3 {
  7317. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7318. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7319. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7320. operation_time := time.Now().Unix()
  7321. creater := adminInfo.AdminUser.Id
  7322. //创建退库单
  7323. timeStr := time.Now().Format("2006-01-02")
  7324. timeArr := strings.Split(timeStr, "-")
  7325. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7326. total = total + 1
  7327. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7328. cancelStock := models.CancelStock{
  7329. OrderNumber: orderNumber,
  7330. OperaTime: operation_time,
  7331. OrgId: adminInfo.CurrentOrgId,
  7332. Creater: creater,
  7333. Ctime: time.Now().Unix(),
  7334. Status: 1,
  7335. ReturnTime: project.RecordDate,
  7336. Type: 1,
  7337. StorehouseId: houseConfig.StorehouseOutInfo,
  7338. IsCheck: 1,
  7339. }
  7340. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7341. if msgerrkonde == gorm.ErrRecordNotFound {
  7342. service.AddSigleCancelStock(&cancelStock)
  7343. }
  7344. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7345. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7346. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7347. //获取出库数据
  7348. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7349. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7350. deaerler, _ := service.GetDealerById(info.Dealer)
  7351. if info.ID > 0 {
  7352. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7353. if info.Count >= prescribingNumber {
  7354. cancelStockInfo := models.CancelStockInfo{
  7355. GoodId: project.ProjectId,
  7356. CancelStockId: cancel.ID,
  7357. GoodTypeId: good.GoodTypeId,
  7358. Count: prescribingNumber,
  7359. Price: info.Price,
  7360. Total: 0,
  7361. ProductDate: info.ProductDate,
  7362. ExpiryDate: info.ExpiryDate,
  7363. Ctime: time.Now().Unix(),
  7364. Status: 1,
  7365. OrgId: adminInfo.CurrentOrgId,
  7366. OrderNumber: cancel.OrderNumber,
  7367. Type: 0,
  7368. Dealer: deaerler.DealerName,
  7369. Manufacturer: manufacturer.ManufacturerName,
  7370. Number: info.Number,
  7371. RegisterAccount: "",
  7372. Remark: "",
  7373. WarehouseInfoId: info.WarehouseInfotId,
  7374. PatientId: info.PatientId,
  7375. RecordDate: info.SysRecordTime,
  7376. StorehouseId: houseConfig.StorehouseOutInfo,
  7377. IsCheck: 1,
  7378. }
  7379. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7380. //退库数量增加
  7381. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7382. //出库数量减少
  7383. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7384. }
  7385. if info.Count < prescribingNumber {
  7386. cancelStockInfo := models.CancelStockInfo{
  7387. GoodId: project.ProjectId,
  7388. CancelStockId: cancel.ID,
  7389. GoodTypeId: good.GoodTypeId,
  7390. Count: prescribingNumber,
  7391. Price: info.Price,
  7392. Total: 0,
  7393. ProductDate: info.ProductDate,
  7394. ExpiryDate: info.ExpiryDate,
  7395. Ctime: time.Now().Unix(),
  7396. Status: 1,
  7397. OrgId: adminInfo.CurrentOrgId,
  7398. OrderNumber: cancel.OrderNumber,
  7399. Type: 0,
  7400. Dealer: deaerler.DealerName,
  7401. Manufacturer: manufacturer.ManufacturerName,
  7402. Number: info.Number,
  7403. RegisterAccount: "",
  7404. Remark: "",
  7405. WarehouseInfoId: info.WarehouseInfotId,
  7406. PatientId: info.PatientId,
  7407. RecordDate: info.SysRecordTime,
  7408. StorehouseId: houseConfig.StorehouseOutInfo,
  7409. IsCheck: 1,
  7410. }
  7411. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7412. //回退库存
  7413. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7414. }
  7415. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7416. var over_count int64
  7417. for _, it := range goodList {
  7418. over_count += it.StockCount
  7419. }
  7420. //查询出库数量
  7421. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7422. //出库数据 大于 退库数量
  7423. if len(list) > 0 {
  7424. for _, it := range list {
  7425. //回退库存
  7426. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7427. //退库数量增加
  7428. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7429. //出库数量减少
  7430. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7431. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7432. var over_count_one int64
  7433. for _, it := range goodList {
  7434. over_count_one += it.StockCount
  7435. }
  7436. //查询该批次是否有退库数据
  7437. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7438. flow := models.VmStockFlow{
  7439. WarehousingId: it.WarehouseInfotId,
  7440. GoodId: it.GoodId,
  7441. Number: it.Number,
  7442. LicenseNumber: it.LicenseNumber,
  7443. Count: it.Count,
  7444. UserOrgId: adminInfo.CurrentOrgId,
  7445. PatientId: it.PatientId,
  7446. SystemTime: it.SysRecordTime,
  7447. ConsumableType: 7,
  7448. IsSys: 0,
  7449. WarehousingOrder: "",
  7450. WarehouseOutId: it.WarehouseOutId,
  7451. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7452. IsEdit: 0,
  7453. CancelStockId: cancel.ID,
  7454. CancelOrderNumber: cancel.OrderNumber,
  7455. Manufacturer: manufacturer.ID,
  7456. Dealer: 0,
  7457. Creator: adminInfo.AdminUser.Id,
  7458. UpdateCreator: 0,
  7459. Status: 1,
  7460. Ctime: time.Now().Unix(),
  7461. Mtime: 0,
  7462. Price: it.Price,
  7463. WarehousingDetailId: it.WarehouseInfotId,
  7464. WarehouseOutDetailId: it.ID,
  7465. CancelOutDetailId: cancelInfo.ID,
  7466. ProductDate: it.ProductDate,
  7467. ExpireDate: it.ExpiryDate,
  7468. StorehouseId: houseConfig.StorehouseOutInfo,
  7469. OverCount: over_count_one,
  7470. OperateTime: time.Now().Unix(),
  7471. }
  7472. service.CreateStockFlowOne(flow)
  7473. }
  7474. }
  7475. //查询已出库数量
  7476. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7477. if prescribingNumber < dialysisInfo.Count {
  7478. //改变数量
  7479. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7480. }
  7481. if prescribingNumber >= dialysisInfo.Count {
  7482. //删除出库表
  7483. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7484. }
  7485. //更新剩余库存
  7486. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7487. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7488. var total_count_one int64
  7489. for _, it := range stockList {
  7490. total_count_one += it.StockCount
  7491. }
  7492. //基础库插入数据
  7493. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7494. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7495. var flush_count int64
  7496. for _, it := range goodListOne {
  7497. flush_count += it.StockCount
  7498. }
  7499. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7500. if errs != nil {
  7501. goodErrcode := models.XtGoodErrcode{
  7502. UserOrgId: project.UserOrgId,
  7503. Errcode: "手动出库更新剩余出库失败",
  7504. GoodId: project.ProjectId,
  7505. Status: 1,
  7506. Ctime: time.Now().Unix(),
  7507. Mtime: 0,
  7508. Count: 0,
  7509. StockCount: 0,
  7510. Creater: creater,
  7511. BatchNumberId: 0,
  7512. WarehouseOutId: 0,
  7513. }
  7514. service.CreateGoodErrcode(goodErrcode)
  7515. }
  7516. }
  7517. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7518. fmt.Println(err)
  7519. } else {
  7520. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7521. fmt.Println(err)
  7522. }
  7523. }
  7524. c.ServeSuccessJSON(map[string]interface{}{
  7525. "msg": "删除成功",
  7526. })
  7527. return
  7528. }
  7529. func (c *HisApiController) CreateHisAdditionalCharge() {
  7530. his_patient_id, _ := c.GetInt64("his_patient_id")
  7531. patient_id, _ := c.GetInt64("patient_id")
  7532. record_date := c.GetString("record_date")
  7533. timeLayout := "2006-01-02"
  7534. loc, _ := time.LoadLocation("Local")
  7535. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7536. if err != nil {
  7537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7538. return
  7539. }
  7540. adminInfo := c.GetAdminUserInfo()
  7541. recordDateTime := theTime.Unix()
  7542. dataBody := make(map[string]interface{}, 0)
  7543. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7544. if err != nil {
  7545. utils.ErrorLog(err.Error())
  7546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7547. return
  7548. }
  7549. var additions []*models.HisAdditionalCharge
  7550. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7551. additions, _ := dataBody["addition"].([]interface{})
  7552. if len(additions) > 0 {
  7553. for _, item := range additions {
  7554. items := item.(map[string]interface{})
  7555. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7556. utils.ErrorLog("item_id")
  7557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7558. return
  7559. }
  7560. item_id := int64(items["item_id"].(float64))
  7561. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7562. utils.ErrorLog("item_name")
  7563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7564. return
  7565. }
  7566. item_name := items["item_name"].(string)
  7567. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7568. utils.ErrorLog("price")
  7569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7570. return
  7571. }
  7572. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7573. ctime := time.Now().Unix()
  7574. additional := &models.HisAdditionalCharge{
  7575. PatientId: patient_id,
  7576. HisPatientId: his_patient_id,
  7577. UserOrgId: adminInfo.CurrentOrgId,
  7578. RecordDate: recordDateTime,
  7579. CreatedTime: ctime,
  7580. UpdatedTime: ctime,
  7581. Modifier: adminInfo.AdminUser.Id,
  7582. Creator: adminInfo.AdminUser.Id,
  7583. Price: price,
  7584. ItemName: item_name,
  7585. ItemId: item_id,
  7586. Status: 1,
  7587. }
  7588. additions = append(additions, additional)
  7589. }
  7590. }
  7591. }
  7592. for _, item := range additions {
  7593. service.CreateAddtionalCharge(item)
  7594. }
  7595. c.ServeSuccessJSON(map[string]interface{}{
  7596. "msg": "创建成功",
  7597. })
  7598. }
  7599. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7600. blood_fat := c.GetString("blood_fat")
  7601. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7602. blood_sugar := c.GetString("blood_sugar")
  7603. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7604. chief_conplaint := c.GetString("chief_conplaint")
  7605. dbp := c.GetString("dbp")
  7606. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7607. delivery_way, _ := c.GetInt64("delivery_way")
  7608. diagnostic := c.GetString("diagnostic")
  7609. family_history := c.GetString("family_history")
  7610. height := c.GetString("height")
  7611. history_of_present_illness := c.GetString("history_of_present_illness")
  7612. is_infect, _ := c.GetInt64("is_infect")
  7613. past_history := c.GetString("past_history")
  7614. patient_id, _ := c.GetInt64("patient_id")
  7615. his_patient_id, _ := c.GetInt64("his_patient_id")
  7616. personal_history := c.GetString("personal_history")
  7617. pulse := c.GetString("pulse")
  7618. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7619. sbp := c.GetString("sbp")
  7620. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7621. heightfloat, _ := strconv.ParseFloat(height, 64)
  7622. sicktype := c.GetString("sick_type")
  7623. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7624. symptom := c.GetString("symptom")
  7625. sick_date := c.GetString("sick_date")
  7626. temperatures := c.GetString("temperature")
  7627. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7628. record_date := c.GetString("record_date")
  7629. breathing := c.GetString("breathing")
  7630. doctor_advice := c.GetString("doctor_advice")
  7631. remark := c.GetString("remark")
  7632. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7633. sick, _ := c.GetInt64("sick")
  7634. diagnose, _ := c.GetInt64("diagnose")
  7635. //id, _ := c.GetInt64("id")
  7636. timeLayout := "2006-01-02"
  7637. loc, _ := time.LoadLocation("Local")
  7638. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7639. allergic_history := c.GetString("allergic_history")
  7640. if err != nil {
  7641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7642. return
  7643. }
  7644. recordDateTime := theTime.Unix()
  7645. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7646. if err != nil {
  7647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7648. return
  7649. }
  7650. sickTimes := sickTime.Unix()
  7651. ctime := time.Now().Unix()
  7652. primary_disease := c.GetString("primary_disease")
  7653. confirm_failure_date := c.GetString("confirm_failure_date")
  7654. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7655. drug_allergy_history := c.GetString("drug_allergy_history")
  7656. physical_examination := c.GetString("physical_examination")
  7657. special_inspection := c.GetString("special_inspection")
  7658. lab_apparatus := c.GetString("lab_apparatus")
  7659. caseHistory := models.HisPatientCaseHistory{
  7660. HisPatientId: his_patient_id,
  7661. PatientId: patient_id,
  7662. Temperature: temperature,
  7663. BloodSugar: bloodsugarfloat,
  7664. Pulse: pulsefloat,
  7665. Sbp: sbpfloat,
  7666. Dbp: dbpfloat,
  7667. Height: heightfloat,
  7668. BloodFat: bloodfatfloat,
  7669. SickType: sick_type,
  7670. Symptom: symptom,
  7671. SickDate: sickTimes,
  7672. IsInfect: is_infect,
  7673. HistoryOfPresentIllness: history_of_present_illness,
  7674. PastHistory: past_history,
  7675. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7676. ChiefConplaint: chief_conplaint,
  7677. PersonalHistory: personal_history,
  7678. FamilyHistory: family_history,
  7679. Diagnostic: diagnostic,
  7680. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7681. Status: 1,
  7682. Ctime: ctime,
  7683. Mtime: ctime,
  7684. RecordDate: recordDateTime,
  7685. DeliveryWay: delivery_way,
  7686. Breathing: breathingfloat,
  7687. DoctorAdvice: doctor_advice,
  7688. Remark: remark,
  7689. Sick: sick,
  7690. Diagnose: diagnose,
  7691. AllergicHistory: allergic_history,
  7692. PrimaryDisease: primary_disease,
  7693. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7694. DrugAllergyHistory: drug_allergy_history,
  7695. PhysicalExamination: physical_examination,
  7696. SpecialInspection: special_inspection,
  7697. LabApparatus: lab_apparatus,
  7698. }
  7699. //查询该患者是否有病历
  7700. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7701. if errcodes == gorm.ErrRecordNotFound {
  7702. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7703. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7704. if err != nil {
  7705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7706. return
  7707. }
  7708. c.ServeSuccessJSON(map[string]interface{}{
  7709. "caseHistory": caseHistory,
  7710. "historyInfo": historyInfo,
  7711. })
  7712. return
  7713. } else if errcodes == nil {
  7714. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7715. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7716. if err != nil {
  7717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7718. return
  7719. }
  7720. c.ServeSuccessJSON(map[string]interface{}{
  7721. "caseHistory": caseHistory,
  7722. "historyInfo": historyInfo,
  7723. })
  7724. }
  7725. //查询该患者是否有病历
  7726. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7727. //if errcode == gorm.ErrRecordNotFound {
  7728. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7729. // if err != nil {
  7730. // c.ServeSuccessJSON(map[string]interface{}{
  7731. // "msg": "保存成功",
  7732. // })
  7733. // }
  7734. //} else if errcode == nil {
  7735. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7736. // return
  7737. //}
  7738. }
  7739. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7740. patient_id, _ := c.GetInt64("patient_id", 0)
  7741. adminUser := c.GetAdminUserInfo()
  7742. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7743. c.ServeSuccessJSON(map[string]interface{}{
  7744. "list": caseHistorys,
  7745. })
  7746. }
  7747. func (c *HisApiController) GetHisPatientCaseHistory() {
  7748. record_date, _ := c.GetInt64("record_date", 0)
  7749. patient_id, _ := c.GetInt64("patient_id", 0)
  7750. admin := c.GetAdminUserInfo()
  7751. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7752. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7753. c.ServeSuccessJSON(map[string]interface{}{
  7754. "info": info,
  7755. "case_history": case_history,
  7756. })
  7757. }
  7758. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7759. template_name := c.GetString("template_name")
  7760. template_remark := c.GetString("template_remark")
  7761. doctor := c.GetAdminUserInfo().AdminUser.Id
  7762. diagnostic := c.GetString("diagnostic")
  7763. chief_conplaint := c.GetString("chief_conplain")
  7764. history_of_present_illness := c.GetString("history_of_present_illness")
  7765. past_history := c.GetString("past_history")
  7766. personal_history := c.GetString("personal_history")
  7767. family_history := c.GetString("family_history")
  7768. user_name := c.GetString("user_name")
  7769. doctor_advice := c.GetString("doctor_advice")
  7770. remark := c.GetString("remark")
  7771. //record_date := c.GetString("record_date")
  7772. //fmt.Println("record_date--------",record_date)
  7773. //timeLayout := "2006-01-02"
  7774. //loc, _ := time.LoadLocation("Local")
  7775. //
  7776. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7777. //if err != nil {
  7778. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7779. // return
  7780. //}
  7781. //recordDateTime := theTime.Unix()
  7782. ctime := time.Now().Unix()
  7783. template := models.HisCaseHistoryTemplate{
  7784. HistoryOfPresentIllness: history_of_present_illness,
  7785. PastHistory: past_history,
  7786. ChiefConplaint: chief_conplaint,
  7787. PersonalHistory: personal_history,
  7788. FamilyHistory: family_history,
  7789. Diagnostic: diagnostic,
  7790. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7791. Status: 1,
  7792. Ctime: ctime,
  7793. Mtime: ctime,
  7794. RecordDate: time.Now().Unix(),
  7795. TemplateName: template_name,
  7796. TemplateRemark: template_remark,
  7797. Creator: doctor,
  7798. Modifier: doctor,
  7799. UserName: user_name,
  7800. DoctorAdvice: doctor_advice,
  7801. Remark: remark,
  7802. }
  7803. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7804. if err == nil {
  7805. c.ServeSuccessJSON(map[string]interface{}{
  7806. "msg": "保存成功",
  7807. })
  7808. } else {
  7809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7810. return
  7811. }
  7812. }
  7813. func (c *HisApiController) GetCaseHistoryTemplate() {
  7814. timeLayout := "2006-01-02"
  7815. loc, _ := time.LoadLocation("Local")
  7816. keyword := c.GetString("keyword")
  7817. start_time := c.GetString("start_time")
  7818. end_time := c.GetString("end_time")
  7819. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7820. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7821. admin := c.GetAdminUserInfo()
  7822. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7823. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7824. c.ServeSuccessJSON(map[string]interface{}{
  7825. "template": template,
  7826. //"history": history,
  7827. })
  7828. }
  7829. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7830. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7831. utils.ErrorLog("drug_name")
  7832. return enums.ErrorCodeParamWrong
  7833. }
  7834. adviceName, _ := json["drug_name"].(string)
  7835. if len(adviceName) == 0 {
  7836. utils.ErrorLog("len(advice_name) == 0")
  7837. return enums.ErrorCodeParamWrong
  7838. }
  7839. advice.AdviceName = adviceName
  7840. adviceDesc, _ := json["advice_desc"].(string)
  7841. advice.AdviceDesc = adviceDesc
  7842. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7843. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7844. advice.DrugSpec = drugSpec
  7845. }
  7846. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7847. remark, _ := json["remark"].(string)
  7848. advice.Remark = remark
  7849. }
  7850. if json["id"] == nil {
  7851. advice.DrugId = 0
  7852. } else {
  7853. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7854. drug_id := int64(json["id"].(float64))
  7855. advice.DrugId = drug_id
  7856. }
  7857. }
  7858. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7859. advice_id := int64(json["advice_id"].(float64))
  7860. advice.ID = advice_id
  7861. if advice.ID > 0 {
  7862. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7863. if err == nil {
  7864. if hisAdvice.ID > 0 {
  7865. advice.ExecutionTime = hisAdvice.ExecutionTime
  7866. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7867. advice.ExecutionState = hisAdvice.ExecutionState
  7868. advice.CheckTime = hisAdvice.CheckTime
  7869. advice.Checker = hisAdvice.Checker
  7870. advice.CheckState = hisAdvice.CheckState
  7871. advice.StartTime = hisAdvice.StartTime
  7872. advice.FeedetlSn = hisAdvice.FeedetlSn
  7873. }
  7874. }
  7875. }
  7876. }
  7877. //
  7878. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7879. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7880. // advice.ExecutionTime = execution_time
  7881. //}
  7882. //
  7883. //
  7884. //
  7885. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7886. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7887. // advice.ExecutionStaff = execution_staff
  7888. //}
  7889. //
  7890. //
  7891. //
  7892. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7893. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7894. // advice.ExecutionState = execution_state
  7895. //}
  7896. //
  7897. //
  7898. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7899. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7900. // advice.CheckTime = check_time
  7901. //}
  7902. //
  7903. //
  7904. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7905. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7906. // advice.CheckState = check_state
  7907. //}
  7908. //
  7909. //
  7910. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7911. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7912. // advice.Checker = checker
  7913. //}
  7914. //
  7915. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7916. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7917. // advice.StartTime = start_time
  7918. //}
  7919. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7920. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7921. advice.IsSelfDrug = is_self_drug
  7922. }
  7923. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7924. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7925. drug_way_count, _ := json["drug_way_count"].(string)
  7926. advice.DrugWayCount = drug_way_count
  7927. }
  7928. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7929. drugSpecUnit, _ := json["min_unit"].(string)
  7930. advice.DrugSpecUnit = drugSpecUnit
  7931. }
  7932. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7933. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7934. advice.SingleDose = singleDose
  7935. }
  7936. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7937. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7938. advice.SingleDoseUnit = singleDoseUnit
  7939. }
  7940. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7941. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7942. advice.PrescribingNumber = prescribingNumber
  7943. }
  7944. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7945. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7946. advice.PrescribingNumberUnit = prescribingNumberUnit
  7947. }
  7948. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7949. deliveryWay, _ := json["delivery_way"].(string)
  7950. advice.DeliveryWay = deliveryWay
  7951. }
  7952. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7953. executionFrequency, _ := json["execution_frequency"].(string)
  7954. advice.ExecutionFrequency = executionFrequency
  7955. }
  7956. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7957. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7958. advice.Price = price
  7959. }
  7960. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7961. med_list_codg, _ := json["medical_insurance_number"].(string)
  7962. advice.MedListCodg = med_list_codg
  7963. }
  7964. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7965. day := int64(json["day"].(float64))
  7966. advice.Day = day
  7967. }
  7968. return 0
  7969. }
  7970. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7971. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7972. id := int64(json["id"].(float64))
  7973. project.ID = id
  7974. historyProject, _ := service.GetHisProjectByID(id)
  7975. project.FeedetlSn = historyProject.FeedetlSn
  7976. }
  7977. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7978. project_id := int64(json["project_id"].(float64))
  7979. project.ProjectId = project_id
  7980. }
  7981. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7982. // price := int64(json["price"].(float64))
  7983. // formatInt_price := strconv.FormatInt(price, 10)
  7984. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7985. // project.Price = float_price
  7986. // }
  7987. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7988. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7989. project.Price = price
  7990. }
  7991. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7992. total, _ := json["total"].(string)
  7993. project.Count = total
  7994. }
  7995. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7996. medical_code, _ := json["medical_code"].(string)
  7997. project.MedListCodg = medical_code
  7998. }
  7999. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8000. single_dose, _ := json["single_dose"].(string)
  8001. project.SingleDose = single_dose
  8002. }
  8003. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8004. delivery_way, _ := json["delivery_way"].(string)
  8005. project.DeliveryWay = delivery_way
  8006. }
  8007. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8008. execution_frequency, _ := json["execution_frequency"].(string)
  8009. project.ExecutionFrequency = execution_frequency
  8010. }
  8011. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8012. remark, _ := json["remark"].(string)
  8013. project.Remark = remark
  8014. }
  8015. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8016. day, _ := json["number_days"].(string)
  8017. project.Day = day
  8018. }
  8019. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8020. unit, _ := json["unit"].(string)
  8021. project.Unit = unit
  8022. }
  8023. return 0
  8024. }
  8025. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8026. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8027. id := int64(json["id"].(float64))
  8028. historyAddtions, _ := service.GetHisAdditionByID(id)
  8029. additionalCharge.ID = id
  8030. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  8031. }
  8032. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8033. item_id := int64(json["item_id"].(float64))
  8034. additionalCharge.ItemId = item_id
  8035. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8036. if config.ID > 0 {
  8037. if len(config.Code) > 0 {
  8038. additionalCharge.MedListCodg = config.Code
  8039. }
  8040. }
  8041. }
  8042. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8043. // price := int64(json["price"].(float64))
  8044. // formatInt_price := strconv.FormatInt(price, 10)
  8045. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8046. // additionalCharge.Price = float_price
  8047. // }
  8048. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8049. // price := int64(json["price"].(float64))
  8050. // formatInt_price := strconv.FormatInt(price, 10)
  8051. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8052. // additionalCharge.Price = float_price
  8053. //}
  8054. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8055. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8056. additionalCharge.Price = price
  8057. }
  8058. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8059. count, _ := json["count"].(string)
  8060. counts, _ := strconv.ParseInt(count, 10, 64)
  8061. additionalCharge.Count = counts
  8062. }
  8063. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8064. item_name, _ := json["item_name"].(string)
  8065. additionalCharge.ItemName = item_name
  8066. }
  8067. return 0
  8068. }
  8069. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8070. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8071. utils.ErrorLog("drug_name")
  8072. return enums.ErrorCodeParamWrong
  8073. }
  8074. adviceName, _ := json["drug_name"].(string)
  8075. if len(adviceName) == 0 {
  8076. utils.ErrorLog("len(advice_name) == 0")
  8077. return enums.ErrorCodeParamWrong
  8078. }
  8079. advice.AdviceName = adviceName
  8080. adviceDesc, _ := json["advice_desc"].(string)
  8081. advice.AdviceDesc = adviceDesc
  8082. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8083. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8084. advice.DrugSpec = drugSpec
  8085. }
  8086. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8087. remark, _ := json["remark"].(string)
  8088. advice.Remark = remark
  8089. }
  8090. if json["id"] == nil {
  8091. advice.DrugId = 0
  8092. } else {
  8093. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8094. drug_id := int64(json["id"].(float64))
  8095. advice.DrugId = drug_id
  8096. }
  8097. }
  8098. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8099. groupno := int64(json["groupno"].(float64))
  8100. advice.Groupno = groupno
  8101. }
  8102. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8103. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8104. advice.IsSelfDrug = is_self_drug
  8105. }
  8106. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8107. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8108. drug_way_count, _ := json["drug_way_count"].(string)
  8109. advice.DrugWayCount = drug_way_count
  8110. }
  8111. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8112. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8113. advice.HospApprFlag = hosp_appr_flag
  8114. }
  8115. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8116. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8117. advice.PrescribingNumber = prescribingNumber
  8118. }
  8119. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8120. // frequency_type := int64(json["frequency_type"].(float64))
  8121. // advice.FrequencyType = frequency_type
  8122. //}
  8123. //
  8124. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8125. // day_count := int64(json["day_count"].(float64))
  8126. // advice.DayCount = day_count
  8127. //}
  8128. //
  8129. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8130. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8131. // week_day, _ := json["week_day"].(string)
  8132. // advice.WeekDay = week_day
  8133. //}
  8134. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8135. drugSpecUnit, _ := json["min_unit"].(string)
  8136. advice.DrugSpecUnit = drugSpecUnit
  8137. }
  8138. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8139. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8140. advice.SingleDose = singleDose
  8141. }
  8142. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8143. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8144. advice.SingleDoseUnit = singleDoseUnit
  8145. }
  8146. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8147. deliveryWay, _ := json["delivery_way"].(string)
  8148. advice.DeliveryWay = deliveryWay
  8149. }
  8150. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8151. executionFrequency, _ := json["execution_frequency"].(string)
  8152. advice.ExecutionFrequency = executionFrequency
  8153. }
  8154. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8155. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8156. advice.Price = price
  8157. }
  8158. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8159. med_list_codg, _ := json["medical_insurance_number"].(string)
  8160. advice.MedListCodg = med_list_codg
  8161. }
  8162. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8163. day := int64(json["day"].(float64))
  8164. advice.Day = day
  8165. }
  8166. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8167. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8168. advice.PrescribingNumberUnit = prescribingNumberUnit
  8169. }
  8170. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8171. advice_id := int64(json["advice_id"].(float64))
  8172. advice.ID = advice_id
  8173. if advice.ID > 0 {
  8174. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8175. if err == nil {
  8176. if hisAdvice.ID > 0 {
  8177. advice.ExecutionTime = hisAdvice.ExecutionTime
  8178. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8179. advice.ExecutionState = hisAdvice.ExecutionState
  8180. advice.CheckTime = hisAdvice.CheckTime
  8181. advice.Checker = hisAdvice.Checker
  8182. advice.CheckState = hisAdvice.CheckState
  8183. advice.StartTime = hisAdvice.StartTime
  8184. advice.HospApprFlag = hisAdvice.HospApprFlag
  8185. advice.IsMedicine = hisAdvice.IsMedicine
  8186. if hisAdvice.UserOrgId == 10028 {
  8187. 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 {
  8188. advice.ExecutionTime = 0
  8189. advice.ExecutionStaff = 0
  8190. advice.ExecutionState = 2
  8191. advice.CheckTime = 0
  8192. advice.Checker = 0
  8193. advice.CheckState = 2
  8194. }
  8195. } else {
  8196. 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 {
  8197. advice.ExecutionTime = 0
  8198. advice.ExecutionStaff = 0
  8199. advice.ExecutionState = 2
  8200. advice.CheckTime = 0
  8201. advice.Checker = 0
  8202. advice.CheckState = 2
  8203. advice.UpdatedTime = time.Now().Unix()
  8204. }
  8205. }
  8206. //advice.Groupno = hisAdvice.Groupno
  8207. }
  8208. }
  8209. }
  8210. }
  8211. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8212. //
  8213. //if drugStockConfig.IsOpen == 1 {
  8214. //
  8215. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8216. // if advice.ID == 0 { //医嘱不存在
  8217. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8218. // drug.Total = drug.Total - advice.PrescribingNumber
  8219. // service.UpdateBaseDrugLib(&drug)
  8220. //
  8221. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8222. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8223. // drug.Total = drug.Total - num
  8224. // service.UpdateBaseDrugLib(&drug)
  8225. // }
  8226. //
  8227. // } else if advice.ID > 0 { //医嘱存在
  8228. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8229. // var num float64
  8230. //
  8231. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8232. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8233. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8234. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8235. // drug.Total = drug.Total + num
  8236. // service.UpdateBaseDrugLib(&drug)
  8237. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8238. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8239. // drug.Total = drug.Total - num
  8240. // service.UpdateBaseDrugLib(&drug)
  8241. // }
  8242. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8243. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8244. // if num2 > advice.PrescribingNumber {
  8245. // num = num2 - advice.PrescribingNumber
  8246. // drug.Total = drug.Total + num
  8247. // service.UpdateBaseDrugLib(&drug)
  8248. // } else if num2 < advice.PrescribingNumber {
  8249. // num = advice.PrescribingNumber - num2
  8250. // drug.Total = drug.Total - num
  8251. // service.UpdateBaseDrugLib(&drug)
  8252. // }
  8253. //
  8254. // }
  8255. //
  8256. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8257. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8258. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8259. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8260. // if num1 > num2 {
  8261. // num = num1 - num2
  8262. // drug.Total = drug.Total + num
  8263. // service.UpdateBaseDrugLib(&drug)
  8264. // } else if num1 < num2 {
  8265. // num = num2 - num1
  8266. // drug.Total = drug.Total - num
  8267. // service.UpdateBaseDrugLib(&drug)
  8268. // }
  8269. //
  8270. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8271. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8272. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8273. // if hisAdvice.PrescribingNumber > num2 {
  8274. // num = hisAdvice.PrescribingNumber - num2
  8275. // drug.Total = drug.Total + num
  8276. // service.UpdateBaseDrugLib(&drug)
  8277. // } else if num2 < advice.PrescribingNumber {
  8278. // num = num2 - hisAdvice.PrescribingNumber
  8279. // drug.Total = drug.Total - num
  8280. // service.UpdateBaseDrugLib(&drug)
  8281. // }
  8282. //
  8283. // }
  8284. // }
  8285. // }
  8286. //}
  8287. //
  8288. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8289. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8290. // advice.ExecutionTime = execution_time
  8291. //}
  8292. //
  8293. //
  8294. //
  8295. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8296. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8297. // advice.ExecutionStaff = execution_staff
  8298. //}
  8299. //
  8300. //
  8301. //
  8302. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8303. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8304. // advice.ExecutionState = execution_state
  8305. //}
  8306. //
  8307. //
  8308. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8309. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8310. // advice.CheckTime = check_time
  8311. //}
  8312. //
  8313. //
  8314. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8315. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8316. // advice.CheckState = check_state
  8317. //}
  8318. //
  8319. //
  8320. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8321. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8322. // advice.Checker = checker
  8323. //}
  8324. //
  8325. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8326. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8327. // advice.StartTime = start_time
  8328. //}
  8329. return 0
  8330. }
  8331. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8332. project.ExecutionStaff = 0
  8333. project.ExecutionState = 2
  8334. project.ExecutionTime = 0
  8335. project.Checker = 0
  8336. project.CheckState = 2
  8337. project.CheckTime = 0
  8338. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8339. id := int64(json["id"].(float64))
  8340. project.ID = id
  8341. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8342. project.ExecutionStaff = temp_project.ExecutionStaff
  8343. project.ExecutionState = temp_project.ExecutionState
  8344. project.ExecutionTime = temp_project.ExecutionTime
  8345. project.Checker = temp_project.Checker
  8346. project.CheckState = temp_project.CheckState
  8347. project.CheckTime = temp_project.CheckTime
  8348. project.TeamId = temp_project.TeamId
  8349. }
  8350. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8351. types := int64(json["type"].(float64))
  8352. project.Type = types
  8353. }
  8354. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8355. project_id := int64(json["project_id"].(float64))
  8356. project.ProjectId = project_id
  8357. }
  8358. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8359. team_id := int64(json["team_id"].(float64))
  8360. project.TeamId = team_id
  8361. }
  8362. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8363. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8364. project.Price = price
  8365. }
  8366. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8367. total, _ := json["total"].(string)
  8368. //totals, _ := strconv.ParseInt(total, 10, 64)
  8369. project.Count = total
  8370. }
  8371. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8372. medical_code, _ := json["medical_code"].(string)
  8373. project.MedListCodg = medical_code
  8374. }
  8375. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8376. single_dose, _ := json["single_dose"].(string)
  8377. project.SingleDose = single_dose
  8378. }
  8379. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8380. delivery_way, _ := json["delivery_way"].(string)
  8381. project.DeliveryWay = delivery_way
  8382. }
  8383. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8384. execution_frequency, _ := json["execution_frequency"].(string)
  8385. project.ExecutionFrequency = execution_frequency
  8386. }
  8387. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8388. remark, _ := json["remark"].(string)
  8389. project.Remark = remark
  8390. }
  8391. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8392. day, _ := json["number_days"].(string)
  8393. project.Day = day
  8394. }
  8395. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8396. unit, _ := json["unit"].(string)
  8397. project.Unit = unit
  8398. }
  8399. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8400. // frequency_type := int64(json["frequency_type"].(float64))
  8401. // project.FrequencyType = frequency_type
  8402. //}
  8403. //
  8404. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8405. // day_count := int64(json["day_count"].(float64))
  8406. // project.DayCount = day_count
  8407. //}
  8408. //
  8409. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8410. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8411. // week_day, _ := json["week_day"].(string)
  8412. // project.WeekDay = week_day
  8413. //}
  8414. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8415. //
  8416. //if project.ID == 0 {
  8417. // if stockConfig.IsOpen == 1 {
  8418. // if project.Type == 3 {
  8419. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8420. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8421. // good.Total = good.Total - f_count
  8422. // service.UpdateGoodInfo(&good)
  8423. // }
  8424. // }
  8425. //
  8426. //} else {
  8427. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8428. //
  8429. // if stockConfig.IsOpen == 1 {
  8430. // if project.Type == 3 {
  8431. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8432. // if project.Count < temp_project.Count {
  8433. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8434. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8435. //
  8436. // other_count := f_count_two - f_count_one
  8437. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8438. // good.Total = good.Total + other_count_two
  8439. // service.UpdateGoodInfo(&good)
  8440. // } else if project.Count > temp_project.Count {
  8441. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8442. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8443. //
  8444. // other_count := f_count_one - f_count_two
  8445. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8446. // good.Total = good.Total - other_count_two
  8447. // service.UpdateGoodInfo(&good)
  8448. // }
  8449. //
  8450. // }
  8451. // }
  8452. //
  8453. //}
  8454. return 0
  8455. }
  8456. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8457. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8458. utils.ErrorLog("drug_name")
  8459. return enums.ErrorCodeParamWrong
  8460. }
  8461. adviceName, _ := json["drug_name"].(string)
  8462. if len(adviceName) == 0 {
  8463. utils.ErrorLog("len(advice_name) == 0")
  8464. return enums.ErrorCodeParamWrong
  8465. }
  8466. advice.AdviceName = adviceName
  8467. adviceDesc, _ := json["advice_desc"].(string)
  8468. advice.AdviceDesc = adviceDesc
  8469. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8470. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8471. advice.DrugSpec = drugSpec
  8472. }
  8473. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8474. remark, _ := json["remark"].(string)
  8475. advice.Remark = remark
  8476. }
  8477. if json["id"] == nil {
  8478. advice.DrugId = 0
  8479. } else {
  8480. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8481. drug_id := int64(json["id"].(float64))
  8482. advice.DrugId = drug_id
  8483. }
  8484. }
  8485. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8486. groupno := int64(json["groupno"].(float64))
  8487. advice.Groupno = groupno
  8488. }
  8489. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8490. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8491. advice.IsSelfDrug = is_self_drug
  8492. }
  8493. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8494. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8495. drug_way_count, _ := json["drug_way_count"].(string)
  8496. advice.DrugWayCount = drug_way_count
  8497. }
  8498. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8499. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8500. advice.HospApprFlag = hosp_appr_flag
  8501. }
  8502. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8503. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8504. advice.PrescribingNumber = prescribingNumber
  8505. }
  8506. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8507. // frequency_type := int64(json["frequency_type"].(float64))
  8508. // advice.FrequencyType = frequency_type
  8509. //}
  8510. //
  8511. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8512. // day_count := int64(json["day_count"].(float64))
  8513. // advice.DayCount = day_count
  8514. //}
  8515. //
  8516. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8517. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8518. // week_day, _ := json["week_day"].(string)
  8519. // advice.WeekDay = week_day
  8520. //}
  8521. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8522. drugSpecUnit, _ := json["min_unit"].(string)
  8523. advice.DrugSpecUnit = drugSpecUnit
  8524. }
  8525. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8526. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8527. advice.SingleDose = singleDose
  8528. }
  8529. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8530. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8531. advice.SingleDoseUnit = singleDoseUnit
  8532. }
  8533. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8534. deliveryWay, _ := json["delivery_way"].(string)
  8535. advice.DeliveryWay = deliveryWay
  8536. }
  8537. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8538. executionFrequency, _ := json["execution_frequency"].(string)
  8539. advice.ExecutionFrequency = executionFrequency
  8540. }
  8541. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8542. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8543. advice.Price = price
  8544. }
  8545. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8546. med_list_codg, _ := json["medical_insurance_number"].(string)
  8547. advice.MedListCodg = med_list_codg
  8548. }
  8549. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8550. day := int64(json["day"].(float64))
  8551. advice.Day = day
  8552. }
  8553. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8554. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8555. advice.PrescribingNumberUnit = prescribingNumberUnit
  8556. }
  8557. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8558. advice_id := int64(json["advice_id"].(float64))
  8559. advice.ID = advice_id
  8560. if advice.ID > 0 {
  8561. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8562. if err == nil {
  8563. if hisAdvice.ID > 0 {
  8564. advice.ExecutionTime = hisAdvice.ExecutionTime
  8565. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8566. advice.ExecutionState = hisAdvice.ExecutionState
  8567. advice.CheckTime = hisAdvice.CheckTime
  8568. advice.Checker = hisAdvice.Checker
  8569. advice.DrugCode = hisAdvice.DrugCode
  8570. advice.CheckState = hisAdvice.CheckState
  8571. advice.StartTime = hisAdvice.StartTime
  8572. advice.HospApprFlag = hisAdvice.HospApprFlag
  8573. advice.IsMedicine = hisAdvice.IsMedicine
  8574. if hisAdvice.UserOrgId == 10028 {
  8575. 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 {
  8576. advice.ExecutionTime = 0
  8577. advice.ExecutionStaff = 0
  8578. advice.ExecutionState = 2
  8579. advice.CheckTime = 0
  8580. advice.Checker = 0
  8581. advice.CheckState = 2
  8582. }
  8583. } else {
  8584. 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 {
  8585. advice.ExecutionTime = 0
  8586. advice.ExecutionStaff = 0
  8587. advice.ExecutionState = 2
  8588. advice.CheckTime = 0
  8589. advice.Checker = 0
  8590. advice.CheckState = 2
  8591. //advice.UpdatedTime = time.Now().Unix()
  8592. advice.CreatedTime = hisAdvice.CreatedTime
  8593. advice.UpdatedTime = time.Now().Unix()
  8594. } else {
  8595. advice.CreatedTime = hisAdvice.CreatedTime
  8596. advice.UpdatedTime = hisAdvice.UpdatedTime
  8597. }
  8598. }
  8599. //advice.Groupno = hisAdvice.Groupno
  8600. } else {
  8601. advice.IsMedicine = 0
  8602. ctime := time.Now().Unix()
  8603. advice.CreatedTime = ctime
  8604. advice.UpdatedTime = ctime
  8605. }
  8606. }
  8607. } else {
  8608. advice.IsMedicine = 0
  8609. ctime := time.Now().Unix()
  8610. advice.CreatedTime = ctime
  8611. advice.UpdatedTime = ctime
  8612. }
  8613. }
  8614. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8615. //
  8616. //if drugStockConfig.IsOpen == 1 {
  8617. //
  8618. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8619. // if advice.ID == 0 { //医嘱不存在
  8620. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8621. // drug.Total = drug.Total - advice.PrescribingNumber
  8622. // service.UpdateBaseDrugLib(&drug)
  8623. //
  8624. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8625. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8626. // drug.Total = drug.Total - num
  8627. // service.UpdateBaseDrugLib(&drug)
  8628. // }
  8629. //
  8630. // } else if advice.ID > 0 { //医嘱存在
  8631. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8632. // var num float64
  8633. //
  8634. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8635. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8636. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8637. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8638. // drug.Total = drug.Total + num
  8639. // service.UpdateBaseDrugLib(&drug)
  8640. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8641. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8642. // drug.Total = drug.Total - num
  8643. // service.UpdateBaseDrugLib(&drug)
  8644. // }
  8645. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8646. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8647. // if num2 > advice.PrescribingNumber {
  8648. // num = num2 - advice.PrescribingNumber
  8649. // drug.Total = drug.Total + num
  8650. // service.UpdateBaseDrugLib(&drug)
  8651. // } else if num2 < advice.PrescribingNumber {
  8652. // num = advice.PrescribingNumber - num2
  8653. // drug.Total = drug.Total - num
  8654. // service.UpdateBaseDrugLib(&drug)
  8655. // }
  8656. //
  8657. // }
  8658. //
  8659. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8660. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8661. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8662. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8663. // if num1 > num2 {
  8664. // num = num1 - num2
  8665. // drug.Total = drug.Total + num
  8666. // service.UpdateBaseDrugLib(&drug)
  8667. // } else if num1 < num2 {
  8668. // num = num2 - num1
  8669. // drug.Total = drug.Total - num
  8670. // service.UpdateBaseDrugLib(&drug)
  8671. // }
  8672. //
  8673. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8674. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8675. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8676. // if hisAdvice.PrescribingNumber > num2 {
  8677. // num = hisAdvice.PrescribingNumber - num2
  8678. // drug.Total = drug.Total + num
  8679. // service.UpdateBaseDrugLib(&drug)
  8680. // } else if num2 < advice.PrescribingNumber {
  8681. // num = num2 - hisAdvice.PrescribingNumber
  8682. // drug.Total = drug.Total - num
  8683. // service.UpdateBaseDrugLib(&drug)
  8684. // }
  8685. //
  8686. // }
  8687. // }
  8688. // }
  8689. //}
  8690. //
  8691. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8692. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8693. // advice.ExecutionTime = execution_time
  8694. //}
  8695. //
  8696. //
  8697. //
  8698. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8699. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8700. // advice.ExecutionStaff = execution_staff
  8701. //}
  8702. //
  8703. //
  8704. //
  8705. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8706. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8707. // advice.ExecutionState = execution_state
  8708. //}
  8709. //
  8710. //
  8711. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8712. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8713. // advice.CheckTime = check_time
  8714. //}
  8715. //
  8716. //
  8717. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8718. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8719. // advice.CheckState = check_state
  8720. //}
  8721. //
  8722. //
  8723. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8724. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8725. // advice.Checker = checker
  8726. //}
  8727. //
  8728. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8729. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8730. // advice.StartTime = start_time
  8731. //}
  8732. return 0
  8733. }
  8734. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8735. project.ExecutionStaff = 0
  8736. project.ExecutionState = 2
  8737. project.ExecutionTime = 0
  8738. project.Checker = 0
  8739. project.CheckState = 2
  8740. project.CheckTime = 0
  8741. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8742. id := int64(json["id"].(float64))
  8743. project.ID = id
  8744. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8745. project.ExecutionStaff = temp_project.ExecutionStaff
  8746. project.ExecutionState = temp_project.ExecutionState
  8747. project.ExecutionTime = temp_project.ExecutionTime
  8748. project.Checker = temp_project.Checker
  8749. project.CheckState = temp_project.CheckState
  8750. project.CheckTime = temp_project.CheckTime
  8751. project.TeamId = temp_project.TeamId
  8752. }
  8753. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8754. types := int64(json["type"].(float64))
  8755. project.Type = types
  8756. }
  8757. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8758. project_id := int64(json["project_id"].(float64))
  8759. project.ProjectId = project_id
  8760. }
  8761. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8762. team_id := int64(json["team_id"].(float64))
  8763. project.TeamId = team_id
  8764. }
  8765. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8766. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8767. project.Price = price
  8768. }
  8769. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8770. total, _ := json["total"].(string)
  8771. //totals, _ := strconv.ParseInt(total, 10, 64)
  8772. project.Count = total
  8773. }
  8774. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8775. medical_code, _ := json["medical_code"].(string)
  8776. project.MedListCodg = medical_code
  8777. }
  8778. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8779. single_dose, _ := json["single_dose"].(string)
  8780. project.SingleDose = single_dose
  8781. }
  8782. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8783. delivery_way, _ := json["delivery_way"].(string)
  8784. project.DeliveryWay = delivery_way
  8785. }
  8786. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8787. execution_frequency, _ := json["execution_frequency"].(string)
  8788. project.ExecutionFrequency = execution_frequency
  8789. }
  8790. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8791. remark, _ := json["remark"].(string)
  8792. project.Remark = remark
  8793. }
  8794. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8795. day, _ := json["number_days"].(string)
  8796. project.Day = day
  8797. }
  8798. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8799. unit, _ := json["unit"].(string)
  8800. project.Unit = unit
  8801. }
  8802. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8803. // frequency_type := int64(json["frequency_type"].(float64))
  8804. // project.FrequencyType = frequency_type
  8805. //}
  8806. //
  8807. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8808. // day_count := int64(json["day_count"].(float64))
  8809. // project.DayCount = day_count
  8810. //}
  8811. //
  8812. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8813. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8814. // week_day, _ := json["week_day"].(string)
  8815. // project.WeekDay = week_day
  8816. //}
  8817. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8818. //
  8819. //if project.ID == 0 {
  8820. // if stockConfig.IsOpen == 1 {
  8821. // if project.Type == 3 {
  8822. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8823. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8824. // good.Total = good.Total - f_count
  8825. // service.UpdateGoodInfo(&good)
  8826. // }
  8827. // }
  8828. //
  8829. //} else {
  8830. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8831. //
  8832. // if stockConfig.IsOpen == 1 {
  8833. // if project.Type == 3 {
  8834. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8835. // if project.Count < temp_project.Count {
  8836. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8837. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8838. //
  8839. // other_count := f_count_two - f_count_one
  8840. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8841. // good.Total = good.Total + other_count_two
  8842. // service.UpdateGoodInfo(&good)
  8843. // } else if project.Count > temp_project.Count {
  8844. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8845. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8846. //
  8847. // other_count := f_count_one - f_count_two
  8848. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8849. // good.Total = good.Total - other_count_two
  8850. // service.UpdateGoodInfo(&good)
  8851. // }
  8852. //
  8853. // }
  8854. // }
  8855. //
  8856. //}
  8857. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8858. id := int64(json["id"].(float64))
  8859. if id > 0 {
  8860. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8861. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8862. fmt.Println("666666")
  8863. project.Mtime = time.Now().Unix()
  8864. project.Ctime = temp_project.Ctime
  8865. } else {
  8866. project.Mtime = temp_project.Mtime
  8867. project.Ctime = temp_project.Ctime
  8868. }
  8869. } else {
  8870. ctime := time.Now().Unix()
  8871. project.Mtime = ctime
  8872. project.Ctime = ctime
  8873. }
  8874. }
  8875. return 0
  8876. }
  8877. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8878. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8879. id := int64(json["id"].(float64))
  8880. additionalCharge.ID = id
  8881. }
  8882. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8883. item_id := int64(json["item_id"].(float64))
  8884. additionalCharge.ItemId = item_id
  8885. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8886. if config.ID > 0 {
  8887. if len(config.Code) > 0 {
  8888. additionalCharge.MedListCodg = config.Code
  8889. }
  8890. }
  8891. }
  8892. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8893. // price := int64(json["price"].(float64))
  8894. // formatInt_price := strconv.FormatInt(price, 10)
  8895. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8896. // additionalCharge.Price = float_price
  8897. // }
  8898. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8899. // price := int64(json["price"].(float64))
  8900. // formatInt_price := strconv.FormatInt(price, 10)
  8901. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8902. // additionalCharge.Price = float_price
  8903. //}
  8904. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8905. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8906. additionalCharge.Price = price
  8907. }
  8908. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8909. count, _ := json["count"].(string)
  8910. counts, _ := strconv.ParseInt(count, 10, 64)
  8911. additionalCharge.Count = counts
  8912. }
  8913. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8914. item_name, _ := json["item_name"].(string)
  8915. additionalCharge.ItemName = item_name
  8916. }
  8917. return 0
  8918. }
  8919. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8920. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8921. utils.ErrorLog("drug_name")
  8922. return enums.ErrorCodeParamWrong
  8923. }
  8924. adviceName, _ := json["drug_name"].(string)
  8925. if len(adviceName) == 0 {
  8926. utils.ErrorLog("len(advice_name) == 0")
  8927. return enums.ErrorCodeParamWrong
  8928. }
  8929. advice.AdviceName = adviceName
  8930. adviceDesc, _ := json["advice_desc"].(string)
  8931. advice.AdviceDesc = adviceDesc
  8932. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8933. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8934. advice.DrugSpec = drugSpec
  8935. }
  8936. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8937. remark, _ := json["remark"].(string)
  8938. advice.Remark = remark
  8939. }
  8940. if json["id"] == nil {
  8941. advice.DrugId = 0
  8942. } else {
  8943. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8944. drug_id := int64(json["id"].(float64))
  8945. advice.DrugId = drug_id
  8946. }
  8947. }
  8948. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8949. groupno := int64(json["groupno"].(float64))
  8950. advice.Groupno = groupno
  8951. }
  8952. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8953. drugSpecUnit, _ := json["min_unit"].(string)
  8954. advice.DrugSpecUnit = drugSpecUnit
  8955. }
  8956. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8957. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8958. advice.SingleDose = singleDose
  8959. }
  8960. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8961. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8962. advice.SingleDoseUnit = singleDoseUnit
  8963. }
  8964. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8965. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8966. advice.PrescribingNumber = prescribingNumber
  8967. }
  8968. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8969. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8970. advice.PrescribingNumberUnit = prescribingNumberUnit
  8971. }
  8972. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8973. deliveryWay, _ := json["delivery_way"].(string)
  8974. advice.DeliveryWay = deliveryWay
  8975. }
  8976. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8977. executionFrequency, _ := json["execution_frequency"].(string)
  8978. advice.ExecutionFrequency = executionFrequency
  8979. }
  8980. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8981. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8982. advice.Price = price
  8983. }
  8984. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8985. med_list_codg, _ := json["medical_insurance_number"].(string)
  8986. advice.MedListCodg = med_list_codg
  8987. }
  8988. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8989. day := int64(json["day"].(float64))
  8990. advice.Day = day
  8991. }
  8992. advice.FrequencyType = 1
  8993. return 0
  8994. }
  8995. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8996. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8997. types := int64(json["type"].(float64))
  8998. project.Type = types
  8999. }
  9000. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  9001. project_id := int64(json["project_id"].(float64))
  9002. project.ProjectId = project_id
  9003. }
  9004. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  9005. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  9006. project.Price = price
  9007. }
  9008. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  9009. total, _ := json["total"].(string)
  9010. //totals, _ := strconv.ParseInt(total, 10, 64)
  9011. project.Count = total
  9012. }
  9013. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  9014. medical_code, _ := json["medical_code"].(string)
  9015. project.MedListCodg = medical_code
  9016. }
  9017. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  9018. single_dose, _ := json["single_dose"].(string)
  9019. project.SingleDose = single_dose
  9020. }
  9021. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  9022. delivery_way, _ := json["delivery_way"].(string)
  9023. project.DeliveryWay = delivery_way
  9024. }
  9025. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  9026. execution_frequency, _ := json["execution_frequency"].(string)
  9027. project.ExecutionFrequency = execution_frequency
  9028. }
  9029. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  9030. remark, _ := json["remark"].(string)
  9031. project.Remark = remark
  9032. }
  9033. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  9034. day, _ := json["number_days"].(string)
  9035. project.Day = day
  9036. }
  9037. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  9038. unit, _ := json["unit"].(string)
  9039. project.Unit = unit
  9040. }
  9041. project.FrequencyType = 1
  9042. return 0
  9043. }
  9044. func (c *HisApiController) GetHisOrderListTwo() {
  9045. start_time := c.GetString("start_time")
  9046. end_time := c.GetString("end_time")
  9047. timeLayout := "2006-01-02"
  9048. loc, _ := time.LoadLocation("Local")
  9049. var startTime int64
  9050. if len(start_time) > 0 {
  9051. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9052. if err != nil {
  9053. //fmt.Println(err)
  9054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9055. return
  9056. }
  9057. startTime = theTime.Unix()
  9058. }
  9059. var endTime int64
  9060. if len(end_time) > 0 {
  9061. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9062. if err != nil {
  9063. utils.ErrorLog(err.Error())
  9064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9065. return
  9066. }
  9067. endTime = theTime.Unix()
  9068. }
  9069. adminUser := c.GetAdminUserInfo()
  9070. org_id := adminUser.CurrentOrgId
  9071. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  9072. if err == nil {
  9073. c.ServeSuccessJSON(map[string]interface{}{
  9074. "order2": order,
  9075. })
  9076. } else {
  9077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9078. return
  9079. }
  9080. }
  9081. func (c *HisApiController) GetHisOrderList() {
  9082. page, _ := c.GetInt64("page", -1)
  9083. limit, _ := c.GetInt64("limit", -1)
  9084. start_time := c.GetString("start_time")
  9085. end_time := c.GetString("end_time")
  9086. types, _ := c.GetInt64("type", 0)
  9087. keywords := c.GetString("keywords")
  9088. p_type, _ := c.GetInt64("p_type", 0)
  9089. sort_type, _ := c.GetInt64("sort_type", 0)
  9090. charge_type, _ := c.GetInt64("charge_type", 0)
  9091. sch_type, _ := c.GetInt64("sch_type", 0)
  9092. zone_type, _ := c.GetInt64("zone_type", 0)
  9093. med_type, _ := c.GetInt64("med_type", 0)
  9094. fee_type, _ := c.GetInt64("fee_type", 0)
  9095. timeLayout := "2006-01-02"
  9096. loc, _ := time.LoadLocation("Local")
  9097. var startTime int64
  9098. if len(start_time) > 0 {
  9099. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9100. if err != nil {
  9101. //fmt.Println(err)
  9102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9103. return
  9104. }
  9105. startTime = theTime.Unix()
  9106. }
  9107. var endTime int64
  9108. if len(end_time) > 0 {
  9109. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9110. if err != nil {
  9111. utils.ErrorLog(err.Error())
  9112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9113. return
  9114. }
  9115. endTime = theTime.Unix()
  9116. }
  9117. adminUser := c.GetAdminUserInfo()
  9118. org_id := adminUser.CurrentOrgId
  9119. 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, fee_type)
  9120. for _, item := range order {
  9121. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  9122. item.DoctorName = info.Doctor
  9123. item.DepartmentName = info.XtHisDepartment.Name
  9124. }
  9125. if err == nil {
  9126. c.ServeSuccessJSON(map[string]interface{}{
  9127. "order": order,
  9128. "total": total,
  9129. })
  9130. } else {
  9131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9132. return
  9133. }
  9134. }
  9135. func (c *HisApiController) GetHisOrder() {
  9136. patient_id, _ := c.GetInt64("patient_id", 0)
  9137. number := c.GetString("number")
  9138. adminInfo := c.GetAdminUserInfo()
  9139. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  9140. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  9141. if err == nil {
  9142. c.ServeSuccessJSON(map[string]interface{}{
  9143. "order": order,
  9144. "prescription": prescriptions,
  9145. })
  9146. } else {
  9147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9148. return
  9149. }
  9150. }
  9151. func (c *HisApiController) GetHisPrescriptionList() {
  9152. record_date := c.GetString("record_date")
  9153. keywords := c.GetString("keywords")
  9154. page, _ := c.GetInt64("page")
  9155. limit, _ := c.GetInt64("limit")
  9156. sch_type, _ := c.GetInt64("sch_type")
  9157. timeLayout := "2006-01-02"
  9158. loc, _ := time.LoadLocation("Local")
  9159. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9160. if err != nil {
  9161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9162. return
  9163. }
  9164. recordDateTime := theTime.Unix()
  9165. adminInfo := c.GetAdminUserInfo()
  9166. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  9167. //adminInfo := c.GetAdminUserInfo()
  9168. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  9169. //fmt.Println(prescriptionOrder)
  9170. if err == nil {
  9171. c.ServeSuccessJSON(map[string]interface{}{
  9172. "order": prescriptionOrder,
  9173. "total": total,
  9174. })
  9175. } else {
  9176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9177. return
  9178. }
  9179. }
  9180. func (c *HisApiController) GetHisPrescriptionInfo() {
  9181. id, _ := c.GetInt64("id")
  9182. adminInfo := c.GetAdminUserInfo()
  9183. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  9184. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  9185. if err == nil {
  9186. c.ServeSuccessJSON(map[string]interface{}{
  9187. "order": prescriptionOrder,
  9188. "prescription": prescription,
  9189. })
  9190. } else {
  9191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9192. return
  9193. }
  9194. }
  9195. func (c *HisApiController) GetMedicalInsuranceConfig() {
  9196. adminUser := c.GetAdminUserInfo()
  9197. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  9198. c.ServeSuccessJSON(map[string]interface{}{
  9199. "config": config,
  9200. })
  9201. }
  9202. type ResultTwo struct {
  9203. ErrMsg interface{} `json:"err_msg"`
  9204. InfRefmsgid string `json:"inf_refmsgid"`
  9205. Infcode int64 `json:"infcode"`
  9206. Output struct {
  9207. Baseinfo struct {
  9208. Age float64 `json:"age"`
  9209. Brdy string `json:"brdy"`
  9210. Certno string `json:"certno"`
  9211. Gend string `json:"gend"`
  9212. Naty string `json:"naty"`
  9213. PsnCertType string `json:"psn_cert_type"`
  9214. PsnName string `json:"psn_name"`
  9215. PsnNo string `json:"psn_no"`
  9216. } `json:"baseinfo"`
  9217. Idetinfo []interface{} `json:"idetinfo"`
  9218. Iinfo []struct {
  9219. Balc float64 `json:"balc"`
  9220. CvlservFlag string `json:"cvlserv_flag"`
  9221. EmpName string `json:"emp_name"`
  9222. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  9223. Insutype string `json:"insutype"`
  9224. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  9225. PausInsuDate interface{} `json:"paus_insu_date"`
  9226. PsnInsuDate string `json:"psn_insu_date"`
  9227. PsnInsuStas string `json:"psn_insu_stas"`
  9228. PsnType string `json:"psn_type"`
  9229. } `json:"insuinfo"`
  9230. } `json:"output"`
  9231. RefmsgTime string `json:"refmsg_time"`
  9232. RespondTime string `json:"respond_time"`
  9233. Signtype interface{} `json:"signtype"`
  9234. WarnInfo interface{} `json:"warn_info"`
  9235. }
  9236. type ResultThree struct {
  9237. Cainfo interface{} `json:"cainfo"`
  9238. ErrMsg interface{} `json:"err_msg"`
  9239. InfRefmsgid string `json:"inf_refmsgid"`
  9240. Infcode int64 `json:"infcode"`
  9241. Output struct {
  9242. Data struct {
  9243. IptOtpNo string `json:"ipt_otp_no"`
  9244. MdtrtID string `json:"mdtrt_id"`
  9245. PsnNo string `json:"psn_no"`
  9246. } `json:"data"`
  9247. } `json:"output"`
  9248. RefmsgTime string `json:"refmsg_time"`
  9249. RespondTime string `json:"respond_time"`
  9250. Signtype interface{} `json:"signtype"`
  9251. WarnMsg interface{} `json:"warn_msg"`
  9252. }
  9253. type ResultFour struct {
  9254. Cainfo string `json:"cainfo"`
  9255. ErrMsg string `json:"err_msg"`
  9256. InfRefmsgid string `json:"inf_refmsgid"`
  9257. Infcode int64 `json:"infcode"`
  9258. Output struct {
  9259. Result []struct {
  9260. BasMednFlag string `json:"bas_medn_flag"`
  9261. ChldMedcFlag string `json:"chld_medc_flag"`
  9262. ChrgitmLv string `json:"chrgitm_lv"`
  9263. Cnt float64 `json:"cnt"`
  9264. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9265. DrtReimFlag string `json:"drt_reim_flag"`
  9266. FeedetlSn string `json:"feedetl_sn"`
  9267. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9268. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9269. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9270. ListSpItemFlag string `json:"list_sp_item_flag"`
  9271. LmtUsedFlag string `json:"lmt_used_flag"`
  9272. MedChrgitmType string `json:"med_chrgitm_type"`
  9273. Memo string `json:"memo"`
  9274. OverlmtAmt float64 `json:"overlmt_amt"`
  9275. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9276. Pric float64 `json:"pric"`
  9277. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9278. SelfpayProp float64 `json:"selfpay_prop"`
  9279. } `json:"result"`
  9280. } `json:"output"`
  9281. RefmsgTime string `json:"refmsg_time"`
  9282. RespondTime string `json:"respond_time"`
  9283. Signtype string `json:"signtype"`
  9284. WarnMsg string `json:"warn_msg"`
  9285. }
  9286. type ResultFive struct {
  9287. Insutype string `json:"insutype"`
  9288. }
  9289. type ResultSix struct {
  9290. Cainfo interface{} `json:"cainfo"`
  9291. ErrMsg interface{} `json:"err_msg"`
  9292. InfRefmsgid string `json:"inf_refmsgid"`
  9293. Infcode int64 `json:"infcode"`
  9294. Output struct {
  9295. } `json:"output"`
  9296. RefmsgTime string `json:"refmsg_time"`
  9297. RespondTime string `json:"respond_time"`
  9298. Signtype interface{} `json:"signtype"`
  9299. WarnMsg interface{} `json:"warn_msg"`
  9300. }
  9301. type ResultSeven struct {
  9302. Cainfo string `json:"cainfo"`
  9303. ErrMsg string `json:"err_msg"`
  9304. InfRefmsgid string `json:"inf_refmsgid"`
  9305. Infcode int64 `json:"infcode"`
  9306. Output struct {
  9307. Setldetail []interface{} `json:"setldetail"`
  9308. Setlinfo struct {
  9309. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9310. AcctPay float64 `json:"acct_pay"`
  9311. ActPayDedc float64 `json:"act_pay_dedc"`
  9312. Age float64 `json:"age"`
  9313. Balc float64 `json:"balc"`
  9314. Brdy string `json:"brdy"`
  9315. Certno string `json:"certno"`
  9316. ClrOptins string `json:"clr_optins"`
  9317. ClrType string `json:"clr_type"`
  9318. ClrWay string `json:"clr_way"`
  9319. CvlservFlag string `json:"cvlserv_flag"`
  9320. CvlservPay float64 `json:"cvlserv_pay"`
  9321. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9322. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9323. Gend string `json:"gend"`
  9324. HifesPay float64 `json:"hifes_pay"`
  9325. HifmiPay float64 `json:"hifmi_pay"`
  9326. HifobPay float64 `json:"hifob_pay"`
  9327. HifpPay float64 `json:"hifp_pay"`
  9328. HospPartAmt float64 `json:"hosp_part_amt"`
  9329. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9330. Insutype string `json:"insutype"`
  9331. MafPay float64 `json:"maf_pay"`
  9332. MdtrtCertType string `json:"mdtrt_cert_type"`
  9333. MdtrtID string `json:"mdtrt_id"`
  9334. MedType string `json:"med_type"`
  9335. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9336. MedinsSetlID string `json:"medins_setl_id"`
  9337. Naty string `json:"naty"`
  9338. OthPay float64 `json:"oth_pay"`
  9339. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9340. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9341. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9342. PsnCashPay float64 `json:"psn_cash_pay"`
  9343. PsnCertType string `json:"psn_cert_type"`
  9344. PsnName string `json:"psn_name"`
  9345. PsnNo string `json:"psn_no"`
  9346. PsnPartAmt float64 `json:"psn_part_amt"`
  9347. PsnType string `json:"psn_type"`
  9348. SetlID string `json:"setl_id"`
  9349. SetlTime string `json:"setl_time"`
  9350. } `json:"setlinfo"`
  9351. } `json:"output"`
  9352. RefmsgTime string `json:"refmsg_time"`
  9353. RespondTime string `json:"respond_time"`
  9354. Signtype interface{} `json:"signtype"`
  9355. WarnMsg interface{} `json:"warn_msg"`
  9356. }
  9357. type ResultEight struct {
  9358. Cainfo string `json:"cainfo"`
  9359. ErrMsg string `json:"err_msg"`
  9360. InfRefmsgid string `json:"inf_refmsgid"`
  9361. Infcode int64 `json:"infcode"`
  9362. Output struct {
  9363. Stmtinfo struct {
  9364. SetlOptins string `json:"setl_optins"`
  9365. StmtRslt string `json:"stmt_rslt"`
  9366. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9367. } `json:"stmtinfo"`
  9368. } `json:"output"`
  9369. RefmsgTime string `json:"refmsg_time"`
  9370. RespondTime string `json:"respond_time"`
  9371. Signtype interface{} `json:"signtype"`
  9372. WarnMsg interface{} `json:"warn_msg"`
  9373. }
  9374. type ResultNine struct {
  9375. Cainfo string `json:"cainfo"`
  9376. ErrMsg string `json:"err_msg"`
  9377. InfRefmsgid string `json:"inf_refmsgid"`
  9378. Infcode int64 `json:"infcode"`
  9379. Output struct {
  9380. FileQuryNo string `json:"file_qury_no"`
  9381. } `json:"output"`
  9382. RefmsgTime string `json:"refmsg_time"`
  9383. RespondTime string `json:"respond_time"`
  9384. Signtype interface{} `json:"signtype"`
  9385. WarnMsg interface{} `json:"warn_msg"`
  9386. }
  9387. type ResultTen struct {
  9388. Cainfo string `json:"cainfo"`
  9389. ErrMsg string `json:"err_msg"`
  9390. InfRefmsgid string `json:"inf_refmsgid"`
  9391. Infcode int64 `json:"infcode"`
  9392. Output struct {
  9393. DldEndtime string `json:"dld_endtime"`
  9394. FileQuryNo string `json:"file_qury_no"`
  9395. Filename string `json:"filename"`
  9396. } `json:"output"`
  9397. RefmsgTime string `json:"refmsg_time"`
  9398. RespondTime string `json:"respond_time"`
  9399. Signtype interface{} `json:"signtype"`
  9400. WarnMsg interface{} `json:"warn_msg"`
  9401. }
  9402. type ResultEleven struct {
  9403. Cainfo string `json:"cainfo"`
  9404. ErrMsg string `json:"err_msg"`
  9405. InfRefmsgid string `json:"inf_refmsgid"`
  9406. Infcode int64 `json:"infcode"`
  9407. Output struct {
  9408. Setlinfo struct {
  9409. FixmedinsName string `json:"fixmedins_name"`
  9410. FixmedinsCode string `json:"fixmedins_code"`
  9411. PsnNo string `json:"psn_no"`
  9412. PsnName string `json:"psn_name"`
  9413. HifobPay float64 `json:"hifob_pay"`
  9414. Gend string `json:"gend"`
  9415. Brdy string `json:"brdy"`
  9416. PsnCertType string `json:"psn_cert_type"`
  9417. PsnType string `json:"psn_type"`
  9418. EmpName string `json:"emp_name"`
  9419. Certno string `json:"certno"`
  9420. Insutype string `json:"insutype"`
  9421. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9422. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9423. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9424. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9425. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9426. ActPayDedc float64 `json:"act_pay_dedc"`
  9427. HifpPay float64 `json:"hifp_pay"`
  9428. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9429. CvlservPay float64 `json:"cvlserv_pay"`
  9430. HifesPay float64 `json:"hifes_pay"`
  9431. HifmiPay float64 `json:"hifmi_pay"`
  9432. MafPay float64 `json:"maf_pay"`
  9433. OthPay float64 `json:"oth_pay"`
  9434. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9435. PsnPay float64 `json:"psn_pay"`
  9436. AcctPay float64 `json:"acct_pay"`
  9437. CashPayamt float64 `json:"cash_payamt"`
  9438. Balc float64 `json:"balc"`
  9439. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9440. MedinsSetlId string `json:"medins_setl_id"`
  9441. RefdSetlFlag string `json:"refd_setl_flag"`
  9442. SetlTime string `json:"setl_time"`
  9443. MedType string `json:"med_type"`
  9444. } `json:"setlinfo"`
  9445. } `json:"output"`
  9446. RefmsgTime string `json:"refmsg_time"`
  9447. RespondTime string `json:"respond_time"`
  9448. Signtype interface{} `json:"signtype"`
  9449. WarnMsg interface{} `json:"warn_msg"`
  9450. }
  9451. type Custom struct {
  9452. DetItemFeeSumamt string
  9453. Cut string
  9454. FeedetlSn string
  9455. Price string
  9456. MedListCodg string
  9457. Type int64
  9458. AdviceId int64
  9459. ProjectId int64
  9460. ItemId int64
  9461. CostType int64
  9462. }
  9463. // 获取个人信息----挂号-----上传就诊信息
  9464. func (c *HisApiController) GetRegisterInfo() {
  9465. id, _ := c.GetInt64("id")
  9466. record_time := c.GetString("record_time")
  9467. settlementValue, _ := c.GetInt64("settlement_value")
  9468. medical_insurance_card := c.GetString("medical_insurance_card")
  9469. name := c.GetString("name")
  9470. id_card_type, _ := c.GetInt64("id_card_type")
  9471. certificates, _ := c.GetInt64("certificates")
  9472. medical_care, _ := c.GetInt64("medical_care")
  9473. birthday := c.GetString("birthday")
  9474. age, _ := c.GetInt64("age")
  9475. id_card := c.GetString("id_card")
  9476. register_type, _ := c.GetInt64("register")
  9477. doctor, _ := c.GetInt64("doctor")
  9478. department, _ := c.GetInt64("department")
  9479. gender, _ := c.GetInt64("sex")
  9480. phone := c.GetString("phone")
  9481. registration_fee, _ := c.GetFloat("registration_fee")
  9482. medical_expenses, _ := c.GetFloat("medical_expenses")
  9483. social_type, _ := c.GetInt64("social_type")
  9484. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9485. diagnosis_ids := c.GetString("diagnosis")
  9486. sick_type, _ := c.GetInt64("sick_type")
  9487. reg_type := c.GetString("p_type")
  9488. timeLayout := "2006-01-02"
  9489. loc, _ := time.LoadLocation("Local")
  9490. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9491. birthUnix := birthdays.Unix()
  9492. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9493. if err != nil {
  9494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9495. return
  9496. }
  9497. recordDateTime := theTime.Unix()
  9498. adminInfo := c.GetAdminUserInfo()
  9499. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9500. if tempPatient.ID == 0 {
  9501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9502. return
  9503. }
  9504. var patient service.Patients
  9505. if id == 0 {
  9506. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9507. } else {
  9508. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9509. }
  9510. if patient.ID == 0 {
  9511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9512. return
  9513. }
  9514. if len(patient.IdCardNo) == 0 {
  9515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9516. return
  9517. }
  9518. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9519. if len(his) >= 1 {
  9520. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9521. if len(his) >= 1 && order.ID == 0 {
  9522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9523. return
  9524. }
  9525. }
  9526. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9527. fmt.Println(timeStr)
  9528. timeArr := strings.Split(timeStr, " ")
  9529. fmt.Println(timeArr)
  9530. timeArrTwo := strings.Split(timeArr[0], "-")
  9531. timeArrThree := strings.Split(timeArr[1], ":")
  9532. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9533. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9534. if len(lists) == 0 {
  9535. var hisPatient models.XtHisPatient
  9536. hisPatient = models.XtHisPatient{
  9537. Name: name,
  9538. Age: age,
  9539. Gender: gender,
  9540. Birthday: birthUnix,
  9541. Phone: phone,
  9542. MedicalTreatmentType: medical_care,
  9543. IdType: certificates,
  9544. IdCardNo: id_card,
  9545. BalanceAccountsType: settlementValue,
  9546. SocialType: social_type,
  9547. MedicalInsuranceNumber: medical_insurance_card,
  9548. RegisterType: register_type,
  9549. RegisterCost: registration_fee,
  9550. TreatmentCost: medical_expenses,
  9551. AdminUserId: adminInfo.AdminUser.Id,
  9552. UserOrgId: adminInfo.CurrentOrgId,
  9553. Status: 1,
  9554. RecordDate: recordDateTime,
  9555. IsReturn: 1,
  9556. PatientId: patient.ID,
  9557. Ctime: time.Now().Unix(),
  9558. Mtime: time.Now().Unix(),
  9559. Number: str,
  9560. IdCardType: id_card_type,
  9561. Departments: department,
  9562. Doctor: doctor,
  9563. PType: reg_type,
  9564. Diagnosis: diagnosis_ids,
  9565. SickType: sick_type,
  9566. }
  9567. service.CreateHisPatient(&hisPatient)
  9568. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9569. c.ServeSuccessJSON(map[string]interface{}{
  9570. "his_info": hisPatient,
  9571. })
  9572. } else {
  9573. //chrgBchno := rand.Intn(1000000) + 10000
  9574. var hisPatient models.XtHisPatient
  9575. hisPatient = models.XtHisPatient{
  9576. Name: name,
  9577. Age: age,
  9578. Gender: gender,
  9579. Birthday: birthUnix,
  9580. Phone: phone,
  9581. MedicalTreatmentType: medical_care,
  9582. IdType: certificates,
  9583. IdCardNo: id_card,
  9584. BalanceAccountsType: settlementValue,
  9585. SocialType: social_type,
  9586. MedicalInsuranceNumber: medical_insurance_card,
  9587. RegisterType: register_type,
  9588. RegisterCost: registration_fee,
  9589. TreatmentCost: medical_expenses,
  9590. AdminUserId: adminInfo.AdminUser.Id,
  9591. UserOrgId: adminInfo.CurrentOrgId,
  9592. Status: 1,
  9593. RecordDate: recordDateTime,
  9594. IsReturn: 1,
  9595. PatientId: patient.ID,
  9596. Ctime: time.Now().Unix(),
  9597. Mtime: time.Now().Unix(),
  9598. Number: str,
  9599. IdCardType: id_card_type,
  9600. Departments: department,
  9601. Doctor: doctor,
  9602. PType: reg_type,
  9603. Diagnosis: diagnosis_ids,
  9604. SickType: sick_type,
  9605. }
  9606. service.CreateHisPatient(&hisPatient)
  9607. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9608. c.ServeSuccessJSON(map[string]interface{}{
  9609. "his_info": hisPatient,
  9610. })
  9611. }
  9612. }
  9613. // 上传明细----结算
  9614. func (c *HisApiController) GetUploadInfo() {
  9615. id, _ := c.GetInt64("id")
  9616. record_time := c.GetString("record_time")
  9617. his_patient_id, _ := c.GetInt64("his_patient_id")
  9618. oth_desc := c.GetString("oth_desc")
  9619. pay_way, _ := c.GetInt64("pay_way")
  9620. pay_ways := c.GetString("pay_ways")
  9621. pay_price, _ := c.GetFloat("pay_price")
  9622. pay_card_no := c.GetString("pay_card_no")
  9623. discount_price, _ := c.GetFloat("discount_price")
  9624. preferential_price, _ := c.GetFloat("preferential_price")
  9625. reality_price, _ := c.GetFloat("reality_price")
  9626. found_price, _ := c.GetFloat("found_price")
  9627. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9628. private_price, _ := c.GetFloat("private_price")
  9629. timeLayout := "2006-01-02"
  9630. loc, _ := time.LoadLocation("Local")
  9631. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9632. fapiao_code := c.GetString("fapiao_code")
  9633. fapiao_number := c.GetString("fapiao_number")
  9634. diagnosis_id := c.GetString("diagnosis")
  9635. sick_type, _ := c.GetInt64("sick_type")
  9636. reg_type, _ := c.GetInt64("p_type")
  9637. order_id, _ := c.GetInt64("order_id")
  9638. cash_pay := c.GetString("cash_pay")
  9639. wechat_pay := c.GetString("wechat_pay")
  9640. ali_pay := c.GetString("ali_pay")
  9641. jifen_pay := c.GetString("jifen_pay")
  9642. card_desc := c.GetString("card_desc")
  9643. band_card_pay := c.GetString("band_card_pay")
  9644. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9645. tmp_decimal := c.GetString("tmp_decimal")
  9646. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9647. var decimal float64 //本次使用的押金
  9648. var errmsg error
  9649. tx := service.XTWriteDB().Begin() //开了事务
  9650. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9651. defer func() {
  9652. if errmsg != nil {
  9653. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9654. tx.Rollback()
  9655. } else {
  9656. tx.Commit()
  9657. }
  9658. }()
  9659. fmt.Println("dec_way", dec_way)
  9660. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9661. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9662. return
  9663. }
  9664. if len(tmp_decimal) > 0 {
  9665. if tmp_decimal[0] == 45 {
  9666. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9667. return
  9668. }
  9669. }
  9670. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9671. fmt.Println(errs)
  9672. decimal = tt
  9673. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9674. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9675. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9676. if err != nil {
  9677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9678. return
  9679. }
  9680. recordDateTime := theTime.Unix()
  9681. adminUser := c.GetAdminUserInfo()
  9682. var prescriptions []*models.HisPrescription
  9683. var prescriptionsOne []*models.HisPrescription
  9684. var start_time int64
  9685. var end_time int64
  9686. ids_str := c.GetString("ids")
  9687. ids_arr := strings.Split(ids_str, ",")
  9688. if tempOrder.ID == 0 {
  9689. if settle_accounts_type == 1 { //日结
  9690. fmt.Println(reg_type)
  9691. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9692. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9693. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9694. } else {
  9695. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9696. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9697. }
  9698. } else { //月结
  9699. start_time_str := c.GetString("start_time")
  9700. end_time_str := c.GetString("end_time")
  9701. timeLayout := "2006-01-02"
  9702. loc, _ := time.LoadLocation("Local")
  9703. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9704. if err != nil {
  9705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9706. return
  9707. }
  9708. recordStartTime := theStartTime.Unix()
  9709. start_time = recordStartTime
  9710. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9711. if err != nil {
  9712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9713. return
  9714. }
  9715. recordEndTime := theEndTime.Unix()
  9716. end_time = recordEndTime
  9717. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9718. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9719. }
  9720. var goods []*models.DialysisBeforePrepareGoods
  9721. var newGoods []*models.NewDialysisBeforePrepareGoods
  9722. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9723. var infos []*models.HisDoctorAdviceInfo
  9724. var infoList []*models.HisDoctorAdviceInfo
  9725. var hisAdvice []*models.HisDoctorAdviceInfo
  9726. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9727. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9728. //判断库存不足
  9729. //结算出库开关
  9730. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9731. if settConfig.IsOpen == 1 {
  9732. //判断库存的地方
  9733. for _, info := range prescriptions {
  9734. if info.Type == 1 {
  9735. infos = append(infos, info.HisDoctorAdviceInfo...)
  9736. }
  9737. if info.Type == 2 {
  9738. for _, sumItem := range info.HisPrescriptionProject {
  9739. if sumItem.Type == 3 {
  9740. var good models.DialysisBeforePrepareGoods
  9741. var newGood models.NewDialysisBeforePrepareGoods
  9742. good.GoodId = sumItem.GoodInfo.ID
  9743. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9744. count, _ := strconv.Atoi(sumItem.Count)
  9745. good.Count = int64(count)
  9746. good.StorehouseId = houseConfig.StorehouseOutInfo
  9747. good.ProjectId = sumItem.ID
  9748. goods = append(goods, &good)
  9749. newGood.GoodId = sumItem.GoodInfo.ID
  9750. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9751. count2, _ := strconv.Atoi(sumItem.Count)
  9752. newGood.Count = int64(count2)
  9753. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9754. newGood.ProjectId = sumItem.ID
  9755. newGoods = append(newGoods, &newGood)
  9756. }
  9757. }
  9758. }
  9759. }
  9760. for _, info := range prescriptionsOne {
  9761. if info.Type == 1 {
  9762. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9763. }
  9764. if info.Type == 2 {
  9765. for _, sumItem := range info.HisPrescriptionProject {
  9766. if sumItem.Type == 3 {
  9767. var newGood models.NewDialysisBeforePrepareGoods
  9768. newGood.GoodId = sumItem.GoodInfo.ID
  9769. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9770. count2, _ := strconv.Atoi(sumItem.Count)
  9771. newGood.Count = int64(count2)
  9772. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9773. newGood.ProjectId = sumItem.ID
  9774. newGoodOne = append(newGoodOne, &newGood)
  9775. }
  9776. }
  9777. }
  9778. }
  9779. //判断
  9780. for _, itemOne := range infos {
  9781. for _, itemTwo := range hisAdvice {
  9782. if itemOne.DrugId == itemTwo.DrugId {
  9783. itemTwo.Child = append(itemTwo.Child, itemOne)
  9784. }
  9785. }
  9786. }
  9787. for _, itemTwo := range hisAdvice {
  9788. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9789. var sum_out_count int64
  9790. for _, itemThree := range itemTwo.Child {
  9791. var prescribing_number int64
  9792. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9793. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9794. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9795. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9796. }
  9797. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9798. prescribing_number = parseIntPrescribingNumber
  9799. }
  9800. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9801. prescribing_number = parseIntPrescribingNumber
  9802. }
  9803. sum_out_count += prescribing_number
  9804. }
  9805. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9806. if sum_out_count > drugStockOut.FlushCount {
  9807. c.ServeSuccessJSON(map[string]interface{}{
  9808. "msg": "2",
  9809. "drug": medical,
  9810. })
  9811. return
  9812. }
  9813. }
  9814. for _, itemOne := range newGoods {
  9815. for _, item := range newGoodOne {
  9816. if itemOne.GoodId == item.GoodId {
  9817. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9818. }
  9819. }
  9820. }
  9821. for _, item := range newGoodOne {
  9822. var sum_out_count_one int64
  9823. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9824. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9825. sum_out_count_one += itemOne.Count
  9826. }
  9827. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9828. fmt.Println("sum_out_count_one", sum_out_count_one)
  9829. fmt.Println("list.FlushCount", list.FlushCount)
  9830. if sum_out_count_one > list.FlushCount {
  9831. c.ServeSuccessJSON(map[string]interface{}{
  9832. "msg": "3",
  9833. "good": good,
  9834. })
  9835. return
  9836. }
  9837. }
  9838. }
  9839. timestamp := time.Now().Unix()
  9840. tempTime := time.Unix(timestamp, 0)
  9841. timeFormat := tempTime.Format("20060102150405")
  9842. chrgBchno := rand.Intn(100000) + 10000
  9843. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9844. strconv.FormatInt(his.PatientId, 10)
  9845. var ids []int64
  9846. for _, item := range prescriptions {
  9847. ids = append(ids, item.ID)
  9848. }
  9849. var total float64
  9850. for _, item := range prescriptions {
  9851. fmt.Println(item)
  9852. if item.Type == 1 { //药品
  9853. for _, subItem := range item.HisDoctorAdviceInfo {
  9854. if subItem.Drug.IsUser != 1 {
  9855. total = total + (subItem.Price * subItem.PrescribingNumber)
  9856. }
  9857. }
  9858. }
  9859. if item.Type == 2 { //项目
  9860. for _, subItem := range item.HisPrescriptionProject {
  9861. if subItem.Type == 2 {
  9862. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9863. total = total + (subItem.Price * cnt)
  9864. } else {
  9865. if subItem.GoodInfo.IsUser != 1 {
  9866. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9867. total = total + (subItem.Price * cnt)
  9868. }
  9869. }
  9870. }
  9871. }
  9872. for _, subItem := range item.HisAdditionalCharge {
  9873. total = total + (subItem.Price * float64(subItem.Count))
  9874. }
  9875. }
  9876. if reg_type == 1111 || reg_type == 1112 {
  9877. reg_type = 11
  9878. }
  9879. tm := time.Unix(time.Now().Unix(), 0)
  9880. allTotal := fmt.Sprintf("%.4f", total)
  9881. totals, _ := strconv.ParseFloat(allTotal, 64)
  9882. order := &models.HisOrder{
  9883. UserOrgId: adminUser.CurrentOrgId,
  9884. HisPatientId: his.ID,
  9885. PatientId: id,
  9886. SettleAccountsDate: recordDateTime,
  9887. Ctime: time.Now().Unix(),
  9888. Mtime: time.Now().Unix(),
  9889. Status: 1,
  9890. OrderStatus: 2,
  9891. MdtrtId: his.Number,
  9892. Number: chrg_bchno,
  9893. MedfeeSumamt: totals,
  9894. PayWay: pay_way,
  9895. PayWays: pay_ways,
  9896. PayPrice: pay_price,
  9897. MedType: strconv.Itoa(int(reg_type)),
  9898. PayCardNo: pay_card_no,
  9899. DiscountPrice: discount_price,
  9900. PreferentialPrice: preferential_price,
  9901. RealityPrice: reality_price,
  9902. FoundPrice: found_price,
  9903. MedicalInsurancePrice: medical_insurance_price,
  9904. PrivatePrice: private_price,
  9905. SettleEndTime: end_time,
  9906. SettleStartTime: start_time,
  9907. PsnPartAmt: totals,
  9908. PsnCashPay: totals,
  9909. SettleType: settle_accounts_type,
  9910. FaPiaoCode: fapiao_code,
  9911. FaPiaoNumber: fapiao_number,
  9912. Diagnosis: diagnosis_id,
  9913. PType: 2,
  9914. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9915. Decimal: decimal,
  9916. OthDesc: oth_desc,
  9917. CashPay: cash_pay,
  9918. WechatPay: wechat_pay,
  9919. AliPay: ali_pay,
  9920. JifenPay: jifen_pay,
  9921. BandCardPay: band_card_pay,
  9922. Creator: adminUser.AdminUser.Id,
  9923. CardDesc: card_desc,
  9924. }
  9925. err = service.CreateOrderTX(order, tx)
  9926. if err != nil {
  9927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9928. return
  9929. }
  9930. var customs []*Custom
  9931. for _, item := range prescriptions {
  9932. if item.Type == 1 { //药品a
  9933. for _, subItem := range item.HisDoctorAdviceInfo {
  9934. if subItem.Drug.IsUser != 1 {
  9935. cus := &Custom{
  9936. AdviceId: subItem.ID,
  9937. ProjectId: 0,
  9938. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9939. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9940. FeedetlSn: subItem.FeedetlSn,
  9941. Price: fmt.Sprintf("%.4f", subItem.Price),
  9942. MedListCodg: subItem.MedListCodg,
  9943. Type: 1,
  9944. CostType: 9,
  9945. }
  9946. customs = append(customs, cus)
  9947. }
  9948. }
  9949. }
  9950. if item.Type == 2 { //项目
  9951. for _, subItem := range item.HisPrescriptionProject {
  9952. if subItem.Type == 2 {
  9953. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9954. cus := &Custom{
  9955. AdviceId: 0,
  9956. ProjectId: subItem.ID,
  9957. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9958. Cut: fmt.Sprintf("%.4f", cnt),
  9959. FeedetlSn: subItem.FeedetlSn,
  9960. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9961. MedListCodg: subItem.MedListCodg,
  9962. Type: 2,
  9963. CostType: subItem.HisProject.CostClassify,
  9964. }
  9965. customs = append(customs, cus)
  9966. } else {
  9967. if subItem.GoodInfo.IsUser != 1 {
  9968. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9969. cus := &Custom{
  9970. AdviceId: 0,
  9971. ProjectId: subItem.ID,
  9972. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9973. Cut: fmt.Sprintf("%.4f", cnt),
  9974. FeedetlSn: subItem.FeedetlSn,
  9975. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9976. MedListCodg: subItem.MedListCodg,
  9977. Type: 2,
  9978. CostType: subItem.HisProject.CostClassify,
  9979. }
  9980. customs = append(customs, cus)
  9981. }
  9982. }
  9983. }
  9984. }
  9985. for _, item := range item.HisAdditionalCharge {
  9986. cus := &Custom{
  9987. ItemId: item.ID,
  9988. AdviceId: 0,
  9989. ProjectId: 0,
  9990. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9991. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9992. FeedetlSn: item.FeedetlSn,
  9993. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9994. MedListCodg: item.XtHisAddtionConfig.Code,
  9995. Type: 3,
  9996. CostType: 5,
  9997. }
  9998. customs = append(customs, cus)
  9999. }
  10000. }
  10001. for _, item := range customs {
  10002. var advice_id int64 = 0
  10003. var project_id int64 = 0
  10004. var item_id int64 = 0
  10005. var types int64 = 0
  10006. var med_chrgitm_type string
  10007. if item.Type == 1 {
  10008. advice_id = item.AdviceId
  10009. project_id = 0
  10010. item_id = 0
  10011. med_chrgitm_type = "09"
  10012. } else if item.Type == 2 {
  10013. med_chrgitm_type = "05"
  10014. if item.CostType == 3 {
  10015. med_chrgitm_type = "04"
  10016. }
  10017. if item.CostType == 8 {
  10018. med_chrgitm_type = "03"
  10019. }
  10020. advice_id = 0
  10021. item_id = 0
  10022. project_id = item.ProjectId
  10023. } else if item.Type == 3 {
  10024. advice_id = 0
  10025. item_id = item.ItemId
  10026. project_id = 0
  10027. med_chrgitm_type = "08"
  10028. }
  10029. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10030. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10031. pric, _ := strconv.ParseFloat(item.Price, 32)
  10032. info := &models.HisOrderInfo{
  10033. OrderNumber: order.Number,
  10034. UploadDate: time.Now().Unix(),
  10035. AdviceId: advice_id,
  10036. DetItemFeeSumamt: detItemFeeSumamt,
  10037. MedChrgitmType: med_chrgitm_type,
  10038. Cnt: cut,
  10039. Pric: pric,
  10040. PatientId: id,
  10041. Status: 1,
  10042. Mtime: time.Now().Unix(),
  10043. Ctime: time.Now().Unix(),
  10044. UserOrgId: adminUser.CurrentOrgId,
  10045. HisPatientId: his.ID,
  10046. OrderId: order.ID,
  10047. ProjectId: project_id,
  10048. Type: types,
  10049. ItemId: item_id,
  10050. }
  10051. service.CreateOrderInfoTX(info, tx)
  10052. }
  10053. his.Diagnosis = diagnosis_id
  10054. his.SickType = sick_type
  10055. his.RegisterType = reg_type
  10056. his.MedicalTreatmentType = reg_type
  10057. service.UpdataHisPateintTX(&his, tx)
  10058. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  10059. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  10060. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  10061. //判断是否使用了押金
  10062. if dec_way == "true" {
  10063. tmpstring := strconv.FormatInt(order.ID, 10)
  10064. //扣押金
  10065. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  10066. order.Decimal = decimal
  10067. service.UpDateOrderTwo(order, tx)
  10068. if errmsg != nil {
  10069. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  10070. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10071. return
  10072. }
  10073. }
  10074. if err == nil {
  10075. for _, info := range prescriptions {
  10076. if info.Type == 1 {
  10077. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  10078. }
  10079. if info.Type == 2 {
  10080. for _, sumItem := range info.HisPrescriptionProject {
  10081. if sumItem.Type == 3 {
  10082. var good models.DialysisBeforePrepareGoods
  10083. var newGood models.NewDialysisBeforePrepareGoods
  10084. var oldGood models.OldDialysisBeforePrepareGoods
  10085. good.GoodId = sumItem.GoodInfo.ID
  10086. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10087. count, _ := strconv.Atoi(sumItem.Count)
  10088. good.Count = int64(count)
  10089. good.StorehouseId = houseConfig.StorehouseOutInfo
  10090. good.ProjectId = sumItem.ID
  10091. good.PatientId = sumItem.PatientId
  10092. goods = append(goods, &good)
  10093. newGood.GoodId = sumItem.GoodInfo.ID
  10094. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10095. count2, _ := strconv.Atoi(sumItem.Count)
  10096. newGood.Count = int64(count2)
  10097. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10098. newGood.ProjectId = sumItem.ID
  10099. newGood.PatientId = sumItem.HisPatientId
  10100. newGoods = append(newGoods, &newGood)
  10101. oldGood.GoodId = sumItem.GoodInfo.ID
  10102. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  10103. count3, _ := strconv.Atoi(sumItem.Count)
  10104. oldGood.Count = int64(count3)
  10105. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  10106. oldGood.ProjectId = sumItem.ID
  10107. oldGood.RecordDate = sumItem.RecordDate
  10108. oldGood.PatientId = sumItem.HisPatientId
  10109. oldGoods = append(oldGoods, &oldGood)
  10110. }
  10111. }
  10112. }
  10113. }
  10114. if settConfig.IsOpen == 1 {
  10115. for _, item := range infoList {
  10116. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  10117. if medical.IsUse == 2 {
  10118. //药品出库
  10119. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  10120. //查询默认仓库
  10121. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  10122. //查询默认仓库剩余多少库存
  10123. var sum_count int64
  10124. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  10125. for _, its := range stockInfo {
  10126. if its.MaxUnit == medical.MaxUnit {
  10127. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  10128. }
  10129. sum_count += its.StockMaxNumber + its.StockMinNumber
  10130. }
  10131. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  10132. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  10133. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  10134. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  10135. }
  10136. }
  10137. orgId := c.GetAdminUserInfo().CurrentOrgId
  10138. if len(oldGoods) > 0 {
  10139. timeStr := time.Now().Format("2006-01-02")
  10140. timeArr := strings.Split(timeStr, "-")
  10141. total, _ := service.FindAllWarehouseOut(orgId)
  10142. total = total + 1
  10143. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  10144. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  10145. number = number + total
  10146. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  10147. operation_time := time.Now().Unix()
  10148. creater := c.GetAdminUserInfo().AdminUser.Id
  10149. //查询默认出库仓库库存
  10150. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  10151. recordDateStr := time.Now().Format("2006-01-02")
  10152. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  10153. nowtime := recordDate.Unix()
  10154. warehouseOut := models.WarehouseOut{
  10155. WarehouseOutOrderNumber: warehousing_out_order,
  10156. OperationTime: operation_time,
  10157. OrgId: orgId,
  10158. Creater: creater,
  10159. Ctime: time.Now().Unix(),
  10160. Status: 1,
  10161. WarehouseOutTime: nowtime,
  10162. Type: 1,
  10163. StorehouseId: storeConfig.StorehouseOutInfo,
  10164. IsCheck: 1,
  10165. OrderId: order.ID,
  10166. IsSys: 5,
  10167. }
  10168. //查询是否生成出库单
  10169. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10170. if out.ID == 0 {
  10171. service.AddSigleWarehouseOutOne(&warehouseOut)
  10172. }
  10173. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  10174. for _, item := range oldGoods {
  10175. dialyPrepareOne := models.DialysisBeforePrepare{
  10176. GoodTypeId: item.GoodTypeId,
  10177. GoodId: item.GoodId,
  10178. PatientId: his.PatientId,
  10179. RecordDate: item.RecordDate,
  10180. UserOrgId: adminUser.CurrentOrgId,
  10181. Count: item.Count,
  10182. Ctime: time.Now().Unix(),
  10183. Creater: adminUser.AdminUser.Id,
  10184. CommdityCode: item.CommdityCode,
  10185. Status: 1,
  10186. StorehouseId: houseConfig.StorehouseOutInfo,
  10187. }
  10188. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  10189. //非零用
  10190. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  10191. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10192. //查询剩余库存
  10193. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10194. var sum_count int64
  10195. for _, item := range goodList {
  10196. sum_count += item.StockCount
  10197. }
  10198. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10199. //耗材
  10200. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10201. }
  10202. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  10203. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10204. //查询剩余库存
  10205. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10206. var sum_count int64
  10207. for _, item := range goodList {
  10208. sum_count += item.StockCount
  10209. }
  10210. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10211. //耗材
  10212. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10213. }
  10214. }
  10215. }
  10216. }
  10217. c.ServeSuccessJSON(map[string]interface{}{
  10218. "msg": "结算成功",
  10219. })
  10220. }
  10221. }
  10222. }
  10223. // 退款
  10224. func (c *HisApiController) Refund() {
  10225. order_id, _ := c.GetInt64("order_id")
  10226. order, _ := service.GetHisOrderByID(order_id)
  10227. adminUser := c.GetAdminUserInfo()
  10228. orgid := c.GetAdminUserInfo().CurrentOrgId
  10229. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  10230. if err != nil {
  10231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10232. return
  10233. }
  10234. tmp := strconv.FormatInt(order.ID, 10)
  10235. //当押金不为零时产生退费记录
  10236. if order.Decimal != 0 {
  10237. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  10238. if err != nil {
  10239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10240. return
  10241. }
  10242. }
  10243. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  10244. if fapiao.ID > 0 {
  10245. c.ServeSuccessJSON(map[string]interface{}{
  10246. "failed_code": -10,
  10247. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  10248. })
  10249. return
  10250. }
  10251. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  10252. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  10253. var goods []*models.DialysisBeforePrepareGoods
  10254. var newGoods []*models.NewDialysisBeforePrepareGoods
  10255. var infos []*models.HisDoctorAdviceInfo
  10256. for _, info := range orders {
  10257. if info.AdviceId > 0 && info.ProjectId == 0 {
  10258. infos = append(infos, &info.HisDoctorAdviceInfo)
  10259. }
  10260. if info.ProjectId > 0 && info.AdviceId == 0 {
  10261. if info.HisPrescriptionProject.Type == 3 {
  10262. var good models.DialysisBeforePrepareGoods
  10263. var newGood models.NewDialysisBeforePrepareGoods
  10264. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10265. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10266. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10267. good.Count = int64(count)
  10268. good.StorehouseId = houseConfig.StorehouseOutInfo
  10269. good.ProjectId = info.HisPrescriptionProject.ID
  10270. good.PatientId = info.PatientId
  10271. good.OrderId = order_id
  10272. goods = append(goods, &good)
  10273. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10274. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10275. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10276. newGood.Count = int64(count2)
  10277. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10278. newGood.ProjectId = info.HisPrescriptionProject.ID
  10279. newGood.RecordDate = order.SettleAccountsDate
  10280. newGood.UserOrgId = order.UserOrgId
  10281. newGood.PatientId = info.PatientId
  10282. newGood.OrderId = order_id
  10283. newGoods = append(newGoods, &newGood)
  10284. }
  10285. }
  10286. }
  10287. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10288. if settConfig.IsOpen == 1 {
  10289. for _, item := range infos {
  10290. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10291. }
  10292. for _, item := range newGoods {
  10293. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10294. }
  10295. }
  10296. c.ServeSuccessJSON(map[string]interface{}{
  10297. "msg": "退费成功",
  10298. })
  10299. }
  10300. func (c *HisApiController) RefundNumber() {
  10301. his_patient_id, _ := c.GetInt64("id")
  10302. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10303. info.Status = 0
  10304. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10305. if count > 0 {
  10306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10307. return
  10308. }
  10309. err := service.SaveHisPatient(info)
  10310. if err == nil {
  10311. c.ServeSuccessJSON(map[string]interface{}{
  10312. "msg": "退号成功",
  10313. })
  10314. } else {
  10315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10316. return
  10317. }
  10318. }
  10319. func (this *HisApiController) AdditionalCharge() {
  10320. dataBody := make(map[string]interface{}, 0)
  10321. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10322. fmt.Println(err)
  10323. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10324. patient_id := int64(dataBody["patient_id"].(float64))
  10325. medicineData, _ := dataBody["medicineData"].([]interface{})
  10326. adminUserInfo := this.GetAdminUserInfo()
  10327. orgId := adminUserInfo.CurrentOrgId
  10328. admin_user_id := adminUserInfo.AdminUser.Id
  10329. timeStr := time.Now().Format("2006-01-02")
  10330. timeLayout := "2006-01-02 15:04:05"
  10331. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10332. timenow := timeStringToTime.Unix()
  10333. var additionalCharges []*models.HisAdditionalCharge
  10334. for _, item := range medicineData {
  10335. var randNum int
  10336. randNum = rand.Intn(10000) + 1000
  10337. timestamp := time.Now().Unix()
  10338. tempTime := time.Unix(timestamp, 0)
  10339. timeFormat := tempTime.Format("20060102150405")
  10340. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10341. items := item.(map[string]interface{})
  10342. money := items["price"].(string)
  10343. item_id_str := items["item_id"].(string)
  10344. name := items["name"].(string)
  10345. id_str := items["id"].(string)
  10346. moneys, _ := strconv.ParseInt(money, 10, 64)
  10347. monStr := strconv.FormatInt(moneys, 10)
  10348. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10349. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10350. id, _ := strconv.ParseInt(id_str, 10, 64)
  10351. additionalCharge := &models.HisAdditionalCharge{
  10352. ID: id,
  10353. HisPatientId: his_patient_id,
  10354. UserOrgId: orgId,
  10355. PatientId: patient_id,
  10356. RecordDate: timenow,
  10357. Price: monneyStr,
  10358. Status: 1,
  10359. ItemName: name,
  10360. ItemId: item_id,
  10361. AdminUserId: admin_user_id,
  10362. CreatedTime: time.Now().Unix(),
  10363. OrderStatus: 0,
  10364. PrescriptionNumber: "",
  10365. BatchNumber: "",
  10366. FeedetlSn: p_number,
  10367. }
  10368. service.CreateAdditionalCharge(additionalCharge)
  10369. additionalCharges = append(additionalCharges, additionalCharge)
  10370. }
  10371. this.ServeSuccessJSON(map[string]interface{}{
  10372. "msg": "添加成功",
  10373. "additional_charges": additionalCharges,
  10374. })
  10375. }
  10376. func (this *HisApiController) DeleteAddition() {
  10377. id, _ := this.GetInt64("id")
  10378. //TODO 需要判断是否已经结算
  10379. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10380. if err == nil {
  10381. this.ServeSuccessJSON(map[string]interface{}{
  10382. "msg": "删除成功",
  10383. })
  10384. return
  10385. } else {
  10386. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10387. return
  10388. }
  10389. }
  10390. func (this *HisApiController) GetAdminUsers() {
  10391. adminUser := this.GetAdminUserInfo()
  10392. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10393. this.ServeSuccessJSON(map[string]interface{}{
  10394. "doctors": doctors,
  10395. })
  10396. }
  10397. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10398. change_type, _ := this.GetInt64("type", 0)
  10399. record_date := this.GetString("record_time")
  10400. patient_id, _ := this.GetInt64("patient_id", 0)
  10401. p_type, _ := this.GetInt64("p_type", 0)
  10402. timeLayout := "2006-01-02"
  10403. loc, _ := time.LoadLocation("Local")
  10404. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10405. record_time := theAdviceRecordTime.Unix()
  10406. adminUserInfo := this.GetAdminUserInfo()
  10407. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10408. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10409. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10410. if config.ID > 0 && config.IsOpen == 1 {
  10411. for _, subitems := range prescriptions {
  10412. for _, item := range subitems.VMHisPrescription {
  10413. for _, subItem := range item.HisDoctorAdviceInfo {
  10414. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10415. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10416. if info.RetailPrice > 0 {
  10417. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10418. subItem.Drug.RetailPrice = drug.RetailPrice
  10419. }
  10420. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10421. subItem.Drug.MinPrice = info.RetailPrice
  10422. subItem.Drug.RetailPrice = info.RetailPrice
  10423. }
  10424. }
  10425. }
  10426. }
  10427. }
  10428. }
  10429. if config.ID > 0 && config.IsOpen == 1 {
  10430. for _, subitems := range prescriptions {
  10431. for _, item := range subitems.VMHisPrescription {
  10432. for _, subItem := range item.HisPrescriptionProject {
  10433. if subItem.Type == 3 {
  10434. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10435. if info.Price > 0 {
  10436. subItem.GoodInfo.PackingPrice = info.Price
  10437. }
  10438. }
  10439. }
  10440. }
  10441. }
  10442. }
  10443. }
  10444. if err == nil {
  10445. if len(prescriptions) == 0 {
  10446. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10447. return
  10448. } else {
  10449. this.ServeSuccessJSON(map[string]interface{}{
  10450. "prescriptions": prescriptions,
  10451. })
  10452. return
  10453. }
  10454. } else {
  10455. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10456. return
  10457. }
  10458. }
  10459. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10460. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10461. for i := 0; i < len(arr); i++ {
  10462. repeat := false
  10463. for j := i + 1; j < len(arr); j++ {
  10464. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10465. repeat = true
  10466. break
  10467. }
  10468. }
  10469. if !repeat {
  10470. newArr = append(newArr, arr[i])
  10471. }
  10472. }
  10473. return
  10474. }
  10475. func (this *HisApiController) GetCallHisPrescription() {
  10476. patient_id, _ := this.GetInt64("patient_id", 0)
  10477. timeLayout := "2006-01-02"
  10478. loc, _ := time.LoadLocation("Local")
  10479. start_time := this.GetString("start_time")
  10480. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10481. end_time := this.GetString("end_time")
  10482. p_type, _ := this.GetInt64("p_type")
  10483. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10484. adminUserInfo := this.GetAdminUserInfo()
  10485. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10486. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10487. //if
  10488. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10489. //
  10490. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10491. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10492. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10493. if config.ID > 0 && config.IsOpen == 1 {
  10494. for _, subitems := range prescriptions {
  10495. for _, item := range subitems.VMHisPrescription {
  10496. for _, subItem := range item.HisDoctorAdviceInfo {
  10497. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10498. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10499. if info.RetailPrice > 0 {
  10500. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10501. subItem.Drug.RetailPrice = drug.RetailPrice
  10502. }
  10503. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10504. subItem.Drug.MinPrice = info.RetailPrice
  10505. subItem.Drug.RetailPrice = info.RetailPrice
  10506. }
  10507. }
  10508. }
  10509. }
  10510. }
  10511. }
  10512. if config.ID > 0 && config.IsOpen == 1 {
  10513. for _, subitems := range prescriptions {
  10514. for _, item := range subitems.VMHisPrescription {
  10515. for _, subItem := range item.HisPrescriptionProject {
  10516. if subItem.Type == 3 {
  10517. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10518. if info.Price > 0 {
  10519. subItem.GoodInfo.PackingPrice = info.Price
  10520. }
  10521. }
  10522. }
  10523. }
  10524. }
  10525. }
  10526. }
  10527. if err == nil {
  10528. this.ServeSuccessJSON(map[string]interface{}{
  10529. "prescriptions": prescriptions,
  10530. })
  10531. return
  10532. } else {
  10533. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10534. return
  10535. }
  10536. }
  10537. func (this *HisApiController) GetHisDayPrescription() {
  10538. timeLayout := "2006-01-02"
  10539. loc, _ := time.LoadLocation("Local")
  10540. start_time := this.GetString("start_time")
  10541. patient_id, _ := this.GetInt64("patient_id", 0)
  10542. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10543. end_time := this.GetString("end_time")
  10544. p_type, _ := this.GetInt64("p_type")
  10545. order_status, _ := this.GetInt64("type")
  10546. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10547. adminUserInfo := this.GetAdminUserInfo()
  10548. var dayHisPrescription []*models.HisPrescription
  10549. var err error
  10550. if order_status == 1 || order_status == 0 {
  10551. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10552. } else if order_status == 2 {
  10553. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10554. }
  10555. var settle_total float64
  10556. for _, item := range dayHisPrescription {
  10557. if len(item.HisPrescriptionProject) > 0 {
  10558. for _, subItem := range item.HisPrescriptionProject {
  10559. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10560. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10561. settle_total = settle_total + total
  10562. }
  10563. }
  10564. if len(item.HisDoctorAdviceInfo) > 0 {
  10565. for _, subItem := range item.HisDoctorAdviceInfo {
  10566. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10567. settle_total = settle_total + total
  10568. }
  10569. }
  10570. }
  10571. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10572. if err == nil {
  10573. this.ServeSuccessJSON(map[string]interface{}{
  10574. "day_prescription": dayHisPrescription,
  10575. "settle_total": settle_total,
  10576. })
  10577. return
  10578. } else {
  10579. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10580. return
  10581. }
  10582. }
  10583. func (c *HisApiController) GetHisChargePatientList() {
  10584. record_date := c.GetString("record_date")
  10585. order_status, _ := c.GetInt64("type")
  10586. sch_type, _ := c.GetInt64("sch_type")
  10587. timeLayout := "2006-01-02"
  10588. loc, _ := time.LoadLocation("Local")
  10589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10590. if err != nil {
  10591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10592. return
  10593. }
  10594. recordDateTime := theTime.Unix()
  10595. adminInfo := c.GetAdminUserInfo()
  10596. var tempPatients []*service.NewTempPatients
  10597. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10598. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10599. if order_status != 2 {
  10600. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10601. } else {
  10602. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10603. }
  10604. } else {
  10605. if order_status != 2 {
  10606. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10607. } else {
  10608. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10609. }
  10610. }
  10611. var patients []*service.NewTempPatients
  10612. var patients_two []*service.NewTempPatients
  10613. for _, item := range tempPatients {
  10614. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10615. //过滤掉没挂号的和没开处方的
  10616. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10617. patients = append(patients, item)
  10618. }
  10619. //过滤掉没挂号的
  10620. if len(item.HisPatient) > 0 {
  10621. patients_two = append(patients_two, item)
  10622. }
  10623. } else {
  10624. if len(item.HisPrescription) > 0 {
  10625. patients = append(patients, item)
  10626. }
  10627. }
  10628. }
  10629. c.ServeSuccessJSON(map[string]interface{}{
  10630. "list": patients,
  10631. "list_two": patients_two,
  10632. })
  10633. }
  10634. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10635. record_date := c.GetString("record_date")
  10636. timeLayout := "2006-01-02"
  10637. loc, _ := time.LoadLocation("Local")
  10638. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10639. if err != nil {
  10640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10641. return
  10642. }
  10643. recordDateTime := theTime.Unix()
  10644. adminUser := c.GetAdminUserInfo()
  10645. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10646. var patients []*service.Patients
  10647. for _, item := range tempPatients {
  10648. if item.HisPatient.ID == 0 {
  10649. patients = append(patients, item)
  10650. }
  10651. }
  10652. c.ServeSuccessJSON(map[string]interface{}{
  10653. "list": patients,
  10654. //"list_two": patients_two,
  10655. })
  10656. }
  10657. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10658. newArr = make([]*service.Patients, 0)
  10659. for i := 0; i < len(patient); i++ {
  10660. repeat := false
  10661. for j := i + 1; j < len(patient); j++ {
  10662. if patient[i].ID == patient[j].ID {
  10663. repeat = true
  10664. break
  10665. }
  10666. }
  10667. if !repeat {
  10668. newArr = append(newArr, patient[i])
  10669. }
  10670. }
  10671. return
  10672. }
  10673. func (c *HisApiController) GetHisChargePatientInfo() {
  10674. patient_id, _ := c.GetInt64("patient_id")
  10675. his_patient_id, _ := c.GetInt64("his_patient_id")
  10676. record_date := c.GetString("record_date")
  10677. //start_time := c.GetString("start_time")
  10678. //end_time := c.GetString("end_time")
  10679. order_status, _ := c.GetInt64("type", 0)
  10680. p_type, _ := c.GetInt64("p_type", 0)
  10681. order_id, _ := c.GetInt64("order_id", 0)
  10682. timeLayout := "2006-01-02"
  10683. loc, _ := time.LoadLocation("Local")
  10684. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10685. if err != nil {
  10686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10687. return
  10688. }
  10689. recordDateTime := theTime.Unix()
  10690. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10691. //if err != nil {
  10692. //
  10693. //}
  10694. //startRecordDateTime := startTime.Unix()
  10695. //
  10696. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10697. //if err != nil {
  10698. //
  10699. //}
  10700. //endRecordDateTime := endTime.Unix()
  10701. admin := c.GetAdminUserInfo()
  10702. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10703. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10704. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10705. var prescriptions []*models.HisPrescription
  10706. //var unChargeMonthPrescriptions []*models.HisPrescription
  10707. order, _ := service.GetHisOrderByID(order_id)
  10708. if order_status == 1 || order_status == 0 {
  10709. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10710. } else if order_status == 2 {
  10711. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10712. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10713. }
  10714. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10715. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10716. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10717. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10718. //获取所有科室信息
  10719. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10720. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10721. c.ServeSuccessJSON(map[string]interface{}{
  10722. "his_info": his_patient_info,
  10723. "last_his_patient_info": last_his_patient_info,
  10724. "xt_info": xt_patient_info,
  10725. "prescription": prescriptions,
  10726. "case_history": case_history,
  10727. "info": patientPrescriptionInfo,
  10728. "last_info": lastPatientPrescriptionInfo,
  10729. "order": order,
  10730. "doctors": doctors,
  10731. "department": department,
  10732. "sch": sch,
  10733. })
  10734. return
  10735. }
  10736. func (c *HisApiController) GetAllOrderDetail() {
  10737. order_id, _ := c.GetInt64("id", 0)
  10738. order, _ := service.GetHisOrderByID(order_id)
  10739. if order.ID == 0 {
  10740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10741. return
  10742. }
  10743. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10744. org_id := c.GetAdminUserInfo().CurrentOrgId
  10745. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10746. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10747. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10748. c.ServeSuccessJSON(map[string]interface{}{
  10749. "order": order,
  10750. "order_info": order_info,
  10751. "patient": patient,
  10752. "admin_info": adminInfo,
  10753. "hospital_record": record,
  10754. })
  10755. return
  10756. }
  10757. func (c *HisApiController) GetAllOrderDetailCollect() {
  10758. order_id, _ := c.GetInt64("id", 0)
  10759. order, _ := service.GetHisOrderByID(order_id)
  10760. if order.ID == 0 {
  10761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10762. return
  10763. }
  10764. org_id := c.GetAdminUserInfo().CurrentOrgId
  10765. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10766. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10767. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10768. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10769. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10770. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10771. var bedCostTotal float64 = 0 //床位总费
  10772. //var bedCostSelfTotal float64 = 0 //床位自费
  10773. var operationCostTotal float64 = 0 //手术费
  10774. //var operationCostSelfTotal float64 = 0 //手术费
  10775. var otherCostTotal float64 = 0 //其他费用
  10776. //var otherCostSelfTotal float64 = 0 //其他费用
  10777. var materialCostTotal float64 = 0 //材料费
  10778. //var materialCostSelfTotal float64 = 0 //材料费
  10779. var westernMedicineCostTotal float64 = 0 //西药费
  10780. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10781. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10782. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10783. var checkCostTotal float64 = 0 //检查费
  10784. //var checkCostSelfTotal float64 = 0 //检查费
  10785. var laboratoryCostTotal float64 = 0 //化验费
  10786. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10787. var treatCostTotal float64 = 0 //治疗费用
  10788. //var treatCostSelfTotal float64 = 0 //治疗费用
  10789. var zhenChaCostTotal float64 = 0 //其他费用
  10790. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10791. decimal.DivisionPrecision = 2
  10792. var BalanceAccountsType int64
  10793. if his.ID > 0 {
  10794. BalanceAccountsType = his.BalanceAccountsType
  10795. } else {
  10796. BalanceAccountsType = record.BalanceAccountsType
  10797. }
  10798. if BalanceAccountsType != 2 {
  10799. for _, item := range order_info {
  10800. if org_id == 10215 {
  10801. if item.MedChrgitmType == "01" { //床位费
  10802. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10803. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10804. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10805. }
  10806. if item.MedChrgitmType == "02" { //诊察费
  10807. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10808. //zhenChaCostSelfTotal = zhenChaCostTotal
  10809. }
  10810. if item.MedChrgitmType == "03" { //检查费
  10811. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10812. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10813. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10814. }
  10815. //if item.MedChrgitmType == "02" { //检查费
  10816. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10817. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10818. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10819. //}
  10820. if item.MedChrgitmType == "04" { //化验费
  10821. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10822. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10823. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10824. }
  10825. if item.MedChrgitmType == "05" { //治疗费
  10826. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10827. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10828. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10829. }
  10830. if item.MedChrgitmType == "06" { //手术费
  10831. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10832. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10833. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10834. }
  10835. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10836. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10837. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10838. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10839. }
  10840. if item.MedChrgitmType == "09" { //西药费
  10841. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10842. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10843. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10844. }
  10845. if item.MedChrgitmType == "11" { //中成费
  10846. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10847. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10848. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10849. }
  10850. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10851. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10852. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10853. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10854. }
  10855. } else if org_id == 10188 || org_id == 10217 {
  10856. if item.MedChrgitmType == "01" { //床位费
  10857. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10858. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10859. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10860. }
  10861. if item.MedChrgitmType == "02" { //诊察费
  10862. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10863. //zhenChaCostSelfTotal = zhenChaCostTotal
  10864. }
  10865. if item.MedChrgitmType == "03" { //检查费
  10866. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10867. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10868. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10869. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10870. }
  10871. //if item.MedChrgitmType == "02" { //检查费
  10872. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10873. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10874. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10875. //}
  10876. if item.MedChrgitmType == "04" { //化验费
  10877. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10878. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10879. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10880. }
  10881. if item.MedChrgitmType == "05" { //治疗费
  10882. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10883. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10884. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10885. }
  10886. if item.MedChrgitmType == "06" { //手术费
  10887. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10888. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10889. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10890. }
  10891. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10892. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10893. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10894. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10895. }
  10896. if item.MedChrgitmType == "09" { //西药费
  10897. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10898. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10899. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10900. }
  10901. if item.MedChrgitmType == "11" { //中成费
  10902. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10903. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10904. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10905. }
  10906. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10907. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10908. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10909. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10910. }
  10911. } else {
  10912. if item.MedChrgitmType == "01" { //床位费
  10913. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10914. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10915. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10916. }
  10917. //if item.MedChrgitmType == "02" { //诊察费
  10918. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10919. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10920. //}
  10921. if item.MedChrgitmType == "03" { //检查费
  10922. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10923. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10924. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10925. }
  10926. //if item.MedChrgitmType == "02" { //检查费
  10927. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10928. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10929. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10930. //}
  10931. if item.MedChrgitmType == "04" { //化验费
  10932. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10933. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10934. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10935. }
  10936. if item.MedChrgitmType == "05" { //治疗费
  10937. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10938. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10939. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10940. }
  10941. if item.MedChrgitmType == "06" { //手术费
  10942. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10943. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10944. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10945. }
  10946. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10947. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10948. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10949. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10950. }
  10951. if item.MedChrgitmType == "09" { //西药费
  10952. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10953. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10954. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10955. }
  10956. if item.MedChrgitmType == "11" { //中成费
  10957. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10958. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10959. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10960. }
  10961. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10962. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10963. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10964. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10965. }
  10966. }
  10967. }
  10968. c.ServeSuccessJSON(map[string]interface{}{
  10969. "order": order,
  10970. "order_info": order_info,
  10971. "patient": patient,
  10972. "admin_info": adminInfo,
  10973. "his_hospital": record,
  10974. "bedCostTotal": bedCostTotal,
  10975. "operationCostTotal": operationCostTotal,
  10976. "otherCostTotal": otherCostTotal,
  10977. "materialCostTotal": materialCostTotal,
  10978. "westernMedicineCostTotal": westernMedicineCostTotal,
  10979. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10980. "checkCostTotal": checkCostTotal,
  10981. "zhenChaCostTotal": zhenChaCostTotal,
  10982. "laboratoryCostTotal": laboratoryCostTotal,
  10983. "treatCostTotal": treatCostTotal,
  10984. })
  10985. } else {
  10986. for _, item := range order_info {
  10987. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10988. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10989. item.MedChrgitmType = "09"
  10990. }
  10991. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10992. if item.HisPrescriptionProject.Type == 2 {
  10993. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10994. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10995. case 0:
  10996. item.MedChrgitmType = "0"
  10997. break
  10998. case 1:
  10999. item.MedChrgitmType = "14"
  11000. break
  11001. case 2:
  11002. item.MedChrgitmType = "05"
  11003. break
  11004. case 3:
  11005. item.MedChrgitmType = "03"
  11006. break
  11007. case 4:
  11008. item.MedChrgitmType = "03"
  11009. break
  11010. case 5:
  11011. item.MedChrgitmType = "08"
  11012. break
  11013. case 6:
  11014. item.MedChrgitmType = "14"
  11015. break
  11016. case 7:
  11017. item.MedChrgitmType = "14"
  11018. break
  11019. case 8:
  11020. item.MedChrgitmType = "03"
  11021. break
  11022. case 9:
  11023. item.MedChrgitmType = "14"
  11024. break
  11025. case 10:
  11026. item.MedChrgitmType = "14"
  11027. break
  11028. case 11:
  11029. item.MedChrgitmType = "06"
  11030. break
  11031. case 12:
  11032. item.MedChrgitmType = "12"
  11033. break
  11034. case 13:
  11035. item.MedChrgitmType = "01"
  11036. break
  11037. case 14:
  11038. item.MedChrgitmType = "04"
  11039. break
  11040. case 15:
  11041. item.MedChrgitmType = "14"
  11042. break
  11043. }
  11044. } else {
  11045. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11046. case 1:
  11047. item.MedChrgitmType = "14"
  11048. break
  11049. case 2:
  11050. item.MedChrgitmType = "05"
  11051. break
  11052. case 3:
  11053. item.MedChrgitmType = "04"
  11054. break
  11055. case 4:
  11056. item.MedChrgitmType = "14"
  11057. break
  11058. case 5:
  11059. item.MedChrgitmType = "08"
  11060. break
  11061. case 6:
  11062. item.MedChrgitmType = "14"
  11063. break
  11064. case 7:
  11065. item.MedChrgitmType = "14"
  11066. break
  11067. case 8:
  11068. item.MedChrgitmType = "03"
  11069. break
  11070. case 9:
  11071. item.MedChrgitmType = "14"
  11072. break
  11073. }
  11074. }
  11075. } else if item.HisPrescriptionProject.Type == 3 {
  11076. item.MedChrgitmType = "08"
  11077. }
  11078. }
  11079. }
  11080. for _, item := range order_info {
  11081. if org_id == 10215 {
  11082. if item.MedChrgitmType == "01" { //床位费
  11083. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11084. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11085. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11086. }
  11087. if item.MedChrgitmType == "02" { //诊察费
  11088. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11089. //zhenChaCostSelfTotal = zhenChaCostTotal
  11090. }
  11091. if item.MedChrgitmType == "03" { //检查费
  11092. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11093. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11094. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11095. }
  11096. //if item.MedChrgitmType == "02" { //检查费
  11097. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11098. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11099. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11100. //}
  11101. if item.MedChrgitmType == "04" { //化验费
  11102. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11103. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11104. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11105. }
  11106. if item.MedChrgitmType == "05" { //治疗费
  11107. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11108. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11109. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11110. }
  11111. if item.MedChrgitmType == "06" { //手术费
  11112. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11113. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11114. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11115. }
  11116. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11117. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11118. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11119. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11120. }
  11121. if item.MedChrgitmType == "09" { //西药费
  11122. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11123. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11124. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11125. }
  11126. if item.MedChrgitmType == "11" { //中成费
  11127. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11128. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11129. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11130. }
  11131. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11132. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11133. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11134. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11135. }
  11136. } else {
  11137. if item.MedChrgitmType == "01" { //床位费
  11138. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11139. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11140. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11141. }
  11142. //if item.MedChrgitmType == "02" { //诊察费
  11143. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11144. // //zhenChaCostSelfTotal = zhenChaCostTotal
  11145. //}
  11146. if item.MedChrgitmType == "03" { //检查费
  11147. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11148. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11149. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11150. }
  11151. //if item.MedChrgitmType == "02" { //检查费
  11152. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11153. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11154. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11155. //}
  11156. if item.MedChrgitmType == "04" { //化验费
  11157. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11158. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11159. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11160. }
  11161. if item.MedChrgitmType == "05" { //治疗费
  11162. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11163. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11164. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11165. }
  11166. if item.MedChrgitmType == "06" { //手术费
  11167. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11168. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11169. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11170. }
  11171. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  11172. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11173. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11174. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11175. }
  11176. if item.MedChrgitmType == "09" { //西药费
  11177. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11178. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11179. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11180. }
  11181. if item.MedChrgitmType == "11" { //中成费
  11182. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11183. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11184. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11185. }
  11186. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11187. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11188. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11189. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11190. }
  11191. }
  11192. }
  11193. c.ServeSuccessJSON(map[string]interface{}{
  11194. "order": order,
  11195. "order_info": order_info,
  11196. "patient": patient,
  11197. "admin_info": adminInfo,
  11198. "his_hospital": record,
  11199. "bedCostTotal": bedCostTotal,
  11200. "operationCostTotal": operationCostTotal,
  11201. "otherCostTotal": otherCostTotal,
  11202. "materialCostTotal": materialCostTotal,
  11203. "westernMedicineCostTotal": westernMedicineCostTotal,
  11204. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11205. "checkCostTotal": checkCostTotal,
  11206. "zhenChaCostTotal": zhenChaCostTotal,
  11207. "laboratoryCostTotal": laboratoryCostTotal,
  11208. "treatCostTotal": treatCostTotal,
  11209. })
  11210. }
  11211. }
  11212. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  11213. page, _ := c.GetInt64("page")
  11214. limit, _ := c.GetInt64("limit")
  11215. keywords := c.GetString("keywords")
  11216. start_time := c.GetString("start_time")
  11217. end_time := c.GetString("end_time")
  11218. //clr_type := c.GetString("clr_type")
  11219. insutype := c.GetString("insutype")
  11220. timeLayout := "2006-01-02"
  11221. loc, _ := time.LoadLocation("Local")
  11222. var theStartTIme int64
  11223. if len(start_time) > 0 {
  11224. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11225. theStartTIme = theTime.Unix()
  11226. }
  11227. var theEndtTIme int64
  11228. if len(end_time) > 0 {
  11229. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11230. theEndtTIme = theTime.Unix()
  11231. }
  11232. if page <= 0 {
  11233. page = 1
  11234. }
  11235. if limit <= 0 {
  11236. limit = 10
  11237. }
  11238. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  11239. c.ServeSuccessJSON(map[string]interface{}{
  11240. "total": total,
  11241. "list": list,
  11242. })
  11243. return
  11244. }
  11245. func (c *HisApiController) GetPutOnRecordList() {
  11246. page, _ := c.GetInt64("page")
  11247. limit, _ := c.GetInt64("limit")
  11248. keywords := c.GetString("keywords")
  11249. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  11250. if page <= 0 {
  11251. page = 1
  11252. }
  11253. if limit <= 0 {
  11254. limit = 10
  11255. }
  11256. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  11257. c.ServeSuccessJSON(map[string]interface{}{
  11258. "total": total,
  11259. "list": list,
  11260. })
  11261. return
  11262. }
  11263. func (c *HisApiController) GetCompareData() {
  11264. start_time := c.GetString("start_time")
  11265. end_time := c.GetString("end_time")
  11266. insutype := c.GetString("insutype")
  11267. clr_type := c.GetString("clr_type")
  11268. timeLayout := "2006-01-02"
  11269. loc, _ := time.LoadLocation("Local")
  11270. var theStartTIme int64
  11271. if len(start_time) > 0 {
  11272. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11273. if err != nil {
  11274. theStartTIme = 0
  11275. }
  11276. theStartTIme = theTime.Unix()
  11277. }
  11278. var theEndtTIme int64
  11279. if len(end_time) > 0 {
  11280. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11281. if err != nil {
  11282. theEndtTIme = 0
  11283. }
  11284. theEndtTIme = theTime.Unix()
  11285. }
  11286. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11287. fmt.Println(err)
  11288. if err == nil {
  11289. c.ServeSuccessJSON(map[string]interface{}{
  11290. "list": formData,
  11291. })
  11292. } else {
  11293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11294. return
  11295. }
  11296. }
  11297. func (c *HisApiController) GetFaPiaoData() {
  11298. order_id, _ := c.GetInt64("order_id")
  11299. patient_id, _ := c.GetInt64("patient_id")
  11300. //number := c.GetString("number")
  11301. adminUser := c.GetAdminUserInfo()
  11302. order, _ := service.GetHisOrderByID(order_id)
  11303. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11304. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11305. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11306. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11307. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11308. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11309. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11310. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11311. var bedCostTotal float64 = 0 //床位总费
  11312. var bedCostSelfTotal float64 = 0 //床位自费
  11313. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11314. var operationCostTotal float64 = 0 //手术费
  11315. var operationCostSelfTotal float64 = 0 //手术费
  11316. var operationCostPartSelfTotal float64 = 0 //手术费
  11317. var otherCostTotal float64 = 0 //其他费用
  11318. var otherCostSelfTotal float64 = 0 //其他费用
  11319. var otherCostPartSelfTotal float64 = 0 //其他费用
  11320. var materialCostTotal float64 = 0 //材料费
  11321. var materialCostSelfTotal float64 = 0 //材料费
  11322. var materialCostPartSelfTotal float64 = 0 //材料费
  11323. var westernMedicineCostTotal float64 = 0 //西药费
  11324. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11325. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11326. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11327. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11328. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11329. var checkCostTotal float64 = 0 //检查费
  11330. var checkCostSelfTotal float64 = 0 //检查费
  11331. var checkCostPartSelfTotal float64 = 0 //检查费
  11332. var hiliCostTotal float64 = 0 //护理费
  11333. var hiliCostSelfTotal float64 = 0 //护理费
  11334. var hiliCostPartSelfTotal float64 = 0 //护理费
  11335. var laboratoryCostTotal float64 = 0 //化验费
  11336. var laboratoryCostSelfTotal float64 = 0 //化验费
  11337. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11338. var treatCostTotal float64 = 0 //治疗费用
  11339. var treatCostSelfTotal float64 = 0 //治疗费用
  11340. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11341. var zhenChaCostTotal float64 = 0 //其他费用
  11342. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11343. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11344. decimal.DivisionPrecision = 2
  11345. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11346. var balanceAccountsType int64
  11347. if his.ID > 0 {
  11348. balanceAccountsType = his.BalanceAccountsType
  11349. } else {
  11350. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11351. }
  11352. if balanceAccountsType == 2 {
  11353. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11354. for _, item := range orderInfos_two {
  11355. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11356. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11357. item.MedChrgitmType = "09"
  11358. }
  11359. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11360. if item.HisPrescriptionProject.Type == 2 {
  11361. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11362. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11363. case 0:
  11364. item.MedChrgitmType = "0"
  11365. break
  11366. case 1:
  11367. item.MedChrgitmType = "14"
  11368. break
  11369. case 2:
  11370. item.MedChrgitmType = "05"
  11371. break
  11372. case 3:
  11373. item.MedChrgitmType = "03"
  11374. break
  11375. case 4:
  11376. item.MedChrgitmType = "03"
  11377. break
  11378. case 5:
  11379. item.MedChrgitmType = "08"
  11380. break
  11381. case 6:
  11382. item.MedChrgitmType = "14"
  11383. break
  11384. case 7:
  11385. item.MedChrgitmType = "14"
  11386. break
  11387. case 8:
  11388. item.MedChrgitmType = "03"
  11389. break
  11390. case 9:
  11391. item.MedChrgitmType = "14"
  11392. break
  11393. case 10:
  11394. item.MedChrgitmType = "14"
  11395. break
  11396. case 11:
  11397. item.MedChrgitmType = "06"
  11398. break
  11399. case 12:
  11400. item.MedChrgitmType = "12"
  11401. break
  11402. case 13:
  11403. item.MedChrgitmType = "01"
  11404. break
  11405. case 14:
  11406. item.MedChrgitmType = "04"
  11407. break
  11408. case 15:
  11409. item.MedChrgitmType = "02"
  11410. break
  11411. }
  11412. } else {
  11413. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11414. case 1:
  11415. item.MedChrgitmType = "14"
  11416. break
  11417. case 2:
  11418. item.MedChrgitmType = "05"
  11419. break
  11420. case 3:
  11421. item.MedChrgitmType = "04"
  11422. break
  11423. case 4:
  11424. item.MedChrgitmType = "03"
  11425. break
  11426. case 5:
  11427. item.MedChrgitmType = "08"
  11428. break
  11429. case 6:
  11430. item.MedChrgitmType = "14"
  11431. break
  11432. case 7:
  11433. item.MedChrgitmType = "14"
  11434. break
  11435. case 8:
  11436. item.MedChrgitmType = "03"
  11437. break
  11438. case 9:
  11439. item.MedChrgitmType = "14"
  11440. break
  11441. }
  11442. }
  11443. } else if item.HisPrescriptionProject.Type == 3 {
  11444. item.MedChrgitmType = "08"
  11445. }
  11446. }
  11447. }
  11448. for _, item := range orderInfos_two {
  11449. fmt.Println(item.MedChrgitmType)
  11450. if item.MedChrgitmType == "07" { //床位费
  11451. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11452. hiliCostSelfTotal = hiliCostTotal
  11453. }
  11454. if item.MedChrgitmType == "01" { //床位费
  11455. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11456. bedCostSelfTotal = bedCostTotal
  11457. }
  11458. if item.MedChrgitmType == "02" { //诊察费
  11459. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11460. zhenChaCostSelfTotal = zhenChaCostTotal
  11461. }
  11462. if item.MedChrgitmType == "03" { //检查费
  11463. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11464. checkCostSelfTotal = checkCostTotal
  11465. }
  11466. if item.MedChrgitmType == "04" { //化验费
  11467. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11468. laboratoryCostSelfTotal = laboratoryCostTotal
  11469. }
  11470. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11471. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11472. treatCostSelfTotal = treatCostTotal
  11473. }
  11474. if item.MedChrgitmType == "06" { //手术费
  11475. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11476. operationCostSelfTotal = treatCostTotal
  11477. }
  11478. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11479. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11480. materialCostSelfTotal = materialCostTotal
  11481. }
  11482. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11483. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11484. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11485. }
  11486. if item.MedChrgitmType == "11" { //中成费
  11487. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11488. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11489. }
  11490. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11491. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11492. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11493. otherCostSelfTotal = otherCostTotal
  11494. }
  11495. } else {
  11496. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11497. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11498. otherCostSelfTotal = otherCostTotal
  11499. }
  11500. }
  11501. }
  11502. } else {
  11503. for _, item := range orderInfos {
  11504. if item.MedChrgitmType == "01" { //床位费
  11505. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11506. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11507. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11508. }
  11509. if item.MedChrgitmType == "02" { //诊察费
  11510. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11511. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11512. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11513. }
  11514. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11515. if item.MedChrgitmType == "03" { //检查费
  11516. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11517. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11518. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11519. }
  11520. } else {
  11521. if item.MedChrgitmType == "03" { //检查费
  11522. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11523. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11524. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11525. }
  11526. }
  11527. if item.MedChrgitmType == "04" { //化验费
  11528. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11529. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11530. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11531. }
  11532. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11533. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11534. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11535. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11536. }
  11537. if item.MedChrgitmType == "06" { //手术费
  11538. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11539. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11540. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11541. }
  11542. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11543. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11544. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11545. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11546. }
  11547. if item.MedChrgitmType == "07" { //护理
  11548. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11549. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11550. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11551. }
  11552. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11553. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11554. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11555. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11556. }
  11557. if item.MedChrgitmType == "11" { //中成费
  11558. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11559. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11560. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11561. }
  11562. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11563. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11564. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11565. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11566. }
  11567. }
  11568. }
  11569. timeLayout := "2006-01-02"
  11570. loc, _ := time.LoadLocation("Local")
  11571. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11572. if err != nil {
  11573. }
  11574. startRecordDateTime := startTime.Unix()
  11575. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11576. if err != nil {
  11577. }
  11578. endRecordDateTime := endTime.Unix()
  11579. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11580. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11581. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11582. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11583. c.ServeSuccessJSON(map[string]interface{}{
  11584. "charge_admin_name": charge_admin.UserName,
  11585. "order_number": order.Number, //业务流水号
  11586. "id_card_no": his.IdCardNo, //社会保障号
  11587. "patient": patient,
  11588. "department_name": department.Name, //科室
  11589. "number": his.Number, //门诊号
  11590. "date": order.SettleAccountsDate, //结算日期
  11591. "name": order.PsnName, //姓名
  11592. "gender": patient.Gender, //性别
  11593. "psn_cash_money": order.PsnCashPay, //个人支付
  11594. "pay_way": "门诊", //结算方式
  11595. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11596. "admin_user_name": admin.UserName, //收款员
  11597. "order": order,
  11598. "order_info": orderInfos_two,
  11599. "his": his,
  11600. "bedCostTotal": bedCostTotal,
  11601. "bedCostSelfTotal": bedCostSelfTotal,
  11602. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11603. "operationCostTotal": operationCostTotal,
  11604. "operationCostSelfTotal": operationCostSelfTotal,
  11605. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11606. "otherCostTotal": otherCostTotal,
  11607. "otherCostSelfTotal": otherCostSelfTotal,
  11608. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11609. "materialCostTotal": materialCostTotal,
  11610. "materialCostSelfTotal": materialCostSelfTotal,
  11611. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11612. "westernMedicineCostTotal": westernMedicineCostTotal,
  11613. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11614. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11615. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11616. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11617. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11618. "checkCostTotal": checkCostTotal,
  11619. "checkCostSelfTotal": checkCostSelfTotal,
  11620. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11621. "laboratoryCostTotal": laboratoryCostTotal,
  11622. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11623. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11624. "treatCostTotal": treatCostTotal,
  11625. "treatCostSelfTotal": treatCostSelfTotal,
  11626. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11627. "zhenChaCostTotal": zhenChaCostTotal,
  11628. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11629. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11630. "his_hospital_record": his_hospital_record,
  11631. "pre_pay_money": pre_pay_money,
  11632. "refund_sum": sum,
  11633. "doctor_info": doctor_info,
  11634. "hiliCostTotal": hiliCostTotal,
  11635. "hiliCostSelfTotal": hiliCostSelfTotal,
  11636. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11637. })
  11638. }
  11639. //func (c *HisApiController) GetFaPiaoDatas() {
  11640. // order_ids := c.GetString("order_ids")
  11641. // patient_id, _ := c.GetInt64("patient_id")
  11642. // adminUser := c.GetAdminUserInfo()
  11643. //
  11644. // orders := strings.Split(order_ids, ",")
  11645. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11646. //
  11647. // for _, item := range orders {
  11648. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11649. // order, _ := service.GetHisOrderByID(order_id)
  11650. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11651. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11652. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11653. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11654. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11655. //
  11656. // }
  11657. //
  11658. // var bedCostTotal float64 = 0 //床位总费
  11659. // var bedCostSelfTotal float64 = 0 //床位自费
  11660. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11661. //
  11662. // var operationCostTotal float64 = 0 //手术费
  11663. // var operationCostSelfTotal float64 = 0 //手术费
  11664. // var operationCostPartSelfTotal float64 = 0 //手术费
  11665. //
  11666. // var otherCostTotal float64 = 0 //其他费用
  11667. // var otherCostSelfTotal float64 = 0 //其他费用
  11668. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11669. //
  11670. // var materialCostTotal float64 = 0 //材料费
  11671. // var materialCostSelfTotal float64 = 0 //材料费
  11672. // var materialCostPartSelfTotal float64 = 0 //材料费
  11673. //
  11674. // var westernMedicineCostTotal float64 = 0 //西药费
  11675. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11676. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11677. //
  11678. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11679. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11680. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11681. //
  11682. // var checkCostTotal float64 = 0 //检查费
  11683. // var checkCostSelfTotal float64 = 0 //检查费
  11684. // var checkCostPartSelfTotal float64 = 0 //检查费
  11685. //
  11686. // var laboratoryCostTotal float64 = 0 //化验费
  11687. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11688. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11689. //
  11690. // var treatCostTotal float64 = 0 //治疗费用
  11691. // var treatCostSelfTotal float64 = 0 //治疗费用
  11692. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11693. //
  11694. // var zhenChaCostTotal float64 = 0 //其他费用
  11695. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11696. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11697. //
  11698. // decimal.DivisionPrecision = 2
  11699. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11700. //
  11701. // var balanceAccountsType int64
  11702. // if his.ID > 0 {
  11703. // balanceAccountsType = his.BalanceAccountsType
  11704. // } else {
  11705. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11706. // }
  11707. // if balanceAccountsType == 2 {
  11708. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11709. // for _, item := range orderInfos_two {
  11710. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11711. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11712. // item.MedChrgitmType = "09"
  11713. // }
  11714. //
  11715. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11716. // if item.HisPrescriptionProject.Type == 2 {
  11717. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11718. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11719. // case 0:
  11720. // item.MedChrgitmType = "0"
  11721. // break
  11722. // case 1:
  11723. // item.MedChrgitmType = "14"
  11724. // break
  11725. // case 2:
  11726. // item.MedChrgitmType = "05"
  11727. //
  11728. // break
  11729. // case 3:
  11730. // item.MedChrgitmType = "03"
  11731. //
  11732. // break
  11733. // case 4:
  11734. // item.MedChrgitmType = "03"
  11735. //
  11736. // break
  11737. // case 5:
  11738. // item.MedChrgitmType = "08"
  11739. //
  11740. // break
  11741. // case 6:
  11742. // item.MedChrgitmType = "14"
  11743. //
  11744. // break
  11745. // case 7:
  11746. // item.MedChrgitmType = "14"
  11747. //
  11748. // break
  11749. // case 8:
  11750. // item.MedChrgitmType = "03"
  11751. // break
  11752. // case 9:
  11753. // item.MedChrgitmType = "14"
  11754. // break
  11755. // case 10:
  11756. // item.MedChrgitmType = "14"
  11757. // break
  11758. // case 11:
  11759. // item.MedChrgitmType = "06"
  11760. // break
  11761. // case 12:
  11762. // item.MedChrgitmType = "12"
  11763. // break
  11764. // case 13:
  11765. // item.MedChrgitmType = "01"
  11766. // break
  11767. // case 14:
  11768. // item.MedChrgitmType = "04"
  11769. // break
  11770. // case 15:
  11771. // item.MedChrgitmType = "02"
  11772. // break
  11773. //
  11774. // }
  11775. //
  11776. // } else {
  11777. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11778. //
  11779. // case 1:
  11780. // item.MedChrgitmType = "14"
  11781. // break
  11782. // case 2:
  11783. // item.MedChrgitmType = "05"
  11784. //
  11785. // break
  11786. // case 3:
  11787. // item.MedChrgitmType = "03"
  11788. //
  11789. // break
  11790. // case 4:
  11791. // item.MedChrgitmType = "03"
  11792. //
  11793. // break
  11794. // case 5:
  11795. // item.MedChrgitmType = "08"
  11796. //
  11797. // break
  11798. // case 6:
  11799. // item.MedChrgitmType = "14"
  11800. //
  11801. // break
  11802. // case 7:
  11803. // item.MedChrgitmType = "14"
  11804. //
  11805. // break
  11806. // case 8:
  11807. // item.MedChrgitmType = "03"
  11808. // break
  11809. // case 9:
  11810. // item.MedChrgitmType = "14"
  11811. // break
  11812. //
  11813. // }
  11814. //
  11815. // }
  11816. //
  11817. // } else if item.HisPrescriptionProject.Type == 3 {
  11818. // item.MedChrgitmType = "08"
  11819. // }
  11820. // }
  11821. // }
  11822. //
  11823. // for _, item := range orderInfos_two {
  11824. // fmt.Println(item.MedChrgitmType)
  11825. // if item.MedChrgitmType == "01" { //床位费
  11826. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11827. // bedCostSelfTotal = bedCostTotal
  11828. // }
  11829. //
  11830. // if item.MedChrgitmType == "02" { //诊察费
  11831. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11832. // zhenChaCostSelfTotal = zhenChaCostTotal
  11833. // }
  11834. //
  11835. // if item.MedChrgitmType == "03" { //检查费
  11836. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11837. // checkCostSelfTotal = checkCostTotal
  11838. // }
  11839. //
  11840. // if item.MedChrgitmType == "04" { //化验费
  11841. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11842. // laboratoryCostSelfTotal = laboratoryCostTotal
  11843. // }
  11844. //
  11845. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11846. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11847. // treatCostSelfTotal = treatCostTotal
  11848. // }
  11849. //
  11850. // if item.MedChrgitmType == "06" { //手术费
  11851. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11852. // operationCostSelfTotal = treatCostTotal
  11853. // }
  11854. //
  11855. // if item.MedChrgitmType == "08" { //材料费
  11856. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11857. // materialCostSelfTotal = materialCostTotal
  11858. // }
  11859. //
  11860. // if item.MedChrgitmType == "09" { //西药费
  11861. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11862. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11863. // }
  11864. //
  11865. // if item.MedChrgitmType == "11" { //中成费
  11866. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11867. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11868. // }
  11869. //
  11870. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11871. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11872. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11873. // otherCostSelfTotal = otherCostTotal
  11874. // }
  11875. // } else {
  11876. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11877. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11878. // otherCostSelfTotal = otherCostTotal
  11879. // }
  11880. //
  11881. // }
  11882. //
  11883. // }
  11884. //
  11885. // } else {
  11886. // for _, item := range orderInfos {
  11887. // if item.MedChrgitmType == "01" { //床位费
  11888. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11889. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11890. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11891. // }
  11892. //
  11893. // if item.MedChrgitmType == "02" { //诊察费
  11894. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11895. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11896. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11897. // }
  11898. //
  11899. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11900. // if item.MedChrgitmType == "03" { //检查费
  11901. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11902. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11903. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11904. //
  11905. // }
  11906. // } else {
  11907. // if item.MedChrgitmType == "03" { //检查费
  11908. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11909. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11910. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11911. // }
  11912. //
  11913. // }
  11914. //
  11915. // if item.MedChrgitmType == "04" { //化验费
  11916. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11917. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11918. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11919. //
  11920. // }
  11921. //
  11922. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11923. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11924. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11925. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11926. //
  11927. // }
  11928. //
  11929. // if item.MedChrgitmType == "06" { //手术费
  11930. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11931. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11932. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11933. // }
  11934. //
  11935. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11936. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11937. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11938. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11939. // }
  11940. //
  11941. // if item.MedChrgitmType == "09" { //西药费
  11942. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11943. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11944. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11945. // }
  11946. //
  11947. // if item.MedChrgitmType == "11" { //中成费
  11948. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11949. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11950. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11951. // }
  11952. //
  11953. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11954. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11955. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11956. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11957. // }
  11958. //
  11959. // }
  11960. // }
  11961. // timeLayout := "2006-01-02"
  11962. // loc, _ := time.LoadLocation("Local")
  11963. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11964. // if err != nil {
  11965. // }
  11966. // startRecordDateTime := startTime.Unix()
  11967. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11968. // if err != nil {
  11969. // }
  11970. // endRecordDateTime := endTime.Unix()
  11971. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11972. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11973. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11974. //
  11975. // c.ServeSuccessJSON(map[string]interface{}{
  11976. // "order_number": order.Number, //业务流水号
  11977. // "id_card_no": his.IdCardNo, //社会保障号
  11978. // "department_name": department.Name, //科室
  11979. // "number": his.Number, //门诊号
  11980. // "date": order.SettleAccountsDate, //结算日期
  11981. // "name": order.PsnName, //姓名
  11982. // "gender": patient.Gender, //性别
  11983. // "psn_cash_money": order.PsnCashPay, //个人支付
  11984. // "pay_way": "门诊", //结算方式
  11985. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11986. // "admin_user_name": admin.UserName, //收款员
  11987. // "order": order,
  11988. // "order_info": orderInfos_two,
  11989. // "his": his,
  11990. // "bedCostTotal": bedCostTotal,
  11991. // "bedCostSelfTotal": bedCostSelfTotal,
  11992. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11993. // "operationCostTotal": operationCostTotal,
  11994. // "operationCostSelfTotal": operationCostSelfTotal,
  11995. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11996. // "otherCostTotal": otherCostTotal,
  11997. // "otherCostSelfTotal": otherCostSelfTotal,
  11998. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11999. // "materialCostTotal": materialCostTotal,
  12000. // "materialCostSelfTotal": materialCostSelfTotal,
  12001. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  12002. // "westernMedicineCostTotal": westernMedicineCostTotal,
  12003. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  12004. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  12005. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  12006. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  12007. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  12008. // "checkCostTotal": checkCostTotal,
  12009. // "checkCostSelfTotal": checkCostSelfTotal,
  12010. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  12011. // "laboratoryCostTotal": laboratoryCostTotal,
  12012. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  12013. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  12014. // "treatCostTotal": treatCostTotal,
  12015. // "treatCostSelfTotal": treatCostSelfTotal,
  12016. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  12017. // "zhenChaCostTotal": zhenChaCostTotal,
  12018. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  12019. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  12020. // "his_hospital_record": his_hospital_record,
  12021. // "pre_pay_money": pre_pay_money,
  12022. // "refund_sum": sum,
  12023. // })
  12024. //
  12025. //}
  12026. func (this *HisApiController) GetIncomeStatisticsData() {
  12027. start_time := this.GetString("start_time")
  12028. end_time := this.GetString("end_time")
  12029. key_words := this.GetString("key_words")
  12030. limit, _ := this.GetInt64("limit")
  12031. page, _ := this.GetInt64("page")
  12032. if page <= 0 {
  12033. page = 1
  12034. }
  12035. if limit <= 0 {
  12036. limit = 10
  12037. }
  12038. statistics_type, _ := this.GetInt64("statistics_type")
  12039. admin := this.GetAdminUserInfo()
  12040. timeLayout := "2006-01-02"
  12041. loc, _ := time.LoadLocation("Local")
  12042. var theStartTIme int64
  12043. if len(start_time) > 0 {
  12044. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12045. if err != nil {
  12046. theStartTIme = 0
  12047. }
  12048. theStartTIme = theTime.Unix()
  12049. }
  12050. var theEndtTIme int64
  12051. if len(end_time) > 0 {
  12052. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12053. if err != nil {
  12054. theEndtTIme = 0
  12055. }
  12056. theEndtTIme = theTime.Unix()
  12057. }
  12058. if statistics_type == 1 {
  12059. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12060. this.ServeSuccessJSON(map[string]interface{}{
  12061. "list": list,
  12062. "total": total,
  12063. })
  12064. } else {
  12065. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  12066. this.ServeSuccessJSON(map[string]interface{}{
  12067. "list": list,
  12068. "total": total,
  12069. })
  12070. }
  12071. }
  12072. func (c *HisApiController) PostProjectInformation() {
  12073. adminUser := c.GetAdminUserInfo()
  12074. orgId := adminUser.CurrentOrgId
  12075. dataBody := make(map[string]interface{}, 0)
  12076. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12077. if err != nil {
  12078. utils.ErrorLog(err.Error())
  12079. return
  12080. }
  12081. utils.ErrorLog("%v", dataBody)
  12082. var projectList []*models.HisProject
  12083. var total_goods []interface{}
  12084. tempProjects := dataBody["projects"].([]interface{})
  12085. total_goods = tempProjects
  12086. for index, projectMap := range tempProjects {
  12087. projectM := projectMap.(map[string]interface{})
  12088. var project models.HisProject
  12089. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  12090. utils.ErrorLog("project_name")
  12091. return
  12092. }
  12093. project_name, _ := projectM["project_name"].(string)
  12094. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  12095. err_log := models.ExportErrLog{
  12096. LogType: 6,
  12097. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12098. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  12099. Status: 1,
  12100. CreateTime: time.Now().Unix(),
  12101. UpdateTime: time.Now().Unix(),
  12102. ExportTime: time.Now().Unix(),
  12103. }
  12104. service.CreateExportErrLog(&err_log)
  12105. continue
  12106. }
  12107. project.ProjectName = project_name
  12108. prices := projectM["price"].(string)
  12109. price, _ := strconv.ParseFloat(prices, 64)
  12110. if price <= 0 { //名字为空则生成一条导入错误日志
  12111. err_log := models.ExportErrLog{
  12112. LogType: 6,
  12113. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12114. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  12115. Status: 1,
  12116. CreateTime: time.Now().Unix(),
  12117. UpdateTime: time.Now().Unix(),
  12118. ExportTime: time.Now().Unix(),
  12119. }
  12120. service.CreateExportErrLog(&err_log)
  12121. continue
  12122. }
  12123. project.Price = price
  12124. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  12125. utils.ErrorLog("unit_id")
  12126. return
  12127. }
  12128. unit := projectM["unit"].(string)
  12129. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  12130. err_log := models.ExportErrLog{
  12131. LogType: 6,
  12132. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12133. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  12134. Status: 1,
  12135. CreateTime: time.Now().Unix(),
  12136. UpdateTime: time.Now().Unix(),
  12137. ExportTime: time.Now().Unix(),
  12138. }
  12139. service.CreateExportErrLog(&err_log)
  12140. continue
  12141. }
  12142. project.Unit = unit
  12143. cost_classify := projectM["cost_classify"].(string)
  12144. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  12145. err_log := models.ExportErrLog{
  12146. LogType: 6,
  12147. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12148. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12149. Status: 1,
  12150. CreateTime: time.Now().Unix(),
  12151. UpdateTime: time.Now().Unix(),
  12152. ExportTime: time.Now().Unix(),
  12153. }
  12154. service.CreateExportErrLog(&err_log)
  12155. continue
  12156. }
  12157. var costClassify = "费用类别"
  12158. var cost_classify_id int64
  12159. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  12160. if len(cost_classify) != 0 {
  12161. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  12162. if errcode == gorm.ErrRecordNotFound {
  12163. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  12164. dataconfig := models.DictDataconfig{
  12165. ParentId: costClassifyConfig.ID,
  12166. Module: "system",
  12167. OrgId: orgId,
  12168. Name: cost_classify,
  12169. FieldName: "",
  12170. Value: costConfig.Value + 1,
  12171. CreatedTime: "",
  12172. UpdatedTime: "",
  12173. CreateUserId: adminUser.AdminUser.Id,
  12174. Status: 1,
  12175. Remark: "",
  12176. DeleteIdSystem: 0,
  12177. Title: "",
  12178. Content: "",
  12179. Order: 0,
  12180. Code: "",
  12181. }
  12182. service.CreatedDicConfig(&dataconfig)
  12183. }
  12184. }
  12185. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  12186. for _, it := range costClassList {
  12187. if cost_classify == it.Name {
  12188. cost_classify_id = int64(it.Value)
  12189. }
  12190. }
  12191. project.CostClassify = cost_classify_id
  12192. executive_section := projectM["executive_section"].(string)
  12193. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  12194. err_log := models.ExportErrLog{
  12195. LogType: 6,
  12196. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12197. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  12198. Status: 1,
  12199. CreateTime: time.Now().Unix(),
  12200. UpdateTime: time.Now().Unix(),
  12201. ExportTime: time.Now().Unix(),
  12202. }
  12203. service.CreateExportErrLog(&err_log)
  12204. continue
  12205. }
  12206. if len(executive_section) != 0 {
  12207. //查找科室是否有内容
  12208. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  12209. if errcodedepart == gorm.ErrRecordNotFound {
  12210. department := models.XtHisDepartment{
  12211. Name: executive_section,
  12212. Status: 1,
  12213. UserOrgId: adminUser.CurrentOrgId,
  12214. CreatedTime: time.Now().Unix(),
  12215. }
  12216. service.CreateDePartment(&department)
  12217. }
  12218. }
  12219. var executive_section_id int64
  12220. departMentList, _ := service.GetAllDepartMent(orgId)
  12221. for _, it := range departMentList {
  12222. if executive_section == it.Name {
  12223. executive_section_id = it.ID
  12224. }
  12225. }
  12226. project.ExecutiveSection = executive_section_id
  12227. medical_coverage := projectM["medical_coverage"].(string)
  12228. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  12229. err_log := models.ExportErrLog{
  12230. LogType: 6,
  12231. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12232. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12233. Status: 1,
  12234. CreateTime: time.Now().Unix(),
  12235. UpdateTime: time.Now().Unix(),
  12236. ExportTime: time.Now().Unix(),
  12237. }
  12238. service.CreateExportErrLog(&err_log)
  12239. continue
  12240. }
  12241. var medicalCoverage = "医保等级"
  12242. var medical_coverage_id int64
  12243. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  12244. if len(medical_coverage) != 0 {
  12245. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  12246. if errormedicalcoverage == gorm.ErrRecordNotFound {
  12247. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  12248. dataconfig := models.DictDataconfig{
  12249. ParentId: medicalCoverageConfig.ID,
  12250. Module: "system",
  12251. OrgId: orgId,
  12252. Name: medical_coverage,
  12253. FieldName: "",
  12254. Value: medicalCoverageConfig.Value + 1,
  12255. CreatedTime: "",
  12256. UpdatedTime: "",
  12257. CreateUserId: adminUser.AdminUser.Id,
  12258. Status: 1,
  12259. Remark: "",
  12260. DeleteIdSystem: 0,
  12261. Title: "",
  12262. Content: "",
  12263. Order: 0,
  12264. Code: "",
  12265. }
  12266. service.CreatedDicConfig(&dataconfig)
  12267. }
  12268. }
  12269. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12270. for _, it := range medicalCoverageList {
  12271. if medical_coverage == it.Name {
  12272. medical_coverage_id = int64(it.Value)
  12273. }
  12274. }
  12275. project.MedicalCoverage = medical_coverage_id
  12276. pinyin := projectM["pinyin"].(string)
  12277. project.Pinyin = pinyin
  12278. wubi := projectM["wubi"].(string)
  12279. project.Wubi = wubi
  12280. statistical_classification := projectM["statistical_classification"].(string)
  12281. var statisticalClassification = "统计分类"
  12282. var statistical_classification_id int64
  12283. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12284. if len(statistical_classification) != 0 {
  12285. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12286. if classificationerrcodes == gorm.ErrRecordNotFound {
  12287. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12288. dataconfig := models.DictDataconfig{
  12289. ParentId: classiFication.ID,
  12290. Module: "system",
  12291. OrgId: orgId,
  12292. Name: statistical_classification,
  12293. FieldName: "",
  12294. Value: classiFicationConfig.Value + 1,
  12295. CreatedTime: "",
  12296. UpdatedTime: "",
  12297. CreateUserId: adminUser.AdminUser.Id,
  12298. Status: 1,
  12299. Remark: "",
  12300. DeleteIdSystem: 0,
  12301. Title: "",
  12302. Content: "",
  12303. Order: 0,
  12304. Code: "",
  12305. }
  12306. service.CreatedDicConfig(&dataconfig)
  12307. }
  12308. }
  12309. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12310. for _, it := range classiFicationList {
  12311. if statistical_classification == it.Name {
  12312. statistical_classification_id = int64(it.Value)
  12313. }
  12314. }
  12315. project.StatisticalClassification = statistical_classification_id
  12316. disease_directory := int64(projectM["disease_directory"].(float64))
  12317. project.DiseaseDirectory = disease_directory
  12318. is_record := int64(projectM["is_record"].(float64))
  12319. project.IsRecord = is_record
  12320. medical_code := projectM["medical_code"].(string)
  12321. project.MedicalCode = medical_code
  12322. tube_color := projectM["tube_color"].(string)
  12323. var tubeColor = "试管颜色"
  12324. var tube_color_id int64
  12325. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12326. if len(tube_color) != 0 {
  12327. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12328. if errcodetube == gorm.ErrRecordNotFound {
  12329. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12330. dataconfig := models.DictDataconfig{
  12331. ParentId: tubeColorConfig.ID,
  12332. Module: "system",
  12333. OrgId: orgId,
  12334. Name: tube_color,
  12335. FieldName: "",
  12336. Value: tubeConfig.Value + 1,
  12337. CreatedTime: "",
  12338. UpdatedTime: "",
  12339. CreateUserId: adminUser.AdminUser.Id,
  12340. Status: 1,
  12341. Remark: "",
  12342. DeleteIdSystem: 0,
  12343. Title: "",
  12344. Content: "",
  12345. Order: 0,
  12346. Code: "",
  12347. }
  12348. service.CreatedDicConfig(&dataconfig)
  12349. }
  12350. }
  12351. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12352. for _, it := range tubeColorList {
  12353. if tube_color == it.Name {
  12354. tube_color_id = int64(it.Value)
  12355. }
  12356. }
  12357. project.TubeColor = tube_color_id
  12358. single_dose := projectM["single_dose"].(string)
  12359. project.SingleDose = single_dose
  12360. execution_frequency := projectM["execution_frequency"].(string)
  12361. project.ExecutionFrequency = execution_frequency
  12362. delivery_way := projectM["delivery_way"].(string)
  12363. project.DeliveryWay = delivery_way
  12364. number_days := projectM["number_days"].(string)
  12365. project.NumberDays = number_days
  12366. total := projectM["total"].(string)
  12367. project.Total = total
  12368. medical_status := int64(projectM["medical_status"].(float64))
  12369. project.MedicalStatus = medical_status
  12370. category := int64(projectM["category"].(float64))
  12371. project.Category = category
  12372. specail_project := int64(projectM["specail_project"].(float64))
  12373. project.SpecailProject = specail_project
  12374. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12375. project.SocialSecurityDirectoryCode = social_security_directory_code
  12376. remark := projectM["remark"].(string)
  12377. project.Remark = remark
  12378. record_date := projectM["record_date"].(string)
  12379. timeLayout := "2006-01-02"
  12380. loc, _ := time.LoadLocation("Local")
  12381. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12382. project.RecordDate = theTime.Unix()
  12383. projectList = append(projectList, &project)
  12384. }
  12385. export_time := time.Now().Unix()
  12386. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12387. if len(projectList) > 0 {
  12388. for _, item := range projectList {
  12389. hans := item.ProjectName // 要转换的汉字字符串
  12390. // 创建一个拼音转换器
  12391. p := pinyin.NewArgs()
  12392. // 将汉字转为拼音
  12393. pinyinSlice := pinyin.Pinyin(hans, p)
  12394. // 输出拼音
  12395. fmt.Println("Pinyin:", pinyinSlice)
  12396. // 获取首字母
  12397. firstLetter := ""
  12398. for _, py := range pinyinSlice {
  12399. if len(py) > 0 {
  12400. firstLetter += string(py[0][0])
  12401. }
  12402. }
  12403. item.FirstLetter = firstLetter
  12404. project := models.HisProject{
  12405. ProjectName: item.ProjectName,
  12406. Price: item.Price,
  12407. Unit: item.Unit,
  12408. CostClassify: item.CostClassify,
  12409. ExecutiveSection: item.ExecutiveSection,
  12410. MedicalCoverage: item.MedicalCoverage,
  12411. UserOrgId: orgId,
  12412. Status: 1,
  12413. CreatedTime: time.Now().Unix(),
  12414. Pinyin: item.Pinyin,
  12415. Wubi: item.Wubi,
  12416. StatisticalClassification: item.StatisticalClassification,
  12417. DiseaseDirectory: item.DiseaseDirectory,
  12418. IsRecord: item.IsRecord,
  12419. MedicalCode: item.MedicalCode,
  12420. TubeColor: item.TubeColor,
  12421. SingleDose: item.SingleDose,
  12422. DeliveryWay: item.DeliveryWay,
  12423. NumberDays: item.NumberDays,
  12424. Total: item.Total,
  12425. Category: item.Category,
  12426. MedicalStatus: item.MedicalStatus,
  12427. SpecailProject: item.SpecailProject,
  12428. RecordDate: item.RecordDate,
  12429. Remark: item.Remark,
  12430. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12431. ExecutionFrequency: item.ExecutionFrequency,
  12432. FirstLetter: item.FirstLetter,
  12433. }
  12434. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12435. if errcodeproject == gorm.ErrRecordNotFound {
  12436. service.CreateProjectInfomation(&project)
  12437. } else if errcodeproject == nil {
  12438. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12439. }
  12440. log := models.ExportLog{
  12441. LogType: 6,
  12442. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12443. TotalNum: int64(len(total_goods)),
  12444. FailNum: int64(len(errLogs)),
  12445. SuccessNum: int64(len(projectList)),
  12446. CreateTime: time.Now().Unix(),
  12447. UpdateTime: time.Now().Unix(),
  12448. ExportTime: export_time,
  12449. Status: 1,
  12450. }
  12451. service.CreateExportLog(&log)
  12452. c.ServeSuccessJSON(map[string]interface{}{
  12453. "msg": "导入成功",
  12454. "total_num": len(total_goods),
  12455. "success_num": len(projectList),
  12456. "fail_num": int64(len(errLogs)),
  12457. })
  12458. }
  12459. } else {
  12460. log := models.ExportLog{
  12461. LogType: 6,
  12462. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12463. TotalNum: int64(len(total_goods)),
  12464. FailNum: int64(len(errLogs)),
  12465. SuccessNum: int64(len(projectList)),
  12466. CreateTime: time.Now().Unix(),
  12467. UpdateTime: time.Now().Unix(),
  12468. ExportTime: export_time,
  12469. Status: 1,
  12470. }
  12471. service.CreateExportLog(&log)
  12472. c.ServeSuccessJSON(map[string]interface{}{
  12473. "msg": "导入成功",
  12474. "total_num": len(total_goods),
  12475. "success_num": len(projectList),
  12476. "fail_num": int64(len(errLogs)),
  12477. })
  12478. }
  12479. }
  12480. //func (this *HisApiController) EditProjectInformation(){
  12481. //
  12482. // id, _ := this.GetInt64("id")
  12483. // project_team := this.GetString("project_team")
  12484. // price := this.GetString("price")
  12485. // price_float, _ := strconv.ParseFloat(price, 64)
  12486. // pinyin := this.GetString("pinyin")
  12487. // wubi := this.GetString("wubi")
  12488. // tube_color, _ := this.GetInt64("tube_color")
  12489. // team_type, _ := this.GetInt64("team_type")
  12490. // remark := this.GetString("remark")
  12491. // ids := this.GetString("ids")
  12492. // item_id := this.GetString("item_id")
  12493. // projectTeam := models.XtHisProjectTeam{
  12494. // ProjectTeam: project_team,
  12495. // Price: price_float,
  12496. // Pinyin: pinyin,
  12497. // Wubi: wubi,
  12498. // TubeColor: tube_color,
  12499. // TeamType: team_type,
  12500. // Remark: remark,
  12501. // ProjectId: ids,
  12502. // ItemId: item_id,
  12503. // }
  12504. //
  12505. //
  12506. // dataBody := make(map[string]interface{}, 0)
  12507. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12508. // if err != nil {
  12509. // utils.ErrorLog(err.Error())
  12510. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12511. // return
  12512. // }
  12513. //
  12514. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12515. //
  12516. //
  12517. // if err != nil {
  12518. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12519. // return
  12520. // }
  12521. //
  12522. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12523. // infos, _ := dataBody["info"].([]interface{})
  12524. // if len(infos) > 0 {
  12525. // var ids []string
  12526. //
  12527. // for _, item := range infos {
  12528. // items := item.(map[string]interface{})
  12529. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12530. // utils.ErrorLog("id")
  12531. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12532. // return
  12533. // }
  12534. // id := int64(items["id"].(float64))
  12535. //
  12536. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12537. // utils.ErrorLog("type")
  12538. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12539. // return
  12540. // }
  12541. // types := int64(items["type"].(float64))
  12542. //
  12543. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12544. // utils.ErrorLog("number")
  12545. // }
  12546. //
  12547. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12548. //
  12549. // projectList := models.XtHisProjectList{
  12550. // Number: number,
  12551. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12552. // ProjectId: id,
  12553. // Status: 1,
  12554. // CreatedTime: time.Now().Unix(),
  12555. // UpdatedTime: time.Now().Unix(),
  12556. // TeamId: projectTeam.ID,
  12557. // Type: types,
  12558. // }
  12559. // list := projectList
  12560. //
  12561. // service.CreateProjectList(&list)
  12562. //
  12563. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12564. //
  12565. // }
  12566. // ids_str := strings.Join(ids, ",")
  12567. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12568. // service.SaveProjectTeam(&projectTeam)
  12569. // this.ServeSuccessJSON(map[string]interface{}{
  12570. // "projectTeam": projectTeam,
  12571. // })
  12572. // }
  12573. // }
  12574. //}
  12575. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12576. name := c.GetString("name")
  12577. mode_id, _ := c.GetInt64("mode", 0)
  12578. types, _ := c.GetInt64("type", 0)
  12579. patient_id, _ := c.GetInt64("patient_id", 0)
  12580. types = 1
  12581. adminInfo := c.GetAdminUserInfo()
  12582. template := &models.HisPrescriptionTemplate{
  12583. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12584. PatientId: patient_id,
  12585. Type: types,
  12586. Status: 1,
  12587. Ctime: time.Now().Unix(),
  12588. Mtime: time.Now().Unix(),
  12589. Name: name,
  12590. Mode: mode_id,
  12591. }
  12592. dataBody := make(map[string]interface{}, 0)
  12593. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12594. if err != nil {
  12595. utils.ErrorLog(err.Error())
  12596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12597. return
  12598. }
  12599. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12600. //如果已经存在记录则删除处方
  12601. if template_one.ID > 0 {
  12602. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12603. var ids []int64
  12604. var org_id int64
  12605. for _, item := range ps {
  12606. org_id = c.GetAdminUserInfo().CurrentOrgId
  12607. ids = append(ids, item.ID)
  12608. }
  12609. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12610. if err2 == nil {
  12611. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12612. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12613. if len(prescriptions) > 0 {
  12614. for _, item := range prescriptions {
  12615. items := item.(map[string]interface{})
  12616. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12617. utils.ErrorLog("type")
  12618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12619. return
  12620. }
  12621. types := int64(items["type"].(float64))
  12622. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12623. utils.ErrorLog("med_type")
  12624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12625. return
  12626. }
  12627. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12628. ctime := time.Now().Unix()
  12629. prescription := &models.HisPrescriptionInfoTemplate{
  12630. PatientId: patient_id,
  12631. UserOrgId: adminInfo.CurrentOrgId,
  12632. Ctime: ctime,
  12633. Mtime: ctime,
  12634. Type: types,
  12635. Modifier: adminInfo.AdminUser.Id,
  12636. Creator: adminInfo.AdminUser.Id,
  12637. Status: 1,
  12638. PTemplateId: template_one.ID,
  12639. MedType: med_type,
  12640. }
  12641. service.CreateHisPrescriptionInfoTemplate(prescription)
  12642. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12643. advices := items["advices"].([]interface{})
  12644. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12645. ctime := time.Now().Unix()
  12646. mtime := ctime
  12647. if len(advices) > 0 {
  12648. for _, advice := range advices {
  12649. var s models.HisPrescriptionAdviceTemplate
  12650. s.PrescriptionId = prescription.ID
  12651. s.AdviceType = 2
  12652. s.StopState = 2
  12653. s.ExecutionState = 2
  12654. s.Status = 1
  12655. s.UserOrgId = adminInfo.CurrentOrgId
  12656. s.CreatedTime = ctime
  12657. s.UpdatedTime = mtime
  12658. s.PatientId = patient_id
  12659. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12660. if errcode > 0 {
  12661. c.ServeFailJSONWithSGJErrorCode(errcode)
  12662. return
  12663. }
  12664. service.CreateHisPrescriptionAdviceTemplate(&s)
  12665. }
  12666. }
  12667. }
  12668. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12669. projects := items["project"].([]interface{})
  12670. if len(projects) > 0 {
  12671. for _, project := range projects {
  12672. var p models.HisPrescriptionProjectTemplate
  12673. p.PrescriptionId = prescription.ID
  12674. p.Ctime = time.Now().Unix()
  12675. p.Mtime = time.Now().Unix()
  12676. p.PatientId = patient_id
  12677. p.UserOrgId = adminInfo.CurrentOrgId
  12678. p.Status = 1
  12679. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12680. if errcode > 0 {
  12681. c.ServeFailJSONWithSGJErrorCode(errcode)
  12682. return
  12683. }
  12684. service.CreateHisPrescriptionProjectTemplate(&p)
  12685. }
  12686. }
  12687. }
  12688. }
  12689. c.ServeSuccessJSON(map[string]interface{}{
  12690. "msg": "创建成功",
  12691. })
  12692. }
  12693. }
  12694. } else {
  12695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12696. return
  12697. }
  12698. } else {
  12699. err3 := service.CreateHisPrescriptionTemplate(template)
  12700. if err3 == nil {
  12701. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12702. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12703. if len(prescriptions) > 0 {
  12704. for _, item := range prescriptions {
  12705. items := item.(map[string]interface{})
  12706. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12707. utils.ErrorLog("type")
  12708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12709. return
  12710. }
  12711. types := int64(items["type"].(float64))
  12712. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12713. utils.ErrorLog("med_type")
  12714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12715. return
  12716. }
  12717. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12718. ctime := time.Now().Unix()
  12719. prescription := &models.HisPrescriptionInfoTemplate{
  12720. PatientId: patient_id,
  12721. UserOrgId: adminInfo.CurrentOrgId,
  12722. Ctime: ctime,
  12723. Mtime: ctime,
  12724. Type: types,
  12725. Modifier: adminInfo.AdminUser.Id,
  12726. Creator: adminInfo.AdminUser.Id,
  12727. Status: 1,
  12728. PTemplateId: template.ID,
  12729. MedType: med_type,
  12730. }
  12731. service.CreateHisPrescriptionInfoTemplate(prescription)
  12732. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12733. advices := items["advices"].([]interface{})
  12734. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12735. ctime := time.Now().Unix()
  12736. mtime := ctime
  12737. if len(advices) > 0 {
  12738. for _, advice := range advices {
  12739. var s models.HisPrescriptionAdviceTemplate
  12740. s.PrescriptionId = prescription.ID
  12741. s.AdviceType = 2
  12742. s.StopState = 2
  12743. s.ExecutionState = 2
  12744. s.Status = 1
  12745. s.UserOrgId = adminInfo.CurrentOrgId
  12746. s.CreatedTime = ctime
  12747. s.UpdatedTime = mtime
  12748. s.PatientId = patient_id
  12749. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12750. if errcode > 0 {
  12751. c.ServeFailJSONWithSGJErrorCode(errcode)
  12752. return
  12753. }
  12754. service.CreateHisPrescriptionAdviceTemplate(&s)
  12755. }
  12756. }
  12757. }
  12758. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12759. projects := items["project"].([]interface{})
  12760. if len(projects) > 0 {
  12761. for _, project := range projects {
  12762. var p models.HisPrescriptionProjectTemplate
  12763. p.PrescriptionId = prescription.ID
  12764. p.Ctime = time.Now().Unix()
  12765. p.Mtime = time.Now().Unix()
  12766. p.PatientId = patient_id
  12767. p.UserOrgId = adminInfo.CurrentOrgId
  12768. p.Status = 1
  12769. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12770. if errcode > 0 {
  12771. c.ServeFailJSONWithSGJErrorCode(errcode)
  12772. return
  12773. }
  12774. service.CreateHisPrescriptionProjectTemplate(&p)
  12775. }
  12776. }
  12777. }
  12778. }
  12779. c.ServeSuccessJSON(map[string]interface{}{
  12780. "msg": "创建成功",
  12781. })
  12782. }
  12783. }
  12784. } else {
  12785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12786. return
  12787. }
  12788. }
  12789. }
  12790. func (c *HisApiController) PreSettle() {
  12791. id, _ := c.GetInt64("id")
  12792. record_time := c.GetString("record_time")
  12793. his_patient_id, _ := c.GetInt64("his_patient_id")
  12794. timeLayout := "2006-01-02"
  12795. loc, _ := time.LoadLocation("Local")
  12796. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12797. diagnosis_id := c.GetString("diagnosis")
  12798. sick_type, _ := c.GetInt64("sick_type")
  12799. reg_type, _ := c.GetInt64("p_type")
  12800. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12801. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12802. if err != nil {
  12803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12804. return
  12805. }
  12806. recordDateTime := theTime.Unix()
  12807. adminUser := c.GetAdminUserInfo()
  12808. var prescriptions []*models.HisPrescription
  12809. var start_time int64
  12810. var end_time int64
  12811. ids_str := c.GetString("ids")
  12812. ids_arr := strings.Split(ids_str, ",")
  12813. fmt.Println(reg_type)
  12814. if settle_accounts_type == 1 { //日结
  12815. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12816. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12817. } else {
  12818. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12819. }
  12820. fmt.Println(prescriptions)
  12821. } else { //月结
  12822. start_time_str := c.GetString("start_time")
  12823. end_time_str := c.GetString("end_time")
  12824. timeLayout := "2006-01-02"
  12825. loc, _ := time.LoadLocation("Local")
  12826. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12827. if err != nil {
  12828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12829. return
  12830. }
  12831. recordStartTime := theStartTime.Unix()
  12832. start_time = recordStartTime
  12833. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12834. if err != nil {
  12835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12836. return
  12837. }
  12838. recordEndTime := theEndTime.Unix()
  12839. end_time = recordEndTime
  12840. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12841. }
  12842. if reg_type == 1111 || reg_type == 1112 {
  12843. reg_type = 11
  12844. }
  12845. timestamp := time.Now().Unix()
  12846. tempTime := time.Unix(timestamp, 0)
  12847. timeFormat := tempTime.Format("20060102150405")
  12848. chrgBchno := rand.Intn(100000) + 10000
  12849. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12850. strconv.FormatInt(his.PatientId, 10)
  12851. var ids []int64
  12852. for _, item := range prescriptions {
  12853. ids = append(ids, item.ID)
  12854. }
  12855. fmt.Println(ids)
  12856. var total float64
  12857. for _, item := range prescriptions {
  12858. fmt.Println(item)
  12859. if item.Type == 1 { //药品
  12860. for _, subItem := range item.HisDoctorAdviceInfo {
  12861. total = total + (subItem.Price * subItem.PrescribingNumber)
  12862. }
  12863. }
  12864. if item.Type == 2 { //项目
  12865. for _, subItem := range item.HisPrescriptionProject {
  12866. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12867. total = total + (subItem.Price * cnt)
  12868. }
  12869. }
  12870. for _, subItem := range item.HisAdditionalCharge {
  12871. total = total + (subItem.Price * float64(subItem.Count))
  12872. }
  12873. }
  12874. allTotal := fmt.Sprintf("%.2f", total)
  12875. totals, _ := strconv.ParseFloat(allTotal, 64)
  12876. order := &models.HisOrder{
  12877. UserOrgId: adminUser.CurrentOrgId,
  12878. HisPatientId: his.ID,
  12879. PatientId: id,
  12880. SettleAccountsDate: recordDateTime,
  12881. Ctime: time.Now().Unix(),
  12882. Mtime: time.Now().Unix(),
  12883. Status: 1,
  12884. OrderStatus: 1,
  12885. MdtrtId: his.Number,
  12886. Number: chrg_bchno,
  12887. MedfeeSumamt: totals,
  12888. SettleEndTime: end_time,
  12889. SettleStartTime: start_time,
  12890. SettleType: settle_accounts_type,
  12891. PsnPartAmt: totals,
  12892. PsnCashPay: totals,
  12893. PType: 2,
  12894. IsPre: 1,
  12895. MedType: strconv.Itoa(int(reg_type)),
  12896. Diagnosis: diagnosis_id,
  12897. }
  12898. err = service.CreateOrder(order)
  12899. if err != nil {
  12900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12901. return
  12902. }
  12903. var customs []*Custom
  12904. for _, item := range prescriptions {
  12905. fmt.Println(item.Type)
  12906. if item.Type == 1 { //药品
  12907. for _, subItem := range item.HisDoctorAdviceInfo {
  12908. cus := &Custom{
  12909. AdviceId: subItem.ID,
  12910. ProjectId: 0,
  12911. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12912. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12913. FeedetlSn: subItem.FeedetlSn,
  12914. Price: fmt.Sprintf("%.2f", subItem.Price),
  12915. MedListCodg: subItem.MedListCodg,
  12916. Type: 1,
  12917. }
  12918. customs = append(customs, cus)
  12919. }
  12920. }
  12921. if item.Type == 2 { //项目
  12922. for _, subItem := range item.HisPrescriptionProject {
  12923. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12924. cus := &Custom{
  12925. AdviceId: 0,
  12926. ProjectId: subItem.ID,
  12927. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12928. Cut: fmt.Sprintf("%.2f", cnt),
  12929. FeedetlSn: subItem.FeedetlSn,
  12930. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12931. MedListCodg: subItem.MedListCodg,
  12932. Type: 2,
  12933. }
  12934. customs = append(customs, cus)
  12935. }
  12936. }
  12937. for _, item := range item.HisAdditionalCharge {
  12938. cus := &Custom{
  12939. ItemId: item.ID,
  12940. AdviceId: 0,
  12941. ProjectId: 0,
  12942. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12943. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12944. FeedetlSn: item.FeedetlSn,
  12945. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12946. MedListCodg: item.XtHisAddtionConfig.Code,
  12947. Type: 3,
  12948. }
  12949. customs = append(customs, cus)
  12950. }
  12951. }
  12952. fmt.Println(customs)
  12953. for _, item := range customs {
  12954. var advice_id int64 = 0
  12955. var project_id int64 = 0
  12956. var item_id int64 = 0
  12957. var types int64 = 0
  12958. if item.Type == 1 {
  12959. advice_id = item.AdviceId
  12960. project_id = 0
  12961. item_id = 0
  12962. } else if item.Type == 2 {
  12963. advice_id = 0
  12964. item_id = 0
  12965. project_id = item.ProjectId
  12966. } else if item.Type == 3 {
  12967. advice_id = 0
  12968. item_id = item.ItemId
  12969. project_id = 0
  12970. }
  12971. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12972. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12973. pric, _ := strconv.ParseFloat(item.Price, 32)
  12974. info := &models.HisOrderInfo{
  12975. OrderNumber: order.Number,
  12976. UploadDate: time.Now().Unix(),
  12977. AdviceId: advice_id,
  12978. DetItemFeeSumamt: detItemFeeSumamt,
  12979. Cnt: cut,
  12980. Pric: pric,
  12981. PatientId: id,
  12982. Status: 1,
  12983. Mtime: time.Now().Unix(),
  12984. Ctime: time.Now().Unix(),
  12985. UserOrgId: adminUser.CurrentOrgId,
  12986. HisPatientId: his.ID,
  12987. OrderId: order.ID,
  12988. ProjectId: project_id,
  12989. Type: types,
  12990. ItemId: item_id,
  12991. }
  12992. service.CreateOrderInfo(info)
  12993. }
  12994. his.SickType = sick_type
  12995. service.UpdataHisPateint(&his)
  12996. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12997. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12998. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12999. if err == nil {
  13000. c.ServeSuccessJSON(map[string]interface{}{
  13001. "msg": "结算成功",
  13002. })
  13003. }
  13004. }
  13005. type CustomOrderInfo struct {
  13006. Name string
  13007. Spec string
  13008. Unit string
  13009. Count float64
  13010. Price float64
  13011. Total float64
  13012. }
  13013. func (c *HisApiController) GetPrivateExpensesInfo() {
  13014. order_id, _ := c.GetInt64("id", 0)
  13015. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  13016. order, _ := service.GetHisOrderByID(order_id)
  13017. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  13018. if order.ID == 0 {
  13019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  13020. return
  13021. }
  13022. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  13023. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  13024. org_id := c.GetAdminUserInfo().CurrentOrgId
  13025. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  13026. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  13027. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  13028. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  13029. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  13030. //var orderInfos_four []*models.HisOrderInfoTwo
  13031. //for _, item := range orderInfos_three {
  13032. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  13033. // item.HisPrescriptionProject.IsCheckTeam = 1
  13034. // orderInfos_four = append(orderInfos_four, item)
  13035. //
  13036. // }
  13037. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  13038. // item.HisPrescriptionProject.IsCheckTeam = 2
  13039. // orderInfos_two = append(orderInfos_two, item)
  13040. // }
  13041. //}
  13042. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  13043. //var cus_slice []CustomOrderInfo
  13044. //for _, item := range new_order_info {
  13045. // var cus CustomOrderInfo
  13046. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  13047. // cus.Unit = ""
  13048. // cus.Spec = ""
  13049. // var total float64
  13050. // for _, subItem := range orderInfos_four {
  13051. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  13052. // total = total + subItem.DetItemFeeSumamt
  13053. // fmt.Println(subItem.DetItemFeeSumamt)
  13054. // }
  13055. // }
  13056. // cus.Count = 1
  13057. // cus.Total = total
  13058. // cus_slice = append(cus_slice, cus)
  13059. //}
  13060. orderInfos = append(orderInfos, orderInfos_two...)
  13061. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  13062. //orderInfos = append(orderInfos, orderInfos_three...)
  13063. //}/**/
  13064. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  13065. c.ServeSuccessJSON(map[string]interface{}{
  13066. "order": order,
  13067. "order_info": orderInfos,
  13068. "patient": patient,
  13069. "admin_info": adminInfo,
  13070. "his": his,
  13071. "current_admin": role,
  13072. "org_config": miConfig,
  13073. //"new_order_info": cus_slice,
  13074. })
  13075. }
  13076. func (this *HisApiController) ChangeMedType() {
  13077. med_type := this.GetString("med_type")
  13078. old_med_type := this.GetString("old_med_type")
  13079. ids := this.GetString("ids")
  13080. settle_type, _ := this.GetInt64("settle_type")
  13081. start_time := this.GetString("start_time")
  13082. end_time := this.GetString("end_time")
  13083. ids_arr := strings.Split(ids, ",")
  13084. if settle_type == 1 { //日结
  13085. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  13086. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  13087. prescription.MedType = med_type
  13088. err := service.SaveHisPrescriptionTwo(&prescription)
  13089. if err == nil {
  13090. this.ServeSuccessJSON(map[string]interface{}{
  13091. "msg": "修改成功",
  13092. })
  13093. } else {
  13094. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13095. return
  13096. }
  13097. } else if settle_type == 2 {
  13098. timeLayout := "2006-01-02"
  13099. loc, _ := time.LoadLocation("Local")
  13100. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13101. if err != nil {
  13102. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13103. return
  13104. }
  13105. recordStartTime := theStartTime.Unix()
  13106. start_time_timestamp := recordStartTime
  13107. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  13108. if err != nil {
  13109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13110. return
  13111. }
  13112. recordEndTime := theEndTime.Unix()
  13113. end_time_timestamp := recordEndTime
  13114. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  13115. if updateErr == nil {
  13116. this.ServeSuccessJSON(map[string]interface{}{
  13117. "msg": "修改成功",
  13118. })
  13119. } else {
  13120. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  13121. return
  13122. }
  13123. }
  13124. }
  13125. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  13126. patient_id, _ := c.GetInt64("patient_id")
  13127. his_patient_id, _ := c.GetInt64("his_patient_id")
  13128. record_date := c.GetString("record_date")
  13129. start_time := c.GetString("start_time")
  13130. end_time := c.GetString("end_time")
  13131. order_status, _ := c.GetInt64("type", 0)
  13132. p_type, _ := c.GetInt64("p_type", 0)
  13133. order_id, _ := c.GetInt64("order_id", 0)
  13134. timeLayout := "2006-01-02"
  13135. loc, _ := time.LoadLocation("Local")
  13136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13137. if err != nil {
  13138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13139. return
  13140. }
  13141. recordDateTime := theTime.Unix()
  13142. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13143. if err != nil {
  13144. }
  13145. startRecordDateTime := startTime.Unix()
  13146. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13147. if err != nil {
  13148. }
  13149. endRecordDateTime := endTime.Unix()
  13150. admin := c.GetAdminUserInfo()
  13151. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  13152. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13153. order, _ := service.GetHisOrderByID(order_id)
  13154. var monthPrescriptions []*models.HisPrescription
  13155. if order_status == 1 || order_status == 0 {
  13156. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13157. } else if order_status == 2 {
  13158. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  13159. }
  13160. var settle_total float64
  13161. for _, item := range monthPrescriptions {
  13162. if len(item.HisPrescriptionProject) > 0 {
  13163. for _, subItem := range item.HisPrescriptionProject {
  13164. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13165. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13166. settle_total = settle_total + total
  13167. }
  13168. }
  13169. if len(item.HisDoctorAdviceInfo) > 0 {
  13170. for _, subItem := range item.HisDoctorAdviceInfo {
  13171. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13172. settle_total = settle_total + total
  13173. }
  13174. }
  13175. }
  13176. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13177. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13178. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13179. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13180. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13181. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13182. //获取所有科室信息
  13183. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13184. var dia string
  13185. for _, item := range month_p_info {
  13186. if len(dia) == 0 {
  13187. dia = item.Diagnosis
  13188. } else {
  13189. dia = dia + "," + item.Diagnosis
  13190. }
  13191. }
  13192. dia_arr := removeDuplicates(strings.Split(dia, ","))
  13193. dia_arr = removeEmptyStrings(dia_arr)
  13194. c.ServeSuccessJSON(map[string]interface{}{
  13195. "his_info": his_patient_info,
  13196. "xt_info": xt_patient_info,
  13197. "case_history": case_history,
  13198. "info": patientPrescriptionInfo,
  13199. "last_info": lastPatientPrescriptionInfo,
  13200. "month_prescriptions": monthPrescriptions,
  13201. "order": order,
  13202. "doctors": doctors,
  13203. "department": department,
  13204. "settle_total": settle_total,
  13205. "dia_arr": dia_arr,
  13206. })
  13207. return
  13208. }
  13209. func removeEmptyStrings(input []string) []string {
  13210. var output []string
  13211. for _, s := range input {
  13212. if s != "" {
  13213. output = append(output, s)
  13214. }
  13215. }
  13216. return output
  13217. }
  13218. func removeDuplicates(input []string) []string {
  13219. seen := make(map[string]bool)
  13220. output := []string{}
  13221. for _, s := range input {
  13222. if _, exists := seen[s]; !exists {
  13223. seen[s] = true
  13224. output = append(output, s)
  13225. }
  13226. }
  13227. return output
  13228. }
  13229. func (c *HisApiController) GetHisMonthPatientInfo() {
  13230. patient_id, _ := c.GetInt64("patient_id")
  13231. his_patient_id, _ := c.GetInt64("his_patient_id")
  13232. record_date := c.GetString("record_date")
  13233. number := c.GetString("number")
  13234. start_time := c.GetString("start_time")
  13235. end_time := c.GetString("end_time")
  13236. p_type, _ := c.GetInt64("p_type")
  13237. timeLayout := "2006-01-02"
  13238. loc, _ := time.LoadLocation("Local")
  13239. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13240. if err != nil {
  13241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13242. return
  13243. }
  13244. recordDateTime := theTime.Unix()
  13245. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13246. if err != nil {
  13247. }
  13248. startRecordDateTime := startTime.Unix()
  13249. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13250. if err != nil {
  13251. }
  13252. endRecordDateTime := endTime.Unix()
  13253. admin := c.GetAdminUserInfo()
  13254. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  13255. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13256. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  13257. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13258. var settle_total float64
  13259. for _, item := range monthPrescriptions {
  13260. if len(item.HisPrescriptionProject) > 0 {
  13261. for _, subItem := range item.HisPrescriptionProject {
  13262. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13263. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13264. settle_total = settle_total + total
  13265. }
  13266. }
  13267. if len(item.HisDoctorAdviceInfo) > 0 {
  13268. for _, subItem := range item.HisDoctorAdviceInfo {
  13269. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13270. settle_total = settle_total + total
  13271. }
  13272. }
  13273. }
  13274. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13275. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13276. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13277. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13278. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13279. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13280. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13281. //获取所有科室信息
  13282. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13283. c.ServeSuccessJSON(map[string]interface{}{
  13284. "his_info": his_patient_info,
  13285. "xt_info": xt_patient_info,
  13286. "case_history": case_history,
  13287. "info": patientPrescriptionInfo,
  13288. "month_prescriptions": monthPrescriptions,
  13289. "order": order,
  13290. "doctors": doctors,
  13291. "department": department,
  13292. "count": count,
  13293. "drugStockConfig": drugStockConfig,
  13294. "last_info": lastPatientPrescriptionInfo,
  13295. "settle_total": settle_total,
  13296. })
  13297. return
  13298. }
  13299. func (c *HisApiController) GetAllOrder() {
  13300. org_id := c.GetAdminUserInfo().CurrentOrgId
  13301. orders, _ := service.GetNewHisOrderList(org_id)
  13302. c.ServeSuccessJSON(map[string]interface{}{
  13303. "order": orders,
  13304. })
  13305. return
  13306. }
  13307. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13308. newArr = make([]*models.HisOrderInfoTwo, 0)
  13309. for i := 0; i < len(arr); i++ {
  13310. repeat := false
  13311. for j := i + 1; j < len(arr); j++ {
  13312. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13313. repeat = true
  13314. break
  13315. }
  13316. }
  13317. if !repeat {
  13318. newArr = append(newArr, arr[i])
  13319. }
  13320. }
  13321. return
  13322. }
  13323. // 修改处方退库操作 参数传修改之前的处方数据
  13324. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13325. if advice.ExecutionState == 1 {
  13326. //查询该病人该药品是否有库存记录
  13327. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13328. if errcode == gorm.ErrRecordNotFound {
  13329. } else {
  13330. //退库
  13331. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13332. if advice.PrescribingNumberUnit == drug.MinUnit {
  13333. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13334. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13335. //退库
  13336. warehouseInfo := models.DrugWarehouseInfo{
  13337. StockMinNumber: prescribingNumber,
  13338. }
  13339. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13340. operation_time := time.Now().Unix()
  13341. creater := advice.AdviceDoctor
  13342. ctime := time.Now().Unix()
  13343. timeStr := time.Now().Format("2006-01-02")
  13344. timeArr := strings.Split(timeStr, "-")
  13345. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13346. total = total + 1
  13347. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13348. cancelStock := models.DrugCancelStock{
  13349. OrderNumber: orderNumber,
  13350. OperaTime: operation_time,
  13351. OrgId: advice.UserOrgId,
  13352. Creater: creater,
  13353. Ctime: ctime,
  13354. Status: 1,
  13355. ReturnTime: advice.AdviceDate,
  13356. Dealer: info.Dealer,
  13357. Manufacturer: info.Manufacturer,
  13358. Type: 1,
  13359. }
  13360. service.AddSigleDrugCancelStock(&cancelStock)
  13361. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13362. dealer, _ := service.GetDealerById(info.Dealer)
  13363. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13364. cancelStockInfo := models.DrugCancelStockInfo{
  13365. OrderNumber: cancelInfo.OrderNumber,
  13366. CancelStockId: cancelInfo.ID,
  13367. DrugId: info.DrugId,
  13368. Count: info.Count,
  13369. Status: 1,
  13370. Ctime: ctime,
  13371. OrgId: advice.UserOrgId,
  13372. Type: 1,
  13373. Manufacturer: manufactureName.ManufacturerName,
  13374. Dealer: dealer.DealerName,
  13375. Total: 0,
  13376. RetailPrice: info.RetailPrice,
  13377. RetailTotalPrice: info.RetailTotalPrice,
  13378. Price: info.Price,
  13379. RegisterAccount: "",
  13380. Remark: info.Remark,
  13381. BatchNumber: info.BatchNumber,
  13382. MaxUnit: info.CountUnit,
  13383. ProductDate: info.ProductDate,
  13384. ExpiryDate: info.ExpiryDate,
  13385. BatchNumberId: info.WarehouseInfoId,
  13386. }
  13387. flow := models.DrugFlow{
  13388. WarehousingId: 0,
  13389. DrugId: info.DrugId,
  13390. Number: "",
  13391. BatchNumber: info.BatchNumber,
  13392. Count: info.Count,
  13393. UserOrgId: advice.UserOrgId,
  13394. PatientId: 0,
  13395. SystemTime: ctime,
  13396. ConsumableType: 4,
  13397. IsSys: 0,
  13398. WarehousingOrder: "",
  13399. WarehouseOutId: 0,
  13400. WarehouseOutOrderNumber: "",
  13401. IsEdit: 0,
  13402. CancelStockId: cancelStock.ID,
  13403. CancelOrderNumber: cancelStock.OrderNumber,
  13404. Manufacturer: info.Manufacturer,
  13405. Dealer: info.Dealer,
  13406. Creator: advice.UserOrgId,
  13407. UpdateCreator: 0,
  13408. Status: 1,
  13409. Ctime: time.Now().Unix(),
  13410. Mtime: 0,
  13411. Price: info.Price,
  13412. WarehousingDetailId: 0,
  13413. WarehouseOutDetailId: 0,
  13414. CancelOutDetailId: 0,
  13415. ExpireDate: info.ExpiryDate,
  13416. ProductDate: info.ProductDate,
  13417. MaxUnit: info.CountUnit,
  13418. MinUnit: "",
  13419. }
  13420. service.CreatedCancelStock(cancelStockInfo)
  13421. service.CreateDrugFlowOne(flow)
  13422. } else {
  13423. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13424. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13425. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13426. warehouseInfo := models.DrugWarehouseInfo{
  13427. StockMinNumber: prescribingNumber,
  13428. }
  13429. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13430. }
  13431. operation_time := time.Now().Unix()
  13432. creater := advice.AdviceDoctor
  13433. ctime := time.Now().Unix()
  13434. timeStr := time.Now().Format("2006-01-02")
  13435. timeArr := strings.Split(timeStr, "-")
  13436. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13437. total = total + 1
  13438. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13439. cancelStock := models.DrugCancelStock{
  13440. OrderNumber: orderNumber,
  13441. OperaTime: operation_time,
  13442. OrgId: advice.UserOrgId,
  13443. Creater: creater,
  13444. Ctime: ctime,
  13445. Status: 1,
  13446. ReturnTime: advice.AdviceDate,
  13447. Dealer: info.Dealer,
  13448. Manufacturer: info.Manufacturer,
  13449. Type: 1,
  13450. }
  13451. service.AddSigleDrugCancelStock(&cancelStock)
  13452. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13453. dealer, _ := service.GetDealerById(info.Dealer)
  13454. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13455. cancelStockInfo := models.DrugCancelStockInfo{
  13456. OrderNumber: cancelInfo.OrderNumber,
  13457. CancelStockId: cancelInfo.ID,
  13458. DrugId: info.DrugId,
  13459. Count: info.Count,
  13460. Status: 1,
  13461. Ctime: ctime,
  13462. OrgId: advice.UserOrgId,
  13463. Type: 1,
  13464. Manufacturer: manufactureName.ManufacturerName,
  13465. Dealer: dealer.DealerName,
  13466. Total: 0,
  13467. RetailPrice: info.RetailPrice,
  13468. RetailTotalPrice: info.RetailTotalPrice,
  13469. Price: info.Price,
  13470. RegisterAccount: "",
  13471. Remark: info.Remark,
  13472. BatchNumber: info.BatchNumber,
  13473. MaxUnit: info.CountUnit,
  13474. ProductDate: info.ProductDate,
  13475. ExpiryDate: info.ExpiryDate,
  13476. BatchNumberId: info.WarehouseInfoId,
  13477. }
  13478. flow := models.DrugFlow{
  13479. WarehousingId: 0,
  13480. DrugId: info.DrugId,
  13481. Number: "",
  13482. BatchNumber: info.BatchNumber,
  13483. Count: info.Count,
  13484. UserOrgId: advice.UserOrgId,
  13485. PatientId: 0,
  13486. SystemTime: ctime,
  13487. ConsumableType: 4,
  13488. IsSys: 0,
  13489. WarehousingOrder: "",
  13490. WarehouseOutId: 0,
  13491. WarehouseOutOrderNumber: "",
  13492. IsEdit: 0,
  13493. CancelStockId: cancelStock.ID,
  13494. CancelOrderNumber: cancelStock.OrderNumber,
  13495. Manufacturer: info.Manufacturer,
  13496. Dealer: info.Dealer,
  13497. Creator: advice.AdviceDoctor,
  13498. UpdateCreator: 0,
  13499. Status: 1,
  13500. Ctime: time.Now().Unix(),
  13501. Mtime: 0,
  13502. Price: info.Price,
  13503. WarehousingDetailId: 0,
  13504. WarehouseOutDetailId: 0,
  13505. CancelOutDetailId: 0,
  13506. ExpireDate: info.ExpiryDate,
  13507. ProductDate: info.ProductDate,
  13508. MaxUnit: info.CountUnit,
  13509. MinUnit: "",
  13510. }
  13511. service.CreatedCancelStock(cancelStockInfo)
  13512. service.CreateDrugFlowOne(flow)
  13513. }
  13514. }
  13515. }
  13516. return err
  13517. }
  13518. func (this *HisApiController) DeleteNCDS() {
  13519. id, _ := this.GetInt64("id", 0)
  13520. if id > 0 {
  13521. service.DeletePsnNCDSRecordById(id)
  13522. this.ServeSuccessJSON(map[string]interface{}{
  13523. "msg": "删除成功",
  13524. })
  13525. } else {
  13526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13527. return
  13528. }
  13529. }
  13530. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13531. id, _ := c.GetInt64("id")
  13532. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13533. c.ServeSuccessJSON(map[string]interface{}{
  13534. "advice": advice,
  13535. })
  13536. return
  13537. }
  13538. func (c *HisApiController) GetHisMonthChargePatientList() {
  13539. record_date := c.GetString("record_date")
  13540. start_time := c.GetString("start_time")
  13541. end_time := c.GetString("end_time")
  13542. timeLayout := "2006-01-02"
  13543. loc, _ := time.LoadLocation("Local")
  13544. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13545. if err != nil {
  13546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13547. return
  13548. }
  13549. if err != nil {
  13550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13551. return
  13552. }
  13553. recordDateTime := theTime.Unix()
  13554. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13555. if err != nil {
  13556. }
  13557. startRecordDateTime := startTime.Unix()
  13558. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13559. if err != nil {
  13560. }
  13561. endRecordDateTime := endTime.Unix()
  13562. adminInfo := c.GetAdminUserInfo()
  13563. var tempMonthChargePatients []*service.MonthChargePatients
  13564. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13565. for _, item := range tempPatients {
  13566. //过滤没有处方的
  13567. if len(item.HisPrescription) == 0 {
  13568. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13569. }
  13570. }
  13571. c.ServeSuccessJSON(map[string]interface{}{
  13572. "list": tempMonthChargePatients,
  13573. })
  13574. }
  13575. // PrescriptionDifference 医嘱数量差值结构体
  13576. type PrescriptionDrugDifference struct {
  13577. DrugID int64 //基础库药品id
  13578. ID int64 //医嘱id
  13579. Difference float64 //差值
  13580. Unit string //单位
  13581. }
  13582. type PrescriptionGoodDifference struct {
  13583. GoodID int64 //基础库项目耗材id
  13584. ID int64 //医嘱id
  13585. Difference int64 //差值
  13586. Unit string //单位
  13587. Type int64 //类型
  13588. }
  13589. type EditCustomData struct {
  13590. adviceList []*models.HisDoctorAdviceInfo
  13591. projectList []*models.HisPrescriptionProject
  13592. }
  13593. type SrcCustomData struct {
  13594. adviceList []*models.HisDoctorAdviceInfo
  13595. projectList []*models.HisPrescriptionProject
  13596. }
  13597. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13598. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13599. differences := make([]*PrescriptionDrugDifference, 0)
  13600. // 创建一个 map 来存储第一个切片中的药品信息
  13601. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13602. for _, advice := range firstPrescription {
  13603. firstMap[advice.DrugId] = advice
  13604. }
  13605. // 遍历第二个切片中的药品信息,并比较数量差值
  13606. for _, advice := range secondPrescription {
  13607. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13608. diff := &PrescriptionDrugDifference{
  13609. DrugID: advice.DrugId,
  13610. ID: firstAdvice.ID,
  13611. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13612. Unit: firstAdvice.PrescribingNumberUnit,
  13613. }
  13614. differences = append(differences, diff)
  13615. }
  13616. }
  13617. return differences
  13618. }
  13619. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13620. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13621. differences := make([]*PrescriptionGoodDifference, 0)
  13622. // 创建一个 map 来存储第一个切片中的耗材信息
  13623. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13624. for _, good := range firstPrescription {
  13625. firstMap[good.ProjectId] = good
  13626. }
  13627. // 遍历第二个切片中的耗材信息,并比较数量差值
  13628. for _, good := range secondPrescription {
  13629. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13630. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13631. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13632. diff := &PrescriptionGoodDifference{
  13633. GoodID: good.ProjectId,
  13634. ID: firstGood.ID,
  13635. Difference: count - firstCount,
  13636. Unit: firstGood.Unit,
  13637. Type: firstGood.Type,
  13638. }
  13639. differences = append(differences, diff)
  13640. }
  13641. }
  13642. return differences
  13643. }
  13644. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13645. var adviceList []*models.HisDoctorAdviceInfo
  13646. var projectList []*models.HisPrescriptionProject
  13647. var advice_ids []int64
  13648. var project_ids []int64
  13649. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13650. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13651. //var tempPrescription *models.HisPrescriptionProjectscription
  13652. if len(prescriptions) > 0 {
  13653. for _, item := range prescriptions {
  13654. items := item.(map[string]interface{})
  13655. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13656. advices := items["advices"].([]interface{})
  13657. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13658. groupNo := int64(0)
  13659. ctime := time.Now().Unix()
  13660. mtime := ctime
  13661. if len(advices) > 0 {
  13662. for _, advice := range advices {
  13663. var s models.HisDoctorAdviceInfo
  13664. s.AdviceType = 2
  13665. s.StopState = 2
  13666. s.ExecutionState = 2
  13667. s.Status = 1
  13668. s.Groupno = groupNo
  13669. s.CreatedTime = ctime
  13670. s.UpdatedTime = mtime
  13671. s.IsSettle = 2
  13672. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13673. //存储切片中
  13674. if s.ID > 0 {
  13675. advice_ids = append(advice_ids, s.ID)
  13676. adviceList = append(adviceList, &s)
  13677. }
  13678. }
  13679. }
  13680. }
  13681. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13682. projects := items["project"].([]interface{})
  13683. if len(projects) > 0 {
  13684. for _, project := range projects {
  13685. var p models.HisPrescriptionProject
  13686. p.Ctime = time.Now().Unix()
  13687. p.Mtime = time.Now().Unix()
  13688. p.Status = 1
  13689. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13690. if p.ID > 0 {
  13691. project_ids = append(project_ids, p.ID)
  13692. projectList = append(projectList, &p)
  13693. }
  13694. }
  13695. }
  13696. }
  13697. }
  13698. }
  13699. }
  13700. editCustomData.projectList = projectList
  13701. editCustomData.adviceList = adviceList
  13702. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13703. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13704. srcCustomData.adviceList = list
  13705. srcCustomData.projectList = list2
  13706. return
  13707. }
  13708. func (c *HisApiController) GetAllGoodInforList() {
  13709. orgId := c.GetAdminUserInfo().CurrentOrgId
  13710. goodList, _ := service.GetAllGoodList(orgId)
  13711. c.ServeSuccessJSON(map[string]interface{}{
  13712. "goodList": goodList,
  13713. })
  13714. return
  13715. }
  13716. func (this *HisApiController) SaveGoodList() {
  13717. project_name := this.GetString("project_name")
  13718. sort, _ := this.GetInt64("sort")
  13719. orgId := this.GetAdminUserInfo().CurrentOrgId
  13720. dataBody := make(map[string]interface{}, 0)
  13721. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13722. if err != nil {
  13723. utils.ErrorLog(err.Error())
  13724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13725. return
  13726. }
  13727. goodTeam := models.XtGoodTeam{
  13728. ProjectName: project_name,
  13729. Sort: sort,
  13730. UserOrgId: orgId,
  13731. Status: 1,
  13732. Ctime: time.Now().Unix(),
  13733. Mtime: time.Now().Unix(),
  13734. }
  13735. service.CreateGoodTeam(goodTeam)
  13736. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13737. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13738. infos, _ := dataBody["info"].([]interface{})
  13739. if len(infos) > 0 {
  13740. for _, item := range infos {
  13741. items := item.(map[string]interface{})
  13742. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13743. utils.ErrorLog("good_id")
  13744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13745. return
  13746. }
  13747. good_id := int64(items["good_id"].(float64))
  13748. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13749. utils.ErrorLog("number")
  13750. }
  13751. number := int64(items["number"].(float64))
  13752. xtGoodTeamList := models.XtGoodTeamList{
  13753. GoodId: good_id,
  13754. Count: number,
  13755. TeamId: lastGoodTeam.ID,
  13756. UserOrgId: orgId,
  13757. Status: 1,
  13758. Ctime: time.Now().Unix(),
  13759. Mtime: time.Now().Unix(),
  13760. }
  13761. service.CreateGoodList(xtGoodTeamList)
  13762. }
  13763. this.ServeSuccessJSON(map[string]interface{}{
  13764. "lastGoodTeam": lastGoodTeam,
  13765. })
  13766. }
  13767. }
  13768. return
  13769. }
  13770. func (this *HisApiController) GetGoodList() {
  13771. orgId := this.GetAdminUserInfo().CurrentOrgId
  13772. limit, _ := this.GetInt64("limit")
  13773. page, _ := this.GetInt64("page")
  13774. keyword := this.GetString("keyword")
  13775. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13776. this.ServeSuccessJSON(map[string]interface{}{
  13777. "list": list,
  13778. "total": total,
  13779. })
  13780. }
  13781. func (this *HisApiController) GetGoodNameDetail() {
  13782. id, _ := this.GetInt64("id")
  13783. orgId := this.GetAdminUserInfo().CurrentOrgId
  13784. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13785. goodList, _ := service.GetAllGoodList(orgId)
  13786. this.ServeSuccessJSON(map[string]interface{}{
  13787. "goodNameDetail": goodNameDetail,
  13788. "goodList": goodList,
  13789. })
  13790. }
  13791. func (this *HisApiController) UpdateGoodList() {
  13792. project_name := this.GetString("project_name")
  13793. sort, _ := this.GetInt64("sort")
  13794. id, _ := this.GetInt64("id")
  13795. orgId := this.GetAdminUserInfo().CurrentOrgId
  13796. dataBody := make(map[string]interface{}, 0)
  13797. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13798. if err != nil {
  13799. utils.ErrorLog(err.Error())
  13800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13801. return
  13802. }
  13803. goodTeam := models.XtGoodTeam{
  13804. ProjectName: project_name,
  13805. Sort: sort,
  13806. UserOrgId: orgId,
  13807. Status: 1,
  13808. Ctime: time.Now().Unix(),
  13809. Mtime: time.Now().Unix(),
  13810. ID: id,
  13811. }
  13812. service.SaveGoodTeam(goodTeam)
  13813. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13814. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13815. infos, _ := dataBody["info"].([]interface{})
  13816. if len(infos) > 0 {
  13817. for _, item := range infos {
  13818. items := item.(map[string]interface{})
  13819. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13820. utils.ErrorLog("good_id")
  13821. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13822. return
  13823. }
  13824. good_id := int64(items["good_id"].(float64))
  13825. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13826. utils.ErrorLog("id")
  13827. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13828. return
  13829. }
  13830. id := int64(items["id"].(float64))
  13831. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13832. utils.ErrorLog("number")
  13833. }
  13834. number := int64(items["number"].(float64))
  13835. xtGoodTeamList := models.XtGoodTeamList{
  13836. ID: id,
  13837. GoodId: good_id,
  13838. Count: number,
  13839. TeamId: lastGoodTeam.ID,
  13840. UserOrgId: orgId,
  13841. Status: 1,
  13842. Ctime: time.Now().Unix(),
  13843. Mtime: time.Now().Unix(),
  13844. }
  13845. service.SaveGoodList(xtGoodTeamList)
  13846. }
  13847. this.ServeSuccessJSON(map[string]interface{}{
  13848. "lastGoodTeam": lastGoodTeam,
  13849. })
  13850. }
  13851. }
  13852. return
  13853. }
  13854. func (this *HisApiController) DeleteGoodTeam() {
  13855. id, _ := this.GetInt64("id")
  13856. team, _ := service.DeleteGoodTeam(id)
  13857. this.ServeSuccessJSON(map[string]interface{}{
  13858. "team": team,
  13859. })
  13860. }
  13861. func (this *HisApiController) DeleteGood() {
  13862. id, _ := this.GetInt64("id")
  13863. good, _ := service.DeleteGood(id)
  13864. this.ServeSuccessJSON(map[string]interface{}{
  13865. "good": good,
  13866. })
  13867. }