his_api_controller.go 584KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "band_card_pay":
  229. order.BandCardPay = desc
  230. break
  231. case "ali_pay":
  232. order.AliPay = desc
  233. break
  234. case "wechat_pay":
  235. order.WechatPay = desc
  236. break
  237. case "fa_piao_number":
  238. order.FaPiaoNumber = desc
  239. break
  240. case "fa_piao_code":
  241. order.FaPiaoCode = desc
  242. break
  243. }
  244. err := service.SaveHisOrder(&order)
  245. if err == nil {
  246. c.ServeSuccessJSON(map[string]interface{}{
  247. "msg": "修改成功",
  248. })
  249. return
  250. } else {
  251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  252. return
  253. }
  254. }
  255. func (c *HisApiController) GetMonthHisPatient() {
  256. record_date := c.GetString("record_date")
  257. //order_status, _ := c.GetInt64("type")
  258. timeLayout := "2006-01-02"
  259. loc, _ := time.LoadLocation("Local")
  260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  261. if err != nil {
  262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  263. return
  264. }
  265. recordDateTime := theTime.Unix()
  266. adminInfo := c.GetAdminUserInfo()
  267. var tempPatients []service.NewTempPatients
  268. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  269. // 获取当前时间
  270. now := time.Now()
  271. // 获取本月的第一天
  272. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  273. // 获取下个月的第一天
  274. nextMonth := firstDay.AddDate(0, 1, 0)
  275. // 获取本月的最后一天
  276. lastDay := nextMonth.Add(-time.Nanosecond)
  277. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  278. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  279. var patients []service.NewTempPatients
  280. var patients_two []service.NewTempPatients
  281. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  282. for _, item := range tempPatients {
  283. //过滤掉没挂号的和没开处方的
  284. if len(item.HisPrescription) > 0 {
  285. patients = append(patients, item)
  286. patients_two = append(patients_two, item)
  287. }
  288. ////过滤掉没挂号的
  289. //if len(item.HisPatient) > 0 {
  290. //}
  291. }
  292. } else {
  293. for _, item := range tempPatients {
  294. //过滤掉没挂号的和没开处方的
  295. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  296. patients = append(patients, item)
  297. }
  298. ////过滤掉没挂号的
  299. //if len(item.HisPatient) > 0 {
  300. // patients_two = append(patients_two, item)
  301. //}
  302. }
  303. }
  304. c.ServeSuccessJSON(map[string]interface{}{
  305. "list": patients,
  306. "list_two": patients_two,
  307. "chargePatients": chargePatients,
  308. })
  309. }
  310. func (c *HisApiController) GetBatchSettleAccounts() {
  311. order_ids := c.GetString("order_ids")
  312. admin_user_id, _ := c.GetInt64("admin_user_id")
  313. adminUser := c.GetAdminUserInfo()
  314. orders := strings.Split(order_ids, ",")
  315. var newOrders []models.Orders
  316. for _, item := range orders {
  317. order, _ := service.GetHisOrderByIDTenOne(item)
  318. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  319. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  320. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  321. orderInfos = append(orderInfos, orderInfos_two...)
  322. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  323. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  324. var diagnosis_ids []string
  325. if his.ID > 0 {
  326. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  327. } else {
  328. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  329. }
  330. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  331. var dia_config []*models.HisXtDiagnoseConfig
  332. var name string
  333. for _, item := range diagnosis_ids {
  334. id, _ := strconv.ParseInt(item, 10, 64)
  335. diagnosisConfig, _ := service.FindDiagnoseById(id)
  336. dia_config = append(dia_config, diagnosisConfig)
  337. if len(name) == 0 {
  338. name = diagnosisConfig.ClassName
  339. } else {
  340. name = name + "," + diagnosisConfig.ClassName
  341. }
  342. }
  343. var bedCostTotal float64 = 0 //床位总费
  344. var bedCostSelfTotal float64 = 0 //床位自费
  345. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  346. var bedSelfTotal float64 = 0 //床位部分项目自费
  347. var bedInscpTotal float64 = 0 //床位部分项目自费
  348. var operationCostTotal float64 = 0 //手术费
  349. var operationCostSelfTotal float64 = 0 //手术费
  350. var operationCostPartSelfTotal float64 = 0 //手术费
  351. var operationSelfTotal float64 = 0 //床位部分项目自费
  352. var operationInscpTotal float64 = 0 //床位部分项目自费
  353. var otherCostTotal float64 = 0 //其他费用
  354. var otherCostSelfTotal float64 = 0 //其他费用
  355. var otherCostPartSelfTotal float64 = 0 //其他费用
  356. var otherSelfTotal float64 = 0 //床位部分项目自费
  357. var otherInscpTotal float64 = 0 //床位部分项目自费
  358. var materialCostTotal float64 = 0 //材料费
  359. var materialCostSelfTotal float64 = 0 //材料费
  360. var materialCostPartSelfTotal float64 = 0 //材料费
  361. var materialSelfTotal float64 = 0 //床位部分项目自费
  362. var materialInscpTotal float64 = 0 //床位部分项目自费
  363. var westernMedicineCostTotal float64 = 0 //西药费
  364. var westernMedicineCostSelfTotal float64 = 0 //西药费
  365. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  366. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  367. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  368. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  369. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  370. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  371. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  372. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  373. var checkCostTotal float64 = 0 //检查费
  374. var checkCostSelfTotal float64 = 0 //检查费
  375. var checkCostPartSelfTotal float64 = 0 //检查费
  376. var checkSelfTotal float64 = 0 //床位部分项目自费
  377. var checkInscpTotal float64 = 0 //床位部分项目自费
  378. var laboratoryCostTotal float64 = 0 //化验费
  379. var laboratoryCostSelfTotal float64 = 0 //化验费
  380. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  381. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  382. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  383. var treatCostTotal float64 = 0 //治疗费用
  384. var treatCostSelfTotal float64 = 0 //治疗费用
  385. var treatCostPartSelfTotal float64 = 0 //治疗费用
  386. var treatSelfTotal float64 = 0 //床位部分项目自费
  387. var treatInscpTotal float64 = 0 //床位部分项目自费
  388. decimal.DivisionPrecision = 2
  389. for _, item := range orderInfos {
  390. if item.MedChrgitmType == "01" { //床位费
  391. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  392. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  393. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  394. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  395. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  396. }
  397. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  398. if item.MedChrgitmType == "03" { //检查费
  399. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  400. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  401. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  402. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  403. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  404. }
  405. } else {
  406. if item.MedChrgitmType == "03" { //检查费
  407. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  408. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  409. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  410. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  411. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  412. }
  413. }
  414. if item.MedChrgitmType == "04" { //化验费
  415. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "05" { //治疗费
  422. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "06" { //手术费
  429. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  436. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "09" { //西药费
  443. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "11" { //中成费
  450. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  457. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  458. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  459. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  460. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  461. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  462. }
  463. }
  464. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  465. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  466. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  467. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  468. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. var doctor_name string
  470. if roles.ID == 0 {
  471. doctor_name = "管理员"
  472. } else {
  473. doctor_name = roles.UserName
  474. }
  475. yiliao_leibie := ""
  476. switch order.MedType {
  477. case "11":
  478. yiliao_leibie = "普通门诊"
  479. break
  480. case "12":
  481. yiliao_leibie = "门诊挂号"
  482. break
  483. case "13":
  484. yiliao_leibie = "急诊"
  485. break
  486. case "14":
  487. yiliao_leibie = "门诊特殊病"
  488. break
  489. case "15":
  490. yiliao_leibie = "门诊统筹"
  491. break
  492. case "16":
  493. yiliao_leibie = "门诊慢性病"
  494. break
  495. case "21":
  496. yiliao_leibie = "普通住院"
  497. break
  498. }
  499. var newOrder models.Orders
  500. newOrder.Diagnosis = name
  501. newOrder.OrderInfos = orderInfos
  502. newOrder.Number = order.MdtrtId
  503. newOrder.Date = order.SettleAccountsDate
  504. newOrder.ChargeAdmin = charge_admin
  505. newOrder.PrintorAdmin = printor_admin
  506. newOrder.Order = order
  507. newOrder.BedCostTotal = bedCostTotal
  508. newOrder.BedCostSelfTotal = bedCostSelfTotal
  509. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  510. newOrder.BedSelfTotal = bedSelfTotal
  511. newOrder.BedInscpTotal = bedInscpTotal
  512. newOrder.OperationCostTotal = operationCostTotal
  513. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  514. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  515. newOrder.OperationSelfTotal = operationSelfTotal
  516. newOrder.OperationInscpTotal = operationInscpTotal
  517. newOrder.OtherCostTotal = otherCostTotal
  518. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  519. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  520. newOrder.OtherSelfTotal = otherSelfTotal
  521. newOrder.OtherInscpTotal = otherInscpTotal
  522. newOrder.MaterialCostTotal = materialCostTotal
  523. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  524. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  525. newOrder.MaterialSelfTotal = materialSelfTotal
  526. newOrder.MaterialInscpTotal = materialInscpTotal
  527. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  528. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  529. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  530. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  531. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  532. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  533. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  534. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  535. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  536. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  537. newOrder.CheckCostTotal = checkCostTotal
  538. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  539. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  540. newOrder.CheckSelfTotal = checkSelfTotal
  541. newOrder.CheckInscpTotal = checkInscpTotal
  542. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  543. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  544. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  545. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  546. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  547. newOrder.TreatCostTotal = treatCostTotal
  548. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  549. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  550. newOrder.TreatSelfTotal = treatSelfTotal
  551. newOrder.TreatInscpTotal = treatInscpTotal
  552. newOrder.DoctorInfo = doctor_info
  553. newOrder.DoctorName = doctor_name
  554. newOrder.HealthCardNo = order.PsnNo
  555. newOrder.YiliaoLeibie = yiliao_leibie
  556. newOrder.Patient = patient
  557. newOrder.OrgName = miConfig.OrgName
  558. newOrder.OrgCode = miConfig.Code
  559. newOrder.OrderNumber = order.Number
  560. newOrder.HisPatient = his
  561. newOrder.DiaConfig = dia_config
  562. newOrders = append(newOrders, newOrder)
  563. }
  564. c.ServeSuccessJSON(map[string]interface{}{
  565. "orders": newOrders,
  566. })
  567. }
  568. func (c *HisApiController) GetTestOrder() {
  569. order_id, _ := c.GetInt64("order_id")
  570. admin_user_id, _ := c.GetInt64("admin_user_id")
  571. adminUser := c.GetAdminUserInfo()
  572. order, _ := service.GetHisOrderByID(order_id)
  573. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  574. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  575. orderInfos = append(orderInfos, orderInfos_two...)
  576. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  577. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  578. var dia_config []*models.HisXtDiagnoseConfig
  579. var name string
  580. var bedCostTotal float64 = 0 //床位总费
  581. var bedCostSelfTotal float64 = 0 //床位自费
  582. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  583. var bedSelfTotal float64 = 0 //床位部分项目自费
  584. var bedInscpTotal float64 = 0 //床位部分项目自费
  585. var operationCostTotal float64 = 0 //手术费
  586. var operationCostSelfTotal float64 = 0 //手术费
  587. var operationCostPartSelfTotal float64 = 0 //手术费
  588. var operationSelfTotal float64 = 0 //床位部分项目自费
  589. var operationInscpTotal float64 = 0 //床位部分项目自费
  590. var otherCostTotal float64 = 0 //其他费用
  591. var otherCostSelfTotal float64 = 0 //其他费用
  592. var otherCostPartSelfTotal float64 = 0 //其他费用
  593. var otherSelfTotal float64 = 0 //床位部分项目自费
  594. var otherInscpTotal float64 = 0 //床位部分项目自费
  595. var materialCostTotal float64 = 0 //材料费
  596. var materialCostSelfTotal float64 = 0 //材料费
  597. var materialCostPartSelfTotal float64 = 0 //材料费
  598. var materialSelfTotal float64 = 0 //床位部分项目自费
  599. var materialInscpTotal float64 = 0 //床位部分项目自费
  600. var westernMedicineCostTotal float64 = 0 //西药费
  601. var westernMedicineCostSelfTotal float64 = 0 //西药费
  602. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  603. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  604. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  605. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  606. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  607. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  608. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  609. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  610. var checkCostTotal float64 = 0 //检查费
  611. var checkCostSelfTotal float64 = 0 //检查费
  612. var checkCostPartSelfTotal float64 = 0 //检查费
  613. var checkSelfTotal float64 = 0 //床位部分项目自费
  614. var checkInscpTotal float64 = 0 //床位部分项目自费
  615. var laboratoryCostTotal float64 = 0 //化验费
  616. var laboratoryCostSelfTotal float64 = 0 //化验费
  617. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  618. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  619. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  620. var treatCostTotal float64 = 0 //治疗费用
  621. var treatCostSelfTotal float64 = 0 //治疗费用
  622. var treatCostPartSelfTotal float64 = 0 //治疗费用
  623. var treatSelfTotal float64 = 0 //床位部分项目自费
  624. var treatInscpTotal float64 = 0 //床位部分项目自费
  625. decimal.DivisionPrecision = 2
  626. for _, item := range orderInfos {
  627. if item.MedChrgitmType == "01" { //床位费
  628. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  629. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  630. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  631. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  632. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  633. }
  634. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  635. if item.MedChrgitmType == "03" { //检查费
  636. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  637. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  638. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  639. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  640. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  641. }
  642. } else {
  643. if item.MedChrgitmType == "03" { //检查费
  644. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  645. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  646. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  647. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  648. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  649. }
  650. }
  651. if item.MedChrgitmType == "04" { //化验费
  652. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "05" { //治疗费
  659. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "06" { //手术费
  666. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  673. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "09" { //西药费
  680. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "11" { //中成费
  687. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  694. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  695. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  696. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  697. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  698. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  699. }
  700. }
  701. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  702. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  703. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  704. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  705. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. var doctor_name string
  707. if roles.ID == 0 {
  708. doctor_name = "管理员"
  709. } else {
  710. doctor_name = roles.UserName
  711. }
  712. yiliao_leibie := ""
  713. switch order.MedType {
  714. case "11":
  715. yiliao_leibie = "普通门诊"
  716. break
  717. case "12":
  718. yiliao_leibie = "门诊挂号"
  719. break
  720. case "13":
  721. yiliao_leibie = "急诊"
  722. break
  723. case "14":
  724. yiliao_leibie = "门诊特殊病"
  725. break
  726. case "15":
  727. yiliao_leibie = "门诊统筹"
  728. break
  729. case "16":
  730. yiliao_leibie = "门诊慢性病"
  731. break
  732. case "21":
  733. yiliao_leibie = "普通住院"
  734. break
  735. }
  736. c.ServeSuccessJSON(map[string]interface{}{
  737. "diagnosis": name,
  738. "order_infos": orderInfos,
  739. "number": order.MdtrtId,
  740. "date": order.SettleAccountsDate,
  741. "charge_admin": charge_admin,
  742. "printor_admin": printor_admin,
  743. "info": order,
  744. "order": order,
  745. "bedCostTotal": bedCostTotal,
  746. "bedCostSelfTotal": bedCostSelfTotal,
  747. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  748. "bedSelfTotal": bedSelfTotal,
  749. "bedInscpTotal": bedInscpTotal,
  750. "operationCostTotal": operationCostTotal,
  751. "operationCostSelfTotal": operationCostSelfTotal,
  752. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  753. "operationSelfTotal": operationSelfTotal,
  754. "operationInscpTotal": operationInscpTotal,
  755. "otherCostTotal": otherCostTotal,
  756. "otherCostSelfTotal": otherCostSelfTotal,
  757. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  758. "otherSelfTotal": otherSelfTotal,
  759. "otherInscpTotal": otherInscpTotal,
  760. "materialCostTotal": materialCostTotal,
  761. "materialCostSelfTotal": materialCostSelfTotal,
  762. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  763. "materialSelfTotal": materialSelfTotal,
  764. "materialInscpTotal": materialInscpTotal,
  765. "westernMedicineCostTotal": westernMedicineCostTotal,
  766. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  767. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  768. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  769. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  770. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  771. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  772. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  773. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  774. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  775. "checkCostTotal": checkCostTotal,
  776. "checkCostSelfTotal": checkCostSelfTotal,
  777. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  778. "checkSelfTotal": checkSelfTotal,
  779. "checkInscpTotal": checkInscpTotal,
  780. "laboratoryCostTotal": laboratoryCostTotal,
  781. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  782. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  783. "laboratorySelfTotal": laboratorySelfTotal,
  784. "laboratoryInscpTotal": laboratoryInscpTotal,
  785. "treatCostTotal": treatCostTotal,
  786. "treatCostSelfTotal": treatCostSelfTotal,
  787. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  788. "treatSelfTotal": treatSelfTotal,
  789. "treatInscpTotal": treatInscpTotal,
  790. "doctor_info": doctor_info,
  791. "doctor_name": doctor_name,
  792. "health_card_no": order.PsnNo,
  793. "yiliao_leibie": yiliao_leibie,
  794. "patient": patient,
  795. "org_name": miConfig.OrgName,
  796. "org_code": miConfig.Code,
  797. "order_number": order.Number,
  798. "his_hospital": his_hospital,
  799. "dia_config": dia_config,
  800. })
  801. }
  802. type CustomFundPay struct {
  803. FundPayType string `json:"fund_pay_type"`
  804. FundPayamt float64 `json:"fund_payamt"`
  805. InscpScpAmt float64 `json:"inscp_scp_amt"`
  806. }
  807. func (c *PublicApiController) GetBaiLinExportData() {
  808. data := service.GetBaiLinOrderData()
  809. fmt.Println(len(data))
  810. var new_data []*models.NewCustomHisOrder
  811. for _, item := range data {
  812. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  813. new_data = append(new_data, item)
  814. }
  815. }
  816. fmt.Println(len(new_data))
  817. c.ServeSuccessJSON(map[string]interface{}{
  818. "list": new_data,
  819. })
  820. }
  821. func (c *HisApiController) GetHisUnChargePatientList() {
  822. record_date := c.GetString("record_date")
  823. sch_type, _ := c.GetInt64("sch_type")
  824. timeLayout := "2006-01-02"
  825. loc, _ := time.LoadLocation("Local")
  826. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  827. if err != nil {
  828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  829. return
  830. }
  831. recordDateTime := theTime.Unix()
  832. adminInfo := c.GetAdminUserInfo()
  833. var tempPatients []*service.NewTempPatients
  834. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  835. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  836. var patients []*service.NewTempPatients
  837. var patients_two []*service.NewTempPatients
  838. for _, item := range tempPatients {
  839. //过滤掉没挂号的和没开处方的
  840. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  841. patients = append(patients, item)
  842. }
  843. //过滤掉没挂号的
  844. if len(item.HisPatient) > 0 {
  845. patients_two = append(patients_two, item)
  846. }
  847. }
  848. c.ServeSuccessJSON(map[string]interface{}{
  849. "list": patients,
  850. "list_two": patients_two,
  851. })
  852. }
  853. func (c *HisApiController) GetPrivateExpensesOrder() {
  854. //id, _ := c.GetInt64("id")
  855. //record_time := c.GetString("record_time")
  856. order_id, _ := c.GetInt64("order_id")
  857. admin_user_id, _ := c.GetInt64("admin_user_id")
  858. //timeLayout := "2006-01-02"
  859. //loc, _ := time.LoadLocation("Local")
  860. //
  861. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  862. //if err != nil {
  863. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  864. // return
  865. //}
  866. //recordDateTime := theTime.Unix()
  867. adminUser := c.GetAdminUserInfo()
  868. order, _ := service.GetHisOrderByID(order_id)
  869. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  870. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  871. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  872. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  873. //var config []*models.HisXtDiagnoseConfig
  874. var name string
  875. if order.PType == 1 {
  876. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  877. for _, item := range diagnosis_ids {
  878. id, _ := strconv.ParseInt(item, 10, 64)
  879. diagnosisConfig, _ := service.FindDiagnoseById(id)
  880. if len(name) == 0 {
  881. name = diagnosisConfig.ClassName
  882. } else {
  883. name = name + "," + diagnosisConfig.ClassName
  884. }
  885. }
  886. } else {
  887. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  888. for _, item := range diagnosis_ids {
  889. id, _ := strconv.ParseInt(item, 10, 64)
  890. diagnosisConfig, _ := service.FindDiagnoseById(id)
  891. if len(name) == 0 {
  892. name = diagnosisConfig.ClassName
  893. } else {
  894. name = name + "," + diagnosisConfig.ClassName
  895. }
  896. }
  897. }
  898. var bedCostTotal float64 = 0 //床位总费
  899. //var bedCostSelfTotal float64 = 0 //床位自费
  900. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  901. var operationCostTotal float64 = 0 //手术费
  902. //var operationCostSelfTotal float64 = 0 //手术费
  903. var operationCostPartSelfTotal float64 = 0 //手术费
  904. var otherCostTotal float64 = 0 //其他费用
  905. //var otherCostSelfTotal float64 = 0 //其他费用
  906. var otherCostPartSelfTotal float64 = 0 //其他费用
  907. var materialCostTotal float64 = 0 //材料费
  908. //var materialCostSelfTotal float64 = 0 //材料费
  909. var materialCostPartSelfTotal float64 = 0 //材料费
  910. var westernMedicineCostTotal float64 = 0 //西药费
  911. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  912. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  913. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  914. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  915. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  916. var checkCostTotal float64 = 0 //检查费
  917. //var checkCostSelfTotal float64 = 0 //检查费
  918. var checkCostPartSelfTotal float64 = 0 //检查费
  919. var laboratoryCostTotal float64 = 0 //化验费
  920. //var laboratoryCostSelfTotal float64 = 0 //化验费
  921. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  922. var treatCostTotal float64 = 0 //治疗费用
  923. //var treatCostSelfTotal float64 = 0 //治疗费用
  924. var treatCostPartSelfTotal float64 = 0 //治疗费用
  925. var zhenChaCostTotal float64 = 0 //其他费用
  926. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  927. decimal.DivisionPrecision = 2
  928. for _, item := range orderInfos {
  929. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  930. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  931. item.MedChrgitmType = "09"
  932. }
  933. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  934. if item.HisPrescriptionProject.Type == 2 {
  935. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  936. fmt.Println("CostClassify")
  937. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  938. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  939. case 0:
  940. item.MedChrgitmType = "0"
  941. break
  942. case 1:
  943. item.MedChrgitmType = "14"
  944. break
  945. case 2:
  946. item.MedChrgitmType = "05"
  947. break
  948. case 3:
  949. item.MedChrgitmType = "03"
  950. break
  951. case 4:
  952. item.MedChrgitmType = "03"
  953. break
  954. case 5:
  955. item.MedChrgitmType = "08"
  956. break
  957. case 6:
  958. item.MedChrgitmType = "14"
  959. break
  960. case 7:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 8:
  964. item.MedChrgitmType = "03"
  965. break
  966. case 9:
  967. item.MedChrgitmType = "14"
  968. break
  969. case 10:
  970. item.MedChrgitmType = "14"
  971. break
  972. case 11:
  973. item.MedChrgitmType = "06"
  974. break
  975. case 12:
  976. item.MedChrgitmType = "12"
  977. break
  978. case 13:
  979. item.MedChrgitmType = "01"
  980. break
  981. case 14:
  982. item.MedChrgitmType = "04"
  983. break
  984. case 15:
  985. item.MedChrgitmType = "14"
  986. break
  987. }
  988. } else {
  989. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  990. case 1:
  991. item.MedChrgitmType = "14"
  992. break
  993. case 2:
  994. item.MedChrgitmType = "05"
  995. break
  996. case 3:
  997. item.MedChrgitmType = "04"
  998. break
  999. case 4:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 5:
  1003. item.MedChrgitmType = "08"
  1004. break
  1005. case 6:
  1006. item.MedChrgitmType = "14"
  1007. break
  1008. case 7:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. case 8:
  1012. item.MedChrgitmType = "03"
  1013. break
  1014. case 9:
  1015. item.MedChrgitmType = "14"
  1016. break
  1017. default:
  1018. item.MedChrgitmType = "14"
  1019. break
  1020. }
  1021. }
  1022. } else if item.HisPrescriptionProject.Type == 3 {
  1023. item.MedChrgitmType = "08"
  1024. }
  1025. }
  1026. }
  1027. if order.IsMedicineInsurance != 1 {
  1028. order.PsnCashPay = order.MedfeeSumamt
  1029. }
  1030. for _, item := range orderInfos {
  1031. if item.MedChrgitmType == "01" { //床位费
  1032. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "02" { //诊察费
  1037. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //zhenChaCostSelfTotal = zhenChaCostTotal
  1039. }
  1040. if item.MedChrgitmType == "03" { //检查费
  1041. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1042. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1043. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1044. }
  1045. if item.MedChrgitmType == "02" { //检查费
  1046. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1047. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1048. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1049. }
  1050. if item.MedChrgitmType == "04" { //化验费
  1051. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1052. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1053. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1054. }
  1055. if item.MedChrgitmType == "05" { //治疗费
  1056. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1057. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1058. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1059. }
  1060. if item.MedChrgitmType == "06" { //手术费
  1061. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1062. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1063. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1064. }
  1065. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1066. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. }
  1070. if item.MedChrgitmType == "09" { //西药费
  1071. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1072. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1073. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1074. }
  1075. if item.MedChrgitmType == "11" { //中成费
  1076. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1077. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1078. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1079. }
  1080. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1081. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1082. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1083. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1084. }
  1085. }
  1086. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1087. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1088. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1089. var dia_config []*models.HisXtDiagnoseConfig
  1090. var diagnosis_ids []string
  1091. if his.ID > 0 {
  1092. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1093. } else {
  1094. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1095. }
  1096. for _, item := range diagnosis_ids {
  1097. id, _ := strconv.ParseInt(item, 10, 64)
  1098. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1099. dia_config = append(dia_config, diagnosisConfig)
  1100. }
  1101. var rf []CustomFundPay
  1102. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1103. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1104. c.ServeSuccessJSON(map[string]interface{}{
  1105. "patient": patient,
  1106. "order_infos": orderInfos,
  1107. "diagnosis": name,
  1108. "bedCostTotal": bedCostTotal,
  1109. "bedCostSelfTotal": bedCostTotal,
  1110. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1111. "operationCostTotal": operationCostTotal,
  1112. "operationCostSelfTotal": operationCostTotal,
  1113. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1114. "otherCostTotal": otherCostTotal,
  1115. "otherCostSelfTotal": otherCostTotal,
  1116. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1117. "materialCostTotal": materialCostTotal,
  1118. "materialCostSelfTotal": materialCostTotal,
  1119. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1120. "westernMedicineCostTotal": westernMedicineCostTotal,
  1121. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1122. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1123. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1124. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1125. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1126. "checkCostTotal": checkCostTotal,
  1127. "checkCostSelfTotal": checkCostTotal,
  1128. "zhenChaCostTotal": zhenChaCostTotal,
  1129. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1130. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1131. "laboratoryCostTotal": laboratoryCostTotal,
  1132. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1133. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1134. "treatCostTotal": treatCostTotal,
  1135. "treatCostSelfTotal": treatCostTotal,
  1136. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1137. "charge_admin": charge_admin,
  1138. "printor_admin": printor_admin,
  1139. "org_name": org.OrgName,
  1140. "org_code": miConfig.Code,
  1141. "name": patient.Name,
  1142. "number": order.MdtrtId,
  1143. "date": order.SettleAccountsDate,
  1144. "info": order,
  1145. "new_order": order,
  1146. "his_hospital": his_hospital,
  1147. "his": his,
  1148. "funds": rf,
  1149. "dia_config": dia_config,
  1150. })
  1151. }
  1152. func (c *HisApiController) RefudDetail() {
  1153. order_id, _ := c.GetInt64("order_id")
  1154. order, _ := service.GetHisOrderByID(order_id)
  1155. adminUser := c.GetAdminUserInfo()
  1156. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1157. c.ServeSuccessJSON(map[string]interface{}{
  1158. "msg": "撤销成功",
  1159. })
  1160. }
  1161. func (c *HisApiController) Sscard() {
  1162. //r := CardInit()
  1163. //if r == 0 {
  1164. // GetBaseInfo()
  1165. //}
  1166. //c.ServeSuccessJSON(map[string]interface{}{
  1167. // "list": "11",
  1168. //})
  1169. }
  1170. func GetBaseInfo() error {
  1171. //handle := syscall.MustLoadDLL("SSCard.dll")
  1172. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1173. //
  1174. //str := make([]byte, 256)
  1175. //str1 := make([]byte, 256)
  1176. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1177. //if ferr != nil {
  1178. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1179. // return ferr
  1180. //}
  1181. //
  1182. //fmt.Println(string(str))
  1183. //
  1184. //fmt.Println(r)
  1185. return nil
  1186. }
  1187. func CardInit() int {
  1188. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1189. //add := DllTestDef.MustFindProc("Init")
  1190. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1191. //if err != nil {
  1192. // fmt.Println("SSCard的运算结果为:", ret)
  1193. //}
  1194. //result := int(ret)
  1195. return 0
  1196. }
  1197. func IntPtr(n int) uintptr {
  1198. return uintptr(n)
  1199. }
  1200. func StrPtr(s string) uintptr {
  1201. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1202. }
  1203. func (c *HisApiController) GetHisPatientList() {
  1204. record_date := c.GetString("record_date")
  1205. sch_type, _ := c.GetInt64("sch_type")
  1206. patient_type, _ := c.GetInt64("patient_type")
  1207. fmt.Println("patient_type")
  1208. fmt.Println(patient_type)
  1209. timeLayout := "2006-01-02"
  1210. loc, _ := time.LoadLocation("Local")
  1211. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1212. if err != nil {
  1213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1214. return
  1215. }
  1216. recordDateTime := theTime.Unix()
  1217. adminInfo := c.GetAdminUserInfo()
  1218. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1219. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1220. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1221. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1222. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1223. fmt.Println(patients_three)
  1224. //获取当前用户的信息
  1225. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1226. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1227. //获取所有科室信息
  1228. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1229. //var aa []service.PatientThree
  1230. noElementsSlice := make([]service.PatientThree, 0)
  1231. c.ServeSuccessJSON(map[string]interface{}{
  1232. "list": patients_three,
  1233. "list_two": patients_four,
  1234. "list_three": noElementsSlice,
  1235. "info": adminUserInfo,
  1236. "doctors": doctors,
  1237. "department": department,
  1238. })
  1239. } else {
  1240. //获取当前用户的信息
  1241. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1242. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1243. //获取所有科室信息
  1244. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1245. //var aa []service.PatientThree
  1246. noElementsSlice := make([]service.PatientThree, 0)
  1247. c.ServeSuccessJSON(map[string]interface{}{
  1248. "list": patients,
  1249. "list_two": patients_two,
  1250. "list_three": noElementsSlice,
  1251. "info": adminUserInfo,
  1252. "doctors": doctors,
  1253. "department": department,
  1254. })
  1255. }
  1256. }
  1257. type CustomTemplate struct {
  1258. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1259. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1260. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1261. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1262. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1263. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1264. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1265. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1266. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1267. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1268. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1269. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1270. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1271. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1272. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1273. }
  1274. func (c *HisApiController) GetHisPatientInfo() {
  1275. patient_id, _ := c.GetInt64("patient_id")
  1276. his_patient_id, _ := c.GetInt64("his_patient_id")
  1277. record_date := c.GetString("record_date")
  1278. number := c.GetString("number")
  1279. //start_time := c.GetString("start_time")
  1280. //end_time := c.GetString("end_time")
  1281. p_type, _ := c.GetInt64("p_type")
  1282. timeLayout := "2006-01-02"
  1283. loc, _ := time.LoadLocation("Local")
  1284. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1285. if err != nil {
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1287. return
  1288. }
  1289. recordDateTime := theTime.Unix()
  1290. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1291. //if err != nil {
  1292. //
  1293. //}
  1294. //startRecordDateTime := startTime.Unix()
  1295. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1296. //if err != nil {
  1297. //
  1298. //}
  1299. //endRecordDateTime := endTime.Unix()
  1300. admin := c.GetAdminUserInfo()
  1301. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1302. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1303. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1304. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1305. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1306. var prescriptions []*models.HisPrescription
  1307. var last_prescriptions []*models.HisPrescription
  1308. var sch_prescriptions []CustomTemplate
  1309. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1310. if p_type == 1 { //住院
  1311. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1312. for _, item := range prescriptions {
  1313. for _, subItem := range item.HisDoctorAdviceInfo {
  1314. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1315. if info.RetailPrice > 0 {
  1316. subItem.Drug.MinPrice = info.RetailPrice
  1317. }
  1318. }
  1319. }
  1320. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1321. } else { //门诊
  1322. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1323. for _, item := range prescriptions {
  1324. for _, subItem := range item.HisDoctorAdviceInfo {
  1325. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1326. if info.RetailPrice > 0 {
  1327. subItem.Drug.MinPrice = info.RetailPrice
  1328. }
  1329. }
  1330. }
  1331. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1332. }
  1333. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1334. if sch.ID > 0 {
  1335. var week string
  1336. t := time.Now()
  1337. switch t.Weekday().String() {
  1338. case "Monday":
  1339. week = "周一"
  1340. break
  1341. case "Tuesday":
  1342. week = "周二"
  1343. break
  1344. case "Wednesday":
  1345. week = "周三"
  1346. break
  1347. case "Thursday":
  1348. week = "周四"
  1349. break
  1350. case "Friday":
  1351. week = "周五"
  1352. break
  1353. case "Saturday":
  1354. week = "周六"
  1355. break
  1356. case "Sunday":
  1357. week = "周日"
  1358. break
  1359. }
  1360. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1361. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1362. //根据推送频率组装新的数组
  1363. for _, item := range temp_sch_prescriptions {
  1364. var cus CustomTemplate
  1365. cus.ID = item.ID
  1366. cus.UserOrgId = item.UserOrgId
  1367. cus.PatientId = item.PatientId
  1368. cus.MedType = item.MedType
  1369. cus.RecordDate = item.RecordDate
  1370. cus.Type = item.Type
  1371. cus.PType = item.PType
  1372. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1373. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1374. if subItem.FrequencyType == 1 { //每次必推
  1375. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1376. }
  1377. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1378. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1379. }
  1380. if subItem.FrequencyType == 2 { //按照天数频率
  1381. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1382. now := p.Unix()
  1383. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1384. dayStr2 := "-" + dayStr
  1385. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1386. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1387. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1388. if len(advices) == 0 {
  1389. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1390. }
  1391. }
  1392. }
  1393. }
  1394. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1395. if subItem.Type == 2 {
  1396. if subItem.XtHisProject.MedicalStatus != 1 {
  1397. if subItem.FrequencyType == 1 {
  1398. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1399. }
  1400. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. if subItem.FrequencyType == 2 {
  1404. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1405. now := p.Unix()
  1406. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1407. dayStr2 := "-" + dayStr
  1408. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1409. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1410. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1411. if len(projects) == 0 {
  1412. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1413. }
  1414. }
  1415. }
  1416. } else if subItem.Type == 3 {
  1417. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1418. if subItem.FrequencyType == 1 {
  1419. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1420. }
  1421. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1422. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1423. }
  1424. if subItem.FrequencyType == 2 {
  1425. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1426. now := p.Unix()
  1427. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1428. dayStr2 := "-" + dayStr
  1429. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1430. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1431. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1432. if len(projects) == 0 {
  1433. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1434. }
  1435. }
  1436. }
  1437. }
  1438. }
  1439. sch_prescriptions = append(sch_prescriptions, cus)
  1440. }
  1441. for _, item := range sch_prescriptions {
  1442. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1443. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1444. }
  1445. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1446. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1447. }
  1448. }
  1449. }
  1450. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1451. if config.ID > 0 && config.IsOpen == 1 {
  1452. for _, item := range sch_prescriptions {
  1453. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1454. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1455. if info.RetailPrice > 0 {
  1456. subItem.Drug.MinPrice = info.RetailPrice
  1457. if admin.CurrentOrgId != 10598 {
  1458. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1459. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1460. }
  1461. }
  1462. }
  1463. }
  1464. }
  1465. if config.ID > 0 && config.IsOpen == 1 {
  1466. for _, item := range sch_prescriptions {
  1467. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1468. if subItem.Type == 3 {
  1469. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1470. if info.Price > 0 {
  1471. subItem.GoodInfo.PackingPrice = info.Price
  1472. if admin.CurrentOrgId != 10598 {
  1473. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1474. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1482. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1483. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1484. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1485. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1486. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1487. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1488. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1489. //获取所有科室信息
  1490. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1491. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1492. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1493. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1494. fmt.Println(prescriptions)
  1495. fmt.Println(sch_prescriptions)
  1496. fmt.Println(last_prescriptions)
  1497. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1498. if len(sch_prescriptions) > 0 {
  1499. var index = 0
  1500. for subindex, item := range sch_prescriptions {
  1501. if item.Type == 2 {
  1502. index = subindex
  1503. }
  1504. }
  1505. fmt.Println(index)
  1506. fmt.Println(len(sch_prescriptions))
  1507. if index >= 0 && index < len(sch_prescriptions) {
  1508. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1509. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1510. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1511. if one.ID > 0 {
  1512. var hpt models.HisPrescriptionProjectTemplate
  1513. hpt.Type = 3
  1514. hpt.ID = 0
  1515. hpt.PatientId = sch_prescriptions[index].PatientId
  1516. hpt.Status = 1
  1517. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1518. hpt.Mtime = time.Now().Unix()
  1519. hpt.Ctime = time.Now().Unix()
  1520. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1521. hpt.Count = "1"
  1522. hpt.Price = one.RetailPrice
  1523. hpt.ProjectId = one.ID
  1524. hpt.FeedetlSn = ""
  1525. hpt.PrescriptionId = sch_prescriptions[index].ID
  1526. hpt.Unit = one.PackingUnit
  1527. hpt.Day = "1"
  1528. hpt.SingleDose = "1"
  1529. hpt.GoodInfo = one
  1530. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1531. }
  1532. if two.ID > 0 {
  1533. var hpt models.HisPrescriptionProjectTemplate
  1534. hpt.Type = 3
  1535. hpt.ID = 0
  1536. hpt.PatientId = sch_prescriptions[index].PatientId
  1537. hpt.Status = 1
  1538. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1539. hpt.Mtime = time.Now().Unix()
  1540. hpt.Ctime = time.Now().Unix()
  1541. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1542. hpt.Count = "1"
  1543. hpt.Price = two.RetailPrice
  1544. hpt.ProjectId = two.ID
  1545. hpt.FeedetlSn = ""
  1546. hpt.PrescriptionId = sch_prescriptions[index].ID
  1547. hpt.Unit = two.PackingUnit
  1548. hpt.Day = "1"
  1549. hpt.SingleDose = "1"
  1550. hpt.GoodInfo = two
  1551. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1552. }
  1553. //if three.ID > 0 {
  1554. // var hpt models.HisPrescriptionProjectTemplate
  1555. // hpt.Type = 3
  1556. // hpt.ID = 0
  1557. // hpt.PatientId = sch_prescriptions[index].PatientId
  1558. // hpt.Status = 1
  1559. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1560. // hpt.Mtime = time.Now().Unix()
  1561. // hpt.Ctime = time.Now().Unix()
  1562. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1563. // hpt.Count = "1"
  1564. // hpt.Price = three.RetailPrice
  1565. // hpt.ProjectId = three.ID
  1566. // hpt.FeedetlSn = ""
  1567. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1568. // hpt.Unit = three.PackingUnit
  1569. // hpt.Day = "1"
  1570. // hpt.SingleDose = "1"
  1571. // hpt.GoodInfo = three
  1572. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1573. //}
  1574. fmt.Println(sch_prescriptions)
  1575. }
  1576. } else {
  1577. if len(last_prescriptions) > 0 {
  1578. var index = 0
  1579. for subindex, item := range last_prescriptions {
  1580. if item.Type == 2 {
  1581. index = subindex
  1582. }
  1583. }
  1584. if index >= 0 && index < len(last_prescriptions) {
  1585. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1586. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1587. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1588. if one.ID > 0 {
  1589. var hpt models.HisPrescriptionProject
  1590. hpt.Type = 3
  1591. hpt.ID = 0
  1592. hpt.PatientId = last_prescriptions[index].PatientId
  1593. hpt.Status = 1
  1594. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1595. hpt.Mtime = time.Now().Unix()
  1596. hpt.Ctime = time.Now().Unix()
  1597. hpt.RecordDate = last_prescriptions[index].RecordDate
  1598. hpt.Count = "1"
  1599. hpt.Price = one.RetailPrice
  1600. hpt.ProjectId = one.ID
  1601. hpt.FeedetlSn = ""
  1602. hpt.PrescriptionId = last_prescriptions[index].ID
  1603. hpt.Unit = one.PackingUnit
  1604. hpt.Day = "1"
  1605. hpt.SingleDose = "1"
  1606. hpt.GoodInfo = one
  1607. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1608. }
  1609. if two.ID > 0 {
  1610. var hpt models.HisPrescriptionProject
  1611. hpt.Type = 3
  1612. hpt.ID = 0
  1613. hpt.PatientId = last_prescriptions[index].PatientId
  1614. hpt.Status = 1
  1615. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1616. hpt.Mtime = time.Now().Unix()
  1617. hpt.Ctime = time.Now().Unix()
  1618. hpt.RecordDate = last_prescriptions[index].RecordDate
  1619. hpt.Count = "1"
  1620. hpt.Price = two.RetailPrice
  1621. hpt.ProjectId = two.ID
  1622. hpt.FeedetlSn = ""
  1623. hpt.PrescriptionId = last_prescriptions[index].ID
  1624. hpt.Unit = two.PackingUnit
  1625. hpt.Day = "1"
  1626. hpt.SingleDose = "1"
  1627. hpt.GoodInfo = two
  1628. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1629. }
  1630. //if three.ID > 0 {
  1631. // var hpt models.HisPrescriptionProject
  1632. // hpt.Type = 3
  1633. // hpt.ID = 0
  1634. // hpt.PatientId = last_prescriptions[index].PatientId
  1635. // hpt.Status = 1
  1636. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1637. // hpt.Mtime = time.Now().Unix()
  1638. // hpt.Ctime = time.Now().Unix()
  1639. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1640. // hpt.Count = "1"
  1641. // hpt.Price = three.RetailPrice
  1642. // hpt.ProjectId = three.ID
  1643. // hpt.FeedetlSn = ""
  1644. // hpt.PrescriptionId = last_prescriptions[index].ID
  1645. // hpt.Unit = three.PackingUnit
  1646. // hpt.Day = "1"
  1647. // hpt.SingleDose = "1"
  1648. // hpt.GoodInfo = three
  1649. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1650. //}
  1651. }
  1652. }
  1653. }
  1654. }
  1655. c.ServeSuccessJSON(map[string]interface{}{
  1656. "his_info": his_patient_info,
  1657. "xt_info": xt_patient_info,
  1658. "prescription": prescriptions,
  1659. "case_history": case_history,
  1660. "info": patientPrescriptionInfo,
  1661. //"month_prescriptions": monthPrescriptions,
  1662. "order": order,
  1663. "doctors": doctors,
  1664. "department": department,
  1665. "sch_prescriptions": sch_prescriptions,
  1666. "last_prescriptions": last_prescriptions,
  1667. "schedule": sch,
  1668. "count": count,
  1669. "drugStockConfig": drugStockConfig,
  1670. "last_info": lastPatientPrescriptionInfo,
  1671. "befor": beforThrity,
  1672. "LastCaseHistory": LastCaseHistory,
  1673. "prescriptionInfo": prescriptionInfo,
  1674. })
  1675. return
  1676. }
  1677. func (c *HisApiController) GetHisPrescriptionConfig() {
  1678. adminInfo := c.GetAdminUserInfo()
  1679. //获取医嘱模版
  1680. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1681. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1682. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1683. //获取所有基础药
  1684. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1685. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1686. if config.ID > 0 && config.IsOpen == 1 {
  1687. for _, item := range drugs {
  1688. var index = 0
  1689. for _, subItem := range item.OtherDrugWarehouseInfo {
  1690. if index == 0 {
  1691. index = index + 1
  1692. if subItem.RetailPrice > 0 {
  1693. item.MinPrice = subItem.RetailPrice
  1694. }
  1695. }
  1696. }
  1697. }
  1698. }
  1699. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1700. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1701. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1702. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1703. //获取所有科室信息
  1704. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1705. //获取诊断信息
  1706. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1707. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1708. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1709. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1710. //获取是否开启保存耗材出库的开关
  1711. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1712. c.ServeSuccessJSON(map[string]interface{}{
  1713. "drugs": drugs,
  1714. "advices_template": advices,
  1715. "drugways": drugways,
  1716. "efs": efs,
  1717. "doctors": doctors,
  1718. "department": department,
  1719. "sick": sick,
  1720. "additions": additions,
  1721. "diagnose": diagnose,
  1722. "manufacturers": manufacturers,
  1723. "goodOutOpen": goodOutOpen,
  1724. "patientDiagnose": patientDiagnose,
  1725. })
  1726. }
  1727. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1728. //获取所有基础药
  1729. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1730. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1731. if config.ID > 0 && config.IsOpen == 1 {
  1732. for _, item := range drugs {
  1733. var index = 0
  1734. for _, subItem := range item.OtherDrugWarehouseInfo {
  1735. if index == 0 {
  1736. index = index + 1
  1737. if subItem.RetailPrice > 0 {
  1738. item.MinPrice = subItem.RetailPrice
  1739. }
  1740. }
  1741. }
  1742. }
  1743. }
  1744. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1745. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1746. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1747. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1748. //获取所有科室信息
  1749. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1750. //获取诊断信息
  1751. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1752. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1753. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1754. //获取是否开启保存耗材出库的开关
  1755. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1756. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1757. c.ServeSuccessJSON(map[string]interface{}{
  1758. "drugs": drugs,
  1759. "advices_template": advices,
  1760. "drugways": drugways,
  1761. "efs": efs,
  1762. "doctors": doctors,
  1763. "department": department,
  1764. "sick": sick,
  1765. "additions": additions,
  1766. "diagnose": diagnose,
  1767. "manufacturers": manufacturers,
  1768. "goodOutOpen": goodOutOpen,
  1769. "patientDiagnose": patientDiagnose,
  1770. })
  1771. }
  1772. }
  1773. func (c *HisApiController) CreateHisPrescription() {
  1774. record_date := c.GetString("record_date")
  1775. patient_id, _ := c.GetInt64("patient_id")
  1776. reg_type, _ := c.GetInt64("reg_type")
  1777. diagnose := c.GetString("diagnose")
  1778. sick_type, _ := c.GetInt64("sick_type")
  1779. sick_history := c.GetString("sick_history")
  1780. doctor_id, _ := c.GetInt64("doctor", 0)
  1781. department, _ := c.GetInt64("department", 0)
  1782. his_patient_id, _ := c.GetInt64("his_patient_id")
  1783. p_type, _ := c.GetInt64("p_type")
  1784. patient_diagnose := c.GetString("patient_diagnose")
  1785. dataBody := make(map[string]interface{}, 0)
  1786. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1787. if err != nil {
  1788. utils.ErrorLog(err.Error())
  1789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1790. return
  1791. }
  1792. //edit, src := GetCompareData(dataBody)
  1793. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1794. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1795. //fmt.Println(drugResult)
  1796. //fmt.Println(goodResult)
  1797. timeLayout := "2006-01-02"
  1798. loc, _ := time.LoadLocation("Local")
  1799. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1800. if err != nil {
  1801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1802. return
  1803. }
  1804. adminInfo := c.GetAdminUserInfo()
  1805. recordDateTime := theTime.Unix()
  1806. //查询默认出库仓库库存
  1807. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1808. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1809. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1810. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1811. if len(lists) == 1 {
  1812. his_patient_id = lists[0].ID
  1813. }
  1814. }
  1815. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1816. //自动出库的开关开启
  1817. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1818. //自动出库
  1819. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1820. //耗材保存处方出库
  1821. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1822. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1823. //已发药和已收费限制逻辑
  1824. isMidicine := false
  1825. isCharge := false
  1826. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1827. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1828. if len(prescriptions) > 0 {
  1829. for _, item := range prescriptions {
  1830. items := item.(map[string]interface{})
  1831. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1832. utils.ErrorLog("id")
  1833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1834. return
  1835. }
  1836. id := int64(items["id"].(float64))
  1837. if id > 0 {
  1838. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1839. if err != nil {
  1840. if new_prescription.OrderStatus == 4 {
  1841. isCharge = true
  1842. }
  1843. }
  1844. }
  1845. }
  1846. }
  1847. }
  1848. if isMidicine == true {
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1850. return
  1851. }
  1852. if isCharge == true {
  1853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1854. return
  1855. }
  1856. // 开始主事务
  1857. db := service.XTWriteDB()
  1858. tx := db.Begin()
  1859. // 在函数结束时处理事务回滚
  1860. defer func() {
  1861. if r := recover(); r != nil {
  1862. tx.Rollback()
  1863. }
  1864. }()
  1865. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1866. //药品发药出库
  1867. if pharmacyConfig.IsOpen == 1 {
  1868. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1869. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1870. if len(prescriptions) > 0 {
  1871. for _, item := range prescriptions {
  1872. items := item.(map[string]interface{})
  1873. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1874. advices := items["advices"].([]interface{})
  1875. if len(advices) > 0 {
  1876. for _, advice := range advices {
  1877. var drug_id int64
  1878. var prescribing_number float64
  1879. var prescribingNumberUnit string
  1880. var adviceId int64
  1881. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1882. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1883. }
  1884. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1885. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1886. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1887. }
  1888. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1889. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1890. }
  1891. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1892. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1893. }
  1894. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1895. if drug.ID == 0 {
  1896. tx.Rollback()
  1897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1898. return
  1899. }
  1900. //查询药品的所有库存
  1901. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1902. var total_count int64
  1903. for _, it := range list {
  1904. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1905. }
  1906. totals := strconv.FormatInt(total_count, 10)
  1907. //查询该药品是否存在开药记录
  1908. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1909. //新增处方盘点库存是否充足
  1910. if advicelist.ID == 0 {
  1911. all_count, _ := strconv.ParseFloat(totals, 64)
  1912. if prescribingNumberUnit == drug.MinUnit {
  1913. if drug.IsUse != 1 {
  1914. if drug.IsProject == 0 || drug.IsProject == 2 {
  1915. if all_count == 0 {
  1916. tx.Rollback()
  1917. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1918. return
  1919. }
  1920. if prescribing_number > all_count {
  1921. tx.Rollback()
  1922. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1923. return
  1924. }
  1925. }
  1926. }
  1927. }
  1928. if prescribingNumberUnit == drug.MaxUnit {
  1929. num := prescribing_number * float64(drug.MinNumber)
  1930. if drug.IsUse != 1 {
  1931. if drug.IsProject == 0 || drug.IsProject == 2 {
  1932. if all_count == 0 {
  1933. tx.Rollback()
  1934. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1935. return
  1936. }
  1937. if num > all_count {
  1938. tx.Rollback()
  1939. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1940. return
  1941. }
  1942. }
  1943. }
  1944. }
  1945. }
  1946. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1947. //不使用保存处方出库
  1948. if drugOutConfig.IsOpen != 1 {
  1949. //修改处方
  1950. for _, advice := range advices {
  1951. var drug_id int64
  1952. var prescribing_number float64
  1953. var prescribingNumberUnit string
  1954. var prescribingNumber string
  1955. var adviceId int64
  1956. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1957. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1958. }
  1959. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1960. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1961. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1962. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1963. }
  1964. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1965. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1966. }
  1967. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1968. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1969. }
  1970. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1971. if drug.ID == 0 {
  1972. tx.Rollback()
  1973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1974. return
  1975. }
  1976. //查询药品的所有库存
  1977. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1978. var total_count int64
  1979. for _, it := range list {
  1980. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1981. }
  1982. totals := strconv.FormatInt(total_count, 10)
  1983. //查询该药品是否存在开药记录
  1984. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1985. //新增处方
  1986. if advicelist.ID == 0 {
  1987. all_count, _ := strconv.ParseFloat(totals, 64)
  1988. if prescribingNumberUnit == drug.MinUnit {
  1989. if drug.IsUse != 1 {
  1990. if drug.IsProject == 0 || drug.IsProject == 2 {
  1991. if all_count == 0 {
  1992. tx.Rollback()
  1993. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1994. return
  1995. }
  1996. if prescribing_number > all_count {
  1997. tx.Rollback()
  1998. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1999. return
  2000. }
  2001. }
  2002. }
  2003. } else {
  2004. if prescribingNumberUnit == drug.MaxUnit {
  2005. num := prescribing_number * float64(drug.MinNumber)
  2006. if drug.IsUse != 1 {
  2007. if drug.IsProject == 0 || drug.IsProject == 2 {
  2008. if all_count == 0 {
  2009. tx.Rollback()
  2010. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2011. return
  2012. }
  2013. if num > all_count {
  2014. tx.Rollback()
  2015. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2016. return
  2017. }
  2018. }
  2019. }
  2020. }
  2021. }
  2022. }
  2023. //修改处方
  2024. if advicelist.ID > 0 {
  2025. var device_number int64
  2026. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2027. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2028. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2029. device_number = prescribingNumberInt * drug.MinNumber
  2030. }
  2031. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2032. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2033. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2034. device_number = prescribingNumberInt
  2035. }
  2036. var number_count int64
  2037. if prescribingNumberUnit == drug.MaxUnit {
  2038. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2039. number_count = prescribingNumberInt * drug.MinNumber
  2040. }
  2041. if prescribingNumberUnit == drug.MinUnit {
  2042. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2043. number_count = prescribingNumberInt
  2044. }
  2045. //如果修改的数量大于之前修改的数量
  2046. if (number_count - device_number) > 0 {
  2047. //如果修改的差数量 大于库存数量
  2048. if drug.IsUse != 1 {
  2049. if (number_count - device_number) > total_count {
  2050. tx.Rollback()
  2051. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2052. return
  2053. }
  2054. }
  2055. }
  2056. }
  2057. }
  2058. }
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. }
  2066. //已发药和已收费限制逻辑
  2067. //执行出库的逻辑
  2068. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2069. //校验库存总量
  2070. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2071. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2072. if len(prescriptions) > 0 {
  2073. for _, item := range prescriptions {
  2074. items := item.(map[string]interface{})
  2075. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2076. advices := items["advices"].([]interface{})
  2077. if len(advices) > 0 {
  2078. for _, advice := range advices {
  2079. var drug_id int64
  2080. var prescribing_number float64
  2081. var prescribingNumberUnit string
  2082. var adviceId int64
  2083. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2084. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2085. }
  2086. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2087. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2088. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2089. }
  2090. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2091. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2092. }
  2093. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2094. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2095. }
  2096. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2097. if drug.ID == 0 {
  2098. tx.Rollback()
  2099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2100. return
  2101. }
  2102. //查询药品的所有库存
  2103. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2104. var total_count int64
  2105. for _, it := range list {
  2106. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2107. }
  2108. totals := strconv.FormatInt(total_count, 10)
  2109. //查询该药品是否存在开药记录
  2110. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2111. //查询最新批次库存
  2112. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2113. var batch_number_count int64
  2114. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2115. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2116. //新增处方
  2117. if advicelist.ID == 0 {
  2118. all_count, _ := strconv.ParseFloat(totals, 64)
  2119. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2120. if prescribingNumberUnit == drug.MinUnit {
  2121. if drug.IsUse != 1 {
  2122. if drug.IsProject == 0 || drug.IsProject == 2 {
  2123. if all_count == 0 {
  2124. tx.Rollback()
  2125. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2126. return
  2127. }
  2128. if prescribing_number > all_count {
  2129. tx.Rollback()
  2130. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2131. return
  2132. }
  2133. }
  2134. if adminInfo.CurrentOrgId == 10215 {
  2135. if prescribing_number > batch_number_all_count {
  2136. tx.Rollback()
  2137. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2138. return
  2139. }
  2140. }
  2141. }
  2142. }
  2143. if prescribingNumberUnit == drug.MaxUnit {
  2144. num := prescribing_number * float64(drug.MinNumber)
  2145. if drug.IsUse != 1 {
  2146. if drug.IsProject == 0 || drug.IsProject == 2 {
  2147. if all_count == 0 {
  2148. tx.Rollback()
  2149. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2150. return
  2151. }
  2152. if num > all_count {
  2153. tx.Rollback()
  2154. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2155. return
  2156. }
  2157. }
  2158. if adminInfo.CurrentOrgId == 10215 {
  2159. if num > batch_number_all_count {
  2160. tx.Rollback()
  2161. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2162. return
  2163. }
  2164. }
  2165. }
  2166. }
  2167. }
  2168. //不是保存处方出库
  2169. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2170. if drugOutConfig.IsOpen != 1 {
  2171. //修改处方
  2172. for _, advice := range advices {
  2173. var drug_id int64
  2174. var prescribing_number float64
  2175. var prescribingNumberUnit string
  2176. var prescribingNumber string
  2177. var adviceId int64
  2178. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2179. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2180. }
  2181. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2182. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2183. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2184. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2185. }
  2186. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2187. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2188. }
  2189. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2190. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2191. }
  2192. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2193. if drug.ID == 0 {
  2194. tx.Rollback()
  2195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2196. return
  2197. }
  2198. //查询药品的所有库存
  2199. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2200. var total_count int64
  2201. for _, it := range list {
  2202. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2203. }
  2204. totals := strconv.FormatInt(total_count, 10)
  2205. //查询该药品是否存在开药记录
  2206. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2207. //新增处方
  2208. if advicelist.ID == 0 {
  2209. //查询最新批次库存
  2210. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2211. var batch_number_count int64
  2212. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2213. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2214. all_count, _ := strconv.ParseFloat(totals, 64)
  2215. if all_count == 0 {
  2216. tx.Rollback()
  2217. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2218. return
  2219. }
  2220. if prescribingNumberUnit == drug.MinUnit {
  2221. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2222. if drug.IsUse != 1 {
  2223. if drug.IsProject == 0 || drug.IsProject == 2 {
  2224. if all_count == 0 {
  2225. tx.Rollback()
  2226. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2227. return
  2228. }
  2229. if prescribing_number > all_count {
  2230. tx.Rollback()
  2231. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2232. return
  2233. }
  2234. }
  2235. if adminInfo.CurrentOrgId == 10215 {
  2236. if prescribing_number > batch_number_all_count {
  2237. tx.Rollback()
  2238. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2239. return
  2240. }
  2241. }
  2242. }
  2243. } else {
  2244. if prescribingNumberUnit == drug.MaxUnit {
  2245. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2246. num := prescribing_number * float64(drug.MinNumber)
  2247. if drug.IsUse != 1 {
  2248. if drug.IsProject == 0 || drug.IsProject == 2 {
  2249. if all_count == 0 {
  2250. tx.Rollback()
  2251. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2252. return
  2253. }
  2254. if num > all_count {
  2255. tx.Rollback()
  2256. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2257. return
  2258. }
  2259. }
  2260. if adminInfo.CurrentOrgId == 10215 {
  2261. if prescribing_number > batch_number_all_count {
  2262. tx.Rollback()
  2263. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2264. return
  2265. }
  2266. }
  2267. }
  2268. }
  2269. }
  2270. }
  2271. //修改处方
  2272. if advicelist.ID > 0 {
  2273. //查询最新批次库存
  2274. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2275. var batch_number_count int64
  2276. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2277. var device_number int64
  2278. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2279. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2280. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2281. device_number = prescribingNumberInt * drug.MinNumber
  2282. }
  2283. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2284. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2285. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2286. device_number = prescribingNumberInt
  2287. //回退库存
  2288. }
  2289. var number_count int64
  2290. if prescribingNumberUnit == drug.MaxUnit {
  2291. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2292. number_count = prescribingNumberInt * drug.MinNumber
  2293. //回退库存
  2294. }
  2295. if prescribingNumberUnit == drug.MinUnit {
  2296. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2297. number_count = prescribingNumberInt
  2298. //回退库存
  2299. }
  2300. //如果修改的数量大于之前修改的数量
  2301. if (number_count - device_number) > 0 {
  2302. //如果修改的差数量 大于库存数量
  2303. if drug.IsUse != 1 {
  2304. if drug.IsProject == 0 || drug.IsProject == 2 {
  2305. if total_count == 0 {
  2306. tx.Rollback()
  2307. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2308. return
  2309. }
  2310. if (number_count - device_number) > total_count {
  2311. tx.Rollback()
  2312. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2313. return
  2314. }
  2315. if (number_count - device_number) > batch_number_count {
  2316. tx.Rollback()
  2317. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2318. return
  2319. }
  2320. }
  2321. if adminInfo.CurrentOrgId == 10215 {
  2322. // 查询该药品最后一次出库记录
  2323. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2324. var out_count int64
  2325. var in_count int64
  2326. var stock_max_number int64
  2327. var stock_min_number int64
  2328. for _, it := range outInfo {
  2329. if it.CountUnit == drug.MaxUnit {
  2330. it.Count = it.Count * drug.MinNumber
  2331. }
  2332. out_count += it.Count
  2333. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2334. stock_max_number = warehouseInfoList.StockMaxNumber
  2335. stock_min_number = warehouseInfoList.StockMinNumber
  2336. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2337. }
  2338. if out_count > 0 {
  2339. if (number_count - device_number) > in_count {
  2340. tx.Rollback()
  2341. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2342. return
  2343. }
  2344. }
  2345. // 未出库
  2346. if out_count == 0 {
  2347. var sum_in_count int64
  2348. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2349. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2350. //如果修改的数量大于有库存的第一个批次
  2351. if number_count > sum_in_count {
  2352. tx.Rollback()
  2353. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2354. return
  2355. }
  2356. }
  2357. }
  2358. }
  2359. }
  2360. //药品发药
  2361. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2362. //不使用药品发药的功能
  2363. //if pharmacyConfig.IsOpen != 1 {
  2364. // if device_number != number_count {
  2365. //
  2366. // //查询该药品的出库记录
  2367. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2368. // if len(outListExport) > 0 {
  2369. // //
  2370. // for _, item := range outListExport {
  2371. // //回退库存
  2372. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2373. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2374. // }
  2375. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2376. // var stock_max_number int64
  2377. // var stock_min_number int64
  2378. //
  2379. // if number_count >= drug.MinNumber {
  2380. //
  2381. // stock_max_number = device_number / drug.MinNumber
  2382. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2383. //
  2384. // stock_min_number = device_number % drug.MinNumber
  2385. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2386. //
  2387. // } else {
  2388. //
  2389. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2390. //
  2391. // }
  2392. // }
  2393. //
  2394. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2395. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2396. // }
  2397. // }
  2398. // }
  2399. //
  2400. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2401. // var sum_count int64
  2402. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2403. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2404. // for _, its := range stockInfo {
  2405. // if its.MaxUnit == drug.MaxUnit {
  2406. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2407. // }
  2408. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2409. // }
  2410. // //更新字典里面的库存
  2411. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2412. //
  2413. // //剩余库存
  2414. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2415. //
  2416. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2417. // //减少出库数量
  2418. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2419. //
  2420. // }
  2421. //}
  2422. }
  2423. }
  2424. }
  2425. //保存处方开药
  2426. if drugOutConfig.IsOpen == 1 {
  2427. //修改处方
  2428. for _, advice := range advices {
  2429. var drug_id int64
  2430. var prescribing_number float64
  2431. var prescribingNumberUnit string
  2432. var prescribingNumber string
  2433. var adviceId int64
  2434. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2435. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2436. }
  2437. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2438. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2439. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2440. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2441. }
  2442. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2443. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2444. }
  2445. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2446. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2447. }
  2448. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2449. if drug.ID == 0 {
  2450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2451. return
  2452. }
  2453. //查询药品的所有库存
  2454. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2455. var total_count int64
  2456. for _, it := range list {
  2457. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2458. }
  2459. totals := strconv.FormatInt(total_count, 10)
  2460. //查询该药品是否存在开药记录
  2461. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2462. //新增处方
  2463. if advicelist.ID == 0 {
  2464. //查询最新批次库存
  2465. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2466. var batch_number_count int64
  2467. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2468. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2469. all_count, _ := strconv.ParseFloat(totals, 64)
  2470. if prescribingNumberUnit == drug.MinUnit {
  2471. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2472. if drug.IsUse != 1 {
  2473. if drug.IsProject == 0 || drug.IsProject == 2 {
  2474. if all_count == 0 {
  2475. tx.Rollback()
  2476. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2477. return
  2478. }
  2479. if prescribing_number > all_count {
  2480. tx.Rollback()
  2481. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2482. return
  2483. }
  2484. }
  2485. if adminInfo.CurrentOrgId == 10215 {
  2486. if prescribing_number > batch_number_all_count {
  2487. tx.Rollback()
  2488. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2489. return
  2490. }
  2491. }
  2492. }
  2493. } else {
  2494. if prescribingNumberUnit == drug.MaxUnit {
  2495. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2496. num := prescribing_number * float64(drug.MinNumber)
  2497. if drug.IsUse != 1 {
  2498. if drug.IsProject == 0 || drug.IsProject == 2 {
  2499. if all_count == 0 {
  2500. tx.Rollback()
  2501. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2502. return
  2503. }
  2504. if num > all_count {
  2505. tx.Rollback()
  2506. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2507. return
  2508. }
  2509. }
  2510. if adminInfo.CurrentOrgId == 10215 {
  2511. if prescribing_number > batch_number_all_count {
  2512. tx.Rollback()
  2513. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2514. return
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. //修改处方
  2522. if advicelist.ID > 0 {
  2523. //查询最新批次库存
  2524. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2525. var batch_number_count int64
  2526. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2527. var device_number int64
  2528. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2529. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2530. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2531. device_number = prescribingNumberInt * drug.MinNumber
  2532. }
  2533. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2534. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2535. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2536. device_number = prescribingNumberInt
  2537. }
  2538. var number_count int64
  2539. if prescribingNumberUnit == drug.MaxUnit {
  2540. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2541. number_count = prescribingNumberInt * drug.MinNumber
  2542. }
  2543. if prescribingNumberUnit == drug.MinUnit {
  2544. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2545. number_count = prescribingNumberInt
  2546. }
  2547. //如果修改的数量大于之前修改的数量
  2548. if (number_count - device_number) > 0 {
  2549. //如果修改的差数量 大于库存数量
  2550. if drug.IsUse != 1 {
  2551. if drug.IsProject == 0 || drug.IsProject == 2 {
  2552. if total_count == 0 {
  2553. tx.Rollback()
  2554. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2555. return
  2556. }
  2557. if (number_count - device_number) > total_count {
  2558. tx.Rollback()
  2559. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2560. return
  2561. }
  2562. }
  2563. if adminInfo.CurrentOrgId == 10215 {
  2564. if (number_count - device_number) > batch_number_count {
  2565. tx.Rollback()
  2566. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2567. return
  2568. }
  2569. }
  2570. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2571. //查询历史出库数据总批次
  2572. // 查询该药品最后一次出库记录
  2573. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2574. var out_count int64
  2575. var in_count int64
  2576. var stock_max_number int64
  2577. var stock_min_number int64
  2578. for _, it := range outInfo {
  2579. if it.CountUnit == drug.MaxUnit {
  2580. it.Count = it.Count * drug.MinNumber
  2581. }
  2582. out_count += it.Count
  2583. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2584. stock_max_number = warehouseInfoList.StockMaxNumber
  2585. stock_min_number = warehouseInfoList.StockMinNumber
  2586. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2587. }
  2588. if out_count > 0 {
  2589. if (number_count - device_number) > in_count {
  2590. tx.Rollback()
  2591. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2592. return
  2593. }
  2594. }
  2595. // 未出库
  2596. if out_count == 0 {
  2597. var sum_in_count int64
  2598. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2599. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2600. if sum_in_count == 0 {
  2601. tx.Rollback()
  2602. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2603. return
  2604. }
  2605. //如果修改的数量大于有库存的第一个批次
  2606. if number_count > sum_in_count {
  2607. tx.Rollback()
  2608. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2609. return
  2610. }
  2611. }
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. }
  2619. }
  2620. }
  2621. }
  2622. }
  2623. }
  2624. }
  2625. //校验耗材库存
  2626. if goodOutConfig.IsOpen == 1 {
  2627. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2628. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2629. if len(prescriptions) > 0 {
  2630. for _, item := range prescriptions {
  2631. items := item.(map[string]interface{})
  2632. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2633. projects := items["project"].([]interface{})
  2634. if len(projects) > 0 {
  2635. for _, project := range projects {
  2636. var project_id int64
  2637. var project_type int64
  2638. var totals float64
  2639. var project_name string
  2640. var parsetotal int64
  2641. var id int64
  2642. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2643. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2644. }
  2645. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2646. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2647. }
  2648. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2649. total, _ := project.(map[string]interface{})["total"].(string)
  2650. totals, _ = strconv.ParseFloat(total, 64)
  2651. }
  2652. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2653. project_name = project.(map[string]interface{})["project_name"].(string)
  2654. }
  2655. if project_type == 3 {
  2656. //查找该耗材的出库记录
  2657. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2658. if len(goodWarehouseInfo) == 0 {
  2659. //查询耗材库存
  2660. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2661. var stock_count int64
  2662. for _, it := range list {
  2663. stock_count += it.StockCount
  2664. }
  2665. stock_counts := strconv.FormatInt(stock_count, 10)
  2666. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2667. if stock_total_count == 0 {
  2668. tx.Rollback()
  2669. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2670. return
  2671. }
  2672. if totals > stock_total_count {
  2673. tx.Rollback()
  2674. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2675. return
  2676. }
  2677. }
  2678. if len(goodWarehouseInfo) > 0 {
  2679. //查询该患者耗材的历史数据
  2680. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2681. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2682. //数量发生改变
  2683. if parsetotal != count {
  2684. //如果现在的数量大于历史数量,就要看库存是否足够
  2685. if parsetotal > count {
  2686. //查询耗材所有库存
  2687. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2688. var stock_count int64
  2689. for _, it := range list {
  2690. stock_count += it.StockCount
  2691. }
  2692. //库存不足
  2693. if stock_count == 0 {
  2694. tx.Rollback()
  2695. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2696. return
  2697. }
  2698. if (parsetotal - count) > stock_count {
  2699. tx.Rollback()
  2700. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2701. return
  2702. }
  2703. }
  2704. }
  2705. }
  2706. }
  2707. }
  2708. }
  2709. }
  2710. }
  2711. }
  2712. }
  2713. }
  2714. //不使用耗材保存处方出库
  2715. if goodOutConfig.IsOpen != 1 {
  2716. if stockConfig.IsOpen == 1 {
  2717. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2718. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2719. if len(prescriptions) > 0 {
  2720. for _, item := range prescriptions {
  2721. items := item.(map[string]interface{})
  2722. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2723. projects := items["project"].([]interface{})
  2724. if len(projects) > 0 {
  2725. for _, project := range projects {
  2726. var project_id int64
  2727. var project_type int64
  2728. var totals float64
  2729. var project_name string
  2730. var parsetotal int64
  2731. var id int64
  2732. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2733. id = int64(project.(map[string]interface{})["id"].(float64))
  2734. }
  2735. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2736. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2737. }
  2738. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2739. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2740. }
  2741. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2742. total, _ := project.(map[string]interface{})["total"].(string)
  2743. totals, _ = strconv.ParseFloat(total, 64)
  2744. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2745. }
  2746. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2747. project_name = project.(map[string]interface{})["project_name"].(string)
  2748. }
  2749. if project_type == 3 {
  2750. //查找该耗材的出库记录
  2751. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2752. //没有出库记录
  2753. if len(goodWarehouseInfo) == 0 {
  2754. //查询耗材库存
  2755. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2756. var stock_count int64
  2757. for _, it := range list {
  2758. stock_count += it.StockCount
  2759. }
  2760. stock_counts := strconv.FormatInt(stock_count, 10)
  2761. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2762. if stock_total_count == 0 {
  2763. tx.Rollback()
  2764. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2765. return
  2766. }
  2767. if totals > stock_total_count {
  2768. tx.Rollback()
  2769. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2770. return
  2771. }
  2772. //查找今日该患者已经出库的所有耗材
  2773. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2774. for _, item := range goodList {
  2775. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2776. var flush_count int64
  2777. for _, it := range goodListSix {
  2778. flush_count += it.StockCount
  2779. }
  2780. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2781. creater := adminInfo.AdminUser.Id
  2782. if errs != nil {
  2783. goodErrcode := models.XtGoodErrcode{
  2784. UserOrgId: item.OrgId,
  2785. Errcode: "手动出库更新剩余出库失败",
  2786. GoodId: item.GoodId,
  2787. Status: 1,
  2788. Ctime: time.Now().Unix(),
  2789. Mtime: 0,
  2790. Count: 0,
  2791. StockCount: 0,
  2792. Creater: creater,
  2793. BatchNumberId: 0,
  2794. WarehouseOutId: 0,
  2795. }
  2796. service.CreateGoodErrcode(goodErrcode)
  2797. }
  2798. }
  2799. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2800. }
  2801. //有出库记录
  2802. if len(goodWarehouseInfo) > 0 {
  2803. //查询该患者耗材的历史数据
  2804. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2805. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2806. //数量发生改变
  2807. if parsetotal != count {
  2808. //查找今日该患者已经出库的所有耗材
  2809. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2810. for _, item := range goodList {
  2811. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2812. var flush_count int64
  2813. for _, it := range goodListSix {
  2814. flush_count += it.StockCount
  2815. }
  2816. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2817. //减少出库数量
  2818. creater := adminInfo.AdminUser.Id
  2819. if errs != nil {
  2820. goodErrcode := models.XtGoodErrcode{
  2821. UserOrgId: item.OrgId,
  2822. Errcode: "手动出库更新剩余出库失败",
  2823. GoodId: item.GoodId,
  2824. Status: 1,
  2825. Ctime: time.Now().Unix(),
  2826. Mtime: 0,
  2827. Count: 0,
  2828. StockCount: 0,
  2829. Creater: creater,
  2830. BatchNumberId: 0,
  2831. WarehouseOutId: 0,
  2832. }
  2833. service.CreateGoodErrcode(goodErrcode)
  2834. }
  2835. //查询默认仓库
  2836. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2837. var total_count int64
  2838. for _, it := range stockList {
  2839. total_count += it.StockCount
  2840. }
  2841. //基础库插入数据
  2842. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2843. }
  2844. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2845. }
  2846. }
  2847. }
  2848. }
  2849. }
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2857. var hpInfo models.HisPrescriptionInfo
  2858. if info.ID == 0 {
  2859. var randNum int
  2860. randNum = rand.Intn(10000) + 1000
  2861. timestamp := time.Now().Unix()
  2862. tempTime := time.Unix(timestamp, 0)
  2863. timeFormat := tempTime.Format("20060102150405")
  2864. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2865. hpInfo = models.HisPrescriptionInfo{
  2866. HisPatientId: his_patient_id,
  2867. UserOrgId: adminInfo.CurrentOrgId,
  2868. RecordDate: theTime.Unix(),
  2869. PatientId: patient_id,
  2870. Status: 1,
  2871. Ctime: time.Now().Unix(),
  2872. Mtime: time.Now().Unix(),
  2873. Creator: adminInfo.AdminUser.Id,
  2874. Modifier: adminInfo.AdminUser.Id,
  2875. Diagnosis: diagnose,
  2876. SickHistory: sick_history,
  2877. Departments: department,
  2878. RegisterType: reg_type,
  2879. PrescriptionNumber: p_number,
  2880. PrescriptionStatus: 1,
  2881. Doctor: role.UserName,
  2882. DoctorId: doctor_id,
  2883. SickType: sick_type,
  2884. PType: p_type,
  2885. PatientDiagnosis: patient_diagnose,
  2886. }
  2887. service.SavePatientPrescriptionInfo(hpInfo)
  2888. //创建步骤表
  2889. finish := models.XtDialysisFinish{
  2890. IsFinish: 1,
  2891. UserOrgId: adminInfo.CurrentOrgId,
  2892. Status: 1,
  2893. Ctime: time.Now().Unix(),
  2894. Mtime: 0,
  2895. Module: 4,
  2896. RecordDate: theTime.Unix(),
  2897. Sourse: 1,
  2898. PatientId: patient_id,
  2899. }
  2900. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2901. if dialysisFinish.ID == 0 {
  2902. service.CreateDialysisFinish(finish)
  2903. }
  2904. redis := service.RedisClient()
  2905. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2906. redis.Set(key, "", time.Second)
  2907. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2908. redis.Set(keyOne, "", time.Second)
  2909. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2910. redis.Set(keySeven, "", time.Second)
  2911. defer redis.Close()
  2912. } else {
  2913. hpInfo = models.HisPrescriptionInfo{
  2914. ID: info.ID,
  2915. UserOrgId: adminInfo.CurrentOrgId,
  2916. RecordDate: info.RecordDate,
  2917. PatientId: info.PatientId,
  2918. Status: 1,
  2919. Ctime: info.Ctime,
  2920. Mtime: time.Now().Unix(),
  2921. Creator: info.Creator,
  2922. Modifier: adminInfo.AdminUser.Id,
  2923. Diagnosis: diagnose,
  2924. SickHistory: sick_history,
  2925. Departments: department,
  2926. RegisterType: reg_type,
  2927. PrescriptionNumber: info.PrescriptionNumber,
  2928. Doctor: role.UserName,
  2929. PrescriptionStatus: info.PrescriptionStatus,
  2930. DoctorId: doctor_id,
  2931. SickType: sick_type,
  2932. PType: info.PType,
  2933. HisPatientId: info.HisPatientId,
  2934. PatientDiagnosis: patient_diagnose,
  2935. }
  2936. service.SavePatientPrescriptionInfo(hpInfo)
  2937. //创建步骤表
  2938. finish := models.XtDialysisFinish{
  2939. IsFinish: 1,
  2940. UserOrgId: adminInfo.CurrentOrgId,
  2941. Status: 1,
  2942. Ctime: time.Now().Unix(),
  2943. Mtime: 0,
  2944. Module: 4,
  2945. RecordDate: info.RecordDate,
  2946. Sourse: 1,
  2947. PatientId: info.PatientId,
  2948. }
  2949. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2950. if dialysisFinish.ID == 0 {
  2951. service.CreateDialysisFinish(finish)
  2952. }
  2953. redis := service.RedisClient()
  2954. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2955. redis.Set(key, "", time.Second)
  2956. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2957. redis.Set(keyOne, "", time.Second)
  2958. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2959. redis.Set(keySeven, "", time.Second)
  2960. defer redis.Close()
  2961. }
  2962. //定义切片
  2963. var adviceList []models.HisDoctorAdviceInfo
  2964. var projectList []models.HisPrescriptionProject
  2965. 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 {
  2966. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2967. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2968. var tempPrescription *models.HisPrescription
  2969. if len(prescriptions) > 0 {
  2970. for _, item := range prescriptions {
  2971. // 开始外部循环的事务
  2972. tx := db.Begin()
  2973. // 在函数结束时处理事务回滚
  2974. defer func() {
  2975. if r := recover(); r != nil {
  2976. tx.Rollback()
  2977. }
  2978. }()
  2979. items := item.(map[string]interface{})
  2980. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2981. utils.ErrorLog("id")
  2982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2983. return
  2984. }
  2985. id := int64(items["id"].(float64))
  2986. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2987. tempPrescription = &new_prescription
  2988. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2989. utils.ErrorLog("type")
  2990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2991. return
  2992. }
  2993. types := int64(items["type"].(float64))
  2994. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2995. utils.ErrorLog("med_type")
  2996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2997. return
  2998. }
  2999. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3000. if med_type == "0" {
  3001. med_type = "14"
  3002. }
  3003. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3004. // utils.ErrorLog("diagnoses")
  3005. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3006. // return
  3007. //}
  3008. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3009. diagnoses, _ := items["diagnoses"].(string)
  3010. //if order_status == 0 {
  3011. // order_status = 1
  3012. //}
  3013. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3014. utils.ErrorLog("pre_time")
  3015. }
  3016. preTime, _ := items["pre_time"].(string)
  3017. fmt.Println("preTime", preTime)
  3018. timeLayout := "2006-01-02"
  3019. loc, _ := time.LoadLocation("Local")
  3020. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3021. //result := strings.Split(preTime, " ")
  3022. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3023. if err != nil {
  3024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3025. return
  3026. }
  3027. pTime := theTime2.Unix()
  3028. ctime := time.Now().Unix()
  3029. if tempPrescription.ID == 0 {
  3030. prescription := &models.HisPrescription{
  3031. ID: 0,
  3032. PatientId: patient_id,
  3033. UserOrgId: adminInfo.CurrentOrgId,
  3034. RecordDate: recordDateTime,
  3035. Ctime: ctime,
  3036. Mtime: ctime,
  3037. Type: types,
  3038. Modifier: adminInfo.AdminUser.Id,
  3039. Creator: adminInfo.AdminUser.Id,
  3040. Status: 1,
  3041. Doctor: role.UserName,
  3042. HisPatientId: his_patient_id,
  3043. OrderStatus: 1,
  3044. BatchNumber: "",
  3045. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3046. PreTime: pTime,
  3047. PType: p_type,
  3048. MedType: med_type,
  3049. Diagnose: diagnoses,
  3050. }
  3051. tempPrescription = prescription
  3052. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3053. redis := service.RedisClient()
  3054. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3055. redis.Set(key, "", time.Second)
  3056. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3057. redis.Set(keyOne, "", time.Second)
  3058. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3059. redis.Set(keySeven, "", time.Second)
  3060. defer redis.Close()
  3061. } else {
  3062. tempPrescription.ID = id
  3063. tempPrescription.Type = types
  3064. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3065. tempPrescription.Mtime = time.Now().Unix()
  3066. tempPrescription.Doctor = role.UserName
  3067. //tempPrescription.OrderStatus = order_status
  3068. tempPrescription.PreTime = pTime
  3069. tempPrescription.MedType = med_type
  3070. tempPrescription.Diagnose = diagnoses
  3071. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3072. redis := service.RedisClient()
  3073. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3074. redis.Set(key, "", time.Second)
  3075. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3076. redis.Set(keyOne, "", time.Second)
  3077. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3078. redis.Set(keySeven, "", time.Second)
  3079. defer redis.Close()
  3080. }
  3081. //service.SaveHisPrescription(prescription)
  3082. //更改患者挂号状态
  3083. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3084. fmt.Println("更改失败", err2)
  3085. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3086. advices := items["advices"].([]interface{})
  3087. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3088. groupNo := int64(0)
  3089. if len(advices) > 0 {
  3090. for _, advice := range advices {
  3091. tx := db.Begin()
  3092. // 在函数结束时处理事务回滚
  3093. defer func() {
  3094. if r := recover(); r != nil {
  3095. tx.Rollback()
  3096. }
  3097. }()
  3098. var s models.HisDoctorAdviceInfo
  3099. s.PrescriptionId = tempPrescription.ID
  3100. s.AdviceType = 2
  3101. s.AdviceDoctor = doctor_id
  3102. s.StopState = 2
  3103. s.ExecutionState = 2
  3104. s.AdviceDate = theTime3.Unix()
  3105. s.Status = 1
  3106. s.UserOrgId = adminInfo.CurrentOrgId
  3107. s.RecordDate = theTime3.Unix()
  3108. s.StartTime = tempPrescription.PreTime
  3109. s.Groupno = groupNo
  3110. s.PatientId = patient_id
  3111. s.HisPatientId = his_patient_id
  3112. s.StartTime = pTime
  3113. s.IsSettle = 2
  3114. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3115. if errcode > 0 {
  3116. c.ServeFailJSONWithSGJErrorCode(errcode)
  3117. return
  3118. }
  3119. s.StartTime = pTime
  3120. var total_count int64 //处方总库存
  3121. //查询改药品信息
  3122. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3123. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3124. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3125. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3126. total_count += prescribingNumberSeven * medical.MinNumber
  3127. }
  3128. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3129. total_count += prescribingNumberSeven
  3130. }
  3131. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3132. total_count += prescribingNumberSeven
  3133. }
  3134. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3135. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3136. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3137. if s.Price != lastWarehouse.RetailPrice {
  3138. s.Price = lastWarehouse.RetailPrice
  3139. }
  3140. if s.Price == 0 {
  3141. if lastWarehouse.ID == 0 {
  3142. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3143. s.Price = lastWarehouseTwo.RetailPrice
  3144. }
  3145. }
  3146. }
  3147. //查询保存处方出库开关是否打开
  3148. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3149. if s.PatientId != 30038 {
  3150. if drugOutConfig.IsOpen == 1 {
  3151. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3152. // 查询该药品最后一次出库记录
  3153. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3154. var is_user_total int64
  3155. var no_user_total int64
  3156. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3157. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3158. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3159. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3160. }
  3161. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3162. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3163. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3164. no_user_total += prescribingNumberSevenTy
  3165. }
  3166. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3167. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3168. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3169. no_user_total += prescribingNumberSevenTy
  3170. }
  3171. if len(druginfo) > 0 {
  3172. for _, it := range druginfo {
  3173. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3174. it.Count = it.Count * drug.MinNumber
  3175. is_user_total += it.Count
  3176. }
  3177. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3178. is_user_total += it.Count
  3179. }
  3180. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3181. is_user_total += it.Count
  3182. }
  3183. }
  3184. }
  3185. //fmt.Println("药品名称----------------------", drug.DrugName)
  3186. //fmt.Println("药品名称----------------------", drug.IsUse)
  3187. //fmt.Println("is_user_total-------------------------", is_user_total)
  3188. //fmt.Println("no_user_total-------------------------", no_user_total)
  3189. if is_user_total != no_user_total {
  3190. //出库
  3191. if drug.IsUse == 2 {
  3192. creater := adminInfo.AdminUser.Id
  3193. newadviceInfo := &models.HisDoctorAdviceInfo{
  3194. ID: s.ID,
  3195. UserOrgId: s.UserOrgId,
  3196. PatientId: s.PatientId,
  3197. HisPatientId: s.HisPatientId,
  3198. AdviceType: s.AdviceType,
  3199. AdviceDate: s.AdviceDate,
  3200. StartTime: s.StartTime,
  3201. AdviceName: s.AdviceName,
  3202. AdviceDesc: s.AdviceDesc,
  3203. ReminderDate: s.ReminderDate,
  3204. SingleDose: s.SingleDose,
  3205. SingleDoseUnit: s.SingleDoseUnit,
  3206. PrescribingNumber: s.PrescribingNumber,
  3207. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3208. DeliveryWay: s.DeliveryWay,
  3209. ExecutionFrequency: s.ExecutionFrequency,
  3210. AdviceDoctor: s.AdviceDoctor,
  3211. Status: s.Status,
  3212. CreatedTime: s.CreatedTime,
  3213. UpdatedTime: s.UpdatedTime,
  3214. AdviceAffirm: s.AdviceAffirm,
  3215. Remark: s.Remark,
  3216. StopTime: s.StopTime,
  3217. StopReason: s.StopReason,
  3218. StopDoctor: s.StopDoctor,
  3219. StopState: s.StopState,
  3220. ParentId: s.ParentId,
  3221. ExecutionTime: s.ExecutionTime,
  3222. ExecutionStaff: s.ExecutionStaff,
  3223. ExecutionState: s.ExecutionState,
  3224. Checker: s.Checker,
  3225. RecordDate: s.RecordDate,
  3226. DialysisOrderId: s.DialysisOrderId,
  3227. CheckTime: s.CheckTime,
  3228. CheckState: s.CheckState,
  3229. DrugSpec: s.DrugSpec,
  3230. DrugSpecUnit: s.DrugSpecUnit,
  3231. Groupno: s.Groupno,
  3232. RemindType: s.RemindType,
  3233. FrequencyType: s.FrequencyType,
  3234. DayCount: s.DayCount,
  3235. WeekDay: s.WeekDay,
  3236. TemplateId: s.TemplateId,
  3237. Modifier: s.Modifier,
  3238. DrugId: s.DrugId,
  3239. Price: s.Price,
  3240. PrescriptionId: s.PrescriptionId,
  3241. MedListCodg: s.MedListCodg,
  3242. FeedetlSn: s.FeedetlSn,
  3243. Day: s.DayCount,
  3244. ChildDoctorAdvice: nil,
  3245. Drug: models.Drug{},
  3246. Diagnosis: s.Diagnosis,
  3247. Way: s.Way,
  3248. HospApprFlag: s.HospApprFlag,
  3249. LmtUsedFlag: s.LmtUsedFlag,
  3250. HisOrderInfo: models.HisOrderInfo{},
  3251. IsMedicine: s.IsMedicine,
  3252. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3253. Child: nil,
  3254. IsSettle: s.IsSettle,
  3255. IsMobile: s.IsMobile,
  3256. IsSelfDrug: s.IsSelfDrug,
  3257. DrugWayCount: s.DrugWayCount,
  3258. }
  3259. var history_count int64
  3260. var local_count int64
  3261. //查找已经开过的医嘱信息
  3262. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  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. local_count += 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. local_count += 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. local_count += prescribingNumberSevenTy
  3277. }
  3278. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3279. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3280. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3281. history_count += prescribingNumberSevenTy * drug.MinNumber
  3282. }
  3283. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3284. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3285. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3286. history_count += prescribingNumberSevenTy
  3287. }
  3288. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3289. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3290. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3291. history_count += prescribingNumberSevenTy
  3292. }
  3293. //如果当前出库数量大于历史出库数量则需要出库
  3294. if local_count > history_count {
  3295. //按最小单位出库
  3296. var cha_count = local_count - history_count
  3297. newadviceInfo.PrescribingNumber = float64(cha_count)
  3298. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3299. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3300. }
  3301. //如果当前出库数量小于历史出库数量则需要退库
  3302. if local_count < history_count {
  3303. var cha_count = history_count - local_count
  3304. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3305. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3306. }
  3307. if local_count == history_count {
  3308. if is_user_total == 0 {
  3309. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3310. }
  3311. }
  3312. }
  3313. //更新字典里面的库存
  3314. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3315. var sum_count int64
  3316. for _, its := range stockInfo {
  3317. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3318. if its.MaxUnit == baseDrug.MaxUnit {
  3319. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3320. }
  3321. sum_count += its.StockMaxNumber + its.StockMinNumber
  3322. }
  3323. //更新基础库存
  3324. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3325. //剩余库存
  3326. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3327. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3328. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3329. //创建医嘱
  3330. service.CreateHisDoctorAdviceOne(&s, tx)
  3331. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3332. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3333. if len(outInfoTwo) > 0 {
  3334. for _, item := range outInfoTwo {
  3335. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3336. }
  3337. }
  3338. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3339. if len(drugAutoDetail) > 0 {
  3340. for _, item := range drugAutoDetail {
  3341. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3342. }
  3343. }
  3344. }
  3345. }
  3346. }
  3347. //记录日志
  3348. byterequest, _ := json.Marshal(s)
  3349. adviceLog := models.XtDoctorAdviceLog{
  3350. UserOrgId: s.UserOrgId,
  3351. PatientId: s.PatientId,
  3352. AdminUserId: adminInfo.AdminUser.Id,
  3353. Module: 1,
  3354. ErrLog: string(byterequest),
  3355. Status: 1,
  3356. Ctime: time.Now().Unix(),
  3357. Mtime: 0,
  3358. Source: "电脑端新建his医嘱",
  3359. RecordDate: s.AdviceDate,
  3360. }
  3361. service.CreateDoctorAdviceLog(adviceLog)
  3362. //存储切片中
  3363. adviceList = append(adviceList, s)
  3364. redis := service.RedisClient()
  3365. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3366. redis.Set(key, "", time.Second)
  3367. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3368. redis.Set(keyOne, "", time.Second)
  3369. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3370. redis.Set(keySeven, "", time.Second)
  3371. var randNum int
  3372. randNum = rand.Intn(10000) + 1000
  3373. timestamp := time.Now().Unix()
  3374. tempTime := time.Unix(timestamp, 0)
  3375. timeFormat := tempTime.Format("20060102150405")
  3376. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3377. if s.UserOrgId != 10206 {
  3378. if s.ID == 0 {
  3379. //查询改药品是否已经停用
  3380. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3381. if base.ID > 0 {
  3382. tx.Rollback()
  3383. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3384. return
  3385. }
  3386. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3387. if drugMedical.SumCount == 0 {
  3388. tx.Rollback()
  3389. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3390. return
  3391. }
  3392. }
  3393. }
  3394. //赤峰
  3395. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3396. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3397. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3398. if info.RetailPrice > 0 {
  3399. if s.DeliveryWay == "口服" {
  3400. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3401. s.Price = drug.RetailPrice
  3402. }
  3403. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3404. s.Price = info.RetailPrice
  3405. }
  3406. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3407. s.Price = info.RetailPrice
  3408. }
  3409. }
  3410. }
  3411. }
  3412. service.CreateHisDoctorAdviceOne(&s, tx)
  3413. tx.Commit()
  3414. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3415. redis.Set(keySix, "", time.Second)
  3416. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3417. redis.Set(keyFive, "", time.Second)
  3418. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3419. redis.Set(keyEight, "", time.Second)
  3420. defer redis.Close()
  3421. }
  3422. }
  3423. }
  3424. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3425. projects := items["project"].([]interface{})
  3426. if len(projects) > 0 {
  3427. for _, project := range projects {
  3428. tx := db.Begin()
  3429. // 在函数结束时处理事务回滚
  3430. defer func() {
  3431. if r := recover(); r != nil {
  3432. tx.Rollback()
  3433. }
  3434. }()
  3435. var p models.HisPrescriptionProject
  3436. p.PrescriptionId = tempPrescription.ID
  3437. p.PatientId = patient_id
  3438. p.RecordDate = theTime3.Unix()
  3439. p.Doctor = doctor_id
  3440. p.UserOrgId = adminInfo.CurrentOrgId
  3441. p.HisPatientId = his_patient_id
  3442. p.Status = 1
  3443. p.StartTime = pTime
  3444. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3445. if errcode > 0 {
  3446. tx.Rollback()
  3447. c.ServeFailJSONWithSGJErrorCode(errcode)
  3448. return
  3449. }
  3450. if p.ID == 0 {
  3451. p.IsOut = 2
  3452. }
  3453. if p.ID > 0 {
  3454. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3455. p.IsOut = projectDetail.IsOut
  3456. }
  3457. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3458. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3459. if p.Type == 3 {
  3460. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3461. if p.Price != lastWarehouse.PackingPrice {
  3462. p.Price = lastWarehouse.PackingPrice
  3463. }
  3464. if p.Price == 0 {
  3465. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3466. p.Price = lastWarehouseTwo.PackingPrice
  3467. }
  3468. if p.Unit == "" {
  3469. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3470. p.Unit = goodInfoOne.PackingUnit
  3471. }
  3472. }
  3473. }
  3474. if adminInfo.CurrentOrgId != 10206 {
  3475. if p.Type == 3 {
  3476. if p.ID == 0 {
  3477. //查询该耗材是否停用
  3478. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3479. //表示该耗材已经停用,不能保存
  3480. if goodInfoSeven.ID == 0 {
  3481. tx.Rollback()
  3482. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3483. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3484. return
  3485. }
  3486. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3487. if goodInfoOne.SumCount == 0 {
  3488. tx.Rollback()
  3489. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3490. return
  3491. }
  3492. }
  3493. }
  3494. }
  3495. //查询保存耗材出库开关是否打开
  3496. if p.PatientId != 30038 {
  3497. //用机构ID区分
  3498. if adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10164 {
  3499. if goodOutConfig.IsOpen == 1 {
  3500. //耗材出库
  3501. if p.Type == 3 {
  3502. //对比当前数据和历史出库数据
  3503. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3504. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3505. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3506. //如果当前处方数量大于历史数据,则需要出库
  3507. if nowCount > historyCount {
  3508. var cha_count int64
  3509. cha_count = nowCount - historyCount
  3510. timeStr := time.Now().Format("2006-01-02")
  3511. timeArr := strings.Split(timeStr, "-")
  3512. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3513. total = total + 1
  3514. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3515. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3516. number = number + total
  3517. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3518. operation_time := time.Now().Unix()
  3519. creater := c.GetAdminUserInfo().AdminUser.Id
  3520. recordDateStr := time.Now().Format("2006-01-02")
  3521. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3522. nowtime := recordDate.Unix()
  3523. warehouseOut := models.WarehouseOut{
  3524. WarehouseOutOrderNumber: warehousing_out_order,
  3525. OperationTime: operation_time,
  3526. OrgId: adminInfo.CurrentOrgId,
  3527. Creater: creater,
  3528. Ctime: time.Now().Unix(),
  3529. Status: 1,
  3530. WarehouseOutTime: nowtime,
  3531. Type: 1,
  3532. StorehouseId: storeConfig.StorehouseOutInfo,
  3533. IsCheck: 1,
  3534. IsSys: 1,
  3535. }
  3536. //查询是否生成出库单
  3537. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3538. if out.ID == 0 {
  3539. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3540. }
  3541. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3542. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3543. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3544. dialyPrepareOne := models.DialysisBeforePrepare{
  3545. GoodTypeId: goodObj.GoodTypeId,
  3546. GoodId: p.ProjectId,
  3547. PatientId: p.PatientId,
  3548. RecordDate: p.RecordDate,
  3549. UserOrgId: adminInfo.CurrentOrgId,
  3550. Count: cha_count,
  3551. Ctime: time.Now().Unix(),
  3552. Creater: creater,
  3553. Status: 1,
  3554. StorehouseId: houseConfig.StorehouseOutInfo,
  3555. ProjectId: p.ID,
  3556. }
  3557. //出库
  3558. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3559. }
  3560. //如果当前处方数量小于历史数据,怎需要退库
  3561. if nowCount < historyCount {
  3562. var cha_count int64
  3563. cha_count = historyCount - nowCount
  3564. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3565. creater := c.GetAdminUserInfo().AdminUser.Id
  3566. newPrescriptionProject := &models.HisPrescriptionProject{
  3567. ID: p.ID,
  3568. ProjectId: p.ProjectId,
  3569. Price: p.Price,
  3570. UserOrgId: p.UserOrgId,
  3571. Status: 1,
  3572. Ctime: time.Now().Unix(),
  3573. Mtime: time.Now().Unix(),
  3574. PatientId: p.PatientId,
  3575. HisPatientId: p.HisPatientId,
  3576. RecordDate: p.RecordDate,
  3577. PrescriptionId: p.PrescriptionId,
  3578. Count: p.Count,
  3579. FeedetlSn: p.FeedetlSn,
  3580. MedListCodg: p.MedListCodg,
  3581. SingleDose: p.SingleDose,
  3582. DeliveryWay: p.DeliveryWay,
  3583. ExecutionFrequency: p.ExecutionFrequency,
  3584. Day: p.Day,
  3585. HisProject: models.HisProject{},
  3586. GoodInfo: models.GoodInfo{},
  3587. Remark: p.Remark,
  3588. Unit: p.Unit,
  3589. Type: p.Type,
  3590. Doctor: p.Doctor,
  3591. ExecutionTime: p.ExecutionTime,
  3592. ExecutionStaff: p.ExecutionStaff,
  3593. ExecutionState: p.ExecutionState,
  3594. CheckTime: p.CheckTime,
  3595. CheckState: p.CheckState,
  3596. Checker: p.Checker,
  3597. StartTime: p.StartTime,
  3598. TeamId: p.TeamId,
  3599. XtHisProjectTeam: models.XtHisProjectTeam{},
  3600. FrequencyType: p.FrequencyType,
  3601. DayCount: p.DayCount,
  3602. WeekDay: p.WeekDay,
  3603. IsCheckTeam: p.IsCheckTeam,
  3604. HisOrderInfo: models.HisOrderInfo{},
  3605. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3606. IsOut: p.IsOut,
  3607. YbSyncStatus: p.YbSyncStatus,
  3608. }
  3609. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3610. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3611. }
  3612. if nowCount == historyCount {
  3613. if historyCount == 0 {
  3614. recordDateStr := time.Now().Format("2006-01-02")
  3615. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3616. nowtime := recordDate.Unix()
  3617. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3618. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3619. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3620. creater := c.GetAdminUserInfo().AdminUser.Id
  3621. dialyPrepareOne := models.DialysisBeforePrepare{
  3622. GoodTypeId: goodObj.GoodTypeId,
  3623. GoodId: p.ProjectId,
  3624. PatientId: p.PatientId,
  3625. RecordDate: p.RecordDate,
  3626. UserOrgId: adminInfo.CurrentOrgId,
  3627. Count: nowCount,
  3628. Ctime: time.Now().Unix(),
  3629. Creater: creater,
  3630. Status: 1,
  3631. StorehouseId: houseConfig.StorehouseOutInfo,
  3632. ProjectId: p.ID,
  3633. }
  3634. //出库
  3635. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3636. }
  3637. }
  3638. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3639. //查询历史出库数据
  3640. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3641. var out_count_five int64
  3642. for _, item := range flowGood {
  3643. out_count_five += item.Count
  3644. }
  3645. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3646. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3647. if out_count_five != parseIntCount {
  3648. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3649. detail := models.AutomaticReduceDetail{
  3650. WarehouseOutId: 0,
  3651. WarehouseOutOrderNumber: "",
  3652. PatientId: p.PatientId,
  3653. Ctime: time.Now().Unix(),
  3654. Mtime: 0,
  3655. Status: 1,
  3656. RecordTime: p.RecordDate,
  3657. OrgId: p.UserOrgId,
  3658. GoodId: p.ProjectId,
  3659. GoodTypeId: 0,
  3660. Count: parseIntCount,
  3661. Type: 0,
  3662. ProjectId: lastHisProject.ID,
  3663. StorehouseId: 0,
  3664. }
  3665. service.CreateNewAutoDetail(detail, tx)
  3666. }
  3667. // //查询耗材最后一次出库记录
  3668. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3669. // //查询默认出库仓库库存
  3670. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3671. // if len(wareOut) > 0 {
  3672. //
  3673. // for _, it := range wareOut {
  3674. // //回退库存
  3675. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3676. //
  3677. // //删除出库记录
  3678. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3679. //
  3680. // }
  3681. // }
  3682. //
  3683. // timeStr := time.Now().Format("2006-01-02")
  3684. // timeArr := strings.Split(timeStr, "-")
  3685. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3686. //
  3687. // total = total + 1
  3688. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3689. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3690. // number = number + total
  3691. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3692. //
  3693. // operation_time := time.Now().Unix()
  3694. // creater := c.GetAdminUserInfo().AdminUser.Id
  3695. //
  3696. // recordDateStr := time.Now().Format("2006-01-02")
  3697. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3698. // nowtime := recordDate.Unix()
  3699. // warehouseOut := models.WarehouseOut{
  3700. // WarehouseOutOrderNumber: warehousing_out_order,
  3701. // OperationTime: operation_time,
  3702. // OrgId: adminInfo.CurrentOrgId,
  3703. // Creater: creater,
  3704. // Ctime: time.Now().Unix(),
  3705. // Status: 1,
  3706. // WarehouseOutTime: nowtime,
  3707. // Type: 1,
  3708. // StorehouseId: storeConfig.StorehouseOutInfo,
  3709. // IsCheck: 1,
  3710. // IsSys: 1,
  3711. // }
  3712. // //查询是否生成出库单
  3713. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3714. // if out.ID == 0 {
  3715. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3716. // }
  3717. //
  3718. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3719. //
  3720. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3721. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3722. //
  3723. // dialyPrepareOne := models.DialysisBeforePrepare{
  3724. // GoodTypeId: goodObj.GoodTypeId,
  3725. // GoodId: p.ProjectId,
  3726. // PatientId: p.PatientId,
  3727. // RecordDate: p.RecordDate,
  3728. // UserOrgId: adminInfo.CurrentOrgId,
  3729. // Count: parseIntCount,
  3730. // Ctime: time.Now().Unix(),
  3731. // Creater: creater,
  3732. // Status: 1,
  3733. // StorehouseId: houseConfig.StorehouseOutInfo,
  3734. // ProjectId: lastHisProject.ID,
  3735. // }
  3736. // //判断是否是零用耗材(非零用)
  3737. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3738. //
  3739. // //查询历史出库数据
  3740. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3741. // var out_count int64
  3742. // for _, item := range flowGood {
  3743. // out_count += item.Count
  3744. // }
  3745. // //如果历史数和当前数据不想等才进行退库出库
  3746. // if out_count != parseIntCount {
  3747. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3748. //
  3749. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3750. // detail := models.AutomaticReduceDetail{
  3751. // WarehouseOutId: 0,
  3752. // WarehouseOutOrderNumber: "",
  3753. // PatientId: p.PatientId,
  3754. // Ctime: time.Now().Unix(),
  3755. // Mtime: 0,
  3756. // Status: 1,
  3757. // RecordTime: p.RecordDate,
  3758. // OrgId: p.UserOrgId,
  3759. // GoodId: p.ProjectId,
  3760. // GoodTypeId: 0,
  3761. // Count: parseIntCount,
  3762. // Type: 0,
  3763. // ProjectId: lastHisProject.ID,
  3764. // StorehouseId: 0,
  3765. // }
  3766. //
  3767. // service.CreateNewAutoDetail(detail, tx)
  3768. //
  3769. // //查询剩余库存
  3770. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3771. // var sum_count int64
  3772. // for _, item := range goodList {
  3773. // sum_count += item.StockCount
  3774. // }
  3775. //
  3776. // //更新剩余库存
  3777. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3778. //
  3779. // //耗材
  3780. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3781. //
  3782. // }
  3783. // //判断是否是零用耗材(零用但是是出库耗材)
  3784. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3785. //
  3786. // //查询历史出库数据
  3787. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3788. // var out_count int64
  3789. // for _, item := range flowGood {
  3790. // out_count += item.Count
  3791. // }
  3792. // //如果历史数和当前数据不想等才进行退库出库
  3793. // if out_count != parseIntCount {
  3794. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3795. //
  3796. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3797. // detail := models.AutomaticReduceDetail{
  3798. // WarehouseOutId: 0,
  3799. // WarehouseOutOrderNumber: "",
  3800. // PatientId: p.PatientId,
  3801. // Ctime: time.Now().Unix(),
  3802. // Mtime: 0,
  3803. // Status: 1,
  3804. // RecordTime: p.RecordDate,
  3805. // OrgId: p.UserOrgId,
  3806. // GoodId: p.ProjectId,
  3807. // GoodTypeId: 0,
  3808. // Count: parseIntCount,
  3809. // Type: 0,
  3810. // ProjectId: p.ID,
  3811. // StorehouseId: 0,
  3812. // }
  3813. //
  3814. // service.CreateNewAutoDetail(detail, tx)
  3815. //
  3816. // //查询剩余库存
  3817. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3818. // var sum_count int64
  3819. // for _, item := range goodList {
  3820. // sum_count += item.StockCount
  3821. // }
  3822. //
  3823. // //更新剩余库存
  3824. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3825. //
  3826. // //耗材
  3827. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3828. // }
  3829. //
  3830. // }
  3831. //
  3832. // }
  3833. //
  3834. //}
  3835. //记录日志
  3836. byterequest, _ := json.Marshal(p)
  3837. adviceLog := models.XtDoctorAdviceLog{
  3838. UserOrgId: p.UserOrgId,
  3839. PatientId: p.PatientId,
  3840. AdminUserId: adminInfo.AdminUser.Id,
  3841. Module: 1,
  3842. ErrLog: string(byterequest),
  3843. Status: 1,
  3844. Ctime: time.Now().Unix(),
  3845. Mtime: 0,
  3846. Source: "电脑端新建his项目",
  3847. RecordDate: p.RecordDate,
  3848. }
  3849. service.CreateDoctorAdviceLog(adviceLog)
  3850. projectList = append(projectList, p)
  3851. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3852. //新增或者编辑项目,修改对应的标签数据
  3853. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3854. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3855. var label models.HisLabelPrintInfo
  3856. project, _ := service.GetProjectDetail(p.ProjectId)
  3857. if project.CostClassify == 3 { //类别为检验检查
  3858. if p.TeamId > 0 { //检验检查组套
  3859. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3860. if tempLabel.ID == 0 {
  3861. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3862. label.Number = tempPrescription.PrescriptionNumber
  3863. label.ProjectId = project.ID
  3864. label.Status = 1
  3865. label.IsPrint = 2
  3866. label.DoctorId = info.DoctorId
  3867. label.UserOrgId = p.UserOrgId
  3868. label.PatientId = patient_id
  3869. label.RecordDate = recordDateTime
  3870. label.Ctime = time.Now().Unix()
  3871. label.Mtime = time.Now().Unix()
  3872. label.ItemId = p.TeamId
  3873. label.FeedetlSn = p.FeedetlSn
  3874. label.PProjectId = p.ID
  3875. label.ProjectName = team.ProjectTeam
  3876. label.PatientName = patient.Name
  3877. service.CreateNewHisLabelRecord(&label, tx)
  3878. }
  3879. } else { //单条检验检查项目
  3880. label.Number = tempPrescription.PrescriptionNumber
  3881. label.ProjectId = project.ID
  3882. label.Status = 1
  3883. label.DoctorId = info.DoctorId
  3884. label.UserOrgId = p.UserOrgId
  3885. label.PatientId = patient_id
  3886. label.RecordDate = recordDateTime
  3887. label.IsPrint = 2
  3888. label.Ctime = time.Now().Unix()
  3889. label.Mtime = time.Now().Unix()
  3890. label.FeedetlSn = p.FeedetlSn
  3891. label.PProjectId = p.ID
  3892. label.ItemId = p.TeamId
  3893. label.ProjectName = project.ProjectName
  3894. label.PatientName = patient.Name
  3895. service.CreateNewHisLabelRecord(&label, tx)
  3896. }
  3897. }
  3898. }
  3899. }
  3900. }
  3901. }
  3902. }
  3903. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  3904. //耗材出库
  3905. if p.Type == 3 {
  3906. //对比当前数据和历史出库数据
  3907. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3908. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3909. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3910. //如果当前处方数量大于历史数据,则需要出库
  3911. if nowCount > historyCount {
  3912. var cha_count int64
  3913. cha_count = nowCount - historyCount
  3914. timeStr := time.Now().Format("2006-01-02")
  3915. timeArr := strings.Split(timeStr, "-")
  3916. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3917. total = total + 1
  3918. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3919. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3920. number = number + total
  3921. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3922. operation_time := time.Now().Unix()
  3923. creater := c.GetAdminUserInfo().AdminUser.Id
  3924. recordDateStr := time.Now().Format("2006-01-02")
  3925. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3926. nowtime := recordDate.Unix()
  3927. warehouseOut := models.WarehouseOut{
  3928. WarehouseOutOrderNumber: warehousing_out_order,
  3929. OperationTime: operation_time,
  3930. OrgId: adminInfo.CurrentOrgId,
  3931. Creater: creater,
  3932. Ctime: time.Now().Unix(),
  3933. Status: 1,
  3934. WarehouseOutTime: nowtime,
  3935. Type: 1,
  3936. StorehouseId: storeConfig.StorehouseOutInfo,
  3937. IsCheck: 1,
  3938. IsSys: 1,
  3939. }
  3940. //查询是否生成出库单
  3941. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3942. if out.ID == 0 {
  3943. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3944. }
  3945. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3946. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3947. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3948. dialyPrepareOne := models.DialysisBeforePrepare{
  3949. GoodTypeId: goodObj.GoodTypeId,
  3950. GoodId: p.ProjectId,
  3951. PatientId: p.PatientId,
  3952. RecordDate: p.RecordDate,
  3953. UserOrgId: adminInfo.CurrentOrgId,
  3954. Count: cha_count,
  3955. Ctime: time.Now().Unix(),
  3956. Creater: creater,
  3957. Status: 1,
  3958. StorehouseId: houseConfig.StorehouseOutInfo,
  3959. ProjectId: p.ID,
  3960. }
  3961. //出库
  3962. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3963. }
  3964. //如果当前处方数量小于历史数据,怎需要退库
  3965. if nowCount < historyCount {
  3966. var cha_count int64
  3967. cha_count = historyCount - nowCount
  3968. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3969. creater := c.GetAdminUserInfo().AdminUser.Id
  3970. newPrescriptionProject := &models.HisPrescriptionProject{
  3971. ID: p.ID,
  3972. ProjectId: p.ProjectId,
  3973. Price: p.Price,
  3974. UserOrgId: p.UserOrgId,
  3975. Status: 1,
  3976. Ctime: time.Now().Unix(),
  3977. Mtime: time.Now().Unix(),
  3978. PatientId: p.PatientId,
  3979. HisPatientId: p.HisPatientId,
  3980. RecordDate: p.RecordDate,
  3981. PrescriptionId: p.PrescriptionId,
  3982. Count: p.Count,
  3983. FeedetlSn: p.FeedetlSn,
  3984. MedListCodg: p.MedListCodg,
  3985. SingleDose: p.SingleDose,
  3986. DeliveryWay: p.DeliveryWay,
  3987. ExecutionFrequency: p.ExecutionFrequency,
  3988. Day: p.Day,
  3989. HisProject: models.HisProject{},
  3990. GoodInfo: models.GoodInfo{},
  3991. Remark: p.Remark,
  3992. Unit: p.Unit,
  3993. Type: p.Type,
  3994. Doctor: p.Doctor,
  3995. ExecutionTime: p.ExecutionTime,
  3996. ExecutionStaff: p.ExecutionStaff,
  3997. ExecutionState: p.ExecutionState,
  3998. CheckTime: p.CheckTime,
  3999. CheckState: p.CheckState,
  4000. Checker: p.Checker,
  4001. StartTime: p.StartTime,
  4002. TeamId: p.TeamId,
  4003. XtHisProjectTeam: models.XtHisProjectTeam{},
  4004. FrequencyType: p.FrequencyType,
  4005. DayCount: p.DayCount,
  4006. WeekDay: p.WeekDay,
  4007. IsCheckTeam: p.IsCheckTeam,
  4008. HisOrderInfo: models.HisOrderInfo{},
  4009. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4010. IsOut: p.IsOut,
  4011. YbSyncStatus: p.YbSyncStatus,
  4012. }
  4013. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4014. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4015. }
  4016. if nowCount == historyCount {
  4017. if historyCount == 0 {
  4018. recordDateStr := time.Now().Format("2006-01-02")
  4019. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4020. nowtime := recordDate.Unix()
  4021. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4022. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4023. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4024. creater := c.GetAdminUserInfo().AdminUser.Id
  4025. dialyPrepareOne := models.DialysisBeforePrepare{
  4026. GoodTypeId: goodObj.GoodTypeId,
  4027. GoodId: p.ProjectId,
  4028. PatientId: p.PatientId,
  4029. RecordDate: p.RecordDate,
  4030. UserOrgId: adminInfo.CurrentOrgId,
  4031. Count: nowCount,
  4032. Ctime: time.Now().Unix(),
  4033. Creater: creater,
  4034. Status: 1,
  4035. StorehouseId: houseConfig.StorehouseOutInfo,
  4036. ProjectId: p.ID,
  4037. }
  4038. //出库
  4039. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4040. }
  4041. }
  4042. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4043. //查询历史出库数据
  4044. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4045. var out_count_five int64
  4046. for _, item := range flowGood {
  4047. out_count_five += item.Count
  4048. }
  4049. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4050. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4051. if out_count_five != parseIntCount {
  4052. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4053. detail := models.AutomaticReduceDetail{
  4054. WarehouseOutId: 0,
  4055. WarehouseOutOrderNumber: "",
  4056. PatientId: p.PatientId,
  4057. Ctime: time.Now().Unix(),
  4058. Mtime: 0,
  4059. Status: 1,
  4060. RecordTime: p.RecordDate,
  4061. OrgId: p.UserOrgId,
  4062. GoodId: p.ProjectId,
  4063. GoodTypeId: 0,
  4064. Count: parseIntCount,
  4065. Type: 0,
  4066. ProjectId: lastHisProject.ID,
  4067. StorehouseId: 0,
  4068. }
  4069. service.CreateNewAutoDetail(detail, tx)
  4070. }
  4071. // //查询耗材最后一次出库记录
  4072. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4073. // //查询默认出库仓库库存
  4074. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4075. // if len(wareOut) > 0 {
  4076. //
  4077. // for _, it := range wareOut {
  4078. // //回退库存
  4079. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4080. //
  4081. // //删除出库记录
  4082. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4083. //
  4084. // }
  4085. // }
  4086. //
  4087. // timeStr := time.Now().Format("2006-01-02")
  4088. // timeArr := strings.Split(timeStr, "-")
  4089. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4090. //
  4091. // total = total + 1
  4092. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4093. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4094. // number = number + total
  4095. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4096. //
  4097. // operation_time := time.Now().Unix()
  4098. // creater := c.GetAdminUserInfo().AdminUser.Id
  4099. //
  4100. // recordDateStr := time.Now().Format("2006-01-02")
  4101. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4102. // nowtime := recordDate.Unix()
  4103. // warehouseOut := models.WarehouseOut{
  4104. // WarehouseOutOrderNumber: warehousing_out_order,
  4105. // OperationTime: operation_time,
  4106. // OrgId: adminInfo.CurrentOrgId,
  4107. // Creater: creater,
  4108. // Ctime: time.Now().Unix(),
  4109. // Status: 1,
  4110. // WarehouseOutTime: nowtime,
  4111. // Type: 1,
  4112. // StorehouseId: storeConfig.StorehouseOutInfo,
  4113. // IsCheck: 1,
  4114. // IsSys: 1,
  4115. // }
  4116. // //查询是否生成出库单
  4117. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4118. // if out.ID == 0 {
  4119. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4120. // }
  4121. //
  4122. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4123. //
  4124. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4125. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4126. //
  4127. // dialyPrepareOne := models.DialysisBeforePrepare{
  4128. // GoodTypeId: goodObj.GoodTypeId,
  4129. // GoodId: p.ProjectId,
  4130. // PatientId: p.PatientId,
  4131. // RecordDate: p.RecordDate,
  4132. // UserOrgId: adminInfo.CurrentOrgId,
  4133. // Count: parseIntCount,
  4134. // Ctime: time.Now().Unix(),
  4135. // Creater: creater,
  4136. // Status: 1,
  4137. // StorehouseId: houseConfig.StorehouseOutInfo,
  4138. // ProjectId: lastHisProject.ID,
  4139. // }
  4140. // //判断是否是零用耗材(非零用)
  4141. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4142. //
  4143. // //查询历史出库数据
  4144. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4145. // var out_count int64
  4146. // for _, item := range flowGood {
  4147. // out_count += item.Count
  4148. // }
  4149. // //如果历史数和当前数据不想等才进行退库出库
  4150. // if out_count != parseIntCount {
  4151. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4152. //
  4153. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4154. // detail := models.AutomaticReduceDetail{
  4155. // WarehouseOutId: 0,
  4156. // WarehouseOutOrderNumber: "",
  4157. // PatientId: p.PatientId,
  4158. // Ctime: time.Now().Unix(),
  4159. // Mtime: 0,
  4160. // Status: 1,
  4161. // RecordTime: p.RecordDate,
  4162. // OrgId: p.UserOrgId,
  4163. // GoodId: p.ProjectId,
  4164. // GoodTypeId: 0,
  4165. // Count: parseIntCount,
  4166. // Type: 0,
  4167. // ProjectId: lastHisProject.ID,
  4168. // StorehouseId: 0,
  4169. // }
  4170. //
  4171. // service.CreateNewAutoDetail(detail, tx)
  4172. //
  4173. // //查询剩余库存
  4174. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4175. // var sum_count int64
  4176. // for _, item := range goodList {
  4177. // sum_count += item.StockCount
  4178. // }
  4179. //
  4180. // //更新剩余库存
  4181. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4182. //
  4183. // //耗材
  4184. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4185. //
  4186. // }
  4187. // //判断是否是零用耗材(零用但是是出库耗材)
  4188. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4189. //
  4190. // //查询历史出库数据
  4191. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4192. // var out_count int64
  4193. // for _, item := range flowGood {
  4194. // out_count += item.Count
  4195. // }
  4196. // //如果历史数和当前数据不想等才进行退库出库
  4197. // if out_count != parseIntCount {
  4198. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4199. //
  4200. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4201. // detail := models.AutomaticReduceDetail{
  4202. // WarehouseOutId: 0,
  4203. // WarehouseOutOrderNumber: "",
  4204. // PatientId: p.PatientId,
  4205. // Ctime: time.Now().Unix(),
  4206. // Mtime: 0,
  4207. // Status: 1,
  4208. // RecordTime: p.RecordDate,
  4209. // OrgId: p.UserOrgId,
  4210. // GoodId: p.ProjectId,
  4211. // GoodTypeId: 0,
  4212. // Count: parseIntCount,
  4213. // Type: 0,
  4214. // ProjectId: p.ID,
  4215. // StorehouseId: 0,
  4216. // }
  4217. //
  4218. // service.CreateNewAutoDetail(detail, tx)
  4219. //
  4220. // //查询剩余库存
  4221. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4222. // var sum_count int64
  4223. // for _, item := range goodList {
  4224. // sum_count += item.StockCount
  4225. // }
  4226. //
  4227. // //更新剩余库存
  4228. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4229. //
  4230. // //耗材
  4231. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4232. // }
  4233. //
  4234. // }
  4235. //
  4236. // }
  4237. //
  4238. //}
  4239. //记录日志
  4240. byterequest, _ := json.Marshal(p)
  4241. adviceLog := models.XtDoctorAdviceLog{
  4242. UserOrgId: p.UserOrgId,
  4243. PatientId: p.PatientId,
  4244. AdminUserId: adminInfo.AdminUser.Id,
  4245. Module: 1,
  4246. ErrLog: string(byterequest),
  4247. Status: 1,
  4248. Ctime: time.Now().Unix(),
  4249. Mtime: 0,
  4250. Source: "电脑端新建his项目",
  4251. RecordDate: p.RecordDate,
  4252. }
  4253. service.CreateDoctorAdviceLog(adviceLog)
  4254. projectList = append(projectList, p)
  4255. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4256. //新增或者编辑项目,修改对应的标签数据
  4257. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4258. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4259. var label models.HisLabelPrintInfo
  4260. project, _ := service.GetProjectDetail(p.ProjectId)
  4261. if project.CostClassify == 3 { //类别为检验检查
  4262. if p.TeamId > 0 { //检验检查组套
  4263. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4264. if tempLabel.ID == 0 {
  4265. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4266. label.Number = tempPrescription.PrescriptionNumber
  4267. label.ProjectId = project.ID
  4268. label.Status = 1
  4269. label.IsPrint = 2
  4270. label.DoctorId = info.DoctorId
  4271. label.UserOrgId = p.UserOrgId
  4272. label.PatientId = patient_id
  4273. label.RecordDate = recordDateTime
  4274. label.Ctime = time.Now().Unix()
  4275. label.Mtime = time.Now().Unix()
  4276. label.ItemId = p.TeamId
  4277. label.FeedetlSn = p.FeedetlSn
  4278. label.PProjectId = p.ID
  4279. label.ProjectName = team.ProjectTeam
  4280. label.PatientName = patient.Name
  4281. service.CreateNewHisLabelRecord(&label, tx)
  4282. }
  4283. } else { //单条检验检查项目
  4284. label.Number = tempPrescription.PrescriptionNumber
  4285. label.ProjectId = project.ID
  4286. label.Status = 1
  4287. label.DoctorId = info.DoctorId
  4288. label.UserOrgId = p.UserOrgId
  4289. label.PatientId = patient_id
  4290. label.RecordDate = recordDateTime
  4291. label.IsPrint = 2
  4292. label.Ctime = time.Now().Unix()
  4293. label.Mtime = time.Now().Unix()
  4294. label.FeedetlSn = p.FeedetlSn
  4295. label.PProjectId = p.ID
  4296. label.ItemId = p.TeamId
  4297. label.ProjectName = project.ProjectName
  4298. label.PatientName = patient.Name
  4299. service.CreateNewHisLabelRecord(&label, tx)
  4300. }
  4301. }
  4302. }
  4303. }
  4304. }
  4305. }
  4306. }
  4307. //插入检验数据
  4308. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4309. //新增或者编辑项目,修改对应的标签数据
  4310. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4311. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4312. var label models.HisLabelPrintInfo
  4313. project, _ := service.GetProjectDetail(p.ProjectId)
  4314. if project.CostClassify == 3 { //类别为检验检查
  4315. if p.TeamId > 0 { //检验检查组套
  4316. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4317. if tempLabel.ID == 0 {
  4318. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4319. label.Number = tempPrescription.PrescriptionNumber
  4320. label.ProjectId = project.ID
  4321. label.Status = 1
  4322. label.IsPrint = 2
  4323. label.DoctorId = info.DoctorId
  4324. label.UserOrgId = p.UserOrgId
  4325. label.PatientId = patient_id
  4326. label.RecordDate = recordDateTime
  4327. label.Ctime = time.Now().Unix()
  4328. label.Mtime = time.Now().Unix()
  4329. label.ItemId = p.TeamId
  4330. label.FeedetlSn = p.FeedetlSn
  4331. label.PProjectId = p.ID
  4332. label.ProjectName = team.ProjectTeam
  4333. label.PatientName = patient.Name
  4334. service.CreateHisLabelRecord(&label)
  4335. }
  4336. } else { //单条检验检查项目
  4337. label.Number = tempPrescription.PrescriptionNumber
  4338. label.ProjectId = project.ID
  4339. label.Status = 1
  4340. label.DoctorId = info.DoctorId
  4341. label.UserOrgId = p.UserOrgId
  4342. label.PatientId = patient_id
  4343. label.RecordDate = recordDateTime
  4344. label.IsPrint = 2
  4345. label.Ctime = time.Now().Unix()
  4346. label.Mtime = time.Now().Unix()
  4347. label.FeedetlSn = p.FeedetlSn
  4348. label.PProjectId = p.ID
  4349. label.ItemId = p.TeamId
  4350. label.ProjectName = project.ProjectName
  4351. label.PatientName = patient.Name
  4352. service.CreateHisLabelRecord(&label)
  4353. }
  4354. }
  4355. }
  4356. }
  4357. service.CreateNewHisProjectTwo(&p, tx)
  4358. var randNum int
  4359. randNum = rand.Intn(10000) + 1000
  4360. timestamp := time.Now().Unix()
  4361. tempTime := time.Unix(timestamp, 0)
  4362. timeFormat := tempTime.Format("20060102150405")
  4363. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4364. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4365. if goodBase.ID > 0 {
  4366. tx.Rollback()
  4367. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4368. return
  4369. }
  4370. service.CreateNewHisProjectTwo(&p, tx)
  4371. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4372. //查询剩余库存
  4373. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4374. var sum_count int64
  4375. for _, item := range goodList {
  4376. sum_count += item.StockCount
  4377. }
  4378. //更新剩余库存
  4379. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4380. //耗材
  4381. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4382. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4383. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4384. if len(outInfoTwo) > 0 {
  4385. for _, item := range outInfoTwo {
  4386. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4387. }
  4388. }
  4389. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4390. if len(drugAutoDetail) > 0 {
  4391. for _, item := range drugAutoDetail {
  4392. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4393. }
  4394. }
  4395. tx.Commit()
  4396. }
  4397. }
  4398. }
  4399. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4400. // addition := items["addition"].([]interface{})
  4401. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4402. // ctime := time.Now().Unix()
  4403. // mtime := ctime
  4404. // if len(addition) > 0 {
  4405. // for _, item := range addition {
  4406. // var s models.HisAdditionalCharge
  4407. // s.PrescriptionId = tempPrescription.ID
  4408. // s.Status = 1
  4409. // s.UserOrgId = adminInfo.CurrentOrgId
  4410. // s.RecordDate = recordDateTime
  4411. // s.CreatedTime = ctime
  4412. // s.UpdatedTime = mtime
  4413. // s.PatientId = patient_id
  4414. // s.HisPatientId = his_patient_id
  4415. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4416. // if errcode > 0 {
  4417. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4418. // return
  4419. // }
  4420. // service.CreateAdditionalCharge(&s)
  4421. // var randNum int
  4422. // randNum = rand.Intn(10000) + 1000
  4423. // timestamp := time.Now().Unix()
  4424. // tempTime := time.Unix(timestamp, 0)
  4425. // timeFormat := tempTime.Format("20060102150405")
  4426. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4427. // service.CreateAdditionalCharge(&s)
  4428. //
  4429. // }
  4430. // }
  4431. //}
  4432. }
  4433. }
  4434. }
  4435. tx.Commit()
  4436. if err == nil {
  4437. c.ServeSuccessJSON(map[string]interface{}{
  4438. "msg": "保存成功",
  4439. })
  4440. return
  4441. } else {
  4442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4443. return
  4444. }
  4445. } else {
  4446. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4447. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4448. var tempPrescription *models.HisPrescription
  4449. if len(prescriptions) > 0 {
  4450. for _, item := range prescriptions {
  4451. items := item.(map[string]interface{})
  4452. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4453. utils.ErrorLog("id")
  4454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4455. return
  4456. }
  4457. id := int64(items["id"].(float64))
  4458. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4459. tempPrescription = &new_prescription
  4460. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4461. utils.ErrorLog("type")
  4462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4463. return
  4464. }
  4465. types := int64(items["type"].(float64))
  4466. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4467. utils.ErrorLog("med_type")
  4468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4469. return
  4470. }
  4471. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4472. if med_type == "0" {
  4473. med_type = "14"
  4474. }
  4475. //if order_status == 0 {
  4476. // order_status = 1
  4477. //}
  4478. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4479. // utils.ErrorLog("diagnoses")
  4480. //}
  4481. diagnoses, _ := items["diagnoses"].(string)
  4482. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4483. utils.ErrorLog("pre_time")
  4484. }
  4485. preTime, _ := items["pre_time"].(string)
  4486. timeLayout := "2006-01-02"
  4487. loc, _ := time.LoadLocation("Local")
  4488. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4489. //result := strings.Split(preTime, " ")
  4490. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4491. if err != nil {
  4492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4493. return
  4494. }
  4495. pTime := theTime2.Unix()
  4496. ctime := time.Now().Unix()
  4497. if tempPrescription.ID == 0 {
  4498. prescription := &models.HisPrescription{
  4499. ID: 0,
  4500. PatientId: patient_id,
  4501. UserOrgId: adminInfo.CurrentOrgId,
  4502. RecordDate: recordDateTime,
  4503. Ctime: ctime,
  4504. Mtime: ctime,
  4505. Type: types,
  4506. Modifier: adminInfo.AdminUser.Id,
  4507. Creator: adminInfo.AdminUser.Id,
  4508. Status: 1,
  4509. Doctor: role.UserName,
  4510. HisPatientId: his_patient_id,
  4511. OrderStatus: 1,
  4512. BatchNumber: "",
  4513. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4514. PreTime: pTime,
  4515. PType: p_type,
  4516. MedType: med_type,
  4517. Diagnose: diagnoses,
  4518. }
  4519. tempPrescription = prescription
  4520. service.SaveHisPrescription(tempPrescription)
  4521. redis := service.RedisClient()
  4522. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4523. redis.Set(key, "", time.Second)
  4524. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4525. redis.Set(keyOne, "", time.Second)
  4526. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4527. redis.Set(keySeven, "", time.Second)
  4528. defer redis.Close()
  4529. } else {
  4530. tempPrescription.ID = id
  4531. tempPrescription.Type = types
  4532. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4533. tempPrescription.Mtime = time.Now().Unix()
  4534. tempPrescription.Doctor = role.UserName
  4535. //tempPrescription.OrderStatus = order_status
  4536. tempPrescription.PreTime = pTime
  4537. tempPrescription.MedType = med_type
  4538. tempPrescription.Diagnose = diagnoses
  4539. service.SaveHisPrescription(tempPrescription)
  4540. redis := service.RedisClient()
  4541. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4542. redis.Set(key, "", time.Second)
  4543. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4544. redis.Set(keyOne, "", time.Second)
  4545. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4546. redis.Set(keySeven, "", time.Second)
  4547. defer redis.Close()
  4548. }
  4549. //service.SaveHisPrescription(prescription)
  4550. //更改患者挂号状态
  4551. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4552. fmt.Println("更改失败", err2)
  4553. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4554. advices := items["advices"].([]interface{})
  4555. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4556. groupNo := int64(0)
  4557. if len(advices) > 0 {
  4558. for _, advice := range advices {
  4559. var s models.HisDoctorAdviceInfo
  4560. s.PrescriptionId = tempPrescription.ID
  4561. s.AdviceType = 2
  4562. s.AdviceDoctor = doctor_id
  4563. s.StopState = 2
  4564. s.ExecutionState = 2
  4565. s.AdviceDate = theTime3.Unix()
  4566. s.Status = 1
  4567. s.UserOrgId = adminInfo.CurrentOrgId
  4568. s.RecordDate = theTime3.Unix()
  4569. s.StartTime = tempPrescription.PreTime
  4570. s.Groupno = groupNo
  4571. s.PatientId = patient_id
  4572. s.HisPatientId = his_patient_id
  4573. s.StartTime = pTime
  4574. s.IsSettle = 2
  4575. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4576. if errcode > 0 {
  4577. c.ServeFailJSONWithSGJErrorCode(errcode)
  4578. return
  4579. }
  4580. s.StartTime = pTime
  4581. var total_count int64 //处方总库存
  4582. //查询改药品信息
  4583. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4584. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4585. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4586. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4587. total_count += prescribingNumberSeven * medical.MinNumber
  4588. }
  4589. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4590. total_count += prescribingNumberSeven
  4591. }
  4592. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4593. total_count += prescribingNumberSeven
  4594. }
  4595. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4596. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4597. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4598. if s.Price != lastWarehouse.RetailPrice {
  4599. s.Price = lastWarehouse.RetailPrice
  4600. }
  4601. if s.Price == 0 {
  4602. if lastWarehouse.ID == 0 {
  4603. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4604. s.Price = lastWarehouseTwo.RetailPrice
  4605. }
  4606. }
  4607. }
  4608. if adminInfo.CurrentOrgId != 10206 {
  4609. if s.ID == 0 {
  4610. //查询改药品是否已经停用
  4611. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4612. if base.ID > 0 {
  4613. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4614. return
  4615. }
  4616. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4617. if drugMedical.SumCount == 0 {
  4618. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4619. return
  4620. }
  4621. }
  4622. }
  4623. //赤峰
  4624. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4625. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4626. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4627. if info.RetailPrice > 0 {
  4628. if s.DeliveryWay == "口服" {
  4629. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4630. s.Price = drug.RetailPrice
  4631. }
  4632. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4633. s.Price = info.RetailPrice
  4634. }
  4635. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4636. s.Price = info.RetailPrice
  4637. }
  4638. }
  4639. }
  4640. }
  4641. service.CreateHisDoctorAdvice(&s)
  4642. //记录日志
  4643. byterequest, _ := json.Marshal(s)
  4644. adviceLog := models.XtDoctorAdviceLog{
  4645. UserOrgId: s.UserOrgId,
  4646. PatientId: s.PatientId,
  4647. AdminUserId: adminInfo.AdminUser.Id,
  4648. Module: 1,
  4649. ErrLog: string(byterequest),
  4650. Status: 1,
  4651. Ctime: time.Now().Unix(),
  4652. Mtime: 0,
  4653. Source: "电脑端新建his医嘱",
  4654. RecordDate: s.AdviceDate,
  4655. }
  4656. service.CreateDoctorAdviceLog(adviceLog)
  4657. //存储切片中
  4658. adviceList = append(adviceList, s)
  4659. redis := service.RedisClient()
  4660. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4661. redis.Set(key, "", time.Second)
  4662. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4663. redis.Set(keyOne, "", time.Second)
  4664. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4665. redis.Set(keySeven, "", time.Second)
  4666. var randNum int
  4667. randNum = rand.Intn(10000) + 1000
  4668. timestamp := time.Now().Unix()
  4669. tempTime := time.Unix(timestamp, 0)
  4670. timeFormat := tempTime.Format("20060102150405")
  4671. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4672. service.CreateHisDoctorAdvice(&s)
  4673. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4674. redis.Set(keySix, "", time.Second)
  4675. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4676. redis.Set(keyFive, "", time.Second)
  4677. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4678. redis.Set(keyEight, "", time.Second)
  4679. defer redis.Close()
  4680. }
  4681. }
  4682. }
  4683. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4684. projects := items["project"].([]interface{})
  4685. if len(projects) > 0 {
  4686. for _, project := range projects {
  4687. var p models.HisPrescriptionProject
  4688. p.PrescriptionId = tempPrescription.ID
  4689. p.PatientId = patient_id
  4690. p.RecordDate = theTime3.Unix()
  4691. p.Doctor = doctor_id
  4692. p.UserOrgId = adminInfo.CurrentOrgId
  4693. p.HisPatientId = his_patient_id
  4694. p.Status = 1
  4695. p.StartTime = pTime
  4696. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4697. if errcode > 0 {
  4698. c.ServeFailJSONWithSGJErrorCode(errcode)
  4699. return
  4700. }
  4701. if p.ID == 0 {
  4702. p.IsOut = 2
  4703. }
  4704. if p.ID > 0 {
  4705. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4706. p.IsOut = projectDetail.IsOut
  4707. }
  4708. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4709. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4710. if p.Type == 3 {
  4711. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4712. if p.Price != lastWarehouse.PackingPrice {
  4713. p.Price = lastWarehouse.PackingPrice
  4714. }
  4715. if p.Price == 0 {
  4716. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4717. p.Price = lastWarehouseTwo.PackingPrice
  4718. }
  4719. if p.Unit == "" {
  4720. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4721. p.Unit = goodInfoOne.PackingUnit
  4722. }
  4723. }
  4724. }
  4725. if adminInfo.CurrentOrgId != 10206 {
  4726. if p.Type == 3 {
  4727. if p.ID == 0 {
  4728. //查询该耗材是否停用
  4729. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4730. //表示该耗材已经停用,不能保存
  4731. if goodInfoSeven.ID == 0 {
  4732. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4733. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4734. return
  4735. }
  4736. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4737. if goodInfoOne.SumCount == 0 {
  4738. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4739. return
  4740. }
  4741. }
  4742. }
  4743. }
  4744. service.CreateHisProjectTwo(&p)
  4745. //记录日志
  4746. byterequest, _ := json.Marshal(p)
  4747. adviceLog := models.XtDoctorAdviceLog{
  4748. UserOrgId: p.UserOrgId,
  4749. PatientId: p.PatientId,
  4750. AdminUserId: adminInfo.AdminUser.Id,
  4751. Module: 1,
  4752. ErrLog: string(byterequest),
  4753. Status: 1,
  4754. Ctime: time.Now().Unix(),
  4755. Mtime: 0,
  4756. Source: "电脑端新建his项目",
  4757. RecordDate: p.RecordDate,
  4758. }
  4759. service.CreateDoctorAdviceLog(adviceLog)
  4760. projectList = append(projectList, p)
  4761. var randNum int
  4762. randNum = rand.Intn(10000) + 1000
  4763. timestamp := time.Now().Unix()
  4764. tempTime := time.Unix(timestamp, 0)
  4765. timeFormat := tempTime.Format("20060102150405")
  4766. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4767. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4768. //新增或者编辑项目,修改对应的标签数据
  4769. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4770. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4771. var label models.HisLabelPrintInfo
  4772. project, _ := service.GetProjectDetail(p.ProjectId)
  4773. if project.CostClassify == 3 { //类别为检验检查
  4774. if p.TeamId > 0 { //检验检查组套
  4775. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4776. if tempLabel.ID == 0 {
  4777. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4778. label.Number = tempPrescription.PrescriptionNumber
  4779. label.ProjectId = project.ID
  4780. label.Status = 1
  4781. label.IsPrint = 2
  4782. label.DoctorId = info.DoctorId
  4783. label.UserOrgId = p.UserOrgId
  4784. label.PatientId = patient_id
  4785. label.RecordDate = recordDateTime
  4786. label.Ctime = time.Now().Unix()
  4787. label.Mtime = time.Now().Unix()
  4788. label.ItemId = p.TeamId
  4789. label.FeedetlSn = p.FeedetlSn
  4790. label.PProjectId = p.ID
  4791. label.ProjectName = team.ProjectTeam
  4792. label.PatientName = patient.Name
  4793. service.CreateHisLabelRecord(&label)
  4794. }
  4795. } else { //单条检验检查项目
  4796. label.Number = tempPrescription.PrescriptionNumber
  4797. label.ProjectId = project.ID
  4798. label.Status = 1
  4799. label.DoctorId = info.DoctorId
  4800. label.UserOrgId = p.UserOrgId
  4801. label.PatientId = patient_id
  4802. label.RecordDate = recordDateTime
  4803. label.IsPrint = 2
  4804. label.Ctime = time.Now().Unix()
  4805. label.Mtime = time.Now().Unix()
  4806. label.FeedetlSn = p.FeedetlSn
  4807. label.PProjectId = p.ID
  4808. label.ItemId = p.TeamId
  4809. label.ProjectName = project.ProjectName
  4810. label.PatientName = patient.Name
  4811. service.CreateHisLabelRecord(&label)
  4812. }
  4813. }
  4814. }
  4815. }
  4816. service.SaveHisProjectTwo(&p)
  4817. }
  4818. }
  4819. }
  4820. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4821. // addition := items["addition"].([]interface{})
  4822. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4823. // ctime := time.Now().Unix()
  4824. // mtime := ctime
  4825. // if len(addition) > 0 {
  4826. // for _, item := range addition {
  4827. // var s models.HisAdditionalCharge
  4828. // s.PrescriptionId = tempPrescription.ID
  4829. // s.Status = 1
  4830. // s.UserOrgId = adminInfo.CurrentOrgId
  4831. // s.RecordDate = recordDateTime
  4832. // s.CreatedTime = ctime
  4833. // s.UpdatedTime = mtime
  4834. // s.PatientId = patient_id
  4835. // s.HisPatientId = his_patient_id
  4836. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4837. // if errcode > 0 {
  4838. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4839. // return
  4840. // }
  4841. // service.CreateAdditionalCharge(&s)
  4842. // var randNum int
  4843. // randNum = rand.Intn(10000) + 1000
  4844. // timestamp := time.Now().Unix()
  4845. // tempTime := time.Unix(timestamp, 0)
  4846. // timeFormat := tempTime.Format("20060102150405")
  4847. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4848. // service.CreateAdditionalCharge(&s)
  4849. //
  4850. // }
  4851. // }
  4852. //}
  4853. }
  4854. }
  4855. //查询今日该患者开的药品处方
  4856. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4857. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4858. //药品出库
  4859. if drugOutConfig.IsOpen == 1 {
  4860. for _, item := range hisdoctorlist {
  4861. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4862. // 查询该药品最后一次出库记录
  4863. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4864. if len(druginfo) > 0 {
  4865. //回退库存
  4866. for _, it := range druginfo {
  4867. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4868. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4869. }
  4870. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4871. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4872. }
  4873. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4874. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4875. }
  4876. }
  4877. }
  4878. //删除记录
  4879. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4880. //查询最后一次数据
  4881. if drugOutConfig.IsOpen == 1 {
  4882. //出库
  4883. if drug.IsUse == 2 {
  4884. creater := adminInfo.AdminUser.Id
  4885. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4886. }
  4887. //更新字典里面的库存
  4888. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4889. var sum_count int64
  4890. for _, its := range stockInfo {
  4891. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4892. if its.MaxUnit == baseDrug.MaxUnit {
  4893. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4894. }
  4895. sum_count += its.StockMaxNumber + its.StockMinNumber
  4896. }
  4897. //更新基础库存
  4898. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4899. //剩余库存
  4900. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4901. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4902. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4903. }
  4904. }
  4905. }
  4906. //耗材保存处方出库
  4907. if goodOutConfig.IsOpen == 1 {
  4908. //查询今日耗材出库数量
  4909. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4910. for _, item := range hisgoodlist {
  4911. //查询历史出库数据
  4912. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4913. var out_count_five int64
  4914. for _, item := range flowGood {
  4915. out_count_five += item.Count
  4916. }
  4917. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4918. if out_count_five != parseIntCount {
  4919. //查询耗材最后一次出库记录
  4920. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4921. //查询默认出库仓库库存
  4922. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4923. if len(wareOut) > 0 {
  4924. for _, it := range wareOut {
  4925. //回退库存
  4926. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4927. //删除出库记录
  4928. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4929. }
  4930. }
  4931. timeStr := time.Now().Format("2006-01-02")
  4932. timeArr := strings.Split(timeStr, "-")
  4933. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4934. total = total + 1
  4935. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4936. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4937. number = number + total
  4938. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4939. operation_time := time.Now().Unix()
  4940. creater := c.GetAdminUserInfo().AdminUser.Id
  4941. recordDateStr := time.Now().Format("2006-01-02")
  4942. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4943. nowtime := recordDate.Unix()
  4944. warehouseOut := models.WarehouseOut{
  4945. WarehouseOutOrderNumber: warehousing_out_order,
  4946. OperationTime: operation_time,
  4947. OrgId: adminInfo.CurrentOrgId,
  4948. Creater: creater,
  4949. Ctime: time.Now().Unix(),
  4950. Status: 1,
  4951. WarehouseOutTime: nowtime,
  4952. Type: 1,
  4953. StorehouseId: storeConfig.StorehouseOutInfo,
  4954. IsCheck: 1,
  4955. IsSys: 1,
  4956. }
  4957. //查询是否生成出库单
  4958. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4959. if out.ID == 0 {
  4960. service.AddSigleWarehouseOut(&warehouseOut)
  4961. }
  4962. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4963. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4964. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4965. dialyPrepareOne := models.DialysisBeforePrepare{
  4966. GoodTypeId: goodObj.GoodTypeId,
  4967. GoodId: item.ProjectId,
  4968. PatientId: item.PatientId,
  4969. RecordDate: item.RecordDate,
  4970. UserOrgId: adminInfo.CurrentOrgId,
  4971. Count: parseIntCount,
  4972. Ctime: time.Now().Unix(),
  4973. Creater: creater,
  4974. Status: 1,
  4975. StorehouseId: houseConfig.StorehouseOutInfo,
  4976. ProjectId: item.ID,
  4977. }
  4978. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4979. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4980. //查询历史出库数据
  4981. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4982. var out_count int64
  4983. for _, item := range flowGood {
  4984. out_count += item.Count
  4985. }
  4986. //如果历史数和当前数据不想等才进行退库出库
  4987. if out_count != parseIntCount {
  4988. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4989. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4990. detail := models.AutomaticReduceDetail{
  4991. WarehouseOutId: 0,
  4992. WarehouseOutOrderNumber: "",
  4993. PatientId: item.PatientId,
  4994. Ctime: time.Now().Unix(),
  4995. Mtime: 0,
  4996. Status: 1,
  4997. RecordTime: item.RecordDate,
  4998. OrgId: item.UserOrgId,
  4999. GoodId: item.ProjectId,
  5000. GoodTypeId: 0,
  5001. Count: parseIntCount,
  5002. Type: 0,
  5003. ProjectId: item.ID,
  5004. StorehouseId: 0,
  5005. }
  5006. service.CreateAutoDetail(detail)
  5007. //查询剩余库存
  5008. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5009. var sum_count int64
  5010. for _, item := range goodList {
  5011. sum_count += item.StockCount
  5012. }
  5013. //更新剩余库存
  5014. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5015. //耗材
  5016. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5017. }
  5018. }
  5019. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5020. //查询历史出库数据
  5021. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5022. var out_count int64
  5023. for _, item := range flowGood {
  5024. out_count += item.Count
  5025. }
  5026. //如果历史数和当前数据不想等才进行退库出库
  5027. if out_count != parseIntCount {
  5028. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5029. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5030. detail := models.AutomaticReduceDetail{
  5031. WarehouseOutId: 0,
  5032. WarehouseOutOrderNumber: "",
  5033. PatientId: item.PatientId,
  5034. Ctime: time.Now().Unix(),
  5035. Mtime: 0,
  5036. Status: 1,
  5037. RecordTime: item.RecordDate,
  5038. OrgId: item.UserOrgId,
  5039. GoodId: item.ProjectId,
  5040. GoodTypeId: 0,
  5041. Count: parseIntCount,
  5042. Type: 0,
  5043. ProjectId: item.ID,
  5044. StorehouseId: 0,
  5045. }
  5046. service.CreateAutoDetail(detail)
  5047. //查询剩余库存
  5048. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5049. var sum_count int64
  5050. for _, item := range goodList {
  5051. sum_count += item.StockCount
  5052. }
  5053. //更新剩余库存
  5054. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5055. //耗材
  5056. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5057. }
  5058. }
  5059. }
  5060. }
  5061. }
  5062. ////同步到自备药
  5063. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5064. if selfPrescriptionOpen.IsOpen == 1 {
  5065. timeStr := time.Now().Format("2006-01-02")
  5066. timeArr := strings.Split(timeStr, "-")
  5067. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5068. total = total + 1
  5069. operation_time := time.Now().Unix()
  5070. creater := adminInfo.AdminUser.Id
  5071. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5072. warehousing := models.XtSelfDrugWarehouse{
  5073. WarehousingOrder: warehousing_order,
  5074. OperationTime: operation_time,
  5075. OrgId: adminInfo.CurrentOrgId,
  5076. Creater: creater,
  5077. Ctime: time.Now().Unix(),
  5078. Status: 1,
  5079. WarehousingTime: recordDateTime,
  5080. Type: 0,
  5081. StorehouseId: 0,
  5082. IsCheck: 1,
  5083. PatientId: patient_id,
  5084. IsSys: 1,
  5085. }
  5086. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5087. if selfDrugWarehouse.ID == 0 {
  5088. service.AddSelfDrugWarehouse(&warehousing, tx)
  5089. }
  5090. if selfDrugWarehouse.ID > 0 {
  5091. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5092. }
  5093. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5094. fmt.Println(info)
  5095. for _, item := range hisdoctorlist {
  5096. //查询该病人的该药品是否已经入库
  5097. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5098. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5099. var in_count int64
  5100. if len(selfdruginfo) > 0 {
  5101. for _, item := range selfdruginfo {
  5102. var in_count_one int64
  5103. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5104. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5105. }
  5106. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5107. in_count_one = item.WarehousingCount
  5108. }
  5109. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5110. in_count_one = item.WarehousingCount
  5111. }
  5112. in_count += in_count_one
  5113. }
  5114. }
  5115. if selfBasedrug.IsSelfDrug == 1 {
  5116. var total_count int64
  5117. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5118. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5119. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5120. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5121. }
  5122. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5123. total_count += prescribingNumberSeven
  5124. }
  5125. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5126. total_count += prescribingNumberSeven
  5127. }
  5128. //入库
  5129. if total_count > in_count {
  5130. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5131. WarehousingOrder: warehousing_order,
  5132. WarehousingId: info.ID,
  5133. DrugId: item.DrugId,
  5134. Number: "",
  5135. ProductDate: 0,
  5136. ExpiryDate: 0,
  5137. WarehousingCount: total_count - in_count,
  5138. WarehouseingUnit: selfBasedrug.MinUnit,
  5139. Price: 0,
  5140. TotalPrice: 0,
  5141. Status: 1,
  5142. Ctime: time.Now().Unix(),
  5143. Remark: "",
  5144. OrgId: adminInfo.CurrentOrgId,
  5145. Type: 0,
  5146. Manufacturer: selfBasedrug.Manufacturer,
  5147. Dealer: selfBasedrug.Dealer,
  5148. StockMaxNumber: total_count - in_count,
  5149. RetailTotalPrice: 0,
  5150. BatchNumber: "",
  5151. MaxUnit: selfBasedrug.MinUnit,
  5152. MinUnit: selfBasedrug.MinUnit,
  5153. RetailPrice: 0,
  5154. StorehouseId: 0,
  5155. IsCheck: 1,
  5156. StockMinNumber: 0,
  5157. PatientId: patient_id,
  5158. IsSys: 1,
  5159. RecordDate: item.RecordDate,
  5160. AdviceId: item.ID,
  5161. }
  5162. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5163. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5164. Creator := adminInfo.AdminUser.Id
  5165. //查询默认仓库剩余多少库存
  5166. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5167. var sum_count int64
  5168. for _, it := range list {
  5169. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5170. if it.MaxUnit == baseDrug.MaxUnit {
  5171. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5172. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5173. }
  5174. sum_count += it.StockMaxNumber + it.StockMinNumber
  5175. }
  5176. flow := &models.XtSelfDrugFlow{
  5177. WarehousingId: info.ID,
  5178. DrugId: item.DrugId,
  5179. Number: "",
  5180. BatchNumber: "",
  5181. Count: total_count - in_count,
  5182. UserOrgId: adminInfo.CurrentOrgId,
  5183. PatientId: item.PatientId,
  5184. SystemTime: time.Now().Unix(),
  5185. ConsumableType: 1,
  5186. IsSys: 1,
  5187. WarehousingOrder: warehousing_order,
  5188. WarehouseOutId: 0,
  5189. WarehouseOutOrderNumber: "",
  5190. IsEdit: 0,
  5191. CancelStockId: 0,
  5192. CancelOrderNumber: "",
  5193. Manufacturer: selfBasedrug.Manufacturer,
  5194. Dealer: selfBasedrug.Dealer,
  5195. Creator: Creator,
  5196. UpdateCreator: Creator,
  5197. Status: 1,
  5198. Ctime: item.AdviceDate,
  5199. Mtime: 0,
  5200. Price: item.Price,
  5201. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5202. WarehouseOutDetailId: 0,
  5203. CancelOutDetailId: 0,
  5204. ExpireDate: 0,
  5205. ProductDate: 0,
  5206. MaxUnit: selfBasedrug.MinUnit,
  5207. MinUnit: selfBasedrug.MinUnit,
  5208. StorehouseId: 0,
  5209. OverCount: sum_count,
  5210. OperateTime: time.Now().Unix(),
  5211. AdviceId: item.ID,
  5212. }
  5213. service.CreateSelfDrugFlow(flow, tx)
  5214. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5215. var total_count int64 // 入库总数量
  5216. var over_count int64 //剩余库存
  5217. for _, it := range drugInfolist {
  5218. if it.MaxUnit == selfBasedrug.MaxUnit {
  5219. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5220. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5221. }
  5222. }
  5223. for _, it := range drugInfolist {
  5224. total_count += it.WarehousingCount
  5225. over_count += it.StockMaxNumber + it.StockMinNumber
  5226. }
  5227. //查询该仓库是否有默认数据
  5228. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5229. if selfDrugStock.ID == 0 {
  5230. drugStock := models.XtSelfDrugStockCount{
  5231. UserOrgId: item.UserOrgId,
  5232. PatientId: item.PatientId,
  5233. SumInCount: total_count,
  5234. SumOutCount: 0,
  5235. SumCancelCount: 0,
  5236. DrugId: item.DrugId,
  5237. Ctime: time.Now().Unix(),
  5238. Mtime: 0,
  5239. Status: 1,
  5240. FlushCount: over_count,
  5241. SumActOutCount: 0,
  5242. }
  5243. service.CreateSelfDrugStockSum(drugStock, tx)
  5244. }
  5245. if selfDrugStock.ID > 0 {
  5246. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5247. }
  5248. }
  5249. //查询这个单据的出库数量
  5250. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5251. var his_out_count int64
  5252. for _, item := range drugFlowList {
  5253. his_out_count += item.Count
  5254. }
  5255. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5256. if (total_count + his_out_count) <= in_count {
  5257. // 出库
  5258. if total_count < in_count {
  5259. var cha_count int64
  5260. cha_count = in_count - total_count
  5261. var stock_number int64 = 0
  5262. //查询库存是否充足
  5263. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5264. // 将该批次的剩余库存数量转换为拆零数量
  5265. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5266. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5267. }
  5268. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5269. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5270. }
  5271. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5272. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5273. }
  5274. if stock_number >= cha_count {
  5275. var maxNumber int64 = 0
  5276. var minNumber int64 = 0
  5277. maxNumber = cha_count / selfBasedrug.MinNumber
  5278. minNumber = cha_count % selfBasedrug.MinNumber
  5279. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5280. minNumber = maxNumber
  5281. }
  5282. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5283. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5285. return
  5286. }
  5287. }
  5288. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5289. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5290. }
  5291. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5292. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5293. }
  5294. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5295. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5296. }
  5297. if warehouse.StockMaxNumber < 0 {
  5298. warehouse.StockMaxNumber = 0
  5299. }
  5300. if warehouse.StockMinNumber < 0 {
  5301. warehouse.StockMinNumber = 0
  5302. }
  5303. warehouse.Mtime = time.Now().Unix()
  5304. if warehouse.StockMinNumber < minNumber {
  5305. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5306. if warehouse.MaxUnit != warehouse.MinUnit {
  5307. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5308. }
  5309. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5310. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5311. }
  5312. } else {
  5313. if minNumber > 0 {
  5314. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5315. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5316. }
  5317. }
  5318. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5319. if warehouse.StockMinNumber > 0 {
  5320. if warehouse.StockMinNumber-cha_count >= 0 {
  5321. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5322. }
  5323. }
  5324. }
  5325. }
  5326. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5327. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5328. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5329. }
  5330. }
  5331. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5332. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5334. return
  5335. }
  5336. }
  5337. if warehouse.StockMinNumber <= 0 {
  5338. warehouse.StockMinNumber = 0
  5339. }
  5340. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5341. //查询该药品剩余库存
  5342. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5343. var over_count int64
  5344. for _, its := range infolist {
  5345. if its.MaxUnit == selfBasedrug.MaxUnit {
  5346. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5347. }
  5348. over_count += its.StockMaxNumber + its.StockMinNumber
  5349. }
  5350. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5351. drugflow := models.XtSelfDrugFlow{
  5352. WarehouseOutId: 0,
  5353. WarehouseOutOrderNumber: warehousing_order,
  5354. WarehousingOrder: warehousing_order,
  5355. DrugId: item.DrugId,
  5356. Number: warehouse.Number,
  5357. ProductDate: warehouse.ProductDate,
  5358. ExpireDate: warehouse.ExpiryDate,
  5359. Count: cha_count,
  5360. Price: warehouse.RetailPrice,
  5361. Status: 1,
  5362. Ctime: item.AdviceDate,
  5363. Mtime: time.Now().Unix(),
  5364. UserOrgId: item.UserOrgId,
  5365. Manufacturer: warehouse.Manufacturer,
  5366. Dealer: warehouse.Dealer,
  5367. BatchNumber: warehouse.BatchNumber,
  5368. MaxUnit: selfBasedrug.MinUnit,
  5369. ConsumableType: 20,
  5370. IsEdit: 1,
  5371. Creator: 0,
  5372. IsSys: 3,
  5373. WarehouseOutDetailId: drugWareInfo.ID,
  5374. AdviceId: item.ID,
  5375. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5376. StorehouseId: 0,
  5377. AdminUserId: creater,
  5378. LastPrice: warehouse.Price,
  5379. StockCount: "",
  5380. WarehousingDetailId: 0,
  5381. OverCount: over_count,
  5382. RetailPrice: item.Price, //手动出库出库价格
  5383. WarehousingId: warehouse.ID,
  5384. SystemTime: item.AdviceDate,
  5385. PatientId: item.PatientId,
  5386. Remark: "保存处方入库数据差",
  5387. OperateTime: time.Now().Unix(),
  5388. }
  5389. if warehouse.RetailPrice == 0 {
  5390. drugflow.Price = item.Price
  5391. }
  5392. service.CreateSelfDrugFlowOne(drugflow, tx)
  5393. var out_count int64
  5394. out_count = in_count - total_count
  5395. //
  5396. //fmt.Println("in_count------------------", in_count)
  5397. //fmt.Println("total_count------------------", total_count)
  5398. //添加出库数量
  5399. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5400. //查询剩余库存
  5401. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5402. var sum_count int64
  5403. for _, its := range stockInfo {
  5404. if its.MaxUnit == selfBasedrug.MaxUnit {
  5405. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5406. }
  5407. sum_count += its.StockMaxNumber + its.StockMinNumber
  5408. }
  5409. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5410. } else {
  5411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5412. return
  5413. }
  5414. }
  5415. }
  5416. }
  5417. }
  5418. }
  5419. }
  5420. tx.Commit()
  5421. if err == nil {
  5422. c.ServeSuccessJSON(map[string]interface{}{
  5423. "msg": "保存成功",
  5424. })
  5425. return
  5426. } else {
  5427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5428. return
  5429. }
  5430. }
  5431. }
  5432. //func (c *HisApiController) EditHisPrescription() {
  5433. // record_date := c.GetString("record_date")
  5434. // patient_id, _ := c.GetInt64("patient_id")
  5435. // reg_type, _ := c.GetInt64("reg_type")
  5436. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5437. // diagnose := c.GetString("diagnose")
  5438. // sick_type, _ := c.GetInt64("sick_type")
  5439. // sick_history := c.GetString("sick_history")
  5440. // doctor_id, _ := c.GetInt64("doctor", 0)
  5441. // department, _ := c.GetInt64("department", 0)
  5442. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5443. // p_type, _ := c.GetInt64("p_type")
  5444. //
  5445. // dataBody := make(map[string]interface{}, 0)
  5446. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5447. // if err != nil {
  5448. // utils.ErrorLog(err.Error())
  5449. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5450. // return
  5451. // }
  5452. //
  5453. // timeLayout := "2006-01-02"
  5454. // loc, _ := time.LoadLocation("Local")
  5455. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5456. // if err != nil {
  5457. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5458. // return
  5459. // }
  5460. // adminInfo := c.GetAdminUserInfo()
  5461. // recordDateTime := theTime.Unix()
  5462. //
  5463. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5464. //
  5465. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5466. // var hpInfo models.HisPrescriptionInfo
  5467. // if info.ID == 0 {
  5468. // var randNum int
  5469. // randNum = rand.Intn(10000) + 1000
  5470. // timestamp := time.Now().Unix()
  5471. // tempTime := time.Unix(timestamp, 0)
  5472. // timeFormat := tempTime.Format("20060102150405")
  5473. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5474. //
  5475. // hpInfo = models.HisPrescriptionInfo{
  5476. // UserOrgId: adminInfo.CurrentOrgId,
  5477. // RecordDate: theTime.Unix(),
  5478. // PatientId: patient_id,
  5479. // Status: 1,
  5480. // Ctime: time.Now().Unix(),
  5481. // Mtime: time.Now().Unix(),
  5482. // Creator: adminInfo.AdminUser.Id,
  5483. // Modifier: adminInfo.AdminUser.Id,
  5484. // Diagnosis: diagnose,
  5485. // SickHistory: sick_history,
  5486. // Departments: department,
  5487. // RegisterType: reg_type,
  5488. // PrescriptionNumber: p_number,
  5489. // PrescriptionStatus: 1,
  5490. // Doctor: role.UserName,
  5491. // DoctorId: doctor_id,
  5492. // SickType: sick_type,
  5493. // PType: p_type,
  5494. // }
  5495. // service.SavePatientPrescriptionInfo(hpInfo)
  5496. //
  5497. // } else {
  5498. // hpInfo = models.HisPrescriptionInfo{
  5499. // ID: info.ID,
  5500. // UserOrgId: adminInfo.CurrentOrgId,
  5501. // RecordDate: info.RecordDate,
  5502. // PatientId: info.PatientId,
  5503. // Status: 1,
  5504. // Ctime: info.Ctime,
  5505. // Mtime: time.Now().Unix(),
  5506. // Creator: info.Creator,
  5507. // Modifier: adminInfo.AdminUser.Id,
  5508. // Diagnosis: diagnose,
  5509. // SickHistory: sick_history,
  5510. // Departments: department,
  5511. // RegisterType: reg_type,
  5512. // PrescriptionNumber: info.PrescriptionNumber,
  5513. // Doctor: role.UserName,
  5514. // PrescriptionStatus: info.PrescriptionStatus,
  5515. // DoctorId: doctor_id,
  5516. // SickType: sick_type,
  5517. // PType: info.PType,
  5518. // }
  5519. // service.SavePatientPrescriptionInfo(hpInfo)
  5520. // }
  5521. //
  5522. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5523. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5524. //
  5525. // if len(prescriptions) > 0 {
  5526. // for _, item := range prescriptions {
  5527. // items := item.(map[string]interface{})
  5528. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5529. // utils.ErrorLog("id")
  5530. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5531. // return
  5532. // }
  5533. // id := int64(items["id"].(float64))
  5534. //
  5535. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5536. // utils.ErrorLog("type")
  5537. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5538. // return
  5539. // }
  5540. // types := int64(items["type"].(float64))
  5541. //
  5542. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5543. // utils.ErrorLog("med_type")
  5544. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5545. // return
  5546. // }
  5547. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5548. //
  5549. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5550. //
  5551. // ctime := time.Now().Unix()
  5552. //
  5553. // prescription := &models.HisPrescription{
  5554. // ID: id,
  5555. // PatientId: patient_id,
  5556. // UserOrgId: adminInfo.CurrentOrgId,
  5557. // RecordDate: recordDateTime,
  5558. // Ctime: ctime,
  5559. // Mtime: ctime,
  5560. // Type: types,
  5561. // Modifier: adminInfo.AdminUser.Id,
  5562. // Creator: adminInfo.AdminUser.Id,
  5563. // Status: 1,
  5564. // Doctor: role.UserName,
  5565. // HisPatientId: his_patient_id,
  5566. // OrderStatus: 1,
  5567. // BatchNumber: "",
  5568. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5569. // PType: hpInfo.PType,
  5570. // MedType: med_type,
  5571. // }
  5572. //
  5573. // if historyPrescription.ID > 0 {
  5574. // prescription.PreTime = historyPrescription.PreTime
  5575. //
  5576. // }
  5577. //
  5578. // service.SaveHisPrescription(prescription)
  5579. //
  5580. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5581. // advices := items["advices"].([]interface{})
  5582. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5583. // groupNo := int64(0)
  5584. // ctime := time.Now().Unix()
  5585. // mtime := ctime
  5586. // if len(advices) > 0 {
  5587. // for _, advice := range advices {
  5588. // var s models.HisDoctorAdviceInfo
  5589. // s.PrescriptionId = prescription.ID
  5590. // s.AdviceType = 2
  5591. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5592. // s.StopState = 2
  5593. // s.ExecutionState = 2
  5594. // s.AdviceDate = recordDateTime
  5595. // s.Status = 1
  5596. // s.UserOrgId = adminInfo.CurrentOrgId
  5597. // s.RecordDate = recordDateTime
  5598. // s.StartTime = prescription.PreTime
  5599. // s.Groupno = groupNo
  5600. // s.CreatedTime = ctime
  5601. // s.UpdatedTime = mtime
  5602. // s.PatientId = patient_id
  5603. // s.HisPatientId = his_patient_id
  5604. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5605. // if errcode > 0 {
  5606. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5607. // return
  5608. // }
  5609. //
  5610. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5611. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5612. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5613. // if s.Price == 0 {
  5614. // s.Price = lastWarehouse.RetailPrice
  5615. // }
  5616. // }
  5617. //
  5618. // service.CreateHisDoctorAdvice(&s)
  5619. // //记录日志
  5620. // byterequest, _ := json.Marshal(s)
  5621. // adviceLog := models.XtDoctorAdviceLog{
  5622. // UserOrgId: s.UserOrgId,
  5623. // PatientId: s.PatientId,
  5624. // AdminUserId: adminInfo.AdminUser.Id,
  5625. // Module: 1,
  5626. // ErrLog: string(byterequest),
  5627. // Status: 1,
  5628. // Ctime: time.Now().Unix(),
  5629. // Mtime: 0,
  5630. // Source: "电脑端his医嘱修改",
  5631. // RecordDate: s.AdviceDate,
  5632. // }
  5633. // service.CreateDoctorAdviceLog(adviceLog)
  5634. // redis := service.RedisClient()
  5635. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5636. // redis.Set(key, "", time.Second)
  5637. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5638. // fmt.Println("keyOne", keyOne)
  5639. // redis.Set(keyOne, "", time.Second)
  5640. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5641. // redis.Set(keySeven, "", time.Second)
  5642. // redis.Close()
  5643. //
  5644. // }
  5645. // }
  5646. // }
  5647. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5648. // projects := items["project"].([]interface{})
  5649. // if len(projects) > 0 {
  5650. // for _, project := range projects {
  5651. // var p models.HisPrescriptionProject
  5652. // p.PrescriptionId = prescription.ID
  5653. // p.Ctime = time.Now().Unix()
  5654. // p.Mtime = time.Now().Unix()
  5655. // p.PatientId = patient_id
  5656. // p.RecordDate = recordDateTime
  5657. // p.UserOrgId = adminInfo.CurrentOrgId
  5658. // p.HisPatientId = his_patient_id
  5659. // p.Status = 1
  5660. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5661. // if errcode > 0 {
  5662. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5663. // return
  5664. // }
  5665. // service.CreateHisProjectTwo(&p)
  5666. //
  5667. // //记录日志
  5668. // byterequest, _ := json.Marshal(p)
  5669. // adviceLog := models.XtDoctorAdviceLog{
  5670. // UserOrgId: p.UserOrgId,
  5671. // PatientId: p.PatientId,
  5672. // AdminUserId: adminInfo.AdminUser.Id,
  5673. // Module: 1,
  5674. // ErrLog: string(byterequest),
  5675. // Status: 1,
  5676. // Ctime: time.Now().Unix(),
  5677. // Mtime: 0,
  5678. // Source: "电脑端his项目修改",
  5679. // RecordDate: p.RecordDate,
  5680. // }
  5681. // service.CreateDoctorAdviceLog(adviceLog)
  5682. // }
  5683. // }
  5684. // }
  5685. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5686. // addition := items["addition"].([]interface{})
  5687. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5688. // ctime := time.Now().Unix()
  5689. // mtime := ctime
  5690. // if len(addition) > 0 {
  5691. // for _, item := range addition {
  5692. // var s models.HisAdditionalCharge
  5693. // s.PrescriptionId = prescription.ID
  5694. // s.Status = 1
  5695. // s.UserOrgId = adminInfo.CurrentOrgId
  5696. // s.RecordDate = recordDateTime
  5697. // s.CreatedTime = ctime
  5698. // s.UpdatedTime = mtime
  5699. // s.PatientId = patient_id
  5700. // s.HisPatientId = his_patient_id
  5701. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5702. // if errcode > 0 {
  5703. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5704. // return
  5705. // }
  5706. // service.CreateAdditionalCharge(&s)
  5707. // }
  5708. // }
  5709. // }
  5710. //
  5711. // }
  5712. // }
  5713. // }
  5714. // if err == nil {
  5715. // c.ServeSuccessJSON(map[string]interface{}{
  5716. // "msg": "保存成功",
  5717. // })
  5718. // return
  5719. //
  5720. // } else {
  5721. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5722. // return
  5723. // }
  5724. //}
  5725. func (c *HisApiController) DeletePrescription() {
  5726. prescription_id, _ := c.GetInt64("id")
  5727. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5728. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5729. ////同步到自备药
  5730. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5731. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5732. if selfPrescriptionOpen.IsOpen == 1 {
  5733. // 在函数结束时处理事务回滚
  5734. db := service.XTWriteDB()
  5735. tx := db.Begin()
  5736. defer func() {
  5737. if r := recover(); r != nil {
  5738. tx.Rollback()
  5739. } else {
  5740. tx.Commit()
  5741. }
  5742. }()
  5743. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5744. for _, item := range advicesList {
  5745. timeStr := time.Now().Format("2006-01-02")
  5746. timeArr := strings.Split(timeStr, "-")
  5747. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5748. total = total + 1
  5749. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5750. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5751. number = number + total
  5752. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5753. operation_time := time.Now().Unix()
  5754. creater := c.GetAdminUserInfo().AdminUser.Id
  5755. //创建一个出库单
  5756. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5757. WarehouseOutOrderNumber: warehousing_out_order,
  5758. OperationTime: operation_time,
  5759. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5760. Creater: creater,
  5761. Ctime: time.Now().Unix(),
  5762. Status: 1,
  5763. WarehouseOutTime: item.AdviceDate,
  5764. Type: 0,
  5765. PatientId: item.PatientId,
  5766. IsCheck: 1,
  5767. }
  5768. //查询今日是否有出库数据
  5769. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5770. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5771. if lastWarehouseOut.ID == 0 {
  5772. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5773. }
  5774. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5775. var total_count int64
  5776. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5777. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5778. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5779. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5780. }
  5781. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5782. total_count += prescribingNumberSeven
  5783. }
  5784. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5785. total_count += prescribingNumberSeven
  5786. }
  5787. //出库
  5788. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5789. WarehouseOutOrderNumber: warehousing_out_order,
  5790. WarehouseOutId: lastWarehouseOut.ID,
  5791. DrugId: item.DrugId,
  5792. Count: total_count,
  5793. Price: 0,
  5794. TotalPrice: 0,
  5795. Status: 1,
  5796. Ctime: item.AdviceDate,
  5797. Mtime: item.AdviceDate,
  5798. Remark: "",
  5799. OrgId: item.UserOrgId,
  5800. Type: 0,
  5801. Manufacturer: selfBasedrug.Manufacturer,
  5802. Dealer: selfBasedrug.Dealer,
  5803. RetailPrice: 0,
  5804. RetailTotalPrice: 0,
  5805. CountUnit: selfBasedrug.MinUnit,
  5806. ExpiryDate: 0,
  5807. ProductDate: 0,
  5808. Number: "",
  5809. BatchNumber: "",
  5810. IsSys: 1,
  5811. WarehouseInfoId: 0,
  5812. AdminUserId: 0,
  5813. StockCount: "",
  5814. IsCheck: 1,
  5815. SysRecordTime: item.AdviceDate,
  5816. PatientId: item.PatientId,
  5817. ClassType: "",
  5818. AdviceId: item.ID,
  5819. }
  5820. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5821. }
  5822. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5823. for _, it := range warehousingOutInfo {
  5824. //查询今日是否有出库数据
  5825. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5826. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5827. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5828. //出库逻辑
  5829. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5830. //查询剩余库存
  5831. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5832. var sum_count int64
  5833. for _, its := range stockInfo {
  5834. if its.MaxUnit == medical.MaxUnit {
  5835. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5836. }
  5837. sum_count += its.StockMaxNumber + its.StockMinNumber
  5838. }
  5839. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5840. }
  5841. }
  5842. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5843. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5844. //耗材保存处方出库
  5845. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5846. //已收费和已发药限制逻辑
  5847. isCharge := false
  5848. isMedicine := false
  5849. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5850. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5851. if new_prescription.IsMedicine == 1 {
  5852. isMedicine = true
  5853. }
  5854. for _, item := range new_prescriptions {
  5855. if item.OrderStatus == 4 {
  5856. isCharge = true
  5857. }
  5858. }
  5859. if p_err != nil {
  5860. if new_prescription.ID > 0 {
  5861. if new_prescription.OrderStatus == 2 {
  5862. isCharge = true
  5863. }
  5864. }
  5865. }
  5866. for _, item := range advices {
  5867. if item.IsMedicine == 1 {
  5868. isMedicine = true
  5869. }
  5870. }
  5871. if isCharge {
  5872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5873. return
  5874. }
  5875. if isMedicine {
  5876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5877. return
  5878. }
  5879. //已收费和已发药限制逻辑
  5880. if len(projects) > 0 {
  5881. for _, item := range projects {
  5882. service.DeletePrintInfo(item.ID) //删除打印信息
  5883. if goodOutConfig.IsOpen != 1 {
  5884. if stockConfig.IsOpen == 1 {
  5885. if item.Type == 3 && item.IsOut == 1 {
  5886. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5887. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5888. good.Total = good.Total + f_count
  5889. service.UpdateGoodInfo(&good)
  5890. operation_time := time.Now().Unix()
  5891. creater := c.GetAdminUserInfo().AdminUser.Id
  5892. //创建退库单
  5893. timeStr := time.Now().Format("2006-01-02")
  5894. timeArr := strings.Split(timeStr, "-")
  5895. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5896. total = total + 1
  5897. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5898. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5899. cancelStock := models.CancelStock{
  5900. OrderNumber: orderNumber,
  5901. OperaTime: operation_time,
  5902. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5903. Creater: creater,
  5904. Ctime: time.Now().Unix(),
  5905. Status: 1,
  5906. ReturnTime: item.RecordDate,
  5907. Type: 1,
  5908. StorehouseId: houseConfig.StorehouseOutInfo,
  5909. IsCheck: 1,
  5910. }
  5911. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5912. if msgerrkonde == gorm.ErrRecordNotFound {
  5913. service.AddSigleCancelStock(&cancelStock)
  5914. }
  5915. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5916. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5917. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5918. //查询该耗材是否出库
  5919. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5920. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5921. deaerler, _ := service.GetDealerById(info.Dealer)
  5922. var total_count int64
  5923. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5924. total_count += count
  5925. if info.ID > 0 {
  5926. if info.Count >= total_count {
  5927. //回退库存
  5928. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5929. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5930. var flush_count int64
  5931. for _, it := range goodList {
  5932. flush_count += it.StockCount
  5933. }
  5934. cancelStockInfo := models.CancelStockInfo{
  5935. GoodId: item.ProjectId,
  5936. CancelStockId: cancel.ID,
  5937. GoodTypeId: good.GoodTypeId,
  5938. Count: prescribingNumber,
  5939. Price: info.Price,
  5940. Total: 0,
  5941. ProductDate: info.ProductDate,
  5942. ExpiryDate: info.ExpiryDate,
  5943. Ctime: time.Now().Unix(),
  5944. Status: 1,
  5945. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5946. OrderNumber: cancel.OrderNumber,
  5947. Type: 0,
  5948. Dealer: deaerler.DealerName,
  5949. Manufacturer: manufacturer.ManufacturerName,
  5950. Number: info.Number,
  5951. RegisterAccount: "",
  5952. Remark: "",
  5953. WarehouseInfoId: info.WarehouseInfotId,
  5954. PatientId: info.PatientId,
  5955. RecordDate: info.SysRecordTime,
  5956. StorehouseId: houseConfig.StorehouseOutInfo,
  5957. IsCheck: 1,
  5958. }
  5959. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5960. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5961. flow := models.VmStockFlow{
  5962. WarehousingId: info.WarehouseInfotId,
  5963. GoodId: item.ProjectId,
  5964. Number: info.Number,
  5965. LicenseNumber: info.LicenseNumber,
  5966. Count: prescribingNumber,
  5967. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5968. PatientId: item.PatientId,
  5969. SystemTime: info.SysRecordTime,
  5970. ConsumableType: 7,
  5971. IsSys: 0,
  5972. WarehousingOrder: "",
  5973. WarehouseOutId: info.WarehouseOutId,
  5974. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5975. IsEdit: 0,
  5976. CancelStockId: cancel.ID,
  5977. CancelOrderNumber: cancel.OrderNumber,
  5978. Manufacturer: manufacturer.ID,
  5979. Dealer: 0,
  5980. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5981. UpdateCreator: 0,
  5982. Status: 1,
  5983. Ctime: time.Now().Unix(),
  5984. Mtime: 0,
  5985. Price: info.Price,
  5986. WarehousingDetailId: info.WarehouseInfotId,
  5987. WarehouseOutDetailId: info.ID,
  5988. CancelOutDetailId: cancelInfo.ID,
  5989. ProductDate: info.ProductDate,
  5990. ExpireDate: info.ExpiryDate,
  5991. StorehouseId: houseConfig.StorehouseOutInfo,
  5992. OverCount: flush_count,
  5993. OperateTime: time.Now().Unix(),
  5994. }
  5995. service.CreateStockFlowOne(flow)
  5996. //退库数量增加
  5997. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5998. //出库数量减少
  5999. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6000. }
  6001. if info.Count < total_count {
  6002. //回退库存
  6003. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6004. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6005. var flush_count int64
  6006. for _, it := range goodList {
  6007. flush_count += it.StockCount
  6008. }
  6009. cancelStockInfo := models.CancelStockInfo{
  6010. GoodId: item.ProjectId,
  6011. CancelStockId: cancel.ID,
  6012. GoodTypeId: good.GoodTypeId,
  6013. Count: info.Count,
  6014. Price: info.Price,
  6015. Total: 0,
  6016. ProductDate: info.ProductDate,
  6017. ExpiryDate: info.ExpiryDate,
  6018. Ctime: time.Now().Unix(),
  6019. Status: 1,
  6020. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6021. OrderNumber: cancel.OrderNumber,
  6022. Type: 0,
  6023. Dealer: deaerler.DealerName,
  6024. Manufacturer: manufacturer.ManufacturerName,
  6025. Number: info.Number,
  6026. RegisterAccount: "",
  6027. Remark: "",
  6028. WarehouseInfoId: info.WarehouseInfotId,
  6029. PatientId: info.PatientId,
  6030. RecordDate: info.SysRecordTime,
  6031. StorehouseId: houseConfig.StorehouseOutInfo,
  6032. IsCheck: 1,
  6033. }
  6034. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6035. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6036. flow := models.VmStockFlow{
  6037. WarehousingId: info.WarehouseInfotId,
  6038. GoodId: item.ProjectId,
  6039. Number: info.Number,
  6040. LicenseNumber: info.LicenseNumber,
  6041. Count: info.Count,
  6042. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6043. PatientId: item.PatientId,
  6044. SystemTime: info.SysRecordTime,
  6045. ConsumableType: 7,
  6046. IsSys: 0,
  6047. WarehousingOrder: "",
  6048. WarehouseOutId: info.WarehouseOutId,
  6049. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6050. IsEdit: 0,
  6051. CancelStockId: cancel.ID,
  6052. CancelOrderNumber: cancel.OrderNumber,
  6053. Manufacturer: manufacturer.ID,
  6054. Dealer: 0,
  6055. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6056. UpdateCreator: 0,
  6057. Status: 1,
  6058. Ctime: time.Now().Unix(),
  6059. Mtime: 0,
  6060. Price: info.Price,
  6061. WarehousingDetailId: info.WarehouseInfotId,
  6062. WarehouseOutDetailId: info.ID,
  6063. CancelOutDetailId: cancelInfo.ID,
  6064. ProductDate: info.ProductDate,
  6065. ExpireDate: info.ExpiryDate,
  6066. StorehouseId: houseConfig.StorehouseOutInfo,
  6067. OverCount: flush_count,
  6068. OperateTime: time.Now().Unix(),
  6069. }
  6070. service.CreateStockFlowOne(flow)
  6071. //退库数量增加
  6072. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6073. //出库数量减少
  6074. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6075. }
  6076. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6077. var flush_count int64
  6078. for _, it := range goodList {
  6079. flush_count += it.StockCount
  6080. }
  6081. //查询已出库数量
  6082. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6083. if prescribingNumber < dialysisInfo.Count {
  6084. //改变数量
  6085. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6086. }
  6087. if prescribingNumber >= dialysisInfo.Count {
  6088. //删除出库表
  6089. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6090. }
  6091. //更新库存
  6092. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6093. //更新基础库库存
  6094. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6095. }
  6096. }
  6097. }
  6098. }
  6099. //保存耗材出库
  6100. if goodOutConfig.IsOpen == 1 {
  6101. if item.Type == 3 {
  6102. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6103. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6104. good.Total = good.Total + f_count
  6105. service.UpdateGoodInfo(&good)
  6106. operation_time := time.Now().Unix()
  6107. creater := c.GetAdminUserInfo().AdminUser.Id
  6108. //创建退库单
  6109. timeStr := time.Now().Format("2006-01-02")
  6110. timeArr := strings.Split(timeStr, "-")
  6111. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6112. total = total + 1
  6113. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6114. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6115. cancelStock := models.CancelStock{
  6116. OrderNumber: orderNumber,
  6117. OperaTime: operation_time,
  6118. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6119. Creater: creater,
  6120. Ctime: time.Now().Unix(),
  6121. Status: 1,
  6122. ReturnTime: item.RecordDate,
  6123. Type: 1,
  6124. StorehouseId: houseConfig.StorehouseOutInfo,
  6125. IsCheck: 1,
  6126. }
  6127. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6128. if msgerrkonde == gorm.ErrRecordNotFound {
  6129. service.AddSigleCancelStock(&cancelStock)
  6130. }
  6131. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6132. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6133. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6134. //查询该耗材是否出库
  6135. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6136. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6137. deaerler, _ := service.GetDealerById(info.Dealer)
  6138. var total_count int64
  6139. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6140. total_count += count
  6141. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6142. var flush_count int64
  6143. for _, it := range goodList {
  6144. flush_count += it.StockCount
  6145. }
  6146. fmt.Println("历史出库数据", info.Count)
  6147. fmt.Println("出库数量", total_count)
  6148. if info.ID > 0 {
  6149. cancelStockInfo := models.CancelStockInfo{
  6150. GoodId: item.ProjectId,
  6151. CancelStockId: cancel.ID,
  6152. GoodTypeId: good.GoodTypeId,
  6153. Count: prescribingNumber,
  6154. Price: info.Price,
  6155. Total: 0,
  6156. ProductDate: info.ProductDate,
  6157. ExpiryDate: info.ExpiryDate,
  6158. Ctime: time.Now().Unix(),
  6159. Status: 1,
  6160. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6161. OrderNumber: cancel.OrderNumber,
  6162. Type: 0,
  6163. Dealer: deaerler.DealerName,
  6164. Manufacturer: manufacturer.ManufacturerName,
  6165. Number: info.Number,
  6166. RegisterAccount: "",
  6167. Remark: "",
  6168. WarehouseInfoId: info.WarehouseInfotId,
  6169. PatientId: info.PatientId,
  6170. RecordDate: info.SysRecordTime,
  6171. StorehouseId: houseConfig.StorehouseOutInfo,
  6172. IsCheck: 1,
  6173. }
  6174. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6175. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6176. //查询出库数量
  6177. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6178. //出库数据 大于 退库数量
  6179. if len(list) > 0 {
  6180. for _, it := range list {
  6181. //回退库存
  6182. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6183. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6184. var flush_count_one int64
  6185. for _, it := range goodList {
  6186. flush_count_one += it.StockCount
  6187. }
  6188. //查询该批次是否有退库数据
  6189. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6190. creater := c.GetAdminUserInfo().AdminUser.Id
  6191. flow := models.VmStockFlow{
  6192. WarehousingId: it.WarehouseInfotId,
  6193. GoodId: it.GoodId,
  6194. Number: it.Number,
  6195. LicenseNumber: it.LicenseNumber,
  6196. Count: it.Count,
  6197. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6198. PatientId: it.PatientId,
  6199. SystemTime: it.SysRecordTime,
  6200. ConsumableType: 7,
  6201. IsSys: 0,
  6202. WarehousingOrder: "",
  6203. WarehouseOutId: it.WarehouseOutId,
  6204. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6205. IsEdit: 0,
  6206. CancelStockId: cancel.ID,
  6207. CancelOrderNumber: cancel.OrderNumber,
  6208. Manufacturer: manufacturer.ID,
  6209. Dealer: 0,
  6210. Creator: creater,
  6211. UpdateCreator: 0,
  6212. Status: 1,
  6213. Ctime: time.Now().Unix(),
  6214. Mtime: 0,
  6215. Price: it.Price,
  6216. WarehousingDetailId: it.WarehouseInfotId,
  6217. WarehouseOutDetailId: it.ID,
  6218. CancelOutDetailId: cancelInfo.ID,
  6219. ProductDate: it.ProductDate,
  6220. ExpireDate: it.ExpiryDate,
  6221. StorehouseId: houseConfig.StorehouseOutInfo,
  6222. OverCount: flush_count_one,
  6223. OperateTime: time.Now().Unix(),
  6224. }
  6225. service.CreateStockFlowOne(flow)
  6226. //if flow.ID > 0 {
  6227. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6228. //}
  6229. }
  6230. }
  6231. //flow := models.VmStockFlow{
  6232. // WarehousingId: info.WarehouseInfotId,
  6233. // GoodId: item.ProjectId,
  6234. // Number: info.Number,
  6235. // LicenseNumber: info.LicenseNumber,
  6236. // Count: prescribingNumber,
  6237. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6238. // PatientId: item.PatientId,
  6239. // SystemTime: info.SysRecordTime,
  6240. // ConsumableType: 7,
  6241. // IsSys: 0,
  6242. // WarehousingOrder: "",
  6243. // WarehouseOutId: info.WarehouseOutId,
  6244. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6245. // IsEdit: 0,
  6246. // CancelStockId: cancel.ID,
  6247. // CancelOrderNumber: cancel.OrderNumber,
  6248. // Manufacturer: manufacturer.ID,
  6249. // Dealer: 0,
  6250. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6251. // UpdateCreator: 0,
  6252. // Status: 1,
  6253. // Ctime: time.Now().Unix(),
  6254. // Mtime: 0,
  6255. // Price: info.Price,
  6256. // WarehousingDetailId: info.WarehouseInfotId,
  6257. // WarehouseOutDetailId: info.ID,
  6258. // CancelOutDetailId: cancelInfo.ID,
  6259. // ProductDate: info.ProductDate,
  6260. // ExpireDate: info.ExpiryDate,
  6261. // StorehouseId: houseConfig.StorehouseOutInfo,
  6262. // OverCount: flush_count,
  6263. //}
  6264. //service.CreateStockFlowOne(flow)
  6265. //退库数量增加
  6266. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6267. //出库数量减少
  6268. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6269. //查询已出库数量
  6270. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6271. if prescribingNumber < dialysisInfo.Count {
  6272. //改变数量
  6273. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6274. }
  6275. if prescribingNumber >= dialysisInfo.Count {
  6276. //删除出库表
  6277. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6278. }
  6279. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6280. var flush_count_one int64
  6281. for _, it := range goodList {
  6282. flush_count_one += it.StockCount
  6283. }
  6284. //更新库存
  6285. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6286. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6287. //更新基础库库存
  6288. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6289. }
  6290. }
  6291. }
  6292. }
  6293. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6294. fmt.Println(err)
  6295. }
  6296. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6297. fmt.Println(err)
  6298. if len(advices) > 0 {
  6299. for _, item := range advices {
  6300. redis := service.RedisClient()
  6301. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6302. redis.Set(keyFive, "", time.Second)
  6303. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6304. redis.Set(keyOne, "", time.Second)
  6305. redis.Close()
  6306. }
  6307. }
  6308. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6309. if len(advices) > 0 {
  6310. for _, item := range advices {
  6311. creater := c.GetAdminUserInfo().AdminUser.Id
  6312. service.DrugAutoAddCancelInfo(item, creater)
  6313. }
  6314. }
  6315. } else {
  6316. if drugOutConfig.IsOpen == 1 {
  6317. if len(advices) > 0 {
  6318. for _, item := range advices {
  6319. creater := c.GetAdminUserInfo().AdminUser.Id
  6320. service.DrugAutoAddCancelInfo(item, creater)
  6321. }
  6322. }
  6323. } else {
  6324. if len(advices) > 0 {
  6325. for _, item := range advices {
  6326. creater := c.GetAdminUserInfo().AdminUser.Id
  6327. service.DrugAutoAddCancelInfo(item, creater)
  6328. }
  6329. }
  6330. }
  6331. }
  6332. c.ServeSuccessJSON(map[string]interface{}{
  6333. "msg": "删除成功",
  6334. })
  6335. return
  6336. }
  6337. func (c *HisApiController) DeleteDoctorAdvice() {
  6338. id, _ := c.GetInt64("id")
  6339. advice, _ := service.GetHisDoctorAdvicesById(id)
  6340. ////同步到自备药
  6341. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6342. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6343. if selfPrescriptionOpen.IsOpen == 1 {
  6344. db := service.XTWriteDB()
  6345. tx := db.Begin()
  6346. defer func() {
  6347. if r := recover(); r != nil {
  6348. tx.Rollback()
  6349. } else {
  6350. tx.Commit()
  6351. }
  6352. }()
  6353. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6354. var total_count int64
  6355. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6356. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6357. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6358. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6359. }
  6360. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6361. total_count += prescribingNumberSeven
  6362. }
  6363. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6364. total_count += prescribingNumberSeven
  6365. }
  6366. timeStr := time.Now().Format("2006-01-02")
  6367. timeArr := strings.Split(timeStr, "-")
  6368. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6369. total = total + 1
  6370. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6371. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6372. number = number + total
  6373. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6374. operation_time := time.Now().Unix()
  6375. creater := c.GetAdminUserInfo().AdminUser.Id
  6376. //创建一个出库单
  6377. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6378. WarehouseOutOrderNumber: warehousing_out_order,
  6379. OperationTime: operation_time,
  6380. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6381. Creater: creater,
  6382. Ctime: time.Now().Unix(),
  6383. Status: 1,
  6384. WarehouseOutTime: advice.AdviceDate,
  6385. Type: 0,
  6386. PatientId: advice.PatientId,
  6387. IsCheck: 1,
  6388. }
  6389. //查询今日是否有出库数据
  6390. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6391. if lastWarehouseOut.ID == 0 {
  6392. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6393. }
  6394. //出库
  6395. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6396. WarehouseOutId: lastWarehouseOut.ID,
  6397. WarehouseOutOrderNumber: warehousing_out_order,
  6398. DrugId: advice.DrugId,
  6399. Count: total_count,
  6400. Price: 0,
  6401. TotalPrice: 0,
  6402. Status: 1,
  6403. Ctime: advice.AdviceDate,
  6404. Mtime: advice.AdviceDate,
  6405. Remark: "",
  6406. OrgId: advice.UserOrgId,
  6407. Type: 0,
  6408. Manufacturer: selfBasedrug.Manufacturer,
  6409. Dealer: selfBasedrug.Dealer,
  6410. RetailPrice: 0,
  6411. RetailTotalPrice: 0,
  6412. CountUnit: advice.PrescribingNumberUnit,
  6413. ExpiryDate: 0,
  6414. ProductDate: 0,
  6415. Number: "",
  6416. BatchNumber: "",
  6417. IsSys: 0,
  6418. WarehouseInfoId: 0,
  6419. AdminUserId: 0,
  6420. StockCount: "",
  6421. IsCheck: 1,
  6422. SysRecordTime: advice.AdviceDate,
  6423. PatientId: advice.PatientId,
  6424. AdviceId: advice.ID,
  6425. ClassType: "",
  6426. }
  6427. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6428. for _, it := range warehousingOutInfo {
  6429. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6430. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6431. //出库逻辑
  6432. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6433. //查询剩余库存
  6434. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6435. var sum_count int64
  6436. for _, its := range stockInfo {
  6437. if its.MaxUnit == medical.MaxUnit {
  6438. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6439. }
  6440. sum_count += its.StockMaxNumber + its.StockMinNumber
  6441. }
  6442. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6443. }
  6444. }
  6445. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6446. //已收费和已发药的限制逻辑
  6447. isCharge := false
  6448. isMedicine := false
  6449. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6450. //获取今天该患者所有处方,判断是否发药或者收费
  6451. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6452. //for _, item := range new_prescriptions {
  6453. if new_prescription.IsMedicine == 1 {
  6454. isMedicine = true
  6455. }
  6456. //}
  6457. for _, item := range new_prescriptions {
  6458. if item.OrderStatus == 4 {
  6459. isCharge = true
  6460. }
  6461. }
  6462. if isMedicine {
  6463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6464. return
  6465. }
  6466. if isCharge {
  6467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6468. return
  6469. }
  6470. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6471. for _, item := range advices {
  6472. if item.IsMedicine == 1 {
  6473. isMedicine = true
  6474. }
  6475. }
  6476. if isMedicine {
  6477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6478. return
  6479. }
  6480. if new_prescription.ID > 0 {
  6481. if new_prescription.OrderStatus == 2 {
  6482. isCharge = true
  6483. }
  6484. }
  6485. if isCharge {
  6486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6487. return
  6488. }
  6489. //已收费和已发药的限制逻辑
  6490. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6491. redis := service.RedisClient()
  6492. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6493. redis.Set(keyFive, "", time.Second)
  6494. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6495. redis.Set(keyOne, "", time.Second)
  6496. defer redis.Close()
  6497. if err == nil {
  6498. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6499. //查询是否在处方中出库
  6500. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6501. if openConfig.IsOpen != 1 {
  6502. //判断该医嘱是否执行了
  6503. if advice.ExecutionState == 1 {
  6504. creater := c.GetAdminUserInfo().AdminUser.Id
  6505. service.DrugAutoAddCancelInfo(&advice, creater)
  6506. }
  6507. }
  6508. //开启保存处方扣减功能
  6509. if openConfig.IsOpen == 1 {
  6510. creater := c.GetAdminUserInfo().AdminUser.Id
  6511. service.DrugAutoAddCancelInfo(&advice, creater)
  6512. }
  6513. } else {
  6514. if drugOutConfig.IsOpen == 1 {
  6515. //查询是否在处方中出库
  6516. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6517. if openConfig.IsOpen != 1 {
  6518. //判断该医嘱是否执行了
  6519. if advice.ExecutionState == 1 {
  6520. creater := c.GetAdminUserInfo().AdminUser.Id
  6521. service.DrugAutoAddCancelInfo(&advice, creater)
  6522. }
  6523. }
  6524. //开启保存处方扣减功能
  6525. if openConfig.IsOpen == 1 {
  6526. creater := c.GetAdminUserInfo().AdminUser.Id
  6527. service.DrugAutoAddCancelInfo(&advice, creater)
  6528. }
  6529. } else {
  6530. //判断该医嘱是否执行了
  6531. if advice.ExecutionState == 1 {
  6532. creater := c.GetAdminUserInfo().AdminUser.Id
  6533. service.DrugAutoAddCancelInfo(&advice, creater)
  6534. }
  6535. }
  6536. }
  6537. c.ServeSuccessJSON(map[string]interface{}{
  6538. "msg": "删除成功",
  6539. })
  6540. return
  6541. } else {
  6542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6543. return
  6544. }
  6545. }
  6546. func (c *HisApiController) DeleteProject() {
  6547. id, _ := c.GetInt64("id")
  6548. adminInfo := c.GetAdminUserInfo()
  6549. project, _ := service.GetHisProjectByID(id)
  6550. // var consumable models.DialysisBeforePrepare
  6551. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6552. //耗材保存处方出库
  6553. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6554. isCharge := false
  6555. isMedicine := false
  6556. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6557. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6558. for _, item := range new_prescriptions {
  6559. if item.IsMedicine == 1 {
  6560. isMedicine = true
  6561. }
  6562. }
  6563. for _, item := range new_prescriptions {
  6564. if item.OrderStatus == 4 {
  6565. isCharge = true
  6566. }
  6567. }
  6568. if isMedicine {
  6569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6570. return
  6571. }
  6572. if isCharge {
  6573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6574. return
  6575. }
  6576. if new_prescription.ID > 0 {
  6577. if new_prescription.OrderStatus == 2 {
  6578. isCharge = true
  6579. }
  6580. }
  6581. if isCharge {
  6582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6583. return
  6584. }
  6585. service.DeletePrintInfo(id)
  6586. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6587. label.Status = 0
  6588. service.CreateHisLabelRecordTwo(&label)
  6589. fmt.Println(goodOutConfig.IsOpen)
  6590. if goodOutConfig.IsOpen != 1 {
  6591. if stockConfig.IsOpen == 1 {
  6592. if project.Type == 2 {
  6593. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6594. fmt.Println(err)
  6595. }
  6596. if project.Type == 3 && project.IsOut == 1 {
  6597. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6598. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6599. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6600. operation_time := time.Now().Unix()
  6601. creater := adminInfo.AdminUser.Id
  6602. //创建退库单
  6603. timeStr := time.Now().Format("2006-01-02")
  6604. timeArr := strings.Split(timeStr, "-")
  6605. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6606. total = total + 1
  6607. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6608. cancelStock := models.CancelStock{
  6609. OrderNumber: orderNumber,
  6610. OperaTime: operation_time,
  6611. OrgId: adminInfo.CurrentOrgId,
  6612. Creater: creater,
  6613. Ctime: time.Now().Unix(),
  6614. Status: 1,
  6615. ReturnTime: project.RecordDate,
  6616. Type: 1,
  6617. StorehouseId: houseConfig.StorehouseOutInfo,
  6618. IsCheck: 1,
  6619. }
  6620. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6621. if msgerrkonde == gorm.ErrRecordNotFound {
  6622. service.AddSigleCancelStock(&cancelStock)
  6623. }
  6624. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6625. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6626. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6627. //查询是否有出库
  6628. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6629. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6630. deaerler, _ := service.GetDealerById(info.Dealer)
  6631. if info.ID > 0 {
  6632. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6633. if info.Count >= prescribingNumber {
  6634. cancelStockInfo := models.CancelStockInfo{
  6635. GoodId: project.ProjectId,
  6636. CancelStockId: cancel.ID,
  6637. GoodTypeId: good.GoodTypeId,
  6638. Count: prescribingNumber,
  6639. Price: info.Price,
  6640. Total: 0,
  6641. ProductDate: info.ProductDate,
  6642. ExpiryDate: info.ExpiryDate,
  6643. Ctime: time.Now().Unix(),
  6644. Status: 1,
  6645. OrgId: adminInfo.CurrentOrgId,
  6646. OrderNumber: cancel.OrderNumber,
  6647. Type: 0,
  6648. Dealer: deaerler.DealerName,
  6649. Manufacturer: manufacturer.ManufacturerName,
  6650. Number: info.Number,
  6651. RegisterAccount: "",
  6652. Remark: "",
  6653. WarehouseInfoId: info.WarehouseInfotId,
  6654. PatientId: info.PatientId,
  6655. RecordDate: info.SysRecordTime,
  6656. StorehouseId: houseConfig.StorehouseOutInfo,
  6657. IsCheck: 1,
  6658. }
  6659. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6660. //回退库存
  6661. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6662. //退库数量增加
  6663. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6664. //出库数量减少
  6665. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6666. }
  6667. if info.Count < prescribingNumber {
  6668. cancelStockInfo := models.CancelStockInfo{
  6669. GoodId: project.ProjectId,
  6670. CancelStockId: cancel.ID,
  6671. GoodTypeId: good.GoodTypeId,
  6672. Count: info.Count,
  6673. Price: info.Price,
  6674. Total: 0,
  6675. ProductDate: info.ProductDate,
  6676. ExpiryDate: info.ExpiryDate,
  6677. Ctime: time.Now().Unix(),
  6678. Status: 1,
  6679. OrgId: adminInfo.CurrentOrgId,
  6680. OrderNumber: cancel.OrderNumber,
  6681. Type: 0,
  6682. Dealer: deaerler.DealerName,
  6683. Manufacturer: manufacturer.ManufacturerName,
  6684. Number: info.Number,
  6685. RegisterAccount: "",
  6686. Remark: "",
  6687. WarehouseInfoId: info.WarehouseInfotId,
  6688. PatientId: info.PatientId,
  6689. RecordDate: info.SysRecordTime,
  6690. StorehouseId: houseConfig.StorehouseOutInfo,
  6691. IsCheck: 1,
  6692. }
  6693. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6694. //回退库存
  6695. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6696. //退库数量增加
  6697. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6698. //出库数量减少
  6699. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6700. }
  6701. //查询剩余库存
  6702. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6703. var over_count int64
  6704. for _, it := range goodList {
  6705. over_count += it.StockCount
  6706. }
  6707. //出库数据 大于 退库数量
  6708. if info.Count >= prescribingNumber {
  6709. flow := models.VmStockFlow{
  6710. WarehousingId: info.WarehouseInfotId,
  6711. GoodId: project.ProjectId,
  6712. Number: info.Number,
  6713. LicenseNumber: info.LicenseNumber,
  6714. Count: prescribingNumber,
  6715. UserOrgId: adminInfo.CurrentOrgId,
  6716. PatientId: project.PatientId,
  6717. SystemTime: info.SysRecordTime,
  6718. ConsumableType: 7,
  6719. IsSys: 0,
  6720. WarehousingOrder: "",
  6721. WarehouseOutId: info.WarehouseOutId,
  6722. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6723. IsEdit: 0,
  6724. CancelStockId: cancel.ID,
  6725. CancelOrderNumber: cancel.OrderNumber,
  6726. Manufacturer: manufacturer.ID,
  6727. Dealer: 0,
  6728. Creator: adminInfo.AdminUser.Id,
  6729. UpdateCreator: 0,
  6730. Status: 1,
  6731. Ctime: time.Now().Unix(),
  6732. Mtime: 0,
  6733. Price: info.Price,
  6734. WarehousingDetailId: info.WarehouseInfotId,
  6735. WarehouseOutDetailId: info.ID,
  6736. CancelOutDetailId: cancelInfo.ID,
  6737. ProductDate: info.ProductDate,
  6738. ExpireDate: info.ExpiryDate,
  6739. StorehouseId: houseConfig.StorehouseOutInfo,
  6740. OverCount: over_count,
  6741. OperateTime: time.Now().Unix(),
  6742. }
  6743. service.CreateStockFlowOne(flow)
  6744. }
  6745. //出库数据小于退库数据
  6746. if info.Count < prescribingNumber {
  6747. flow := models.VmStockFlow{
  6748. WarehousingId: info.WarehouseInfotId,
  6749. GoodId: project.ProjectId,
  6750. Number: info.Number,
  6751. LicenseNumber: info.LicenseNumber,
  6752. Count: info.Count,
  6753. UserOrgId: adminInfo.CurrentOrgId,
  6754. PatientId: project.PatientId,
  6755. SystemTime: info.SysRecordTime,
  6756. ConsumableType: 7,
  6757. IsSys: 0,
  6758. WarehousingOrder: "",
  6759. WarehouseOutId: info.WarehouseOutId,
  6760. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6761. IsEdit: 0,
  6762. CancelStockId: cancel.ID,
  6763. CancelOrderNumber: cancel.OrderNumber,
  6764. Manufacturer: manufacturer.ID,
  6765. Dealer: 0,
  6766. Creator: adminInfo.AdminUser.Id,
  6767. UpdateCreator: 0,
  6768. Status: 1,
  6769. Ctime: time.Now().Unix(),
  6770. Mtime: 0,
  6771. Price: info.Price,
  6772. WarehousingDetailId: info.WarehouseInfotId,
  6773. WarehouseOutDetailId: info.ID,
  6774. CancelOutDetailId: cancelInfo.ID,
  6775. ProductDate: info.ProductDate,
  6776. ExpireDate: info.ExpiryDate,
  6777. StorehouseId: houseConfig.StorehouseOutInfo,
  6778. OverCount: over_count,
  6779. OperateTime: time.Now().Unix(),
  6780. }
  6781. service.CreateStockFlowOne(flow)
  6782. }
  6783. //查询已出库数量
  6784. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6785. if prescribingNumber < dialysisInfo.Count {
  6786. //改变数量
  6787. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6788. }
  6789. if prescribingNumber >= dialysisInfo.Count {
  6790. //删除出库表
  6791. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6792. }
  6793. //更新剩余库存
  6794. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6795. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6796. var total_count_one int64
  6797. for _, it := range stockList {
  6798. total_count_one += it.StockCount
  6799. }
  6800. //基础库插入数据
  6801. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6802. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6803. var flush_count int64
  6804. for _, it := range goodListOne {
  6805. flush_count += it.StockCount
  6806. }
  6807. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6808. if errs != nil {
  6809. goodErrcode := models.XtGoodErrcode{
  6810. UserOrgId: project.UserOrgId,
  6811. Errcode: "手动出库更新剩余出库失败",
  6812. GoodId: project.ProjectId,
  6813. Status: 1,
  6814. Ctime: time.Now().Unix(),
  6815. Mtime: 0,
  6816. Count: 0,
  6817. StockCount: 0,
  6818. Creater: creater,
  6819. BatchNumberId: 0,
  6820. WarehouseOutId: 0,
  6821. }
  6822. service.CreateGoodErrcode(goodErrcode)
  6823. }
  6824. }
  6825. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6826. fmt.Println(err)
  6827. } else {
  6828. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6829. fmt.Println(err)
  6830. }
  6831. } else {
  6832. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6833. fmt.Println(err)
  6834. }
  6835. }
  6836. //保存处方出库
  6837. if goodOutConfig.IsOpen == 1 {
  6838. if project.Type == 3 {
  6839. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6840. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6841. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6842. operation_time := time.Now().Unix()
  6843. creater := adminInfo.AdminUser.Id
  6844. //创建退库单
  6845. timeStr := time.Now().Format("2006-01-02")
  6846. timeArr := strings.Split(timeStr, "-")
  6847. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6848. total = total + 1
  6849. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6850. cancelStock := models.CancelStock{
  6851. OrderNumber: orderNumber,
  6852. OperaTime: operation_time,
  6853. OrgId: adminInfo.CurrentOrgId,
  6854. Creater: creater,
  6855. Ctime: time.Now().Unix(),
  6856. Status: 1,
  6857. ReturnTime: project.RecordDate,
  6858. Type: 1,
  6859. StorehouseId: houseConfig.StorehouseOutInfo,
  6860. IsCheck: 1,
  6861. }
  6862. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6863. if msgerrkonde == gorm.ErrRecordNotFound {
  6864. service.AddSigleCancelStock(&cancelStock)
  6865. }
  6866. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6867. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6868. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6869. //获取出库数据
  6870. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6871. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6872. deaerler, _ := service.GetDealerById(info.Dealer)
  6873. if info.ID > 0 {
  6874. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6875. if info.Count >= prescribingNumber {
  6876. cancelStockInfo := models.CancelStockInfo{
  6877. GoodId: project.ProjectId,
  6878. CancelStockId: cancel.ID,
  6879. GoodTypeId: good.GoodTypeId,
  6880. Count: prescribingNumber,
  6881. Price: info.Price,
  6882. Total: 0,
  6883. ProductDate: info.ProductDate,
  6884. ExpiryDate: info.ExpiryDate,
  6885. Ctime: time.Now().Unix(),
  6886. Status: 1,
  6887. OrgId: adminInfo.CurrentOrgId,
  6888. OrderNumber: cancel.OrderNumber,
  6889. Type: 0,
  6890. Dealer: deaerler.DealerName,
  6891. Manufacturer: manufacturer.ManufacturerName,
  6892. Number: info.Number,
  6893. RegisterAccount: "",
  6894. Remark: "",
  6895. WarehouseInfoId: info.WarehouseInfotId,
  6896. PatientId: info.PatientId,
  6897. RecordDate: info.SysRecordTime,
  6898. StorehouseId: houseConfig.StorehouseOutInfo,
  6899. IsCheck: 1,
  6900. }
  6901. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6902. //退库数量增加
  6903. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6904. //出库数量减少
  6905. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6906. }
  6907. if info.Count < prescribingNumber {
  6908. cancelStockInfo := models.CancelStockInfo{
  6909. GoodId: project.ProjectId,
  6910. CancelStockId: cancel.ID,
  6911. GoodTypeId: good.GoodTypeId,
  6912. Count: prescribingNumber,
  6913. Price: info.Price,
  6914. Total: 0,
  6915. ProductDate: info.ProductDate,
  6916. ExpiryDate: info.ExpiryDate,
  6917. Ctime: time.Now().Unix(),
  6918. Status: 1,
  6919. OrgId: adminInfo.CurrentOrgId,
  6920. OrderNumber: cancel.OrderNumber,
  6921. Type: 0,
  6922. Dealer: deaerler.DealerName,
  6923. Manufacturer: manufacturer.ManufacturerName,
  6924. Number: info.Number,
  6925. RegisterAccount: "",
  6926. Remark: "",
  6927. WarehouseInfoId: info.WarehouseInfotId,
  6928. PatientId: info.PatientId,
  6929. RecordDate: info.SysRecordTime,
  6930. StorehouseId: houseConfig.StorehouseOutInfo,
  6931. IsCheck: 1,
  6932. }
  6933. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6934. //回退库存
  6935. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6936. }
  6937. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6938. var over_count int64
  6939. for _, it := range goodList {
  6940. over_count += it.StockCount
  6941. }
  6942. //查询出库数量
  6943. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6944. //出库数据 大于 退库数量
  6945. if len(list) > 0 {
  6946. for _, it := range list {
  6947. //回退库存
  6948. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6949. //退库数量增加
  6950. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6951. //出库数量减少
  6952. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6953. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6954. var over_count_one int64
  6955. for _, it := range goodList {
  6956. over_count_one += it.StockCount
  6957. }
  6958. //查询该批次是否有退库数据
  6959. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6960. flow := models.VmStockFlow{
  6961. WarehousingId: it.WarehouseInfotId,
  6962. GoodId: it.GoodId,
  6963. Number: it.Number,
  6964. LicenseNumber: it.LicenseNumber,
  6965. Count: it.Count,
  6966. UserOrgId: adminInfo.CurrentOrgId,
  6967. PatientId: it.PatientId,
  6968. SystemTime: it.SysRecordTime,
  6969. ConsumableType: 7,
  6970. IsSys: 0,
  6971. WarehousingOrder: "",
  6972. WarehouseOutId: it.WarehouseOutId,
  6973. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6974. IsEdit: 0,
  6975. CancelStockId: cancel.ID,
  6976. CancelOrderNumber: cancel.OrderNumber,
  6977. Manufacturer: manufacturer.ID,
  6978. Dealer: 0,
  6979. Creator: adminInfo.AdminUser.Id,
  6980. UpdateCreator: 0,
  6981. Status: 1,
  6982. Ctime: time.Now().Unix(),
  6983. Mtime: 0,
  6984. Price: it.Price,
  6985. WarehousingDetailId: it.WarehouseInfotId,
  6986. WarehouseOutDetailId: it.ID,
  6987. CancelOutDetailId: cancelInfo.ID,
  6988. ProductDate: it.ProductDate,
  6989. ExpireDate: it.ExpiryDate,
  6990. StorehouseId: houseConfig.StorehouseOutInfo,
  6991. OverCount: over_count_one,
  6992. OperateTime: time.Now().Unix(),
  6993. }
  6994. service.CreateStockFlowOne(flow)
  6995. }
  6996. }
  6997. //查询已出库数量
  6998. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6999. if prescribingNumber < dialysisInfo.Count {
  7000. //改变数量
  7001. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7002. }
  7003. if prescribingNumber >= dialysisInfo.Count {
  7004. //删除出库表
  7005. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7006. }
  7007. //更新剩余库存
  7008. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7009. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7010. var total_count_one int64
  7011. for _, it := range stockList {
  7012. total_count_one += it.StockCount
  7013. }
  7014. //基础库插入数据
  7015. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7016. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7017. var flush_count int64
  7018. for _, it := range goodListOne {
  7019. flush_count += it.StockCount
  7020. }
  7021. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7022. if errs != nil {
  7023. goodErrcode := models.XtGoodErrcode{
  7024. UserOrgId: project.UserOrgId,
  7025. Errcode: "手动出库更新剩余出库失败",
  7026. GoodId: project.ProjectId,
  7027. Status: 1,
  7028. Ctime: time.Now().Unix(),
  7029. Mtime: 0,
  7030. Count: 0,
  7031. StockCount: 0,
  7032. Creater: creater,
  7033. BatchNumberId: 0,
  7034. WarehouseOutId: 0,
  7035. }
  7036. service.CreateGoodErrcode(goodErrcode)
  7037. }
  7038. }
  7039. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7040. fmt.Println(err)
  7041. } else {
  7042. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7043. fmt.Println(err)
  7044. }
  7045. }
  7046. c.ServeSuccessJSON(map[string]interface{}{
  7047. "msg": "删除成功",
  7048. })
  7049. return
  7050. }
  7051. func (c *HisApiController) CreateHisAdditionalCharge() {
  7052. his_patient_id, _ := c.GetInt64("his_patient_id")
  7053. patient_id, _ := c.GetInt64("patient_id")
  7054. record_date := c.GetString("record_date")
  7055. timeLayout := "2006-01-02"
  7056. loc, _ := time.LoadLocation("Local")
  7057. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7058. if err != nil {
  7059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7060. return
  7061. }
  7062. adminInfo := c.GetAdminUserInfo()
  7063. recordDateTime := theTime.Unix()
  7064. dataBody := make(map[string]interface{}, 0)
  7065. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7066. if err != nil {
  7067. utils.ErrorLog(err.Error())
  7068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7069. return
  7070. }
  7071. var additions []*models.HisAdditionalCharge
  7072. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7073. additions, _ := dataBody["addition"].([]interface{})
  7074. if len(additions) > 0 {
  7075. for _, item := range additions {
  7076. items := item.(map[string]interface{})
  7077. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7078. utils.ErrorLog("item_id")
  7079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7080. return
  7081. }
  7082. item_id := int64(items["item_id"].(float64))
  7083. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7084. utils.ErrorLog("item_name")
  7085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7086. return
  7087. }
  7088. item_name := items["item_name"].(string)
  7089. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7090. utils.ErrorLog("price")
  7091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7092. return
  7093. }
  7094. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7095. ctime := time.Now().Unix()
  7096. additional := &models.HisAdditionalCharge{
  7097. PatientId: patient_id,
  7098. HisPatientId: his_patient_id,
  7099. UserOrgId: adminInfo.CurrentOrgId,
  7100. RecordDate: recordDateTime,
  7101. CreatedTime: ctime,
  7102. UpdatedTime: ctime,
  7103. Modifier: adminInfo.AdminUser.Id,
  7104. Creator: adminInfo.AdminUser.Id,
  7105. Price: price,
  7106. ItemName: item_name,
  7107. ItemId: item_id,
  7108. Status: 1,
  7109. }
  7110. additions = append(additions, additional)
  7111. }
  7112. }
  7113. }
  7114. for _, item := range additions {
  7115. service.CreateAddtionalCharge(item)
  7116. }
  7117. c.ServeSuccessJSON(map[string]interface{}{
  7118. "msg": "创建成功",
  7119. })
  7120. }
  7121. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7122. blood_fat := c.GetString("blood_fat")
  7123. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7124. blood_sugar := c.GetString("blood_sugar")
  7125. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7126. chief_conplaint := c.GetString("chief_conplaint")
  7127. dbp := c.GetString("dbp")
  7128. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7129. delivery_way, _ := c.GetInt64("delivery_way")
  7130. diagnostic := c.GetString("diagnostic")
  7131. family_history := c.GetString("family_history")
  7132. height := c.GetString("height")
  7133. history_of_present_illness := c.GetString("history_of_present_illness")
  7134. is_infect, _ := c.GetInt64("is_infect")
  7135. past_history := c.GetString("past_history")
  7136. patient_id, _ := c.GetInt64("patient_id")
  7137. his_patient_id, _ := c.GetInt64("his_patient_id")
  7138. personal_history := c.GetString("personal_history")
  7139. pulse := c.GetString("pulse")
  7140. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7141. sbp := c.GetString("sbp")
  7142. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7143. heightfloat, _ := strconv.ParseFloat(height, 64)
  7144. sicktype := c.GetString("sick_type")
  7145. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7146. symptom := c.GetString("symptom")
  7147. sick_date := c.GetString("sick_date")
  7148. temperatures := c.GetString("temperature")
  7149. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7150. record_date := c.GetString("record_date")
  7151. breathing := c.GetString("breathing")
  7152. doctor_advice := c.GetString("doctor_advice")
  7153. remark := c.GetString("remark")
  7154. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7155. sick, _ := c.GetInt64("sick")
  7156. diagnose, _ := c.GetInt64("diagnose")
  7157. //id, _ := c.GetInt64("id")
  7158. timeLayout := "2006-01-02"
  7159. loc, _ := time.LoadLocation("Local")
  7160. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7161. allergic_history := c.GetString("allergic_history")
  7162. if err != nil {
  7163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7164. return
  7165. }
  7166. recordDateTime := theTime.Unix()
  7167. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7168. if err != nil {
  7169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7170. return
  7171. }
  7172. sickTimes := sickTime.Unix()
  7173. ctime := time.Now().Unix()
  7174. primary_disease := c.GetString("primary_disease")
  7175. confirm_failure_date := c.GetString("confirm_failure_date")
  7176. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7177. drug_allergy_history := c.GetString("drug_allergy_history")
  7178. physical_examination := c.GetString("physical_examination")
  7179. special_inspection := c.GetString("special_inspection")
  7180. lab_apparatus := c.GetString("lab_apparatus")
  7181. caseHistory := models.HisPatientCaseHistory{
  7182. HisPatientId: his_patient_id,
  7183. PatientId: patient_id,
  7184. Temperature: temperature,
  7185. BloodSugar: bloodsugarfloat,
  7186. Pulse: pulsefloat,
  7187. Sbp: sbpfloat,
  7188. Dbp: dbpfloat,
  7189. Height: heightfloat,
  7190. BloodFat: bloodfatfloat,
  7191. SickType: sick_type,
  7192. Symptom: symptom,
  7193. SickDate: sickTimes,
  7194. IsInfect: is_infect,
  7195. HistoryOfPresentIllness: history_of_present_illness,
  7196. PastHistory: past_history,
  7197. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7198. ChiefConplaint: chief_conplaint,
  7199. PersonalHistory: personal_history,
  7200. FamilyHistory: family_history,
  7201. Diagnostic: diagnostic,
  7202. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7203. Status: 1,
  7204. Ctime: ctime,
  7205. Mtime: ctime,
  7206. RecordDate: recordDateTime,
  7207. DeliveryWay: delivery_way,
  7208. Breathing: breathingfloat,
  7209. DoctorAdvice: doctor_advice,
  7210. Remark: remark,
  7211. Sick: sick,
  7212. Diagnose: diagnose,
  7213. AllergicHistory: allergic_history,
  7214. PrimaryDisease: primary_disease,
  7215. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7216. DrugAllergyHistory: drug_allergy_history,
  7217. PhysicalExamination: physical_examination,
  7218. SpecialInspection: special_inspection,
  7219. LabApparatus: lab_apparatus,
  7220. }
  7221. //查询该患者是否有病历
  7222. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7223. if errcodes == gorm.ErrRecordNotFound {
  7224. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7225. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7226. if err != nil {
  7227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7228. return
  7229. }
  7230. c.ServeSuccessJSON(map[string]interface{}{
  7231. "caseHistory": caseHistory,
  7232. "historyInfo": historyInfo,
  7233. })
  7234. return
  7235. } else if errcodes == nil {
  7236. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7237. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7238. if err != nil {
  7239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7240. return
  7241. }
  7242. c.ServeSuccessJSON(map[string]interface{}{
  7243. "caseHistory": caseHistory,
  7244. "historyInfo": historyInfo,
  7245. })
  7246. }
  7247. //查询该患者是否有病历
  7248. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7249. //if errcode == gorm.ErrRecordNotFound {
  7250. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7251. // if err != nil {
  7252. // c.ServeSuccessJSON(map[string]interface{}{
  7253. // "msg": "保存成功",
  7254. // })
  7255. // }
  7256. //} else if errcode == nil {
  7257. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7258. // return
  7259. //}
  7260. }
  7261. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7262. patient_id, _ := c.GetInt64("patient_id", 0)
  7263. adminUser := c.GetAdminUserInfo()
  7264. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7265. c.ServeSuccessJSON(map[string]interface{}{
  7266. "list": caseHistorys,
  7267. })
  7268. }
  7269. func (c *HisApiController) GetHisPatientCaseHistory() {
  7270. record_date, _ := c.GetInt64("record_date", 0)
  7271. patient_id, _ := c.GetInt64("patient_id", 0)
  7272. admin := c.GetAdminUserInfo()
  7273. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7274. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7275. c.ServeSuccessJSON(map[string]interface{}{
  7276. "info": info,
  7277. "case_history": case_history,
  7278. })
  7279. }
  7280. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7281. template_name := c.GetString("template_name")
  7282. template_remark := c.GetString("template_remark")
  7283. doctor := c.GetAdminUserInfo().AdminUser.Id
  7284. diagnostic := c.GetString("diagnostic")
  7285. chief_conplaint := c.GetString("chief_conplain")
  7286. history_of_present_illness := c.GetString("history_of_present_illness")
  7287. past_history := c.GetString("past_history")
  7288. personal_history := c.GetString("personal_history")
  7289. family_history := c.GetString("family_history")
  7290. user_name := c.GetString("user_name")
  7291. doctor_advice := c.GetString("doctor_advice")
  7292. remark := c.GetString("remark")
  7293. //record_date := c.GetString("record_date")
  7294. //fmt.Println("record_date--------",record_date)
  7295. //timeLayout := "2006-01-02"
  7296. //loc, _ := time.LoadLocation("Local")
  7297. //
  7298. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7299. //if err != nil {
  7300. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7301. // return
  7302. //}
  7303. //recordDateTime := theTime.Unix()
  7304. ctime := time.Now().Unix()
  7305. template := models.HisCaseHistoryTemplate{
  7306. HistoryOfPresentIllness: history_of_present_illness,
  7307. PastHistory: past_history,
  7308. ChiefConplaint: chief_conplaint,
  7309. PersonalHistory: personal_history,
  7310. FamilyHistory: family_history,
  7311. Diagnostic: diagnostic,
  7312. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7313. Status: 1,
  7314. Ctime: ctime,
  7315. Mtime: ctime,
  7316. RecordDate: time.Now().Unix(),
  7317. TemplateName: template_name,
  7318. TemplateRemark: template_remark,
  7319. Creator: doctor,
  7320. Modifier: doctor,
  7321. UserName: user_name,
  7322. DoctorAdvice: doctor_advice,
  7323. Remark: remark,
  7324. }
  7325. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7326. if err == nil {
  7327. c.ServeSuccessJSON(map[string]interface{}{
  7328. "msg": "保存成功",
  7329. })
  7330. } else {
  7331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7332. return
  7333. }
  7334. }
  7335. func (c *HisApiController) GetCaseHistoryTemplate() {
  7336. timeLayout := "2006-01-02"
  7337. loc, _ := time.LoadLocation("Local")
  7338. keyword := c.GetString("keyword")
  7339. start_time := c.GetString("start_time")
  7340. end_time := c.GetString("end_time")
  7341. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7342. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7343. admin := c.GetAdminUserInfo()
  7344. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7345. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7346. c.ServeSuccessJSON(map[string]interface{}{
  7347. "template": template,
  7348. //"history": history,
  7349. })
  7350. }
  7351. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7352. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7353. utils.ErrorLog("drug_name")
  7354. return enums.ErrorCodeParamWrong
  7355. }
  7356. adviceName, _ := json["drug_name"].(string)
  7357. if len(adviceName) == 0 {
  7358. utils.ErrorLog("len(advice_name) == 0")
  7359. return enums.ErrorCodeParamWrong
  7360. }
  7361. advice.AdviceName = adviceName
  7362. adviceDesc, _ := json["advice_desc"].(string)
  7363. advice.AdviceDesc = adviceDesc
  7364. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7365. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7366. advice.DrugSpec = drugSpec
  7367. }
  7368. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7369. remark, _ := json["remark"].(string)
  7370. advice.Remark = remark
  7371. }
  7372. if json["id"] == nil {
  7373. advice.DrugId = 0
  7374. } else {
  7375. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7376. drug_id := int64(json["id"].(float64))
  7377. advice.DrugId = drug_id
  7378. }
  7379. }
  7380. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7381. advice_id := int64(json["advice_id"].(float64))
  7382. advice.ID = advice_id
  7383. if advice.ID > 0 {
  7384. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7385. if err == nil {
  7386. if hisAdvice.ID > 0 {
  7387. advice.ExecutionTime = hisAdvice.ExecutionTime
  7388. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7389. advice.ExecutionState = hisAdvice.ExecutionState
  7390. advice.CheckTime = hisAdvice.CheckTime
  7391. advice.Checker = hisAdvice.Checker
  7392. advice.CheckState = hisAdvice.CheckState
  7393. advice.StartTime = hisAdvice.StartTime
  7394. advice.FeedetlSn = hisAdvice.FeedetlSn
  7395. }
  7396. }
  7397. }
  7398. }
  7399. //
  7400. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7401. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7402. // advice.ExecutionTime = execution_time
  7403. //}
  7404. //
  7405. //
  7406. //
  7407. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7408. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7409. // advice.ExecutionStaff = execution_staff
  7410. //}
  7411. //
  7412. //
  7413. //
  7414. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7415. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7416. // advice.ExecutionState = execution_state
  7417. //}
  7418. //
  7419. //
  7420. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7421. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7422. // advice.CheckTime = check_time
  7423. //}
  7424. //
  7425. //
  7426. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7427. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7428. // advice.CheckState = check_state
  7429. //}
  7430. //
  7431. //
  7432. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7433. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7434. // advice.Checker = checker
  7435. //}
  7436. //
  7437. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7438. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7439. // advice.StartTime = start_time
  7440. //}
  7441. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7442. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7443. advice.IsSelfDrug = is_self_drug
  7444. }
  7445. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7446. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7447. drug_way_count, _ := json["drug_way_count"].(string)
  7448. advice.DrugWayCount = drug_way_count
  7449. }
  7450. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7451. drugSpecUnit, _ := json["min_unit"].(string)
  7452. advice.DrugSpecUnit = drugSpecUnit
  7453. }
  7454. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7455. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7456. advice.SingleDose = singleDose
  7457. }
  7458. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7459. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7460. advice.SingleDoseUnit = singleDoseUnit
  7461. }
  7462. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7463. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7464. advice.PrescribingNumber = prescribingNumber
  7465. }
  7466. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7467. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7468. advice.PrescribingNumberUnit = prescribingNumberUnit
  7469. }
  7470. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7471. deliveryWay, _ := json["delivery_way"].(string)
  7472. advice.DeliveryWay = deliveryWay
  7473. }
  7474. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7475. executionFrequency, _ := json["execution_frequency"].(string)
  7476. advice.ExecutionFrequency = executionFrequency
  7477. }
  7478. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7479. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7480. advice.Price = price
  7481. }
  7482. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7483. med_list_codg, _ := json["medical_insurance_number"].(string)
  7484. advice.MedListCodg = med_list_codg
  7485. }
  7486. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7487. day := int64(json["day"].(float64))
  7488. advice.Day = day
  7489. }
  7490. return 0
  7491. }
  7492. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7493. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7494. id := int64(json["id"].(float64))
  7495. project.ID = id
  7496. historyProject, _ := service.GetHisProjectByID(id)
  7497. project.FeedetlSn = historyProject.FeedetlSn
  7498. }
  7499. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7500. project_id := int64(json["project_id"].(float64))
  7501. project.ProjectId = project_id
  7502. }
  7503. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7504. // price := int64(json["price"].(float64))
  7505. // formatInt_price := strconv.FormatInt(price, 10)
  7506. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7507. // project.Price = float_price
  7508. // }
  7509. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7510. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7511. project.Price = price
  7512. }
  7513. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7514. total, _ := json["total"].(string)
  7515. project.Count = total
  7516. }
  7517. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7518. medical_code, _ := json["medical_code"].(string)
  7519. project.MedListCodg = medical_code
  7520. }
  7521. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7522. single_dose, _ := json["single_dose"].(string)
  7523. project.SingleDose = single_dose
  7524. }
  7525. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7526. delivery_way, _ := json["delivery_way"].(string)
  7527. project.DeliveryWay = delivery_way
  7528. }
  7529. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7530. execution_frequency, _ := json["execution_frequency"].(string)
  7531. project.ExecutionFrequency = execution_frequency
  7532. }
  7533. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7534. remark, _ := json["remark"].(string)
  7535. project.Remark = remark
  7536. }
  7537. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7538. day, _ := json["number_days"].(string)
  7539. project.Day = day
  7540. }
  7541. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7542. unit, _ := json["unit"].(string)
  7543. project.Unit = unit
  7544. }
  7545. return 0
  7546. }
  7547. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7548. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7549. id := int64(json["id"].(float64))
  7550. historyAddtions, _ := service.GetHisAdditionByID(id)
  7551. additionalCharge.ID = id
  7552. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7553. }
  7554. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7555. item_id := int64(json["item_id"].(float64))
  7556. additionalCharge.ItemId = item_id
  7557. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7558. if config.ID > 0 {
  7559. if len(config.Code) > 0 {
  7560. additionalCharge.MedListCodg = config.Code
  7561. }
  7562. }
  7563. }
  7564. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7565. // price := int64(json["price"].(float64))
  7566. // formatInt_price := strconv.FormatInt(price, 10)
  7567. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7568. // additionalCharge.Price = float_price
  7569. // }
  7570. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7571. // price := int64(json["price"].(float64))
  7572. // formatInt_price := strconv.FormatInt(price, 10)
  7573. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7574. // additionalCharge.Price = float_price
  7575. //}
  7576. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7577. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7578. additionalCharge.Price = price
  7579. }
  7580. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7581. count, _ := json["count"].(string)
  7582. counts, _ := strconv.ParseInt(count, 10, 64)
  7583. additionalCharge.Count = counts
  7584. }
  7585. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7586. item_name, _ := json["item_name"].(string)
  7587. additionalCharge.ItemName = item_name
  7588. }
  7589. return 0
  7590. }
  7591. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7592. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7593. utils.ErrorLog("drug_name")
  7594. return enums.ErrorCodeParamWrong
  7595. }
  7596. adviceName, _ := json["drug_name"].(string)
  7597. if len(adviceName) == 0 {
  7598. utils.ErrorLog("len(advice_name) == 0")
  7599. return enums.ErrorCodeParamWrong
  7600. }
  7601. advice.AdviceName = adviceName
  7602. adviceDesc, _ := json["advice_desc"].(string)
  7603. advice.AdviceDesc = adviceDesc
  7604. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7605. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7606. advice.DrugSpec = drugSpec
  7607. }
  7608. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7609. remark, _ := json["remark"].(string)
  7610. advice.Remark = remark
  7611. }
  7612. if json["id"] == nil {
  7613. advice.DrugId = 0
  7614. } else {
  7615. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7616. drug_id := int64(json["id"].(float64))
  7617. advice.DrugId = drug_id
  7618. }
  7619. }
  7620. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7621. groupno := int64(json["groupno"].(float64))
  7622. advice.Groupno = groupno
  7623. }
  7624. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7625. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7626. advice.IsSelfDrug = is_self_drug
  7627. }
  7628. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7629. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7630. drug_way_count, _ := json["drug_way_count"].(string)
  7631. advice.DrugWayCount = drug_way_count
  7632. }
  7633. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7634. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7635. advice.HospApprFlag = hosp_appr_flag
  7636. }
  7637. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7638. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7639. advice.PrescribingNumber = prescribingNumber
  7640. }
  7641. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7642. // frequency_type := int64(json["frequency_type"].(float64))
  7643. // advice.FrequencyType = frequency_type
  7644. //}
  7645. //
  7646. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7647. // day_count := int64(json["day_count"].(float64))
  7648. // advice.DayCount = day_count
  7649. //}
  7650. //
  7651. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7652. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7653. // week_day, _ := json["week_day"].(string)
  7654. // advice.WeekDay = week_day
  7655. //}
  7656. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7657. drugSpecUnit, _ := json["min_unit"].(string)
  7658. advice.DrugSpecUnit = drugSpecUnit
  7659. }
  7660. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7661. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7662. advice.SingleDose = singleDose
  7663. }
  7664. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7665. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7666. advice.SingleDoseUnit = singleDoseUnit
  7667. }
  7668. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7669. deliveryWay, _ := json["delivery_way"].(string)
  7670. advice.DeliveryWay = deliveryWay
  7671. }
  7672. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7673. executionFrequency, _ := json["execution_frequency"].(string)
  7674. advice.ExecutionFrequency = executionFrequency
  7675. }
  7676. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7677. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7678. advice.Price = price
  7679. }
  7680. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7681. med_list_codg, _ := json["medical_insurance_number"].(string)
  7682. advice.MedListCodg = med_list_codg
  7683. }
  7684. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7685. day := int64(json["day"].(float64))
  7686. advice.Day = day
  7687. }
  7688. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7689. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7690. advice.PrescribingNumberUnit = prescribingNumberUnit
  7691. }
  7692. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7693. advice_id := int64(json["advice_id"].(float64))
  7694. advice.ID = advice_id
  7695. if advice.ID > 0 {
  7696. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7697. if err == nil {
  7698. if hisAdvice.ID > 0 {
  7699. advice.ExecutionTime = hisAdvice.ExecutionTime
  7700. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7701. advice.ExecutionState = hisAdvice.ExecutionState
  7702. advice.CheckTime = hisAdvice.CheckTime
  7703. advice.Checker = hisAdvice.Checker
  7704. advice.CheckState = hisAdvice.CheckState
  7705. advice.StartTime = hisAdvice.StartTime
  7706. advice.HospApprFlag = hisAdvice.HospApprFlag
  7707. advice.IsMedicine = hisAdvice.IsMedicine
  7708. if hisAdvice.UserOrgId == 10028 {
  7709. 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 {
  7710. advice.ExecutionTime = 0
  7711. advice.ExecutionStaff = 0
  7712. advice.ExecutionState = 2
  7713. advice.CheckTime = 0
  7714. advice.Checker = 0
  7715. advice.CheckState = 2
  7716. }
  7717. } else {
  7718. 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 {
  7719. advice.ExecutionTime = 0
  7720. advice.ExecutionStaff = 0
  7721. advice.ExecutionState = 2
  7722. advice.CheckTime = 0
  7723. advice.Checker = 0
  7724. advice.CheckState = 2
  7725. advice.UpdatedTime = time.Now().Unix()
  7726. }
  7727. }
  7728. //advice.Groupno = hisAdvice.Groupno
  7729. }
  7730. }
  7731. }
  7732. }
  7733. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7734. //
  7735. //if drugStockConfig.IsOpen == 1 {
  7736. //
  7737. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7738. // if advice.ID == 0 { //医嘱不存在
  7739. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7740. // drug.Total = drug.Total - advice.PrescribingNumber
  7741. // service.UpdateBaseDrugLib(&drug)
  7742. //
  7743. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7744. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7745. // drug.Total = drug.Total - num
  7746. // service.UpdateBaseDrugLib(&drug)
  7747. // }
  7748. //
  7749. // } else if advice.ID > 0 { //医嘱存在
  7750. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7751. // var num float64
  7752. //
  7753. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7754. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7755. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7756. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7757. // drug.Total = drug.Total + num
  7758. // service.UpdateBaseDrugLib(&drug)
  7759. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7760. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7761. // drug.Total = drug.Total - num
  7762. // service.UpdateBaseDrugLib(&drug)
  7763. // }
  7764. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7765. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7766. // if num2 > advice.PrescribingNumber {
  7767. // num = num2 - advice.PrescribingNumber
  7768. // drug.Total = drug.Total + num
  7769. // service.UpdateBaseDrugLib(&drug)
  7770. // } else if num2 < advice.PrescribingNumber {
  7771. // num = advice.PrescribingNumber - num2
  7772. // drug.Total = drug.Total - num
  7773. // service.UpdateBaseDrugLib(&drug)
  7774. // }
  7775. //
  7776. // }
  7777. //
  7778. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7779. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7780. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7781. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7782. // if num1 > num2 {
  7783. // num = num1 - num2
  7784. // drug.Total = drug.Total + num
  7785. // service.UpdateBaseDrugLib(&drug)
  7786. // } else if num1 < num2 {
  7787. // num = num2 - num1
  7788. // drug.Total = drug.Total - num
  7789. // service.UpdateBaseDrugLib(&drug)
  7790. // }
  7791. //
  7792. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7793. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7794. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7795. // if hisAdvice.PrescribingNumber > num2 {
  7796. // num = hisAdvice.PrescribingNumber - num2
  7797. // drug.Total = drug.Total + num
  7798. // service.UpdateBaseDrugLib(&drug)
  7799. // } else if num2 < advice.PrescribingNumber {
  7800. // num = num2 - hisAdvice.PrescribingNumber
  7801. // drug.Total = drug.Total - num
  7802. // service.UpdateBaseDrugLib(&drug)
  7803. // }
  7804. //
  7805. // }
  7806. // }
  7807. // }
  7808. //}
  7809. //
  7810. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7811. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7812. // advice.ExecutionTime = execution_time
  7813. //}
  7814. //
  7815. //
  7816. //
  7817. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7818. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7819. // advice.ExecutionStaff = execution_staff
  7820. //}
  7821. //
  7822. //
  7823. //
  7824. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7825. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7826. // advice.ExecutionState = execution_state
  7827. //}
  7828. //
  7829. //
  7830. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7831. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7832. // advice.CheckTime = check_time
  7833. //}
  7834. //
  7835. //
  7836. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7837. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7838. // advice.CheckState = check_state
  7839. //}
  7840. //
  7841. //
  7842. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7843. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7844. // advice.Checker = checker
  7845. //}
  7846. //
  7847. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7848. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7849. // advice.StartTime = start_time
  7850. //}
  7851. return 0
  7852. }
  7853. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7854. project.ExecutionStaff = 0
  7855. project.ExecutionState = 2
  7856. project.ExecutionTime = 0
  7857. project.Checker = 0
  7858. project.CheckState = 2
  7859. project.CheckTime = 0
  7860. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7861. id := int64(json["id"].(float64))
  7862. project.ID = id
  7863. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7864. project.ExecutionStaff = temp_project.ExecutionStaff
  7865. project.ExecutionState = temp_project.ExecutionState
  7866. project.ExecutionTime = temp_project.ExecutionTime
  7867. project.Checker = temp_project.Checker
  7868. project.CheckState = temp_project.CheckState
  7869. project.CheckTime = temp_project.CheckTime
  7870. project.TeamId = temp_project.TeamId
  7871. }
  7872. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7873. types := int64(json["type"].(float64))
  7874. project.Type = types
  7875. }
  7876. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7877. project_id := int64(json["project_id"].(float64))
  7878. project.ProjectId = project_id
  7879. }
  7880. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7881. team_id := int64(json["team_id"].(float64))
  7882. project.TeamId = team_id
  7883. }
  7884. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7885. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7886. project.Price = price
  7887. }
  7888. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7889. total, _ := json["total"].(string)
  7890. //totals, _ := strconv.ParseInt(total, 10, 64)
  7891. project.Count = total
  7892. }
  7893. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7894. medical_code, _ := json["medical_code"].(string)
  7895. project.MedListCodg = medical_code
  7896. }
  7897. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7898. single_dose, _ := json["single_dose"].(string)
  7899. project.SingleDose = single_dose
  7900. }
  7901. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7902. delivery_way, _ := json["delivery_way"].(string)
  7903. project.DeliveryWay = delivery_way
  7904. }
  7905. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7906. execution_frequency, _ := json["execution_frequency"].(string)
  7907. project.ExecutionFrequency = execution_frequency
  7908. }
  7909. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7910. remark, _ := json["remark"].(string)
  7911. project.Remark = remark
  7912. }
  7913. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7914. day, _ := json["number_days"].(string)
  7915. project.Day = day
  7916. }
  7917. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7918. unit, _ := json["unit"].(string)
  7919. project.Unit = unit
  7920. }
  7921. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7922. // frequency_type := int64(json["frequency_type"].(float64))
  7923. // project.FrequencyType = frequency_type
  7924. //}
  7925. //
  7926. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7927. // day_count := int64(json["day_count"].(float64))
  7928. // project.DayCount = day_count
  7929. //}
  7930. //
  7931. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7932. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7933. // week_day, _ := json["week_day"].(string)
  7934. // project.WeekDay = week_day
  7935. //}
  7936. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7937. //
  7938. //if project.ID == 0 {
  7939. // if stockConfig.IsOpen == 1 {
  7940. // if project.Type == 3 {
  7941. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7942. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7943. // good.Total = good.Total - f_count
  7944. // service.UpdateGoodInfo(&good)
  7945. // }
  7946. // }
  7947. //
  7948. //} else {
  7949. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7950. //
  7951. // if stockConfig.IsOpen == 1 {
  7952. // if project.Type == 3 {
  7953. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7954. // if project.Count < temp_project.Count {
  7955. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7956. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7957. //
  7958. // other_count := f_count_two - f_count_one
  7959. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7960. // good.Total = good.Total + other_count_two
  7961. // service.UpdateGoodInfo(&good)
  7962. // } else if project.Count > temp_project.Count {
  7963. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7964. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7965. //
  7966. // other_count := f_count_one - f_count_two
  7967. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7968. // good.Total = good.Total - other_count_two
  7969. // service.UpdateGoodInfo(&good)
  7970. // }
  7971. //
  7972. // }
  7973. // }
  7974. //
  7975. //}
  7976. return 0
  7977. }
  7978. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7979. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7980. utils.ErrorLog("drug_name")
  7981. return enums.ErrorCodeParamWrong
  7982. }
  7983. adviceName, _ := json["drug_name"].(string)
  7984. if len(adviceName) == 0 {
  7985. utils.ErrorLog("len(advice_name) == 0")
  7986. return enums.ErrorCodeParamWrong
  7987. }
  7988. advice.AdviceName = adviceName
  7989. adviceDesc, _ := json["advice_desc"].(string)
  7990. advice.AdviceDesc = adviceDesc
  7991. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7992. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7993. advice.DrugSpec = drugSpec
  7994. }
  7995. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7996. remark, _ := json["remark"].(string)
  7997. advice.Remark = remark
  7998. }
  7999. if json["id"] == nil {
  8000. advice.DrugId = 0
  8001. } else {
  8002. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8003. drug_id := int64(json["id"].(float64))
  8004. advice.DrugId = drug_id
  8005. }
  8006. }
  8007. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8008. groupno := int64(json["groupno"].(float64))
  8009. advice.Groupno = groupno
  8010. }
  8011. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8012. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8013. advice.IsSelfDrug = is_self_drug
  8014. }
  8015. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8016. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8017. drug_way_count, _ := json["drug_way_count"].(string)
  8018. advice.DrugWayCount = drug_way_count
  8019. }
  8020. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8021. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8022. advice.HospApprFlag = hosp_appr_flag
  8023. }
  8024. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8025. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8026. advice.PrescribingNumber = prescribingNumber
  8027. }
  8028. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8029. // frequency_type := int64(json["frequency_type"].(float64))
  8030. // advice.FrequencyType = frequency_type
  8031. //}
  8032. //
  8033. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8034. // day_count := int64(json["day_count"].(float64))
  8035. // advice.DayCount = day_count
  8036. //}
  8037. //
  8038. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8039. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8040. // week_day, _ := json["week_day"].(string)
  8041. // advice.WeekDay = week_day
  8042. //}
  8043. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8044. drugSpecUnit, _ := json["min_unit"].(string)
  8045. advice.DrugSpecUnit = drugSpecUnit
  8046. }
  8047. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8048. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8049. advice.SingleDose = singleDose
  8050. }
  8051. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8052. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8053. advice.SingleDoseUnit = singleDoseUnit
  8054. }
  8055. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8056. deliveryWay, _ := json["delivery_way"].(string)
  8057. advice.DeliveryWay = deliveryWay
  8058. }
  8059. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8060. executionFrequency, _ := json["execution_frequency"].(string)
  8061. advice.ExecutionFrequency = executionFrequency
  8062. }
  8063. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8064. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8065. advice.Price = price
  8066. }
  8067. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8068. med_list_codg, _ := json["medical_insurance_number"].(string)
  8069. advice.MedListCodg = med_list_codg
  8070. }
  8071. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8072. day := int64(json["day"].(float64))
  8073. advice.Day = day
  8074. }
  8075. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8076. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8077. advice.PrescribingNumberUnit = prescribingNumberUnit
  8078. }
  8079. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8080. advice_id := int64(json["advice_id"].(float64))
  8081. advice.ID = advice_id
  8082. if advice.ID > 0 {
  8083. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8084. if err == nil {
  8085. if hisAdvice.ID > 0 {
  8086. advice.ExecutionTime = hisAdvice.ExecutionTime
  8087. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8088. advice.ExecutionState = hisAdvice.ExecutionState
  8089. advice.CheckTime = hisAdvice.CheckTime
  8090. advice.Checker = hisAdvice.Checker
  8091. advice.DrugCode = hisAdvice.DrugCode
  8092. advice.CheckState = hisAdvice.CheckState
  8093. advice.StartTime = hisAdvice.StartTime
  8094. advice.HospApprFlag = hisAdvice.HospApprFlag
  8095. advice.IsMedicine = hisAdvice.IsMedicine
  8096. if hisAdvice.UserOrgId == 10028 {
  8097. 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 {
  8098. advice.ExecutionTime = 0
  8099. advice.ExecutionStaff = 0
  8100. advice.ExecutionState = 2
  8101. advice.CheckTime = 0
  8102. advice.Checker = 0
  8103. advice.CheckState = 2
  8104. }
  8105. } else {
  8106. 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 {
  8107. advice.ExecutionTime = 0
  8108. advice.ExecutionStaff = 0
  8109. advice.ExecutionState = 2
  8110. advice.CheckTime = 0
  8111. advice.Checker = 0
  8112. advice.CheckState = 2
  8113. //advice.UpdatedTime = time.Now().Unix()
  8114. advice.CreatedTime = hisAdvice.CreatedTime
  8115. advice.UpdatedTime = time.Now().Unix()
  8116. } else {
  8117. advice.CreatedTime = hisAdvice.CreatedTime
  8118. advice.UpdatedTime = hisAdvice.UpdatedTime
  8119. }
  8120. }
  8121. //advice.Groupno = hisAdvice.Groupno
  8122. } else {
  8123. advice.IsMedicine = 0
  8124. ctime := time.Now().Unix()
  8125. advice.CreatedTime = ctime
  8126. advice.UpdatedTime = ctime
  8127. }
  8128. }
  8129. } else {
  8130. advice.IsMedicine = 0
  8131. ctime := time.Now().Unix()
  8132. advice.CreatedTime = ctime
  8133. advice.UpdatedTime = ctime
  8134. }
  8135. }
  8136. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8137. //
  8138. //if drugStockConfig.IsOpen == 1 {
  8139. //
  8140. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8141. // if advice.ID == 0 { //医嘱不存在
  8142. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8143. // drug.Total = drug.Total - advice.PrescribingNumber
  8144. // service.UpdateBaseDrugLib(&drug)
  8145. //
  8146. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8147. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8148. // drug.Total = drug.Total - num
  8149. // service.UpdateBaseDrugLib(&drug)
  8150. // }
  8151. //
  8152. // } else if advice.ID > 0 { //医嘱存在
  8153. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8154. // var num float64
  8155. //
  8156. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8157. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8158. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8159. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8160. // drug.Total = drug.Total + num
  8161. // service.UpdateBaseDrugLib(&drug)
  8162. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8163. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8164. // drug.Total = drug.Total - num
  8165. // service.UpdateBaseDrugLib(&drug)
  8166. // }
  8167. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8168. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8169. // if num2 > advice.PrescribingNumber {
  8170. // num = num2 - advice.PrescribingNumber
  8171. // drug.Total = drug.Total + num
  8172. // service.UpdateBaseDrugLib(&drug)
  8173. // } else if num2 < advice.PrescribingNumber {
  8174. // num = advice.PrescribingNumber - num2
  8175. // drug.Total = drug.Total - num
  8176. // service.UpdateBaseDrugLib(&drug)
  8177. // }
  8178. //
  8179. // }
  8180. //
  8181. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8182. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8183. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8184. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8185. // if num1 > num2 {
  8186. // num = num1 - num2
  8187. // drug.Total = drug.Total + num
  8188. // service.UpdateBaseDrugLib(&drug)
  8189. // } else if num1 < num2 {
  8190. // num = num2 - num1
  8191. // drug.Total = drug.Total - num
  8192. // service.UpdateBaseDrugLib(&drug)
  8193. // }
  8194. //
  8195. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8196. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8197. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8198. // if hisAdvice.PrescribingNumber > num2 {
  8199. // num = hisAdvice.PrescribingNumber - num2
  8200. // drug.Total = drug.Total + num
  8201. // service.UpdateBaseDrugLib(&drug)
  8202. // } else if num2 < advice.PrescribingNumber {
  8203. // num = num2 - hisAdvice.PrescribingNumber
  8204. // drug.Total = drug.Total - num
  8205. // service.UpdateBaseDrugLib(&drug)
  8206. // }
  8207. //
  8208. // }
  8209. // }
  8210. // }
  8211. //}
  8212. //
  8213. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8214. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8215. // advice.ExecutionTime = execution_time
  8216. //}
  8217. //
  8218. //
  8219. //
  8220. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8221. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8222. // advice.ExecutionStaff = execution_staff
  8223. //}
  8224. //
  8225. //
  8226. //
  8227. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8228. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8229. // advice.ExecutionState = execution_state
  8230. //}
  8231. //
  8232. //
  8233. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8234. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8235. // advice.CheckTime = check_time
  8236. //}
  8237. //
  8238. //
  8239. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8240. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8241. // advice.CheckState = check_state
  8242. //}
  8243. //
  8244. //
  8245. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8246. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8247. // advice.Checker = checker
  8248. //}
  8249. //
  8250. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8251. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8252. // advice.StartTime = start_time
  8253. //}
  8254. return 0
  8255. }
  8256. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8257. project.ExecutionStaff = 0
  8258. project.ExecutionState = 2
  8259. project.ExecutionTime = 0
  8260. project.Checker = 0
  8261. project.CheckState = 2
  8262. project.CheckTime = 0
  8263. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8264. id := int64(json["id"].(float64))
  8265. project.ID = id
  8266. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8267. project.ExecutionStaff = temp_project.ExecutionStaff
  8268. project.ExecutionState = temp_project.ExecutionState
  8269. project.ExecutionTime = temp_project.ExecutionTime
  8270. project.Checker = temp_project.Checker
  8271. project.CheckState = temp_project.CheckState
  8272. project.CheckTime = temp_project.CheckTime
  8273. project.TeamId = temp_project.TeamId
  8274. }
  8275. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8276. types := int64(json["type"].(float64))
  8277. project.Type = types
  8278. }
  8279. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8280. project_id := int64(json["project_id"].(float64))
  8281. project.ProjectId = project_id
  8282. }
  8283. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8284. team_id := int64(json["team_id"].(float64))
  8285. project.TeamId = team_id
  8286. }
  8287. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8288. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8289. project.Price = price
  8290. }
  8291. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8292. total, _ := json["total"].(string)
  8293. //totals, _ := strconv.ParseInt(total, 10, 64)
  8294. project.Count = total
  8295. }
  8296. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8297. medical_code, _ := json["medical_code"].(string)
  8298. project.MedListCodg = medical_code
  8299. }
  8300. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8301. single_dose, _ := json["single_dose"].(string)
  8302. project.SingleDose = single_dose
  8303. }
  8304. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8305. delivery_way, _ := json["delivery_way"].(string)
  8306. project.DeliveryWay = delivery_way
  8307. }
  8308. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8309. execution_frequency, _ := json["execution_frequency"].(string)
  8310. project.ExecutionFrequency = execution_frequency
  8311. }
  8312. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8313. remark, _ := json["remark"].(string)
  8314. project.Remark = remark
  8315. }
  8316. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8317. day, _ := json["number_days"].(string)
  8318. project.Day = day
  8319. }
  8320. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8321. unit, _ := json["unit"].(string)
  8322. project.Unit = unit
  8323. }
  8324. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8325. // frequency_type := int64(json["frequency_type"].(float64))
  8326. // project.FrequencyType = frequency_type
  8327. //}
  8328. //
  8329. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8330. // day_count := int64(json["day_count"].(float64))
  8331. // project.DayCount = day_count
  8332. //}
  8333. //
  8334. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8335. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8336. // week_day, _ := json["week_day"].(string)
  8337. // project.WeekDay = week_day
  8338. //}
  8339. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8340. //
  8341. //if project.ID == 0 {
  8342. // if stockConfig.IsOpen == 1 {
  8343. // if project.Type == 3 {
  8344. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8345. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8346. // good.Total = good.Total - f_count
  8347. // service.UpdateGoodInfo(&good)
  8348. // }
  8349. // }
  8350. //
  8351. //} else {
  8352. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8353. //
  8354. // if stockConfig.IsOpen == 1 {
  8355. // if project.Type == 3 {
  8356. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8357. // if project.Count < temp_project.Count {
  8358. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8359. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8360. //
  8361. // other_count := f_count_two - f_count_one
  8362. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8363. // good.Total = good.Total + other_count_two
  8364. // service.UpdateGoodInfo(&good)
  8365. // } else if project.Count > temp_project.Count {
  8366. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8367. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8368. //
  8369. // other_count := f_count_one - f_count_two
  8370. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8371. // good.Total = good.Total - other_count_two
  8372. // service.UpdateGoodInfo(&good)
  8373. // }
  8374. //
  8375. // }
  8376. // }
  8377. //
  8378. //}
  8379. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8380. id := int64(json["id"].(float64))
  8381. if id > 0 {
  8382. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8383. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8384. fmt.Println("666666")
  8385. project.Mtime = time.Now().Unix()
  8386. project.Ctime = temp_project.Ctime
  8387. } else {
  8388. project.Mtime = temp_project.Mtime
  8389. project.Ctime = temp_project.Ctime
  8390. }
  8391. } else {
  8392. ctime := time.Now().Unix()
  8393. project.Mtime = ctime
  8394. project.Ctime = ctime
  8395. }
  8396. }
  8397. return 0
  8398. }
  8399. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8400. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8401. id := int64(json["id"].(float64))
  8402. additionalCharge.ID = id
  8403. }
  8404. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8405. item_id := int64(json["item_id"].(float64))
  8406. additionalCharge.ItemId = item_id
  8407. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8408. if config.ID > 0 {
  8409. if len(config.Code) > 0 {
  8410. additionalCharge.MedListCodg = config.Code
  8411. }
  8412. }
  8413. }
  8414. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8415. // price := int64(json["price"].(float64))
  8416. // formatInt_price := strconv.FormatInt(price, 10)
  8417. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8418. // additionalCharge.Price = float_price
  8419. // }
  8420. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8421. // price := int64(json["price"].(float64))
  8422. // formatInt_price := strconv.FormatInt(price, 10)
  8423. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8424. // additionalCharge.Price = float_price
  8425. //}
  8426. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8427. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8428. additionalCharge.Price = price
  8429. }
  8430. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8431. count, _ := json["count"].(string)
  8432. counts, _ := strconv.ParseInt(count, 10, 64)
  8433. additionalCharge.Count = counts
  8434. }
  8435. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8436. item_name, _ := json["item_name"].(string)
  8437. additionalCharge.ItemName = item_name
  8438. }
  8439. return 0
  8440. }
  8441. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8442. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8443. utils.ErrorLog("drug_name")
  8444. return enums.ErrorCodeParamWrong
  8445. }
  8446. adviceName, _ := json["drug_name"].(string)
  8447. if len(adviceName) == 0 {
  8448. utils.ErrorLog("len(advice_name) == 0")
  8449. return enums.ErrorCodeParamWrong
  8450. }
  8451. advice.AdviceName = adviceName
  8452. adviceDesc, _ := json["advice_desc"].(string)
  8453. advice.AdviceDesc = adviceDesc
  8454. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8455. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8456. advice.DrugSpec = drugSpec
  8457. }
  8458. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8459. remark, _ := json["remark"].(string)
  8460. advice.Remark = remark
  8461. }
  8462. if json["id"] == nil {
  8463. advice.DrugId = 0
  8464. } else {
  8465. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8466. drug_id := int64(json["id"].(float64))
  8467. advice.DrugId = drug_id
  8468. }
  8469. }
  8470. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8471. groupno := int64(json["groupno"].(float64))
  8472. advice.Groupno = groupno
  8473. }
  8474. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8475. drugSpecUnit, _ := json["min_unit"].(string)
  8476. advice.DrugSpecUnit = drugSpecUnit
  8477. }
  8478. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8479. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8480. advice.SingleDose = singleDose
  8481. }
  8482. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8483. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8484. advice.SingleDoseUnit = singleDoseUnit
  8485. }
  8486. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8487. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8488. advice.PrescribingNumber = prescribingNumber
  8489. }
  8490. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8491. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8492. advice.PrescribingNumberUnit = prescribingNumberUnit
  8493. }
  8494. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8495. deliveryWay, _ := json["delivery_way"].(string)
  8496. advice.DeliveryWay = deliveryWay
  8497. }
  8498. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8499. executionFrequency, _ := json["execution_frequency"].(string)
  8500. advice.ExecutionFrequency = executionFrequency
  8501. }
  8502. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8503. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8504. advice.Price = price
  8505. }
  8506. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8507. med_list_codg, _ := json["medical_insurance_number"].(string)
  8508. advice.MedListCodg = med_list_codg
  8509. }
  8510. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8511. day := int64(json["day"].(float64))
  8512. advice.Day = day
  8513. }
  8514. advice.FrequencyType = 1
  8515. return 0
  8516. }
  8517. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8518. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8519. types := int64(json["type"].(float64))
  8520. project.Type = types
  8521. }
  8522. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8523. project_id := int64(json["project_id"].(float64))
  8524. project.ProjectId = project_id
  8525. }
  8526. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8527. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8528. project.Price = price
  8529. }
  8530. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8531. total, _ := json["total"].(string)
  8532. //totals, _ := strconv.ParseInt(total, 10, 64)
  8533. project.Count = total
  8534. }
  8535. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8536. medical_code, _ := json["medical_code"].(string)
  8537. project.MedListCodg = medical_code
  8538. }
  8539. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8540. single_dose, _ := json["single_dose"].(string)
  8541. project.SingleDose = single_dose
  8542. }
  8543. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8544. delivery_way, _ := json["delivery_way"].(string)
  8545. project.DeliveryWay = delivery_way
  8546. }
  8547. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8548. execution_frequency, _ := json["execution_frequency"].(string)
  8549. project.ExecutionFrequency = execution_frequency
  8550. }
  8551. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8552. remark, _ := json["remark"].(string)
  8553. project.Remark = remark
  8554. }
  8555. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8556. day, _ := json["number_days"].(string)
  8557. project.Day = day
  8558. }
  8559. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8560. unit, _ := json["unit"].(string)
  8561. project.Unit = unit
  8562. }
  8563. project.FrequencyType = 1
  8564. return 0
  8565. }
  8566. func (c *HisApiController) GetHisOrderListTwo() {
  8567. start_time := c.GetString("start_time")
  8568. end_time := c.GetString("end_time")
  8569. timeLayout := "2006-01-02"
  8570. loc, _ := time.LoadLocation("Local")
  8571. var startTime int64
  8572. if len(start_time) > 0 {
  8573. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8574. if err != nil {
  8575. //fmt.Println(err)
  8576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8577. return
  8578. }
  8579. startTime = theTime.Unix()
  8580. }
  8581. var endTime int64
  8582. if len(end_time) > 0 {
  8583. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8584. if err != nil {
  8585. utils.ErrorLog(err.Error())
  8586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8587. return
  8588. }
  8589. endTime = theTime.Unix()
  8590. }
  8591. adminUser := c.GetAdminUserInfo()
  8592. org_id := adminUser.CurrentOrgId
  8593. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8594. if err == nil {
  8595. c.ServeSuccessJSON(map[string]interface{}{
  8596. "order2": order,
  8597. })
  8598. } else {
  8599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8600. return
  8601. }
  8602. }
  8603. func (c *HisApiController) GetHisOrderList() {
  8604. page, _ := c.GetInt64("page", -1)
  8605. limit, _ := c.GetInt64("limit", -1)
  8606. start_time := c.GetString("start_time")
  8607. end_time := c.GetString("end_time")
  8608. types, _ := c.GetInt64("type", 0)
  8609. keywords := c.GetString("keywords")
  8610. p_type, _ := c.GetInt64("p_type", 0)
  8611. sort_type, _ := c.GetInt64("sort_type", 0)
  8612. charge_type, _ := c.GetInt64("charge_type", 0)
  8613. sch_type, _ := c.GetInt64("sch_type", 0)
  8614. zone_type, _ := c.GetInt64("zone_type", 0)
  8615. med_type, _ := c.GetInt64("med_type", 0)
  8616. timeLayout := "2006-01-02"
  8617. loc, _ := time.LoadLocation("Local")
  8618. var startTime int64
  8619. if len(start_time) > 0 {
  8620. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8621. if err != nil {
  8622. //fmt.Println(err)
  8623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8624. return
  8625. }
  8626. startTime = theTime.Unix()
  8627. }
  8628. var endTime int64
  8629. if len(end_time) > 0 {
  8630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8631. if err != nil {
  8632. utils.ErrorLog(err.Error())
  8633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8634. return
  8635. }
  8636. endTime = theTime.Unix()
  8637. }
  8638. adminUser := c.GetAdminUserInfo()
  8639. org_id := adminUser.CurrentOrgId
  8640. 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)
  8641. for _, item := range order {
  8642. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8643. item.DoctorName = info.Doctor
  8644. item.DepartmentName = info.XtHisDepartment.Name
  8645. }
  8646. if err == nil {
  8647. c.ServeSuccessJSON(map[string]interface{}{
  8648. "order": order,
  8649. "total": total,
  8650. })
  8651. } else {
  8652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8653. return
  8654. }
  8655. }
  8656. func (c *HisApiController) GetHisOrder() {
  8657. patient_id, _ := c.GetInt64("patient_id", 0)
  8658. number := c.GetString("number")
  8659. adminInfo := c.GetAdminUserInfo()
  8660. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8661. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8662. if err == nil {
  8663. c.ServeSuccessJSON(map[string]interface{}{
  8664. "order": order,
  8665. "prescription": prescriptions,
  8666. })
  8667. } else {
  8668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8669. return
  8670. }
  8671. }
  8672. func (c *HisApiController) GetHisPrescriptionList() {
  8673. record_date := c.GetString("record_date")
  8674. keywords := c.GetString("keywords")
  8675. page, _ := c.GetInt64("page")
  8676. limit, _ := c.GetInt64("limit")
  8677. sch_type, _ := c.GetInt64("sch_type")
  8678. timeLayout := "2006-01-02"
  8679. loc, _ := time.LoadLocation("Local")
  8680. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8681. if err != nil {
  8682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8683. return
  8684. }
  8685. recordDateTime := theTime.Unix()
  8686. adminInfo := c.GetAdminUserInfo()
  8687. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8688. //adminInfo := c.GetAdminUserInfo()
  8689. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8690. //fmt.Println(prescriptionOrder)
  8691. if err == nil {
  8692. c.ServeSuccessJSON(map[string]interface{}{
  8693. "order": prescriptionOrder,
  8694. "total": total,
  8695. })
  8696. } else {
  8697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8698. return
  8699. }
  8700. }
  8701. func (c *HisApiController) GetHisPrescriptionInfo() {
  8702. id, _ := c.GetInt64("id")
  8703. adminInfo := c.GetAdminUserInfo()
  8704. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8705. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8706. if err == nil {
  8707. c.ServeSuccessJSON(map[string]interface{}{
  8708. "order": prescriptionOrder,
  8709. "prescription": prescription,
  8710. })
  8711. } else {
  8712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8713. return
  8714. }
  8715. }
  8716. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8717. adminUser := c.GetAdminUserInfo()
  8718. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8719. c.ServeSuccessJSON(map[string]interface{}{
  8720. "config": config,
  8721. })
  8722. }
  8723. type ResultTwo struct {
  8724. ErrMsg interface{} `json:"err_msg"`
  8725. InfRefmsgid string `json:"inf_refmsgid"`
  8726. Infcode int64 `json:"infcode"`
  8727. Output struct {
  8728. Baseinfo struct {
  8729. Age float64 `json:"age"`
  8730. Brdy string `json:"brdy"`
  8731. Certno string `json:"certno"`
  8732. Gend string `json:"gend"`
  8733. Naty string `json:"naty"`
  8734. PsnCertType string `json:"psn_cert_type"`
  8735. PsnName string `json:"psn_name"`
  8736. PsnNo string `json:"psn_no"`
  8737. } `json:"baseinfo"`
  8738. Idetinfo []interface{} `json:"idetinfo"`
  8739. Iinfo []struct {
  8740. Balc float64 `json:"balc"`
  8741. CvlservFlag string `json:"cvlserv_flag"`
  8742. EmpName string `json:"emp_name"`
  8743. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8744. Insutype string `json:"insutype"`
  8745. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8746. PausInsuDate interface{} `json:"paus_insu_date"`
  8747. PsnInsuDate string `json:"psn_insu_date"`
  8748. PsnInsuStas string `json:"psn_insu_stas"`
  8749. PsnType string `json:"psn_type"`
  8750. } `json:"insuinfo"`
  8751. } `json:"output"`
  8752. RefmsgTime string `json:"refmsg_time"`
  8753. RespondTime string `json:"respond_time"`
  8754. Signtype interface{} `json:"signtype"`
  8755. WarnInfo interface{} `json:"warn_info"`
  8756. }
  8757. type ResultThree struct {
  8758. Cainfo interface{} `json:"cainfo"`
  8759. ErrMsg interface{} `json:"err_msg"`
  8760. InfRefmsgid string `json:"inf_refmsgid"`
  8761. Infcode int64 `json:"infcode"`
  8762. Output struct {
  8763. Data struct {
  8764. IptOtpNo string `json:"ipt_otp_no"`
  8765. MdtrtID string `json:"mdtrt_id"`
  8766. PsnNo string `json:"psn_no"`
  8767. } `json:"data"`
  8768. } `json:"output"`
  8769. RefmsgTime string `json:"refmsg_time"`
  8770. RespondTime string `json:"respond_time"`
  8771. Signtype interface{} `json:"signtype"`
  8772. WarnMsg interface{} `json:"warn_msg"`
  8773. }
  8774. type ResultFour struct {
  8775. Cainfo string `json:"cainfo"`
  8776. ErrMsg string `json:"err_msg"`
  8777. InfRefmsgid string `json:"inf_refmsgid"`
  8778. Infcode int64 `json:"infcode"`
  8779. Output struct {
  8780. Result []struct {
  8781. BasMednFlag string `json:"bas_medn_flag"`
  8782. ChldMedcFlag string `json:"chld_medc_flag"`
  8783. ChrgitmLv string `json:"chrgitm_lv"`
  8784. Cnt float64 `json:"cnt"`
  8785. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8786. DrtReimFlag string `json:"drt_reim_flag"`
  8787. FeedetlSn string `json:"feedetl_sn"`
  8788. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8789. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8790. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8791. ListSpItemFlag string `json:"list_sp_item_flag"`
  8792. LmtUsedFlag string `json:"lmt_used_flag"`
  8793. MedChrgitmType string `json:"med_chrgitm_type"`
  8794. Memo string `json:"memo"`
  8795. OverlmtAmt float64 `json:"overlmt_amt"`
  8796. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8797. Pric float64 `json:"pric"`
  8798. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8799. SelfpayProp float64 `json:"selfpay_prop"`
  8800. } `json:"result"`
  8801. } `json:"output"`
  8802. RefmsgTime string `json:"refmsg_time"`
  8803. RespondTime string `json:"respond_time"`
  8804. Signtype string `json:"signtype"`
  8805. WarnMsg string `json:"warn_msg"`
  8806. }
  8807. type ResultFive struct {
  8808. Insutype string `json:"insutype"`
  8809. }
  8810. type ResultSix struct {
  8811. Cainfo interface{} `json:"cainfo"`
  8812. ErrMsg interface{} `json:"err_msg"`
  8813. InfRefmsgid string `json:"inf_refmsgid"`
  8814. Infcode int64 `json:"infcode"`
  8815. Output struct {
  8816. } `json:"output"`
  8817. RefmsgTime string `json:"refmsg_time"`
  8818. RespondTime string `json:"respond_time"`
  8819. Signtype interface{} `json:"signtype"`
  8820. WarnMsg interface{} `json:"warn_msg"`
  8821. }
  8822. type ResultSeven struct {
  8823. Cainfo string `json:"cainfo"`
  8824. ErrMsg string `json:"err_msg"`
  8825. InfRefmsgid string `json:"inf_refmsgid"`
  8826. Infcode int64 `json:"infcode"`
  8827. Output struct {
  8828. Setldetail []interface{} `json:"setldetail"`
  8829. Setlinfo struct {
  8830. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8831. AcctPay float64 `json:"acct_pay"`
  8832. ActPayDedc float64 `json:"act_pay_dedc"`
  8833. Age float64 `json:"age"`
  8834. Balc float64 `json:"balc"`
  8835. Brdy string `json:"brdy"`
  8836. Certno string `json:"certno"`
  8837. ClrOptins string `json:"clr_optins"`
  8838. ClrType string `json:"clr_type"`
  8839. ClrWay string `json:"clr_way"`
  8840. CvlservFlag string `json:"cvlserv_flag"`
  8841. CvlservPay float64 `json:"cvlserv_pay"`
  8842. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8843. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8844. Gend string `json:"gend"`
  8845. HifesPay float64 `json:"hifes_pay"`
  8846. HifmiPay float64 `json:"hifmi_pay"`
  8847. HifobPay float64 `json:"hifob_pay"`
  8848. HifpPay float64 `json:"hifp_pay"`
  8849. HospPartAmt float64 `json:"hosp_part_amt"`
  8850. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8851. Insutype string `json:"insutype"`
  8852. MafPay float64 `json:"maf_pay"`
  8853. MdtrtCertType string `json:"mdtrt_cert_type"`
  8854. MdtrtID string `json:"mdtrt_id"`
  8855. MedType string `json:"med_type"`
  8856. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8857. MedinsSetlID string `json:"medins_setl_id"`
  8858. Naty string `json:"naty"`
  8859. OthPay float64 `json:"oth_pay"`
  8860. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8861. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8862. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8863. PsnCashPay float64 `json:"psn_cash_pay"`
  8864. PsnCertType string `json:"psn_cert_type"`
  8865. PsnName string `json:"psn_name"`
  8866. PsnNo string `json:"psn_no"`
  8867. PsnPartAmt float64 `json:"psn_part_amt"`
  8868. PsnType string `json:"psn_type"`
  8869. SetlID string `json:"setl_id"`
  8870. SetlTime string `json:"setl_time"`
  8871. } `json:"setlinfo"`
  8872. } `json:"output"`
  8873. RefmsgTime string `json:"refmsg_time"`
  8874. RespondTime string `json:"respond_time"`
  8875. Signtype interface{} `json:"signtype"`
  8876. WarnMsg interface{} `json:"warn_msg"`
  8877. }
  8878. type ResultEight struct {
  8879. Cainfo string `json:"cainfo"`
  8880. ErrMsg string `json:"err_msg"`
  8881. InfRefmsgid string `json:"inf_refmsgid"`
  8882. Infcode int64 `json:"infcode"`
  8883. Output struct {
  8884. Stmtinfo struct {
  8885. SetlOptins string `json:"setl_optins"`
  8886. StmtRslt string `json:"stmt_rslt"`
  8887. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8888. } `json:"stmtinfo"`
  8889. } `json:"output"`
  8890. RefmsgTime string `json:"refmsg_time"`
  8891. RespondTime string `json:"respond_time"`
  8892. Signtype interface{} `json:"signtype"`
  8893. WarnMsg interface{} `json:"warn_msg"`
  8894. }
  8895. type ResultNine struct {
  8896. Cainfo string `json:"cainfo"`
  8897. ErrMsg string `json:"err_msg"`
  8898. InfRefmsgid string `json:"inf_refmsgid"`
  8899. Infcode int64 `json:"infcode"`
  8900. Output struct {
  8901. FileQuryNo string `json:"file_qury_no"`
  8902. } `json:"output"`
  8903. RefmsgTime string `json:"refmsg_time"`
  8904. RespondTime string `json:"respond_time"`
  8905. Signtype interface{} `json:"signtype"`
  8906. WarnMsg interface{} `json:"warn_msg"`
  8907. }
  8908. type ResultTen struct {
  8909. Cainfo string `json:"cainfo"`
  8910. ErrMsg string `json:"err_msg"`
  8911. InfRefmsgid string `json:"inf_refmsgid"`
  8912. Infcode int64 `json:"infcode"`
  8913. Output struct {
  8914. DldEndtime string `json:"dld_endtime"`
  8915. FileQuryNo string `json:"file_qury_no"`
  8916. Filename string `json:"filename"`
  8917. } `json:"output"`
  8918. RefmsgTime string `json:"refmsg_time"`
  8919. RespondTime string `json:"respond_time"`
  8920. Signtype interface{} `json:"signtype"`
  8921. WarnMsg interface{} `json:"warn_msg"`
  8922. }
  8923. type ResultEleven struct {
  8924. Cainfo string `json:"cainfo"`
  8925. ErrMsg string `json:"err_msg"`
  8926. InfRefmsgid string `json:"inf_refmsgid"`
  8927. Infcode int64 `json:"infcode"`
  8928. Output struct {
  8929. Setlinfo struct {
  8930. FixmedinsName string `json:"fixmedins_name"`
  8931. FixmedinsCode string `json:"fixmedins_code"`
  8932. PsnNo string `json:"psn_no"`
  8933. PsnName string `json:"psn_name"`
  8934. HifobPay float64 `json:"hifob_pay"`
  8935. Gend string `json:"gend"`
  8936. Brdy string `json:"brdy"`
  8937. PsnCertType string `json:"psn_cert_type"`
  8938. PsnType string `json:"psn_type"`
  8939. EmpName string `json:"emp_name"`
  8940. Certno string `json:"certno"`
  8941. Insutype string `json:"insutype"`
  8942. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8943. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8944. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8945. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8946. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8947. ActPayDedc float64 `json:"act_pay_dedc"`
  8948. HifpPay float64 `json:"hifp_pay"`
  8949. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8950. CvlservPay float64 `json:"cvlserv_pay"`
  8951. HifesPay float64 `json:"hifes_pay"`
  8952. HifmiPay float64 `json:"hifmi_pay"`
  8953. MafPay float64 `json:"maf_pay"`
  8954. OthPay float64 `json:"oth_pay"`
  8955. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8956. PsnPay float64 `json:"psn_pay"`
  8957. AcctPay float64 `json:"acct_pay"`
  8958. CashPayamt float64 `json:"cash_payamt"`
  8959. Balc float64 `json:"balc"`
  8960. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8961. MedinsSetlId string `json:"medins_setl_id"`
  8962. RefdSetlFlag string `json:"refd_setl_flag"`
  8963. SetlTime string `json:"setl_time"`
  8964. MedType string `json:"med_type"`
  8965. } `json:"setlinfo"`
  8966. } `json:"output"`
  8967. RefmsgTime string `json:"refmsg_time"`
  8968. RespondTime string `json:"respond_time"`
  8969. Signtype interface{} `json:"signtype"`
  8970. WarnMsg interface{} `json:"warn_msg"`
  8971. }
  8972. type Custom struct {
  8973. DetItemFeeSumamt string
  8974. Cut string
  8975. FeedetlSn string
  8976. Price string
  8977. MedListCodg string
  8978. Type int64
  8979. AdviceId int64
  8980. ProjectId int64
  8981. ItemId int64
  8982. CostType int64
  8983. }
  8984. // 获取个人信息----挂号-----上传就诊信息
  8985. func (c *HisApiController) GetRegisterInfo() {
  8986. id, _ := c.GetInt64("id")
  8987. record_time := c.GetString("record_time")
  8988. settlementValue, _ := c.GetInt64("settlement_value")
  8989. medical_insurance_card := c.GetString("medical_insurance_card")
  8990. name := c.GetString("name")
  8991. id_card_type, _ := c.GetInt64("id_card_type")
  8992. certificates, _ := c.GetInt64("certificates")
  8993. medical_care, _ := c.GetInt64("medical_care")
  8994. birthday := c.GetString("birthday")
  8995. age, _ := c.GetInt64("age")
  8996. id_card := c.GetString("id_card")
  8997. register_type, _ := c.GetInt64("register")
  8998. doctor, _ := c.GetInt64("doctor")
  8999. department, _ := c.GetInt64("department")
  9000. gender, _ := c.GetInt64("sex")
  9001. phone := c.GetString("phone")
  9002. registration_fee, _ := c.GetFloat("registration_fee")
  9003. medical_expenses, _ := c.GetFloat("medical_expenses")
  9004. social_type, _ := c.GetInt64("social_type")
  9005. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9006. diagnosis_ids := c.GetString("diagnosis")
  9007. sick_type, _ := c.GetInt64("sick_type")
  9008. reg_type := c.GetString("p_type")
  9009. timeLayout := "2006-01-02"
  9010. loc, _ := time.LoadLocation("Local")
  9011. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9012. birthUnix := birthdays.Unix()
  9013. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9014. if err != nil {
  9015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9016. return
  9017. }
  9018. recordDateTime := theTime.Unix()
  9019. adminInfo := c.GetAdminUserInfo()
  9020. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9021. if tempPatient.ID == 0 {
  9022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9023. return
  9024. }
  9025. var patient service.Patients
  9026. if id == 0 {
  9027. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9028. } else {
  9029. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9030. }
  9031. if patient.ID == 0 {
  9032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9033. return
  9034. }
  9035. if len(patient.IdCardNo) == 0 {
  9036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9037. return
  9038. }
  9039. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9040. if len(his) >= 1 {
  9041. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9042. if len(his) >= 1 && order.ID == 0 {
  9043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9044. return
  9045. }
  9046. }
  9047. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9048. fmt.Println(timeStr)
  9049. timeArr := strings.Split(timeStr, " ")
  9050. fmt.Println(timeArr)
  9051. timeArrTwo := strings.Split(timeArr[0], "-")
  9052. timeArrThree := strings.Split(timeArr[1], ":")
  9053. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9054. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9055. if len(lists) == 0 {
  9056. var hisPatient models.XtHisPatient
  9057. hisPatient = models.XtHisPatient{
  9058. Name: name,
  9059. Age: age,
  9060. Gender: gender,
  9061. Birthday: birthUnix,
  9062. Phone: phone,
  9063. MedicalTreatmentType: medical_care,
  9064. IdType: certificates,
  9065. IdCardNo: id_card,
  9066. BalanceAccountsType: settlementValue,
  9067. SocialType: social_type,
  9068. MedicalInsuranceNumber: medical_insurance_card,
  9069. RegisterType: register_type,
  9070. RegisterCost: registration_fee,
  9071. TreatmentCost: medical_expenses,
  9072. AdminUserId: adminInfo.AdminUser.Id,
  9073. UserOrgId: adminInfo.CurrentOrgId,
  9074. Status: 1,
  9075. RecordDate: recordDateTime,
  9076. IsReturn: 1,
  9077. PatientId: patient.ID,
  9078. Ctime: time.Now().Unix(),
  9079. Mtime: time.Now().Unix(),
  9080. Number: str,
  9081. IdCardType: id_card_type,
  9082. Departments: department,
  9083. Doctor: doctor,
  9084. PType: reg_type,
  9085. Diagnosis: diagnosis_ids,
  9086. SickType: sick_type,
  9087. }
  9088. service.CreateHisPatient(&hisPatient)
  9089. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9090. c.ServeSuccessJSON(map[string]interface{}{
  9091. "his_info": hisPatient,
  9092. })
  9093. } else {
  9094. //chrgBchno := rand.Intn(1000000) + 10000
  9095. var hisPatient models.XtHisPatient
  9096. hisPatient = models.XtHisPatient{
  9097. Name: name,
  9098. Age: age,
  9099. Gender: gender,
  9100. Birthday: birthUnix,
  9101. Phone: phone,
  9102. MedicalTreatmentType: medical_care,
  9103. IdType: certificates,
  9104. IdCardNo: id_card,
  9105. BalanceAccountsType: settlementValue,
  9106. SocialType: social_type,
  9107. MedicalInsuranceNumber: medical_insurance_card,
  9108. RegisterType: register_type,
  9109. RegisterCost: registration_fee,
  9110. TreatmentCost: medical_expenses,
  9111. AdminUserId: adminInfo.AdminUser.Id,
  9112. UserOrgId: adminInfo.CurrentOrgId,
  9113. Status: 1,
  9114. RecordDate: recordDateTime,
  9115. IsReturn: 1,
  9116. PatientId: patient.ID,
  9117. Ctime: time.Now().Unix(),
  9118. Mtime: time.Now().Unix(),
  9119. Number: str,
  9120. IdCardType: id_card_type,
  9121. Departments: department,
  9122. Doctor: doctor,
  9123. PType: reg_type,
  9124. Diagnosis: diagnosis_ids,
  9125. SickType: sick_type,
  9126. }
  9127. service.CreateHisPatient(&hisPatient)
  9128. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9129. c.ServeSuccessJSON(map[string]interface{}{
  9130. "his_info": hisPatient,
  9131. })
  9132. }
  9133. }
  9134. // 上传明细----结算
  9135. func (c *HisApiController) GetUploadInfo() {
  9136. id, _ := c.GetInt64("id")
  9137. record_time := c.GetString("record_time")
  9138. his_patient_id, _ := c.GetInt64("his_patient_id")
  9139. oth_desc := c.GetString("oth_desc")
  9140. pay_way, _ := c.GetInt64("pay_way")
  9141. pay_ways := c.GetString("pay_ways")
  9142. pay_price, _ := c.GetFloat("pay_price")
  9143. pay_card_no := c.GetString("pay_card_no")
  9144. discount_price, _ := c.GetFloat("discount_price")
  9145. preferential_price, _ := c.GetFloat("preferential_price")
  9146. reality_price, _ := c.GetFloat("reality_price")
  9147. found_price, _ := c.GetFloat("found_price")
  9148. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9149. private_price, _ := c.GetFloat("private_price")
  9150. timeLayout := "2006-01-02"
  9151. loc, _ := time.LoadLocation("Local")
  9152. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9153. fapiao_code := c.GetString("fapiao_code")
  9154. fapiao_number := c.GetString("fapiao_number")
  9155. diagnosis_id := c.GetString("diagnosis")
  9156. sick_type, _ := c.GetInt64("sick_type")
  9157. reg_type, _ := c.GetInt64("p_type")
  9158. order_id, _ := c.GetInt64("order_id")
  9159. cash_pay := c.GetString("cash_pay")
  9160. wechat_pay := c.GetString("wechat_pay")
  9161. ali_pay := c.GetString("ali_pay")
  9162. jifen_pay := c.GetString("jifen_pay")
  9163. band_card_pay := c.GetString("band_card_pay")
  9164. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9165. tmp_decimal := c.GetString("tmp_decimal")
  9166. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9167. var decimal float64 //本次使用的押金
  9168. var errmsg error
  9169. tx := service.XTWriteDB().Begin() //开了事务
  9170. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9171. defer func() {
  9172. if errmsg != nil {
  9173. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9174. tx.Rollback()
  9175. } else {
  9176. tx.Commit()
  9177. }
  9178. }()
  9179. fmt.Println("dec_way", dec_way)
  9180. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9181. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9182. return
  9183. }
  9184. if len(tmp_decimal) > 0 {
  9185. if tmp_decimal[0] == 45 {
  9186. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9187. return
  9188. }
  9189. }
  9190. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9191. fmt.Println(errs)
  9192. decimal = tt
  9193. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9194. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9195. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9196. if err != nil {
  9197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9198. return
  9199. }
  9200. recordDateTime := theTime.Unix()
  9201. adminUser := c.GetAdminUserInfo()
  9202. var prescriptions []*models.HisPrescription
  9203. var prescriptionsOne []*models.HisPrescription
  9204. var start_time int64
  9205. var end_time int64
  9206. ids_str := c.GetString("ids")
  9207. ids_arr := strings.Split(ids_str, ",")
  9208. if tempOrder.ID == 0 {
  9209. if settle_accounts_type == 1 { //日结
  9210. fmt.Println(reg_type)
  9211. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9212. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9213. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9214. } else {
  9215. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9216. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9217. }
  9218. } else { //月结
  9219. start_time_str := c.GetString("start_time")
  9220. end_time_str := c.GetString("end_time")
  9221. timeLayout := "2006-01-02"
  9222. loc, _ := time.LoadLocation("Local")
  9223. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9224. if err != nil {
  9225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9226. return
  9227. }
  9228. recordStartTime := theStartTime.Unix()
  9229. start_time = recordStartTime
  9230. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9231. if err != nil {
  9232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9233. return
  9234. }
  9235. recordEndTime := theEndTime.Unix()
  9236. end_time = recordEndTime
  9237. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9238. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9239. }
  9240. var goods []*models.DialysisBeforePrepareGoods
  9241. var newGoods []*models.NewDialysisBeforePrepareGoods
  9242. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9243. var infos []*models.HisDoctorAdviceInfo
  9244. var infoList []*models.HisDoctorAdviceInfo
  9245. var hisAdvice []*models.HisDoctorAdviceInfo
  9246. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9247. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9248. //判断库存不足
  9249. //结算出库开关
  9250. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9251. if settConfig.IsOpen == 1 {
  9252. //判断库存的地方
  9253. for _, info := range prescriptions {
  9254. if info.Type == 1 {
  9255. infos = append(infos, info.HisDoctorAdviceInfo...)
  9256. }
  9257. if info.Type == 2 {
  9258. for _, sumItem := range info.HisPrescriptionProject {
  9259. if sumItem.Type == 3 {
  9260. var good models.DialysisBeforePrepareGoods
  9261. var newGood models.NewDialysisBeforePrepareGoods
  9262. good.GoodId = sumItem.GoodInfo.ID
  9263. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9264. count, _ := strconv.Atoi(sumItem.Count)
  9265. good.Count = int64(count)
  9266. good.StorehouseId = houseConfig.StorehouseOutInfo
  9267. good.ProjectId = sumItem.ID
  9268. goods = append(goods, &good)
  9269. newGood.GoodId = sumItem.GoodInfo.ID
  9270. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9271. count2, _ := strconv.Atoi(sumItem.Count)
  9272. newGood.Count = int64(count2)
  9273. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9274. newGood.ProjectId = sumItem.ID
  9275. newGoods = append(newGoods, &newGood)
  9276. }
  9277. }
  9278. }
  9279. }
  9280. for _, info := range prescriptionsOne {
  9281. if info.Type == 1 {
  9282. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9283. }
  9284. if info.Type == 2 {
  9285. for _, sumItem := range info.HisPrescriptionProject {
  9286. if sumItem.Type == 3 {
  9287. var newGood models.NewDialysisBeforePrepareGoods
  9288. newGood.GoodId = sumItem.GoodInfo.ID
  9289. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9290. count2, _ := strconv.Atoi(sumItem.Count)
  9291. newGood.Count = int64(count2)
  9292. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9293. newGood.ProjectId = sumItem.ID
  9294. newGoodOne = append(newGoodOne, &newGood)
  9295. }
  9296. }
  9297. }
  9298. }
  9299. //判断
  9300. for _, itemOne := range infos {
  9301. for _, itemTwo := range hisAdvice {
  9302. if itemOne.DrugId == itemTwo.DrugId {
  9303. itemTwo.Child = append(itemTwo.Child, itemOne)
  9304. }
  9305. }
  9306. }
  9307. for _, itemTwo := range hisAdvice {
  9308. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9309. var sum_out_count int64
  9310. for _, itemThree := range itemTwo.Child {
  9311. var prescribing_number int64
  9312. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9313. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9314. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9315. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9316. }
  9317. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9318. prescribing_number = parseIntPrescribingNumber
  9319. }
  9320. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9321. prescribing_number = parseIntPrescribingNumber
  9322. }
  9323. sum_out_count += prescribing_number
  9324. }
  9325. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9326. if sum_out_count > drugStockOut.FlushCount {
  9327. c.ServeSuccessJSON(map[string]interface{}{
  9328. "msg": "2",
  9329. "drug": medical,
  9330. })
  9331. return
  9332. }
  9333. }
  9334. for _, itemOne := range newGoods {
  9335. for _, item := range newGoodOne {
  9336. if itemOne.GoodId == item.GoodId {
  9337. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9338. }
  9339. }
  9340. }
  9341. for _, item := range newGoodOne {
  9342. var sum_out_count_one int64
  9343. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9344. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9345. sum_out_count_one += itemOne.Count
  9346. }
  9347. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9348. fmt.Println("sum_out_count_one", sum_out_count_one)
  9349. fmt.Println("list.FlushCount", list.FlushCount)
  9350. if sum_out_count_one > list.FlushCount {
  9351. c.ServeSuccessJSON(map[string]interface{}{
  9352. "msg": "3",
  9353. "good": good,
  9354. })
  9355. return
  9356. }
  9357. }
  9358. }
  9359. timestamp := time.Now().Unix()
  9360. tempTime := time.Unix(timestamp, 0)
  9361. timeFormat := tempTime.Format("20060102150405")
  9362. chrgBchno := rand.Intn(100000) + 10000
  9363. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9364. strconv.FormatInt(his.PatientId, 10)
  9365. var ids []int64
  9366. for _, item := range prescriptions {
  9367. ids = append(ids, item.ID)
  9368. }
  9369. var total float64
  9370. for _, item := range prescriptions {
  9371. fmt.Println(item)
  9372. if item.Type == 1 { //药品
  9373. for _, subItem := range item.HisDoctorAdviceInfo {
  9374. total = total + (subItem.Price * subItem.PrescribingNumber)
  9375. }
  9376. }
  9377. if item.Type == 2 { //项目
  9378. for _, subItem := range item.HisPrescriptionProject {
  9379. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9380. total = total + (subItem.Price * cnt)
  9381. }
  9382. }
  9383. for _, subItem := range item.HisAdditionalCharge {
  9384. total = total + (subItem.Price * float64(subItem.Count))
  9385. }
  9386. }
  9387. if reg_type == 1111 || reg_type == 1112 {
  9388. reg_type = 11
  9389. }
  9390. tm := time.Unix(time.Now().Unix(), 0)
  9391. allTotal := fmt.Sprintf("%.4f", total)
  9392. totals, _ := strconv.ParseFloat(allTotal, 64)
  9393. order := &models.HisOrder{
  9394. UserOrgId: adminUser.CurrentOrgId,
  9395. HisPatientId: his.ID,
  9396. PatientId: id,
  9397. SettleAccountsDate: recordDateTime,
  9398. Ctime: time.Now().Unix(),
  9399. Mtime: time.Now().Unix(),
  9400. Status: 1,
  9401. OrderStatus: 2,
  9402. MdtrtId: his.Number,
  9403. Number: chrg_bchno,
  9404. MedfeeSumamt: totals,
  9405. PayWay: pay_way,
  9406. PayWays: pay_ways,
  9407. PayPrice: pay_price,
  9408. MedType: strconv.Itoa(int(reg_type)),
  9409. PayCardNo: pay_card_no,
  9410. DiscountPrice: discount_price,
  9411. PreferentialPrice: preferential_price,
  9412. RealityPrice: reality_price,
  9413. FoundPrice: found_price,
  9414. MedicalInsurancePrice: medical_insurance_price,
  9415. PrivatePrice: private_price,
  9416. SettleEndTime: end_time,
  9417. SettleStartTime: start_time,
  9418. PsnPartAmt: totals,
  9419. PsnCashPay: totals,
  9420. SettleType: settle_accounts_type,
  9421. FaPiaoCode: fapiao_code,
  9422. FaPiaoNumber: fapiao_number,
  9423. Diagnosis: diagnosis_id,
  9424. PType: 2,
  9425. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9426. Decimal: decimal,
  9427. OthDesc: oth_desc,
  9428. CashPay: cash_pay,
  9429. WechatPay: wechat_pay,
  9430. AliPay: ali_pay,
  9431. JifenPay: jifen_pay,
  9432. BandCardPay: band_card_pay,
  9433. Creator: adminUser.AdminUser.Id,
  9434. }
  9435. err = service.CreateOrderTX(order, tx)
  9436. if err != nil {
  9437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9438. return
  9439. }
  9440. var customs []*Custom
  9441. for _, item := range prescriptions {
  9442. if item.Type == 1 { //药品a
  9443. for _, subItem := range item.HisDoctorAdviceInfo {
  9444. cus := &Custom{
  9445. AdviceId: subItem.ID,
  9446. ProjectId: 0,
  9447. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9448. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9449. FeedetlSn: subItem.FeedetlSn,
  9450. Price: fmt.Sprintf("%.4f", subItem.Price),
  9451. MedListCodg: subItem.MedListCodg,
  9452. Type: 1,
  9453. CostType: 9,
  9454. }
  9455. customs = append(customs, cus)
  9456. }
  9457. }
  9458. if item.Type == 2 { //项目
  9459. for _, subItem := range item.HisPrescriptionProject {
  9460. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9461. cus := &Custom{
  9462. AdviceId: 0,
  9463. ProjectId: subItem.ID,
  9464. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9465. Cut: fmt.Sprintf("%.4f", cnt),
  9466. FeedetlSn: subItem.FeedetlSn,
  9467. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9468. MedListCodg: subItem.MedListCodg,
  9469. Type: 2,
  9470. CostType: subItem.HisProject.CostClassify,
  9471. }
  9472. customs = append(customs, cus)
  9473. }
  9474. }
  9475. for _, item := range item.HisAdditionalCharge {
  9476. cus := &Custom{
  9477. ItemId: item.ID,
  9478. AdviceId: 0,
  9479. ProjectId: 0,
  9480. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9481. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9482. FeedetlSn: item.FeedetlSn,
  9483. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9484. MedListCodg: item.XtHisAddtionConfig.Code,
  9485. Type: 3,
  9486. CostType: 5,
  9487. }
  9488. customs = append(customs, cus)
  9489. }
  9490. }
  9491. for _, item := range customs {
  9492. var advice_id int64 = 0
  9493. var project_id int64 = 0
  9494. var item_id int64 = 0
  9495. var types int64 = 0
  9496. var med_chrgitm_type string
  9497. if item.Type == 1 {
  9498. advice_id = item.AdviceId
  9499. project_id = 0
  9500. item_id = 0
  9501. med_chrgitm_type = "09"
  9502. } else if item.Type == 2 {
  9503. med_chrgitm_type = "05"
  9504. if item.CostType == 3 {
  9505. med_chrgitm_type = "04"
  9506. }
  9507. if item.CostType == 8 {
  9508. med_chrgitm_type = "03"
  9509. }
  9510. advice_id = 0
  9511. item_id = 0
  9512. project_id = item.ProjectId
  9513. } else if item.Type == 3 {
  9514. advice_id = 0
  9515. item_id = item.ItemId
  9516. project_id = 0
  9517. med_chrgitm_type = "08"
  9518. }
  9519. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9520. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9521. pric, _ := strconv.ParseFloat(item.Price, 32)
  9522. info := &models.HisOrderInfo{
  9523. OrderNumber: order.Number,
  9524. UploadDate: time.Now().Unix(),
  9525. AdviceId: advice_id,
  9526. DetItemFeeSumamt: detItemFeeSumamt,
  9527. MedChrgitmType: med_chrgitm_type,
  9528. Cnt: cut,
  9529. Pric: pric,
  9530. PatientId: id,
  9531. Status: 1,
  9532. Mtime: time.Now().Unix(),
  9533. Ctime: time.Now().Unix(),
  9534. UserOrgId: adminUser.CurrentOrgId,
  9535. HisPatientId: his.ID,
  9536. OrderId: order.ID,
  9537. ProjectId: project_id,
  9538. Type: types,
  9539. ItemId: item_id,
  9540. }
  9541. service.CreateOrderInfoTX(info, tx)
  9542. }
  9543. his.Diagnosis = diagnosis_id
  9544. his.SickType = sick_type
  9545. his.RegisterType = reg_type
  9546. his.MedicalTreatmentType = reg_type
  9547. service.UpdataHisPateintTX(&his, tx)
  9548. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9549. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9550. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9551. //判断是否使用了押金
  9552. if dec_way == "true" {
  9553. tmpstring := strconv.FormatInt(order.ID, 10)
  9554. //扣押金
  9555. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9556. order.Decimal = decimal
  9557. service.UpDateOrderTwo(order, tx)
  9558. if errmsg != nil {
  9559. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9560. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9561. return
  9562. }
  9563. }
  9564. if err == nil {
  9565. for _, info := range prescriptions {
  9566. if info.Type == 1 {
  9567. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9568. }
  9569. if info.Type == 2 {
  9570. for _, sumItem := range info.HisPrescriptionProject {
  9571. if sumItem.Type == 3 {
  9572. var good models.DialysisBeforePrepareGoods
  9573. var newGood models.NewDialysisBeforePrepareGoods
  9574. var oldGood models.OldDialysisBeforePrepareGoods
  9575. good.GoodId = sumItem.GoodInfo.ID
  9576. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9577. count, _ := strconv.Atoi(sumItem.Count)
  9578. good.Count = int64(count)
  9579. good.StorehouseId = houseConfig.StorehouseOutInfo
  9580. good.ProjectId = sumItem.ID
  9581. good.PatientId = sumItem.PatientId
  9582. goods = append(goods, &good)
  9583. newGood.GoodId = sumItem.GoodInfo.ID
  9584. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9585. count2, _ := strconv.Atoi(sumItem.Count)
  9586. newGood.Count = int64(count2)
  9587. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9588. newGood.ProjectId = sumItem.ID
  9589. newGood.PatientId = sumItem.HisPatientId
  9590. newGoods = append(newGoods, &newGood)
  9591. oldGood.GoodId = sumItem.GoodInfo.ID
  9592. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9593. count3, _ := strconv.Atoi(sumItem.Count)
  9594. oldGood.Count = int64(count3)
  9595. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9596. oldGood.ProjectId = sumItem.ID
  9597. oldGood.RecordDate = sumItem.RecordDate
  9598. oldGood.PatientId = sumItem.HisPatientId
  9599. oldGoods = append(oldGoods, &oldGood)
  9600. }
  9601. }
  9602. }
  9603. }
  9604. if settConfig.IsOpen == 1 {
  9605. for _, item := range infoList {
  9606. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9607. if medical.IsUse == 2 {
  9608. //药品出库
  9609. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9610. //查询默认仓库
  9611. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9612. //查询默认仓库剩余多少库存
  9613. var sum_count int64
  9614. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9615. for _, its := range stockInfo {
  9616. if its.MaxUnit == medical.MaxUnit {
  9617. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9618. }
  9619. sum_count += its.StockMaxNumber + its.StockMinNumber
  9620. }
  9621. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9622. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9623. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9624. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9625. }
  9626. }
  9627. orgId := c.GetAdminUserInfo().CurrentOrgId
  9628. if len(oldGoods) > 0 {
  9629. timeStr := time.Now().Format("2006-01-02")
  9630. timeArr := strings.Split(timeStr, "-")
  9631. total, _ := service.FindAllWarehouseOut(orgId)
  9632. total = total + 1
  9633. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9634. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9635. number = number + total
  9636. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9637. operation_time := time.Now().Unix()
  9638. creater := c.GetAdminUserInfo().AdminUser.Id
  9639. //查询默认出库仓库库存
  9640. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9641. recordDateStr := time.Now().Format("2006-01-02")
  9642. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9643. nowtime := recordDate.Unix()
  9644. warehouseOut := models.WarehouseOut{
  9645. WarehouseOutOrderNumber: warehousing_out_order,
  9646. OperationTime: operation_time,
  9647. OrgId: orgId,
  9648. Creater: creater,
  9649. Ctime: time.Now().Unix(),
  9650. Status: 1,
  9651. WarehouseOutTime: nowtime,
  9652. Type: 1,
  9653. StorehouseId: storeConfig.StorehouseOutInfo,
  9654. IsCheck: 1,
  9655. OrderId: order.ID,
  9656. IsSys: 5,
  9657. }
  9658. //查询是否生成出库单
  9659. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9660. if out.ID == 0 {
  9661. service.AddSigleWarehouseOut(&warehouseOut)
  9662. }
  9663. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9664. for _, item := range oldGoods {
  9665. dialyPrepareOne := models.DialysisBeforePrepare{
  9666. GoodTypeId: item.GoodTypeId,
  9667. GoodId: item.GoodId,
  9668. PatientId: his.PatientId,
  9669. RecordDate: item.RecordDate,
  9670. UserOrgId: adminUser.CurrentOrgId,
  9671. Count: item.Count,
  9672. Ctime: time.Now().Unix(),
  9673. Creater: adminUser.AdminUser.Id,
  9674. CommdityCode: item.CommdityCode,
  9675. Status: 1,
  9676. StorehouseId: houseConfig.StorehouseOutInfo,
  9677. }
  9678. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9679. //非零用
  9680. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9681. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9682. //查询剩余库存
  9683. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9684. var sum_count int64
  9685. for _, item := range goodList {
  9686. sum_count += item.StockCount
  9687. }
  9688. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9689. //耗材
  9690. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9691. }
  9692. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9693. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9694. //查询剩余库存
  9695. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9696. var sum_count int64
  9697. for _, item := range goodList {
  9698. sum_count += item.StockCount
  9699. }
  9700. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9701. //耗材
  9702. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9703. }
  9704. }
  9705. }
  9706. }
  9707. c.ServeSuccessJSON(map[string]interface{}{
  9708. "msg": "结算成功",
  9709. })
  9710. }
  9711. }
  9712. }
  9713. // 退款
  9714. func (c *HisApiController) Refund() {
  9715. order_id, _ := c.GetInt64("order_id")
  9716. order, _ := service.GetHisOrderByID(order_id)
  9717. adminUser := c.GetAdminUserInfo()
  9718. orgid := c.GetAdminUserInfo().CurrentOrgId
  9719. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9720. if err != nil {
  9721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9722. return
  9723. }
  9724. tmp := strconv.FormatInt(order.ID, 10)
  9725. //当押金不为零时产生退费记录
  9726. if order.Decimal != 0 {
  9727. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9728. if err != nil {
  9729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9730. return
  9731. }
  9732. }
  9733. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9734. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9735. var goods []*models.DialysisBeforePrepareGoods
  9736. var newGoods []*models.NewDialysisBeforePrepareGoods
  9737. var infos []*models.HisDoctorAdviceInfo
  9738. for _, info := range orders {
  9739. if info.AdviceId > 0 && info.ProjectId == 0 {
  9740. infos = append(infos, &info.HisDoctorAdviceInfo)
  9741. }
  9742. if info.ProjectId > 0 && info.AdviceId == 0 {
  9743. if info.HisPrescriptionProject.Type == 3 {
  9744. var good models.DialysisBeforePrepareGoods
  9745. var newGood models.NewDialysisBeforePrepareGoods
  9746. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9747. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9748. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9749. good.Count = int64(count)
  9750. good.StorehouseId = houseConfig.StorehouseOutInfo
  9751. good.ProjectId = info.HisPrescriptionProject.ID
  9752. good.PatientId = info.PatientId
  9753. good.OrderId = order_id
  9754. goods = append(goods, &good)
  9755. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9756. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9757. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9758. newGood.Count = int64(count2)
  9759. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9760. newGood.ProjectId = info.HisPrescriptionProject.ID
  9761. newGood.RecordDate = order.SettleAccountsDate
  9762. newGood.UserOrgId = order.UserOrgId
  9763. newGood.PatientId = info.PatientId
  9764. newGood.OrderId = order_id
  9765. newGoods = append(newGoods, &newGood)
  9766. }
  9767. }
  9768. }
  9769. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9770. if settConfig.IsOpen == 1 {
  9771. for _, item := range infos {
  9772. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9773. }
  9774. for _, item := range newGoods {
  9775. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9776. }
  9777. }
  9778. c.ServeSuccessJSON(map[string]interface{}{
  9779. "msg": "退费成功",
  9780. })
  9781. }
  9782. func (c *HisApiController) RefundNumber() {
  9783. his_patient_id, _ := c.GetInt64("id")
  9784. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9785. info.Status = 0
  9786. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9787. if count > 0 {
  9788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9789. return
  9790. }
  9791. err := service.SaveHisPatient(info)
  9792. if err == nil {
  9793. c.ServeSuccessJSON(map[string]interface{}{
  9794. "msg": "退号成功",
  9795. })
  9796. } else {
  9797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9798. return
  9799. }
  9800. }
  9801. func (this *HisApiController) AdditionalCharge() {
  9802. dataBody := make(map[string]interface{}, 0)
  9803. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9804. fmt.Println(err)
  9805. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9806. patient_id := int64(dataBody["patient_id"].(float64))
  9807. medicineData, _ := dataBody["medicineData"].([]interface{})
  9808. adminUserInfo := this.GetAdminUserInfo()
  9809. orgId := adminUserInfo.CurrentOrgId
  9810. admin_user_id := adminUserInfo.AdminUser.Id
  9811. timeStr := time.Now().Format("2006-01-02")
  9812. timeLayout := "2006-01-02 15:04:05"
  9813. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9814. timenow := timeStringToTime.Unix()
  9815. var additionalCharges []*models.HisAdditionalCharge
  9816. for _, item := range medicineData {
  9817. var randNum int
  9818. randNum = rand.Intn(10000) + 1000
  9819. timestamp := time.Now().Unix()
  9820. tempTime := time.Unix(timestamp, 0)
  9821. timeFormat := tempTime.Format("20060102150405")
  9822. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9823. items := item.(map[string]interface{})
  9824. money := items["price"].(string)
  9825. item_id_str := items["item_id"].(string)
  9826. name := items["name"].(string)
  9827. id_str := items["id"].(string)
  9828. moneys, _ := strconv.ParseInt(money, 10, 64)
  9829. monStr := strconv.FormatInt(moneys, 10)
  9830. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9831. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9832. id, _ := strconv.ParseInt(id_str, 10, 64)
  9833. additionalCharge := &models.HisAdditionalCharge{
  9834. ID: id,
  9835. HisPatientId: his_patient_id,
  9836. UserOrgId: orgId,
  9837. PatientId: patient_id,
  9838. RecordDate: timenow,
  9839. Price: monneyStr,
  9840. Status: 1,
  9841. ItemName: name,
  9842. ItemId: item_id,
  9843. AdminUserId: admin_user_id,
  9844. CreatedTime: time.Now().Unix(),
  9845. OrderStatus: 0,
  9846. PrescriptionNumber: "",
  9847. BatchNumber: "",
  9848. FeedetlSn: p_number,
  9849. }
  9850. service.CreateAdditionalCharge(additionalCharge)
  9851. additionalCharges = append(additionalCharges, additionalCharge)
  9852. }
  9853. this.ServeSuccessJSON(map[string]interface{}{
  9854. "msg": "添加成功",
  9855. "additional_charges": additionalCharges,
  9856. })
  9857. }
  9858. func (this *HisApiController) DeleteAddition() {
  9859. id, _ := this.GetInt64("id")
  9860. //TODO 需要判断是否已经结算
  9861. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9862. if err == nil {
  9863. this.ServeSuccessJSON(map[string]interface{}{
  9864. "msg": "删除成功",
  9865. })
  9866. return
  9867. } else {
  9868. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9869. return
  9870. }
  9871. }
  9872. func (this *HisApiController) GetAdminUsers() {
  9873. adminUser := this.GetAdminUserInfo()
  9874. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9875. this.ServeSuccessJSON(map[string]interface{}{
  9876. "doctors": doctors,
  9877. })
  9878. }
  9879. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9880. change_type, _ := this.GetInt64("type", 0)
  9881. record_date := this.GetString("record_time")
  9882. patient_id, _ := this.GetInt64("patient_id", 0)
  9883. p_type, _ := this.GetInt64("p_type", 0)
  9884. timeLayout := "2006-01-02"
  9885. loc, _ := time.LoadLocation("Local")
  9886. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9887. record_time := theAdviceRecordTime.Unix()
  9888. adminUserInfo := this.GetAdminUserInfo()
  9889. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9890. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9891. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9892. if config.ID > 0 && config.IsOpen == 1 {
  9893. for _, subitems := range prescriptions {
  9894. for _, item := range subitems.VMHisPrescription {
  9895. for _, subItem := range item.HisDoctorAdviceInfo {
  9896. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9897. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9898. if info.RetailPrice > 0 {
  9899. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9900. subItem.Drug.RetailPrice = drug.RetailPrice
  9901. }
  9902. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9903. subItem.Drug.MinPrice = info.RetailPrice
  9904. subItem.Drug.RetailPrice = info.RetailPrice
  9905. }
  9906. }
  9907. }
  9908. }
  9909. }
  9910. }
  9911. if config.ID > 0 && config.IsOpen == 1 {
  9912. for _, subitems := range prescriptions {
  9913. for _, item := range subitems.VMHisPrescription {
  9914. for _, subItem := range item.HisPrescriptionProject {
  9915. if subItem.Type == 3 {
  9916. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9917. if info.Price > 0 {
  9918. subItem.GoodInfo.PackingPrice = info.Price
  9919. }
  9920. }
  9921. }
  9922. }
  9923. }
  9924. }
  9925. }
  9926. if err == nil {
  9927. if len(prescriptions) == 0 {
  9928. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9929. return
  9930. } else {
  9931. this.ServeSuccessJSON(map[string]interface{}{
  9932. "prescriptions": prescriptions,
  9933. })
  9934. return
  9935. }
  9936. } else {
  9937. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9938. return
  9939. }
  9940. }
  9941. func (this *HisApiController) GetCallHisPrescription() {
  9942. patient_id, _ := this.GetInt64("patient_id", 0)
  9943. timeLayout := "2006-01-02"
  9944. loc, _ := time.LoadLocation("Local")
  9945. start_time := this.GetString("start_time")
  9946. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9947. end_time := this.GetString("end_time")
  9948. p_type, _ := this.GetInt64("p_type")
  9949. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9950. adminUserInfo := this.GetAdminUserInfo()
  9951. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9952. //if
  9953. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9954. //
  9955. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9956. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9957. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9958. if config.ID > 0 && config.IsOpen == 1 {
  9959. for _, subitems := range prescriptions {
  9960. for _, item := range subitems.VMHisPrescription {
  9961. for _, subItem := range item.HisDoctorAdviceInfo {
  9962. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9963. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9964. if info.RetailPrice > 0 {
  9965. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9966. subItem.Drug.RetailPrice = drug.RetailPrice
  9967. }
  9968. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9969. subItem.Drug.MinPrice = info.RetailPrice
  9970. subItem.Drug.RetailPrice = info.RetailPrice
  9971. }
  9972. }
  9973. }
  9974. }
  9975. }
  9976. }
  9977. if config.ID > 0 && config.IsOpen == 1 {
  9978. for _, subitems := range prescriptions {
  9979. for _, item := range subitems.VMHisPrescription {
  9980. for _, subItem := range item.HisPrescriptionProject {
  9981. if subItem.Type == 3 {
  9982. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9983. if info.Price > 0 {
  9984. subItem.GoodInfo.PackingPrice = info.Price
  9985. }
  9986. }
  9987. }
  9988. }
  9989. }
  9990. }
  9991. }
  9992. if err == nil {
  9993. this.ServeSuccessJSON(map[string]interface{}{
  9994. "prescriptions": prescriptions,
  9995. })
  9996. return
  9997. } else {
  9998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9999. return
  10000. }
  10001. }
  10002. func (this *HisApiController) GetHisDayPrescription() {
  10003. timeLayout := "2006-01-02"
  10004. loc, _ := time.LoadLocation("Local")
  10005. start_time := this.GetString("start_time")
  10006. patient_id, _ := this.GetInt64("patient_id", 0)
  10007. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10008. end_time := this.GetString("end_time")
  10009. p_type, _ := this.GetInt64("p_type")
  10010. order_status, _ := this.GetInt64("type")
  10011. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10012. adminUserInfo := this.GetAdminUserInfo()
  10013. var dayHisPrescription []*models.HisPrescription
  10014. var err error
  10015. if order_status == 1 || order_status == 0 {
  10016. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10017. } else if order_status == 2 {
  10018. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10019. }
  10020. var settle_total float64
  10021. for _, item := range dayHisPrescription {
  10022. if len(item.HisPrescriptionProject) > 0 {
  10023. for _, subItem := range item.HisPrescriptionProject {
  10024. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10025. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10026. settle_total = settle_total + total
  10027. }
  10028. }
  10029. if len(item.HisDoctorAdviceInfo) > 0 {
  10030. for _, subItem := range item.HisDoctorAdviceInfo {
  10031. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10032. settle_total = settle_total + total
  10033. }
  10034. }
  10035. }
  10036. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10037. if err == nil {
  10038. this.ServeSuccessJSON(map[string]interface{}{
  10039. "day_prescription": dayHisPrescription,
  10040. "settle_total": settle_total,
  10041. })
  10042. return
  10043. } else {
  10044. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10045. return
  10046. }
  10047. }
  10048. func (c *HisApiController) GetHisChargePatientList() {
  10049. record_date := c.GetString("record_date")
  10050. order_status, _ := c.GetInt64("type")
  10051. sch_type, _ := c.GetInt64("sch_type")
  10052. timeLayout := "2006-01-02"
  10053. loc, _ := time.LoadLocation("Local")
  10054. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10055. if err != nil {
  10056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10057. return
  10058. }
  10059. recordDateTime := theTime.Unix()
  10060. adminInfo := c.GetAdminUserInfo()
  10061. var tempPatients []*service.NewTempPatients
  10062. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10063. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10064. if order_status != 2 {
  10065. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10066. } else {
  10067. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10068. }
  10069. } else {
  10070. if order_status != 2 {
  10071. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10072. } else {
  10073. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10074. }
  10075. }
  10076. var patients []*service.NewTempPatients
  10077. var patients_two []*service.NewTempPatients
  10078. for _, item := range tempPatients {
  10079. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10080. //过滤掉没挂号的和没开处方的
  10081. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10082. patients = append(patients, item)
  10083. }
  10084. //过滤掉没挂号的
  10085. if len(item.HisPatient) > 0 {
  10086. patients_two = append(patients_two, item)
  10087. }
  10088. } else {
  10089. if len(item.HisPrescription) > 0 {
  10090. patients = append(patients, item)
  10091. }
  10092. }
  10093. }
  10094. c.ServeSuccessJSON(map[string]interface{}{
  10095. "list": patients,
  10096. "list_two": patients_two,
  10097. })
  10098. }
  10099. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10100. record_date := c.GetString("record_date")
  10101. timeLayout := "2006-01-02"
  10102. loc, _ := time.LoadLocation("Local")
  10103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10104. if err != nil {
  10105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10106. return
  10107. }
  10108. recordDateTime := theTime.Unix()
  10109. adminUser := c.GetAdminUserInfo()
  10110. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10111. var patients []*service.Patients
  10112. for _, item := range tempPatients {
  10113. if item.HisPatient.ID == 0 {
  10114. patients = append(patients, item)
  10115. }
  10116. }
  10117. c.ServeSuccessJSON(map[string]interface{}{
  10118. "list": patients,
  10119. //"list_two": patients_two,
  10120. })
  10121. }
  10122. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10123. newArr = make([]*service.Patients, 0)
  10124. for i := 0; i < len(patient); i++ {
  10125. repeat := false
  10126. for j := i + 1; j < len(patient); j++ {
  10127. if patient[i].ID == patient[j].ID {
  10128. repeat = true
  10129. break
  10130. }
  10131. }
  10132. if !repeat {
  10133. newArr = append(newArr, patient[i])
  10134. }
  10135. }
  10136. return
  10137. }
  10138. func (c *HisApiController) GetHisChargePatientInfo() {
  10139. patient_id, _ := c.GetInt64("patient_id")
  10140. his_patient_id, _ := c.GetInt64("his_patient_id")
  10141. record_date := c.GetString("record_date")
  10142. //start_time := c.GetString("start_time")
  10143. //end_time := c.GetString("end_time")
  10144. order_status, _ := c.GetInt64("type", 0)
  10145. p_type, _ := c.GetInt64("p_type", 0)
  10146. order_id, _ := c.GetInt64("order_id", 0)
  10147. timeLayout := "2006-01-02"
  10148. loc, _ := time.LoadLocation("Local")
  10149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10150. if err != nil {
  10151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10152. return
  10153. }
  10154. recordDateTime := theTime.Unix()
  10155. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10156. //if err != nil {
  10157. //
  10158. //}
  10159. //startRecordDateTime := startTime.Unix()
  10160. //
  10161. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10162. //if err != nil {
  10163. //
  10164. //}
  10165. //endRecordDateTime := endTime.Unix()
  10166. admin := c.GetAdminUserInfo()
  10167. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10168. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10169. var prescriptions []*models.HisPrescription
  10170. //var unChargeMonthPrescriptions []*models.HisPrescription
  10171. order, _ := service.GetHisOrderByID(order_id)
  10172. if order_status == 1 || order_status == 0 {
  10173. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10174. } else if order_status == 2 {
  10175. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10176. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10177. }
  10178. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10179. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10180. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10181. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10182. //获取所有科室信息
  10183. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10184. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10185. c.ServeSuccessJSON(map[string]interface{}{
  10186. "his_info": his_patient_info,
  10187. "xt_info": xt_patient_info,
  10188. "prescription": prescriptions,
  10189. "case_history": case_history,
  10190. "info": patientPrescriptionInfo,
  10191. "last_info": lastPatientPrescriptionInfo,
  10192. "order": order,
  10193. "doctors": doctors,
  10194. "department": department,
  10195. "sch": sch,
  10196. })
  10197. return
  10198. }
  10199. func (c *HisApiController) GetAllOrderDetail() {
  10200. order_id, _ := c.GetInt64("id", 0)
  10201. order, _ := service.GetHisOrderByID(order_id)
  10202. if order.ID == 0 {
  10203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10204. return
  10205. }
  10206. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10207. org_id := c.GetAdminUserInfo().CurrentOrgId
  10208. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10209. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10210. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10211. c.ServeSuccessJSON(map[string]interface{}{
  10212. "order": order,
  10213. "order_info": order_info,
  10214. "patient": patient,
  10215. "admin_info": adminInfo,
  10216. "hospital_record": record,
  10217. })
  10218. return
  10219. }
  10220. func (c *HisApiController) GetAllOrderDetailCollect() {
  10221. order_id, _ := c.GetInt64("id", 0)
  10222. order, _ := service.GetHisOrderByID(order_id)
  10223. if order.ID == 0 {
  10224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10225. return
  10226. }
  10227. org_id := c.GetAdminUserInfo().CurrentOrgId
  10228. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10229. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10230. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10231. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10232. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10233. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10234. var bedCostTotal float64 = 0 //床位总费
  10235. //var bedCostSelfTotal float64 = 0 //床位自费
  10236. var operationCostTotal float64 = 0 //手术费
  10237. //var operationCostSelfTotal float64 = 0 //手术费
  10238. var otherCostTotal float64 = 0 //其他费用
  10239. //var otherCostSelfTotal float64 = 0 //其他费用
  10240. var materialCostTotal float64 = 0 //材料费
  10241. //var materialCostSelfTotal float64 = 0 //材料费
  10242. var westernMedicineCostTotal float64 = 0 //西药费
  10243. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10244. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10245. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10246. var checkCostTotal float64 = 0 //检查费
  10247. //var checkCostSelfTotal float64 = 0 //检查费
  10248. var laboratoryCostTotal float64 = 0 //化验费
  10249. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10250. var treatCostTotal float64 = 0 //治疗费用
  10251. //var treatCostSelfTotal float64 = 0 //治疗费用
  10252. var zhenChaCostTotal float64 = 0 //其他费用
  10253. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10254. decimal.DivisionPrecision = 2
  10255. var BalanceAccountsType int64
  10256. if his.ID > 0 {
  10257. BalanceAccountsType = his.BalanceAccountsType
  10258. } else {
  10259. BalanceAccountsType = record.BalanceAccountsType
  10260. }
  10261. if BalanceAccountsType != 2 {
  10262. for _, item := range order_info {
  10263. if org_id == 10215 {
  10264. if item.MedChrgitmType == "01" { //床位费
  10265. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10266. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10267. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10268. }
  10269. if item.MedChrgitmType == "02" { //诊察费
  10270. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10271. //zhenChaCostSelfTotal = zhenChaCostTotal
  10272. }
  10273. if item.MedChrgitmType == "03" { //检查费
  10274. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10275. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10276. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10277. }
  10278. //if item.MedChrgitmType == "02" { //检查费
  10279. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10280. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10281. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10282. //}
  10283. if item.MedChrgitmType == "04" { //化验费
  10284. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10285. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10286. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10287. }
  10288. if item.MedChrgitmType == "05" { //治疗费
  10289. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10290. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10291. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10292. }
  10293. if item.MedChrgitmType == "06" { //手术费
  10294. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10295. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10296. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10297. }
  10298. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10299. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10300. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10301. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10302. }
  10303. if item.MedChrgitmType == "09" { //西药费
  10304. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10305. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10306. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10307. }
  10308. if item.MedChrgitmType == "11" { //中成费
  10309. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10310. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10311. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10312. }
  10313. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10314. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10315. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10316. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10317. }
  10318. } else if org_id == 10188 || org_id == 10217 {
  10319. if item.MedChrgitmType == "01" { //床位费
  10320. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10321. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10322. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10323. }
  10324. if item.MedChrgitmType == "02" { //诊察费
  10325. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10326. //zhenChaCostSelfTotal = zhenChaCostTotal
  10327. }
  10328. if item.MedChrgitmType == "03" { //检查费
  10329. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10330. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10331. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10332. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10333. }
  10334. //if item.MedChrgitmType == "02" { //检查费
  10335. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10336. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10337. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10338. //}
  10339. if item.MedChrgitmType == "04" { //化验费
  10340. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10341. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10342. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10343. }
  10344. if item.MedChrgitmType == "05" { //治疗费
  10345. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10346. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10347. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10348. }
  10349. if item.MedChrgitmType == "06" { //手术费
  10350. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10351. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10352. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10353. }
  10354. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10355. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10356. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10357. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10358. }
  10359. if item.MedChrgitmType == "09" { //西药费
  10360. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10361. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10362. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10363. }
  10364. if item.MedChrgitmType == "11" { //中成费
  10365. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10366. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10367. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10368. }
  10369. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10370. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10371. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10372. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10373. }
  10374. } else {
  10375. if item.MedChrgitmType == "01" { //床位费
  10376. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10377. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10378. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10379. }
  10380. //if item.MedChrgitmType == "02" { //诊察费
  10381. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10382. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10383. //}
  10384. if item.MedChrgitmType == "03" { //检查费
  10385. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10386. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10387. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10388. }
  10389. //if item.MedChrgitmType == "02" { //检查费
  10390. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10391. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10392. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10393. //}
  10394. if item.MedChrgitmType == "04" { //化验费
  10395. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10396. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10397. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10398. }
  10399. if item.MedChrgitmType == "05" { //治疗费
  10400. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10401. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10402. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10403. }
  10404. if item.MedChrgitmType == "06" { //手术费
  10405. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10406. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10407. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10408. }
  10409. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10410. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10411. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10412. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10413. }
  10414. if item.MedChrgitmType == "09" { //西药费
  10415. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10416. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10417. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10418. }
  10419. if item.MedChrgitmType == "11" { //中成费
  10420. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10421. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10422. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10423. }
  10424. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10425. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10426. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10427. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10428. }
  10429. }
  10430. }
  10431. c.ServeSuccessJSON(map[string]interface{}{
  10432. "order": order,
  10433. "order_info": order_info,
  10434. "patient": patient,
  10435. "admin_info": adminInfo,
  10436. "his_hospital": record,
  10437. "bedCostTotal": bedCostTotal,
  10438. "operationCostTotal": operationCostTotal,
  10439. "otherCostTotal": otherCostTotal,
  10440. "materialCostTotal": materialCostTotal,
  10441. "westernMedicineCostTotal": westernMedicineCostTotal,
  10442. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10443. "checkCostTotal": checkCostTotal,
  10444. "zhenChaCostTotal": zhenChaCostTotal,
  10445. "laboratoryCostTotal": laboratoryCostTotal,
  10446. "treatCostTotal": treatCostTotal,
  10447. })
  10448. } else {
  10449. for _, item := range order_info {
  10450. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10451. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10452. item.MedChrgitmType = "09"
  10453. }
  10454. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10455. if item.HisPrescriptionProject.Type == 2 {
  10456. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10457. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10458. case 0:
  10459. item.MedChrgitmType = "0"
  10460. break
  10461. case 1:
  10462. item.MedChrgitmType = "14"
  10463. break
  10464. case 2:
  10465. item.MedChrgitmType = "05"
  10466. break
  10467. case 3:
  10468. item.MedChrgitmType = "03"
  10469. break
  10470. case 4:
  10471. item.MedChrgitmType = "03"
  10472. break
  10473. case 5:
  10474. item.MedChrgitmType = "08"
  10475. break
  10476. case 6:
  10477. item.MedChrgitmType = "14"
  10478. break
  10479. case 7:
  10480. item.MedChrgitmType = "14"
  10481. break
  10482. case 8:
  10483. item.MedChrgitmType = "03"
  10484. break
  10485. case 9:
  10486. item.MedChrgitmType = "14"
  10487. break
  10488. case 10:
  10489. item.MedChrgitmType = "14"
  10490. break
  10491. case 11:
  10492. item.MedChrgitmType = "06"
  10493. break
  10494. case 12:
  10495. item.MedChrgitmType = "12"
  10496. break
  10497. case 13:
  10498. item.MedChrgitmType = "01"
  10499. break
  10500. case 14:
  10501. item.MedChrgitmType = "04"
  10502. break
  10503. case 15:
  10504. item.MedChrgitmType = "14"
  10505. break
  10506. }
  10507. } else {
  10508. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10509. case 1:
  10510. item.MedChrgitmType = "14"
  10511. break
  10512. case 2:
  10513. item.MedChrgitmType = "05"
  10514. break
  10515. case 3:
  10516. item.MedChrgitmType = "04"
  10517. break
  10518. case 4:
  10519. item.MedChrgitmType = "14"
  10520. break
  10521. case 5:
  10522. item.MedChrgitmType = "08"
  10523. break
  10524. case 6:
  10525. item.MedChrgitmType = "14"
  10526. break
  10527. case 7:
  10528. item.MedChrgitmType = "14"
  10529. break
  10530. case 8:
  10531. item.MedChrgitmType = "03"
  10532. break
  10533. case 9:
  10534. item.MedChrgitmType = "14"
  10535. break
  10536. }
  10537. }
  10538. } else if item.HisPrescriptionProject.Type == 3 {
  10539. item.MedChrgitmType = "08"
  10540. }
  10541. }
  10542. }
  10543. for _, item := range order_info {
  10544. if org_id == 10215 {
  10545. if item.MedChrgitmType == "01" { //床位费
  10546. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10547. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10548. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10549. }
  10550. if item.MedChrgitmType == "02" { //诊察费
  10551. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10552. //zhenChaCostSelfTotal = zhenChaCostTotal
  10553. }
  10554. if item.MedChrgitmType == "03" { //检查费
  10555. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10556. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10557. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10558. }
  10559. //if item.MedChrgitmType == "02" { //检查费
  10560. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10561. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10562. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10563. //}
  10564. if item.MedChrgitmType == "04" { //化验费
  10565. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10566. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10567. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10568. }
  10569. if item.MedChrgitmType == "05" { //治疗费
  10570. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10571. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10572. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10573. }
  10574. if item.MedChrgitmType == "06" { //手术费
  10575. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10576. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10577. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10578. }
  10579. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10580. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10581. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10582. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10583. }
  10584. if item.MedChrgitmType == "09" { //西药费
  10585. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10586. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10587. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10588. }
  10589. if item.MedChrgitmType == "11" { //中成费
  10590. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10591. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10592. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10593. }
  10594. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10595. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10596. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10597. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10598. }
  10599. } else {
  10600. if item.MedChrgitmType == "01" { //床位费
  10601. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10602. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10603. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10604. }
  10605. //if item.MedChrgitmType == "02" { //诊察费
  10606. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10607. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10608. //}
  10609. if item.MedChrgitmType == "03" { //检查费
  10610. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10611. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10612. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10613. }
  10614. //if item.MedChrgitmType == "02" { //检查费
  10615. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10616. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10617. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10618. //}
  10619. if item.MedChrgitmType == "04" { //化验费
  10620. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10621. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10622. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10623. }
  10624. if item.MedChrgitmType == "05" { //治疗费
  10625. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10626. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10627. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10628. }
  10629. if item.MedChrgitmType == "06" { //手术费
  10630. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10631. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10632. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10633. }
  10634. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10635. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10636. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10637. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10638. }
  10639. if item.MedChrgitmType == "09" { //西药费
  10640. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10641. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10642. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10643. }
  10644. if item.MedChrgitmType == "11" { //中成费
  10645. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10646. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10647. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10648. }
  10649. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10650. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10651. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10652. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10653. }
  10654. }
  10655. }
  10656. c.ServeSuccessJSON(map[string]interface{}{
  10657. "order": order,
  10658. "order_info": order_info,
  10659. "patient": patient,
  10660. "admin_info": adminInfo,
  10661. "his_hospital": record,
  10662. "bedCostTotal": bedCostTotal,
  10663. "operationCostTotal": operationCostTotal,
  10664. "otherCostTotal": otherCostTotal,
  10665. "materialCostTotal": materialCostTotal,
  10666. "westernMedicineCostTotal": westernMedicineCostTotal,
  10667. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10668. "checkCostTotal": checkCostTotal,
  10669. "zhenChaCostTotal": zhenChaCostTotal,
  10670. "laboratoryCostTotal": laboratoryCostTotal,
  10671. "treatCostTotal": treatCostTotal,
  10672. })
  10673. }
  10674. }
  10675. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10676. page, _ := c.GetInt64("page")
  10677. limit, _ := c.GetInt64("limit")
  10678. keywords := c.GetString("keywords")
  10679. start_time := c.GetString("start_time")
  10680. end_time := c.GetString("end_time")
  10681. //clr_type := c.GetString("clr_type")
  10682. insutype := c.GetString("insutype")
  10683. timeLayout := "2006-01-02"
  10684. loc, _ := time.LoadLocation("Local")
  10685. var theStartTIme int64
  10686. if len(start_time) > 0 {
  10687. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10688. theStartTIme = theTime.Unix()
  10689. }
  10690. var theEndtTIme int64
  10691. if len(end_time) > 0 {
  10692. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10693. theEndtTIme = theTime.Unix()
  10694. }
  10695. if page <= 0 {
  10696. page = 1
  10697. }
  10698. if limit <= 0 {
  10699. limit = 10
  10700. }
  10701. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10702. c.ServeSuccessJSON(map[string]interface{}{
  10703. "total": total,
  10704. "list": list,
  10705. })
  10706. return
  10707. }
  10708. func (c *HisApiController) GetPutOnRecordList() {
  10709. page, _ := c.GetInt64("page")
  10710. limit, _ := c.GetInt64("limit")
  10711. keywords := c.GetString("keywords")
  10712. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10713. if page <= 0 {
  10714. page = 1
  10715. }
  10716. if limit <= 0 {
  10717. limit = 10
  10718. }
  10719. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10720. c.ServeSuccessJSON(map[string]interface{}{
  10721. "total": total,
  10722. "list": list,
  10723. })
  10724. return
  10725. }
  10726. func (c *HisApiController) GetCompareData() {
  10727. start_time := c.GetString("start_time")
  10728. end_time := c.GetString("end_time")
  10729. insutype := c.GetString("insutype")
  10730. clr_type := c.GetString("clr_type")
  10731. timeLayout := "2006-01-02"
  10732. loc, _ := time.LoadLocation("Local")
  10733. var theStartTIme int64
  10734. if len(start_time) > 0 {
  10735. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10736. if err != nil {
  10737. theStartTIme = 0
  10738. }
  10739. theStartTIme = theTime.Unix()
  10740. }
  10741. var theEndtTIme int64
  10742. if len(end_time) > 0 {
  10743. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10744. if err != nil {
  10745. theEndtTIme = 0
  10746. }
  10747. theEndtTIme = theTime.Unix()
  10748. }
  10749. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10750. fmt.Println(err)
  10751. if err == nil {
  10752. c.ServeSuccessJSON(map[string]interface{}{
  10753. "list": formData,
  10754. })
  10755. } else {
  10756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10757. return
  10758. }
  10759. }
  10760. func (c *HisApiController) GetFaPiaoData() {
  10761. order_id, _ := c.GetInt64("order_id")
  10762. patient_id, _ := c.GetInt64("patient_id")
  10763. //number := c.GetString("number")
  10764. adminUser := c.GetAdminUserInfo()
  10765. order, _ := service.GetHisOrderByID(order_id)
  10766. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10767. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10768. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10769. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10770. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10771. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10772. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10773. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10774. var bedCostTotal float64 = 0 //床位总费
  10775. var bedCostSelfTotal float64 = 0 //床位自费
  10776. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10777. var operationCostTotal float64 = 0 //手术费
  10778. var operationCostSelfTotal float64 = 0 //手术费
  10779. var operationCostPartSelfTotal float64 = 0 //手术费
  10780. var otherCostTotal float64 = 0 //其他费用
  10781. var otherCostSelfTotal float64 = 0 //其他费用
  10782. var otherCostPartSelfTotal float64 = 0 //其他费用
  10783. var materialCostTotal float64 = 0 //材料费
  10784. var materialCostSelfTotal float64 = 0 //材料费
  10785. var materialCostPartSelfTotal float64 = 0 //材料费
  10786. var westernMedicineCostTotal float64 = 0 //西药费
  10787. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10788. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10789. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10790. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10791. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10792. var checkCostTotal float64 = 0 //检查费
  10793. var checkCostSelfTotal float64 = 0 //检查费
  10794. var checkCostPartSelfTotal float64 = 0 //检查费
  10795. var hiliCostTotal float64 = 0 //护理费
  10796. var hiliCostSelfTotal float64 = 0 //护理费
  10797. var hiliCostPartSelfTotal float64 = 0 //护理费
  10798. var laboratoryCostTotal float64 = 0 //化验费
  10799. var laboratoryCostSelfTotal float64 = 0 //化验费
  10800. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10801. var treatCostTotal float64 = 0 //治疗费用
  10802. var treatCostSelfTotal float64 = 0 //治疗费用
  10803. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10804. var zhenChaCostTotal float64 = 0 //其他费用
  10805. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10806. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10807. decimal.DivisionPrecision = 2
  10808. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10809. var balanceAccountsType int64
  10810. if his.ID > 0 {
  10811. balanceAccountsType = his.BalanceAccountsType
  10812. } else {
  10813. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10814. }
  10815. if balanceAccountsType == 2 {
  10816. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10817. for _, item := range orderInfos_two {
  10818. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10819. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10820. item.MedChrgitmType = "09"
  10821. }
  10822. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10823. if item.HisPrescriptionProject.Type == 2 {
  10824. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10825. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10826. case 0:
  10827. item.MedChrgitmType = "0"
  10828. break
  10829. case 1:
  10830. item.MedChrgitmType = "14"
  10831. break
  10832. case 2:
  10833. item.MedChrgitmType = "05"
  10834. break
  10835. case 3:
  10836. item.MedChrgitmType = "03"
  10837. break
  10838. case 4:
  10839. item.MedChrgitmType = "03"
  10840. break
  10841. case 5:
  10842. item.MedChrgitmType = "08"
  10843. break
  10844. case 6:
  10845. item.MedChrgitmType = "14"
  10846. break
  10847. case 7:
  10848. item.MedChrgitmType = "14"
  10849. break
  10850. case 8:
  10851. item.MedChrgitmType = "03"
  10852. break
  10853. case 9:
  10854. item.MedChrgitmType = "14"
  10855. break
  10856. case 10:
  10857. item.MedChrgitmType = "14"
  10858. break
  10859. case 11:
  10860. item.MedChrgitmType = "06"
  10861. break
  10862. case 12:
  10863. item.MedChrgitmType = "12"
  10864. break
  10865. case 13:
  10866. item.MedChrgitmType = "01"
  10867. break
  10868. case 14:
  10869. item.MedChrgitmType = "04"
  10870. break
  10871. case 15:
  10872. item.MedChrgitmType = "02"
  10873. break
  10874. }
  10875. } else {
  10876. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10877. case 1:
  10878. item.MedChrgitmType = "14"
  10879. break
  10880. case 2:
  10881. item.MedChrgitmType = "05"
  10882. break
  10883. case 3:
  10884. item.MedChrgitmType = "04"
  10885. break
  10886. case 4:
  10887. item.MedChrgitmType = "03"
  10888. break
  10889. case 5:
  10890. item.MedChrgitmType = "08"
  10891. break
  10892. case 6:
  10893. item.MedChrgitmType = "14"
  10894. break
  10895. case 7:
  10896. item.MedChrgitmType = "14"
  10897. break
  10898. case 8:
  10899. item.MedChrgitmType = "03"
  10900. break
  10901. case 9:
  10902. item.MedChrgitmType = "14"
  10903. break
  10904. }
  10905. }
  10906. } else if item.HisPrescriptionProject.Type == 3 {
  10907. item.MedChrgitmType = "08"
  10908. }
  10909. }
  10910. }
  10911. for _, item := range orderInfos_two {
  10912. fmt.Println(item.MedChrgitmType)
  10913. if item.MedChrgitmType == "07" { //床位费
  10914. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10915. hiliCostSelfTotal = hiliCostTotal
  10916. }
  10917. if item.MedChrgitmType == "01" { //床位费
  10918. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10919. bedCostSelfTotal = bedCostTotal
  10920. }
  10921. if item.MedChrgitmType == "02" { //诊察费
  10922. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10923. zhenChaCostSelfTotal = zhenChaCostTotal
  10924. }
  10925. if item.MedChrgitmType == "03" { //检查费
  10926. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10927. checkCostSelfTotal = checkCostTotal
  10928. }
  10929. if item.MedChrgitmType == "04" { //化验费
  10930. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10931. laboratoryCostSelfTotal = laboratoryCostTotal
  10932. }
  10933. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10934. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10935. treatCostSelfTotal = treatCostTotal
  10936. }
  10937. if item.MedChrgitmType == "06" { //手术费
  10938. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10939. operationCostSelfTotal = treatCostTotal
  10940. }
  10941. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10942. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10943. materialCostSelfTotal = materialCostTotal
  10944. }
  10945. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10946. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10947. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10948. }
  10949. if item.MedChrgitmType == "11" { //中成费
  10950. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10951. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10952. }
  10953. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10954. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10955. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10956. otherCostSelfTotal = otherCostTotal
  10957. }
  10958. } else {
  10959. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10960. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10961. otherCostSelfTotal = otherCostTotal
  10962. }
  10963. }
  10964. }
  10965. } else {
  10966. for _, item := range orderInfos {
  10967. if item.MedChrgitmType == "01" { //床位费
  10968. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10969. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10970. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10971. }
  10972. if item.MedChrgitmType == "02" { //诊察费
  10973. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10974. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10975. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10976. }
  10977. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10978. if item.MedChrgitmType == "03" { //检查费
  10979. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10980. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10981. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10982. }
  10983. } else {
  10984. if item.MedChrgitmType == "03" { //检查费
  10985. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10986. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10987. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10988. }
  10989. }
  10990. if item.MedChrgitmType == "04" { //化验费
  10991. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10992. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10993. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10994. }
  10995. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10996. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10997. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10998. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10999. }
  11000. if item.MedChrgitmType == "06" { //手术费
  11001. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11002. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11003. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11004. }
  11005. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11006. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11007. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11008. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11009. }
  11010. if item.MedChrgitmType == "07" { //护理
  11011. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11012. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11013. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11014. }
  11015. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11016. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11017. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11018. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11019. }
  11020. if item.MedChrgitmType == "11" { //中成费
  11021. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11022. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11023. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11024. }
  11025. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11026. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11027. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11028. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11029. }
  11030. }
  11031. }
  11032. timeLayout := "2006-01-02"
  11033. loc, _ := time.LoadLocation("Local")
  11034. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11035. if err != nil {
  11036. }
  11037. startRecordDateTime := startTime.Unix()
  11038. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11039. if err != nil {
  11040. }
  11041. endRecordDateTime := endTime.Unix()
  11042. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11043. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11044. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11045. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11046. c.ServeSuccessJSON(map[string]interface{}{
  11047. "charge_admin_name": charge_admin.UserName,
  11048. "order_number": order.Number, //业务流水号
  11049. "id_card_no": his.IdCardNo, //社会保障号
  11050. "patient": patient,
  11051. "department_name": department.Name, //科室
  11052. "number": his.Number, //门诊号
  11053. "date": order.SettleAccountsDate, //结算日期
  11054. "name": order.PsnName, //姓名
  11055. "gender": patient.Gender, //性别
  11056. "psn_cash_money": order.PsnCashPay, //个人支付
  11057. "pay_way": "门诊", //结算方式
  11058. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11059. "admin_user_name": admin.UserName, //收款员
  11060. "order": order,
  11061. "order_info": orderInfos_two,
  11062. "his": his,
  11063. "bedCostTotal": bedCostTotal,
  11064. "bedCostSelfTotal": bedCostSelfTotal,
  11065. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11066. "operationCostTotal": operationCostTotal,
  11067. "operationCostSelfTotal": operationCostSelfTotal,
  11068. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11069. "otherCostTotal": otherCostTotal,
  11070. "otherCostSelfTotal": otherCostSelfTotal,
  11071. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11072. "materialCostTotal": materialCostTotal,
  11073. "materialCostSelfTotal": materialCostSelfTotal,
  11074. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11075. "westernMedicineCostTotal": westernMedicineCostTotal,
  11076. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11077. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11078. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11079. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11080. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11081. "checkCostTotal": checkCostTotal,
  11082. "checkCostSelfTotal": checkCostSelfTotal,
  11083. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11084. "laboratoryCostTotal": laboratoryCostTotal,
  11085. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11086. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11087. "treatCostTotal": treatCostTotal,
  11088. "treatCostSelfTotal": treatCostSelfTotal,
  11089. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11090. "zhenChaCostTotal": zhenChaCostTotal,
  11091. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11092. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11093. "his_hospital_record": his_hospital_record,
  11094. "pre_pay_money": pre_pay_money,
  11095. "refund_sum": sum,
  11096. "doctor_info": doctor_info,
  11097. "hiliCostTotal": hiliCostTotal,
  11098. "hiliCostSelfTotal": hiliCostSelfTotal,
  11099. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11100. })
  11101. }
  11102. //func (c *HisApiController) GetFaPiaoDatas() {
  11103. // order_ids := c.GetString("order_ids")
  11104. // patient_id, _ := c.GetInt64("patient_id")
  11105. // adminUser := c.GetAdminUserInfo()
  11106. //
  11107. // orders := strings.Split(order_ids, ",")
  11108. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11109. //
  11110. // for _, item := range orders {
  11111. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11112. // order, _ := service.GetHisOrderByID(order_id)
  11113. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11114. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11115. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11116. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11117. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11118. //
  11119. // }
  11120. //
  11121. // var bedCostTotal float64 = 0 //床位总费
  11122. // var bedCostSelfTotal float64 = 0 //床位自费
  11123. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11124. //
  11125. // var operationCostTotal float64 = 0 //手术费
  11126. // var operationCostSelfTotal float64 = 0 //手术费
  11127. // var operationCostPartSelfTotal float64 = 0 //手术费
  11128. //
  11129. // var otherCostTotal float64 = 0 //其他费用
  11130. // var otherCostSelfTotal float64 = 0 //其他费用
  11131. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11132. //
  11133. // var materialCostTotal float64 = 0 //材料费
  11134. // var materialCostSelfTotal float64 = 0 //材料费
  11135. // var materialCostPartSelfTotal float64 = 0 //材料费
  11136. //
  11137. // var westernMedicineCostTotal float64 = 0 //西药费
  11138. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11139. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11140. //
  11141. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11142. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11143. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11144. //
  11145. // var checkCostTotal float64 = 0 //检查费
  11146. // var checkCostSelfTotal float64 = 0 //检查费
  11147. // var checkCostPartSelfTotal float64 = 0 //检查费
  11148. //
  11149. // var laboratoryCostTotal float64 = 0 //化验费
  11150. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11151. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11152. //
  11153. // var treatCostTotal float64 = 0 //治疗费用
  11154. // var treatCostSelfTotal float64 = 0 //治疗费用
  11155. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11156. //
  11157. // var zhenChaCostTotal float64 = 0 //其他费用
  11158. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11159. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11160. //
  11161. // decimal.DivisionPrecision = 2
  11162. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11163. //
  11164. // var balanceAccountsType int64
  11165. // if his.ID > 0 {
  11166. // balanceAccountsType = his.BalanceAccountsType
  11167. // } else {
  11168. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11169. // }
  11170. // if balanceAccountsType == 2 {
  11171. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11172. // for _, item := range orderInfos_two {
  11173. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11174. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11175. // item.MedChrgitmType = "09"
  11176. // }
  11177. //
  11178. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11179. // if item.HisPrescriptionProject.Type == 2 {
  11180. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11181. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11182. // case 0:
  11183. // item.MedChrgitmType = "0"
  11184. // break
  11185. // case 1:
  11186. // item.MedChrgitmType = "14"
  11187. // break
  11188. // case 2:
  11189. // item.MedChrgitmType = "05"
  11190. //
  11191. // break
  11192. // case 3:
  11193. // item.MedChrgitmType = "03"
  11194. //
  11195. // break
  11196. // case 4:
  11197. // item.MedChrgitmType = "03"
  11198. //
  11199. // break
  11200. // case 5:
  11201. // item.MedChrgitmType = "08"
  11202. //
  11203. // break
  11204. // case 6:
  11205. // item.MedChrgitmType = "14"
  11206. //
  11207. // break
  11208. // case 7:
  11209. // item.MedChrgitmType = "14"
  11210. //
  11211. // break
  11212. // case 8:
  11213. // item.MedChrgitmType = "03"
  11214. // break
  11215. // case 9:
  11216. // item.MedChrgitmType = "14"
  11217. // break
  11218. // case 10:
  11219. // item.MedChrgitmType = "14"
  11220. // break
  11221. // case 11:
  11222. // item.MedChrgitmType = "06"
  11223. // break
  11224. // case 12:
  11225. // item.MedChrgitmType = "12"
  11226. // break
  11227. // case 13:
  11228. // item.MedChrgitmType = "01"
  11229. // break
  11230. // case 14:
  11231. // item.MedChrgitmType = "04"
  11232. // break
  11233. // case 15:
  11234. // item.MedChrgitmType = "02"
  11235. // break
  11236. //
  11237. // }
  11238. //
  11239. // } else {
  11240. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11241. //
  11242. // case 1:
  11243. // item.MedChrgitmType = "14"
  11244. // break
  11245. // case 2:
  11246. // item.MedChrgitmType = "05"
  11247. //
  11248. // break
  11249. // case 3:
  11250. // item.MedChrgitmType = "03"
  11251. //
  11252. // break
  11253. // case 4:
  11254. // item.MedChrgitmType = "03"
  11255. //
  11256. // break
  11257. // case 5:
  11258. // item.MedChrgitmType = "08"
  11259. //
  11260. // break
  11261. // case 6:
  11262. // item.MedChrgitmType = "14"
  11263. //
  11264. // break
  11265. // case 7:
  11266. // item.MedChrgitmType = "14"
  11267. //
  11268. // break
  11269. // case 8:
  11270. // item.MedChrgitmType = "03"
  11271. // break
  11272. // case 9:
  11273. // item.MedChrgitmType = "14"
  11274. // break
  11275. //
  11276. // }
  11277. //
  11278. // }
  11279. //
  11280. // } else if item.HisPrescriptionProject.Type == 3 {
  11281. // item.MedChrgitmType = "08"
  11282. // }
  11283. // }
  11284. // }
  11285. //
  11286. // for _, item := range orderInfos_two {
  11287. // fmt.Println(item.MedChrgitmType)
  11288. // if item.MedChrgitmType == "01" { //床位费
  11289. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11290. // bedCostSelfTotal = bedCostTotal
  11291. // }
  11292. //
  11293. // if item.MedChrgitmType == "02" { //诊察费
  11294. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11295. // zhenChaCostSelfTotal = zhenChaCostTotal
  11296. // }
  11297. //
  11298. // if item.MedChrgitmType == "03" { //检查费
  11299. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11300. // checkCostSelfTotal = checkCostTotal
  11301. // }
  11302. //
  11303. // if item.MedChrgitmType == "04" { //化验费
  11304. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11305. // laboratoryCostSelfTotal = laboratoryCostTotal
  11306. // }
  11307. //
  11308. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11309. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11310. // treatCostSelfTotal = treatCostTotal
  11311. // }
  11312. //
  11313. // if item.MedChrgitmType == "06" { //手术费
  11314. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11315. // operationCostSelfTotal = treatCostTotal
  11316. // }
  11317. //
  11318. // if item.MedChrgitmType == "08" { //材料费
  11319. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11320. // materialCostSelfTotal = materialCostTotal
  11321. // }
  11322. //
  11323. // if item.MedChrgitmType == "09" { //西药费
  11324. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11325. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11326. // }
  11327. //
  11328. // if item.MedChrgitmType == "11" { //中成费
  11329. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11330. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11331. // }
  11332. //
  11333. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11334. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11335. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11336. // otherCostSelfTotal = otherCostTotal
  11337. // }
  11338. // } else {
  11339. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11340. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11341. // otherCostSelfTotal = otherCostTotal
  11342. // }
  11343. //
  11344. // }
  11345. //
  11346. // }
  11347. //
  11348. // } else {
  11349. // for _, item := range orderInfos {
  11350. // if item.MedChrgitmType == "01" { //床位费
  11351. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11352. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11353. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11354. // }
  11355. //
  11356. // if item.MedChrgitmType == "02" { //诊察费
  11357. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11358. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11359. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11360. // }
  11361. //
  11362. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11363. // if item.MedChrgitmType == "03" { //检查费
  11364. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11365. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11366. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11367. //
  11368. // }
  11369. // } else {
  11370. // if item.MedChrgitmType == "03" { //检查费
  11371. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11372. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11373. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11374. // }
  11375. //
  11376. // }
  11377. //
  11378. // if item.MedChrgitmType == "04" { //化验费
  11379. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11380. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11381. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11382. //
  11383. // }
  11384. //
  11385. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11386. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11387. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11388. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11389. //
  11390. // }
  11391. //
  11392. // if item.MedChrgitmType == "06" { //手术费
  11393. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11394. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11395. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11396. // }
  11397. //
  11398. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11399. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11400. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11401. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11402. // }
  11403. //
  11404. // if item.MedChrgitmType == "09" { //西药费
  11405. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11406. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11407. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11408. // }
  11409. //
  11410. // if item.MedChrgitmType == "11" { //中成费
  11411. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11412. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11413. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11414. // }
  11415. //
  11416. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11417. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11418. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11419. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11420. // }
  11421. //
  11422. // }
  11423. // }
  11424. // timeLayout := "2006-01-02"
  11425. // loc, _ := time.LoadLocation("Local")
  11426. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11427. // if err != nil {
  11428. // }
  11429. // startRecordDateTime := startTime.Unix()
  11430. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11431. // if err != nil {
  11432. // }
  11433. // endRecordDateTime := endTime.Unix()
  11434. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11435. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11436. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11437. //
  11438. // c.ServeSuccessJSON(map[string]interface{}{
  11439. // "order_number": order.Number, //业务流水号
  11440. // "id_card_no": his.IdCardNo, //社会保障号
  11441. // "department_name": department.Name, //科室
  11442. // "number": his.Number, //门诊号
  11443. // "date": order.SettleAccountsDate, //结算日期
  11444. // "name": order.PsnName, //姓名
  11445. // "gender": patient.Gender, //性别
  11446. // "psn_cash_money": order.PsnCashPay, //个人支付
  11447. // "pay_way": "门诊", //结算方式
  11448. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11449. // "admin_user_name": admin.UserName, //收款员
  11450. // "order": order,
  11451. // "order_info": orderInfos_two,
  11452. // "his": his,
  11453. // "bedCostTotal": bedCostTotal,
  11454. // "bedCostSelfTotal": bedCostSelfTotal,
  11455. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11456. // "operationCostTotal": operationCostTotal,
  11457. // "operationCostSelfTotal": operationCostSelfTotal,
  11458. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11459. // "otherCostTotal": otherCostTotal,
  11460. // "otherCostSelfTotal": otherCostSelfTotal,
  11461. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11462. // "materialCostTotal": materialCostTotal,
  11463. // "materialCostSelfTotal": materialCostSelfTotal,
  11464. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11465. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11466. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11467. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11468. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11469. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11470. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11471. // "checkCostTotal": checkCostTotal,
  11472. // "checkCostSelfTotal": checkCostSelfTotal,
  11473. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11474. // "laboratoryCostTotal": laboratoryCostTotal,
  11475. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11476. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11477. // "treatCostTotal": treatCostTotal,
  11478. // "treatCostSelfTotal": treatCostSelfTotal,
  11479. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11480. // "zhenChaCostTotal": zhenChaCostTotal,
  11481. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11482. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11483. // "his_hospital_record": his_hospital_record,
  11484. // "pre_pay_money": pre_pay_money,
  11485. // "refund_sum": sum,
  11486. // })
  11487. //
  11488. //}
  11489. func (this *HisApiController) GetIncomeStatisticsData() {
  11490. start_time := this.GetString("start_time")
  11491. end_time := this.GetString("end_time")
  11492. key_words := this.GetString("key_words")
  11493. limit, _ := this.GetInt64("limit")
  11494. page, _ := this.GetInt64("page")
  11495. if page <= 0 {
  11496. page = 1
  11497. }
  11498. if limit <= 0 {
  11499. limit = 10
  11500. }
  11501. statistics_type, _ := this.GetInt64("statistics_type")
  11502. admin := this.GetAdminUserInfo()
  11503. timeLayout := "2006-01-02"
  11504. loc, _ := time.LoadLocation("Local")
  11505. var theStartTIme int64
  11506. if len(start_time) > 0 {
  11507. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11508. if err != nil {
  11509. theStartTIme = 0
  11510. }
  11511. theStartTIme = theTime.Unix()
  11512. }
  11513. var theEndtTIme int64
  11514. if len(end_time) > 0 {
  11515. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11516. if err != nil {
  11517. theEndtTIme = 0
  11518. }
  11519. theEndtTIme = theTime.Unix()
  11520. }
  11521. if statistics_type == 1 {
  11522. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11523. this.ServeSuccessJSON(map[string]interface{}{
  11524. "list": list,
  11525. "total": total,
  11526. })
  11527. } else {
  11528. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11529. this.ServeSuccessJSON(map[string]interface{}{
  11530. "list": list,
  11531. "total": total,
  11532. })
  11533. }
  11534. }
  11535. func (c *HisApiController) PostProjectInformation() {
  11536. adminUser := c.GetAdminUserInfo()
  11537. orgId := adminUser.CurrentOrgId
  11538. dataBody := make(map[string]interface{}, 0)
  11539. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11540. if err != nil {
  11541. utils.ErrorLog(err.Error())
  11542. return
  11543. }
  11544. utils.ErrorLog("%v", dataBody)
  11545. var projectList []*models.HisProject
  11546. var total_goods []interface{}
  11547. tempProjects := dataBody["projects"].([]interface{})
  11548. total_goods = tempProjects
  11549. for index, projectMap := range tempProjects {
  11550. projectM := projectMap.(map[string]interface{})
  11551. var project models.HisProject
  11552. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11553. utils.ErrorLog("project_name")
  11554. return
  11555. }
  11556. project_name, _ := projectM["project_name"].(string)
  11557. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11558. err_log := models.ExportErrLog{
  11559. LogType: 6,
  11560. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11561. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11562. Status: 1,
  11563. CreateTime: time.Now().Unix(),
  11564. UpdateTime: time.Now().Unix(),
  11565. ExportTime: time.Now().Unix(),
  11566. }
  11567. service.CreateExportErrLog(&err_log)
  11568. continue
  11569. }
  11570. project.ProjectName = project_name
  11571. prices := projectM["price"].(string)
  11572. price, _ := strconv.ParseFloat(prices, 64)
  11573. if price <= 0 { //名字为空则生成一条导入错误日志
  11574. err_log := models.ExportErrLog{
  11575. LogType: 6,
  11576. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11577. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11578. Status: 1,
  11579. CreateTime: time.Now().Unix(),
  11580. UpdateTime: time.Now().Unix(),
  11581. ExportTime: time.Now().Unix(),
  11582. }
  11583. service.CreateExportErrLog(&err_log)
  11584. continue
  11585. }
  11586. project.Price = price
  11587. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11588. utils.ErrorLog("unit_id")
  11589. return
  11590. }
  11591. unit := projectM["unit"].(string)
  11592. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11593. err_log := models.ExportErrLog{
  11594. LogType: 6,
  11595. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11596. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11597. Status: 1,
  11598. CreateTime: time.Now().Unix(),
  11599. UpdateTime: time.Now().Unix(),
  11600. ExportTime: time.Now().Unix(),
  11601. }
  11602. service.CreateExportErrLog(&err_log)
  11603. continue
  11604. }
  11605. project.Unit = unit
  11606. cost_classify := projectM["cost_classify"].(string)
  11607. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11608. err_log := models.ExportErrLog{
  11609. LogType: 6,
  11610. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11611. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11612. Status: 1,
  11613. CreateTime: time.Now().Unix(),
  11614. UpdateTime: time.Now().Unix(),
  11615. ExportTime: time.Now().Unix(),
  11616. }
  11617. service.CreateExportErrLog(&err_log)
  11618. continue
  11619. }
  11620. var costClassify = "费用类别"
  11621. var cost_classify_id int64
  11622. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11623. if len(cost_classify) != 0 {
  11624. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11625. if errcode == gorm.ErrRecordNotFound {
  11626. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11627. dataconfig := models.DictDataconfig{
  11628. ParentId: costClassifyConfig.ID,
  11629. Module: "system",
  11630. OrgId: orgId,
  11631. Name: cost_classify,
  11632. FieldName: "",
  11633. Value: costConfig.Value + 1,
  11634. CreatedTime: "",
  11635. UpdatedTime: "",
  11636. CreateUserId: adminUser.AdminUser.Id,
  11637. Status: 1,
  11638. Remark: "",
  11639. DeleteIdSystem: 0,
  11640. Title: "",
  11641. Content: "",
  11642. Order: 0,
  11643. Code: "",
  11644. }
  11645. service.CreatedDicConfig(&dataconfig)
  11646. }
  11647. }
  11648. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11649. for _, it := range costClassList {
  11650. if cost_classify == it.Name {
  11651. cost_classify_id = int64(it.Value)
  11652. }
  11653. }
  11654. project.CostClassify = cost_classify_id
  11655. executive_section := projectM["executive_section"].(string)
  11656. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11657. err_log := models.ExportErrLog{
  11658. LogType: 6,
  11659. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11660. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11661. Status: 1,
  11662. CreateTime: time.Now().Unix(),
  11663. UpdateTime: time.Now().Unix(),
  11664. ExportTime: time.Now().Unix(),
  11665. }
  11666. service.CreateExportErrLog(&err_log)
  11667. continue
  11668. }
  11669. if len(executive_section) != 0 {
  11670. //查找科室是否有内容
  11671. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11672. if errcodedepart == gorm.ErrRecordNotFound {
  11673. department := models.XtHisDepartment{
  11674. Name: executive_section,
  11675. Status: 1,
  11676. UserOrgId: adminUser.CurrentOrgId,
  11677. CreatedTime: time.Now().Unix(),
  11678. }
  11679. service.CreateDePartment(&department)
  11680. }
  11681. }
  11682. var executive_section_id int64
  11683. departMentList, _ := service.GetAllDepartMent(orgId)
  11684. for _, it := range departMentList {
  11685. if executive_section == it.Name {
  11686. executive_section_id = it.ID
  11687. }
  11688. }
  11689. project.ExecutiveSection = executive_section_id
  11690. medical_coverage := projectM["medical_coverage"].(string)
  11691. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11692. err_log := models.ExportErrLog{
  11693. LogType: 6,
  11694. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11695. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11696. Status: 1,
  11697. CreateTime: time.Now().Unix(),
  11698. UpdateTime: time.Now().Unix(),
  11699. ExportTime: time.Now().Unix(),
  11700. }
  11701. service.CreateExportErrLog(&err_log)
  11702. continue
  11703. }
  11704. var medicalCoverage = "医保等级"
  11705. var medical_coverage_id int64
  11706. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11707. if len(medical_coverage) != 0 {
  11708. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11709. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11710. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11711. dataconfig := models.DictDataconfig{
  11712. ParentId: medicalCoverageConfig.ID,
  11713. Module: "system",
  11714. OrgId: orgId,
  11715. Name: medical_coverage,
  11716. FieldName: "",
  11717. Value: medicalCoverageConfig.Value + 1,
  11718. CreatedTime: "",
  11719. UpdatedTime: "",
  11720. CreateUserId: adminUser.AdminUser.Id,
  11721. Status: 1,
  11722. Remark: "",
  11723. DeleteIdSystem: 0,
  11724. Title: "",
  11725. Content: "",
  11726. Order: 0,
  11727. Code: "",
  11728. }
  11729. service.CreatedDicConfig(&dataconfig)
  11730. }
  11731. }
  11732. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11733. for _, it := range medicalCoverageList {
  11734. if medical_coverage == it.Name {
  11735. medical_coverage_id = int64(it.Value)
  11736. }
  11737. }
  11738. project.MedicalCoverage = medical_coverage_id
  11739. pinyin := projectM["pinyin"].(string)
  11740. project.Pinyin = pinyin
  11741. wubi := projectM["wubi"].(string)
  11742. project.Wubi = wubi
  11743. statistical_classification := projectM["statistical_classification"].(string)
  11744. var statisticalClassification = "统计分类"
  11745. var statistical_classification_id int64
  11746. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11747. if len(statistical_classification) != 0 {
  11748. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11749. if classificationerrcodes == gorm.ErrRecordNotFound {
  11750. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11751. dataconfig := models.DictDataconfig{
  11752. ParentId: classiFication.ID,
  11753. Module: "system",
  11754. OrgId: orgId,
  11755. Name: statistical_classification,
  11756. FieldName: "",
  11757. Value: classiFicationConfig.Value + 1,
  11758. CreatedTime: "",
  11759. UpdatedTime: "",
  11760. CreateUserId: adminUser.AdminUser.Id,
  11761. Status: 1,
  11762. Remark: "",
  11763. DeleteIdSystem: 0,
  11764. Title: "",
  11765. Content: "",
  11766. Order: 0,
  11767. Code: "",
  11768. }
  11769. service.CreatedDicConfig(&dataconfig)
  11770. }
  11771. }
  11772. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11773. for _, it := range classiFicationList {
  11774. if statistical_classification == it.Name {
  11775. statistical_classification_id = int64(it.Value)
  11776. }
  11777. }
  11778. project.StatisticalClassification = statistical_classification_id
  11779. disease_directory := int64(projectM["disease_directory"].(float64))
  11780. project.DiseaseDirectory = disease_directory
  11781. is_record := int64(projectM["is_record"].(float64))
  11782. project.IsRecord = is_record
  11783. medical_code := projectM["medical_code"].(string)
  11784. project.MedicalCode = medical_code
  11785. tube_color := projectM["tube_color"].(string)
  11786. var tubeColor = "试管颜色"
  11787. var tube_color_id int64
  11788. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11789. if len(tube_color) != 0 {
  11790. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11791. if errcodetube == gorm.ErrRecordNotFound {
  11792. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11793. dataconfig := models.DictDataconfig{
  11794. ParentId: tubeColorConfig.ID,
  11795. Module: "system",
  11796. OrgId: orgId,
  11797. Name: tube_color,
  11798. FieldName: "",
  11799. Value: tubeConfig.Value + 1,
  11800. CreatedTime: "",
  11801. UpdatedTime: "",
  11802. CreateUserId: adminUser.AdminUser.Id,
  11803. Status: 1,
  11804. Remark: "",
  11805. DeleteIdSystem: 0,
  11806. Title: "",
  11807. Content: "",
  11808. Order: 0,
  11809. Code: "",
  11810. }
  11811. service.CreatedDicConfig(&dataconfig)
  11812. }
  11813. }
  11814. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11815. for _, it := range tubeColorList {
  11816. if tube_color == it.Name {
  11817. tube_color_id = int64(it.Value)
  11818. }
  11819. }
  11820. project.TubeColor = tube_color_id
  11821. single_dose := projectM["single_dose"].(string)
  11822. project.SingleDose = single_dose
  11823. execution_frequency := projectM["execution_frequency"].(string)
  11824. project.ExecutionFrequency = execution_frequency
  11825. delivery_way := projectM["delivery_way"].(string)
  11826. project.DeliveryWay = delivery_way
  11827. number_days := projectM["number_days"].(string)
  11828. project.NumberDays = number_days
  11829. total := projectM["total"].(string)
  11830. project.Total = total
  11831. medical_status := int64(projectM["medical_status"].(float64))
  11832. project.MedicalStatus = medical_status
  11833. category := int64(projectM["category"].(float64))
  11834. project.Category = category
  11835. specail_project := int64(projectM["specail_project"].(float64))
  11836. project.SpecailProject = specail_project
  11837. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11838. project.SocialSecurityDirectoryCode = social_security_directory_code
  11839. remark := projectM["remark"].(string)
  11840. project.Remark = remark
  11841. record_date := projectM["record_date"].(string)
  11842. timeLayout := "2006-01-02"
  11843. loc, _ := time.LoadLocation("Local")
  11844. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11845. project.RecordDate = theTime.Unix()
  11846. projectList = append(projectList, &project)
  11847. }
  11848. export_time := time.Now().Unix()
  11849. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11850. if len(projectList) > 0 {
  11851. for _, item := range projectList {
  11852. hans := item.ProjectName // 要转换的汉字字符串
  11853. // 创建一个拼音转换器
  11854. p := pinyin.NewArgs()
  11855. // 将汉字转为拼音
  11856. pinyinSlice := pinyin.Pinyin(hans, p)
  11857. // 输出拼音
  11858. fmt.Println("Pinyin:", pinyinSlice)
  11859. // 获取首字母
  11860. firstLetter := ""
  11861. for _, py := range pinyinSlice {
  11862. if len(py) > 0 {
  11863. firstLetter += string(py[0][0])
  11864. }
  11865. }
  11866. item.FirstLetter = firstLetter
  11867. project := models.HisProject{
  11868. ProjectName: item.ProjectName,
  11869. Price: item.Price,
  11870. Unit: item.Unit,
  11871. CostClassify: item.CostClassify,
  11872. ExecutiveSection: item.ExecutiveSection,
  11873. MedicalCoverage: item.MedicalCoverage,
  11874. UserOrgId: orgId,
  11875. Status: 1,
  11876. CreatedTime: time.Now().Unix(),
  11877. Pinyin: item.Pinyin,
  11878. Wubi: item.Wubi,
  11879. StatisticalClassification: item.StatisticalClassification,
  11880. DiseaseDirectory: item.DiseaseDirectory,
  11881. IsRecord: item.IsRecord,
  11882. MedicalCode: item.MedicalCode,
  11883. TubeColor: item.TubeColor,
  11884. SingleDose: item.SingleDose,
  11885. DeliveryWay: item.DeliveryWay,
  11886. NumberDays: item.NumberDays,
  11887. Total: item.Total,
  11888. Category: item.Category,
  11889. MedicalStatus: item.MedicalStatus,
  11890. SpecailProject: item.SpecailProject,
  11891. RecordDate: item.RecordDate,
  11892. Remark: item.Remark,
  11893. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11894. ExecutionFrequency: item.ExecutionFrequency,
  11895. FirstLetter: item.FirstLetter,
  11896. }
  11897. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11898. if errcodeproject == gorm.ErrRecordNotFound {
  11899. service.CreateProjectInfomation(&project)
  11900. } else if errcodeproject == nil {
  11901. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11902. }
  11903. log := models.ExportLog{
  11904. LogType: 6,
  11905. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11906. TotalNum: int64(len(total_goods)),
  11907. FailNum: int64(len(errLogs)),
  11908. SuccessNum: int64(len(projectList)),
  11909. CreateTime: time.Now().Unix(),
  11910. UpdateTime: time.Now().Unix(),
  11911. ExportTime: export_time,
  11912. Status: 1,
  11913. }
  11914. service.CreateExportLog(&log)
  11915. c.ServeSuccessJSON(map[string]interface{}{
  11916. "msg": "导入成功",
  11917. "total_num": len(total_goods),
  11918. "success_num": len(projectList),
  11919. "fail_num": int64(len(errLogs)),
  11920. })
  11921. }
  11922. } else {
  11923. log := models.ExportLog{
  11924. LogType: 6,
  11925. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11926. TotalNum: int64(len(total_goods)),
  11927. FailNum: int64(len(errLogs)),
  11928. SuccessNum: int64(len(projectList)),
  11929. CreateTime: time.Now().Unix(),
  11930. UpdateTime: time.Now().Unix(),
  11931. ExportTime: export_time,
  11932. Status: 1,
  11933. }
  11934. service.CreateExportLog(&log)
  11935. c.ServeSuccessJSON(map[string]interface{}{
  11936. "msg": "导入成功",
  11937. "total_num": len(total_goods),
  11938. "success_num": len(projectList),
  11939. "fail_num": int64(len(errLogs)),
  11940. })
  11941. }
  11942. }
  11943. //func (this *HisApiController) EditProjectInformation(){
  11944. //
  11945. // id, _ := this.GetInt64("id")
  11946. // project_team := this.GetString("project_team")
  11947. // price := this.GetString("price")
  11948. // price_float, _ := strconv.ParseFloat(price, 64)
  11949. // pinyin := this.GetString("pinyin")
  11950. // wubi := this.GetString("wubi")
  11951. // tube_color, _ := this.GetInt64("tube_color")
  11952. // team_type, _ := this.GetInt64("team_type")
  11953. // remark := this.GetString("remark")
  11954. // ids := this.GetString("ids")
  11955. // item_id := this.GetString("item_id")
  11956. // projectTeam := models.XtHisProjectTeam{
  11957. // ProjectTeam: project_team,
  11958. // Price: price_float,
  11959. // Pinyin: pinyin,
  11960. // Wubi: wubi,
  11961. // TubeColor: tube_color,
  11962. // TeamType: team_type,
  11963. // Remark: remark,
  11964. // ProjectId: ids,
  11965. // ItemId: item_id,
  11966. // }
  11967. //
  11968. //
  11969. // dataBody := make(map[string]interface{}, 0)
  11970. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11971. // if err != nil {
  11972. // utils.ErrorLog(err.Error())
  11973. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11974. // return
  11975. // }
  11976. //
  11977. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11978. //
  11979. //
  11980. // if err != nil {
  11981. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11982. // return
  11983. // }
  11984. //
  11985. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11986. // infos, _ := dataBody["info"].([]interface{})
  11987. // if len(infos) > 0 {
  11988. // var ids []string
  11989. //
  11990. // for _, item := range infos {
  11991. // items := item.(map[string]interface{})
  11992. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11993. // utils.ErrorLog("id")
  11994. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11995. // return
  11996. // }
  11997. // id := int64(items["id"].(float64))
  11998. //
  11999. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12000. // utils.ErrorLog("type")
  12001. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12002. // return
  12003. // }
  12004. // types := int64(items["type"].(float64))
  12005. //
  12006. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12007. // utils.ErrorLog("number")
  12008. // }
  12009. //
  12010. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12011. //
  12012. // projectList := models.XtHisProjectList{
  12013. // Number: number,
  12014. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12015. // ProjectId: id,
  12016. // Status: 1,
  12017. // CreatedTime: time.Now().Unix(),
  12018. // UpdatedTime: time.Now().Unix(),
  12019. // TeamId: projectTeam.ID,
  12020. // Type: types,
  12021. // }
  12022. // list := projectList
  12023. //
  12024. // service.CreateProjectList(&list)
  12025. //
  12026. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12027. //
  12028. // }
  12029. // ids_str := strings.Join(ids, ",")
  12030. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12031. // service.SaveProjectTeam(&projectTeam)
  12032. // this.ServeSuccessJSON(map[string]interface{}{
  12033. // "projectTeam": projectTeam,
  12034. // })
  12035. // }
  12036. // }
  12037. //}
  12038. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12039. name := c.GetString("name")
  12040. mode_id, _ := c.GetInt64("mode", 0)
  12041. types, _ := c.GetInt64("type", 0)
  12042. patient_id, _ := c.GetInt64("patient_id", 0)
  12043. types = 1
  12044. adminInfo := c.GetAdminUserInfo()
  12045. template := &models.HisPrescriptionTemplate{
  12046. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12047. PatientId: patient_id,
  12048. Type: types,
  12049. Status: 1,
  12050. Ctime: time.Now().Unix(),
  12051. Mtime: time.Now().Unix(),
  12052. Name: name,
  12053. Mode: mode_id,
  12054. }
  12055. dataBody := make(map[string]interface{}, 0)
  12056. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12057. if err != nil {
  12058. utils.ErrorLog(err.Error())
  12059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12060. return
  12061. }
  12062. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12063. //如果已经存在记录则删除处方
  12064. if template_one.ID > 0 {
  12065. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12066. var ids []int64
  12067. var org_id int64
  12068. for _, item := range ps {
  12069. org_id = c.GetAdminUserInfo().CurrentOrgId
  12070. ids = append(ids, item.ID)
  12071. }
  12072. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12073. if err2 == nil {
  12074. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12075. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12076. if len(prescriptions) > 0 {
  12077. for _, item := range prescriptions {
  12078. items := item.(map[string]interface{})
  12079. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12080. utils.ErrorLog("type")
  12081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12082. return
  12083. }
  12084. types := int64(items["type"].(float64))
  12085. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12086. utils.ErrorLog("med_type")
  12087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12088. return
  12089. }
  12090. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12091. ctime := time.Now().Unix()
  12092. prescription := &models.HisPrescriptionInfoTemplate{
  12093. PatientId: patient_id,
  12094. UserOrgId: adminInfo.CurrentOrgId,
  12095. Ctime: ctime,
  12096. Mtime: ctime,
  12097. Type: types,
  12098. Modifier: adminInfo.AdminUser.Id,
  12099. Creator: adminInfo.AdminUser.Id,
  12100. Status: 1,
  12101. PTemplateId: template_one.ID,
  12102. MedType: med_type,
  12103. }
  12104. service.CreateHisPrescriptionInfoTemplate(prescription)
  12105. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12106. advices := items["advices"].([]interface{})
  12107. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12108. ctime := time.Now().Unix()
  12109. mtime := ctime
  12110. if len(advices) > 0 {
  12111. for _, advice := range advices {
  12112. var s models.HisPrescriptionAdviceTemplate
  12113. s.PrescriptionId = prescription.ID
  12114. s.AdviceType = 2
  12115. s.StopState = 2
  12116. s.ExecutionState = 2
  12117. s.Status = 1
  12118. s.UserOrgId = adminInfo.CurrentOrgId
  12119. s.CreatedTime = ctime
  12120. s.UpdatedTime = mtime
  12121. s.PatientId = patient_id
  12122. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12123. if errcode > 0 {
  12124. c.ServeFailJSONWithSGJErrorCode(errcode)
  12125. return
  12126. }
  12127. service.CreateHisPrescriptionAdviceTemplate(&s)
  12128. }
  12129. }
  12130. }
  12131. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12132. projects := items["project"].([]interface{})
  12133. if len(projects) > 0 {
  12134. for _, project := range projects {
  12135. var p models.HisPrescriptionProjectTemplate
  12136. p.PrescriptionId = prescription.ID
  12137. p.Ctime = time.Now().Unix()
  12138. p.Mtime = time.Now().Unix()
  12139. p.PatientId = patient_id
  12140. p.UserOrgId = adminInfo.CurrentOrgId
  12141. p.Status = 1
  12142. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12143. if errcode > 0 {
  12144. c.ServeFailJSONWithSGJErrorCode(errcode)
  12145. return
  12146. }
  12147. service.CreateHisPrescriptionProjectTemplate(&p)
  12148. }
  12149. }
  12150. }
  12151. }
  12152. c.ServeSuccessJSON(map[string]interface{}{
  12153. "msg": "创建成功",
  12154. })
  12155. }
  12156. }
  12157. } else {
  12158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12159. return
  12160. }
  12161. } else {
  12162. err3 := service.CreateHisPrescriptionTemplate(template)
  12163. if err3 == nil {
  12164. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12165. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12166. if len(prescriptions) > 0 {
  12167. for _, item := range prescriptions {
  12168. items := item.(map[string]interface{})
  12169. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12170. utils.ErrorLog("type")
  12171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12172. return
  12173. }
  12174. types := int64(items["type"].(float64))
  12175. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12176. utils.ErrorLog("med_type")
  12177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12178. return
  12179. }
  12180. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12181. ctime := time.Now().Unix()
  12182. prescription := &models.HisPrescriptionInfoTemplate{
  12183. PatientId: patient_id,
  12184. UserOrgId: adminInfo.CurrentOrgId,
  12185. Ctime: ctime,
  12186. Mtime: ctime,
  12187. Type: types,
  12188. Modifier: adminInfo.AdminUser.Id,
  12189. Creator: adminInfo.AdminUser.Id,
  12190. Status: 1,
  12191. PTemplateId: template.ID,
  12192. MedType: med_type,
  12193. }
  12194. service.CreateHisPrescriptionInfoTemplate(prescription)
  12195. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12196. advices := items["advices"].([]interface{})
  12197. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12198. ctime := time.Now().Unix()
  12199. mtime := ctime
  12200. if len(advices) > 0 {
  12201. for _, advice := range advices {
  12202. var s models.HisPrescriptionAdviceTemplate
  12203. s.PrescriptionId = prescription.ID
  12204. s.AdviceType = 2
  12205. s.StopState = 2
  12206. s.ExecutionState = 2
  12207. s.Status = 1
  12208. s.UserOrgId = adminInfo.CurrentOrgId
  12209. s.CreatedTime = ctime
  12210. s.UpdatedTime = mtime
  12211. s.PatientId = patient_id
  12212. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12213. if errcode > 0 {
  12214. c.ServeFailJSONWithSGJErrorCode(errcode)
  12215. return
  12216. }
  12217. service.CreateHisPrescriptionAdviceTemplate(&s)
  12218. }
  12219. }
  12220. }
  12221. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12222. projects := items["project"].([]interface{})
  12223. if len(projects) > 0 {
  12224. for _, project := range projects {
  12225. var p models.HisPrescriptionProjectTemplate
  12226. p.PrescriptionId = prescription.ID
  12227. p.Ctime = time.Now().Unix()
  12228. p.Mtime = time.Now().Unix()
  12229. p.PatientId = patient_id
  12230. p.UserOrgId = adminInfo.CurrentOrgId
  12231. p.Status = 1
  12232. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12233. if errcode > 0 {
  12234. c.ServeFailJSONWithSGJErrorCode(errcode)
  12235. return
  12236. }
  12237. service.CreateHisPrescriptionProjectTemplate(&p)
  12238. }
  12239. }
  12240. }
  12241. }
  12242. c.ServeSuccessJSON(map[string]interface{}{
  12243. "msg": "创建成功",
  12244. })
  12245. }
  12246. }
  12247. } else {
  12248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12249. return
  12250. }
  12251. }
  12252. }
  12253. func (c *HisApiController) PreSettle() {
  12254. id, _ := c.GetInt64("id")
  12255. record_time := c.GetString("record_time")
  12256. his_patient_id, _ := c.GetInt64("his_patient_id")
  12257. timeLayout := "2006-01-02"
  12258. loc, _ := time.LoadLocation("Local")
  12259. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12260. diagnosis_id := c.GetString("diagnosis")
  12261. sick_type, _ := c.GetInt64("sick_type")
  12262. reg_type, _ := c.GetInt64("p_type")
  12263. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12264. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12265. if err != nil {
  12266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12267. return
  12268. }
  12269. recordDateTime := theTime.Unix()
  12270. adminUser := c.GetAdminUserInfo()
  12271. var prescriptions []*models.HisPrescription
  12272. var start_time int64
  12273. var end_time int64
  12274. ids_str := c.GetString("ids")
  12275. ids_arr := strings.Split(ids_str, ",")
  12276. fmt.Println(reg_type)
  12277. if settle_accounts_type == 1 { //日结
  12278. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12279. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12280. } else {
  12281. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12282. }
  12283. fmt.Println(prescriptions)
  12284. } else { //月结
  12285. start_time_str := c.GetString("start_time")
  12286. end_time_str := c.GetString("end_time")
  12287. timeLayout := "2006-01-02"
  12288. loc, _ := time.LoadLocation("Local")
  12289. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12290. if err != nil {
  12291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12292. return
  12293. }
  12294. recordStartTime := theStartTime.Unix()
  12295. start_time = recordStartTime
  12296. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12297. if err != nil {
  12298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12299. return
  12300. }
  12301. recordEndTime := theEndTime.Unix()
  12302. end_time = recordEndTime
  12303. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12304. }
  12305. if reg_type == 1111 || reg_type == 1112 {
  12306. reg_type = 11
  12307. }
  12308. timestamp := time.Now().Unix()
  12309. tempTime := time.Unix(timestamp, 0)
  12310. timeFormat := tempTime.Format("20060102150405")
  12311. chrgBchno := rand.Intn(100000) + 10000
  12312. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12313. strconv.FormatInt(his.PatientId, 10)
  12314. var ids []int64
  12315. for _, item := range prescriptions {
  12316. ids = append(ids, item.ID)
  12317. }
  12318. fmt.Println(ids)
  12319. var total float64
  12320. for _, item := range prescriptions {
  12321. fmt.Println(item)
  12322. if item.Type == 1 { //药品
  12323. for _, subItem := range item.HisDoctorAdviceInfo {
  12324. total = total + (subItem.Price * subItem.PrescribingNumber)
  12325. }
  12326. }
  12327. if item.Type == 2 { //项目
  12328. for _, subItem := range item.HisPrescriptionProject {
  12329. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12330. total = total + (subItem.Price * cnt)
  12331. }
  12332. }
  12333. for _, subItem := range item.HisAdditionalCharge {
  12334. total = total + (subItem.Price * float64(subItem.Count))
  12335. }
  12336. }
  12337. allTotal := fmt.Sprintf("%.2f", total)
  12338. totals, _ := strconv.ParseFloat(allTotal, 64)
  12339. order := &models.HisOrder{
  12340. UserOrgId: adminUser.CurrentOrgId,
  12341. HisPatientId: his.ID,
  12342. PatientId: id,
  12343. SettleAccountsDate: recordDateTime,
  12344. Ctime: time.Now().Unix(),
  12345. Mtime: time.Now().Unix(),
  12346. Status: 1,
  12347. OrderStatus: 1,
  12348. MdtrtId: his.Number,
  12349. Number: chrg_bchno,
  12350. MedfeeSumamt: totals,
  12351. SettleEndTime: end_time,
  12352. SettleStartTime: start_time,
  12353. SettleType: settle_accounts_type,
  12354. PsnPartAmt: totals,
  12355. PsnCashPay: totals,
  12356. PType: 2,
  12357. IsPre: 1,
  12358. MedType: strconv.Itoa(int(reg_type)),
  12359. Diagnosis: diagnosis_id,
  12360. }
  12361. err = service.CreateOrder(order)
  12362. if err != nil {
  12363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12364. return
  12365. }
  12366. var customs []*Custom
  12367. for _, item := range prescriptions {
  12368. fmt.Println(item.Type)
  12369. if item.Type == 1 { //药品
  12370. for _, subItem := range item.HisDoctorAdviceInfo {
  12371. cus := &Custom{
  12372. AdviceId: subItem.ID,
  12373. ProjectId: 0,
  12374. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12375. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12376. FeedetlSn: subItem.FeedetlSn,
  12377. Price: fmt.Sprintf("%.2f", subItem.Price),
  12378. MedListCodg: subItem.MedListCodg,
  12379. Type: 1,
  12380. }
  12381. customs = append(customs, cus)
  12382. }
  12383. }
  12384. if item.Type == 2 { //项目
  12385. for _, subItem := range item.HisPrescriptionProject {
  12386. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12387. cus := &Custom{
  12388. AdviceId: 0,
  12389. ProjectId: subItem.ID,
  12390. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12391. Cut: fmt.Sprintf("%.2f", cnt),
  12392. FeedetlSn: subItem.FeedetlSn,
  12393. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12394. MedListCodg: subItem.MedListCodg,
  12395. Type: 2,
  12396. }
  12397. customs = append(customs, cus)
  12398. }
  12399. }
  12400. for _, item := range item.HisAdditionalCharge {
  12401. cus := &Custom{
  12402. ItemId: item.ID,
  12403. AdviceId: 0,
  12404. ProjectId: 0,
  12405. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12406. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12407. FeedetlSn: item.FeedetlSn,
  12408. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12409. MedListCodg: item.XtHisAddtionConfig.Code,
  12410. Type: 3,
  12411. }
  12412. customs = append(customs, cus)
  12413. }
  12414. }
  12415. fmt.Println(customs)
  12416. for _, item := range customs {
  12417. var advice_id int64 = 0
  12418. var project_id int64 = 0
  12419. var item_id int64 = 0
  12420. var types int64 = 0
  12421. if item.Type == 1 {
  12422. advice_id = item.AdviceId
  12423. project_id = 0
  12424. item_id = 0
  12425. } else if item.Type == 2 {
  12426. advice_id = 0
  12427. item_id = 0
  12428. project_id = item.ProjectId
  12429. } else if item.Type == 3 {
  12430. advice_id = 0
  12431. item_id = item.ItemId
  12432. project_id = 0
  12433. }
  12434. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12435. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12436. pric, _ := strconv.ParseFloat(item.Price, 32)
  12437. info := &models.HisOrderInfo{
  12438. OrderNumber: order.Number,
  12439. UploadDate: time.Now().Unix(),
  12440. AdviceId: advice_id,
  12441. DetItemFeeSumamt: detItemFeeSumamt,
  12442. Cnt: cut,
  12443. Pric: pric,
  12444. PatientId: id,
  12445. Status: 1,
  12446. Mtime: time.Now().Unix(),
  12447. Ctime: time.Now().Unix(),
  12448. UserOrgId: adminUser.CurrentOrgId,
  12449. HisPatientId: his.ID,
  12450. OrderId: order.ID,
  12451. ProjectId: project_id,
  12452. Type: types,
  12453. ItemId: item_id,
  12454. }
  12455. service.CreateOrderInfo(info)
  12456. }
  12457. his.SickType = sick_type
  12458. service.UpdataHisPateint(&his)
  12459. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12460. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12461. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12462. if err == nil {
  12463. c.ServeSuccessJSON(map[string]interface{}{
  12464. "msg": "结算成功",
  12465. })
  12466. }
  12467. }
  12468. type CustomOrderInfo struct {
  12469. Name string
  12470. Spec string
  12471. Unit string
  12472. Count float64
  12473. Price float64
  12474. Total float64
  12475. }
  12476. func (c *HisApiController) GetPrivateExpensesInfo() {
  12477. order_id, _ := c.GetInt64("id", 0)
  12478. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12479. order, _ := service.GetHisOrderByID(order_id)
  12480. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12481. if order.ID == 0 {
  12482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12483. return
  12484. }
  12485. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12486. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12487. org_id := c.GetAdminUserInfo().CurrentOrgId
  12488. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12489. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12490. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12491. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12492. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12493. //var orderInfos_four []*models.HisOrderInfoTwo
  12494. //for _, item := range orderInfos_three {
  12495. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12496. // item.HisPrescriptionProject.IsCheckTeam = 1
  12497. // orderInfos_four = append(orderInfos_four, item)
  12498. //
  12499. // }
  12500. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12501. // item.HisPrescriptionProject.IsCheckTeam = 2
  12502. // orderInfos_two = append(orderInfos_two, item)
  12503. // }
  12504. //}
  12505. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12506. //var cus_slice []CustomOrderInfo
  12507. //for _, item := range new_order_info {
  12508. // var cus CustomOrderInfo
  12509. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12510. // cus.Unit = ""
  12511. // cus.Spec = ""
  12512. // var total float64
  12513. // for _, subItem := range orderInfos_four {
  12514. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12515. // total = total + subItem.DetItemFeeSumamt
  12516. // fmt.Println(subItem.DetItemFeeSumamt)
  12517. // }
  12518. // }
  12519. // cus.Count = 1
  12520. // cus.Total = total
  12521. // cus_slice = append(cus_slice, cus)
  12522. //}
  12523. orderInfos = append(orderInfos, orderInfos_two...)
  12524. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12525. //orderInfos = append(orderInfos, orderInfos_three...)
  12526. //}/**/
  12527. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12528. c.ServeSuccessJSON(map[string]interface{}{
  12529. "order": order,
  12530. "order_info": orderInfos,
  12531. "patient": patient,
  12532. "admin_info": adminInfo,
  12533. "his": his,
  12534. "current_admin": role,
  12535. "org_config": miConfig,
  12536. //"new_order_info": cus_slice,
  12537. })
  12538. }
  12539. func (this *HisApiController) ChangeMedType() {
  12540. med_type := this.GetString("med_type")
  12541. old_med_type := this.GetString("old_med_type")
  12542. ids := this.GetString("ids")
  12543. settle_type, _ := this.GetInt64("settle_type")
  12544. start_time := this.GetString("start_time")
  12545. end_time := this.GetString("end_time")
  12546. ids_arr := strings.Split(ids, ",")
  12547. if settle_type == 1 { //日结
  12548. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12549. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12550. prescription.MedType = med_type
  12551. err := service.SaveHisPrescriptionTwo(&prescription)
  12552. if err == nil {
  12553. this.ServeSuccessJSON(map[string]interface{}{
  12554. "msg": "修改成功",
  12555. })
  12556. } else {
  12557. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12558. return
  12559. }
  12560. } else if settle_type == 2 {
  12561. timeLayout := "2006-01-02"
  12562. loc, _ := time.LoadLocation("Local")
  12563. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12564. if err != nil {
  12565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12566. return
  12567. }
  12568. recordStartTime := theStartTime.Unix()
  12569. start_time_timestamp := recordStartTime
  12570. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12571. if err != nil {
  12572. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12573. return
  12574. }
  12575. recordEndTime := theEndTime.Unix()
  12576. end_time_timestamp := recordEndTime
  12577. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12578. if updateErr == nil {
  12579. this.ServeSuccessJSON(map[string]interface{}{
  12580. "msg": "修改成功",
  12581. })
  12582. } else {
  12583. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12584. return
  12585. }
  12586. }
  12587. }
  12588. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12589. patient_id, _ := c.GetInt64("patient_id")
  12590. his_patient_id, _ := c.GetInt64("his_patient_id")
  12591. record_date := c.GetString("record_date")
  12592. start_time := c.GetString("start_time")
  12593. end_time := c.GetString("end_time")
  12594. order_status, _ := c.GetInt64("type", 0)
  12595. p_type, _ := c.GetInt64("p_type", 0)
  12596. order_id, _ := c.GetInt64("order_id", 0)
  12597. timeLayout := "2006-01-02"
  12598. loc, _ := time.LoadLocation("Local")
  12599. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12600. if err != nil {
  12601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12602. return
  12603. }
  12604. recordDateTime := theTime.Unix()
  12605. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12606. if err != nil {
  12607. }
  12608. startRecordDateTime := startTime.Unix()
  12609. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12610. if err != nil {
  12611. }
  12612. endRecordDateTime := endTime.Unix()
  12613. admin := c.GetAdminUserInfo()
  12614. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12615. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12616. order, _ := service.GetHisOrderByID(order_id)
  12617. var monthPrescriptions []*models.HisPrescription
  12618. if order_status == 1 || order_status == 0 {
  12619. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12620. } else if order_status == 2 {
  12621. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12622. }
  12623. var settle_total float64
  12624. for _, item := range monthPrescriptions {
  12625. if len(item.HisPrescriptionProject) > 0 {
  12626. for _, subItem := range item.HisPrescriptionProject {
  12627. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12628. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12629. settle_total = settle_total + total
  12630. }
  12631. }
  12632. if len(item.HisDoctorAdviceInfo) > 0 {
  12633. for _, subItem := range item.HisDoctorAdviceInfo {
  12634. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12635. settle_total = settle_total + total
  12636. }
  12637. }
  12638. }
  12639. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12640. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12641. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12642. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12643. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12644. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12645. //获取所有科室信息
  12646. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12647. var dia string
  12648. for _, item := range month_p_info {
  12649. if len(dia) == 0 {
  12650. dia = item.Diagnosis
  12651. } else {
  12652. dia = dia + "," + item.Diagnosis
  12653. }
  12654. }
  12655. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12656. dia_arr = removeEmptyStrings(dia_arr)
  12657. c.ServeSuccessJSON(map[string]interface{}{
  12658. "his_info": his_patient_info,
  12659. "xt_info": xt_patient_info,
  12660. "case_history": case_history,
  12661. "info": patientPrescriptionInfo,
  12662. "last_info": lastPatientPrescriptionInfo,
  12663. "month_prescriptions": monthPrescriptions,
  12664. "order": order,
  12665. "doctors": doctors,
  12666. "department": department,
  12667. "settle_total": settle_total,
  12668. "dia_arr": dia_arr,
  12669. })
  12670. return
  12671. }
  12672. func removeEmptyStrings(input []string) []string {
  12673. var output []string
  12674. for _, s := range input {
  12675. if s != "" {
  12676. output = append(output, s)
  12677. }
  12678. }
  12679. return output
  12680. }
  12681. func removeDuplicates(input []string) []string {
  12682. seen := make(map[string]bool)
  12683. output := []string{}
  12684. for _, s := range input {
  12685. if _, exists := seen[s]; !exists {
  12686. seen[s] = true
  12687. output = append(output, s)
  12688. }
  12689. }
  12690. return output
  12691. }
  12692. func (c *HisApiController) GetHisMonthPatientInfo() {
  12693. patient_id, _ := c.GetInt64("patient_id")
  12694. his_patient_id, _ := c.GetInt64("his_patient_id")
  12695. record_date := c.GetString("record_date")
  12696. number := c.GetString("number")
  12697. start_time := c.GetString("start_time")
  12698. end_time := c.GetString("end_time")
  12699. p_type, _ := c.GetInt64("p_type")
  12700. timeLayout := "2006-01-02"
  12701. loc, _ := time.LoadLocation("Local")
  12702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12703. if err != nil {
  12704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12705. return
  12706. }
  12707. recordDateTime := theTime.Unix()
  12708. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12709. if err != nil {
  12710. }
  12711. startRecordDateTime := startTime.Unix()
  12712. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12713. if err != nil {
  12714. }
  12715. endRecordDateTime := endTime.Unix()
  12716. admin := c.GetAdminUserInfo()
  12717. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12718. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12719. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12720. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12721. var settle_total float64
  12722. for _, item := range monthPrescriptions {
  12723. if len(item.HisPrescriptionProject) > 0 {
  12724. for _, subItem := range item.HisPrescriptionProject {
  12725. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12726. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12727. settle_total = settle_total + total
  12728. }
  12729. }
  12730. if len(item.HisDoctorAdviceInfo) > 0 {
  12731. for _, subItem := range item.HisDoctorAdviceInfo {
  12732. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12733. settle_total = settle_total + total
  12734. }
  12735. }
  12736. }
  12737. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12738. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12739. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12740. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12741. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12742. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12743. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12744. //获取所有科室信息
  12745. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12746. c.ServeSuccessJSON(map[string]interface{}{
  12747. "his_info": his_patient_info,
  12748. "xt_info": xt_patient_info,
  12749. "case_history": case_history,
  12750. "info": patientPrescriptionInfo,
  12751. "month_prescriptions": monthPrescriptions,
  12752. "order": order,
  12753. "doctors": doctors,
  12754. "department": department,
  12755. "count": count,
  12756. "drugStockConfig": drugStockConfig,
  12757. "last_info": lastPatientPrescriptionInfo,
  12758. "settle_total": settle_total,
  12759. })
  12760. return
  12761. }
  12762. func (c *HisApiController) GetAllOrder() {
  12763. org_id := c.GetAdminUserInfo().CurrentOrgId
  12764. orders, _ := service.GetNewHisOrderList(org_id)
  12765. c.ServeSuccessJSON(map[string]interface{}{
  12766. "order": orders,
  12767. })
  12768. return
  12769. }
  12770. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12771. newArr = make([]*models.HisOrderInfoTwo, 0)
  12772. for i := 0; i < len(arr); i++ {
  12773. repeat := false
  12774. for j := i + 1; j < len(arr); j++ {
  12775. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12776. repeat = true
  12777. break
  12778. }
  12779. }
  12780. if !repeat {
  12781. newArr = append(newArr, arr[i])
  12782. }
  12783. }
  12784. return
  12785. }
  12786. // 修改处方退库操作 参数传修改之前的处方数据
  12787. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12788. if advice.ExecutionState == 1 {
  12789. //查询该病人该药品是否有库存记录
  12790. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12791. if errcode == gorm.ErrRecordNotFound {
  12792. } else {
  12793. //退库
  12794. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12795. if advice.PrescribingNumberUnit == drug.MinUnit {
  12796. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12797. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12798. //退库
  12799. warehouseInfo := models.DrugWarehouseInfo{
  12800. StockMinNumber: prescribingNumber,
  12801. }
  12802. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12803. operation_time := time.Now().Unix()
  12804. creater := advice.AdviceDoctor
  12805. ctime := time.Now().Unix()
  12806. timeStr := time.Now().Format("2006-01-02")
  12807. timeArr := strings.Split(timeStr, "-")
  12808. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12809. total = total + 1
  12810. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12811. cancelStock := models.DrugCancelStock{
  12812. OrderNumber: orderNumber,
  12813. OperaTime: operation_time,
  12814. OrgId: advice.UserOrgId,
  12815. Creater: creater,
  12816. Ctime: ctime,
  12817. Status: 1,
  12818. ReturnTime: advice.AdviceDate,
  12819. Dealer: info.Dealer,
  12820. Manufacturer: info.Manufacturer,
  12821. Type: 1,
  12822. }
  12823. service.AddSigleDrugCancelStock(&cancelStock)
  12824. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12825. dealer, _ := service.GetDealerById(info.Dealer)
  12826. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12827. cancelStockInfo := models.DrugCancelStockInfo{
  12828. OrderNumber: cancelInfo.OrderNumber,
  12829. CancelStockId: cancelInfo.ID,
  12830. DrugId: info.DrugId,
  12831. Count: info.Count,
  12832. Status: 1,
  12833. Ctime: ctime,
  12834. OrgId: advice.UserOrgId,
  12835. Type: 1,
  12836. Manufacturer: manufactureName.ManufacturerName,
  12837. Dealer: dealer.DealerName,
  12838. Total: 0,
  12839. RetailPrice: info.RetailPrice,
  12840. RetailTotalPrice: info.RetailTotalPrice,
  12841. Price: info.Price,
  12842. RegisterAccount: "",
  12843. Remark: info.Remark,
  12844. BatchNumber: info.BatchNumber,
  12845. MaxUnit: info.CountUnit,
  12846. ProductDate: info.ProductDate,
  12847. ExpiryDate: info.ExpiryDate,
  12848. BatchNumberId: info.WarehouseInfoId,
  12849. }
  12850. flow := models.DrugFlow{
  12851. WarehousingId: 0,
  12852. DrugId: info.DrugId,
  12853. Number: "",
  12854. BatchNumber: info.BatchNumber,
  12855. Count: info.Count,
  12856. UserOrgId: advice.UserOrgId,
  12857. PatientId: 0,
  12858. SystemTime: ctime,
  12859. ConsumableType: 4,
  12860. IsSys: 0,
  12861. WarehousingOrder: "",
  12862. WarehouseOutId: 0,
  12863. WarehouseOutOrderNumber: "",
  12864. IsEdit: 0,
  12865. CancelStockId: cancelStock.ID,
  12866. CancelOrderNumber: cancelStock.OrderNumber,
  12867. Manufacturer: info.Manufacturer,
  12868. Dealer: info.Dealer,
  12869. Creator: advice.UserOrgId,
  12870. UpdateCreator: 0,
  12871. Status: 1,
  12872. Ctime: time.Now().Unix(),
  12873. Mtime: 0,
  12874. Price: info.Price,
  12875. WarehousingDetailId: 0,
  12876. WarehouseOutDetailId: 0,
  12877. CancelOutDetailId: 0,
  12878. ExpireDate: info.ExpiryDate,
  12879. ProductDate: info.ProductDate,
  12880. MaxUnit: info.CountUnit,
  12881. MinUnit: "",
  12882. }
  12883. service.CreatedCancelStock(cancelStockInfo)
  12884. service.CreateDrugFlowOne(flow)
  12885. } else {
  12886. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12887. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12888. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12889. warehouseInfo := models.DrugWarehouseInfo{
  12890. StockMinNumber: prescribingNumber,
  12891. }
  12892. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12893. }
  12894. operation_time := time.Now().Unix()
  12895. creater := advice.AdviceDoctor
  12896. ctime := time.Now().Unix()
  12897. timeStr := time.Now().Format("2006-01-02")
  12898. timeArr := strings.Split(timeStr, "-")
  12899. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12900. total = total + 1
  12901. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12902. cancelStock := models.DrugCancelStock{
  12903. OrderNumber: orderNumber,
  12904. OperaTime: operation_time,
  12905. OrgId: advice.UserOrgId,
  12906. Creater: creater,
  12907. Ctime: ctime,
  12908. Status: 1,
  12909. ReturnTime: advice.AdviceDate,
  12910. Dealer: info.Dealer,
  12911. Manufacturer: info.Manufacturer,
  12912. Type: 1,
  12913. }
  12914. service.AddSigleDrugCancelStock(&cancelStock)
  12915. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12916. dealer, _ := service.GetDealerById(info.Dealer)
  12917. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12918. cancelStockInfo := models.DrugCancelStockInfo{
  12919. OrderNumber: cancelInfo.OrderNumber,
  12920. CancelStockId: cancelInfo.ID,
  12921. DrugId: info.DrugId,
  12922. Count: info.Count,
  12923. Status: 1,
  12924. Ctime: ctime,
  12925. OrgId: advice.UserOrgId,
  12926. Type: 1,
  12927. Manufacturer: manufactureName.ManufacturerName,
  12928. Dealer: dealer.DealerName,
  12929. Total: 0,
  12930. RetailPrice: info.RetailPrice,
  12931. RetailTotalPrice: info.RetailTotalPrice,
  12932. Price: info.Price,
  12933. RegisterAccount: "",
  12934. Remark: info.Remark,
  12935. BatchNumber: info.BatchNumber,
  12936. MaxUnit: info.CountUnit,
  12937. ProductDate: info.ProductDate,
  12938. ExpiryDate: info.ExpiryDate,
  12939. BatchNumberId: info.WarehouseInfoId,
  12940. }
  12941. flow := models.DrugFlow{
  12942. WarehousingId: 0,
  12943. DrugId: info.DrugId,
  12944. Number: "",
  12945. BatchNumber: info.BatchNumber,
  12946. Count: info.Count,
  12947. UserOrgId: advice.UserOrgId,
  12948. PatientId: 0,
  12949. SystemTime: ctime,
  12950. ConsumableType: 4,
  12951. IsSys: 0,
  12952. WarehousingOrder: "",
  12953. WarehouseOutId: 0,
  12954. WarehouseOutOrderNumber: "",
  12955. IsEdit: 0,
  12956. CancelStockId: cancelStock.ID,
  12957. CancelOrderNumber: cancelStock.OrderNumber,
  12958. Manufacturer: info.Manufacturer,
  12959. Dealer: info.Dealer,
  12960. Creator: advice.AdviceDoctor,
  12961. UpdateCreator: 0,
  12962. Status: 1,
  12963. Ctime: time.Now().Unix(),
  12964. Mtime: 0,
  12965. Price: info.Price,
  12966. WarehousingDetailId: 0,
  12967. WarehouseOutDetailId: 0,
  12968. CancelOutDetailId: 0,
  12969. ExpireDate: info.ExpiryDate,
  12970. ProductDate: info.ProductDate,
  12971. MaxUnit: info.CountUnit,
  12972. MinUnit: "",
  12973. }
  12974. service.CreatedCancelStock(cancelStockInfo)
  12975. service.CreateDrugFlowOne(flow)
  12976. }
  12977. }
  12978. }
  12979. return err
  12980. }
  12981. func (this *HisApiController) DeleteNCDS() {
  12982. id, _ := this.GetInt64("id", 0)
  12983. if id > 0 {
  12984. service.DeletePsnNCDSRecordById(id)
  12985. this.ServeSuccessJSON(map[string]interface{}{
  12986. "msg": "删除成功",
  12987. })
  12988. } else {
  12989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12990. return
  12991. }
  12992. }
  12993. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12994. id, _ := c.GetInt64("id")
  12995. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12996. c.ServeSuccessJSON(map[string]interface{}{
  12997. "advice": advice,
  12998. })
  12999. return
  13000. }
  13001. func (c *HisApiController) GetHisMonthChargePatientList() {
  13002. record_date := c.GetString("record_date")
  13003. start_time := c.GetString("start_time")
  13004. end_time := c.GetString("end_time")
  13005. timeLayout := "2006-01-02"
  13006. loc, _ := time.LoadLocation("Local")
  13007. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13008. if err != nil {
  13009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13010. return
  13011. }
  13012. if err != nil {
  13013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13014. return
  13015. }
  13016. recordDateTime := theTime.Unix()
  13017. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13018. if err != nil {
  13019. }
  13020. startRecordDateTime := startTime.Unix()
  13021. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13022. if err != nil {
  13023. }
  13024. endRecordDateTime := endTime.Unix()
  13025. adminInfo := c.GetAdminUserInfo()
  13026. var tempMonthChargePatients []*service.MonthChargePatients
  13027. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13028. for _, item := range tempPatients {
  13029. //过滤没有处方的
  13030. if len(item.HisPrescription) == 0 {
  13031. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13032. }
  13033. }
  13034. c.ServeSuccessJSON(map[string]interface{}{
  13035. "list": tempMonthChargePatients,
  13036. })
  13037. }
  13038. // PrescriptionDifference 医嘱数量差值结构体
  13039. type PrescriptionDrugDifference struct {
  13040. DrugID int64 //基础库药品id
  13041. ID int64 //医嘱id
  13042. Difference float64 //差值
  13043. Unit string //单位
  13044. }
  13045. type PrescriptionGoodDifference struct {
  13046. GoodID int64 //基础库项目耗材id
  13047. ID int64 //医嘱id
  13048. Difference int64 //差值
  13049. Unit string //单位
  13050. Type int64 //类型
  13051. }
  13052. type EditCustomData struct {
  13053. adviceList []*models.HisDoctorAdviceInfo
  13054. projectList []*models.HisPrescriptionProject
  13055. }
  13056. type SrcCustomData struct {
  13057. adviceList []*models.HisDoctorAdviceInfo
  13058. projectList []*models.HisPrescriptionProject
  13059. }
  13060. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13061. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13062. differences := make([]*PrescriptionDrugDifference, 0)
  13063. // 创建一个 map 来存储第一个切片中的药品信息
  13064. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13065. for _, advice := range firstPrescription {
  13066. firstMap[advice.DrugId] = advice
  13067. }
  13068. // 遍历第二个切片中的药品信息,并比较数量差值
  13069. for _, advice := range secondPrescription {
  13070. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13071. diff := &PrescriptionDrugDifference{
  13072. DrugID: advice.DrugId,
  13073. ID: firstAdvice.ID,
  13074. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13075. Unit: firstAdvice.PrescribingNumberUnit,
  13076. }
  13077. differences = append(differences, diff)
  13078. }
  13079. }
  13080. return differences
  13081. }
  13082. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13083. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13084. differences := make([]*PrescriptionGoodDifference, 0)
  13085. // 创建一个 map 来存储第一个切片中的耗材信息
  13086. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13087. for _, good := range firstPrescription {
  13088. firstMap[good.ProjectId] = good
  13089. }
  13090. // 遍历第二个切片中的耗材信息,并比较数量差值
  13091. for _, good := range secondPrescription {
  13092. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13093. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13094. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13095. diff := &PrescriptionGoodDifference{
  13096. GoodID: good.ProjectId,
  13097. ID: firstGood.ID,
  13098. Difference: count - firstCount,
  13099. Unit: firstGood.Unit,
  13100. Type: firstGood.Type,
  13101. }
  13102. differences = append(differences, diff)
  13103. }
  13104. }
  13105. return differences
  13106. }
  13107. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13108. var adviceList []*models.HisDoctorAdviceInfo
  13109. var projectList []*models.HisPrescriptionProject
  13110. var advice_ids []int64
  13111. var project_ids []int64
  13112. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13113. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13114. //var tempPrescription *models.HisPrescriptionProjectscription
  13115. if len(prescriptions) > 0 {
  13116. for _, item := range prescriptions {
  13117. items := item.(map[string]interface{})
  13118. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13119. advices := items["advices"].([]interface{})
  13120. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13121. groupNo := int64(0)
  13122. ctime := time.Now().Unix()
  13123. mtime := ctime
  13124. if len(advices) > 0 {
  13125. for _, advice := range advices {
  13126. var s models.HisDoctorAdviceInfo
  13127. s.AdviceType = 2
  13128. s.StopState = 2
  13129. s.ExecutionState = 2
  13130. s.Status = 1
  13131. s.Groupno = groupNo
  13132. s.CreatedTime = ctime
  13133. s.UpdatedTime = mtime
  13134. s.IsSettle = 2
  13135. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13136. //存储切片中
  13137. if s.ID > 0 {
  13138. advice_ids = append(advice_ids, s.ID)
  13139. adviceList = append(adviceList, &s)
  13140. }
  13141. }
  13142. }
  13143. }
  13144. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13145. projects := items["project"].([]interface{})
  13146. if len(projects) > 0 {
  13147. for _, project := range projects {
  13148. var p models.HisPrescriptionProject
  13149. p.Ctime = time.Now().Unix()
  13150. p.Mtime = time.Now().Unix()
  13151. p.Status = 1
  13152. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13153. if p.ID > 0 {
  13154. project_ids = append(project_ids, p.ID)
  13155. projectList = append(projectList, &p)
  13156. }
  13157. }
  13158. }
  13159. }
  13160. }
  13161. }
  13162. }
  13163. editCustomData.projectList = projectList
  13164. editCustomData.adviceList = adviceList
  13165. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13166. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13167. srcCustomData.adviceList = list
  13168. srcCustomData.projectList = list2
  13169. return
  13170. }
  13171. func (c *HisApiController) GetAllGoodInforList() {
  13172. orgId := c.GetAdminUserInfo().CurrentOrgId
  13173. goodList, _ := service.GetAllGoodList(orgId)
  13174. c.ServeSuccessJSON(map[string]interface{}{
  13175. "goodList": goodList,
  13176. })
  13177. return
  13178. }
  13179. func (this *HisApiController) SaveGoodList() {
  13180. project_name := this.GetString("project_name")
  13181. sort, _ := this.GetInt64("sort")
  13182. orgId := this.GetAdminUserInfo().CurrentOrgId
  13183. dataBody := make(map[string]interface{}, 0)
  13184. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13185. if err != nil {
  13186. utils.ErrorLog(err.Error())
  13187. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13188. return
  13189. }
  13190. goodTeam := models.XtGoodTeam{
  13191. ProjectName: project_name,
  13192. Sort: sort,
  13193. UserOrgId: orgId,
  13194. Status: 1,
  13195. Ctime: time.Now().Unix(),
  13196. Mtime: time.Now().Unix(),
  13197. }
  13198. service.CreateGoodTeam(goodTeam)
  13199. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13200. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13201. infos, _ := dataBody["info"].([]interface{})
  13202. if len(infos) > 0 {
  13203. for _, item := range infos {
  13204. items := item.(map[string]interface{})
  13205. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13206. utils.ErrorLog("good_id")
  13207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13208. return
  13209. }
  13210. good_id := int64(items["good_id"].(float64))
  13211. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13212. utils.ErrorLog("number")
  13213. }
  13214. number := int64(items["number"].(float64))
  13215. xtGoodTeamList := models.XtGoodTeamList{
  13216. GoodId: good_id,
  13217. Count: number,
  13218. TeamId: lastGoodTeam.ID,
  13219. UserOrgId: orgId,
  13220. Status: 1,
  13221. Ctime: time.Now().Unix(),
  13222. Mtime: time.Now().Unix(),
  13223. }
  13224. service.CreateGoodList(xtGoodTeamList)
  13225. }
  13226. this.ServeSuccessJSON(map[string]interface{}{
  13227. "lastGoodTeam": lastGoodTeam,
  13228. })
  13229. }
  13230. }
  13231. return
  13232. }
  13233. func (this *HisApiController) GetGoodList() {
  13234. orgId := this.GetAdminUserInfo().CurrentOrgId
  13235. limit, _ := this.GetInt64("limit")
  13236. page, _ := this.GetInt64("page")
  13237. keyword := this.GetString("keyword")
  13238. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13239. this.ServeSuccessJSON(map[string]interface{}{
  13240. "list": list,
  13241. "total": total,
  13242. })
  13243. }
  13244. func (this *HisApiController) GetGoodNameDetail() {
  13245. id, _ := this.GetInt64("id")
  13246. orgId := this.GetAdminUserInfo().CurrentOrgId
  13247. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13248. goodList, _ := service.GetAllGoodList(orgId)
  13249. this.ServeSuccessJSON(map[string]interface{}{
  13250. "goodNameDetail": goodNameDetail,
  13251. "goodList": goodList,
  13252. })
  13253. }
  13254. func (this *HisApiController) UpdateGoodList() {
  13255. project_name := this.GetString("project_name")
  13256. sort, _ := this.GetInt64("sort")
  13257. id, _ := this.GetInt64("id")
  13258. orgId := this.GetAdminUserInfo().CurrentOrgId
  13259. dataBody := make(map[string]interface{}, 0)
  13260. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13261. if err != nil {
  13262. utils.ErrorLog(err.Error())
  13263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13264. return
  13265. }
  13266. goodTeam := models.XtGoodTeam{
  13267. ProjectName: project_name,
  13268. Sort: sort,
  13269. UserOrgId: orgId,
  13270. Status: 1,
  13271. Ctime: time.Now().Unix(),
  13272. Mtime: time.Now().Unix(),
  13273. ID: id,
  13274. }
  13275. service.SaveGoodTeam(goodTeam)
  13276. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13277. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13278. infos, _ := dataBody["info"].([]interface{})
  13279. if len(infos) > 0 {
  13280. for _, item := range infos {
  13281. items := item.(map[string]interface{})
  13282. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13283. utils.ErrorLog("good_id")
  13284. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13285. return
  13286. }
  13287. good_id := int64(items["good_id"].(float64))
  13288. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13289. utils.ErrorLog("id")
  13290. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13291. return
  13292. }
  13293. id := int64(items["id"].(float64))
  13294. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13295. utils.ErrorLog("number")
  13296. }
  13297. number := int64(items["number"].(float64))
  13298. xtGoodTeamList := models.XtGoodTeamList{
  13299. ID: id,
  13300. GoodId: good_id,
  13301. Count: number,
  13302. TeamId: lastGoodTeam.ID,
  13303. UserOrgId: orgId,
  13304. Status: 1,
  13305. Ctime: time.Now().Unix(),
  13306. Mtime: time.Now().Unix(),
  13307. }
  13308. service.SaveGoodList(xtGoodTeamList)
  13309. }
  13310. this.ServeSuccessJSON(map[string]interface{}{
  13311. "lastGoodTeam": lastGoodTeam,
  13312. })
  13313. }
  13314. }
  13315. return
  13316. }
  13317. func (this *HisApiController) DeleteGoodTeam() {
  13318. id, _ := this.GetInt64("id")
  13319. team, _ := service.DeleteGoodTeam(id)
  13320. this.ServeSuccessJSON(map[string]interface{}{
  13321. "team": team,
  13322. })
  13323. }
  13324. func (this *HisApiController) DeleteGood() {
  13325. id, _ := this.GetInt64("id")
  13326. good, _ := service.DeleteGood(id)
  13327. this.ServeSuccessJSON(map[string]interface{}{
  13328. "good": good,
  13329. })
  13330. }