his_api_controller.go 585KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072
  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 || adminInfo.CurrentOrgId == 9671 {
  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. if s.ID > 0 {
  3394. //查询改药品是否已经停用
  3395. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3396. if base.ID > 0 {
  3397. tx.Rollback()
  3398. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3399. return
  3400. }
  3401. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3402. if drugMedical.SumCount == 0 {
  3403. tx.Rollback()
  3404. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3405. return
  3406. }
  3407. }
  3408. }
  3409. //赤峰
  3410. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3411. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3412. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3413. if info.RetailPrice > 0 {
  3414. if s.DeliveryWay == "口服" {
  3415. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3416. s.Price = drug.RetailPrice
  3417. }
  3418. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3419. s.Price = info.RetailPrice
  3420. }
  3421. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3422. s.Price = info.RetailPrice
  3423. }
  3424. }
  3425. }
  3426. }
  3427. service.CreateHisDoctorAdviceOne(&s, tx)
  3428. tx.Commit()
  3429. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3430. redis.Set(keySix, "", time.Second)
  3431. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3432. redis.Set(keyFive, "", time.Second)
  3433. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3434. redis.Set(keyEight, "", time.Second)
  3435. defer redis.Close()
  3436. }
  3437. }
  3438. }
  3439. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3440. projects := items["project"].([]interface{})
  3441. if len(projects) > 0 {
  3442. for _, project := range projects {
  3443. tx := db.Begin()
  3444. // 在函数结束时处理事务回滚
  3445. defer func() {
  3446. if r := recover(); r != nil {
  3447. tx.Rollback()
  3448. }
  3449. }()
  3450. var p models.HisPrescriptionProject
  3451. p.PrescriptionId = tempPrescription.ID
  3452. p.PatientId = patient_id
  3453. p.RecordDate = theTime3.Unix()
  3454. p.Doctor = doctor_id
  3455. p.UserOrgId = adminInfo.CurrentOrgId
  3456. p.HisPatientId = his_patient_id
  3457. p.Status = 1
  3458. p.StartTime = pTime
  3459. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3460. if errcode > 0 {
  3461. tx.Rollback()
  3462. c.ServeFailJSONWithSGJErrorCode(errcode)
  3463. return
  3464. }
  3465. if p.ID == 0 {
  3466. p.IsOut = 2
  3467. }
  3468. if p.ID > 0 {
  3469. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3470. p.IsOut = projectDetail.IsOut
  3471. }
  3472. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3473. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3474. if p.Type == 3 {
  3475. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3476. if p.Price != lastWarehouse.PackingPrice {
  3477. p.Price = lastWarehouse.PackingPrice
  3478. }
  3479. if p.Price == 0 {
  3480. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3481. p.Price = lastWarehouseTwo.PackingPrice
  3482. }
  3483. if p.Unit == "" {
  3484. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3485. p.Unit = goodInfoOne.PackingUnit
  3486. }
  3487. }
  3488. }
  3489. if adminInfo.CurrentOrgId != 10206 {
  3490. if p.Type == 3 {
  3491. if p.ID == 0 {
  3492. //查询该耗材是否停用
  3493. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3494. //表示该耗材已经停用,不能保存
  3495. if goodInfoSeven.ID == 0 {
  3496. tx.Rollback()
  3497. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3498. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3499. return
  3500. }
  3501. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3502. if goodInfoOne.SumCount == 0 {
  3503. tx.Rollback()
  3504. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3505. return
  3506. }
  3507. }
  3508. if p.ID > 0 {
  3509. //查询该耗材是否停用
  3510. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3511. //表示该耗材已经停用,不能保存
  3512. if goodInfoSeven.ID == 0 {
  3513. tx.Rollback()
  3514. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3515. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3516. return
  3517. }
  3518. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3519. if goodInfoOne.SumCount == 0 {
  3520. tx.Rollback()
  3521. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3522. return
  3523. }
  3524. }
  3525. }
  3526. }
  3527. //查询保存耗材出库开关是否打开
  3528. if p.PatientId != 30038 {
  3529. //用机构ID区分
  3530. if adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10164 {
  3531. if goodOutConfig.IsOpen == 1 {
  3532. //耗材出库
  3533. if p.Type == 3 {
  3534. //对比当前数据和历史出库数据
  3535. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3536. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3537. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3538. //如果当前处方数量大于历史数据,则需要出库
  3539. if nowCount > historyCount {
  3540. var cha_count int64
  3541. cha_count = nowCount - historyCount
  3542. timeStr := time.Now().Format("2006-01-02")
  3543. timeArr := strings.Split(timeStr, "-")
  3544. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3545. total = total + 1
  3546. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3547. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3548. number = number + total
  3549. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3550. operation_time := time.Now().Unix()
  3551. creater := c.GetAdminUserInfo().AdminUser.Id
  3552. recordDateStr := time.Now().Format("2006-01-02")
  3553. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3554. nowtime := recordDate.Unix()
  3555. warehouseOut := models.WarehouseOut{
  3556. WarehouseOutOrderNumber: warehousing_out_order,
  3557. OperationTime: operation_time,
  3558. OrgId: adminInfo.CurrentOrgId,
  3559. Creater: creater,
  3560. Ctime: time.Now().Unix(),
  3561. Status: 1,
  3562. WarehouseOutTime: nowtime,
  3563. Type: 1,
  3564. StorehouseId: storeConfig.StorehouseOutInfo,
  3565. IsCheck: 1,
  3566. IsSys: 1,
  3567. }
  3568. //查询是否生成出库单
  3569. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3570. if out.ID == 0 {
  3571. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3572. }
  3573. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3574. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3575. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3576. dialyPrepareOne := models.DialysisBeforePrepare{
  3577. GoodTypeId: goodObj.GoodTypeId,
  3578. GoodId: p.ProjectId,
  3579. PatientId: p.PatientId,
  3580. RecordDate: p.RecordDate,
  3581. UserOrgId: adminInfo.CurrentOrgId,
  3582. Count: cha_count,
  3583. Ctime: time.Now().Unix(),
  3584. Creater: creater,
  3585. Status: 1,
  3586. StorehouseId: houseConfig.StorehouseOutInfo,
  3587. ProjectId: p.ID,
  3588. }
  3589. //出库
  3590. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3591. }
  3592. //如果当前处方数量小于历史数据,怎需要退库
  3593. if nowCount < historyCount {
  3594. var cha_count int64
  3595. cha_count = historyCount - nowCount
  3596. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3597. creater := c.GetAdminUserInfo().AdminUser.Id
  3598. newPrescriptionProject := &models.HisPrescriptionProject{
  3599. ID: p.ID,
  3600. ProjectId: p.ProjectId,
  3601. Price: p.Price,
  3602. UserOrgId: p.UserOrgId,
  3603. Status: 1,
  3604. Ctime: time.Now().Unix(),
  3605. Mtime: time.Now().Unix(),
  3606. PatientId: p.PatientId,
  3607. HisPatientId: p.HisPatientId,
  3608. RecordDate: p.RecordDate,
  3609. PrescriptionId: p.PrescriptionId,
  3610. Count: p.Count,
  3611. FeedetlSn: p.FeedetlSn,
  3612. MedListCodg: p.MedListCodg,
  3613. SingleDose: p.SingleDose,
  3614. DeliveryWay: p.DeliveryWay,
  3615. ExecutionFrequency: p.ExecutionFrequency,
  3616. Day: p.Day,
  3617. HisProject: models.HisProject{},
  3618. GoodInfo: models.GoodInfo{},
  3619. Remark: p.Remark,
  3620. Unit: p.Unit,
  3621. Type: p.Type,
  3622. Doctor: p.Doctor,
  3623. ExecutionTime: p.ExecutionTime,
  3624. ExecutionStaff: p.ExecutionStaff,
  3625. ExecutionState: p.ExecutionState,
  3626. CheckTime: p.CheckTime,
  3627. CheckState: p.CheckState,
  3628. Checker: p.Checker,
  3629. StartTime: p.StartTime,
  3630. TeamId: p.TeamId,
  3631. XtHisProjectTeam: models.XtHisProjectTeam{},
  3632. FrequencyType: p.FrequencyType,
  3633. DayCount: p.DayCount,
  3634. WeekDay: p.WeekDay,
  3635. IsCheckTeam: p.IsCheckTeam,
  3636. HisOrderInfo: models.HisOrderInfo{},
  3637. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3638. IsOut: p.IsOut,
  3639. YbSyncStatus: p.YbSyncStatus,
  3640. }
  3641. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3642. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3643. }
  3644. if nowCount == historyCount {
  3645. if historyCount == 0 {
  3646. recordDateStr := time.Now().Format("2006-01-02")
  3647. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3648. nowtime := recordDate.Unix()
  3649. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3650. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3651. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3652. creater := c.GetAdminUserInfo().AdminUser.Id
  3653. dialyPrepareOne := models.DialysisBeforePrepare{
  3654. GoodTypeId: goodObj.GoodTypeId,
  3655. GoodId: p.ProjectId,
  3656. PatientId: p.PatientId,
  3657. RecordDate: p.RecordDate,
  3658. UserOrgId: adminInfo.CurrentOrgId,
  3659. Count: nowCount,
  3660. Ctime: time.Now().Unix(),
  3661. Creater: creater,
  3662. Status: 1,
  3663. StorehouseId: houseConfig.StorehouseOutInfo,
  3664. ProjectId: p.ID,
  3665. }
  3666. //出库
  3667. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3668. }
  3669. }
  3670. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3671. //查询历史出库数据
  3672. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3673. var out_count_five int64
  3674. for _, item := range flowGood {
  3675. out_count_five += item.Count
  3676. }
  3677. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3678. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3679. if out_count_five != parseIntCount {
  3680. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3681. detail := models.AutomaticReduceDetail{
  3682. WarehouseOutId: 0,
  3683. WarehouseOutOrderNumber: "",
  3684. PatientId: p.PatientId,
  3685. Ctime: time.Now().Unix(),
  3686. Mtime: 0,
  3687. Status: 1,
  3688. RecordTime: p.RecordDate,
  3689. OrgId: p.UserOrgId,
  3690. GoodId: p.ProjectId,
  3691. GoodTypeId: 0,
  3692. Count: parseIntCount,
  3693. Type: 0,
  3694. ProjectId: lastHisProject.ID,
  3695. StorehouseId: 0,
  3696. }
  3697. service.CreateNewAutoDetail(detail, tx)
  3698. }
  3699. // //查询耗材最后一次出库记录
  3700. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3701. // //查询默认出库仓库库存
  3702. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3703. // if len(wareOut) > 0 {
  3704. //
  3705. // for _, it := range wareOut {
  3706. // //回退库存
  3707. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3708. //
  3709. // //删除出库记录
  3710. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3711. //
  3712. // }
  3713. // }
  3714. //
  3715. // timeStr := time.Now().Format("2006-01-02")
  3716. // timeArr := strings.Split(timeStr, "-")
  3717. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3718. //
  3719. // total = total + 1
  3720. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3721. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3722. // number = number + total
  3723. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3724. //
  3725. // operation_time := time.Now().Unix()
  3726. // creater := c.GetAdminUserInfo().AdminUser.Id
  3727. //
  3728. // recordDateStr := time.Now().Format("2006-01-02")
  3729. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3730. // nowtime := recordDate.Unix()
  3731. // warehouseOut := models.WarehouseOut{
  3732. // WarehouseOutOrderNumber: warehousing_out_order,
  3733. // OperationTime: operation_time,
  3734. // OrgId: adminInfo.CurrentOrgId,
  3735. // Creater: creater,
  3736. // Ctime: time.Now().Unix(),
  3737. // Status: 1,
  3738. // WarehouseOutTime: nowtime,
  3739. // Type: 1,
  3740. // StorehouseId: storeConfig.StorehouseOutInfo,
  3741. // IsCheck: 1,
  3742. // IsSys: 1,
  3743. // }
  3744. // //查询是否生成出库单
  3745. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3746. // if out.ID == 0 {
  3747. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3748. // }
  3749. //
  3750. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3751. //
  3752. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3753. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3754. //
  3755. // dialyPrepareOne := models.DialysisBeforePrepare{
  3756. // GoodTypeId: goodObj.GoodTypeId,
  3757. // GoodId: p.ProjectId,
  3758. // PatientId: p.PatientId,
  3759. // RecordDate: p.RecordDate,
  3760. // UserOrgId: adminInfo.CurrentOrgId,
  3761. // Count: parseIntCount,
  3762. // Ctime: time.Now().Unix(),
  3763. // Creater: creater,
  3764. // Status: 1,
  3765. // StorehouseId: houseConfig.StorehouseOutInfo,
  3766. // ProjectId: lastHisProject.ID,
  3767. // }
  3768. // //判断是否是零用耗材(非零用)
  3769. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3770. //
  3771. // //查询历史出库数据
  3772. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3773. // var out_count int64
  3774. // for _, item := range flowGood {
  3775. // out_count += item.Count
  3776. // }
  3777. // //如果历史数和当前数据不想等才进行退库出库
  3778. // if out_count != parseIntCount {
  3779. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3780. //
  3781. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3782. // detail := models.AutomaticReduceDetail{
  3783. // WarehouseOutId: 0,
  3784. // WarehouseOutOrderNumber: "",
  3785. // PatientId: p.PatientId,
  3786. // Ctime: time.Now().Unix(),
  3787. // Mtime: 0,
  3788. // Status: 1,
  3789. // RecordTime: p.RecordDate,
  3790. // OrgId: p.UserOrgId,
  3791. // GoodId: p.ProjectId,
  3792. // GoodTypeId: 0,
  3793. // Count: parseIntCount,
  3794. // Type: 0,
  3795. // ProjectId: lastHisProject.ID,
  3796. // StorehouseId: 0,
  3797. // }
  3798. //
  3799. // service.CreateNewAutoDetail(detail, tx)
  3800. //
  3801. // //查询剩余库存
  3802. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3803. // var sum_count int64
  3804. // for _, item := range goodList {
  3805. // sum_count += item.StockCount
  3806. // }
  3807. //
  3808. // //更新剩余库存
  3809. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3810. //
  3811. // //耗材
  3812. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3813. //
  3814. // }
  3815. // //判断是否是零用耗材(零用但是是出库耗材)
  3816. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3817. //
  3818. // //查询历史出库数据
  3819. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3820. // var out_count int64
  3821. // for _, item := range flowGood {
  3822. // out_count += item.Count
  3823. // }
  3824. // //如果历史数和当前数据不想等才进行退库出库
  3825. // if out_count != parseIntCount {
  3826. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3827. //
  3828. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3829. // detail := models.AutomaticReduceDetail{
  3830. // WarehouseOutId: 0,
  3831. // WarehouseOutOrderNumber: "",
  3832. // PatientId: p.PatientId,
  3833. // Ctime: time.Now().Unix(),
  3834. // Mtime: 0,
  3835. // Status: 1,
  3836. // RecordTime: p.RecordDate,
  3837. // OrgId: p.UserOrgId,
  3838. // GoodId: p.ProjectId,
  3839. // GoodTypeId: 0,
  3840. // Count: parseIntCount,
  3841. // Type: 0,
  3842. // ProjectId: p.ID,
  3843. // StorehouseId: 0,
  3844. // }
  3845. //
  3846. // service.CreateNewAutoDetail(detail, tx)
  3847. //
  3848. // //查询剩余库存
  3849. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3850. // var sum_count int64
  3851. // for _, item := range goodList {
  3852. // sum_count += item.StockCount
  3853. // }
  3854. //
  3855. // //更新剩余库存
  3856. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3857. //
  3858. // //耗材
  3859. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3860. // }
  3861. //
  3862. // }
  3863. //
  3864. // }
  3865. //
  3866. //}
  3867. //记录日志
  3868. byterequest, _ := json.Marshal(p)
  3869. adviceLog := models.XtDoctorAdviceLog{
  3870. UserOrgId: p.UserOrgId,
  3871. PatientId: p.PatientId,
  3872. AdminUserId: adminInfo.AdminUser.Id,
  3873. Module: 1,
  3874. ErrLog: string(byterequest),
  3875. Status: 1,
  3876. Ctime: time.Now().Unix(),
  3877. Mtime: 0,
  3878. Source: "电脑端新建his项目",
  3879. RecordDate: p.RecordDate,
  3880. }
  3881. service.CreateDoctorAdviceLog(adviceLog)
  3882. projectList = append(projectList, p)
  3883. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3884. //新增或者编辑项目,修改对应的标签数据
  3885. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3886. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3887. var label models.HisLabelPrintInfo
  3888. project, _ := service.GetProjectDetail(p.ProjectId)
  3889. if project.CostClassify == 3 { //类别为检验检查
  3890. if p.TeamId > 0 { //检验检查组套
  3891. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3892. if tempLabel.ID == 0 {
  3893. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3894. label.Number = tempPrescription.PrescriptionNumber
  3895. label.ProjectId = project.ID
  3896. label.Status = 1
  3897. label.IsPrint = 2
  3898. label.DoctorId = info.DoctorId
  3899. label.UserOrgId = p.UserOrgId
  3900. label.PatientId = patient_id
  3901. label.RecordDate = recordDateTime
  3902. label.Ctime = time.Now().Unix()
  3903. label.Mtime = time.Now().Unix()
  3904. label.ItemId = p.TeamId
  3905. label.FeedetlSn = p.FeedetlSn
  3906. label.PProjectId = p.ID
  3907. label.ProjectName = team.ProjectTeam
  3908. label.PatientName = patient.Name
  3909. service.CreateNewHisLabelRecord(&label, tx)
  3910. }
  3911. } else { //单条检验检查项目
  3912. label.Number = tempPrescription.PrescriptionNumber
  3913. label.ProjectId = project.ID
  3914. label.Status = 1
  3915. label.DoctorId = info.DoctorId
  3916. label.UserOrgId = p.UserOrgId
  3917. label.PatientId = patient_id
  3918. label.RecordDate = recordDateTime
  3919. label.IsPrint = 2
  3920. label.Ctime = time.Now().Unix()
  3921. label.Mtime = time.Now().Unix()
  3922. label.FeedetlSn = p.FeedetlSn
  3923. label.PProjectId = p.ID
  3924. label.ItemId = p.TeamId
  3925. label.ProjectName = project.ProjectName
  3926. label.PatientName = patient.Name
  3927. service.CreateNewHisLabelRecord(&label, tx)
  3928. }
  3929. }
  3930. }
  3931. }
  3932. }
  3933. }
  3934. }
  3935. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  3936. //耗材出库
  3937. if p.Type == 3 {
  3938. //对比当前数据和历史出库数据
  3939. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3940. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3941. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3942. //如果当前处方数量大于历史数据,则需要出库
  3943. if nowCount > historyCount {
  3944. var cha_count int64
  3945. cha_count = nowCount - historyCount
  3946. timeStr := time.Now().Format("2006-01-02")
  3947. timeArr := strings.Split(timeStr, "-")
  3948. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3949. total = total + 1
  3950. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3951. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3952. number = number + total
  3953. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3954. operation_time := time.Now().Unix()
  3955. creater := c.GetAdminUserInfo().AdminUser.Id
  3956. recordDateStr := time.Now().Format("2006-01-02")
  3957. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3958. nowtime := recordDate.Unix()
  3959. warehouseOut := models.WarehouseOut{
  3960. WarehouseOutOrderNumber: warehousing_out_order,
  3961. OperationTime: operation_time,
  3962. OrgId: adminInfo.CurrentOrgId,
  3963. Creater: creater,
  3964. Ctime: time.Now().Unix(),
  3965. Status: 1,
  3966. WarehouseOutTime: nowtime,
  3967. Type: 1,
  3968. StorehouseId: storeConfig.StorehouseOutInfo,
  3969. IsCheck: 1,
  3970. IsSys: 1,
  3971. }
  3972. //查询是否生成出库单
  3973. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3974. if out.ID == 0 {
  3975. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3976. }
  3977. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3978. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3979. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3980. dialyPrepareOne := models.DialysisBeforePrepare{
  3981. GoodTypeId: goodObj.GoodTypeId,
  3982. GoodId: p.ProjectId,
  3983. PatientId: p.PatientId,
  3984. RecordDate: p.RecordDate,
  3985. UserOrgId: adminInfo.CurrentOrgId,
  3986. Count: cha_count,
  3987. Ctime: time.Now().Unix(),
  3988. Creater: creater,
  3989. Status: 1,
  3990. StorehouseId: houseConfig.StorehouseOutInfo,
  3991. ProjectId: p.ID,
  3992. }
  3993. //出库
  3994. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3995. }
  3996. //如果当前处方数量小于历史数据,怎需要退库
  3997. if nowCount < historyCount {
  3998. var cha_count int64
  3999. cha_count = historyCount - nowCount
  4000. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4001. creater := c.GetAdminUserInfo().AdminUser.Id
  4002. newPrescriptionProject := &models.HisPrescriptionProject{
  4003. ID: p.ID,
  4004. ProjectId: p.ProjectId,
  4005. Price: p.Price,
  4006. UserOrgId: p.UserOrgId,
  4007. Status: 1,
  4008. Ctime: time.Now().Unix(),
  4009. Mtime: time.Now().Unix(),
  4010. PatientId: p.PatientId,
  4011. HisPatientId: p.HisPatientId,
  4012. RecordDate: p.RecordDate,
  4013. PrescriptionId: p.PrescriptionId,
  4014. Count: p.Count,
  4015. FeedetlSn: p.FeedetlSn,
  4016. MedListCodg: p.MedListCodg,
  4017. SingleDose: p.SingleDose,
  4018. DeliveryWay: p.DeliveryWay,
  4019. ExecutionFrequency: p.ExecutionFrequency,
  4020. Day: p.Day,
  4021. HisProject: models.HisProject{},
  4022. GoodInfo: models.GoodInfo{},
  4023. Remark: p.Remark,
  4024. Unit: p.Unit,
  4025. Type: p.Type,
  4026. Doctor: p.Doctor,
  4027. ExecutionTime: p.ExecutionTime,
  4028. ExecutionStaff: p.ExecutionStaff,
  4029. ExecutionState: p.ExecutionState,
  4030. CheckTime: p.CheckTime,
  4031. CheckState: p.CheckState,
  4032. Checker: p.Checker,
  4033. StartTime: p.StartTime,
  4034. TeamId: p.TeamId,
  4035. XtHisProjectTeam: models.XtHisProjectTeam{},
  4036. FrequencyType: p.FrequencyType,
  4037. DayCount: p.DayCount,
  4038. WeekDay: p.WeekDay,
  4039. IsCheckTeam: p.IsCheckTeam,
  4040. HisOrderInfo: models.HisOrderInfo{},
  4041. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4042. IsOut: p.IsOut,
  4043. YbSyncStatus: p.YbSyncStatus,
  4044. }
  4045. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4046. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4047. }
  4048. if nowCount == historyCount {
  4049. if historyCount == 0 {
  4050. recordDateStr := time.Now().Format("2006-01-02")
  4051. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4052. nowtime := recordDate.Unix()
  4053. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4054. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4055. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4056. creater := c.GetAdminUserInfo().AdminUser.Id
  4057. dialyPrepareOne := models.DialysisBeforePrepare{
  4058. GoodTypeId: goodObj.GoodTypeId,
  4059. GoodId: p.ProjectId,
  4060. PatientId: p.PatientId,
  4061. RecordDate: p.RecordDate,
  4062. UserOrgId: adminInfo.CurrentOrgId,
  4063. Count: nowCount,
  4064. Ctime: time.Now().Unix(),
  4065. Creater: creater,
  4066. Status: 1,
  4067. StorehouseId: houseConfig.StorehouseOutInfo,
  4068. ProjectId: p.ID,
  4069. }
  4070. //出库
  4071. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4072. }
  4073. }
  4074. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4075. //查询历史出库数据
  4076. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4077. var out_count_five int64
  4078. for _, item := range flowGood {
  4079. out_count_five += item.Count
  4080. }
  4081. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4082. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4083. if out_count_five != parseIntCount {
  4084. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4085. detail := models.AutomaticReduceDetail{
  4086. WarehouseOutId: 0,
  4087. WarehouseOutOrderNumber: "",
  4088. PatientId: p.PatientId,
  4089. Ctime: time.Now().Unix(),
  4090. Mtime: 0,
  4091. Status: 1,
  4092. RecordTime: p.RecordDate,
  4093. OrgId: p.UserOrgId,
  4094. GoodId: p.ProjectId,
  4095. GoodTypeId: 0,
  4096. Count: parseIntCount,
  4097. Type: 0,
  4098. ProjectId: lastHisProject.ID,
  4099. StorehouseId: 0,
  4100. }
  4101. service.CreateNewAutoDetail(detail, tx)
  4102. }
  4103. // //查询耗材最后一次出库记录
  4104. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4105. // //查询默认出库仓库库存
  4106. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4107. // if len(wareOut) > 0 {
  4108. //
  4109. // for _, it := range wareOut {
  4110. // //回退库存
  4111. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4112. //
  4113. // //删除出库记录
  4114. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4115. //
  4116. // }
  4117. // }
  4118. //
  4119. // timeStr := time.Now().Format("2006-01-02")
  4120. // timeArr := strings.Split(timeStr, "-")
  4121. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4122. //
  4123. // total = total + 1
  4124. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4125. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4126. // number = number + total
  4127. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4128. //
  4129. // operation_time := time.Now().Unix()
  4130. // creater := c.GetAdminUserInfo().AdminUser.Id
  4131. //
  4132. // recordDateStr := time.Now().Format("2006-01-02")
  4133. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4134. // nowtime := recordDate.Unix()
  4135. // warehouseOut := models.WarehouseOut{
  4136. // WarehouseOutOrderNumber: warehousing_out_order,
  4137. // OperationTime: operation_time,
  4138. // OrgId: adminInfo.CurrentOrgId,
  4139. // Creater: creater,
  4140. // Ctime: time.Now().Unix(),
  4141. // Status: 1,
  4142. // WarehouseOutTime: nowtime,
  4143. // Type: 1,
  4144. // StorehouseId: storeConfig.StorehouseOutInfo,
  4145. // IsCheck: 1,
  4146. // IsSys: 1,
  4147. // }
  4148. // //查询是否生成出库单
  4149. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4150. // if out.ID == 0 {
  4151. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4152. // }
  4153. //
  4154. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4155. //
  4156. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4157. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4158. //
  4159. // dialyPrepareOne := models.DialysisBeforePrepare{
  4160. // GoodTypeId: goodObj.GoodTypeId,
  4161. // GoodId: p.ProjectId,
  4162. // PatientId: p.PatientId,
  4163. // RecordDate: p.RecordDate,
  4164. // UserOrgId: adminInfo.CurrentOrgId,
  4165. // Count: parseIntCount,
  4166. // Ctime: time.Now().Unix(),
  4167. // Creater: creater,
  4168. // Status: 1,
  4169. // StorehouseId: houseConfig.StorehouseOutInfo,
  4170. // ProjectId: lastHisProject.ID,
  4171. // }
  4172. // //判断是否是零用耗材(非零用)
  4173. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4174. //
  4175. // //查询历史出库数据
  4176. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4177. // var out_count int64
  4178. // for _, item := range flowGood {
  4179. // out_count += item.Count
  4180. // }
  4181. // //如果历史数和当前数据不想等才进行退库出库
  4182. // if out_count != parseIntCount {
  4183. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4184. //
  4185. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4186. // detail := models.AutomaticReduceDetail{
  4187. // WarehouseOutId: 0,
  4188. // WarehouseOutOrderNumber: "",
  4189. // PatientId: p.PatientId,
  4190. // Ctime: time.Now().Unix(),
  4191. // Mtime: 0,
  4192. // Status: 1,
  4193. // RecordTime: p.RecordDate,
  4194. // OrgId: p.UserOrgId,
  4195. // GoodId: p.ProjectId,
  4196. // GoodTypeId: 0,
  4197. // Count: parseIntCount,
  4198. // Type: 0,
  4199. // ProjectId: lastHisProject.ID,
  4200. // StorehouseId: 0,
  4201. // }
  4202. //
  4203. // service.CreateNewAutoDetail(detail, tx)
  4204. //
  4205. // //查询剩余库存
  4206. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4207. // var sum_count int64
  4208. // for _, item := range goodList {
  4209. // sum_count += item.StockCount
  4210. // }
  4211. //
  4212. // //更新剩余库存
  4213. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4214. //
  4215. // //耗材
  4216. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4217. //
  4218. // }
  4219. // //判断是否是零用耗材(零用但是是出库耗材)
  4220. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4221. //
  4222. // //查询历史出库数据
  4223. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4224. // var out_count int64
  4225. // for _, item := range flowGood {
  4226. // out_count += item.Count
  4227. // }
  4228. // //如果历史数和当前数据不想等才进行退库出库
  4229. // if out_count != parseIntCount {
  4230. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4231. //
  4232. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4233. // detail := models.AutomaticReduceDetail{
  4234. // WarehouseOutId: 0,
  4235. // WarehouseOutOrderNumber: "",
  4236. // PatientId: p.PatientId,
  4237. // Ctime: time.Now().Unix(),
  4238. // Mtime: 0,
  4239. // Status: 1,
  4240. // RecordTime: p.RecordDate,
  4241. // OrgId: p.UserOrgId,
  4242. // GoodId: p.ProjectId,
  4243. // GoodTypeId: 0,
  4244. // Count: parseIntCount,
  4245. // Type: 0,
  4246. // ProjectId: p.ID,
  4247. // StorehouseId: 0,
  4248. // }
  4249. //
  4250. // service.CreateNewAutoDetail(detail, tx)
  4251. //
  4252. // //查询剩余库存
  4253. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4254. // var sum_count int64
  4255. // for _, item := range goodList {
  4256. // sum_count += item.StockCount
  4257. // }
  4258. //
  4259. // //更新剩余库存
  4260. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4261. //
  4262. // //耗材
  4263. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4264. // }
  4265. //
  4266. // }
  4267. //
  4268. // }
  4269. //
  4270. //}
  4271. //记录日志
  4272. byterequest, _ := json.Marshal(p)
  4273. adviceLog := models.XtDoctorAdviceLog{
  4274. UserOrgId: p.UserOrgId,
  4275. PatientId: p.PatientId,
  4276. AdminUserId: adminInfo.AdminUser.Id,
  4277. Module: 1,
  4278. ErrLog: string(byterequest),
  4279. Status: 1,
  4280. Ctime: time.Now().Unix(),
  4281. Mtime: 0,
  4282. Source: "电脑端新建his项目",
  4283. RecordDate: p.RecordDate,
  4284. }
  4285. service.CreateDoctorAdviceLog(adviceLog)
  4286. projectList = append(projectList, p)
  4287. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4288. //新增或者编辑项目,修改对应的标签数据
  4289. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4290. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4291. var label models.HisLabelPrintInfo
  4292. project, _ := service.GetProjectDetail(p.ProjectId)
  4293. if project.CostClassify == 3 { //类别为检验检查
  4294. if p.TeamId > 0 { //检验检查组套
  4295. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4296. if tempLabel.ID == 0 {
  4297. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4298. label.Number = tempPrescription.PrescriptionNumber
  4299. label.ProjectId = project.ID
  4300. label.Status = 1
  4301. label.IsPrint = 2
  4302. label.DoctorId = info.DoctorId
  4303. label.UserOrgId = p.UserOrgId
  4304. label.PatientId = patient_id
  4305. label.RecordDate = recordDateTime
  4306. label.Ctime = time.Now().Unix()
  4307. label.Mtime = time.Now().Unix()
  4308. label.ItemId = p.TeamId
  4309. label.FeedetlSn = p.FeedetlSn
  4310. label.PProjectId = p.ID
  4311. label.ProjectName = team.ProjectTeam
  4312. label.PatientName = patient.Name
  4313. service.CreateNewHisLabelRecord(&label, tx)
  4314. }
  4315. } else { //单条检验检查项目
  4316. label.Number = tempPrescription.PrescriptionNumber
  4317. label.ProjectId = project.ID
  4318. label.Status = 1
  4319. label.DoctorId = info.DoctorId
  4320. label.UserOrgId = p.UserOrgId
  4321. label.PatientId = patient_id
  4322. label.RecordDate = recordDateTime
  4323. label.IsPrint = 2
  4324. label.Ctime = time.Now().Unix()
  4325. label.Mtime = time.Now().Unix()
  4326. label.FeedetlSn = p.FeedetlSn
  4327. label.PProjectId = p.ID
  4328. label.ItemId = p.TeamId
  4329. label.ProjectName = project.ProjectName
  4330. label.PatientName = patient.Name
  4331. service.CreateNewHisLabelRecord(&label, tx)
  4332. }
  4333. }
  4334. }
  4335. }
  4336. }
  4337. }
  4338. }
  4339. //插入检验数据
  4340. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4341. //新增或者编辑项目,修改对应的标签数据
  4342. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4343. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4344. var label models.HisLabelPrintInfo
  4345. project, _ := service.GetProjectDetail(p.ProjectId)
  4346. if project.CostClassify == 3 { //类别为检验检查
  4347. if p.TeamId > 0 { //检验检查组套
  4348. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4349. if tempLabel.ID == 0 {
  4350. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4351. label.Number = tempPrescription.PrescriptionNumber
  4352. label.ProjectId = project.ID
  4353. label.Status = 1
  4354. label.IsPrint = 2
  4355. label.DoctorId = info.DoctorId
  4356. label.UserOrgId = p.UserOrgId
  4357. label.PatientId = patient_id
  4358. label.RecordDate = recordDateTime
  4359. label.Ctime = time.Now().Unix()
  4360. label.Mtime = time.Now().Unix()
  4361. label.ItemId = p.TeamId
  4362. label.FeedetlSn = p.FeedetlSn
  4363. label.PProjectId = p.ID
  4364. label.ProjectName = team.ProjectTeam
  4365. label.PatientName = patient.Name
  4366. service.CreateHisLabelRecord(&label)
  4367. }
  4368. } else { //单条检验检查项目
  4369. label.Number = tempPrescription.PrescriptionNumber
  4370. label.ProjectId = project.ID
  4371. label.Status = 1
  4372. label.DoctorId = info.DoctorId
  4373. label.UserOrgId = p.UserOrgId
  4374. label.PatientId = patient_id
  4375. label.RecordDate = recordDateTime
  4376. label.IsPrint = 2
  4377. label.Ctime = time.Now().Unix()
  4378. label.Mtime = time.Now().Unix()
  4379. label.FeedetlSn = p.FeedetlSn
  4380. label.PProjectId = p.ID
  4381. label.ItemId = p.TeamId
  4382. label.ProjectName = project.ProjectName
  4383. label.PatientName = patient.Name
  4384. service.CreateHisLabelRecord(&label)
  4385. }
  4386. }
  4387. }
  4388. }
  4389. service.CreateNewHisProjectTwo(&p, tx)
  4390. var randNum int
  4391. randNum = rand.Intn(10000) + 1000
  4392. timestamp := time.Now().Unix()
  4393. tempTime := time.Unix(timestamp, 0)
  4394. timeFormat := tempTime.Format("20060102150405")
  4395. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4396. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4397. if goodBase.ID > 0 {
  4398. tx.Rollback()
  4399. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4400. return
  4401. }
  4402. service.CreateNewHisProjectTwo(&p, tx)
  4403. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4404. //查询剩余库存
  4405. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4406. var sum_count int64
  4407. for _, item := range goodList {
  4408. sum_count += item.StockCount
  4409. }
  4410. //更新剩余库存
  4411. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4412. //耗材
  4413. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4414. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4415. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4416. if len(outInfoTwo) > 0 {
  4417. for _, item := range outInfoTwo {
  4418. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4419. }
  4420. }
  4421. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4422. if len(drugAutoDetail) > 0 {
  4423. for _, item := range drugAutoDetail {
  4424. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4425. }
  4426. }
  4427. tx.Commit()
  4428. }
  4429. }
  4430. }
  4431. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4432. // addition := items["addition"].([]interface{})
  4433. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4434. // ctime := time.Now().Unix()
  4435. // mtime := ctime
  4436. // if len(addition) > 0 {
  4437. // for _, item := range addition {
  4438. // var s models.HisAdditionalCharge
  4439. // s.PrescriptionId = tempPrescription.ID
  4440. // s.Status = 1
  4441. // s.UserOrgId = adminInfo.CurrentOrgId
  4442. // s.RecordDate = recordDateTime
  4443. // s.CreatedTime = ctime
  4444. // s.UpdatedTime = mtime
  4445. // s.PatientId = patient_id
  4446. // s.HisPatientId = his_patient_id
  4447. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4448. // if errcode > 0 {
  4449. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4450. // return
  4451. // }
  4452. // service.CreateAdditionalCharge(&s)
  4453. // var randNum int
  4454. // randNum = rand.Intn(10000) + 1000
  4455. // timestamp := time.Now().Unix()
  4456. // tempTime := time.Unix(timestamp, 0)
  4457. // timeFormat := tempTime.Format("20060102150405")
  4458. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4459. // service.CreateAdditionalCharge(&s)
  4460. //
  4461. // }
  4462. // }
  4463. //}
  4464. }
  4465. }
  4466. }
  4467. tx.Commit()
  4468. if err == nil {
  4469. c.ServeSuccessJSON(map[string]interface{}{
  4470. "msg": "保存成功",
  4471. })
  4472. return
  4473. } else {
  4474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4475. return
  4476. }
  4477. } else {
  4478. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4479. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4480. var tempPrescription *models.HisPrescription
  4481. if len(prescriptions) > 0 {
  4482. for _, item := range prescriptions {
  4483. items := item.(map[string]interface{})
  4484. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4485. utils.ErrorLog("id")
  4486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4487. return
  4488. }
  4489. id := int64(items["id"].(float64))
  4490. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4491. tempPrescription = &new_prescription
  4492. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4493. utils.ErrorLog("type")
  4494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4495. return
  4496. }
  4497. types := int64(items["type"].(float64))
  4498. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4499. utils.ErrorLog("med_type")
  4500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4501. return
  4502. }
  4503. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4504. if med_type == "0" {
  4505. med_type = "14"
  4506. }
  4507. //if order_status == 0 {
  4508. // order_status = 1
  4509. //}
  4510. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4511. // utils.ErrorLog("diagnoses")
  4512. //}
  4513. diagnoses, _ := items["diagnoses"].(string)
  4514. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4515. utils.ErrorLog("pre_time")
  4516. }
  4517. preTime, _ := items["pre_time"].(string)
  4518. timeLayout := "2006-01-02"
  4519. loc, _ := time.LoadLocation("Local")
  4520. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4521. //result := strings.Split(preTime, " ")
  4522. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4523. if err != nil {
  4524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4525. return
  4526. }
  4527. pTime := theTime2.Unix()
  4528. ctime := time.Now().Unix()
  4529. if tempPrescription.ID == 0 {
  4530. prescription := &models.HisPrescription{
  4531. ID: 0,
  4532. PatientId: patient_id,
  4533. UserOrgId: adminInfo.CurrentOrgId,
  4534. RecordDate: recordDateTime,
  4535. Ctime: ctime,
  4536. Mtime: ctime,
  4537. Type: types,
  4538. Modifier: adminInfo.AdminUser.Id,
  4539. Creator: adminInfo.AdminUser.Id,
  4540. Status: 1,
  4541. Doctor: role.UserName,
  4542. HisPatientId: his_patient_id,
  4543. OrderStatus: 1,
  4544. BatchNumber: "",
  4545. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4546. PreTime: pTime,
  4547. PType: p_type,
  4548. MedType: med_type,
  4549. Diagnose: diagnoses,
  4550. }
  4551. tempPrescription = prescription
  4552. service.SaveHisPrescription(tempPrescription)
  4553. redis := service.RedisClient()
  4554. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4555. redis.Set(key, "", time.Second)
  4556. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4557. redis.Set(keyOne, "", time.Second)
  4558. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4559. redis.Set(keySeven, "", time.Second)
  4560. defer redis.Close()
  4561. } else {
  4562. tempPrescription.ID = id
  4563. tempPrescription.Type = types
  4564. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4565. tempPrescription.Mtime = time.Now().Unix()
  4566. tempPrescription.Doctor = role.UserName
  4567. //tempPrescription.OrderStatus = order_status
  4568. tempPrescription.PreTime = pTime
  4569. tempPrescription.MedType = med_type
  4570. tempPrescription.Diagnose = diagnoses
  4571. service.SaveHisPrescription(tempPrescription)
  4572. redis := service.RedisClient()
  4573. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4574. redis.Set(key, "", time.Second)
  4575. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4576. redis.Set(keyOne, "", time.Second)
  4577. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4578. redis.Set(keySeven, "", time.Second)
  4579. defer redis.Close()
  4580. }
  4581. //service.SaveHisPrescription(prescription)
  4582. //更改患者挂号状态
  4583. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4584. fmt.Println("更改失败", err2)
  4585. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4586. advices := items["advices"].([]interface{})
  4587. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4588. groupNo := int64(0)
  4589. if len(advices) > 0 {
  4590. for _, advice := range advices {
  4591. var s models.HisDoctorAdviceInfo
  4592. s.PrescriptionId = tempPrescription.ID
  4593. s.AdviceType = 2
  4594. s.AdviceDoctor = doctor_id
  4595. s.StopState = 2
  4596. s.ExecutionState = 2
  4597. s.AdviceDate = theTime3.Unix()
  4598. s.Status = 1
  4599. s.UserOrgId = adminInfo.CurrentOrgId
  4600. s.RecordDate = theTime3.Unix()
  4601. s.StartTime = tempPrescription.PreTime
  4602. s.Groupno = groupNo
  4603. s.PatientId = patient_id
  4604. s.HisPatientId = his_patient_id
  4605. s.StartTime = pTime
  4606. s.IsSettle = 2
  4607. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4608. if errcode > 0 {
  4609. c.ServeFailJSONWithSGJErrorCode(errcode)
  4610. return
  4611. }
  4612. s.StartTime = pTime
  4613. var total_count int64 //处方总库存
  4614. //查询改药品信息
  4615. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4616. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4617. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4618. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4619. total_count += prescribingNumberSeven * medical.MinNumber
  4620. }
  4621. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4622. total_count += prescribingNumberSeven
  4623. }
  4624. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4625. total_count += prescribingNumberSeven
  4626. }
  4627. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4628. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4629. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4630. if s.Price != lastWarehouse.RetailPrice {
  4631. s.Price = lastWarehouse.RetailPrice
  4632. }
  4633. if s.Price == 0 {
  4634. if lastWarehouse.ID == 0 {
  4635. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4636. s.Price = lastWarehouseTwo.RetailPrice
  4637. }
  4638. }
  4639. }
  4640. if adminInfo.CurrentOrgId != 10206 {
  4641. if s.ID == 0 {
  4642. //查询改药品是否已经停用
  4643. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4644. if base.ID > 0 {
  4645. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4646. return
  4647. }
  4648. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4649. if drugMedical.SumCount == 0 {
  4650. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4651. return
  4652. }
  4653. }
  4654. }
  4655. //赤峰
  4656. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4657. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4658. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4659. if info.RetailPrice > 0 {
  4660. if s.DeliveryWay == "口服" {
  4661. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4662. s.Price = drug.RetailPrice
  4663. }
  4664. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4665. s.Price = info.RetailPrice
  4666. }
  4667. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4668. s.Price = info.RetailPrice
  4669. }
  4670. }
  4671. }
  4672. }
  4673. service.CreateHisDoctorAdvice(&s)
  4674. //记录日志
  4675. byterequest, _ := json.Marshal(s)
  4676. adviceLog := models.XtDoctorAdviceLog{
  4677. UserOrgId: s.UserOrgId,
  4678. PatientId: s.PatientId,
  4679. AdminUserId: adminInfo.AdminUser.Id,
  4680. Module: 1,
  4681. ErrLog: string(byterequest),
  4682. Status: 1,
  4683. Ctime: time.Now().Unix(),
  4684. Mtime: 0,
  4685. Source: "电脑端新建his医嘱",
  4686. RecordDate: s.AdviceDate,
  4687. }
  4688. service.CreateDoctorAdviceLog(adviceLog)
  4689. //存储切片中
  4690. adviceList = append(adviceList, s)
  4691. redis := service.RedisClient()
  4692. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4693. redis.Set(key, "", time.Second)
  4694. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4695. redis.Set(keyOne, "", time.Second)
  4696. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4697. redis.Set(keySeven, "", time.Second)
  4698. var randNum int
  4699. randNum = rand.Intn(10000) + 1000
  4700. timestamp := time.Now().Unix()
  4701. tempTime := time.Unix(timestamp, 0)
  4702. timeFormat := tempTime.Format("20060102150405")
  4703. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4704. service.CreateHisDoctorAdvice(&s)
  4705. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4706. redis.Set(keySix, "", time.Second)
  4707. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4708. redis.Set(keyFive, "", time.Second)
  4709. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4710. redis.Set(keyEight, "", time.Second)
  4711. defer redis.Close()
  4712. }
  4713. }
  4714. }
  4715. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4716. projects := items["project"].([]interface{})
  4717. if len(projects) > 0 {
  4718. for _, project := range projects {
  4719. var p models.HisPrescriptionProject
  4720. p.PrescriptionId = tempPrescription.ID
  4721. p.PatientId = patient_id
  4722. p.RecordDate = theTime3.Unix()
  4723. p.Doctor = doctor_id
  4724. p.UserOrgId = adminInfo.CurrentOrgId
  4725. p.HisPatientId = his_patient_id
  4726. p.Status = 1
  4727. p.StartTime = pTime
  4728. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4729. if errcode > 0 {
  4730. c.ServeFailJSONWithSGJErrorCode(errcode)
  4731. return
  4732. }
  4733. if p.ID == 0 {
  4734. p.IsOut = 2
  4735. }
  4736. if p.ID > 0 {
  4737. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4738. p.IsOut = projectDetail.IsOut
  4739. }
  4740. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4741. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4742. if p.Type == 3 {
  4743. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4744. if p.Price != lastWarehouse.PackingPrice {
  4745. p.Price = lastWarehouse.PackingPrice
  4746. }
  4747. if p.Price == 0 {
  4748. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4749. p.Price = lastWarehouseTwo.PackingPrice
  4750. }
  4751. if p.Unit == "" {
  4752. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4753. p.Unit = goodInfoOne.PackingUnit
  4754. }
  4755. }
  4756. }
  4757. if adminInfo.CurrentOrgId != 10206 {
  4758. if p.Type == 3 {
  4759. if p.ID == 0 {
  4760. //查询该耗材是否停用
  4761. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4762. //表示该耗材已经停用,不能保存
  4763. if goodInfoSeven.ID == 0 {
  4764. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4765. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4766. return
  4767. }
  4768. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4769. if goodInfoOne.SumCount == 0 {
  4770. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4771. return
  4772. }
  4773. }
  4774. }
  4775. }
  4776. service.CreateHisProjectTwo(&p)
  4777. //记录日志
  4778. byterequest, _ := json.Marshal(p)
  4779. adviceLog := models.XtDoctorAdviceLog{
  4780. UserOrgId: p.UserOrgId,
  4781. PatientId: p.PatientId,
  4782. AdminUserId: adminInfo.AdminUser.Id,
  4783. Module: 1,
  4784. ErrLog: string(byterequest),
  4785. Status: 1,
  4786. Ctime: time.Now().Unix(),
  4787. Mtime: 0,
  4788. Source: "电脑端新建his项目",
  4789. RecordDate: p.RecordDate,
  4790. }
  4791. service.CreateDoctorAdviceLog(adviceLog)
  4792. projectList = append(projectList, p)
  4793. var randNum int
  4794. randNum = rand.Intn(10000) + 1000
  4795. timestamp := time.Now().Unix()
  4796. tempTime := time.Unix(timestamp, 0)
  4797. timeFormat := tempTime.Format("20060102150405")
  4798. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4799. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4800. //新增或者编辑项目,修改对应的标签数据
  4801. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4802. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4803. var label models.HisLabelPrintInfo
  4804. project, _ := service.GetProjectDetail(p.ProjectId)
  4805. if project.CostClassify == 3 { //类别为检验检查
  4806. if p.TeamId > 0 { //检验检查组套
  4807. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4808. if tempLabel.ID == 0 {
  4809. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4810. label.Number = tempPrescription.PrescriptionNumber
  4811. label.ProjectId = project.ID
  4812. label.Status = 1
  4813. label.IsPrint = 2
  4814. label.DoctorId = info.DoctorId
  4815. label.UserOrgId = p.UserOrgId
  4816. label.PatientId = patient_id
  4817. label.RecordDate = recordDateTime
  4818. label.Ctime = time.Now().Unix()
  4819. label.Mtime = time.Now().Unix()
  4820. label.ItemId = p.TeamId
  4821. label.FeedetlSn = p.FeedetlSn
  4822. label.PProjectId = p.ID
  4823. label.ProjectName = team.ProjectTeam
  4824. label.PatientName = patient.Name
  4825. service.CreateHisLabelRecord(&label)
  4826. }
  4827. } else { //单条检验检查项目
  4828. label.Number = tempPrescription.PrescriptionNumber
  4829. label.ProjectId = project.ID
  4830. label.Status = 1
  4831. label.DoctorId = info.DoctorId
  4832. label.UserOrgId = p.UserOrgId
  4833. label.PatientId = patient_id
  4834. label.RecordDate = recordDateTime
  4835. label.IsPrint = 2
  4836. label.Ctime = time.Now().Unix()
  4837. label.Mtime = time.Now().Unix()
  4838. label.FeedetlSn = p.FeedetlSn
  4839. label.PProjectId = p.ID
  4840. label.ItemId = p.TeamId
  4841. label.ProjectName = project.ProjectName
  4842. label.PatientName = patient.Name
  4843. service.CreateHisLabelRecord(&label)
  4844. }
  4845. }
  4846. }
  4847. }
  4848. service.SaveHisProjectTwo(&p)
  4849. }
  4850. }
  4851. }
  4852. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4853. // addition := items["addition"].([]interface{})
  4854. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4855. // ctime := time.Now().Unix()
  4856. // mtime := ctime
  4857. // if len(addition) > 0 {
  4858. // for _, item := range addition {
  4859. // var s models.HisAdditionalCharge
  4860. // s.PrescriptionId = tempPrescription.ID
  4861. // s.Status = 1
  4862. // s.UserOrgId = adminInfo.CurrentOrgId
  4863. // s.RecordDate = recordDateTime
  4864. // s.CreatedTime = ctime
  4865. // s.UpdatedTime = mtime
  4866. // s.PatientId = patient_id
  4867. // s.HisPatientId = his_patient_id
  4868. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4869. // if errcode > 0 {
  4870. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4871. // return
  4872. // }
  4873. // service.CreateAdditionalCharge(&s)
  4874. // var randNum int
  4875. // randNum = rand.Intn(10000) + 1000
  4876. // timestamp := time.Now().Unix()
  4877. // tempTime := time.Unix(timestamp, 0)
  4878. // timeFormat := tempTime.Format("20060102150405")
  4879. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4880. // service.CreateAdditionalCharge(&s)
  4881. //
  4882. // }
  4883. // }
  4884. //}
  4885. }
  4886. }
  4887. //查询今日该患者开的药品处方
  4888. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4889. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4890. //药品出库
  4891. if drugOutConfig.IsOpen == 1 {
  4892. for _, item := range hisdoctorlist {
  4893. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4894. // 查询该药品最后一次出库记录
  4895. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4896. if len(druginfo) > 0 {
  4897. //回退库存
  4898. for _, it := range druginfo {
  4899. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4900. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4901. }
  4902. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4903. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4904. }
  4905. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4906. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4907. }
  4908. }
  4909. }
  4910. //删除记录
  4911. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4912. //查询最后一次数据
  4913. if drugOutConfig.IsOpen == 1 {
  4914. //出库
  4915. if drug.IsUse == 2 {
  4916. creater := adminInfo.AdminUser.Id
  4917. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4918. }
  4919. //更新字典里面的库存
  4920. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4921. var sum_count int64
  4922. for _, its := range stockInfo {
  4923. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4924. if its.MaxUnit == baseDrug.MaxUnit {
  4925. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4926. }
  4927. sum_count += its.StockMaxNumber + its.StockMinNumber
  4928. }
  4929. //更新基础库存
  4930. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4931. //剩余库存
  4932. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4933. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4934. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4935. }
  4936. }
  4937. }
  4938. //耗材保存处方出库
  4939. if goodOutConfig.IsOpen == 1 {
  4940. //查询今日耗材出库数量
  4941. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4942. for _, item := range hisgoodlist {
  4943. //查询历史出库数据
  4944. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4945. var out_count_five int64
  4946. for _, item := range flowGood {
  4947. out_count_five += item.Count
  4948. }
  4949. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4950. if out_count_five != parseIntCount {
  4951. //查询耗材最后一次出库记录
  4952. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4953. //查询默认出库仓库库存
  4954. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4955. if len(wareOut) > 0 {
  4956. for _, it := range wareOut {
  4957. //回退库存
  4958. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4959. //删除出库记录
  4960. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4961. }
  4962. }
  4963. timeStr := time.Now().Format("2006-01-02")
  4964. timeArr := strings.Split(timeStr, "-")
  4965. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4966. total = total + 1
  4967. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4968. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4969. number = number + total
  4970. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4971. operation_time := time.Now().Unix()
  4972. creater := c.GetAdminUserInfo().AdminUser.Id
  4973. recordDateStr := time.Now().Format("2006-01-02")
  4974. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4975. nowtime := recordDate.Unix()
  4976. warehouseOut := models.WarehouseOut{
  4977. WarehouseOutOrderNumber: warehousing_out_order,
  4978. OperationTime: operation_time,
  4979. OrgId: adminInfo.CurrentOrgId,
  4980. Creater: creater,
  4981. Ctime: time.Now().Unix(),
  4982. Status: 1,
  4983. WarehouseOutTime: nowtime,
  4984. Type: 1,
  4985. StorehouseId: storeConfig.StorehouseOutInfo,
  4986. IsCheck: 1,
  4987. IsSys: 1,
  4988. }
  4989. //查询是否生成出库单
  4990. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4991. if out.ID == 0 {
  4992. service.AddSigleWarehouseOut(&warehouseOut)
  4993. }
  4994. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4995. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4996. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4997. dialyPrepareOne := models.DialysisBeforePrepare{
  4998. GoodTypeId: goodObj.GoodTypeId,
  4999. GoodId: item.ProjectId,
  5000. PatientId: item.PatientId,
  5001. RecordDate: item.RecordDate,
  5002. UserOrgId: adminInfo.CurrentOrgId,
  5003. Count: parseIntCount,
  5004. Ctime: time.Now().Unix(),
  5005. Creater: creater,
  5006. Status: 1,
  5007. StorehouseId: houseConfig.StorehouseOutInfo,
  5008. ProjectId: item.ID,
  5009. }
  5010. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5011. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5012. //查询历史出库数据
  5013. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5014. var out_count int64
  5015. for _, item := range flowGood {
  5016. out_count += item.Count
  5017. }
  5018. //如果历史数和当前数据不想等才进行退库出库
  5019. if out_count != parseIntCount {
  5020. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5021. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5022. detail := models.AutomaticReduceDetail{
  5023. WarehouseOutId: 0,
  5024. WarehouseOutOrderNumber: "",
  5025. PatientId: item.PatientId,
  5026. Ctime: time.Now().Unix(),
  5027. Mtime: 0,
  5028. Status: 1,
  5029. RecordTime: item.RecordDate,
  5030. OrgId: item.UserOrgId,
  5031. GoodId: item.ProjectId,
  5032. GoodTypeId: 0,
  5033. Count: parseIntCount,
  5034. Type: 0,
  5035. ProjectId: item.ID,
  5036. StorehouseId: 0,
  5037. }
  5038. service.CreateAutoDetail(detail)
  5039. //查询剩余库存
  5040. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5041. var sum_count int64
  5042. for _, item := range goodList {
  5043. sum_count += item.StockCount
  5044. }
  5045. //更新剩余库存
  5046. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5047. //耗材
  5048. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5049. }
  5050. }
  5051. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5052. //查询历史出库数据
  5053. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5054. var out_count int64
  5055. for _, item := range flowGood {
  5056. out_count += item.Count
  5057. }
  5058. //如果历史数和当前数据不想等才进行退库出库
  5059. if out_count != parseIntCount {
  5060. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5061. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5062. detail := models.AutomaticReduceDetail{
  5063. WarehouseOutId: 0,
  5064. WarehouseOutOrderNumber: "",
  5065. PatientId: item.PatientId,
  5066. Ctime: time.Now().Unix(),
  5067. Mtime: 0,
  5068. Status: 1,
  5069. RecordTime: item.RecordDate,
  5070. OrgId: item.UserOrgId,
  5071. GoodId: item.ProjectId,
  5072. GoodTypeId: 0,
  5073. Count: parseIntCount,
  5074. Type: 0,
  5075. ProjectId: item.ID,
  5076. StorehouseId: 0,
  5077. }
  5078. service.CreateAutoDetail(detail)
  5079. //查询剩余库存
  5080. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5081. var sum_count int64
  5082. for _, item := range goodList {
  5083. sum_count += item.StockCount
  5084. }
  5085. //更新剩余库存
  5086. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5087. //耗材
  5088. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5089. }
  5090. }
  5091. }
  5092. }
  5093. }
  5094. ////同步到自备药
  5095. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5096. if selfPrescriptionOpen.IsOpen == 1 {
  5097. timeStr := time.Now().Format("2006-01-02")
  5098. timeArr := strings.Split(timeStr, "-")
  5099. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5100. total = total + 1
  5101. operation_time := time.Now().Unix()
  5102. creater := adminInfo.AdminUser.Id
  5103. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5104. warehousing := models.XtSelfDrugWarehouse{
  5105. WarehousingOrder: warehousing_order,
  5106. OperationTime: operation_time,
  5107. OrgId: adminInfo.CurrentOrgId,
  5108. Creater: creater,
  5109. Ctime: time.Now().Unix(),
  5110. Status: 1,
  5111. WarehousingTime: recordDateTime,
  5112. Type: 0,
  5113. StorehouseId: 0,
  5114. IsCheck: 1,
  5115. PatientId: patient_id,
  5116. IsSys: 1,
  5117. }
  5118. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5119. if selfDrugWarehouse.ID == 0 {
  5120. service.AddSelfDrugWarehouse(&warehousing, tx)
  5121. }
  5122. if selfDrugWarehouse.ID > 0 {
  5123. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5124. }
  5125. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5126. fmt.Println(info)
  5127. for _, item := range hisdoctorlist {
  5128. //查询该病人的该药品是否已经入库
  5129. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5130. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5131. var in_count int64
  5132. if len(selfdruginfo) > 0 {
  5133. for _, item := range selfdruginfo {
  5134. var in_count_one int64
  5135. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5136. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5137. }
  5138. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5139. in_count_one = item.WarehousingCount
  5140. }
  5141. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5142. in_count_one = item.WarehousingCount
  5143. }
  5144. in_count += in_count_one
  5145. }
  5146. }
  5147. if selfBasedrug.IsSelfDrug == 1 {
  5148. var total_count int64
  5149. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5150. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5151. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5152. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5153. }
  5154. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5155. total_count += prescribingNumberSeven
  5156. }
  5157. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5158. total_count += prescribingNumberSeven
  5159. }
  5160. //入库
  5161. if total_count > in_count {
  5162. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5163. WarehousingOrder: warehousing_order,
  5164. WarehousingId: info.ID,
  5165. DrugId: item.DrugId,
  5166. Number: "",
  5167. ProductDate: 0,
  5168. ExpiryDate: 0,
  5169. WarehousingCount: total_count - in_count,
  5170. WarehouseingUnit: selfBasedrug.MinUnit,
  5171. Price: 0,
  5172. TotalPrice: 0,
  5173. Status: 1,
  5174. Ctime: time.Now().Unix(),
  5175. Remark: "",
  5176. OrgId: adminInfo.CurrentOrgId,
  5177. Type: 0,
  5178. Manufacturer: selfBasedrug.Manufacturer,
  5179. Dealer: selfBasedrug.Dealer,
  5180. StockMaxNumber: total_count - in_count,
  5181. RetailTotalPrice: 0,
  5182. BatchNumber: "",
  5183. MaxUnit: selfBasedrug.MinUnit,
  5184. MinUnit: selfBasedrug.MinUnit,
  5185. RetailPrice: 0,
  5186. StorehouseId: 0,
  5187. IsCheck: 1,
  5188. StockMinNumber: 0,
  5189. PatientId: patient_id,
  5190. IsSys: 1,
  5191. RecordDate: item.RecordDate,
  5192. AdviceId: item.ID,
  5193. }
  5194. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5195. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5196. Creator := adminInfo.AdminUser.Id
  5197. //查询默认仓库剩余多少库存
  5198. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5199. var sum_count int64
  5200. for _, it := range list {
  5201. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5202. if it.MaxUnit == baseDrug.MaxUnit {
  5203. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5204. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5205. }
  5206. sum_count += it.StockMaxNumber + it.StockMinNumber
  5207. }
  5208. flow := &models.XtSelfDrugFlow{
  5209. WarehousingId: info.ID,
  5210. DrugId: item.DrugId,
  5211. Number: "",
  5212. BatchNumber: "",
  5213. Count: total_count - in_count,
  5214. UserOrgId: adminInfo.CurrentOrgId,
  5215. PatientId: item.PatientId,
  5216. SystemTime: time.Now().Unix(),
  5217. ConsumableType: 1,
  5218. IsSys: 1,
  5219. WarehousingOrder: warehousing_order,
  5220. WarehouseOutId: 0,
  5221. WarehouseOutOrderNumber: "",
  5222. IsEdit: 0,
  5223. CancelStockId: 0,
  5224. CancelOrderNumber: "",
  5225. Manufacturer: selfBasedrug.Manufacturer,
  5226. Dealer: selfBasedrug.Dealer,
  5227. Creator: Creator,
  5228. UpdateCreator: Creator,
  5229. Status: 1,
  5230. Ctime: item.AdviceDate,
  5231. Mtime: 0,
  5232. Price: item.Price,
  5233. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5234. WarehouseOutDetailId: 0,
  5235. CancelOutDetailId: 0,
  5236. ExpireDate: 0,
  5237. ProductDate: 0,
  5238. MaxUnit: selfBasedrug.MinUnit,
  5239. MinUnit: selfBasedrug.MinUnit,
  5240. StorehouseId: 0,
  5241. OverCount: sum_count,
  5242. OperateTime: time.Now().Unix(),
  5243. AdviceId: item.ID,
  5244. }
  5245. service.CreateSelfDrugFlow(flow, tx)
  5246. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5247. var total_count int64 // 入库总数量
  5248. var over_count int64 //剩余库存
  5249. for _, it := range drugInfolist {
  5250. if it.MaxUnit == selfBasedrug.MaxUnit {
  5251. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5252. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5253. }
  5254. }
  5255. for _, it := range drugInfolist {
  5256. total_count += it.WarehousingCount
  5257. over_count += it.StockMaxNumber + it.StockMinNumber
  5258. }
  5259. //查询该仓库是否有默认数据
  5260. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5261. if selfDrugStock.ID == 0 {
  5262. drugStock := models.XtSelfDrugStockCount{
  5263. UserOrgId: item.UserOrgId,
  5264. PatientId: item.PatientId,
  5265. SumInCount: total_count,
  5266. SumOutCount: 0,
  5267. SumCancelCount: 0,
  5268. DrugId: item.DrugId,
  5269. Ctime: time.Now().Unix(),
  5270. Mtime: 0,
  5271. Status: 1,
  5272. FlushCount: over_count,
  5273. SumActOutCount: 0,
  5274. }
  5275. service.CreateSelfDrugStockSum(drugStock, tx)
  5276. }
  5277. if selfDrugStock.ID > 0 {
  5278. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5279. }
  5280. }
  5281. //查询这个单据的出库数量
  5282. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5283. var his_out_count int64
  5284. for _, item := range drugFlowList {
  5285. his_out_count += item.Count
  5286. }
  5287. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5288. if (total_count + his_out_count) <= in_count {
  5289. // 出库
  5290. if total_count < in_count {
  5291. var cha_count int64
  5292. cha_count = in_count - total_count
  5293. var stock_number int64 = 0
  5294. //查询库存是否充足
  5295. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5296. // 将该批次的剩余库存数量转换为拆零数量
  5297. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5298. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5299. }
  5300. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5301. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5302. }
  5303. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5304. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5305. }
  5306. if stock_number >= cha_count {
  5307. var maxNumber int64 = 0
  5308. var minNumber int64 = 0
  5309. maxNumber = cha_count / selfBasedrug.MinNumber
  5310. minNumber = cha_count % selfBasedrug.MinNumber
  5311. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5312. minNumber = maxNumber
  5313. }
  5314. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5315. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5317. return
  5318. }
  5319. }
  5320. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5321. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5322. }
  5323. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5324. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5325. }
  5326. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5327. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5328. }
  5329. if warehouse.StockMaxNumber < 0 {
  5330. warehouse.StockMaxNumber = 0
  5331. }
  5332. if warehouse.StockMinNumber < 0 {
  5333. warehouse.StockMinNumber = 0
  5334. }
  5335. warehouse.Mtime = time.Now().Unix()
  5336. if warehouse.StockMinNumber < minNumber {
  5337. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5338. if warehouse.MaxUnit != warehouse.MinUnit {
  5339. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5340. }
  5341. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5342. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5343. }
  5344. } else {
  5345. if minNumber > 0 {
  5346. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5347. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5348. }
  5349. }
  5350. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5351. if warehouse.StockMinNumber > 0 {
  5352. if warehouse.StockMinNumber-cha_count >= 0 {
  5353. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5354. }
  5355. }
  5356. }
  5357. }
  5358. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5359. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5360. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5361. }
  5362. }
  5363. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5364. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5366. return
  5367. }
  5368. }
  5369. if warehouse.StockMinNumber <= 0 {
  5370. warehouse.StockMinNumber = 0
  5371. }
  5372. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5373. //查询该药品剩余库存
  5374. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5375. var over_count int64
  5376. for _, its := range infolist {
  5377. if its.MaxUnit == selfBasedrug.MaxUnit {
  5378. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5379. }
  5380. over_count += its.StockMaxNumber + its.StockMinNumber
  5381. }
  5382. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5383. drugflow := models.XtSelfDrugFlow{
  5384. WarehouseOutId: 0,
  5385. WarehouseOutOrderNumber: warehousing_order,
  5386. WarehousingOrder: warehousing_order,
  5387. DrugId: item.DrugId,
  5388. Number: warehouse.Number,
  5389. ProductDate: warehouse.ProductDate,
  5390. ExpireDate: warehouse.ExpiryDate,
  5391. Count: cha_count,
  5392. Price: warehouse.RetailPrice,
  5393. Status: 1,
  5394. Ctime: item.AdviceDate,
  5395. Mtime: time.Now().Unix(),
  5396. UserOrgId: item.UserOrgId,
  5397. Manufacturer: warehouse.Manufacturer,
  5398. Dealer: warehouse.Dealer,
  5399. BatchNumber: warehouse.BatchNumber,
  5400. MaxUnit: selfBasedrug.MinUnit,
  5401. ConsumableType: 20,
  5402. IsEdit: 1,
  5403. Creator: 0,
  5404. IsSys: 3,
  5405. WarehouseOutDetailId: drugWareInfo.ID,
  5406. AdviceId: item.ID,
  5407. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5408. StorehouseId: 0,
  5409. AdminUserId: creater,
  5410. LastPrice: warehouse.Price,
  5411. StockCount: "",
  5412. WarehousingDetailId: 0,
  5413. OverCount: over_count,
  5414. RetailPrice: item.Price, //手动出库出库价格
  5415. WarehousingId: warehouse.ID,
  5416. SystemTime: item.AdviceDate,
  5417. PatientId: item.PatientId,
  5418. Remark: "保存处方入库数据差",
  5419. OperateTime: time.Now().Unix(),
  5420. }
  5421. if warehouse.RetailPrice == 0 {
  5422. drugflow.Price = item.Price
  5423. }
  5424. service.CreateSelfDrugFlowOne(drugflow, tx)
  5425. var out_count int64
  5426. out_count = in_count - total_count
  5427. //
  5428. //fmt.Println("in_count------------------", in_count)
  5429. //fmt.Println("total_count------------------", total_count)
  5430. //添加出库数量
  5431. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5432. //查询剩余库存
  5433. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5434. var sum_count int64
  5435. for _, its := range stockInfo {
  5436. if its.MaxUnit == selfBasedrug.MaxUnit {
  5437. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5438. }
  5439. sum_count += its.StockMaxNumber + its.StockMinNumber
  5440. }
  5441. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5442. } else {
  5443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5444. return
  5445. }
  5446. }
  5447. }
  5448. }
  5449. }
  5450. }
  5451. }
  5452. tx.Commit()
  5453. if err == nil {
  5454. c.ServeSuccessJSON(map[string]interface{}{
  5455. "msg": "保存成功",
  5456. })
  5457. return
  5458. } else {
  5459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5460. return
  5461. }
  5462. }
  5463. }
  5464. //func (c *HisApiController) EditHisPrescription() {
  5465. // record_date := c.GetString("record_date")
  5466. // patient_id, _ := c.GetInt64("patient_id")
  5467. // reg_type, _ := c.GetInt64("reg_type")
  5468. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5469. // diagnose := c.GetString("diagnose")
  5470. // sick_type, _ := c.GetInt64("sick_type")
  5471. // sick_history := c.GetString("sick_history")
  5472. // doctor_id, _ := c.GetInt64("doctor", 0)
  5473. // department, _ := c.GetInt64("department", 0)
  5474. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5475. // p_type, _ := c.GetInt64("p_type")
  5476. //
  5477. // dataBody := make(map[string]interface{}, 0)
  5478. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5479. // if err != nil {
  5480. // utils.ErrorLog(err.Error())
  5481. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5482. // return
  5483. // }
  5484. //
  5485. // timeLayout := "2006-01-02"
  5486. // loc, _ := time.LoadLocation("Local")
  5487. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5488. // if err != nil {
  5489. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5490. // return
  5491. // }
  5492. // adminInfo := c.GetAdminUserInfo()
  5493. // recordDateTime := theTime.Unix()
  5494. //
  5495. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5496. //
  5497. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5498. // var hpInfo models.HisPrescriptionInfo
  5499. // if info.ID == 0 {
  5500. // var randNum int
  5501. // randNum = rand.Intn(10000) + 1000
  5502. // timestamp := time.Now().Unix()
  5503. // tempTime := time.Unix(timestamp, 0)
  5504. // timeFormat := tempTime.Format("20060102150405")
  5505. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5506. //
  5507. // hpInfo = models.HisPrescriptionInfo{
  5508. // UserOrgId: adminInfo.CurrentOrgId,
  5509. // RecordDate: theTime.Unix(),
  5510. // PatientId: patient_id,
  5511. // Status: 1,
  5512. // Ctime: time.Now().Unix(),
  5513. // Mtime: time.Now().Unix(),
  5514. // Creator: adminInfo.AdminUser.Id,
  5515. // Modifier: adminInfo.AdminUser.Id,
  5516. // Diagnosis: diagnose,
  5517. // SickHistory: sick_history,
  5518. // Departments: department,
  5519. // RegisterType: reg_type,
  5520. // PrescriptionNumber: p_number,
  5521. // PrescriptionStatus: 1,
  5522. // Doctor: role.UserName,
  5523. // DoctorId: doctor_id,
  5524. // SickType: sick_type,
  5525. // PType: p_type,
  5526. // }
  5527. // service.SavePatientPrescriptionInfo(hpInfo)
  5528. //
  5529. // } else {
  5530. // hpInfo = models.HisPrescriptionInfo{
  5531. // ID: info.ID,
  5532. // UserOrgId: adminInfo.CurrentOrgId,
  5533. // RecordDate: info.RecordDate,
  5534. // PatientId: info.PatientId,
  5535. // Status: 1,
  5536. // Ctime: info.Ctime,
  5537. // Mtime: time.Now().Unix(),
  5538. // Creator: info.Creator,
  5539. // Modifier: adminInfo.AdminUser.Id,
  5540. // Diagnosis: diagnose,
  5541. // SickHistory: sick_history,
  5542. // Departments: department,
  5543. // RegisterType: reg_type,
  5544. // PrescriptionNumber: info.PrescriptionNumber,
  5545. // Doctor: role.UserName,
  5546. // PrescriptionStatus: info.PrescriptionStatus,
  5547. // DoctorId: doctor_id,
  5548. // SickType: sick_type,
  5549. // PType: info.PType,
  5550. // }
  5551. // service.SavePatientPrescriptionInfo(hpInfo)
  5552. // }
  5553. //
  5554. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5555. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5556. //
  5557. // if len(prescriptions) > 0 {
  5558. // for _, item := range prescriptions {
  5559. // items := item.(map[string]interface{})
  5560. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5561. // utils.ErrorLog("id")
  5562. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5563. // return
  5564. // }
  5565. // id := int64(items["id"].(float64))
  5566. //
  5567. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5568. // utils.ErrorLog("type")
  5569. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5570. // return
  5571. // }
  5572. // types := int64(items["type"].(float64))
  5573. //
  5574. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5575. // utils.ErrorLog("med_type")
  5576. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5577. // return
  5578. // }
  5579. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5580. //
  5581. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5582. //
  5583. // ctime := time.Now().Unix()
  5584. //
  5585. // prescription := &models.HisPrescription{
  5586. // ID: id,
  5587. // PatientId: patient_id,
  5588. // UserOrgId: adminInfo.CurrentOrgId,
  5589. // RecordDate: recordDateTime,
  5590. // Ctime: ctime,
  5591. // Mtime: ctime,
  5592. // Type: types,
  5593. // Modifier: adminInfo.AdminUser.Id,
  5594. // Creator: adminInfo.AdminUser.Id,
  5595. // Status: 1,
  5596. // Doctor: role.UserName,
  5597. // HisPatientId: his_patient_id,
  5598. // OrderStatus: 1,
  5599. // BatchNumber: "",
  5600. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5601. // PType: hpInfo.PType,
  5602. // MedType: med_type,
  5603. // }
  5604. //
  5605. // if historyPrescription.ID > 0 {
  5606. // prescription.PreTime = historyPrescription.PreTime
  5607. //
  5608. // }
  5609. //
  5610. // service.SaveHisPrescription(prescription)
  5611. //
  5612. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5613. // advices := items["advices"].([]interface{})
  5614. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5615. // groupNo := int64(0)
  5616. // ctime := time.Now().Unix()
  5617. // mtime := ctime
  5618. // if len(advices) > 0 {
  5619. // for _, advice := range advices {
  5620. // var s models.HisDoctorAdviceInfo
  5621. // s.PrescriptionId = prescription.ID
  5622. // s.AdviceType = 2
  5623. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5624. // s.StopState = 2
  5625. // s.ExecutionState = 2
  5626. // s.AdviceDate = recordDateTime
  5627. // s.Status = 1
  5628. // s.UserOrgId = adminInfo.CurrentOrgId
  5629. // s.RecordDate = recordDateTime
  5630. // s.StartTime = prescription.PreTime
  5631. // s.Groupno = groupNo
  5632. // s.CreatedTime = ctime
  5633. // s.UpdatedTime = mtime
  5634. // s.PatientId = patient_id
  5635. // s.HisPatientId = his_patient_id
  5636. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5637. // if errcode > 0 {
  5638. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5639. // return
  5640. // }
  5641. //
  5642. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5643. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5644. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5645. // if s.Price == 0 {
  5646. // s.Price = lastWarehouse.RetailPrice
  5647. // }
  5648. // }
  5649. //
  5650. // service.CreateHisDoctorAdvice(&s)
  5651. // //记录日志
  5652. // byterequest, _ := json.Marshal(s)
  5653. // adviceLog := models.XtDoctorAdviceLog{
  5654. // UserOrgId: s.UserOrgId,
  5655. // PatientId: s.PatientId,
  5656. // AdminUserId: adminInfo.AdminUser.Id,
  5657. // Module: 1,
  5658. // ErrLog: string(byterequest),
  5659. // Status: 1,
  5660. // Ctime: time.Now().Unix(),
  5661. // Mtime: 0,
  5662. // Source: "电脑端his医嘱修改",
  5663. // RecordDate: s.AdviceDate,
  5664. // }
  5665. // service.CreateDoctorAdviceLog(adviceLog)
  5666. // redis := service.RedisClient()
  5667. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5668. // redis.Set(key, "", time.Second)
  5669. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5670. // fmt.Println("keyOne", keyOne)
  5671. // redis.Set(keyOne, "", time.Second)
  5672. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5673. // redis.Set(keySeven, "", time.Second)
  5674. // redis.Close()
  5675. //
  5676. // }
  5677. // }
  5678. // }
  5679. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5680. // projects := items["project"].([]interface{})
  5681. // if len(projects) > 0 {
  5682. // for _, project := range projects {
  5683. // var p models.HisPrescriptionProject
  5684. // p.PrescriptionId = prescription.ID
  5685. // p.Ctime = time.Now().Unix()
  5686. // p.Mtime = time.Now().Unix()
  5687. // p.PatientId = patient_id
  5688. // p.RecordDate = recordDateTime
  5689. // p.UserOrgId = adminInfo.CurrentOrgId
  5690. // p.HisPatientId = his_patient_id
  5691. // p.Status = 1
  5692. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5693. // if errcode > 0 {
  5694. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5695. // return
  5696. // }
  5697. // service.CreateHisProjectTwo(&p)
  5698. //
  5699. // //记录日志
  5700. // byterequest, _ := json.Marshal(p)
  5701. // adviceLog := models.XtDoctorAdviceLog{
  5702. // UserOrgId: p.UserOrgId,
  5703. // PatientId: p.PatientId,
  5704. // AdminUserId: adminInfo.AdminUser.Id,
  5705. // Module: 1,
  5706. // ErrLog: string(byterequest),
  5707. // Status: 1,
  5708. // Ctime: time.Now().Unix(),
  5709. // Mtime: 0,
  5710. // Source: "电脑端his项目修改",
  5711. // RecordDate: p.RecordDate,
  5712. // }
  5713. // service.CreateDoctorAdviceLog(adviceLog)
  5714. // }
  5715. // }
  5716. // }
  5717. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5718. // addition := items["addition"].([]interface{})
  5719. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5720. // ctime := time.Now().Unix()
  5721. // mtime := ctime
  5722. // if len(addition) > 0 {
  5723. // for _, item := range addition {
  5724. // var s models.HisAdditionalCharge
  5725. // s.PrescriptionId = prescription.ID
  5726. // s.Status = 1
  5727. // s.UserOrgId = adminInfo.CurrentOrgId
  5728. // s.RecordDate = recordDateTime
  5729. // s.CreatedTime = ctime
  5730. // s.UpdatedTime = mtime
  5731. // s.PatientId = patient_id
  5732. // s.HisPatientId = his_patient_id
  5733. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5734. // if errcode > 0 {
  5735. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5736. // return
  5737. // }
  5738. // service.CreateAdditionalCharge(&s)
  5739. // }
  5740. // }
  5741. // }
  5742. //
  5743. // }
  5744. // }
  5745. // }
  5746. // if err == nil {
  5747. // c.ServeSuccessJSON(map[string]interface{}{
  5748. // "msg": "保存成功",
  5749. // })
  5750. // return
  5751. //
  5752. // } else {
  5753. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5754. // return
  5755. // }
  5756. //}
  5757. func (c *HisApiController) DeletePrescription() {
  5758. prescription_id, _ := c.GetInt64("id")
  5759. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5760. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5761. ////同步到自备药
  5762. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5763. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5764. if selfPrescriptionOpen.IsOpen == 1 {
  5765. // 在函数结束时处理事务回滚
  5766. db := service.XTWriteDB()
  5767. tx := db.Begin()
  5768. defer func() {
  5769. if r := recover(); r != nil {
  5770. tx.Rollback()
  5771. } else {
  5772. tx.Commit()
  5773. }
  5774. }()
  5775. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5776. for _, item := range advicesList {
  5777. timeStr := time.Now().Format("2006-01-02")
  5778. timeArr := strings.Split(timeStr, "-")
  5779. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5780. total = total + 1
  5781. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5782. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5783. number = number + total
  5784. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5785. operation_time := time.Now().Unix()
  5786. creater := c.GetAdminUserInfo().AdminUser.Id
  5787. //创建一个出库单
  5788. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5789. WarehouseOutOrderNumber: warehousing_out_order,
  5790. OperationTime: operation_time,
  5791. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5792. Creater: creater,
  5793. Ctime: time.Now().Unix(),
  5794. Status: 1,
  5795. WarehouseOutTime: item.AdviceDate,
  5796. Type: 0,
  5797. PatientId: item.PatientId,
  5798. IsCheck: 1,
  5799. }
  5800. //查询今日是否有出库数据
  5801. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5802. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5803. if lastWarehouseOut.ID == 0 {
  5804. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5805. }
  5806. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5807. var total_count int64
  5808. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5809. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5810. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5811. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5812. }
  5813. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5814. total_count += prescribingNumberSeven
  5815. }
  5816. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5817. total_count += prescribingNumberSeven
  5818. }
  5819. //出库
  5820. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5821. WarehouseOutOrderNumber: warehousing_out_order,
  5822. WarehouseOutId: lastWarehouseOut.ID,
  5823. DrugId: item.DrugId,
  5824. Count: total_count,
  5825. Price: 0,
  5826. TotalPrice: 0,
  5827. Status: 1,
  5828. Ctime: item.AdviceDate,
  5829. Mtime: item.AdviceDate,
  5830. Remark: "",
  5831. OrgId: item.UserOrgId,
  5832. Type: 0,
  5833. Manufacturer: selfBasedrug.Manufacturer,
  5834. Dealer: selfBasedrug.Dealer,
  5835. RetailPrice: 0,
  5836. RetailTotalPrice: 0,
  5837. CountUnit: selfBasedrug.MinUnit,
  5838. ExpiryDate: 0,
  5839. ProductDate: 0,
  5840. Number: "",
  5841. BatchNumber: "",
  5842. IsSys: 1,
  5843. WarehouseInfoId: 0,
  5844. AdminUserId: 0,
  5845. StockCount: "",
  5846. IsCheck: 1,
  5847. SysRecordTime: item.AdviceDate,
  5848. PatientId: item.PatientId,
  5849. ClassType: "",
  5850. AdviceId: item.ID,
  5851. }
  5852. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5853. }
  5854. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5855. for _, it := range warehousingOutInfo {
  5856. //查询今日是否有出库数据
  5857. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5858. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5859. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5860. //出库逻辑
  5861. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5862. //查询剩余库存
  5863. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5864. var sum_count int64
  5865. for _, its := range stockInfo {
  5866. if its.MaxUnit == medical.MaxUnit {
  5867. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5868. }
  5869. sum_count += its.StockMaxNumber + its.StockMinNumber
  5870. }
  5871. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5872. }
  5873. }
  5874. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5875. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5876. //耗材保存处方出库
  5877. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5878. //已收费和已发药限制逻辑
  5879. isCharge := false
  5880. isMedicine := false
  5881. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5882. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5883. if new_prescription.IsMedicine == 1 {
  5884. isMedicine = true
  5885. }
  5886. for _, item := range new_prescriptions {
  5887. if item.OrderStatus == 4 {
  5888. isCharge = true
  5889. }
  5890. }
  5891. if p_err != nil {
  5892. if new_prescription.ID > 0 {
  5893. if new_prescription.OrderStatus == 2 {
  5894. isCharge = true
  5895. }
  5896. }
  5897. }
  5898. for _, item := range advices {
  5899. if item.IsMedicine == 1 {
  5900. isMedicine = true
  5901. }
  5902. }
  5903. if isCharge {
  5904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5905. return
  5906. }
  5907. if isMedicine {
  5908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5909. return
  5910. }
  5911. //已收费和已发药限制逻辑
  5912. if len(projects) > 0 {
  5913. for _, item := range projects {
  5914. service.DeletePrintInfo(item.ID) //删除打印信息
  5915. if goodOutConfig.IsOpen != 1 {
  5916. if stockConfig.IsOpen == 1 {
  5917. if item.Type == 3 && item.IsOut == 1 {
  5918. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5919. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5920. good.Total = good.Total + f_count
  5921. service.UpdateGoodInfo(&good)
  5922. operation_time := time.Now().Unix()
  5923. creater := c.GetAdminUserInfo().AdminUser.Id
  5924. //创建退库单
  5925. timeStr := time.Now().Format("2006-01-02")
  5926. timeArr := strings.Split(timeStr, "-")
  5927. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5928. total = total + 1
  5929. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5930. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5931. cancelStock := models.CancelStock{
  5932. OrderNumber: orderNumber,
  5933. OperaTime: operation_time,
  5934. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5935. Creater: creater,
  5936. Ctime: time.Now().Unix(),
  5937. Status: 1,
  5938. ReturnTime: item.RecordDate,
  5939. Type: 1,
  5940. StorehouseId: houseConfig.StorehouseOutInfo,
  5941. IsCheck: 1,
  5942. }
  5943. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5944. if msgerrkonde == gorm.ErrRecordNotFound {
  5945. service.AddSigleCancelStock(&cancelStock)
  5946. }
  5947. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5948. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5949. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5950. //查询该耗材是否出库
  5951. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5952. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5953. deaerler, _ := service.GetDealerById(info.Dealer)
  5954. var total_count int64
  5955. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5956. total_count += count
  5957. if info.ID > 0 {
  5958. if info.Count >= total_count {
  5959. //回退库存
  5960. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5961. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5962. var flush_count int64
  5963. for _, it := range goodList {
  5964. flush_count += it.StockCount
  5965. }
  5966. cancelStockInfo := models.CancelStockInfo{
  5967. GoodId: item.ProjectId,
  5968. CancelStockId: cancel.ID,
  5969. GoodTypeId: good.GoodTypeId,
  5970. Count: prescribingNumber,
  5971. Price: info.Price,
  5972. Total: 0,
  5973. ProductDate: info.ProductDate,
  5974. ExpiryDate: info.ExpiryDate,
  5975. Ctime: time.Now().Unix(),
  5976. Status: 1,
  5977. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5978. OrderNumber: cancel.OrderNumber,
  5979. Type: 0,
  5980. Dealer: deaerler.DealerName,
  5981. Manufacturer: manufacturer.ManufacturerName,
  5982. Number: info.Number,
  5983. RegisterAccount: "",
  5984. Remark: "",
  5985. WarehouseInfoId: info.WarehouseInfotId,
  5986. PatientId: info.PatientId,
  5987. RecordDate: info.SysRecordTime,
  5988. StorehouseId: houseConfig.StorehouseOutInfo,
  5989. IsCheck: 1,
  5990. }
  5991. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5992. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5993. flow := models.VmStockFlow{
  5994. WarehousingId: info.WarehouseInfotId,
  5995. GoodId: item.ProjectId,
  5996. Number: info.Number,
  5997. LicenseNumber: info.LicenseNumber,
  5998. Count: prescribingNumber,
  5999. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6000. PatientId: item.PatientId,
  6001. SystemTime: info.SysRecordTime,
  6002. ConsumableType: 7,
  6003. IsSys: 0,
  6004. WarehousingOrder: "",
  6005. WarehouseOutId: info.WarehouseOutId,
  6006. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6007. IsEdit: 0,
  6008. CancelStockId: cancel.ID,
  6009. CancelOrderNumber: cancel.OrderNumber,
  6010. Manufacturer: manufacturer.ID,
  6011. Dealer: 0,
  6012. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6013. UpdateCreator: 0,
  6014. Status: 1,
  6015. Ctime: time.Now().Unix(),
  6016. Mtime: 0,
  6017. Price: info.Price,
  6018. WarehousingDetailId: info.WarehouseInfotId,
  6019. WarehouseOutDetailId: info.ID,
  6020. CancelOutDetailId: cancelInfo.ID,
  6021. ProductDate: info.ProductDate,
  6022. ExpireDate: info.ExpiryDate,
  6023. StorehouseId: houseConfig.StorehouseOutInfo,
  6024. OverCount: flush_count,
  6025. OperateTime: time.Now().Unix(),
  6026. }
  6027. service.CreateStockFlowOne(flow)
  6028. //退库数量增加
  6029. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6030. //出库数量减少
  6031. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6032. }
  6033. if info.Count < total_count {
  6034. //回退库存
  6035. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6036. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6037. var flush_count int64
  6038. for _, it := range goodList {
  6039. flush_count += it.StockCount
  6040. }
  6041. cancelStockInfo := models.CancelStockInfo{
  6042. GoodId: item.ProjectId,
  6043. CancelStockId: cancel.ID,
  6044. GoodTypeId: good.GoodTypeId,
  6045. Count: info.Count,
  6046. Price: info.Price,
  6047. Total: 0,
  6048. ProductDate: info.ProductDate,
  6049. ExpiryDate: info.ExpiryDate,
  6050. Ctime: time.Now().Unix(),
  6051. Status: 1,
  6052. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6053. OrderNumber: cancel.OrderNumber,
  6054. Type: 0,
  6055. Dealer: deaerler.DealerName,
  6056. Manufacturer: manufacturer.ManufacturerName,
  6057. Number: info.Number,
  6058. RegisterAccount: "",
  6059. Remark: "",
  6060. WarehouseInfoId: info.WarehouseInfotId,
  6061. PatientId: info.PatientId,
  6062. RecordDate: info.SysRecordTime,
  6063. StorehouseId: houseConfig.StorehouseOutInfo,
  6064. IsCheck: 1,
  6065. }
  6066. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6067. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6068. flow := models.VmStockFlow{
  6069. WarehousingId: info.WarehouseInfotId,
  6070. GoodId: item.ProjectId,
  6071. Number: info.Number,
  6072. LicenseNumber: info.LicenseNumber,
  6073. Count: info.Count,
  6074. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6075. PatientId: item.PatientId,
  6076. SystemTime: info.SysRecordTime,
  6077. ConsumableType: 7,
  6078. IsSys: 0,
  6079. WarehousingOrder: "",
  6080. WarehouseOutId: info.WarehouseOutId,
  6081. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6082. IsEdit: 0,
  6083. CancelStockId: cancel.ID,
  6084. CancelOrderNumber: cancel.OrderNumber,
  6085. Manufacturer: manufacturer.ID,
  6086. Dealer: 0,
  6087. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6088. UpdateCreator: 0,
  6089. Status: 1,
  6090. Ctime: time.Now().Unix(),
  6091. Mtime: 0,
  6092. Price: info.Price,
  6093. WarehousingDetailId: info.WarehouseInfotId,
  6094. WarehouseOutDetailId: info.ID,
  6095. CancelOutDetailId: cancelInfo.ID,
  6096. ProductDate: info.ProductDate,
  6097. ExpireDate: info.ExpiryDate,
  6098. StorehouseId: houseConfig.StorehouseOutInfo,
  6099. OverCount: flush_count,
  6100. OperateTime: time.Now().Unix(),
  6101. }
  6102. service.CreateStockFlowOne(flow)
  6103. //退库数量增加
  6104. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6105. //出库数量减少
  6106. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6107. }
  6108. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6109. var flush_count int64
  6110. for _, it := range goodList {
  6111. flush_count += it.StockCount
  6112. }
  6113. //查询已出库数量
  6114. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6115. if prescribingNumber < dialysisInfo.Count {
  6116. //改变数量
  6117. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6118. }
  6119. if prescribingNumber >= dialysisInfo.Count {
  6120. //删除出库表
  6121. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6122. }
  6123. //更新库存
  6124. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6125. //更新基础库库存
  6126. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6127. }
  6128. }
  6129. }
  6130. }
  6131. //保存耗材出库
  6132. if goodOutConfig.IsOpen == 1 {
  6133. if item.Type == 3 {
  6134. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6135. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6136. good.Total = good.Total + f_count
  6137. service.UpdateGoodInfo(&good)
  6138. operation_time := time.Now().Unix()
  6139. creater := c.GetAdminUserInfo().AdminUser.Id
  6140. //创建退库单
  6141. timeStr := time.Now().Format("2006-01-02")
  6142. timeArr := strings.Split(timeStr, "-")
  6143. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6144. total = total + 1
  6145. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6146. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6147. cancelStock := models.CancelStock{
  6148. OrderNumber: orderNumber,
  6149. OperaTime: operation_time,
  6150. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6151. Creater: creater,
  6152. Ctime: time.Now().Unix(),
  6153. Status: 1,
  6154. ReturnTime: item.RecordDate,
  6155. Type: 1,
  6156. StorehouseId: houseConfig.StorehouseOutInfo,
  6157. IsCheck: 1,
  6158. }
  6159. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6160. if msgerrkonde == gorm.ErrRecordNotFound {
  6161. service.AddSigleCancelStock(&cancelStock)
  6162. }
  6163. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6164. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6165. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6166. //查询该耗材是否出库
  6167. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6168. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6169. deaerler, _ := service.GetDealerById(info.Dealer)
  6170. var total_count int64
  6171. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6172. total_count += count
  6173. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6174. var flush_count int64
  6175. for _, it := range goodList {
  6176. flush_count += it.StockCount
  6177. }
  6178. fmt.Println("历史出库数据", info.Count)
  6179. fmt.Println("出库数量", total_count)
  6180. if info.ID > 0 {
  6181. cancelStockInfo := models.CancelStockInfo{
  6182. GoodId: item.ProjectId,
  6183. CancelStockId: cancel.ID,
  6184. GoodTypeId: good.GoodTypeId,
  6185. Count: prescribingNumber,
  6186. Price: info.Price,
  6187. Total: 0,
  6188. ProductDate: info.ProductDate,
  6189. ExpiryDate: info.ExpiryDate,
  6190. Ctime: time.Now().Unix(),
  6191. Status: 1,
  6192. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6193. OrderNumber: cancel.OrderNumber,
  6194. Type: 0,
  6195. Dealer: deaerler.DealerName,
  6196. Manufacturer: manufacturer.ManufacturerName,
  6197. Number: info.Number,
  6198. RegisterAccount: "",
  6199. Remark: "",
  6200. WarehouseInfoId: info.WarehouseInfotId,
  6201. PatientId: info.PatientId,
  6202. RecordDate: info.SysRecordTime,
  6203. StorehouseId: houseConfig.StorehouseOutInfo,
  6204. IsCheck: 1,
  6205. }
  6206. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6207. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6208. //查询出库数量
  6209. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6210. //出库数据 大于 退库数量
  6211. if len(list) > 0 {
  6212. for _, it := range list {
  6213. //回退库存
  6214. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6215. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6216. var flush_count_one int64
  6217. for _, it := range goodList {
  6218. flush_count_one += it.StockCount
  6219. }
  6220. //查询该批次是否有退库数据
  6221. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6222. creater := c.GetAdminUserInfo().AdminUser.Id
  6223. flow := models.VmStockFlow{
  6224. WarehousingId: it.WarehouseInfotId,
  6225. GoodId: it.GoodId,
  6226. Number: it.Number,
  6227. LicenseNumber: it.LicenseNumber,
  6228. Count: it.Count,
  6229. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6230. PatientId: it.PatientId,
  6231. SystemTime: it.SysRecordTime,
  6232. ConsumableType: 7,
  6233. IsSys: 0,
  6234. WarehousingOrder: "",
  6235. WarehouseOutId: it.WarehouseOutId,
  6236. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6237. IsEdit: 0,
  6238. CancelStockId: cancel.ID,
  6239. CancelOrderNumber: cancel.OrderNumber,
  6240. Manufacturer: manufacturer.ID,
  6241. Dealer: 0,
  6242. Creator: creater,
  6243. UpdateCreator: 0,
  6244. Status: 1,
  6245. Ctime: time.Now().Unix(),
  6246. Mtime: 0,
  6247. Price: it.Price,
  6248. WarehousingDetailId: it.WarehouseInfotId,
  6249. WarehouseOutDetailId: it.ID,
  6250. CancelOutDetailId: cancelInfo.ID,
  6251. ProductDate: it.ProductDate,
  6252. ExpireDate: it.ExpiryDate,
  6253. StorehouseId: houseConfig.StorehouseOutInfo,
  6254. OverCount: flush_count_one,
  6255. OperateTime: time.Now().Unix(),
  6256. }
  6257. service.CreateStockFlowOne(flow)
  6258. //if flow.ID > 0 {
  6259. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6260. //}
  6261. }
  6262. }
  6263. //flow := models.VmStockFlow{
  6264. // WarehousingId: info.WarehouseInfotId,
  6265. // GoodId: item.ProjectId,
  6266. // Number: info.Number,
  6267. // LicenseNumber: info.LicenseNumber,
  6268. // Count: prescribingNumber,
  6269. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6270. // PatientId: item.PatientId,
  6271. // SystemTime: info.SysRecordTime,
  6272. // ConsumableType: 7,
  6273. // IsSys: 0,
  6274. // WarehousingOrder: "",
  6275. // WarehouseOutId: info.WarehouseOutId,
  6276. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6277. // IsEdit: 0,
  6278. // CancelStockId: cancel.ID,
  6279. // CancelOrderNumber: cancel.OrderNumber,
  6280. // Manufacturer: manufacturer.ID,
  6281. // Dealer: 0,
  6282. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6283. // UpdateCreator: 0,
  6284. // Status: 1,
  6285. // Ctime: time.Now().Unix(),
  6286. // Mtime: 0,
  6287. // Price: info.Price,
  6288. // WarehousingDetailId: info.WarehouseInfotId,
  6289. // WarehouseOutDetailId: info.ID,
  6290. // CancelOutDetailId: cancelInfo.ID,
  6291. // ProductDate: info.ProductDate,
  6292. // ExpireDate: info.ExpiryDate,
  6293. // StorehouseId: houseConfig.StorehouseOutInfo,
  6294. // OverCount: flush_count,
  6295. //}
  6296. //service.CreateStockFlowOne(flow)
  6297. //退库数量增加
  6298. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6299. //出库数量减少
  6300. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6301. //查询已出库数量
  6302. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6303. if prescribingNumber < dialysisInfo.Count {
  6304. //改变数量
  6305. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6306. }
  6307. if prescribingNumber >= dialysisInfo.Count {
  6308. //删除出库表
  6309. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6310. }
  6311. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6312. var flush_count_one int64
  6313. for _, it := range goodList {
  6314. flush_count_one += it.StockCount
  6315. }
  6316. //更新库存
  6317. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6318. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6319. //更新基础库库存
  6320. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6321. }
  6322. }
  6323. }
  6324. }
  6325. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6326. fmt.Println(err)
  6327. }
  6328. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6329. fmt.Println(err)
  6330. if len(advices) > 0 {
  6331. for _, item := range advices {
  6332. redis := service.RedisClient()
  6333. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6334. redis.Set(keyFive, "", time.Second)
  6335. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6336. redis.Set(keyOne, "", time.Second)
  6337. redis.Close()
  6338. }
  6339. }
  6340. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6341. if len(advices) > 0 {
  6342. for _, item := range advices {
  6343. creater := c.GetAdminUserInfo().AdminUser.Id
  6344. service.DrugAutoAddCancelInfo(item, creater)
  6345. }
  6346. }
  6347. } else {
  6348. if drugOutConfig.IsOpen == 1 {
  6349. if len(advices) > 0 {
  6350. for _, item := range advices {
  6351. creater := c.GetAdminUserInfo().AdminUser.Id
  6352. service.DrugAutoAddCancelInfo(item, creater)
  6353. }
  6354. }
  6355. } else {
  6356. if len(advices) > 0 {
  6357. for _, item := range advices {
  6358. creater := c.GetAdminUserInfo().AdminUser.Id
  6359. service.DrugAutoAddCancelInfo(item, creater)
  6360. }
  6361. }
  6362. }
  6363. }
  6364. c.ServeSuccessJSON(map[string]interface{}{
  6365. "msg": "删除成功",
  6366. })
  6367. return
  6368. }
  6369. func (c *HisApiController) DeleteDoctorAdvice() {
  6370. id, _ := c.GetInt64("id")
  6371. advice, _ := service.GetHisDoctorAdvicesById(id)
  6372. ////同步到自备药
  6373. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6374. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6375. if selfPrescriptionOpen.IsOpen == 1 {
  6376. db := service.XTWriteDB()
  6377. tx := db.Begin()
  6378. defer func() {
  6379. if r := recover(); r != nil {
  6380. tx.Rollback()
  6381. } else {
  6382. tx.Commit()
  6383. }
  6384. }()
  6385. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6386. var total_count int64
  6387. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6388. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6389. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6390. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6391. }
  6392. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6393. total_count += prescribingNumberSeven
  6394. }
  6395. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6396. total_count += prescribingNumberSeven
  6397. }
  6398. timeStr := time.Now().Format("2006-01-02")
  6399. timeArr := strings.Split(timeStr, "-")
  6400. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6401. total = total + 1
  6402. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6403. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6404. number = number + total
  6405. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6406. operation_time := time.Now().Unix()
  6407. creater := c.GetAdminUserInfo().AdminUser.Id
  6408. //创建一个出库单
  6409. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6410. WarehouseOutOrderNumber: warehousing_out_order,
  6411. OperationTime: operation_time,
  6412. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6413. Creater: creater,
  6414. Ctime: time.Now().Unix(),
  6415. Status: 1,
  6416. WarehouseOutTime: advice.AdviceDate,
  6417. Type: 0,
  6418. PatientId: advice.PatientId,
  6419. IsCheck: 1,
  6420. }
  6421. //查询今日是否有出库数据
  6422. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6423. if lastWarehouseOut.ID == 0 {
  6424. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6425. }
  6426. //出库
  6427. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6428. WarehouseOutId: lastWarehouseOut.ID,
  6429. WarehouseOutOrderNumber: warehousing_out_order,
  6430. DrugId: advice.DrugId,
  6431. Count: total_count,
  6432. Price: 0,
  6433. TotalPrice: 0,
  6434. Status: 1,
  6435. Ctime: advice.AdviceDate,
  6436. Mtime: advice.AdviceDate,
  6437. Remark: "",
  6438. OrgId: advice.UserOrgId,
  6439. Type: 0,
  6440. Manufacturer: selfBasedrug.Manufacturer,
  6441. Dealer: selfBasedrug.Dealer,
  6442. RetailPrice: 0,
  6443. RetailTotalPrice: 0,
  6444. CountUnit: advice.PrescribingNumberUnit,
  6445. ExpiryDate: 0,
  6446. ProductDate: 0,
  6447. Number: "",
  6448. BatchNumber: "",
  6449. IsSys: 0,
  6450. WarehouseInfoId: 0,
  6451. AdminUserId: 0,
  6452. StockCount: "",
  6453. IsCheck: 1,
  6454. SysRecordTime: advice.AdviceDate,
  6455. PatientId: advice.PatientId,
  6456. AdviceId: advice.ID,
  6457. ClassType: "",
  6458. }
  6459. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6460. for _, it := range warehousingOutInfo {
  6461. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6462. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6463. //出库逻辑
  6464. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6465. //查询剩余库存
  6466. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6467. var sum_count int64
  6468. for _, its := range stockInfo {
  6469. if its.MaxUnit == medical.MaxUnit {
  6470. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6471. }
  6472. sum_count += its.StockMaxNumber + its.StockMinNumber
  6473. }
  6474. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6475. }
  6476. }
  6477. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6478. //已收费和已发药的限制逻辑
  6479. isCharge := false
  6480. isMedicine := false
  6481. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6482. //获取今天该患者所有处方,判断是否发药或者收费
  6483. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6484. //for _, item := range new_prescriptions {
  6485. if new_prescription.IsMedicine == 1 {
  6486. isMedicine = true
  6487. }
  6488. //}
  6489. for _, item := range new_prescriptions {
  6490. if item.OrderStatus == 4 {
  6491. isCharge = true
  6492. }
  6493. }
  6494. if isMedicine {
  6495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6496. return
  6497. }
  6498. if isCharge {
  6499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6500. return
  6501. }
  6502. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6503. for _, item := range advices {
  6504. if item.IsMedicine == 1 {
  6505. isMedicine = true
  6506. }
  6507. }
  6508. if isMedicine {
  6509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6510. return
  6511. }
  6512. if new_prescription.ID > 0 {
  6513. if new_prescription.OrderStatus == 2 {
  6514. isCharge = true
  6515. }
  6516. }
  6517. if isCharge {
  6518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6519. return
  6520. }
  6521. //已收费和已发药的限制逻辑
  6522. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6523. redis := service.RedisClient()
  6524. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6525. redis.Set(keyFive, "", time.Second)
  6526. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6527. redis.Set(keyOne, "", time.Second)
  6528. defer redis.Close()
  6529. if err == nil {
  6530. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6531. //查询是否在处方中出库
  6532. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6533. if openConfig.IsOpen != 1 {
  6534. //判断该医嘱是否执行了
  6535. if advice.ExecutionState == 1 {
  6536. creater := c.GetAdminUserInfo().AdminUser.Id
  6537. service.DrugAutoAddCancelInfo(&advice, creater)
  6538. }
  6539. }
  6540. //开启保存处方扣减功能
  6541. if openConfig.IsOpen == 1 {
  6542. creater := c.GetAdminUserInfo().AdminUser.Id
  6543. service.DrugAutoAddCancelInfo(&advice, creater)
  6544. }
  6545. } else {
  6546. if drugOutConfig.IsOpen == 1 {
  6547. //查询是否在处方中出库
  6548. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6549. if openConfig.IsOpen != 1 {
  6550. //判断该医嘱是否执行了
  6551. if advice.ExecutionState == 1 {
  6552. creater := c.GetAdminUserInfo().AdminUser.Id
  6553. service.DrugAutoAddCancelInfo(&advice, creater)
  6554. }
  6555. }
  6556. //开启保存处方扣减功能
  6557. if openConfig.IsOpen == 1 {
  6558. creater := c.GetAdminUserInfo().AdminUser.Id
  6559. service.DrugAutoAddCancelInfo(&advice, creater)
  6560. }
  6561. } else {
  6562. //判断该医嘱是否执行了
  6563. if advice.ExecutionState == 1 {
  6564. creater := c.GetAdminUserInfo().AdminUser.Id
  6565. service.DrugAutoAddCancelInfo(&advice, creater)
  6566. }
  6567. }
  6568. }
  6569. c.ServeSuccessJSON(map[string]interface{}{
  6570. "msg": "删除成功",
  6571. })
  6572. return
  6573. } else {
  6574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6575. return
  6576. }
  6577. }
  6578. func (c *HisApiController) DeleteProject() {
  6579. id, _ := c.GetInt64("id")
  6580. adminInfo := c.GetAdminUserInfo()
  6581. project, _ := service.GetHisProjectByID(id)
  6582. // var consumable models.DialysisBeforePrepare
  6583. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6584. //耗材保存处方出库
  6585. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6586. isCharge := false
  6587. isMedicine := false
  6588. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6589. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6590. for _, item := range new_prescriptions {
  6591. if item.IsMedicine == 1 {
  6592. isMedicine = true
  6593. }
  6594. }
  6595. for _, item := range new_prescriptions {
  6596. if item.OrderStatus == 4 {
  6597. isCharge = true
  6598. }
  6599. }
  6600. if isMedicine {
  6601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6602. return
  6603. }
  6604. if isCharge {
  6605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6606. return
  6607. }
  6608. if new_prescription.ID > 0 {
  6609. if new_prescription.OrderStatus == 2 {
  6610. isCharge = true
  6611. }
  6612. }
  6613. if isCharge {
  6614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6615. return
  6616. }
  6617. service.DeletePrintInfo(id)
  6618. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6619. label.Status = 0
  6620. service.CreateHisLabelRecordTwo(&label)
  6621. fmt.Println(goodOutConfig.IsOpen)
  6622. if goodOutConfig.IsOpen != 1 {
  6623. if stockConfig.IsOpen == 1 {
  6624. if project.Type == 2 {
  6625. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6626. fmt.Println(err)
  6627. }
  6628. if project.Type == 3 && project.IsOut == 1 {
  6629. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6630. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6631. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6632. operation_time := time.Now().Unix()
  6633. creater := adminInfo.AdminUser.Id
  6634. //创建退库单
  6635. timeStr := time.Now().Format("2006-01-02")
  6636. timeArr := strings.Split(timeStr, "-")
  6637. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6638. total = total + 1
  6639. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6640. cancelStock := models.CancelStock{
  6641. OrderNumber: orderNumber,
  6642. OperaTime: operation_time,
  6643. OrgId: adminInfo.CurrentOrgId,
  6644. Creater: creater,
  6645. Ctime: time.Now().Unix(),
  6646. Status: 1,
  6647. ReturnTime: project.RecordDate,
  6648. Type: 1,
  6649. StorehouseId: houseConfig.StorehouseOutInfo,
  6650. IsCheck: 1,
  6651. }
  6652. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6653. if msgerrkonde == gorm.ErrRecordNotFound {
  6654. service.AddSigleCancelStock(&cancelStock)
  6655. }
  6656. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6657. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6658. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6659. //查询是否有出库
  6660. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6661. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6662. deaerler, _ := service.GetDealerById(info.Dealer)
  6663. if info.ID > 0 {
  6664. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6665. if info.Count >= prescribingNumber {
  6666. cancelStockInfo := models.CancelStockInfo{
  6667. GoodId: project.ProjectId,
  6668. CancelStockId: cancel.ID,
  6669. GoodTypeId: good.GoodTypeId,
  6670. Count: prescribingNumber,
  6671. Price: info.Price,
  6672. Total: 0,
  6673. ProductDate: info.ProductDate,
  6674. ExpiryDate: info.ExpiryDate,
  6675. Ctime: time.Now().Unix(),
  6676. Status: 1,
  6677. OrgId: adminInfo.CurrentOrgId,
  6678. OrderNumber: cancel.OrderNumber,
  6679. Type: 0,
  6680. Dealer: deaerler.DealerName,
  6681. Manufacturer: manufacturer.ManufacturerName,
  6682. Number: info.Number,
  6683. RegisterAccount: "",
  6684. Remark: "",
  6685. WarehouseInfoId: info.WarehouseInfotId,
  6686. PatientId: info.PatientId,
  6687. RecordDate: info.SysRecordTime,
  6688. StorehouseId: houseConfig.StorehouseOutInfo,
  6689. IsCheck: 1,
  6690. }
  6691. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6692. //回退库存
  6693. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6694. //退库数量增加
  6695. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6696. //出库数量减少
  6697. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6698. }
  6699. if info.Count < prescribingNumber {
  6700. cancelStockInfo := models.CancelStockInfo{
  6701. GoodId: project.ProjectId,
  6702. CancelStockId: cancel.ID,
  6703. GoodTypeId: good.GoodTypeId,
  6704. Count: info.Count,
  6705. Price: info.Price,
  6706. Total: 0,
  6707. ProductDate: info.ProductDate,
  6708. ExpiryDate: info.ExpiryDate,
  6709. Ctime: time.Now().Unix(),
  6710. Status: 1,
  6711. OrgId: adminInfo.CurrentOrgId,
  6712. OrderNumber: cancel.OrderNumber,
  6713. Type: 0,
  6714. Dealer: deaerler.DealerName,
  6715. Manufacturer: manufacturer.ManufacturerName,
  6716. Number: info.Number,
  6717. RegisterAccount: "",
  6718. Remark: "",
  6719. WarehouseInfoId: info.WarehouseInfotId,
  6720. PatientId: info.PatientId,
  6721. RecordDate: info.SysRecordTime,
  6722. StorehouseId: houseConfig.StorehouseOutInfo,
  6723. IsCheck: 1,
  6724. }
  6725. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6726. //回退库存
  6727. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6728. //退库数量增加
  6729. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6730. //出库数量减少
  6731. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6732. }
  6733. //查询剩余库存
  6734. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6735. var over_count int64
  6736. for _, it := range goodList {
  6737. over_count += it.StockCount
  6738. }
  6739. //出库数据 大于 退库数量
  6740. if info.Count >= prescribingNumber {
  6741. flow := models.VmStockFlow{
  6742. WarehousingId: info.WarehouseInfotId,
  6743. GoodId: project.ProjectId,
  6744. Number: info.Number,
  6745. LicenseNumber: info.LicenseNumber,
  6746. Count: prescribingNumber,
  6747. UserOrgId: adminInfo.CurrentOrgId,
  6748. PatientId: project.PatientId,
  6749. SystemTime: info.SysRecordTime,
  6750. ConsumableType: 7,
  6751. IsSys: 0,
  6752. WarehousingOrder: "",
  6753. WarehouseOutId: info.WarehouseOutId,
  6754. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6755. IsEdit: 0,
  6756. CancelStockId: cancel.ID,
  6757. CancelOrderNumber: cancel.OrderNumber,
  6758. Manufacturer: manufacturer.ID,
  6759. Dealer: 0,
  6760. Creator: adminInfo.AdminUser.Id,
  6761. UpdateCreator: 0,
  6762. Status: 1,
  6763. Ctime: time.Now().Unix(),
  6764. Mtime: 0,
  6765. Price: info.Price,
  6766. WarehousingDetailId: info.WarehouseInfotId,
  6767. WarehouseOutDetailId: info.ID,
  6768. CancelOutDetailId: cancelInfo.ID,
  6769. ProductDate: info.ProductDate,
  6770. ExpireDate: info.ExpiryDate,
  6771. StorehouseId: houseConfig.StorehouseOutInfo,
  6772. OverCount: over_count,
  6773. OperateTime: time.Now().Unix(),
  6774. }
  6775. service.CreateStockFlowOne(flow)
  6776. }
  6777. //出库数据小于退库数据
  6778. if info.Count < prescribingNumber {
  6779. flow := models.VmStockFlow{
  6780. WarehousingId: info.WarehouseInfotId,
  6781. GoodId: project.ProjectId,
  6782. Number: info.Number,
  6783. LicenseNumber: info.LicenseNumber,
  6784. Count: info.Count,
  6785. UserOrgId: adminInfo.CurrentOrgId,
  6786. PatientId: project.PatientId,
  6787. SystemTime: info.SysRecordTime,
  6788. ConsumableType: 7,
  6789. IsSys: 0,
  6790. WarehousingOrder: "",
  6791. WarehouseOutId: info.WarehouseOutId,
  6792. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6793. IsEdit: 0,
  6794. CancelStockId: cancel.ID,
  6795. CancelOrderNumber: cancel.OrderNumber,
  6796. Manufacturer: manufacturer.ID,
  6797. Dealer: 0,
  6798. Creator: adminInfo.AdminUser.Id,
  6799. UpdateCreator: 0,
  6800. Status: 1,
  6801. Ctime: time.Now().Unix(),
  6802. Mtime: 0,
  6803. Price: info.Price,
  6804. WarehousingDetailId: info.WarehouseInfotId,
  6805. WarehouseOutDetailId: info.ID,
  6806. CancelOutDetailId: cancelInfo.ID,
  6807. ProductDate: info.ProductDate,
  6808. ExpireDate: info.ExpiryDate,
  6809. StorehouseId: houseConfig.StorehouseOutInfo,
  6810. OverCount: over_count,
  6811. OperateTime: time.Now().Unix(),
  6812. }
  6813. service.CreateStockFlowOne(flow)
  6814. }
  6815. //查询已出库数量
  6816. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6817. if prescribingNumber < dialysisInfo.Count {
  6818. //改变数量
  6819. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6820. }
  6821. if prescribingNumber >= dialysisInfo.Count {
  6822. //删除出库表
  6823. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6824. }
  6825. //更新剩余库存
  6826. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6827. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6828. var total_count_one int64
  6829. for _, it := range stockList {
  6830. total_count_one += it.StockCount
  6831. }
  6832. //基础库插入数据
  6833. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6834. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6835. var flush_count int64
  6836. for _, it := range goodListOne {
  6837. flush_count += it.StockCount
  6838. }
  6839. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6840. if errs != nil {
  6841. goodErrcode := models.XtGoodErrcode{
  6842. UserOrgId: project.UserOrgId,
  6843. Errcode: "手动出库更新剩余出库失败",
  6844. GoodId: project.ProjectId,
  6845. Status: 1,
  6846. Ctime: time.Now().Unix(),
  6847. Mtime: 0,
  6848. Count: 0,
  6849. StockCount: 0,
  6850. Creater: creater,
  6851. BatchNumberId: 0,
  6852. WarehouseOutId: 0,
  6853. }
  6854. service.CreateGoodErrcode(goodErrcode)
  6855. }
  6856. }
  6857. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6858. fmt.Println(err)
  6859. } else {
  6860. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6861. fmt.Println(err)
  6862. }
  6863. } else {
  6864. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6865. fmt.Println(err)
  6866. }
  6867. }
  6868. //保存处方出库
  6869. if goodOutConfig.IsOpen == 1 {
  6870. if project.Type == 3 {
  6871. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6872. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6873. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6874. operation_time := time.Now().Unix()
  6875. creater := adminInfo.AdminUser.Id
  6876. //创建退库单
  6877. timeStr := time.Now().Format("2006-01-02")
  6878. timeArr := strings.Split(timeStr, "-")
  6879. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6880. total = total + 1
  6881. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6882. cancelStock := models.CancelStock{
  6883. OrderNumber: orderNumber,
  6884. OperaTime: operation_time,
  6885. OrgId: adminInfo.CurrentOrgId,
  6886. Creater: creater,
  6887. Ctime: time.Now().Unix(),
  6888. Status: 1,
  6889. ReturnTime: project.RecordDate,
  6890. Type: 1,
  6891. StorehouseId: houseConfig.StorehouseOutInfo,
  6892. IsCheck: 1,
  6893. }
  6894. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6895. if msgerrkonde == gorm.ErrRecordNotFound {
  6896. service.AddSigleCancelStock(&cancelStock)
  6897. }
  6898. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6899. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6900. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6901. //获取出库数据
  6902. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6903. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6904. deaerler, _ := service.GetDealerById(info.Dealer)
  6905. if info.ID > 0 {
  6906. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  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.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6936. //出库数量减少
  6937. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6938. }
  6939. if info.Count < prescribingNumber {
  6940. cancelStockInfo := models.CancelStockInfo{
  6941. GoodId: project.ProjectId,
  6942. CancelStockId: cancel.ID,
  6943. GoodTypeId: good.GoodTypeId,
  6944. Count: prescribingNumber,
  6945. Price: info.Price,
  6946. Total: 0,
  6947. ProductDate: info.ProductDate,
  6948. ExpiryDate: info.ExpiryDate,
  6949. Ctime: time.Now().Unix(),
  6950. Status: 1,
  6951. OrgId: adminInfo.CurrentOrgId,
  6952. OrderNumber: cancel.OrderNumber,
  6953. Type: 0,
  6954. Dealer: deaerler.DealerName,
  6955. Manufacturer: manufacturer.ManufacturerName,
  6956. Number: info.Number,
  6957. RegisterAccount: "",
  6958. Remark: "",
  6959. WarehouseInfoId: info.WarehouseInfotId,
  6960. PatientId: info.PatientId,
  6961. RecordDate: info.SysRecordTime,
  6962. StorehouseId: houseConfig.StorehouseOutInfo,
  6963. IsCheck: 1,
  6964. }
  6965. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6966. //回退库存
  6967. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6968. }
  6969. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6970. var over_count int64
  6971. for _, it := range goodList {
  6972. over_count += it.StockCount
  6973. }
  6974. //查询出库数量
  6975. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6976. //出库数据 大于 退库数量
  6977. if len(list) > 0 {
  6978. for _, it := range list {
  6979. //回退库存
  6980. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6981. //退库数量增加
  6982. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6983. //出库数量减少
  6984. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6985. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6986. var over_count_one int64
  6987. for _, it := range goodList {
  6988. over_count_one += it.StockCount
  6989. }
  6990. //查询该批次是否有退库数据
  6991. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6992. flow := models.VmStockFlow{
  6993. WarehousingId: it.WarehouseInfotId,
  6994. GoodId: it.GoodId,
  6995. Number: it.Number,
  6996. LicenseNumber: it.LicenseNumber,
  6997. Count: it.Count,
  6998. UserOrgId: adminInfo.CurrentOrgId,
  6999. PatientId: it.PatientId,
  7000. SystemTime: it.SysRecordTime,
  7001. ConsumableType: 7,
  7002. IsSys: 0,
  7003. WarehousingOrder: "",
  7004. WarehouseOutId: it.WarehouseOutId,
  7005. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7006. IsEdit: 0,
  7007. CancelStockId: cancel.ID,
  7008. CancelOrderNumber: cancel.OrderNumber,
  7009. Manufacturer: manufacturer.ID,
  7010. Dealer: 0,
  7011. Creator: adminInfo.AdminUser.Id,
  7012. UpdateCreator: 0,
  7013. Status: 1,
  7014. Ctime: time.Now().Unix(),
  7015. Mtime: 0,
  7016. Price: it.Price,
  7017. WarehousingDetailId: it.WarehouseInfotId,
  7018. WarehouseOutDetailId: it.ID,
  7019. CancelOutDetailId: cancelInfo.ID,
  7020. ProductDate: it.ProductDate,
  7021. ExpireDate: it.ExpiryDate,
  7022. StorehouseId: houseConfig.StorehouseOutInfo,
  7023. OverCount: over_count_one,
  7024. OperateTime: time.Now().Unix(),
  7025. }
  7026. service.CreateStockFlowOne(flow)
  7027. }
  7028. }
  7029. //查询已出库数量
  7030. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7031. if prescribingNumber < dialysisInfo.Count {
  7032. //改变数量
  7033. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7034. }
  7035. if prescribingNumber >= dialysisInfo.Count {
  7036. //删除出库表
  7037. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7038. }
  7039. //更新剩余库存
  7040. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7041. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7042. var total_count_one int64
  7043. for _, it := range stockList {
  7044. total_count_one += it.StockCount
  7045. }
  7046. //基础库插入数据
  7047. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7048. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7049. var flush_count int64
  7050. for _, it := range goodListOne {
  7051. flush_count += it.StockCount
  7052. }
  7053. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7054. if errs != nil {
  7055. goodErrcode := models.XtGoodErrcode{
  7056. UserOrgId: project.UserOrgId,
  7057. Errcode: "手动出库更新剩余出库失败",
  7058. GoodId: project.ProjectId,
  7059. Status: 1,
  7060. Ctime: time.Now().Unix(),
  7061. Mtime: 0,
  7062. Count: 0,
  7063. StockCount: 0,
  7064. Creater: creater,
  7065. BatchNumberId: 0,
  7066. WarehouseOutId: 0,
  7067. }
  7068. service.CreateGoodErrcode(goodErrcode)
  7069. }
  7070. }
  7071. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7072. fmt.Println(err)
  7073. } else {
  7074. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7075. fmt.Println(err)
  7076. }
  7077. }
  7078. c.ServeSuccessJSON(map[string]interface{}{
  7079. "msg": "删除成功",
  7080. })
  7081. return
  7082. }
  7083. func (c *HisApiController) CreateHisAdditionalCharge() {
  7084. his_patient_id, _ := c.GetInt64("his_patient_id")
  7085. patient_id, _ := c.GetInt64("patient_id")
  7086. record_date := c.GetString("record_date")
  7087. timeLayout := "2006-01-02"
  7088. loc, _ := time.LoadLocation("Local")
  7089. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7090. if err != nil {
  7091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7092. return
  7093. }
  7094. adminInfo := c.GetAdminUserInfo()
  7095. recordDateTime := theTime.Unix()
  7096. dataBody := make(map[string]interface{}, 0)
  7097. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7098. if err != nil {
  7099. utils.ErrorLog(err.Error())
  7100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7101. return
  7102. }
  7103. var additions []*models.HisAdditionalCharge
  7104. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7105. additions, _ := dataBody["addition"].([]interface{})
  7106. if len(additions) > 0 {
  7107. for _, item := range additions {
  7108. items := item.(map[string]interface{})
  7109. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7110. utils.ErrorLog("item_id")
  7111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7112. return
  7113. }
  7114. item_id := int64(items["item_id"].(float64))
  7115. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7116. utils.ErrorLog("item_name")
  7117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7118. return
  7119. }
  7120. item_name := items["item_name"].(string)
  7121. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7122. utils.ErrorLog("price")
  7123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7124. return
  7125. }
  7126. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7127. ctime := time.Now().Unix()
  7128. additional := &models.HisAdditionalCharge{
  7129. PatientId: patient_id,
  7130. HisPatientId: his_patient_id,
  7131. UserOrgId: adminInfo.CurrentOrgId,
  7132. RecordDate: recordDateTime,
  7133. CreatedTime: ctime,
  7134. UpdatedTime: ctime,
  7135. Modifier: adminInfo.AdminUser.Id,
  7136. Creator: adminInfo.AdminUser.Id,
  7137. Price: price,
  7138. ItemName: item_name,
  7139. ItemId: item_id,
  7140. Status: 1,
  7141. }
  7142. additions = append(additions, additional)
  7143. }
  7144. }
  7145. }
  7146. for _, item := range additions {
  7147. service.CreateAddtionalCharge(item)
  7148. }
  7149. c.ServeSuccessJSON(map[string]interface{}{
  7150. "msg": "创建成功",
  7151. })
  7152. }
  7153. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7154. blood_fat := c.GetString("blood_fat")
  7155. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7156. blood_sugar := c.GetString("blood_sugar")
  7157. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7158. chief_conplaint := c.GetString("chief_conplaint")
  7159. dbp := c.GetString("dbp")
  7160. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7161. delivery_way, _ := c.GetInt64("delivery_way")
  7162. diagnostic := c.GetString("diagnostic")
  7163. family_history := c.GetString("family_history")
  7164. height := c.GetString("height")
  7165. history_of_present_illness := c.GetString("history_of_present_illness")
  7166. is_infect, _ := c.GetInt64("is_infect")
  7167. past_history := c.GetString("past_history")
  7168. patient_id, _ := c.GetInt64("patient_id")
  7169. his_patient_id, _ := c.GetInt64("his_patient_id")
  7170. personal_history := c.GetString("personal_history")
  7171. pulse := c.GetString("pulse")
  7172. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7173. sbp := c.GetString("sbp")
  7174. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7175. heightfloat, _ := strconv.ParseFloat(height, 64)
  7176. sicktype := c.GetString("sick_type")
  7177. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7178. symptom := c.GetString("symptom")
  7179. sick_date := c.GetString("sick_date")
  7180. temperatures := c.GetString("temperature")
  7181. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7182. record_date := c.GetString("record_date")
  7183. breathing := c.GetString("breathing")
  7184. doctor_advice := c.GetString("doctor_advice")
  7185. remark := c.GetString("remark")
  7186. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7187. sick, _ := c.GetInt64("sick")
  7188. diagnose, _ := c.GetInt64("diagnose")
  7189. //id, _ := c.GetInt64("id")
  7190. timeLayout := "2006-01-02"
  7191. loc, _ := time.LoadLocation("Local")
  7192. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7193. allergic_history := c.GetString("allergic_history")
  7194. if err != nil {
  7195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7196. return
  7197. }
  7198. recordDateTime := theTime.Unix()
  7199. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7200. if err != nil {
  7201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7202. return
  7203. }
  7204. sickTimes := sickTime.Unix()
  7205. ctime := time.Now().Unix()
  7206. primary_disease := c.GetString("primary_disease")
  7207. confirm_failure_date := c.GetString("confirm_failure_date")
  7208. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7209. drug_allergy_history := c.GetString("drug_allergy_history")
  7210. physical_examination := c.GetString("physical_examination")
  7211. special_inspection := c.GetString("special_inspection")
  7212. lab_apparatus := c.GetString("lab_apparatus")
  7213. caseHistory := models.HisPatientCaseHistory{
  7214. HisPatientId: his_patient_id,
  7215. PatientId: patient_id,
  7216. Temperature: temperature,
  7217. BloodSugar: bloodsugarfloat,
  7218. Pulse: pulsefloat,
  7219. Sbp: sbpfloat,
  7220. Dbp: dbpfloat,
  7221. Height: heightfloat,
  7222. BloodFat: bloodfatfloat,
  7223. SickType: sick_type,
  7224. Symptom: symptom,
  7225. SickDate: sickTimes,
  7226. IsInfect: is_infect,
  7227. HistoryOfPresentIllness: history_of_present_illness,
  7228. PastHistory: past_history,
  7229. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7230. ChiefConplaint: chief_conplaint,
  7231. PersonalHistory: personal_history,
  7232. FamilyHistory: family_history,
  7233. Diagnostic: diagnostic,
  7234. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7235. Status: 1,
  7236. Ctime: ctime,
  7237. Mtime: ctime,
  7238. RecordDate: recordDateTime,
  7239. DeliveryWay: delivery_way,
  7240. Breathing: breathingfloat,
  7241. DoctorAdvice: doctor_advice,
  7242. Remark: remark,
  7243. Sick: sick,
  7244. Diagnose: diagnose,
  7245. AllergicHistory: allergic_history,
  7246. PrimaryDisease: primary_disease,
  7247. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7248. DrugAllergyHistory: drug_allergy_history,
  7249. PhysicalExamination: physical_examination,
  7250. SpecialInspection: special_inspection,
  7251. LabApparatus: lab_apparatus,
  7252. }
  7253. //查询该患者是否有病历
  7254. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7255. if errcodes == gorm.ErrRecordNotFound {
  7256. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7257. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7258. if err != nil {
  7259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7260. return
  7261. }
  7262. c.ServeSuccessJSON(map[string]interface{}{
  7263. "caseHistory": caseHistory,
  7264. "historyInfo": historyInfo,
  7265. })
  7266. return
  7267. } else if errcodes == nil {
  7268. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7269. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7270. if err != nil {
  7271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7272. return
  7273. }
  7274. c.ServeSuccessJSON(map[string]interface{}{
  7275. "caseHistory": caseHistory,
  7276. "historyInfo": historyInfo,
  7277. })
  7278. }
  7279. //查询该患者是否有病历
  7280. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7281. //if errcode == gorm.ErrRecordNotFound {
  7282. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7283. // if err != nil {
  7284. // c.ServeSuccessJSON(map[string]interface{}{
  7285. // "msg": "保存成功",
  7286. // })
  7287. // }
  7288. //} else if errcode == nil {
  7289. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7290. // return
  7291. //}
  7292. }
  7293. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7294. patient_id, _ := c.GetInt64("patient_id", 0)
  7295. adminUser := c.GetAdminUserInfo()
  7296. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7297. c.ServeSuccessJSON(map[string]interface{}{
  7298. "list": caseHistorys,
  7299. })
  7300. }
  7301. func (c *HisApiController) GetHisPatientCaseHistory() {
  7302. record_date, _ := c.GetInt64("record_date", 0)
  7303. patient_id, _ := c.GetInt64("patient_id", 0)
  7304. admin := c.GetAdminUserInfo()
  7305. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7306. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7307. c.ServeSuccessJSON(map[string]interface{}{
  7308. "info": info,
  7309. "case_history": case_history,
  7310. })
  7311. }
  7312. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7313. template_name := c.GetString("template_name")
  7314. template_remark := c.GetString("template_remark")
  7315. doctor := c.GetAdminUserInfo().AdminUser.Id
  7316. diagnostic := c.GetString("diagnostic")
  7317. chief_conplaint := c.GetString("chief_conplain")
  7318. history_of_present_illness := c.GetString("history_of_present_illness")
  7319. past_history := c.GetString("past_history")
  7320. personal_history := c.GetString("personal_history")
  7321. family_history := c.GetString("family_history")
  7322. user_name := c.GetString("user_name")
  7323. doctor_advice := c.GetString("doctor_advice")
  7324. remark := c.GetString("remark")
  7325. //record_date := c.GetString("record_date")
  7326. //fmt.Println("record_date--------",record_date)
  7327. //timeLayout := "2006-01-02"
  7328. //loc, _ := time.LoadLocation("Local")
  7329. //
  7330. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7331. //if err != nil {
  7332. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7333. // return
  7334. //}
  7335. //recordDateTime := theTime.Unix()
  7336. ctime := time.Now().Unix()
  7337. template := models.HisCaseHistoryTemplate{
  7338. HistoryOfPresentIllness: history_of_present_illness,
  7339. PastHistory: past_history,
  7340. ChiefConplaint: chief_conplaint,
  7341. PersonalHistory: personal_history,
  7342. FamilyHistory: family_history,
  7343. Diagnostic: diagnostic,
  7344. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7345. Status: 1,
  7346. Ctime: ctime,
  7347. Mtime: ctime,
  7348. RecordDate: time.Now().Unix(),
  7349. TemplateName: template_name,
  7350. TemplateRemark: template_remark,
  7351. Creator: doctor,
  7352. Modifier: doctor,
  7353. UserName: user_name,
  7354. DoctorAdvice: doctor_advice,
  7355. Remark: remark,
  7356. }
  7357. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7358. if err == nil {
  7359. c.ServeSuccessJSON(map[string]interface{}{
  7360. "msg": "保存成功",
  7361. })
  7362. } else {
  7363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7364. return
  7365. }
  7366. }
  7367. func (c *HisApiController) GetCaseHistoryTemplate() {
  7368. timeLayout := "2006-01-02"
  7369. loc, _ := time.LoadLocation("Local")
  7370. keyword := c.GetString("keyword")
  7371. start_time := c.GetString("start_time")
  7372. end_time := c.GetString("end_time")
  7373. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7374. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7375. admin := c.GetAdminUserInfo()
  7376. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7377. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7378. c.ServeSuccessJSON(map[string]interface{}{
  7379. "template": template,
  7380. //"history": history,
  7381. })
  7382. }
  7383. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7384. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7385. utils.ErrorLog("drug_name")
  7386. return enums.ErrorCodeParamWrong
  7387. }
  7388. adviceName, _ := json["drug_name"].(string)
  7389. if len(adviceName) == 0 {
  7390. utils.ErrorLog("len(advice_name) == 0")
  7391. return enums.ErrorCodeParamWrong
  7392. }
  7393. advice.AdviceName = adviceName
  7394. adviceDesc, _ := json["advice_desc"].(string)
  7395. advice.AdviceDesc = adviceDesc
  7396. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7397. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7398. advice.DrugSpec = drugSpec
  7399. }
  7400. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7401. remark, _ := json["remark"].(string)
  7402. advice.Remark = remark
  7403. }
  7404. if json["id"] == nil {
  7405. advice.DrugId = 0
  7406. } else {
  7407. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7408. drug_id := int64(json["id"].(float64))
  7409. advice.DrugId = drug_id
  7410. }
  7411. }
  7412. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7413. advice_id := int64(json["advice_id"].(float64))
  7414. advice.ID = advice_id
  7415. if advice.ID > 0 {
  7416. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7417. if err == nil {
  7418. if hisAdvice.ID > 0 {
  7419. advice.ExecutionTime = hisAdvice.ExecutionTime
  7420. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7421. advice.ExecutionState = hisAdvice.ExecutionState
  7422. advice.CheckTime = hisAdvice.CheckTime
  7423. advice.Checker = hisAdvice.Checker
  7424. advice.CheckState = hisAdvice.CheckState
  7425. advice.StartTime = hisAdvice.StartTime
  7426. advice.FeedetlSn = hisAdvice.FeedetlSn
  7427. }
  7428. }
  7429. }
  7430. }
  7431. //
  7432. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7433. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7434. // advice.ExecutionTime = execution_time
  7435. //}
  7436. //
  7437. //
  7438. //
  7439. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7440. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7441. // advice.ExecutionStaff = execution_staff
  7442. //}
  7443. //
  7444. //
  7445. //
  7446. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7447. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7448. // advice.ExecutionState = execution_state
  7449. //}
  7450. //
  7451. //
  7452. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7453. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7454. // advice.CheckTime = check_time
  7455. //}
  7456. //
  7457. //
  7458. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7459. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7460. // advice.CheckState = check_state
  7461. //}
  7462. //
  7463. //
  7464. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7465. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7466. // advice.Checker = checker
  7467. //}
  7468. //
  7469. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7470. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7471. // advice.StartTime = start_time
  7472. //}
  7473. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7474. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7475. advice.IsSelfDrug = is_self_drug
  7476. }
  7477. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7478. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7479. drug_way_count, _ := json["drug_way_count"].(string)
  7480. advice.DrugWayCount = drug_way_count
  7481. }
  7482. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7483. drugSpecUnit, _ := json["min_unit"].(string)
  7484. advice.DrugSpecUnit = drugSpecUnit
  7485. }
  7486. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7487. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7488. advice.SingleDose = singleDose
  7489. }
  7490. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7491. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7492. advice.SingleDoseUnit = singleDoseUnit
  7493. }
  7494. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7495. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7496. advice.PrescribingNumber = prescribingNumber
  7497. }
  7498. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7499. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7500. advice.PrescribingNumberUnit = prescribingNumberUnit
  7501. }
  7502. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7503. deliveryWay, _ := json["delivery_way"].(string)
  7504. advice.DeliveryWay = deliveryWay
  7505. }
  7506. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7507. executionFrequency, _ := json["execution_frequency"].(string)
  7508. advice.ExecutionFrequency = executionFrequency
  7509. }
  7510. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7511. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7512. advice.Price = price
  7513. }
  7514. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7515. med_list_codg, _ := json["medical_insurance_number"].(string)
  7516. advice.MedListCodg = med_list_codg
  7517. }
  7518. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7519. day := int64(json["day"].(float64))
  7520. advice.Day = day
  7521. }
  7522. return 0
  7523. }
  7524. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7525. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7526. id := int64(json["id"].(float64))
  7527. project.ID = id
  7528. historyProject, _ := service.GetHisProjectByID(id)
  7529. project.FeedetlSn = historyProject.FeedetlSn
  7530. }
  7531. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7532. project_id := int64(json["project_id"].(float64))
  7533. project.ProjectId = project_id
  7534. }
  7535. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7536. // price := int64(json["price"].(float64))
  7537. // formatInt_price := strconv.FormatInt(price, 10)
  7538. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7539. // project.Price = float_price
  7540. // }
  7541. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7542. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7543. project.Price = price
  7544. }
  7545. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7546. total, _ := json["total"].(string)
  7547. project.Count = total
  7548. }
  7549. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7550. medical_code, _ := json["medical_code"].(string)
  7551. project.MedListCodg = medical_code
  7552. }
  7553. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7554. single_dose, _ := json["single_dose"].(string)
  7555. project.SingleDose = single_dose
  7556. }
  7557. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7558. delivery_way, _ := json["delivery_way"].(string)
  7559. project.DeliveryWay = delivery_way
  7560. }
  7561. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7562. execution_frequency, _ := json["execution_frequency"].(string)
  7563. project.ExecutionFrequency = execution_frequency
  7564. }
  7565. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7566. remark, _ := json["remark"].(string)
  7567. project.Remark = remark
  7568. }
  7569. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7570. day, _ := json["number_days"].(string)
  7571. project.Day = day
  7572. }
  7573. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7574. unit, _ := json["unit"].(string)
  7575. project.Unit = unit
  7576. }
  7577. return 0
  7578. }
  7579. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7580. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7581. id := int64(json["id"].(float64))
  7582. historyAddtions, _ := service.GetHisAdditionByID(id)
  7583. additionalCharge.ID = id
  7584. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7585. }
  7586. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7587. item_id := int64(json["item_id"].(float64))
  7588. additionalCharge.ItemId = item_id
  7589. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7590. if config.ID > 0 {
  7591. if len(config.Code) > 0 {
  7592. additionalCharge.MedListCodg = config.Code
  7593. }
  7594. }
  7595. }
  7596. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7597. // price := int64(json["price"].(float64))
  7598. // formatInt_price := strconv.FormatInt(price, 10)
  7599. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7600. // additionalCharge.Price = float_price
  7601. // }
  7602. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7603. // price := int64(json["price"].(float64))
  7604. // formatInt_price := strconv.FormatInt(price, 10)
  7605. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7606. // additionalCharge.Price = float_price
  7607. //}
  7608. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7609. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7610. additionalCharge.Price = price
  7611. }
  7612. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7613. count, _ := json["count"].(string)
  7614. counts, _ := strconv.ParseInt(count, 10, 64)
  7615. additionalCharge.Count = counts
  7616. }
  7617. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7618. item_name, _ := json["item_name"].(string)
  7619. additionalCharge.ItemName = item_name
  7620. }
  7621. return 0
  7622. }
  7623. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7624. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7625. utils.ErrorLog("drug_name")
  7626. return enums.ErrorCodeParamWrong
  7627. }
  7628. adviceName, _ := json["drug_name"].(string)
  7629. if len(adviceName) == 0 {
  7630. utils.ErrorLog("len(advice_name) == 0")
  7631. return enums.ErrorCodeParamWrong
  7632. }
  7633. advice.AdviceName = adviceName
  7634. adviceDesc, _ := json["advice_desc"].(string)
  7635. advice.AdviceDesc = adviceDesc
  7636. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7637. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7638. advice.DrugSpec = drugSpec
  7639. }
  7640. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7641. remark, _ := json["remark"].(string)
  7642. advice.Remark = remark
  7643. }
  7644. if json["id"] == nil {
  7645. advice.DrugId = 0
  7646. } else {
  7647. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7648. drug_id := int64(json["id"].(float64))
  7649. advice.DrugId = drug_id
  7650. }
  7651. }
  7652. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7653. groupno := int64(json["groupno"].(float64))
  7654. advice.Groupno = groupno
  7655. }
  7656. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7657. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7658. advice.IsSelfDrug = is_self_drug
  7659. }
  7660. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7661. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7662. drug_way_count, _ := json["drug_way_count"].(string)
  7663. advice.DrugWayCount = drug_way_count
  7664. }
  7665. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7666. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7667. advice.HospApprFlag = hosp_appr_flag
  7668. }
  7669. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7670. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7671. advice.PrescribingNumber = prescribingNumber
  7672. }
  7673. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7674. // frequency_type := int64(json["frequency_type"].(float64))
  7675. // advice.FrequencyType = frequency_type
  7676. //}
  7677. //
  7678. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7679. // day_count := int64(json["day_count"].(float64))
  7680. // advice.DayCount = day_count
  7681. //}
  7682. //
  7683. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7684. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7685. // week_day, _ := json["week_day"].(string)
  7686. // advice.WeekDay = week_day
  7687. //}
  7688. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7689. drugSpecUnit, _ := json["min_unit"].(string)
  7690. advice.DrugSpecUnit = drugSpecUnit
  7691. }
  7692. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7693. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7694. advice.SingleDose = singleDose
  7695. }
  7696. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7697. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7698. advice.SingleDoseUnit = singleDoseUnit
  7699. }
  7700. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7701. deliveryWay, _ := json["delivery_way"].(string)
  7702. advice.DeliveryWay = deliveryWay
  7703. }
  7704. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7705. executionFrequency, _ := json["execution_frequency"].(string)
  7706. advice.ExecutionFrequency = executionFrequency
  7707. }
  7708. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7709. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7710. advice.Price = price
  7711. }
  7712. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7713. med_list_codg, _ := json["medical_insurance_number"].(string)
  7714. advice.MedListCodg = med_list_codg
  7715. }
  7716. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7717. day := int64(json["day"].(float64))
  7718. advice.Day = day
  7719. }
  7720. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7721. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7722. advice.PrescribingNumberUnit = prescribingNumberUnit
  7723. }
  7724. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7725. advice_id := int64(json["advice_id"].(float64))
  7726. advice.ID = advice_id
  7727. if advice.ID > 0 {
  7728. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7729. if err == nil {
  7730. if hisAdvice.ID > 0 {
  7731. advice.ExecutionTime = hisAdvice.ExecutionTime
  7732. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7733. advice.ExecutionState = hisAdvice.ExecutionState
  7734. advice.CheckTime = hisAdvice.CheckTime
  7735. advice.Checker = hisAdvice.Checker
  7736. advice.CheckState = hisAdvice.CheckState
  7737. advice.StartTime = hisAdvice.StartTime
  7738. advice.HospApprFlag = hisAdvice.HospApprFlag
  7739. advice.IsMedicine = hisAdvice.IsMedicine
  7740. if hisAdvice.UserOrgId == 10028 {
  7741. 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 {
  7742. advice.ExecutionTime = 0
  7743. advice.ExecutionStaff = 0
  7744. advice.ExecutionState = 2
  7745. advice.CheckTime = 0
  7746. advice.Checker = 0
  7747. advice.CheckState = 2
  7748. }
  7749. } else {
  7750. 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 {
  7751. advice.ExecutionTime = 0
  7752. advice.ExecutionStaff = 0
  7753. advice.ExecutionState = 2
  7754. advice.CheckTime = 0
  7755. advice.Checker = 0
  7756. advice.CheckState = 2
  7757. advice.UpdatedTime = time.Now().Unix()
  7758. }
  7759. }
  7760. //advice.Groupno = hisAdvice.Groupno
  7761. }
  7762. }
  7763. }
  7764. }
  7765. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7766. //
  7767. //if drugStockConfig.IsOpen == 1 {
  7768. //
  7769. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7770. // if advice.ID == 0 { //医嘱不存在
  7771. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7772. // drug.Total = drug.Total - advice.PrescribingNumber
  7773. // service.UpdateBaseDrugLib(&drug)
  7774. //
  7775. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7776. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7777. // drug.Total = drug.Total - num
  7778. // service.UpdateBaseDrugLib(&drug)
  7779. // }
  7780. //
  7781. // } else if advice.ID > 0 { //医嘱存在
  7782. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7783. // var num float64
  7784. //
  7785. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7786. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7787. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7788. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7789. // drug.Total = drug.Total + num
  7790. // service.UpdateBaseDrugLib(&drug)
  7791. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7792. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7793. // drug.Total = drug.Total - num
  7794. // service.UpdateBaseDrugLib(&drug)
  7795. // }
  7796. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7797. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7798. // if num2 > advice.PrescribingNumber {
  7799. // num = num2 - advice.PrescribingNumber
  7800. // drug.Total = drug.Total + num
  7801. // service.UpdateBaseDrugLib(&drug)
  7802. // } else if num2 < advice.PrescribingNumber {
  7803. // num = advice.PrescribingNumber - num2
  7804. // drug.Total = drug.Total - num
  7805. // service.UpdateBaseDrugLib(&drug)
  7806. // }
  7807. //
  7808. // }
  7809. //
  7810. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7811. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7812. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7813. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7814. // if num1 > num2 {
  7815. // num = num1 - num2
  7816. // drug.Total = drug.Total + num
  7817. // service.UpdateBaseDrugLib(&drug)
  7818. // } else if num1 < num2 {
  7819. // num = num2 - num1
  7820. // drug.Total = drug.Total - num
  7821. // service.UpdateBaseDrugLib(&drug)
  7822. // }
  7823. //
  7824. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7825. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7826. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7827. // if hisAdvice.PrescribingNumber > num2 {
  7828. // num = hisAdvice.PrescribingNumber - num2
  7829. // drug.Total = drug.Total + num
  7830. // service.UpdateBaseDrugLib(&drug)
  7831. // } else if num2 < advice.PrescribingNumber {
  7832. // num = num2 - hisAdvice.PrescribingNumber
  7833. // drug.Total = drug.Total - num
  7834. // service.UpdateBaseDrugLib(&drug)
  7835. // }
  7836. //
  7837. // }
  7838. // }
  7839. // }
  7840. //}
  7841. //
  7842. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7843. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7844. // advice.ExecutionTime = execution_time
  7845. //}
  7846. //
  7847. //
  7848. //
  7849. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7850. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7851. // advice.ExecutionStaff = execution_staff
  7852. //}
  7853. //
  7854. //
  7855. //
  7856. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7857. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7858. // advice.ExecutionState = execution_state
  7859. //}
  7860. //
  7861. //
  7862. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7863. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7864. // advice.CheckTime = check_time
  7865. //}
  7866. //
  7867. //
  7868. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7869. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7870. // advice.CheckState = check_state
  7871. //}
  7872. //
  7873. //
  7874. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7875. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7876. // advice.Checker = checker
  7877. //}
  7878. //
  7879. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7880. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7881. // advice.StartTime = start_time
  7882. //}
  7883. return 0
  7884. }
  7885. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7886. project.ExecutionStaff = 0
  7887. project.ExecutionState = 2
  7888. project.ExecutionTime = 0
  7889. project.Checker = 0
  7890. project.CheckState = 2
  7891. project.CheckTime = 0
  7892. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7893. id := int64(json["id"].(float64))
  7894. project.ID = id
  7895. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7896. project.ExecutionStaff = temp_project.ExecutionStaff
  7897. project.ExecutionState = temp_project.ExecutionState
  7898. project.ExecutionTime = temp_project.ExecutionTime
  7899. project.Checker = temp_project.Checker
  7900. project.CheckState = temp_project.CheckState
  7901. project.CheckTime = temp_project.CheckTime
  7902. project.TeamId = temp_project.TeamId
  7903. }
  7904. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7905. types := int64(json["type"].(float64))
  7906. project.Type = types
  7907. }
  7908. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7909. project_id := int64(json["project_id"].(float64))
  7910. project.ProjectId = project_id
  7911. }
  7912. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7913. team_id := int64(json["team_id"].(float64))
  7914. project.TeamId = team_id
  7915. }
  7916. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7917. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7918. project.Price = price
  7919. }
  7920. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7921. total, _ := json["total"].(string)
  7922. //totals, _ := strconv.ParseInt(total, 10, 64)
  7923. project.Count = total
  7924. }
  7925. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7926. medical_code, _ := json["medical_code"].(string)
  7927. project.MedListCodg = medical_code
  7928. }
  7929. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7930. single_dose, _ := json["single_dose"].(string)
  7931. project.SingleDose = single_dose
  7932. }
  7933. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7934. delivery_way, _ := json["delivery_way"].(string)
  7935. project.DeliveryWay = delivery_way
  7936. }
  7937. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7938. execution_frequency, _ := json["execution_frequency"].(string)
  7939. project.ExecutionFrequency = execution_frequency
  7940. }
  7941. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7942. remark, _ := json["remark"].(string)
  7943. project.Remark = remark
  7944. }
  7945. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7946. day, _ := json["number_days"].(string)
  7947. project.Day = day
  7948. }
  7949. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7950. unit, _ := json["unit"].(string)
  7951. project.Unit = unit
  7952. }
  7953. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7954. // frequency_type := int64(json["frequency_type"].(float64))
  7955. // project.FrequencyType = frequency_type
  7956. //}
  7957. //
  7958. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7959. // day_count := int64(json["day_count"].(float64))
  7960. // project.DayCount = day_count
  7961. //}
  7962. //
  7963. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7964. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7965. // week_day, _ := json["week_day"].(string)
  7966. // project.WeekDay = week_day
  7967. //}
  7968. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7969. //
  7970. //if project.ID == 0 {
  7971. // if stockConfig.IsOpen == 1 {
  7972. // if project.Type == 3 {
  7973. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7974. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7975. // good.Total = good.Total - f_count
  7976. // service.UpdateGoodInfo(&good)
  7977. // }
  7978. // }
  7979. //
  7980. //} else {
  7981. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7982. //
  7983. // if stockConfig.IsOpen == 1 {
  7984. // if project.Type == 3 {
  7985. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7986. // if project.Count < temp_project.Count {
  7987. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7988. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7989. //
  7990. // other_count := f_count_two - f_count_one
  7991. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7992. // good.Total = good.Total + other_count_two
  7993. // service.UpdateGoodInfo(&good)
  7994. // } else if project.Count > temp_project.Count {
  7995. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7996. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7997. //
  7998. // other_count := f_count_one - f_count_two
  7999. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8000. // good.Total = good.Total - other_count_two
  8001. // service.UpdateGoodInfo(&good)
  8002. // }
  8003. //
  8004. // }
  8005. // }
  8006. //
  8007. //}
  8008. return 0
  8009. }
  8010. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8011. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8012. utils.ErrorLog("drug_name")
  8013. return enums.ErrorCodeParamWrong
  8014. }
  8015. adviceName, _ := json["drug_name"].(string)
  8016. if len(adviceName) == 0 {
  8017. utils.ErrorLog("len(advice_name) == 0")
  8018. return enums.ErrorCodeParamWrong
  8019. }
  8020. advice.AdviceName = adviceName
  8021. adviceDesc, _ := json["advice_desc"].(string)
  8022. advice.AdviceDesc = adviceDesc
  8023. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8024. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8025. advice.DrugSpec = drugSpec
  8026. }
  8027. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8028. remark, _ := json["remark"].(string)
  8029. advice.Remark = remark
  8030. }
  8031. if json["id"] == nil {
  8032. advice.DrugId = 0
  8033. } else {
  8034. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8035. drug_id := int64(json["id"].(float64))
  8036. advice.DrugId = drug_id
  8037. }
  8038. }
  8039. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8040. groupno := int64(json["groupno"].(float64))
  8041. advice.Groupno = groupno
  8042. }
  8043. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8044. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8045. advice.IsSelfDrug = is_self_drug
  8046. }
  8047. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8048. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8049. drug_way_count, _ := json["drug_way_count"].(string)
  8050. advice.DrugWayCount = drug_way_count
  8051. }
  8052. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8053. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8054. advice.HospApprFlag = hosp_appr_flag
  8055. }
  8056. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8057. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8058. advice.PrescribingNumber = prescribingNumber
  8059. }
  8060. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8061. // frequency_type := int64(json["frequency_type"].(float64))
  8062. // advice.FrequencyType = frequency_type
  8063. //}
  8064. //
  8065. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8066. // day_count := int64(json["day_count"].(float64))
  8067. // advice.DayCount = day_count
  8068. //}
  8069. //
  8070. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8071. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8072. // week_day, _ := json["week_day"].(string)
  8073. // advice.WeekDay = week_day
  8074. //}
  8075. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8076. drugSpecUnit, _ := json["min_unit"].(string)
  8077. advice.DrugSpecUnit = drugSpecUnit
  8078. }
  8079. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8080. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8081. advice.SingleDose = singleDose
  8082. }
  8083. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8084. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8085. advice.SingleDoseUnit = singleDoseUnit
  8086. }
  8087. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8088. deliveryWay, _ := json["delivery_way"].(string)
  8089. advice.DeliveryWay = deliveryWay
  8090. }
  8091. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8092. executionFrequency, _ := json["execution_frequency"].(string)
  8093. advice.ExecutionFrequency = executionFrequency
  8094. }
  8095. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8096. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8097. advice.Price = price
  8098. }
  8099. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8100. med_list_codg, _ := json["medical_insurance_number"].(string)
  8101. advice.MedListCodg = med_list_codg
  8102. }
  8103. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8104. day := int64(json["day"].(float64))
  8105. advice.Day = day
  8106. }
  8107. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8108. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8109. advice.PrescribingNumberUnit = prescribingNumberUnit
  8110. }
  8111. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8112. advice_id := int64(json["advice_id"].(float64))
  8113. advice.ID = advice_id
  8114. if advice.ID > 0 {
  8115. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8116. if err == nil {
  8117. if hisAdvice.ID > 0 {
  8118. advice.ExecutionTime = hisAdvice.ExecutionTime
  8119. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8120. advice.ExecutionState = hisAdvice.ExecutionState
  8121. advice.CheckTime = hisAdvice.CheckTime
  8122. advice.Checker = hisAdvice.Checker
  8123. advice.DrugCode = hisAdvice.DrugCode
  8124. advice.CheckState = hisAdvice.CheckState
  8125. advice.StartTime = hisAdvice.StartTime
  8126. advice.HospApprFlag = hisAdvice.HospApprFlag
  8127. advice.IsMedicine = hisAdvice.IsMedicine
  8128. if hisAdvice.UserOrgId == 10028 {
  8129. 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 {
  8130. advice.ExecutionTime = 0
  8131. advice.ExecutionStaff = 0
  8132. advice.ExecutionState = 2
  8133. advice.CheckTime = 0
  8134. advice.Checker = 0
  8135. advice.CheckState = 2
  8136. }
  8137. } else {
  8138. 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 {
  8139. advice.ExecutionTime = 0
  8140. advice.ExecutionStaff = 0
  8141. advice.ExecutionState = 2
  8142. advice.CheckTime = 0
  8143. advice.Checker = 0
  8144. advice.CheckState = 2
  8145. //advice.UpdatedTime = time.Now().Unix()
  8146. advice.CreatedTime = hisAdvice.CreatedTime
  8147. advice.UpdatedTime = time.Now().Unix()
  8148. } else {
  8149. advice.CreatedTime = hisAdvice.CreatedTime
  8150. advice.UpdatedTime = hisAdvice.UpdatedTime
  8151. }
  8152. }
  8153. //advice.Groupno = hisAdvice.Groupno
  8154. } else {
  8155. advice.IsMedicine = 0
  8156. ctime := time.Now().Unix()
  8157. advice.CreatedTime = ctime
  8158. advice.UpdatedTime = ctime
  8159. }
  8160. }
  8161. } else {
  8162. advice.IsMedicine = 0
  8163. ctime := time.Now().Unix()
  8164. advice.CreatedTime = ctime
  8165. advice.UpdatedTime = ctime
  8166. }
  8167. }
  8168. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8169. //
  8170. //if drugStockConfig.IsOpen == 1 {
  8171. //
  8172. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8173. // if advice.ID == 0 { //医嘱不存在
  8174. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8175. // drug.Total = drug.Total - advice.PrescribingNumber
  8176. // service.UpdateBaseDrugLib(&drug)
  8177. //
  8178. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8179. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8180. // drug.Total = drug.Total - num
  8181. // service.UpdateBaseDrugLib(&drug)
  8182. // }
  8183. //
  8184. // } else if advice.ID > 0 { //医嘱存在
  8185. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8186. // var num float64
  8187. //
  8188. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8189. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8190. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8191. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8192. // drug.Total = drug.Total + num
  8193. // service.UpdateBaseDrugLib(&drug)
  8194. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8195. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8196. // drug.Total = drug.Total - num
  8197. // service.UpdateBaseDrugLib(&drug)
  8198. // }
  8199. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8200. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8201. // if num2 > advice.PrescribingNumber {
  8202. // num = num2 - advice.PrescribingNumber
  8203. // drug.Total = drug.Total + num
  8204. // service.UpdateBaseDrugLib(&drug)
  8205. // } else if num2 < advice.PrescribingNumber {
  8206. // num = advice.PrescribingNumber - num2
  8207. // drug.Total = drug.Total - num
  8208. // service.UpdateBaseDrugLib(&drug)
  8209. // }
  8210. //
  8211. // }
  8212. //
  8213. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8214. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8215. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8216. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8217. // if num1 > num2 {
  8218. // num = num1 - num2
  8219. // drug.Total = drug.Total + num
  8220. // service.UpdateBaseDrugLib(&drug)
  8221. // } else if num1 < num2 {
  8222. // num = num2 - num1
  8223. // drug.Total = drug.Total - num
  8224. // service.UpdateBaseDrugLib(&drug)
  8225. // }
  8226. //
  8227. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8228. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8229. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8230. // if hisAdvice.PrescribingNumber > num2 {
  8231. // num = hisAdvice.PrescribingNumber - num2
  8232. // drug.Total = drug.Total + num
  8233. // service.UpdateBaseDrugLib(&drug)
  8234. // } else if num2 < advice.PrescribingNumber {
  8235. // num = num2 - hisAdvice.PrescribingNumber
  8236. // drug.Total = drug.Total - num
  8237. // service.UpdateBaseDrugLib(&drug)
  8238. // }
  8239. //
  8240. // }
  8241. // }
  8242. // }
  8243. //}
  8244. //
  8245. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8246. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8247. // advice.ExecutionTime = execution_time
  8248. //}
  8249. //
  8250. //
  8251. //
  8252. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8253. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8254. // advice.ExecutionStaff = execution_staff
  8255. //}
  8256. //
  8257. //
  8258. //
  8259. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8260. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8261. // advice.ExecutionState = execution_state
  8262. //}
  8263. //
  8264. //
  8265. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8266. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8267. // advice.CheckTime = check_time
  8268. //}
  8269. //
  8270. //
  8271. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8272. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8273. // advice.CheckState = check_state
  8274. //}
  8275. //
  8276. //
  8277. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8278. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8279. // advice.Checker = checker
  8280. //}
  8281. //
  8282. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8283. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8284. // advice.StartTime = start_time
  8285. //}
  8286. return 0
  8287. }
  8288. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8289. project.ExecutionStaff = 0
  8290. project.ExecutionState = 2
  8291. project.ExecutionTime = 0
  8292. project.Checker = 0
  8293. project.CheckState = 2
  8294. project.CheckTime = 0
  8295. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8296. id := int64(json["id"].(float64))
  8297. project.ID = id
  8298. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8299. project.ExecutionStaff = temp_project.ExecutionStaff
  8300. project.ExecutionState = temp_project.ExecutionState
  8301. project.ExecutionTime = temp_project.ExecutionTime
  8302. project.Checker = temp_project.Checker
  8303. project.CheckState = temp_project.CheckState
  8304. project.CheckTime = temp_project.CheckTime
  8305. project.TeamId = temp_project.TeamId
  8306. }
  8307. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8308. types := int64(json["type"].(float64))
  8309. project.Type = types
  8310. }
  8311. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8312. project_id := int64(json["project_id"].(float64))
  8313. project.ProjectId = project_id
  8314. }
  8315. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8316. team_id := int64(json["team_id"].(float64))
  8317. project.TeamId = team_id
  8318. }
  8319. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8320. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8321. project.Price = price
  8322. }
  8323. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8324. total, _ := json["total"].(string)
  8325. //totals, _ := strconv.ParseInt(total, 10, 64)
  8326. project.Count = total
  8327. }
  8328. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8329. medical_code, _ := json["medical_code"].(string)
  8330. project.MedListCodg = medical_code
  8331. }
  8332. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8333. single_dose, _ := json["single_dose"].(string)
  8334. project.SingleDose = single_dose
  8335. }
  8336. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8337. delivery_way, _ := json["delivery_way"].(string)
  8338. project.DeliveryWay = delivery_way
  8339. }
  8340. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8341. execution_frequency, _ := json["execution_frequency"].(string)
  8342. project.ExecutionFrequency = execution_frequency
  8343. }
  8344. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8345. remark, _ := json["remark"].(string)
  8346. project.Remark = remark
  8347. }
  8348. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8349. day, _ := json["number_days"].(string)
  8350. project.Day = day
  8351. }
  8352. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8353. unit, _ := json["unit"].(string)
  8354. project.Unit = unit
  8355. }
  8356. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8357. // frequency_type := int64(json["frequency_type"].(float64))
  8358. // project.FrequencyType = frequency_type
  8359. //}
  8360. //
  8361. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8362. // day_count := int64(json["day_count"].(float64))
  8363. // project.DayCount = day_count
  8364. //}
  8365. //
  8366. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8367. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8368. // week_day, _ := json["week_day"].(string)
  8369. // project.WeekDay = week_day
  8370. //}
  8371. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8372. //
  8373. //if project.ID == 0 {
  8374. // if stockConfig.IsOpen == 1 {
  8375. // if project.Type == 3 {
  8376. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8377. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8378. // good.Total = good.Total - f_count
  8379. // service.UpdateGoodInfo(&good)
  8380. // }
  8381. // }
  8382. //
  8383. //} else {
  8384. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8385. //
  8386. // if stockConfig.IsOpen == 1 {
  8387. // if project.Type == 3 {
  8388. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8389. // if project.Count < temp_project.Count {
  8390. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8391. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8392. //
  8393. // other_count := f_count_two - f_count_one
  8394. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8395. // good.Total = good.Total + other_count_two
  8396. // service.UpdateGoodInfo(&good)
  8397. // } else if project.Count > temp_project.Count {
  8398. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8399. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8400. //
  8401. // other_count := f_count_one - f_count_two
  8402. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8403. // good.Total = good.Total - other_count_two
  8404. // service.UpdateGoodInfo(&good)
  8405. // }
  8406. //
  8407. // }
  8408. // }
  8409. //
  8410. //}
  8411. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8412. id := int64(json["id"].(float64))
  8413. if id > 0 {
  8414. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8415. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8416. fmt.Println("666666")
  8417. project.Mtime = time.Now().Unix()
  8418. project.Ctime = temp_project.Ctime
  8419. } else {
  8420. project.Mtime = temp_project.Mtime
  8421. project.Ctime = temp_project.Ctime
  8422. }
  8423. } else {
  8424. ctime := time.Now().Unix()
  8425. project.Mtime = ctime
  8426. project.Ctime = ctime
  8427. }
  8428. }
  8429. return 0
  8430. }
  8431. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8432. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8433. id := int64(json["id"].(float64))
  8434. additionalCharge.ID = id
  8435. }
  8436. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8437. item_id := int64(json["item_id"].(float64))
  8438. additionalCharge.ItemId = item_id
  8439. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8440. if config.ID > 0 {
  8441. if len(config.Code) > 0 {
  8442. additionalCharge.MedListCodg = config.Code
  8443. }
  8444. }
  8445. }
  8446. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8447. // price := int64(json["price"].(float64))
  8448. // formatInt_price := strconv.FormatInt(price, 10)
  8449. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8450. // additionalCharge.Price = float_price
  8451. // }
  8452. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8453. // price := int64(json["price"].(float64))
  8454. // formatInt_price := strconv.FormatInt(price, 10)
  8455. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8456. // additionalCharge.Price = float_price
  8457. //}
  8458. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8459. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8460. additionalCharge.Price = price
  8461. }
  8462. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8463. count, _ := json["count"].(string)
  8464. counts, _ := strconv.ParseInt(count, 10, 64)
  8465. additionalCharge.Count = counts
  8466. }
  8467. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8468. item_name, _ := json["item_name"].(string)
  8469. additionalCharge.ItemName = item_name
  8470. }
  8471. return 0
  8472. }
  8473. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8474. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8475. utils.ErrorLog("drug_name")
  8476. return enums.ErrorCodeParamWrong
  8477. }
  8478. adviceName, _ := json["drug_name"].(string)
  8479. if len(adviceName) == 0 {
  8480. utils.ErrorLog("len(advice_name) == 0")
  8481. return enums.ErrorCodeParamWrong
  8482. }
  8483. advice.AdviceName = adviceName
  8484. adviceDesc, _ := json["advice_desc"].(string)
  8485. advice.AdviceDesc = adviceDesc
  8486. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8487. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8488. advice.DrugSpec = drugSpec
  8489. }
  8490. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8491. remark, _ := json["remark"].(string)
  8492. advice.Remark = remark
  8493. }
  8494. if json["id"] == nil {
  8495. advice.DrugId = 0
  8496. } else {
  8497. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8498. drug_id := int64(json["id"].(float64))
  8499. advice.DrugId = drug_id
  8500. }
  8501. }
  8502. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8503. groupno := int64(json["groupno"].(float64))
  8504. advice.Groupno = groupno
  8505. }
  8506. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8507. drugSpecUnit, _ := json["min_unit"].(string)
  8508. advice.DrugSpecUnit = drugSpecUnit
  8509. }
  8510. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8511. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8512. advice.SingleDose = singleDose
  8513. }
  8514. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8515. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8516. advice.SingleDoseUnit = singleDoseUnit
  8517. }
  8518. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8519. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8520. advice.PrescribingNumber = prescribingNumber
  8521. }
  8522. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8523. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8524. advice.PrescribingNumberUnit = prescribingNumberUnit
  8525. }
  8526. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8527. deliveryWay, _ := json["delivery_way"].(string)
  8528. advice.DeliveryWay = deliveryWay
  8529. }
  8530. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8531. executionFrequency, _ := json["execution_frequency"].(string)
  8532. advice.ExecutionFrequency = executionFrequency
  8533. }
  8534. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8535. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8536. advice.Price = price
  8537. }
  8538. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8539. med_list_codg, _ := json["medical_insurance_number"].(string)
  8540. advice.MedListCodg = med_list_codg
  8541. }
  8542. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8543. day := int64(json["day"].(float64))
  8544. advice.Day = day
  8545. }
  8546. advice.FrequencyType = 1
  8547. return 0
  8548. }
  8549. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8550. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8551. types := int64(json["type"].(float64))
  8552. project.Type = types
  8553. }
  8554. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8555. project_id := int64(json["project_id"].(float64))
  8556. project.ProjectId = project_id
  8557. }
  8558. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8559. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8560. project.Price = price
  8561. }
  8562. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8563. total, _ := json["total"].(string)
  8564. //totals, _ := strconv.ParseInt(total, 10, 64)
  8565. project.Count = total
  8566. }
  8567. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8568. medical_code, _ := json["medical_code"].(string)
  8569. project.MedListCodg = medical_code
  8570. }
  8571. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8572. single_dose, _ := json["single_dose"].(string)
  8573. project.SingleDose = single_dose
  8574. }
  8575. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8576. delivery_way, _ := json["delivery_way"].(string)
  8577. project.DeliveryWay = delivery_way
  8578. }
  8579. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8580. execution_frequency, _ := json["execution_frequency"].(string)
  8581. project.ExecutionFrequency = execution_frequency
  8582. }
  8583. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8584. remark, _ := json["remark"].(string)
  8585. project.Remark = remark
  8586. }
  8587. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8588. day, _ := json["number_days"].(string)
  8589. project.Day = day
  8590. }
  8591. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8592. unit, _ := json["unit"].(string)
  8593. project.Unit = unit
  8594. }
  8595. project.FrequencyType = 1
  8596. return 0
  8597. }
  8598. func (c *HisApiController) GetHisOrderListTwo() {
  8599. start_time := c.GetString("start_time")
  8600. end_time := c.GetString("end_time")
  8601. timeLayout := "2006-01-02"
  8602. loc, _ := time.LoadLocation("Local")
  8603. var startTime int64
  8604. if len(start_time) > 0 {
  8605. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8606. if err != nil {
  8607. //fmt.Println(err)
  8608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8609. return
  8610. }
  8611. startTime = theTime.Unix()
  8612. }
  8613. var endTime int64
  8614. if len(end_time) > 0 {
  8615. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8616. if err != nil {
  8617. utils.ErrorLog(err.Error())
  8618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8619. return
  8620. }
  8621. endTime = theTime.Unix()
  8622. }
  8623. adminUser := c.GetAdminUserInfo()
  8624. org_id := adminUser.CurrentOrgId
  8625. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8626. if err == nil {
  8627. c.ServeSuccessJSON(map[string]interface{}{
  8628. "order2": order,
  8629. })
  8630. } else {
  8631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8632. return
  8633. }
  8634. }
  8635. func (c *HisApiController) GetHisOrderList() {
  8636. page, _ := c.GetInt64("page", -1)
  8637. limit, _ := c.GetInt64("limit", -1)
  8638. start_time := c.GetString("start_time")
  8639. end_time := c.GetString("end_time")
  8640. types, _ := c.GetInt64("type", 0)
  8641. keywords := c.GetString("keywords")
  8642. p_type, _ := c.GetInt64("p_type", 0)
  8643. sort_type, _ := c.GetInt64("sort_type", 0)
  8644. charge_type, _ := c.GetInt64("charge_type", 0)
  8645. sch_type, _ := c.GetInt64("sch_type", 0)
  8646. zone_type, _ := c.GetInt64("zone_type", 0)
  8647. med_type, _ := c.GetInt64("med_type", 0)
  8648. timeLayout := "2006-01-02"
  8649. loc, _ := time.LoadLocation("Local")
  8650. var startTime int64
  8651. if len(start_time) > 0 {
  8652. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8653. if err != nil {
  8654. //fmt.Println(err)
  8655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8656. return
  8657. }
  8658. startTime = theTime.Unix()
  8659. }
  8660. var endTime int64
  8661. if len(end_time) > 0 {
  8662. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8663. if err != nil {
  8664. utils.ErrorLog(err.Error())
  8665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8666. return
  8667. }
  8668. endTime = theTime.Unix()
  8669. }
  8670. adminUser := c.GetAdminUserInfo()
  8671. org_id := adminUser.CurrentOrgId
  8672. 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)
  8673. for _, item := range order {
  8674. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8675. item.DoctorName = info.Doctor
  8676. item.DepartmentName = info.XtHisDepartment.Name
  8677. }
  8678. if err == nil {
  8679. c.ServeSuccessJSON(map[string]interface{}{
  8680. "order": order,
  8681. "total": total,
  8682. })
  8683. } else {
  8684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8685. return
  8686. }
  8687. }
  8688. func (c *HisApiController) GetHisOrder() {
  8689. patient_id, _ := c.GetInt64("patient_id", 0)
  8690. number := c.GetString("number")
  8691. adminInfo := c.GetAdminUserInfo()
  8692. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8693. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8694. if err == nil {
  8695. c.ServeSuccessJSON(map[string]interface{}{
  8696. "order": order,
  8697. "prescription": prescriptions,
  8698. })
  8699. } else {
  8700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8701. return
  8702. }
  8703. }
  8704. func (c *HisApiController) GetHisPrescriptionList() {
  8705. record_date := c.GetString("record_date")
  8706. keywords := c.GetString("keywords")
  8707. page, _ := c.GetInt64("page")
  8708. limit, _ := c.GetInt64("limit")
  8709. sch_type, _ := c.GetInt64("sch_type")
  8710. timeLayout := "2006-01-02"
  8711. loc, _ := time.LoadLocation("Local")
  8712. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8713. if err != nil {
  8714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8715. return
  8716. }
  8717. recordDateTime := theTime.Unix()
  8718. adminInfo := c.GetAdminUserInfo()
  8719. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8720. //adminInfo := c.GetAdminUserInfo()
  8721. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8722. //fmt.Println(prescriptionOrder)
  8723. if err == nil {
  8724. c.ServeSuccessJSON(map[string]interface{}{
  8725. "order": prescriptionOrder,
  8726. "total": total,
  8727. })
  8728. } else {
  8729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8730. return
  8731. }
  8732. }
  8733. func (c *HisApiController) GetHisPrescriptionInfo() {
  8734. id, _ := c.GetInt64("id")
  8735. adminInfo := c.GetAdminUserInfo()
  8736. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8737. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8738. if err == nil {
  8739. c.ServeSuccessJSON(map[string]interface{}{
  8740. "order": prescriptionOrder,
  8741. "prescription": prescription,
  8742. })
  8743. } else {
  8744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8745. return
  8746. }
  8747. }
  8748. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8749. adminUser := c.GetAdminUserInfo()
  8750. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8751. c.ServeSuccessJSON(map[string]interface{}{
  8752. "config": config,
  8753. })
  8754. }
  8755. type ResultTwo struct {
  8756. ErrMsg interface{} `json:"err_msg"`
  8757. InfRefmsgid string `json:"inf_refmsgid"`
  8758. Infcode int64 `json:"infcode"`
  8759. Output struct {
  8760. Baseinfo struct {
  8761. Age float64 `json:"age"`
  8762. Brdy string `json:"brdy"`
  8763. Certno string `json:"certno"`
  8764. Gend string `json:"gend"`
  8765. Naty string `json:"naty"`
  8766. PsnCertType string `json:"psn_cert_type"`
  8767. PsnName string `json:"psn_name"`
  8768. PsnNo string `json:"psn_no"`
  8769. } `json:"baseinfo"`
  8770. Idetinfo []interface{} `json:"idetinfo"`
  8771. Iinfo []struct {
  8772. Balc float64 `json:"balc"`
  8773. CvlservFlag string `json:"cvlserv_flag"`
  8774. EmpName string `json:"emp_name"`
  8775. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8776. Insutype string `json:"insutype"`
  8777. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8778. PausInsuDate interface{} `json:"paus_insu_date"`
  8779. PsnInsuDate string `json:"psn_insu_date"`
  8780. PsnInsuStas string `json:"psn_insu_stas"`
  8781. PsnType string `json:"psn_type"`
  8782. } `json:"insuinfo"`
  8783. } `json:"output"`
  8784. RefmsgTime string `json:"refmsg_time"`
  8785. RespondTime string `json:"respond_time"`
  8786. Signtype interface{} `json:"signtype"`
  8787. WarnInfo interface{} `json:"warn_info"`
  8788. }
  8789. type ResultThree struct {
  8790. Cainfo interface{} `json:"cainfo"`
  8791. ErrMsg interface{} `json:"err_msg"`
  8792. InfRefmsgid string `json:"inf_refmsgid"`
  8793. Infcode int64 `json:"infcode"`
  8794. Output struct {
  8795. Data struct {
  8796. IptOtpNo string `json:"ipt_otp_no"`
  8797. MdtrtID string `json:"mdtrt_id"`
  8798. PsnNo string `json:"psn_no"`
  8799. } `json:"data"`
  8800. } `json:"output"`
  8801. RefmsgTime string `json:"refmsg_time"`
  8802. RespondTime string `json:"respond_time"`
  8803. Signtype interface{} `json:"signtype"`
  8804. WarnMsg interface{} `json:"warn_msg"`
  8805. }
  8806. type ResultFour struct {
  8807. Cainfo string `json:"cainfo"`
  8808. ErrMsg string `json:"err_msg"`
  8809. InfRefmsgid string `json:"inf_refmsgid"`
  8810. Infcode int64 `json:"infcode"`
  8811. Output struct {
  8812. Result []struct {
  8813. BasMednFlag string `json:"bas_medn_flag"`
  8814. ChldMedcFlag string `json:"chld_medc_flag"`
  8815. ChrgitmLv string `json:"chrgitm_lv"`
  8816. Cnt float64 `json:"cnt"`
  8817. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8818. DrtReimFlag string `json:"drt_reim_flag"`
  8819. FeedetlSn string `json:"feedetl_sn"`
  8820. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8821. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8822. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8823. ListSpItemFlag string `json:"list_sp_item_flag"`
  8824. LmtUsedFlag string `json:"lmt_used_flag"`
  8825. MedChrgitmType string `json:"med_chrgitm_type"`
  8826. Memo string `json:"memo"`
  8827. OverlmtAmt float64 `json:"overlmt_amt"`
  8828. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8829. Pric float64 `json:"pric"`
  8830. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8831. SelfpayProp float64 `json:"selfpay_prop"`
  8832. } `json:"result"`
  8833. } `json:"output"`
  8834. RefmsgTime string `json:"refmsg_time"`
  8835. RespondTime string `json:"respond_time"`
  8836. Signtype string `json:"signtype"`
  8837. WarnMsg string `json:"warn_msg"`
  8838. }
  8839. type ResultFive struct {
  8840. Insutype string `json:"insutype"`
  8841. }
  8842. type ResultSix struct {
  8843. Cainfo interface{} `json:"cainfo"`
  8844. ErrMsg interface{} `json:"err_msg"`
  8845. InfRefmsgid string `json:"inf_refmsgid"`
  8846. Infcode int64 `json:"infcode"`
  8847. Output struct {
  8848. } `json:"output"`
  8849. RefmsgTime string `json:"refmsg_time"`
  8850. RespondTime string `json:"respond_time"`
  8851. Signtype interface{} `json:"signtype"`
  8852. WarnMsg interface{} `json:"warn_msg"`
  8853. }
  8854. type ResultSeven struct {
  8855. Cainfo string `json:"cainfo"`
  8856. ErrMsg string `json:"err_msg"`
  8857. InfRefmsgid string `json:"inf_refmsgid"`
  8858. Infcode int64 `json:"infcode"`
  8859. Output struct {
  8860. Setldetail []interface{} `json:"setldetail"`
  8861. Setlinfo struct {
  8862. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8863. AcctPay float64 `json:"acct_pay"`
  8864. ActPayDedc float64 `json:"act_pay_dedc"`
  8865. Age float64 `json:"age"`
  8866. Balc float64 `json:"balc"`
  8867. Brdy string `json:"brdy"`
  8868. Certno string `json:"certno"`
  8869. ClrOptins string `json:"clr_optins"`
  8870. ClrType string `json:"clr_type"`
  8871. ClrWay string `json:"clr_way"`
  8872. CvlservFlag string `json:"cvlserv_flag"`
  8873. CvlservPay float64 `json:"cvlserv_pay"`
  8874. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8875. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8876. Gend string `json:"gend"`
  8877. HifesPay float64 `json:"hifes_pay"`
  8878. HifmiPay float64 `json:"hifmi_pay"`
  8879. HifobPay float64 `json:"hifob_pay"`
  8880. HifpPay float64 `json:"hifp_pay"`
  8881. HospPartAmt float64 `json:"hosp_part_amt"`
  8882. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8883. Insutype string `json:"insutype"`
  8884. MafPay float64 `json:"maf_pay"`
  8885. MdtrtCertType string `json:"mdtrt_cert_type"`
  8886. MdtrtID string `json:"mdtrt_id"`
  8887. MedType string `json:"med_type"`
  8888. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8889. MedinsSetlID string `json:"medins_setl_id"`
  8890. Naty string `json:"naty"`
  8891. OthPay float64 `json:"oth_pay"`
  8892. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8893. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8894. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8895. PsnCashPay float64 `json:"psn_cash_pay"`
  8896. PsnCertType string `json:"psn_cert_type"`
  8897. PsnName string `json:"psn_name"`
  8898. PsnNo string `json:"psn_no"`
  8899. PsnPartAmt float64 `json:"psn_part_amt"`
  8900. PsnType string `json:"psn_type"`
  8901. SetlID string `json:"setl_id"`
  8902. SetlTime string `json:"setl_time"`
  8903. } `json:"setlinfo"`
  8904. } `json:"output"`
  8905. RefmsgTime string `json:"refmsg_time"`
  8906. RespondTime string `json:"respond_time"`
  8907. Signtype interface{} `json:"signtype"`
  8908. WarnMsg interface{} `json:"warn_msg"`
  8909. }
  8910. type ResultEight struct {
  8911. Cainfo string `json:"cainfo"`
  8912. ErrMsg string `json:"err_msg"`
  8913. InfRefmsgid string `json:"inf_refmsgid"`
  8914. Infcode int64 `json:"infcode"`
  8915. Output struct {
  8916. Stmtinfo struct {
  8917. SetlOptins string `json:"setl_optins"`
  8918. StmtRslt string `json:"stmt_rslt"`
  8919. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8920. } `json:"stmtinfo"`
  8921. } `json:"output"`
  8922. RefmsgTime string `json:"refmsg_time"`
  8923. RespondTime string `json:"respond_time"`
  8924. Signtype interface{} `json:"signtype"`
  8925. WarnMsg interface{} `json:"warn_msg"`
  8926. }
  8927. type ResultNine struct {
  8928. Cainfo string `json:"cainfo"`
  8929. ErrMsg string `json:"err_msg"`
  8930. InfRefmsgid string `json:"inf_refmsgid"`
  8931. Infcode int64 `json:"infcode"`
  8932. Output struct {
  8933. FileQuryNo string `json:"file_qury_no"`
  8934. } `json:"output"`
  8935. RefmsgTime string `json:"refmsg_time"`
  8936. RespondTime string `json:"respond_time"`
  8937. Signtype interface{} `json:"signtype"`
  8938. WarnMsg interface{} `json:"warn_msg"`
  8939. }
  8940. type ResultTen struct {
  8941. Cainfo string `json:"cainfo"`
  8942. ErrMsg string `json:"err_msg"`
  8943. InfRefmsgid string `json:"inf_refmsgid"`
  8944. Infcode int64 `json:"infcode"`
  8945. Output struct {
  8946. DldEndtime string `json:"dld_endtime"`
  8947. FileQuryNo string `json:"file_qury_no"`
  8948. Filename string `json:"filename"`
  8949. } `json:"output"`
  8950. RefmsgTime string `json:"refmsg_time"`
  8951. RespondTime string `json:"respond_time"`
  8952. Signtype interface{} `json:"signtype"`
  8953. WarnMsg interface{} `json:"warn_msg"`
  8954. }
  8955. type ResultEleven struct {
  8956. Cainfo string `json:"cainfo"`
  8957. ErrMsg string `json:"err_msg"`
  8958. InfRefmsgid string `json:"inf_refmsgid"`
  8959. Infcode int64 `json:"infcode"`
  8960. Output struct {
  8961. Setlinfo struct {
  8962. FixmedinsName string `json:"fixmedins_name"`
  8963. FixmedinsCode string `json:"fixmedins_code"`
  8964. PsnNo string `json:"psn_no"`
  8965. PsnName string `json:"psn_name"`
  8966. HifobPay float64 `json:"hifob_pay"`
  8967. Gend string `json:"gend"`
  8968. Brdy string `json:"brdy"`
  8969. PsnCertType string `json:"psn_cert_type"`
  8970. PsnType string `json:"psn_type"`
  8971. EmpName string `json:"emp_name"`
  8972. Certno string `json:"certno"`
  8973. Insutype string `json:"insutype"`
  8974. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8975. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8976. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8977. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8978. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8979. ActPayDedc float64 `json:"act_pay_dedc"`
  8980. HifpPay float64 `json:"hifp_pay"`
  8981. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8982. CvlservPay float64 `json:"cvlserv_pay"`
  8983. HifesPay float64 `json:"hifes_pay"`
  8984. HifmiPay float64 `json:"hifmi_pay"`
  8985. MafPay float64 `json:"maf_pay"`
  8986. OthPay float64 `json:"oth_pay"`
  8987. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8988. PsnPay float64 `json:"psn_pay"`
  8989. AcctPay float64 `json:"acct_pay"`
  8990. CashPayamt float64 `json:"cash_payamt"`
  8991. Balc float64 `json:"balc"`
  8992. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8993. MedinsSetlId string `json:"medins_setl_id"`
  8994. RefdSetlFlag string `json:"refd_setl_flag"`
  8995. SetlTime string `json:"setl_time"`
  8996. MedType string `json:"med_type"`
  8997. } `json:"setlinfo"`
  8998. } `json:"output"`
  8999. RefmsgTime string `json:"refmsg_time"`
  9000. RespondTime string `json:"respond_time"`
  9001. Signtype interface{} `json:"signtype"`
  9002. WarnMsg interface{} `json:"warn_msg"`
  9003. }
  9004. type Custom struct {
  9005. DetItemFeeSumamt string
  9006. Cut string
  9007. FeedetlSn string
  9008. Price string
  9009. MedListCodg string
  9010. Type int64
  9011. AdviceId int64
  9012. ProjectId int64
  9013. ItemId int64
  9014. CostType int64
  9015. }
  9016. // 获取个人信息----挂号-----上传就诊信息
  9017. func (c *HisApiController) GetRegisterInfo() {
  9018. id, _ := c.GetInt64("id")
  9019. record_time := c.GetString("record_time")
  9020. settlementValue, _ := c.GetInt64("settlement_value")
  9021. medical_insurance_card := c.GetString("medical_insurance_card")
  9022. name := c.GetString("name")
  9023. id_card_type, _ := c.GetInt64("id_card_type")
  9024. certificates, _ := c.GetInt64("certificates")
  9025. medical_care, _ := c.GetInt64("medical_care")
  9026. birthday := c.GetString("birthday")
  9027. age, _ := c.GetInt64("age")
  9028. id_card := c.GetString("id_card")
  9029. register_type, _ := c.GetInt64("register")
  9030. doctor, _ := c.GetInt64("doctor")
  9031. department, _ := c.GetInt64("department")
  9032. gender, _ := c.GetInt64("sex")
  9033. phone := c.GetString("phone")
  9034. registration_fee, _ := c.GetFloat("registration_fee")
  9035. medical_expenses, _ := c.GetFloat("medical_expenses")
  9036. social_type, _ := c.GetInt64("social_type")
  9037. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9038. diagnosis_ids := c.GetString("diagnosis")
  9039. sick_type, _ := c.GetInt64("sick_type")
  9040. reg_type := c.GetString("p_type")
  9041. timeLayout := "2006-01-02"
  9042. loc, _ := time.LoadLocation("Local")
  9043. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9044. birthUnix := birthdays.Unix()
  9045. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9046. if err != nil {
  9047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9048. return
  9049. }
  9050. recordDateTime := theTime.Unix()
  9051. adminInfo := c.GetAdminUserInfo()
  9052. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9053. if tempPatient.ID == 0 {
  9054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9055. return
  9056. }
  9057. var patient service.Patients
  9058. if id == 0 {
  9059. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9060. } else {
  9061. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9062. }
  9063. if patient.ID == 0 {
  9064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9065. return
  9066. }
  9067. if len(patient.IdCardNo) == 0 {
  9068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9069. return
  9070. }
  9071. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9072. if len(his) >= 1 {
  9073. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9074. if len(his) >= 1 && order.ID == 0 {
  9075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9076. return
  9077. }
  9078. }
  9079. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9080. fmt.Println(timeStr)
  9081. timeArr := strings.Split(timeStr, " ")
  9082. fmt.Println(timeArr)
  9083. timeArrTwo := strings.Split(timeArr[0], "-")
  9084. timeArrThree := strings.Split(timeArr[1], ":")
  9085. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9086. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9087. if len(lists) == 0 {
  9088. var hisPatient models.XtHisPatient
  9089. hisPatient = models.XtHisPatient{
  9090. Name: name,
  9091. Age: age,
  9092. Gender: gender,
  9093. Birthday: birthUnix,
  9094. Phone: phone,
  9095. MedicalTreatmentType: medical_care,
  9096. IdType: certificates,
  9097. IdCardNo: id_card,
  9098. BalanceAccountsType: settlementValue,
  9099. SocialType: social_type,
  9100. MedicalInsuranceNumber: medical_insurance_card,
  9101. RegisterType: register_type,
  9102. RegisterCost: registration_fee,
  9103. TreatmentCost: medical_expenses,
  9104. AdminUserId: adminInfo.AdminUser.Id,
  9105. UserOrgId: adminInfo.CurrentOrgId,
  9106. Status: 1,
  9107. RecordDate: recordDateTime,
  9108. IsReturn: 1,
  9109. PatientId: patient.ID,
  9110. Ctime: time.Now().Unix(),
  9111. Mtime: time.Now().Unix(),
  9112. Number: str,
  9113. IdCardType: id_card_type,
  9114. Departments: department,
  9115. Doctor: doctor,
  9116. PType: reg_type,
  9117. Diagnosis: diagnosis_ids,
  9118. SickType: sick_type,
  9119. }
  9120. service.CreateHisPatient(&hisPatient)
  9121. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9122. c.ServeSuccessJSON(map[string]interface{}{
  9123. "his_info": hisPatient,
  9124. })
  9125. } else {
  9126. //chrgBchno := rand.Intn(1000000) + 10000
  9127. var hisPatient models.XtHisPatient
  9128. hisPatient = models.XtHisPatient{
  9129. Name: name,
  9130. Age: age,
  9131. Gender: gender,
  9132. Birthday: birthUnix,
  9133. Phone: phone,
  9134. MedicalTreatmentType: medical_care,
  9135. IdType: certificates,
  9136. IdCardNo: id_card,
  9137. BalanceAccountsType: settlementValue,
  9138. SocialType: social_type,
  9139. MedicalInsuranceNumber: medical_insurance_card,
  9140. RegisterType: register_type,
  9141. RegisterCost: registration_fee,
  9142. TreatmentCost: medical_expenses,
  9143. AdminUserId: adminInfo.AdminUser.Id,
  9144. UserOrgId: adminInfo.CurrentOrgId,
  9145. Status: 1,
  9146. RecordDate: recordDateTime,
  9147. IsReturn: 1,
  9148. PatientId: patient.ID,
  9149. Ctime: time.Now().Unix(),
  9150. Mtime: time.Now().Unix(),
  9151. Number: str,
  9152. IdCardType: id_card_type,
  9153. Departments: department,
  9154. Doctor: doctor,
  9155. PType: reg_type,
  9156. Diagnosis: diagnosis_ids,
  9157. SickType: sick_type,
  9158. }
  9159. service.CreateHisPatient(&hisPatient)
  9160. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9161. c.ServeSuccessJSON(map[string]interface{}{
  9162. "his_info": hisPatient,
  9163. })
  9164. }
  9165. }
  9166. // 上传明细----结算
  9167. func (c *HisApiController) GetUploadInfo() {
  9168. id, _ := c.GetInt64("id")
  9169. record_time := c.GetString("record_time")
  9170. his_patient_id, _ := c.GetInt64("his_patient_id")
  9171. oth_desc := c.GetString("oth_desc")
  9172. pay_way, _ := c.GetInt64("pay_way")
  9173. pay_ways := c.GetString("pay_ways")
  9174. pay_price, _ := c.GetFloat("pay_price")
  9175. pay_card_no := c.GetString("pay_card_no")
  9176. discount_price, _ := c.GetFloat("discount_price")
  9177. preferential_price, _ := c.GetFloat("preferential_price")
  9178. reality_price, _ := c.GetFloat("reality_price")
  9179. found_price, _ := c.GetFloat("found_price")
  9180. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9181. private_price, _ := c.GetFloat("private_price")
  9182. timeLayout := "2006-01-02"
  9183. loc, _ := time.LoadLocation("Local")
  9184. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9185. fapiao_code := c.GetString("fapiao_code")
  9186. fapiao_number := c.GetString("fapiao_number")
  9187. diagnosis_id := c.GetString("diagnosis")
  9188. sick_type, _ := c.GetInt64("sick_type")
  9189. reg_type, _ := c.GetInt64("p_type")
  9190. order_id, _ := c.GetInt64("order_id")
  9191. cash_pay := c.GetString("cash_pay")
  9192. wechat_pay := c.GetString("wechat_pay")
  9193. ali_pay := c.GetString("ali_pay")
  9194. jifen_pay := c.GetString("jifen_pay")
  9195. band_card_pay := c.GetString("band_card_pay")
  9196. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9197. tmp_decimal := c.GetString("tmp_decimal")
  9198. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9199. var decimal float64 //本次使用的押金
  9200. var errmsg error
  9201. tx := service.XTWriteDB().Begin() //开了事务
  9202. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9203. defer func() {
  9204. if errmsg != nil {
  9205. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9206. tx.Rollback()
  9207. } else {
  9208. tx.Commit()
  9209. }
  9210. }()
  9211. fmt.Println("dec_way", dec_way)
  9212. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9213. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9214. return
  9215. }
  9216. if len(tmp_decimal) > 0 {
  9217. if tmp_decimal[0] == 45 {
  9218. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9219. return
  9220. }
  9221. }
  9222. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9223. fmt.Println(errs)
  9224. decimal = tt
  9225. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9226. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9227. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9228. if err != nil {
  9229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9230. return
  9231. }
  9232. recordDateTime := theTime.Unix()
  9233. adminUser := c.GetAdminUserInfo()
  9234. var prescriptions []*models.HisPrescription
  9235. var prescriptionsOne []*models.HisPrescription
  9236. var start_time int64
  9237. var end_time int64
  9238. ids_str := c.GetString("ids")
  9239. ids_arr := strings.Split(ids_str, ",")
  9240. if tempOrder.ID == 0 {
  9241. if settle_accounts_type == 1 { //日结
  9242. fmt.Println(reg_type)
  9243. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9244. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9245. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9246. } else {
  9247. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9248. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9249. }
  9250. } else { //月结
  9251. start_time_str := c.GetString("start_time")
  9252. end_time_str := c.GetString("end_time")
  9253. timeLayout := "2006-01-02"
  9254. loc, _ := time.LoadLocation("Local")
  9255. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9256. if err != nil {
  9257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9258. return
  9259. }
  9260. recordStartTime := theStartTime.Unix()
  9261. start_time = recordStartTime
  9262. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9263. if err != nil {
  9264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9265. return
  9266. }
  9267. recordEndTime := theEndTime.Unix()
  9268. end_time = recordEndTime
  9269. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9270. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9271. }
  9272. var goods []*models.DialysisBeforePrepareGoods
  9273. var newGoods []*models.NewDialysisBeforePrepareGoods
  9274. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9275. var infos []*models.HisDoctorAdviceInfo
  9276. var infoList []*models.HisDoctorAdviceInfo
  9277. var hisAdvice []*models.HisDoctorAdviceInfo
  9278. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9279. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9280. //判断库存不足
  9281. //结算出库开关
  9282. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9283. if settConfig.IsOpen == 1 {
  9284. //判断库存的地方
  9285. for _, info := range prescriptions {
  9286. if info.Type == 1 {
  9287. infos = append(infos, info.HisDoctorAdviceInfo...)
  9288. }
  9289. if info.Type == 2 {
  9290. for _, sumItem := range info.HisPrescriptionProject {
  9291. if sumItem.Type == 3 {
  9292. var good models.DialysisBeforePrepareGoods
  9293. var newGood models.NewDialysisBeforePrepareGoods
  9294. good.GoodId = sumItem.GoodInfo.ID
  9295. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9296. count, _ := strconv.Atoi(sumItem.Count)
  9297. good.Count = int64(count)
  9298. good.StorehouseId = houseConfig.StorehouseOutInfo
  9299. good.ProjectId = sumItem.ID
  9300. goods = append(goods, &good)
  9301. newGood.GoodId = sumItem.GoodInfo.ID
  9302. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9303. count2, _ := strconv.Atoi(sumItem.Count)
  9304. newGood.Count = int64(count2)
  9305. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9306. newGood.ProjectId = sumItem.ID
  9307. newGoods = append(newGoods, &newGood)
  9308. }
  9309. }
  9310. }
  9311. }
  9312. for _, info := range prescriptionsOne {
  9313. if info.Type == 1 {
  9314. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9315. }
  9316. if info.Type == 2 {
  9317. for _, sumItem := range info.HisPrescriptionProject {
  9318. if sumItem.Type == 3 {
  9319. var newGood models.NewDialysisBeforePrepareGoods
  9320. newGood.GoodId = sumItem.GoodInfo.ID
  9321. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9322. count2, _ := strconv.Atoi(sumItem.Count)
  9323. newGood.Count = int64(count2)
  9324. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9325. newGood.ProjectId = sumItem.ID
  9326. newGoodOne = append(newGoodOne, &newGood)
  9327. }
  9328. }
  9329. }
  9330. }
  9331. //判断
  9332. for _, itemOne := range infos {
  9333. for _, itemTwo := range hisAdvice {
  9334. if itemOne.DrugId == itemTwo.DrugId {
  9335. itemTwo.Child = append(itemTwo.Child, itemOne)
  9336. }
  9337. }
  9338. }
  9339. for _, itemTwo := range hisAdvice {
  9340. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9341. var sum_out_count int64
  9342. for _, itemThree := range itemTwo.Child {
  9343. var prescribing_number int64
  9344. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9345. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9346. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9347. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9348. }
  9349. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9350. prescribing_number = parseIntPrescribingNumber
  9351. }
  9352. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9353. prescribing_number = parseIntPrescribingNumber
  9354. }
  9355. sum_out_count += prescribing_number
  9356. }
  9357. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9358. if sum_out_count > drugStockOut.FlushCount {
  9359. c.ServeSuccessJSON(map[string]interface{}{
  9360. "msg": "2",
  9361. "drug": medical,
  9362. })
  9363. return
  9364. }
  9365. }
  9366. for _, itemOne := range newGoods {
  9367. for _, item := range newGoodOne {
  9368. if itemOne.GoodId == item.GoodId {
  9369. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9370. }
  9371. }
  9372. }
  9373. for _, item := range newGoodOne {
  9374. var sum_out_count_one int64
  9375. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9376. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9377. sum_out_count_one += itemOne.Count
  9378. }
  9379. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9380. fmt.Println("sum_out_count_one", sum_out_count_one)
  9381. fmt.Println("list.FlushCount", list.FlushCount)
  9382. if sum_out_count_one > list.FlushCount {
  9383. c.ServeSuccessJSON(map[string]interface{}{
  9384. "msg": "3",
  9385. "good": good,
  9386. })
  9387. return
  9388. }
  9389. }
  9390. }
  9391. timestamp := time.Now().Unix()
  9392. tempTime := time.Unix(timestamp, 0)
  9393. timeFormat := tempTime.Format("20060102150405")
  9394. chrgBchno := rand.Intn(100000) + 10000
  9395. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9396. strconv.FormatInt(his.PatientId, 10)
  9397. var ids []int64
  9398. for _, item := range prescriptions {
  9399. ids = append(ids, item.ID)
  9400. }
  9401. var total float64
  9402. for _, item := range prescriptions {
  9403. fmt.Println(item)
  9404. if item.Type == 1 { //药品
  9405. for _, subItem := range item.HisDoctorAdviceInfo {
  9406. total = total + (subItem.Price * subItem.PrescribingNumber)
  9407. }
  9408. }
  9409. if item.Type == 2 { //项目
  9410. for _, subItem := range item.HisPrescriptionProject {
  9411. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9412. total = total + (subItem.Price * cnt)
  9413. }
  9414. }
  9415. for _, subItem := range item.HisAdditionalCharge {
  9416. total = total + (subItem.Price * float64(subItem.Count))
  9417. }
  9418. }
  9419. if reg_type == 1111 || reg_type == 1112 {
  9420. reg_type = 11
  9421. }
  9422. tm := time.Unix(time.Now().Unix(), 0)
  9423. allTotal := fmt.Sprintf("%.4f", total)
  9424. totals, _ := strconv.ParseFloat(allTotal, 64)
  9425. order := &models.HisOrder{
  9426. UserOrgId: adminUser.CurrentOrgId,
  9427. HisPatientId: his.ID,
  9428. PatientId: id,
  9429. SettleAccountsDate: recordDateTime,
  9430. Ctime: time.Now().Unix(),
  9431. Mtime: time.Now().Unix(),
  9432. Status: 1,
  9433. OrderStatus: 2,
  9434. MdtrtId: his.Number,
  9435. Number: chrg_bchno,
  9436. MedfeeSumamt: totals,
  9437. PayWay: pay_way,
  9438. PayWays: pay_ways,
  9439. PayPrice: pay_price,
  9440. MedType: strconv.Itoa(int(reg_type)),
  9441. PayCardNo: pay_card_no,
  9442. DiscountPrice: discount_price,
  9443. PreferentialPrice: preferential_price,
  9444. RealityPrice: reality_price,
  9445. FoundPrice: found_price,
  9446. MedicalInsurancePrice: medical_insurance_price,
  9447. PrivatePrice: private_price,
  9448. SettleEndTime: end_time,
  9449. SettleStartTime: start_time,
  9450. PsnPartAmt: totals,
  9451. PsnCashPay: totals,
  9452. SettleType: settle_accounts_type,
  9453. FaPiaoCode: fapiao_code,
  9454. FaPiaoNumber: fapiao_number,
  9455. Diagnosis: diagnosis_id,
  9456. PType: 2,
  9457. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9458. Decimal: decimal,
  9459. OthDesc: oth_desc,
  9460. CashPay: cash_pay,
  9461. WechatPay: wechat_pay,
  9462. AliPay: ali_pay,
  9463. JifenPay: jifen_pay,
  9464. BandCardPay: band_card_pay,
  9465. Creator: adminUser.AdminUser.Id,
  9466. }
  9467. err = service.CreateOrderTX(order, tx)
  9468. if err != nil {
  9469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9470. return
  9471. }
  9472. var customs []*Custom
  9473. for _, item := range prescriptions {
  9474. if item.Type == 1 { //药品a
  9475. for _, subItem := range item.HisDoctorAdviceInfo {
  9476. cus := &Custom{
  9477. AdviceId: subItem.ID,
  9478. ProjectId: 0,
  9479. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9480. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9481. FeedetlSn: subItem.FeedetlSn,
  9482. Price: fmt.Sprintf("%.4f", subItem.Price),
  9483. MedListCodg: subItem.MedListCodg,
  9484. Type: 1,
  9485. CostType: 9,
  9486. }
  9487. customs = append(customs, cus)
  9488. }
  9489. }
  9490. if item.Type == 2 { //项目
  9491. for _, subItem := range item.HisPrescriptionProject {
  9492. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9493. cus := &Custom{
  9494. AdviceId: 0,
  9495. ProjectId: subItem.ID,
  9496. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9497. Cut: fmt.Sprintf("%.4f", cnt),
  9498. FeedetlSn: subItem.FeedetlSn,
  9499. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9500. MedListCodg: subItem.MedListCodg,
  9501. Type: 2,
  9502. CostType: subItem.HisProject.CostClassify,
  9503. }
  9504. customs = append(customs, cus)
  9505. }
  9506. }
  9507. for _, item := range item.HisAdditionalCharge {
  9508. cus := &Custom{
  9509. ItemId: item.ID,
  9510. AdviceId: 0,
  9511. ProjectId: 0,
  9512. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9513. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9514. FeedetlSn: item.FeedetlSn,
  9515. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9516. MedListCodg: item.XtHisAddtionConfig.Code,
  9517. Type: 3,
  9518. CostType: 5,
  9519. }
  9520. customs = append(customs, cus)
  9521. }
  9522. }
  9523. for _, item := range customs {
  9524. var advice_id int64 = 0
  9525. var project_id int64 = 0
  9526. var item_id int64 = 0
  9527. var types int64 = 0
  9528. var med_chrgitm_type string
  9529. if item.Type == 1 {
  9530. advice_id = item.AdviceId
  9531. project_id = 0
  9532. item_id = 0
  9533. med_chrgitm_type = "09"
  9534. } else if item.Type == 2 {
  9535. med_chrgitm_type = "05"
  9536. if item.CostType == 3 {
  9537. med_chrgitm_type = "04"
  9538. }
  9539. if item.CostType == 8 {
  9540. med_chrgitm_type = "03"
  9541. }
  9542. advice_id = 0
  9543. item_id = 0
  9544. project_id = item.ProjectId
  9545. } else if item.Type == 3 {
  9546. advice_id = 0
  9547. item_id = item.ItemId
  9548. project_id = 0
  9549. med_chrgitm_type = "08"
  9550. }
  9551. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9552. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9553. pric, _ := strconv.ParseFloat(item.Price, 32)
  9554. info := &models.HisOrderInfo{
  9555. OrderNumber: order.Number,
  9556. UploadDate: time.Now().Unix(),
  9557. AdviceId: advice_id,
  9558. DetItemFeeSumamt: detItemFeeSumamt,
  9559. MedChrgitmType: med_chrgitm_type,
  9560. Cnt: cut,
  9561. Pric: pric,
  9562. PatientId: id,
  9563. Status: 1,
  9564. Mtime: time.Now().Unix(),
  9565. Ctime: time.Now().Unix(),
  9566. UserOrgId: adminUser.CurrentOrgId,
  9567. HisPatientId: his.ID,
  9568. OrderId: order.ID,
  9569. ProjectId: project_id,
  9570. Type: types,
  9571. ItemId: item_id,
  9572. }
  9573. service.CreateOrderInfoTX(info, tx)
  9574. }
  9575. his.Diagnosis = diagnosis_id
  9576. his.SickType = sick_type
  9577. his.RegisterType = reg_type
  9578. his.MedicalTreatmentType = reg_type
  9579. service.UpdataHisPateintTX(&his, tx)
  9580. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9581. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9582. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9583. //判断是否使用了押金
  9584. if dec_way == "true" {
  9585. tmpstring := strconv.FormatInt(order.ID, 10)
  9586. //扣押金
  9587. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9588. order.Decimal = decimal
  9589. service.UpDateOrderTwo(order, tx)
  9590. if errmsg != nil {
  9591. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9592. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9593. return
  9594. }
  9595. }
  9596. if err == nil {
  9597. for _, info := range prescriptions {
  9598. if info.Type == 1 {
  9599. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9600. }
  9601. if info.Type == 2 {
  9602. for _, sumItem := range info.HisPrescriptionProject {
  9603. if sumItem.Type == 3 {
  9604. var good models.DialysisBeforePrepareGoods
  9605. var newGood models.NewDialysisBeforePrepareGoods
  9606. var oldGood models.OldDialysisBeforePrepareGoods
  9607. good.GoodId = sumItem.GoodInfo.ID
  9608. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9609. count, _ := strconv.Atoi(sumItem.Count)
  9610. good.Count = int64(count)
  9611. good.StorehouseId = houseConfig.StorehouseOutInfo
  9612. good.ProjectId = sumItem.ID
  9613. good.PatientId = sumItem.PatientId
  9614. goods = append(goods, &good)
  9615. newGood.GoodId = sumItem.GoodInfo.ID
  9616. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9617. count2, _ := strconv.Atoi(sumItem.Count)
  9618. newGood.Count = int64(count2)
  9619. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9620. newGood.ProjectId = sumItem.ID
  9621. newGood.PatientId = sumItem.HisPatientId
  9622. newGoods = append(newGoods, &newGood)
  9623. oldGood.GoodId = sumItem.GoodInfo.ID
  9624. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9625. count3, _ := strconv.Atoi(sumItem.Count)
  9626. oldGood.Count = int64(count3)
  9627. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9628. oldGood.ProjectId = sumItem.ID
  9629. oldGood.RecordDate = sumItem.RecordDate
  9630. oldGood.PatientId = sumItem.HisPatientId
  9631. oldGoods = append(oldGoods, &oldGood)
  9632. }
  9633. }
  9634. }
  9635. }
  9636. if settConfig.IsOpen == 1 {
  9637. for _, item := range infoList {
  9638. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9639. if medical.IsUse == 2 {
  9640. //药品出库
  9641. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9642. //查询默认仓库
  9643. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9644. //查询默认仓库剩余多少库存
  9645. var sum_count int64
  9646. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9647. for _, its := range stockInfo {
  9648. if its.MaxUnit == medical.MaxUnit {
  9649. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9650. }
  9651. sum_count += its.StockMaxNumber + its.StockMinNumber
  9652. }
  9653. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9654. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9655. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9656. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9657. }
  9658. }
  9659. orgId := c.GetAdminUserInfo().CurrentOrgId
  9660. if len(oldGoods) > 0 {
  9661. timeStr := time.Now().Format("2006-01-02")
  9662. timeArr := strings.Split(timeStr, "-")
  9663. total, _ := service.FindAllWarehouseOut(orgId)
  9664. total = total + 1
  9665. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9666. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9667. number = number + total
  9668. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9669. operation_time := time.Now().Unix()
  9670. creater := c.GetAdminUserInfo().AdminUser.Id
  9671. //查询默认出库仓库库存
  9672. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9673. recordDateStr := time.Now().Format("2006-01-02")
  9674. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9675. nowtime := recordDate.Unix()
  9676. warehouseOut := models.WarehouseOut{
  9677. WarehouseOutOrderNumber: warehousing_out_order,
  9678. OperationTime: operation_time,
  9679. OrgId: orgId,
  9680. Creater: creater,
  9681. Ctime: time.Now().Unix(),
  9682. Status: 1,
  9683. WarehouseOutTime: nowtime,
  9684. Type: 1,
  9685. StorehouseId: storeConfig.StorehouseOutInfo,
  9686. IsCheck: 1,
  9687. OrderId: order.ID,
  9688. IsSys: 5,
  9689. }
  9690. //查询是否生成出库单
  9691. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9692. if out.ID == 0 {
  9693. service.AddSigleWarehouseOut(&warehouseOut)
  9694. }
  9695. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9696. for _, item := range oldGoods {
  9697. dialyPrepareOne := models.DialysisBeforePrepare{
  9698. GoodTypeId: item.GoodTypeId,
  9699. GoodId: item.GoodId,
  9700. PatientId: his.PatientId,
  9701. RecordDate: item.RecordDate,
  9702. UserOrgId: adminUser.CurrentOrgId,
  9703. Count: item.Count,
  9704. Ctime: time.Now().Unix(),
  9705. Creater: adminUser.AdminUser.Id,
  9706. CommdityCode: item.CommdityCode,
  9707. Status: 1,
  9708. StorehouseId: houseConfig.StorehouseOutInfo,
  9709. }
  9710. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9711. //非零用
  9712. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9713. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9714. //查询剩余库存
  9715. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9716. var sum_count int64
  9717. for _, item := range goodList {
  9718. sum_count += item.StockCount
  9719. }
  9720. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9721. //耗材
  9722. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9723. }
  9724. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9725. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9726. //查询剩余库存
  9727. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9728. var sum_count int64
  9729. for _, item := range goodList {
  9730. sum_count += item.StockCount
  9731. }
  9732. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9733. //耗材
  9734. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9735. }
  9736. }
  9737. }
  9738. }
  9739. c.ServeSuccessJSON(map[string]interface{}{
  9740. "msg": "结算成功",
  9741. })
  9742. }
  9743. }
  9744. }
  9745. // 退款
  9746. func (c *HisApiController) Refund() {
  9747. order_id, _ := c.GetInt64("order_id")
  9748. order, _ := service.GetHisOrderByID(order_id)
  9749. adminUser := c.GetAdminUserInfo()
  9750. orgid := c.GetAdminUserInfo().CurrentOrgId
  9751. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9752. if err != nil {
  9753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9754. return
  9755. }
  9756. tmp := strconv.FormatInt(order.ID, 10)
  9757. //当押金不为零时产生退费记录
  9758. if order.Decimal != 0 {
  9759. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9760. if err != nil {
  9761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9762. return
  9763. }
  9764. }
  9765. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9766. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9767. var goods []*models.DialysisBeforePrepareGoods
  9768. var newGoods []*models.NewDialysisBeforePrepareGoods
  9769. var infos []*models.HisDoctorAdviceInfo
  9770. for _, info := range orders {
  9771. if info.AdviceId > 0 && info.ProjectId == 0 {
  9772. infos = append(infos, &info.HisDoctorAdviceInfo)
  9773. }
  9774. if info.ProjectId > 0 && info.AdviceId == 0 {
  9775. if info.HisPrescriptionProject.Type == 3 {
  9776. var good models.DialysisBeforePrepareGoods
  9777. var newGood models.NewDialysisBeforePrepareGoods
  9778. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9779. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9780. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9781. good.Count = int64(count)
  9782. good.StorehouseId = houseConfig.StorehouseOutInfo
  9783. good.ProjectId = info.HisPrescriptionProject.ID
  9784. good.PatientId = info.PatientId
  9785. good.OrderId = order_id
  9786. goods = append(goods, &good)
  9787. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9788. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9789. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9790. newGood.Count = int64(count2)
  9791. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9792. newGood.ProjectId = info.HisPrescriptionProject.ID
  9793. newGood.RecordDate = order.SettleAccountsDate
  9794. newGood.UserOrgId = order.UserOrgId
  9795. newGood.PatientId = info.PatientId
  9796. newGood.OrderId = order_id
  9797. newGoods = append(newGoods, &newGood)
  9798. }
  9799. }
  9800. }
  9801. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9802. if settConfig.IsOpen == 1 {
  9803. for _, item := range infos {
  9804. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9805. }
  9806. for _, item := range newGoods {
  9807. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9808. }
  9809. }
  9810. c.ServeSuccessJSON(map[string]interface{}{
  9811. "msg": "退费成功",
  9812. })
  9813. }
  9814. func (c *HisApiController) RefundNumber() {
  9815. his_patient_id, _ := c.GetInt64("id")
  9816. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9817. info.Status = 0
  9818. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9819. if count > 0 {
  9820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9821. return
  9822. }
  9823. err := service.SaveHisPatient(info)
  9824. if err == nil {
  9825. c.ServeSuccessJSON(map[string]interface{}{
  9826. "msg": "退号成功",
  9827. })
  9828. } else {
  9829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9830. return
  9831. }
  9832. }
  9833. func (this *HisApiController) AdditionalCharge() {
  9834. dataBody := make(map[string]interface{}, 0)
  9835. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9836. fmt.Println(err)
  9837. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9838. patient_id := int64(dataBody["patient_id"].(float64))
  9839. medicineData, _ := dataBody["medicineData"].([]interface{})
  9840. adminUserInfo := this.GetAdminUserInfo()
  9841. orgId := adminUserInfo.CurrentOrgId
  9842. admin_user_id := adminUserInfo.AdminUser.Id
  9843. timeStr := time.Now().Format("2006-01-02")
  9844. timeLayout := "2006-01-02 15:04:05"
  9845. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9846. timenow := timeStringToTime.Unix()
  9847. var additionalCharges []*models.HisAdditionalCharge
  9848. for _, item := range medicineData {
  9849. var randNum int
  9850. randNum = rand.Intn(10000) + 1000
  9851. timestamp := time.Now().Unix()
  9852. tempTime := time.Unix(timestamp, 0)
  9853. timeFormat := tempTime.Format("20060102150405")
  9854. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9855. items := item.(map[string]interface{})
  9856. money := items["price"].(string)
  9857. item_id_str := items["item_id"].(string)
  9858. name := items["name"].(string)
  9859. id_str := items["id"].(string)
  9860. moneys, _ := strconv.ParseInt(money, 10, 64)
  9861. monStr := strconv.FormatInt(moneys, 10)
  9862. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9863. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9864. id, _ := strconv.ParseInt(id_str, 10, 64)
  9865. additionalCharge := &models.HisAdditionalCharge{
  9866. ID: id,
  9867. HisPatientId: his_patient_id,
  9868. UserOrgId: orgId,
  9869. PatientId: patient_id,
  9870. RecordDate: timenow,
  9871. Price: monneyStr,
  9872. Status: 1,
  9873. ItemName: name,
  9874. ItemId: item_id,
  9875. AdminUserId: admin_user_id,
  9876. CreatedTime: time.Now().Unix(),
  9877. OrderStatus: 0,
  9878. PrescriptionNumber: "",
  9879. BatchNumber: "",
  9880. FeedetlSn: p_number,
  9881. }
  9882. service.CreateAdditionalCharge(additionalCharge)
  9883. additionalCharges = append(additionalCharges, additionalCharge)
  9884. }
  9885. this.ServeSuccessJSON(map[string]interface{}{
  9886. "msg": "添加成功",
  9887. "additional_charges": additionalCharges,
  9888. })
  9889. }
  9890. func (this *HisApiController) DeleteAddition() {
  9891. id, _ := this.GetInt64("id")
  9892. //TODO 需要判断是否已经结算
  9893. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9894. if err == nil {
  9895. this.ServeSuccessJSON(map[string]interface{}{
  9896. "msg": "删除成功",
  9897. })
  9898. return
  9899. } else {
  9900. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9901. return
  9902. }
  9903. }
  9904. func (this *HisApiController) GetAdminUsers() {
  9905. adminUser := this.GetAdminUserInfo()
  9906. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9907. this.ServeSuccessJSON(map[string]interface{}{
  9908. "doctors": doctors,
  9909. })
  9910. }
  9911. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9912. change_type, _ := this.GetInt64("type", 0)
  9913. record_date := this.GetString("record_time")
  9914. patient_id, _ := this.GetInt64("patient_id", 0)
  9915. p_type, _ := this.GetInt64("p_type", 0)
  9916. timeLayout := "2006-01-02"
  9917. loc, _ := time.LoadLocation("Local")
  9918. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9919. record_time := theAdviceRecordTime.Unix()
  9920. adminUserInfo := this.GetAdminUserInfo()
  9921. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9922. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9923. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9924. if config.ID > 0 && config.IsOpen == 1 {
  9925. for _, subitems := range prescriptions {
  9926. for _, item := range subitems.VMHisPrescription {
  9927. for _, subItem := range item.HisDoctorAdviceInfo {
  9928. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9929. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9930. if info.RetailPrice > 0 {
  9931. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9932. subItem.Drug.RetailPrice = drug.RetailPrice
  9933. }
  9934. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9935. subItem.Drug.MinPrice = info.RetailPrice
  9936. subItem.Drug.RetailPrice = info.RetailPrice
  9937. }
  9938. }
  9939. }
  9940. }
  9941. }
  9942. }
  9943. if config.ID > 0 && config.IsOpen == 1 {
  9944. for _, subitems := range prescriptions {
  9945. for _, item := range subitems.VMHisPrescription {
  9946. for _, subItem := range item.HisPrescriptionProject {
  9947. if subItem.Type == 3 {
  9948. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9949. if info.Price > 0 {
  9950. subItem.GoodInfo.PackingPrice = info.Price
  9951. }
  9952. }
  9953. }
  9954. }
  9955. }
  9956. }
  9957. }
  9958. if err == nil {
  9959. if len(prescriptions) == 0 {
  9960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9961. return
  9962. } else {
  9963. this.ServeSuccessJSON(map[string]interface{}{
  9964. "prescriptions": prescriptions,
  9965. })
  9966. return
  9967. }
  9968. } else {
  9969. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9970. return
  9971. }
  9972. }
  9973. func (this *HisApiController) GetCallHisPrescription() {
  9974. patient_id, _ := this.GetInt64("patient_id", 0)
  9975. timeLayout := "2006-01-02"
  9976. loc, _ := time.LoadLocation("Local")
  9977. start_time := this.GetString("start_time")
  9978. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9979. end_time := this.GetString("end_time")
  9980. p_type, _ := this.GetInt64("p_type")
  9981. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9982. adminUserInfo := this.GetAdminUserInfo()
  9983. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9984. //if
  9985. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9986. //
  9987. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9988. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9989. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9990. if config.ID > 0 && config.IsOpen == 1 {
  9991. for _, subitems := range prescriptions {
  9992. for _, item := range subitems.VMHisPrescription {
  9993. for _, subItem := range item.HisDoctorAdviceInfo {
  9994. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9995. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9996. if info.RetailPrice > 0 {
  9997. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9998. subItem.Drug.RetailPrice = drug.RetailPrice
  9999. }
  10000. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10001. subItem.Drug.MinPrice = info.RetailPrice
  10002. subItem.Drug.RetailPrice = info.RetailPrice
  10003. }
  10004. }
  10005. }
  10006. }
  10007. }
  10008. }
  10009. if config.ID > 0 && config.IsOpen == 1 {
  10010. for _, subitems := range prescriptions {
  10011. for _, item := range subitems.VMHisPrescription {
  10012. for _, subItem := range item.HisPrescriptionProject {
  10013. if subItem.Type == 3 {
  10014. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10015. if info.Price > 0 {
  10016. subItem.GoodInfo.PackingPrice = info.Price
  10017. }
  10018. }
  10019. }
  10020. }
  10021. }
  10022. }
  10023. }
  10024. if err == nil {
  10025. this.ServeSuccessJSON(map[string]interface{}{
  10026. "prescriptions": prescriptions,
  10027. })
  10028. return
  10029. } else {
  10030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10031. return
  10032. }
  10033. }
  10034. func (this *HisApiController) GetHisDayPrescription() {
  10035. timeLayout := "2006-01-02"
  10036. loc, _ := time.LoadLocation("Local")
  10037. start_time := this.GetString("start_time")
  10038. patient_id, _ := this.GetInt64("patient_id", 0)
  10039. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10040. end_time := this.GetString("end_time")
  10041. p_type, _ := this.GetInt64("p_type")
  10042. order_status, _ := this.GetInt64("type")
  10043. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10044. adminUserInfo := this.GetAdminUserInfo()
  10045. var dayHisPrescription []*models.HisPrescription
  10046. var err error
  10047. if order_status == 1 || order_status == 0 {
  10048. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10049. } else if order_status == 2 {
  10050. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10051. }
  10052. var settle_total float64
  10053. for _, item := range dayHisPrescription {
  10054. if len(item.HisPrescriptionProject) > 0 {
  10055. for _, subItem := range item.HisPrescriptionProject {
  10056. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10057. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10058. settle_total = settle_total + total
  10059. }
  10060. }
  10061. if len(item.HisDoctorAdviceInfo) > 0 {
  10062. for _, subItem := range item.HisDoctorAdviceInfo {
  10063. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10064. settle_total = settle_total + total
  10065. }
  10066. }
  10067. }
  10068. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10069. if err == nil {
  10070. this.ServeSuccessJSON(map[string]interface{}{
  10071. "day_prescription": dayHisPrescription,
  10072. "settle_total": settle_total,
  10073. })
  10074. return
  10075. } else {
  10076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10077. return
  10078. }
  10079. }
  10080. func (c *HisApiController) GetHisChargePatientList() {
  10081. record_date := c.GetString("record_date")
  10082. order_status, _ := c.GetInt64("type")
  10083. sch_type, _ := c.GetInt64("sch_type")
  10084. timeLayout := "2006-01-02"
  10085. loc, _ := time.LoadLocation("Local")
  10086. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10087. if err != nil {
  10088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10089. return
  10090. }
  10091. recordDateTime := theTime.Unix()
  10092. adminInfo := c.GetAdminUserInfo()
  10093. var tempPatients []*service.NewTempPatients
  10094. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10095. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10096. if order_status != 2 {
  10097. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10098. } else {
  10099. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10100. }
  10101. } else {
  10102. if order_status != 2 {
  10103. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10104. } else {
  10105. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10106. }
  10107. }
  10108. var patients []*service.NewTempPatients
  10109. var patients_two []*service.NewTempPatients
  10110. for _, item := range tempPatients {
  10111. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10112. //过滤掉没挂号的和没开处方的
  10113. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10114. patients = append(patients, item)
  10115. }
  10116. //过滤掉没挂号的
  10117. if len(item.HisPatient) > 0 {
  10118. patients_two = append(patients_two, item)
  10119. }
  10120. } else {
  10121. if len(item.HisPrescription) > 0 {
  10122. patients = append(patients, item)
  10123. }
  10124. }
  10125. }
  10126. c.ServeSuccessJSON(map[string]interface{}{
  10127. "list": patients,
  10128. "list_two": patients_two,
  10129. })
  10130. }
  10131. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10132. record_date := c.GetString("record_date")
  10133. timeLayout := "2006-01-02"
  10134. loc, _ := time.LoadLocation("Local")
  10135. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10136. if err != nil {
  10137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10138. return
  10139. }
  10140. recordDateTime := theTime.Unix()
  10141. adminUser := c.GetAdminUserInfo()
  10142. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10143. var patients []*service.Patients
  10144. for _, item := range tempPatients {
  10145. if item.HisPatient.ID == 0 {
  10146. patients = append(patients, item)
  10147. }
  10148. }
  10149. c.ServeSuccessJSON(map[string]interface{}{
  10150. "list": patients,
  10151. //"list_two": patients_two,
  10152. })
  10153. }
  10154. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10155. newArr = make([]*service.Patients, 0)
  10156. for i := 0; i < len(patient); i++ {
  10157. repeat := false
  10158. for j := i + 1; j < len(patient); j++ {
  10159. if patient[i].ID == patient[j].ID {
  10160. repeat = true
  10161. break
  10162. }
  10163. }
  10164. if !repeat {
  10165. newArr = append(newArr, patient[i])
  10166. }
  10167. }
  10168. return
  10169. }
  10170. func (c *HisApiController) GetHisChargePatientInfo() {
  10171. patient_id, _ := c.GetInt64("patient_id")
  10172. his_patient_id, _ := c.GetInt64("his_patient_id")
  10173. record_date := c.GetString("record_date")
  10174. //start_time := c.GetString("start_time")
  10175. //end_time := c.GetString("end_time")
  10176. order_status, _ := c.GetInt64("type", 0)
  10177. p_type, _ := c.GetInt64("p_type", 0)
  10178. order_id, _ := c.GetInt64("order_id", 0)
  10179. timeLayout := "2006-01-02"
  10180. loc, _ := time.LoadLocation("Local")
  10181. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10182. if err != nil {
  10183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10184. return
  10185. }
  10186. recordDateTime := theTime.Unix()
  10187. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10188. //if err != nil {
  10189. //
  10190. //}
  10191. //startRecordDateTime := startTime.Unix()
  10192. //
  10193. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10194. //if err != nil {
  10195. //
  10196. //}
  10197. //endRecordDateTime := endTime.Unix()
  10198. admin := c.GetAdminUserInfo()
  10199. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10200. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10201. var prescriptions []*models.HisPrescription
  10202. //var unChargeMonthPrescriptions []*models.HisPrescription
  10203. order, _ := service.GetHisOrderByID(order_id)
  10204. if order_status == 1 || order_status == 0 {
  10205. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10206. } else if order_status == 2 {
  10207. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10208. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10209. }
  10210. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10211. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10212. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10213. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10214. //获取所有科室信息
  10215. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10216. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10217. c.ServeSuccessJSON(map[string]interface{}{
  10218. "his_info": his_patient_info,
  10219. "xt_info": xt_patient_info,
  10220. "prescription": prescriptions,
  10221. "case_history": case_history,
  10222. "info": patientPrescriptionInfo,
  10223. "last_info": lastPatientPrescriptionInfo,
  10224. "order": order,
  10225. "doctors": doctors,
  10226. "department": department,
  10227. "sch": sch,
  10228. })
  10229. return
  10230. }
  10231. func (c *HisApiController) GetAllOrderDetail() {
  10232. order_id, _ := c.GetInt64("id", 0)
  10233. order, _ := service.GetHisOrderByID(order_id)
  10234. if order.ID == 0 {
  10235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10236. return
  10237. }
  10238. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10239. org_id := c.GetAdminUserInfo().CurrentOrgId
  10240. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10241. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10242. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10243. c.ServeSuccessJSON(map[string]interface{}{
  10244. "order": order,
  10245. "order_info": order_info,
  10246. "patient": patient,
  10247. "admin_info": adminInfo,
  10248. "hospital_record": record,
  10249. })
  10250. return
  10251. }
  10252. func (c *HisApiController) GetAllOrderDetailCollect() {
  10253. order_id, _ := c.GetInt64("id", 0)
  10254. order, _ := service.GetHisOrderByID(order_id)
  10255. if order.ID == 0 {
  10256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10257. return
  10258. }
  10259. org_id := c.GetAdminUserInfo().CurrentOrgId
  10260. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10261. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10262. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10263. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10264. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10265. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10266. var bedCostTotal float64 = 0 //床位总费
  10267. //var bedCostSelfTotal float64 = 0 //床位自费
  10268. var operationCostTotal float64 = 0 //手术费
  10269. //var operationCostSelfTotal float64 = 0 //手术费
  10270. var otherCostTotal float64 = 0 //其他费用
  10271. //var otherCostSelfTotal float64 = 0 //其他费用
  10272. var materialCostTotal float64 = 0 //材料费
  10273. //var materialCostSelfTotal float64 = 0 //材料费
  10274. var westernMedicineCostTotal float64 = 0 //西药费
  10275. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10276. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10277. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10278. var checkCostTotal float64 = 0 //检查费
  10279. //var checkCostSelfTotal float64 = 0 //检查费
  10280. var laboratoryCostTotal float64 = 0 //化验费
  10281. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10282. var treatCostTotal float64 = 0 //治疗费用
  10283. //var treatCostSelfTotal float64 = 0 //治疗费用
  10284. var zhenChaCostTotal float64 = 0 //其他费用
  10285. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10286. decimal.DivisionPrecision = 2
  10287. var BalanceAccountsType int64
  10288. if his.ID > 0 {
  10289. BalanceAccountsType = his.BalanceAccountsType
  10290. } else {
  10291. BalanceAccountsType = record.BalanceAccountsType
  10292. }
  10293. if BalanceAccountsType != 2 {
  10294. for _, item := range order_info {
  10295. if org_id == 10215 {
  10296. if item.MedChrgitmType == "01" { //床位费
  10297. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10298. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10299. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10300. }
  10301. if item.MedChrgitmType == "02" { //诊察费
  10302. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10303. //zhenChaCostSelfTotal = zhenChaCostTotal
  10304. }
  10305. if item.MedChrgitmType == "03" { //检查费
  10306. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10307. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10308. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10309. }
  10310. //if item.MedChrgitmType == "02" { //检查费
  10311. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10312. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10313. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10314. //}
  10315. if item.MedChrgitmType == "04" { //化验费
  10316. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10317. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10318. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10319. }
  10320. if item.MedChrgitmType == "05" { //治疗费
  10321. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10322. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10323. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10324. }
  10325. if item.MedChrgitmType == "06" { //手术费
  10326. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10327. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10328. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10329. }
  10330. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10331. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10332. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10333. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10334. }
  10335. if item.MedChrgitmType == "09" { //西药费
  10336. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10337. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10338. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10339. }
  10340. if item.MedChrgitmType == "11" { //中成费
  10341. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10342. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10343. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10344. }
  10345. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10346. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10347. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10348. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10349. }
  10350. } else if org_id == 10188 || org_id == 10217 {
  10351. if item.MedChrgitmType == "01" { //床位费
  10352. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10353. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10354. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10355. }
  10356. if item.MedChrgitmType == "02" { //诊察费
  10357. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10358. //zhenChaCostSelfTotal = zhenChaCostTotal
  10359. }
  10360. if item.MedChrgitmType == "03" { //检查费
  10361. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10362. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10363. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10364. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10365. }
  10366. //if item.MedChrgitmType == "02" { //检查费
  10367. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10368. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10369. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10370. //}
  10371. if item.MedChrgitmType == "04" { //化验费
  10372. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10373. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10374. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10375. }
  10376. if item.MedChrgitmType == "05" { //治疗费
  10377. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10378. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10379. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10380. }
  10381. if item.MedChrgitmType == "06" { //手术费
  10382. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10383. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10384. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10385. }
  10386. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10387. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10388. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10389. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10390. }
  10391. if item.MedChrgitmType == "09" { //西药费
  10392. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10393. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10394. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10395. }
  10396. if item.MedChrgitmType == "11" { //中成费
  10397. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10398. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10399. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10400. }
  10401. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10402. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10403. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10404. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10405. }
  10406. } else {
  10407. if item.MedChrgitmType == "01" { //床位费
  10408. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10409. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10410. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10411. }
  10412. //if item.MedChrgitmType == "02" { //诊察费
  10413. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10414. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10415. //}
  10416. if item.MedChrgitmType == "03" { //检查费
  10417. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10418. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10419. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10420. }
  10421. //if item.MedChrgitmType == "02" { //检查费
  10422. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10423. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10424. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10425. //}
  10426. if item.MedChrgitmType == "04" { //化验费
  10427. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10428. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10429. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10430. }
  10431. if item.MedChrgitmType == "05" { //治疗费
  10432. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10433. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10434. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10435. }
  10436. if item.MedChrgitmType == "06" { //手术费
  10437. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10438. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10439. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10440. }
  10441. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10442. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10443. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10444. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10445. }
  10446. if item.MedChrgitmType == "09" { //西药费
  10447. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10448. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10449. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10450. }
  10451. if item.MedChrgitmType == "11" { //中成费
  10452. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10453. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10454. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10455. }
  10456. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10457. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10458. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10459. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10460. }
  10461. }
  10462. }
  10463. c.ServeSuccessJSON(map[string]interface{}{
  10464. "order": order,
  10465. "order_info": order_info,
  10466. "patient": patient,
  10467. "admin_info": adminInfo,
  10468. "his_hospital": record,
  10469. "bedCostTotal": bedCostTotal,
  10470. "operationCostTotal": operationCostTotal,
  10471. "otherCostTotal": otherCostTotal,
  10472. "materialCostTotal": materialCostTotal,
  10473. "westernMedicineCostTotal": westernMedicineCostTotal,
  10474. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10475. "checkCostTotal": checkCostTotal,
  10476. "zhenChaCostTotal": zhenChaCostTotal,
  10477. "laboratoryCostTotal": laboratoryCostTotal,
  10478. "treatCostTotal": treatCostTotal,
  10479. })
  10480. } else {
  10481. for _, item := range order_info {
  10482. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10483. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10484. item.MedChrgitmType = "09"
  10485. }
  10486. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10487. if item.HisPrescriptionProject.Type == 2 {
  10488. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10489. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10490. case 0:
  10491. item.MedChrgitmType = "0"
  10492. break
  10493. case 1:
  10494. item.MedChrgitmType = "14"
  10495. break
  10496. case 2:
  10497. item.MedChrgitmType = "05"
  10498. break
  10499. case 3:
  10500. item.MedChrgitmType = "03"
  10501. break
  10502. case 4:
  10503. item.MedChrgitmType = "03"
  10504. break
  10505. case 5:
  10506. item.MedChrgitmType = "08"
  10507. break
  10508. case 6:
  10509. item.MedChrgitmType = "14"
  10510. break
  10511. case 7:
  10512. item.MedChrgitmType = "14"
  10513. break
  10514. case 8:
  10515. item.MedChrgitmType = "03"
  10516. break
  10517. case 9:
  10518. item.MedChrgitmType = "14"
  10519. break
  10520. case 10:
  10521. item.MedChrgitmType = "14"
  10522. break
  10523. case 11:
  10524. item.MedChrgitmType = "06"
  10525. break
  10526. case 12:
  10527. item.MedChrgitmType = "12"
  10528. break
  10529. case 13:
  10530. item.MedChrgitmType = "01"
  10531. break
  10532. case 14:
  10533. item.MedChrgitmType = "04"
  10534. break
  10535. case 15:
  10536. item.MedChrgitmType = "14"
  10537. break
  10538. }
  10539. } else {
  10540. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10541. case 1:
  10542. item.MedChrgitmType = "14"
  10543. break
  10544. case 2:
  10545. item.MedChrgitmType = "05"
  10546. break
  10547. case 3:
  10548. item.MedChrgitmType = "04"
  10549. break
  10550. case 4:
  10551. item.MedChrgitmType = "14"
  10552. break
  10553. case 5:
  10554. item.MedChrgitmType = "08"
  10555. break
  10556. case 6:
  10557. item.MedChrgitmType = "14"
  10558. break
  10559. case 7:
  10560. item.MedChrgitmType = "14"
  10561. break
  10562. case 8:
  10563. item.MedChrgitmType = "03"
  10564. break
  10565. case 9:
  10566. item.MedChrgitmType = "14"
  10567. break
  10568. }
  10569. }
  10570. } else if item.HisPrescriptionProject.Type == 3 {
  10571. item.MedChrgitmType = "08"
  10572. }
  10573. }
  10574. }
  10575. for _, item := range order_info {
  10576. if org_id == 10215 {
  10577. if item.MedChrgitmType == "01" { //床位费
  10578. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10579. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10580. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10581. }
  10582. if item.MedChrgitmType == "02" { //诊察费
  10583. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10584. //zhenChaCostSelfTotal = zhenChaCostTotal
  10585. }
  10586. if item.MedChrgitmType == "03" { //检查费
  10587. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10588. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10589. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10590. }
  10591. //if item.MedChrgitmType == "02" { //检查费
  10592. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10593. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10594. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10595. //}
  10596. if item.MedChrgitmType == "04" { //化验费
  10597. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10598. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10599. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10600. }
  10601. if item.MedChrgitmType == "05" { //治疗费
  10602. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10603. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10604. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10605. }
  10606. if item.MedChrgitmType == "06" { //手术费
  10607. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10608. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10609. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10610. }
  10611. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10612. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10613. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10614. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10615. }
  10616. if item.MedChrgitmType == "09" { //西药费
  10617. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10618. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10619. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10620. }
  10621. if item.MedChrgitmType == "11" { //中成费
  10622. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10623. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10624. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10625. }
  10626. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10627. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10628. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10629. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10630. }
  10631. } else {
  10632. if item.MedChrgitmType == "01" { //床位费
  10633. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10634. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10635. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10636. }
  10637. //if item.MedChrgitmType == "02" { //诊察费
  10638. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10639. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10640. //}
  10641. if item.MedChrgitmType == "03" { //检查费
  10642. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10643. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10644. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10645. }
  10646. //if item.MedChrgitmType == "02" { //检查费
  10647. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10648. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10649. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10650. //}
  10651. if item.MedChrgitmType == "04" { //化验费
  10652. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10653. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10654. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10655. }
  10656. if item.MedChrgitmType == "05" { //治疗费
  10657. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10658. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10659. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10660. }
  10661. if item.MedChrgitmType == "06" { //手术费
  10662. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10663. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10664. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10665. }
  10666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10668. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10669. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10670. }
  10671. if item.MedChrgitmType == "09" { //西药费
  10672. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10673. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10674. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10675. }
  10676. if item.MedChrgitmType == "11" { //中成费
  10677. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10678. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10679. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10680. }
  10681. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10682. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10683. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10684. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10685. }
  10686. }
  10687. }
  10688. c.ServeSuccessJSON(map[string]interface{}{
  10689. "order": order,
  10690. "order_info": order_info,
  10691. "patient": patient,
  10692. "admin_info": adminInfo,
  10693. "his_hospital": record,
  10694. "bedCostTotal": bedCostTotal,
  10695. "operationCostTotal": operationCostTotal,
  10696. "otherCostTotal": otherCostTotal,
  10697. "materialCostTotal": materialCostTotal,
  10698. "westernMedicineCostTotal": westernMedicineCostTotal,
  10699. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10700. "checkCostTotal": checkCostTotal,
  10701. "zhenChaCostTotal": zhenChaCostTotal,
  10702. "laboratoryCostTotal": laboratoryCostTotal,
  10703. "treatCostTotal": treatCostTotal,
  10704. })
  10705. }
  10706. }
  10707. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10708. page, _ := c.GetInt64("page")
  10709. limit, _ := c.GetInt64("limit")
  10710. keywords := c.GetString("keywords")
  10711. start_time := c.GetString("start_time")
  10712. end_time := c.GetString("end_time")
  10713. //clr_type := c.GetString("clr_type")
  10714. insutype := c.GetString("insutype")
  10715. timeLayout := "2006-01-02"
  10716. loc, _ := time.LoadLocation("Local")
  10717. var theStartTIme int64
  10718. if len(start_time) > 0 {
  10719. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10720. theStartTIme = theTime.Unix()
  10721. }
  10722. var theEndtTIme int64
  10723. if len(end_time) > 0 {
  10724. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10725. theEndtTIme = theTime.Unix()
  10726. }
  10727. if page <= 0 {
  10728. page = 1
  10729. }
  10730. if limit <= 0 {
  10731. limit = 10
  10732. }
  10733. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10734. c.ServeSuccessJSON(map[string]interface{}{
  10735. "total": total,
  10736. "list": list,
  10737. })
  10738. return
  10739. }
  10740. func (c *HisApiController) GetPutOnRecordList() {
  10741. page, _ := c.GetInt64("page")
  10742. limit, _ := c.GetInt64("limit")
  10743. keywords := c.GetString("keywords")
  10744. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10745. if page <= 0 {
  10746. page = 1
  10747. }
  10748. if limit <= 0 {
  10749. limit = 10
  10750. }
  10751. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10752. c.ServeSuccessJSON(map[string]interface{}{
  10753. "total": total,
  10754. "list": list,
  10755. })
  10756. return
  10757. }
  10758. func (c *HisApiController) GetCompareData() {
  10759. start_time := c.GetString("start_time")
  10760. end_time := c.GetString("end_time")
  10761. insutype := c.GetString("insutype")
  10762. clr_type := c.GetString("clr_type")
  10763. timeLayout := "2006-01-02"
  10764. loc, _ := time.LoadLocation("Local")
  10765. var theStartTIme int64
  10766. if len(start_time) > 0 {
  10767. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10768. if err != nil {
  10769. theStartTIme = 0
  10770. }
  10771. theStartTIme = theTime.Unix()
  10772. }
  10773. var theEndtTIme int64
  10774. if len(end_time) > 0 {
  10775. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10776. if err != nil {
  10777. theEndtTIme = 0
  10778. }
  10779. theEndtTIme = theTime.Unix()
  10780. }
  10781. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10782. fmt.Println(err)
  10783. if err == nil {
  10784. c.ServeSuccessJSON(map[string]interface{}{
  10785. "list": formData,
  10786. })
  10787. } else {
  10788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10789. return
  10790. }
  10791. }
  10792. func (c *HisApiController) GetFaPiaoData() {
  10793. order_id, _ := c.GetInt64("order_id")
  10794. patient_id, _ := c.GetInt64("patient_id")
  10795. //number := c.GetString("number")
  10796. adminUser := c.GetAdminUserInfo()
  10797. order, _ := service.GetHisOrderByID(order_id)
  10798. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10799. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10800. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10801. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10802. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10803. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10804. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10805. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10806. var bedCostTotal float64 = 0 //床位总费
  10807. var bedCostSelfTotal float64 = 0 //床位自费
  10808. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10809. var operationCostTotal float64 = 0 //手术费
  10810. var operationCostSelfTotal float64 = 0 //手术费
  10811. var operationCostPartSelfTotal float64 = 0 //手术费
  10812. var otherCostTotal float64 = 0 //其他费用
  10813. var otherCostSelfTotal float64 = 0 //其他费用
  10814. var otherCostPartSelfTotal float64 = 0 //其他费用
  10815. var materialCostTotal float64 = 0 //材料费
  10816. var materialCostSelfTotal float64 = 0 //材料费
  10817. var materialCostPartSelfTotal float64 = 0 //材料费
  10818. var westernMedicineCostTotal float64 = 0 //西药费
  10819. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10820. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10821. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10822. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10823. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10824. var checkCostTotal float64 = 0 //检查费
  10825. var checkCostSelfTotal float64 = 0 //检查费
  10826. var checkCostPartSelfTotal float64 = 0 //检查费
  10827. var hiliCostTotal float64 = 0 //护理费
  10828. var hiliCostSelfTotal float64 = 0 //护理费
  10829. var hiliCostPartSelfTotal float64 = 0 //护理费
  10830. var laboratoryCostTotal float64 = 0 //化验费
  10831. var laboratoryCostSelfTotal float64 = 0 //化验费
  10832. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10833. var treatCostTotal float64 = 0 //治疗费用
  10834. var treatCostSelfTotal float64 = 0 //治疗费用
  10835. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10836. var zhenChaCostTotal float64 = 0 //其他费用
  10837. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10838. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10839. decimal.DivisionPrecision = 2
  10840. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10841. var balanceAccountsType int64
  10842. if his.ID > 0 {
  10843. balanceAccountsType = his.BalanceAccountsType
  10844. } else {
  10845. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10846. }
  10847. if balanceAccountsType == 2 {
  10848. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10849. for _, item := range orderInfos_two {
  10850. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10851. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10852. item.MedChrgitmType = "09"
  10853. }
  10854. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10855. if item.HisPrescriptionProject.Type == 2 {
  10856. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10857. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10858. case 0:
  10859. item.MedChrgitmType = "0"
  10860. break
  10861. case 1:
  10862. item.MedChrgitmType = "14"
  10863. break
  10864. case 2:
  10865. item.MedChrgitmType = "05"
  10866. break
  10867. case 3:
  10868. item.MedChrgitmType = "03"
  10869. break
  10870. case 4:
  10871. item.MedChrgitmType = "03"
  10872. break
  10873. case 5:
  10874. item.MedChrgitmType = "08"
  10875. break
  10876. case 6:
  10877. item.MedChrgitmType = "14"
  10878. break
  10879. case 7:
  10880. item.MedChrgitmType = "14"
  10881. break
  10882. case 8:
  10883. item.MedChrgitmType = "03"
  10884. break
  10885. case 9:
  10886. item.MedChrgitmType = "14"
  10887. break
  10888. case 10:
  10889. item.MedChrgitmType = "14"
  10890. break
  10891. case 11:
  10892. item.MedChrgitmType = "06"
  10893. break
  10894. case 12:
  10895. item.MedChrgitmType = "12"
  10896. break
  10897. case 13:
  10898. item.MedChrgitmType = "01"
  10899. break
  10900. case 14:
  10901. item.MedChrgitmType = "04"
  10902. break
  10903. case 15:
  10904. item.MedChrgitmType = "02"
  10905. break
  10906. }
  10907. } else {
  10908. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10909. case 1:
  10910. item.MedChrgitmType = "14"
  10911. break
  10912. case 2:
  10913. item.MedChrgitmType = "05"
  10914. break
  10915. case 3:
  10916. item.MedChrgitmType = "04"
  10917. break
  10918. case 4:
  10919. item.MedChrgitmType = "03"
  10920. break
  10921. case 5:
  10922. item.MedChrgitmType = "08"
  10923. break
  10924. case 6:
  10925. item.MedChrgitmType = "14"
  10926. break
  10927. case 7:
  10928. item.MedChrgitmType = "14"
  10929. break
  10930. case 8:
  10931. item.MedChrgitmType = "03"
  10932. break
  10933. case 9:
  10934. item.MedChrgitmType = "14"
  10935. break
  10936. }
  10937. }
  10938. } else if item.HisPrescriptionProject.Type == 3 {
  10939. item.MedChrgitmType = "08"
  10940. }
  10941. }
  10942. }
  10943. for _, item := range orderInfos_two {
  10944. fmt.Println(item.MedChrgitmType)
  10945. if item.MedChrgitmType == "07" { //床位费
  10946. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10947. hiliCostSelfTotal = hiliCostTotal
  10948. }
  10949. if item.MedChrgitmType == "01" { //床位费
  10950. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10951. bedCostSelfTotal = bedCostTotal
  10952. }
  10953. if item.MedChrgitmType == "02" { //诊察费
  10954. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10955. zhenChaCostSelfTotal = zhenChaCostTotal
  10956. }
  10957. if item.MedChrgitmType == "03" { //检查费
  10958. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10959. checkCostSelfTotal = checkCostTotal
  10960. }
  10961. if item.MedChrgitmType == "04" { //化验费
  10962. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10963. laboratoryCostSelfTotal = laboratoryCostTotal
  10964. }
  10965. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10966. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10967. treatCostSelfTotal = treatCostTotal
  10968. }
  10969. if item.MedChrgitmType == "06" { //手术费
  10970. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10971. operationCostSelfTotal = treatCostTotal
  10972. }
  10973. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10974. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10975. materialCostSelfTotal = materialCostTotal
  10976. }
  10977. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10978. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10979. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10980. }
  10981. if item.MedChrgitmType == "11" { //中成费
  10982. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10983. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10984. }
  10985. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10986. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10987. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10988. otherCostSelfTotal = otherCostTotal
  10989. }
  10990. } else {
  10991. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10992. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10993. otherCostSelfTotal = otherCostTotal
  10994. }
  10995. }
  10996. }
  10997. } else {
  10998. for _, item := range orderInfos {
  10999. if item.MedChrgitmType == "01" { //床位费
  11000. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11001. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11002. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11003. }
  11004. if item.MedChrgitmType == "02" { //诊察费
  11005. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11006. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11007. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11008. }
  11009. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11010. if item.MedChrgitmType == "03" { //检查费
  11011. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11012. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11013. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11014. }
  11015. } else {
  11016. if item.MedChrgitmType == "03" { //检查费
  11017. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11018. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11019. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11020. }
  11021. }
  11022. if item.MedChrgitmType == "04" { //化验费
  11023. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11024. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11025. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11026. }
  11027. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11028. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11029. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11030. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11031. }
  11032. if item.MedChrgitmType == "06" { //手术费
  11033. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11034. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11035. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11036. }
  11037. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11038. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11039. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11040. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11041. }
  11042. if item.MedChrgitmType == "07" { //护理
  11043. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11044. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11045. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11046. }
  11047. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11048. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11049. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11050. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11051. }
  11052. if item.MedChrgitmType == "11" { //中成费
  11053. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11054. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11055. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11056. }
  11057. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11058. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11059. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11060. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11061. }
  11062. }
  11063. }
  11064. timeLayout := "2006-01-02"
  11065. loc, _ := time.LoadLocation("Local")
  11066. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11067. if err != nil {
  11068. }
  11069. startRecordDateTime := startTime.Unix()
  11070. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11071. if err != nil {
  11072. }
  11073. endRecordDateTime := endTime.Unix()
  11074. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11075. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11076. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11077. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11078. c.ServeSuccessJSON(map[string]interface{}{
  11079. "charge_admin_name": charge_admin.UserName,
  11080. "order_number": order.Number, //业务流水号
  11081. "id_card_no": his.IdCardNo, //社会保障号
  11082. "patient": patient,
  11083. "department_name": department.Name, //科室
  11084. "number": his.Number, //门诊号
  11085. "date": order.SettleAccountsDate, //结算日期
  11086. "name": order.PsnName, //姓名
  11087. "gender": patient.Gender, //性别
  11088. "psn_cash_money": order.PsnCashPay, //个人支付
  11089. "pay_way": "门诊", //结算方式
  11090. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11091. "admin_user_name": admin.UserName, //收款员
  11092. "order": order,
  11093. "order_info": orderInfos_two,
  11094. "his": his,
  11095. "bedCostTotal": bedCostTotal,
  11096. "bedCostSelfTotal": bedCostSelfTotal,
  11097. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11098. "operationCostTotal": operationCostTotal,
  11099. "operationCostSelfTotal": operationCostSelfTotal,
  11100. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11101. "otherCostTotal": otherCostTotal,
  11102. "otherCostSelfTotal": otherCostSelfTotal,
  11103. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11104. "materialCostTotal": materialCostTotal,
  11105. "materialCostSelfTotal": materialCostSelfTotal,
  11106. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11107. "westernMedicineCostTotal": westernMedicineCostTotal,
  11108. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11109. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11110. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11111. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11112. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11113. "checkCostTotal": checkCostTotal,
  11114. "checkCostSelfTotal": checkCostSelfTotal,
  11115. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11116. "laboratoryCostTotal": laboratoryCostTotal,
  11117. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11118. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11119. "treatCostTotal": treatCostTotal,
  11120. "treatCostSelfTotal": treatCostSelfTotal,
  11121. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11122. "zhenChaCostTotal": zhenChaCostTotal,
  11123. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11124. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11125. "his_hospital_record": his_hospital_record,
  11126. "pre_pay_money": pre_pay_money,
  11127. "refund_sum": sum,
  11128. "doctor_info": doctor_info,
  11129. "hiliCostTotal": hiliCostTotal,
  11130. "hiliCostSelfTotal": hiliCostSelfTotal,
  11131. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11132. })
  11133. }
  11134. //func (c *HisApiController) GetFaPiaoDatas() {
  11135. // order_ids := c.GetString("order_ids")
  11136. // patient_id, _ := c.GetInt64("patient_id")
  11137. // adminUser := c.GetAdminUserInfo()
  11138. //
  11139. // orders := strings.Split(order_ids, ",")
  11140. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11141. //
  11142. // for _, item := range orders {
  11143. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11144. // order, _ := service.GetHisOrderByID(order_id)
  11145. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11146. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11147. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11148. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11149. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11150. //
  11151. // }
  11152. //
  11153. // var bedCostTotal float64 = 0 //床位总费
  11154. // var bedCostSelfTotal float64 = 0 //床位自费
  11155. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11156. //
  11157. // var operationCostTotal float64 = 0 //手术费
  11158. // var operationCostSelfTotal float64 = 0 //手术费
  11159. // var operationCostPartSelfTotal float64 = 0 //手术费
  11160. //
  11161. // var otherCostTotal float64 = 0 //其他费用
  11162. // var otherCostSelfTotal float64 = 0 //其他费用
  11163. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11164. //
  11165. // var materialCostTotal float64 = 0 //材料费
  11166. // var materialCostSelfTotal float64 = 0 //材料费
  11167. // var materialCostPartSelfTotal float64 = 0 //材料费
  11168. //
  11169. // var westernMedicineCostTotal float64 = 0 //西药费
  11170. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11171. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11172. //
  11173. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11174. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11175. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11176. //
  11177. // var checkCostTotal float64 = 0 //检查费
  11178. // var checkCostSelfTotal float64 = 0 //检查费
  11179. // var checkCostPartSelfTotal float64 = 0 //检查费
  11180. //
  11181. // var laboratoryCostTotal float64 = 0 //化验费
  11182. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11183. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11184. //
  11185. // var treatCostTotal float64 = 0 //治疗费用
  11186. // var treatCostSelfTotal float64 = 0 //治疗费用
  11187. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11188. //
  11189. // var zhenChaCostTotal float64 = 0 //其他费用
  11190. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11191. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11192. //
  11193. // decimal.DivisionPrecision = 2
  11194. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11195. //
  11196. // var balanceAccountsType int64
  11197. // if his.ID > 0 {
  11198. // balanceAccountsType = his.BalanceAccountsType
  11199. // } else {
  11200. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11201. // }
  11202. // if balanceAccountsType == 2 {
  11203. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11204. // for _, item := range orderInfos_two {
  11205. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11206. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11207. // item.MedChrgitmType = "09"
  11208. // }
  11209. //
  11210. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11211. // if item.HisPrescriptionProject.Type == 2 {
  11212. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11213. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11214. // case 0:
  11215. // item.MedChrgitmType = "0"
  11216. // break
  11217. // case 1:
  11218. // item.MedChrgitmType = "14"
  11219. // break
  11220. // case 2:
  11221. // item.MedChrgitmType = "05"
  11222. //
  11223. // break
  11224. // case 3:
  11225. // item.MedChrgitmType = "03"
  11226. //
  11227. // break
  11228. // case 4:
  11229. // item.MedChrgitmType = "03"
  11230. //
  11231. // break
  11232. // case 5:
  11233. // item.MedChrgitmType = "08"
  11234. //
  11235. // break
  11236. // case 6:
  11237. // item.MedChrgitmType = "14"
  11238. //
  11239. // break
  11240. // case 7:
  11241. // item.MedChrgitmType = "14"
  11242. //
  11243. // break
  11244. // case 8:
  11245. // item.MedChrgitmType = "03"
  11246. // break
  11247. // case 9:
  11248. // item.MedChrgitmType = "14"
  11249. // break
  11250. // case 10:
  11251. // item.MedChrgitmType = "14"
  11252. // break
  11253. // case 11:
  11254. // item.MedChrgitmType = "06"
  11255. // break
  11256. // case 12:
  11257. // item.MedChrgitmType = "12"
  11258. // break
  11259. // case 13:
  11260. // item.MedChrgitmType = "01"
  11261. // break
  11262. // case 14:
  11263. // item.MedChrgitmType = "04"
  11264. // break
  11265. // case 15:
  11266. // item.MedChrgitmType = "02"
  11267. // break
  11268. //
  11269. // }
  11270. //
  11271. // } else {
  11272. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11273. //
  11274. // case 1:
  11275. // item.MedChrgitmType = "14"
  11276. // break
  11277. // case 2:
  11278. // item.MedChrgitmType = "05"
  11279. //
  11280. // break
  11281. // case 3:
  11282. // item.MedChrgitmType = "03"
  11283. //
  11284. // break
  11285. // case 4:
  11286. // item.MedChrgitmType = "03"
  11287. //
  11288. // break
  11289. // case 5:
  11290. // item.MedChrgitmType = "08"
  11291. //
  11292. // break
  11293. // case 6:
  11294. // item.MedChrgitmType = "14"
  11295. //
  11296. // break
  11297. // case 7:
  11298. // item.MedChrgitmType = "14"
  11299. //
  11300. // break
  11301. // case 8:
  11302. // item.MedChrgitmType = "03"
  11303. // break
  11304. // case 9:
  11305. // item.MedChrgitmType = "14"
  11306. // break
  11307. //
  11308. // }
  11309. //
  11310. // }
  11311. //
  11312. // } else if item.HisPrescriptionProject.Type == 3 {
  11313. // item.MedChrgitmType = "08"
  11314. // }
  11315. // }
  11316. // }
  11317. //
  11318. // for _, item := range orderInfos_two {
  11319. // fmt.Println(item.MedChrgitmType)
  11320. // if item.MedChrgitmType == "01" { //床位费
  11321. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11322. // bedCostSelfTotal = bedCostTotal
  11323. // }
  11324. //
  11325. // if item.MedChrgitmType == "02" { //诊察费
  11326. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11327. // zhenChaCostSelfTotal = zhenChaCostTotal
  11328. // }
  11329. //
  11330. // if item.MedChrgitmType == "03" { //检查费
  11331. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11332. // checkCostSelfTotal = checkCostTotal
  11333. // }
  11334. //
  11335. // if item.MedChrgitmType == "04" { //化验费
  11336. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11337. // laboratoryCostSelfTotal = laboratoryCostTotal
  11338. // }
  11339. //
  11340. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11341. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11342. // treatCostSelfTotal = treatCostTotal
  11343. // }
  11344. //
  11345. // if item.MedChrgitmType == "06" { //手术费
  11346. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11347. // operationCostSelfTotal = treatCostTotal
  11348. // }
  11349. //
  11350. // if item.MedChrgitmType == "08" { //材料费
  11351. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11352. // materialCostSelfTotal = materialCostTotal
  11353. // }
  11354. //
  11355. // if item.MedChrgitmType == "09" { //西药费
  11356. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11357. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11358. // }
  11359. //
  11360. // if item.MedChrgitmType == "11" { //中成费
  11361. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11362. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11363. // }
  11364. //
  11365. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11366. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11367. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11368. // otherCostSelfTotal = otherCostTotal
  11369. // }
  11370. // } else {
  11371. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11372. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11373. // otherCostSelfTotal = otherCostTotal
  11374. // }
  11375. //
  11376. // }
  11377. //
  11378. // }
  11379. //
  11380. // } else {
  11381. // for _, item := range orderInfos {
  11382. // if item.MedChrgitmType == "01" { //床位费
  11383. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11384. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11385. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11386. // }
  11387. //
  11388. // if item.MedChrgitmType == "02" { //诊察费
  11389. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11390. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11391. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11392. // }
  11393. //
  11394. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11395. // if item.MedChrgitmType == "03" { //检查费
  11396. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11397. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11398. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11399. //
  11400. // }
  11401. // } else {
  11402. // if item.MedChrgitmType == "03" { //检查费
  11403. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11404. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11405. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11406. // }
  11407. //
  11408. // }
  11409. //
  11410. // if item.MedChrgitmType == "04" { //化验费
  11411. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11412. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11413. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11414. //
  11415. // }
  11416. //
  11417. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11418. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11419. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11420. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11421. //
  11422. // }
  11423. //
  11424. // if item.MedChrgitmType == "06" { //手术费
  11425. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11426. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11427. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11428. // }
  11429. //
  11430. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11431. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11432. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11433. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11434. // }
  11435. //
  11436. // if item.MedChrgitmType == "09" { //西药费
  11437. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11438. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11439. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11440. // }
  11441. //
  11442. // if item.MedChrgitmType == "11" { //中成费
  11443. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11444. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11445. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11446. // }
  11447. //
  11448. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11449. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11450. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11451. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11452. // }
  11453. //
  11454. // }
  11455. // }
  11456. // timeLayout := "2006-01-02"
  11457. // loc, _ := time.LoadLocation("Local")
  11458. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11459. // if err != nil {
  11460. // }
  11461. // startRecordDateTime := startTime.Unix()
  11462. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11463. // if err != nil {
  11464. // }
  11465. // endRecordDateTime := endTime.Unix()
  11466. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11467. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11468. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11469. //
  11470. // c.ServeSuccessJSON(map[string]interface{}{
  11471. // "order_number": order.Number, //业务流水号
  11472. // "id_card_no": his.IdCardNo, //社会保障号
  11473. // "department_name": department.Name, //科室
  11474. // "number": his.Number, //门诊号
  11475. // "date": order.SettleAccountsDate, //结算日期
  11476. // "name": order.PsnName, //姓名
  11477. // "gender": patient.Gender, //性别
  11478. // "psn_cash_money": order.PsnCashPay, //个人支付
  11479. // "pay_way": "门诊", //结算方式
  11480. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11481. // "admin_user_name": admin.UserName, //收款员
  11482. // "order": order,
  11483. // "order_info": orderInfos_two,
  11484. // "his": his,
  11485. // "bedCostTotal": bedCostTotal,
  11486. // "bedCostSelfTotal": bedCostSelfTotal,
  11487. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11488. // "operationCostTotal": operationCostTotal,
  11489. // "operationCostSelfTotal": operationCostSelfTotal,
  11490. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11491. // "otherCostTotal": otherCostTotal,
  11492. // "otherCostSelfTotal": otherCostSelfTotal,
  11493. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11494. // "materialCostTotal": materialCostTotal,
  11495. // "materialCostSelfTotal": materialCostSelfTotal,
  11496. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11497. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11498. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11499. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11500. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11501. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11502. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11503. // "checkCostTotal": checkCostTotal,
  11504. // "checkCostSelfTotal": checkCostSelfTotal,
  11505. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11506. // "laboratoryCostTotal": laboratoryCostTotal,
  11507. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11508. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11509. // "treatCostTotal": treatCostTotal,
  11510. // "treatCostSelfTotal": treatCostSelfTotal,
  11511. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11512. // "zhenChaCostTotal": zhenChaCostTotal,
  11513. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11514. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11515. // "his_hospital_record": his_hospital_record,
  11516. // "pre_pay_money": pre_pay_money,
  11517. // "refund_sum": sum,
  11518. // })
  11519. //
  11520. //}
  11521. func (this *HisApiController) GetIncomeStatisticsData() {
  11522. start_time := this.GetString("start_time")
  11523. end_time := this.GetString("end_time")
  11524. key_words := this.GetString("key_words")
  11525. limit, _ := this.GetInt64("limit")
  11526. page, _ := this.GetInt64("page")
  11527. if page <= 0 {
  11528. page = 1
  11529. }
  11530. if limit <= 0 {
  11531. limit = 10
  11532. }
  11533. statistics_type, _ := this.GetInt64("statistics_type")
  11534. admin := this.GetAdminUserInfo()
  11535. timeLayout := "2006-01-02"
  11536. loc, _ := time.LoadLocation("Local")
  11537. var theStartTIme int64
  11538. if len(start_time) > 0 {
  11539. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11540. if err != nil {
  11541. theStartTIme = 0
  11542. }
  11543. theStartTIme = theTime.Unix()
  11544. }
  11545. var theEndtTIme int64
  11546. if len(end_time) > 0 {
  11547. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11548. if err != nil {
  11549. theEndtTIme = 0
  11550. }
  11551. theEndtTIme = theTime.Unix()
  11552. }
  11553. if statistics_type == 1 {
  11554. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11555. this.ServeSuccessJSON(map[string]interface{}{
  11556. "list": list,
  11557. "total": total,
  11558. })
  11559. } else {
  11560. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11561. this.ServeSuccessJSON(map[string]interface{}{
  11562. "list": list,
  11563. "total": total,
  11564. })
  11565. }
  11566. }
  11567. func (c *HisApiController) PostProjectInformation() {
  11568. adminUser := c.GetAdminUserInfo()
  11569. orgId := adminUser.CurrentOrgId
  11570. dataBody := make(map[string]interface{}, 0)
  11571. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11572. if err != nil {
  11573. utils.ErrorLog(err.Error())
  11574. return
  11575. }
  11576. utils.ErrorLog("%v", dataBody)
  11577. var projectList []*models.HisProject
  11578. var total_goods []interface{}
  11579. tempProjects := dataBody["projects"].([]interface{})
  11580. total_goods = tempProjects
  11581. for index, projectMap := range tempProjects {
  11582. projectM := projectMap.(map[string]interface{})
  11583. var project models.HisProject
  11584. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11585. utils.ErrorLog("project_name")
  11586. return
  11587. }
  11588. project_name, _ := projectM["project_name"].(string)
  11589. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11590. err_log := models.ExportErrLog{
  11591. LogType: 6,
  11592. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11593. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11594. Status: 1,
  11595. CreateTime: time.Now().Unix(),
  11596. UpdateTime: time.Now().Unix(),
  11597. ExportTime: time.Now().Unix(),
  11598. }
  11599. service.CreateExportErrLog(&err_log)
  11600. continue
  11601. }
  11602. project.ProjectName = project_name
  11603. prices := projectM["price"].(string)
  11604. price, _ := strconv.ParseFloat(prices, 64)
  11605. if price <= 0 { //名字为空则生成一条导入错误日志
  11606. err_log := models.ExportErrLog{
  11607. LogType: 6,
  11608. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11609. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11610. Status: 1,
  11611. CreateTime: time.Now().Unix(),
  11612. UpdateTime: time.Now().Unix(),
  11613. ExportTime: time.Now().Unix(),
  11614. }
  11615. service.CreateExportErrLog(&err_log)
  11616. continue
  11617. }
  11618. project.Price = price
  11619. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11620. utils.ErrorLog("unit_id")
  11621. return
  11622. }
  11623. unit := projectM["unit"].(string)
  11624. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11625. err_log := models.ExportErrLog{
  11626. LogType: 6,
  11627. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11628. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11629. Status: 1,
  11630. CreateTime: time.Now().Unix(),
  11631. UpdateTime: time.Now().Unix(),
  11632. ExportTime: time.Now().Unix(),
  11633. }
  11634. service.CreateExportErrLog(&err_log)
  11635. continue
  11636. }
  11637. project.Unit = unit
  11638. cost_classify := projectM["cost_classify"].(string)
  11639. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11640. err_log := models.ExportErrLog{
  11641. LogType: 6,
  11642. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11643. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11644. Status: 1,
  11645. CreateTime: time.Now().Unix(),
  11646. UpdateTime: time.Now().Unix(),
  11647. ExportTime: time.Now().Unix(),
  11648. }
  11649. service.CreateExportErrLog(&err_log)
  11650. continue
  11651. }
  11652. var costClassify = "费用类别"
  11653. var cost_classify_id int64
  11654. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11655. if len(cost_classify) != 0 {
  11656. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11657. if errcode == gorm.ErrRecordNotFound {
  11658. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11659. dataconfig := models.DictDataconfig{
  11660. ParentId: costClassifyConfig.ID,
  11661. Module: "system",
  11662. OrgId: orgId,
  11663. Name: cost_classify,
  11664. FieldName: "",
  11665. Value: costConfig.Value + 1,
  11666. CreatedTime: "",
  11667. UpdatedTime: "",
  11668. CreateUserId: adminUser.AdminUser.Id,
  11669. Status: 1,
  11670. Remark: "",
  11671. DeleteIdSystem: 0,
  11672. Title: "",
  11673. Content: "",
  11674. Order: 0,
  11675. Code: "",
  11676. }
  11677. service.CreatedDicConfig(&dataconfig)
  11678. }
  11679. }
  11680. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11681. for _, it := range costClassList {
  11682. if cost_classify == it.Name {
  11683. cost_classify_id = int64(it.Value)
  11684. }
  11685. }
  11686. project.CostClassify = cost_classify_id
  11687. executive_section := projectM["executive_section"].(string)
  11688. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11689. err_log := models.ExportErrLog{
  11690. LogType: 6,
  11691. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11692. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11693. Status: 1,
  11694. CreateTime: time.Now().Unix(),
  11695. UpdateTime: time.Now().Unix(),
  11696. ExportTime: time.Now().Unix(),
  11697. }
  11698. service.CreateExportErrLog(&err_log)
  11699. continue
  11700. }
  11701. if len(executive_section) != 0 {
  11702. //查找科室是否有内容
  11703. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11704. if errcodedepart == gorm.ErrRecordNotFound {
  11705. department := models.XtHisDepartment{
  11706. Name: executive_section,
  11707. Status: 1,
  11708. UserOrgId: adminUser.CurrentOrgId,
  11709. CreatedTime: time.Now().Unix(),
  11710. }
  11711. service.CreateDePartment(&department)
  11712. }
  11713. }
  11714. var executive_section_id int64
  11715. departMentList, _ := service.GetAllDepartMent(orgId)
  11716. for _, it := range departMentList {
  11717. if executive_section == it.Name {
  11718. executive_section_id = it.ID
  11719. }
  11720. }
  11721. project.ExecutiveSection = executive_section_id
  11722. medical_coverage := projectM["medical_coverage"].(string)
  11723. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11724. err_log := models.ExportErrLog{
  11725. LogType: 6,
  11726. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11727. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11728. Status: 1,
  11729. CreateTime: time.Now().Unix(),
  11730. UpdateTime: time.Now().Unix(),
  11731. ExportTime: time.Now().Unix(),
  11732. }
  11733. service.CreateExportErrLog(&err_log)
  11734. continue
  11735. }
  11736. var medicalCoverage = "医保等级"
  11737. var medical_coverage_id int64
  11738. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11739. if len(medical_coverage) != 0 {
  11740. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11741. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11742. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11743. dataconfig := models.DictDataconfig{
  11744. ParentId: medicalCoverageConfig.ID,
  11745. Module: "system",
  11746. OrgId: orgId,
  11747. Name: medical_coverage,
  11748. FieldName: "",
  11749. Value: medicalCoverageConfig.Value + 1,
  11750. CreatedTime: "",
  11751. UpdatedTime: "",
  11752. CreateUserId: adminUser.AdminUser.Id,
  11753. Status: 1,
  11754. Remark: "",
  11755. DeleteIdSystem: 0,
  11756. Title: "",
  11757. Content: "",
  11758. Order: 0,
  11759. Code: "",
  11760. }
  11761. service.CreatedDicConfig(&dataconfig)
  11762. }
  11763. }
  11764. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11765. for _, it := range medicalCoverageList {
  11766. if medical_coverage == it.Name {
  11767. medical_coverage_id = int64(it.Value)
  11768. }
  11769. }
  11770. project.MedicalCoverage = medical_coverage_id
  11771. pinyin := projectM["pinyin"].(string)
  11772. project.Pinyin = pinyin
  11773. wubi := projectM["wubi"].(string)
  11774. project.Wubi = wubi
  11775. statistical_classification := projectM["statistical_classification"].(string)
  11776. var statisticalClassification = "统计分类"
  11777. var statistical_classification_id int64
  11778. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11779. if len(statistical_classification) != 0 {
  11780. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11781. if classificationerrcodes == gorm.ErrRecordNotFound {
  11782. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11783. dataconfig := models.DictDataconfig{
  11784. ParentId: classiFication.ID,
  11785. Module: "system",
  11786. OrgId: orgId,
  11787. Name: statistical_classification,
  11788. FieldName: "",
  11789. Value: classiFicationConfig.Value + 1,
  11790. CreatedTime: "",
  11791. UpdatedTime: "",
  11792. CreateUserId: adminUser.AdminUser.Id,
  11793. Status: 1,
  11794. Remark: "",
  11795. DeleteIdSystem: 0,
  11796. Title: "",
  11797. Content: "",
  11798. Order: 0,
  11799. Code: "",
  11800. }
  11801. service.CreatedDicConfig(&dataconfig)
  11802. }
  11803. }
  11804. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11805. for _, it := range classiFicationList {
  11806. if statistical_classification == it.Name {
  11807. statistical_classification_id = int64(it.Value)
  11808. }
  11809. }
  11810. project.StatisticalClassification = statistical_classification_id
  11811. disease_directory := int64(projectM["disease_directory"].(float64))
  11812. project.DiseaseDirectory = disease_directory
  11813. is_record := int64(projectM["is_record"].(float64))
  11814. project.IsRecord = is_record
  11815. medical_code := projectM["medical_code"].(string)
  11816. project.MedicalCode = medical_code
  11817. tube_color := projectM["tube_color"].(string)
  11818. var tubeColor = "试管颜色"
  11819. var tube_color_id int64
  11820. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11821. if len(tube_color) != 0 {
  11822. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11823. if errcodetube == gorm.ErrRecordNotFound {
  11824. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11825. dataconfig := models.DictDataconfig{
  11826. ParentId: tubeColorConfig.ID,
  11827. Module: "system",
  11828. OrgId: orgId,
  11829. Name: tube_color,
  11830. FieldName: "",
  11831. Value: tubeConfig.Value + 1,
  11832. CreatedTime: "",
  11833. UpdatedTime: "",
  11834. CreateUserId: adminUser.AdminUser.Id,
  11835. Status: 1,
  11836. Remark: "",
  11837. DeleteIdSystem: 0,
  11838. Title: "",
  11839. Content: "",
  11840. Order: 0,
  11841. Code: "",
  11842. }
  11843. service.CreatedDicConfig(&dataconfig)
  11844. }
  11845. }
  11846. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11847. for _, it := range tubeColorList {
  11848. if tube_color == it.Name {
  11849. tube_color_id = int64(it.Value)
  11850. }
  11851. }
  11852. project.TubeColor = tube_color_id
  11853. single_dose := projectM["single_dose"].(string)
  11854. project.SingleDose = single_dose
  11855. execution_frequency := projectM["execution_frequency"].(string)
  11856. project.ExecutionFrequency = execution_frequency
  11857. delivery_way := projectM["delivery_way"].(string)
  11858. project.DeliveryWay = delivery_way
  11859. number_days := projectM["number_days"].(string)
  11860. project.NumberDays = number_days
  11861. total := projectM["total"].(string)
  11862. project.Total = total
  11863. medical_status := int64(projectM["medical_status"].(float64))
  11864. project.MedicalStatus = medical_status
  11865. category := int64(projectM["category"].(float64))
  11866. project.Category = category
  11867. specail_project := int64(projectM["specail_project"].(float64))
  11868. project.SpecailProject = specail_project
  11869. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11870. project.SocialSecurityDirectoryCode = social_security_directory_code
  11871. remark := projectM["remark"].(string)
  11872. project.Remark = remark
  11873. record_date := projectM["record_date"].(string)
  11874. timeLayout := "2006-01-02"
  11875. loc, _ := time.LoadLocation("Local")
  11876. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11877. project.RecordDate = theTime.Unix()
  11878. projectList = append(projectList, &project)
  11879. }
  11880. export_time := time.Now().Unix()
  11881. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11882. if len(projectList) > 0 {
  11883. for _, item := range projectList {
  11884. hans := item.ProjectName // 要转换的汉字字符串
  11885. // 创建一个拼音转换器
  11886. p := pinyin.NewArgs()
  11887. // 将汉字转为拼音
  11888. pinyinSlice := pinyin.Pinyin(hans, p)
  11889. // 输出拼音
  11890. fmt.Println("Pinyin:", pinyinSlice)
  11891. // 获取首字母
  11892. firstLetter := ""
  11893. for _, py := range pinyinSlice {
  11894. if len(py) > 0 {
  11895. firstLetter += string(py[0][0])
  11896. }
  11897. }
  11898. item.FirstLetter = firstLetter
  11899. project := models.HisProject{
  11900. ProjectName: item.ProjectName,
  11901. Price: item.Price,
  11902. Unit: item.Unit,
  11903. CostClassify: item.CostClassify,
  11904. ExecutiveSection: item.ExecutiveSection,
  11905. MedicalCoverage: item.MedicalCoverage,
  11906. UserOrgId: orgId,
  11907. Status: 1,
  11908. CreatedTime: time.Now().Unix(),
  11909. Pinyin: item.Pinyin,
  11910. Wubi: item.Wubi,
  11911. StatisticalClassification: item.StatisticalClassification,
  11912. DiseaseDirectory: item.DiseaseDirectory,
  11913. IsRecord: item.IsRecord,
  11914. MedicalCode: item.MedicalCode,
  11915. TubeColor: item.TubeColor,
  11916. SingleDose: item.SingleDose,
  11917. DeliveryWay: item.DeliveryWay,
  11918. NumberDays: item.NumberDays,
  11919. Total: item.Total,
  11920. Category: item.Category,
  11921. MedicalStatus: item.MedicalStatus,
  11922. SpecailProject: item.SpecailProject,
  11923. RecordDate: item.RecordDate,
  11924. Remark: item.Remark,
  11925. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11926. ExecutionFrequency: item.ExecutionFrequency,
  11927. FirstLetter: item.FirstLetter,
  11928. }
  11929. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11930. if errcodeproject == gorm.ErrRecordNotFound {
  11931. service.CreateProjectInfomation(&project)
  11932. } else if errcodeproject == nil {
  11933. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11934. }
  11935. log := models.ExportLog{
  11936. LogType: 6,
  11937. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11938. TotalNum: int64(len(total_goods)),
  11939. FailNum: int64(len(errLogs)),
  11940. SuccessNum: int64(len(projectList)),
  11941. CreateTime: time.Now().Unix(),
  11942. UpdateTime: time.Now().Unix(),
  11943. ExportTime: export_time,
  11944. Status: 1,
  11945. }
  11946. service.CreateExportLog(&log)
  11947. c.ServeSuccessJSON(map[string]interface{}{
  11948. "msg": "导入成功",
  11949. "total_num": len(total_goods),
  11950. "success_num": len(projectList),
  11951. "fail_num": int64(len(errLogs)),
  11952. })
  11953. }
  11954. } else {
  11955. log := models.ExportLog{
  11956. LogType: 6,
  11957. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11958. TotalNum: int64(len(total_goods)),
  11959. FailNum: int64(len(errLogs)),
  11960. SuccessNum: int64(len(projectList)),
  11961. CreateTime: time.Now().Unix(),
  11962. UpdateTime: time.Now().Unix(),
  11963. ExportTime: export_time,
  11964. Status: 1,
  11965. }
  11966. service.CreateExportLog(&log)
  11967. c.ServeSuccessJSON(map[string]interface{}{
  11968. "msg": "导入成功",
  11969. "total_num": len(total_goods),
  11970. "success_num": len(projectList),
  11971. "fail_num": int64(len(errLogs)),
  11972. })
  11973. }
  11974. }
  11975. //func (this *HisApiController) EditProjectInformation(){
  11976. //
  11977. // id, _ := this.GetInt64("id")
  11978. // project_team := this.GetString("project_team")
  11979. // price := this.GetString("price")
  11980. // price_float, _ := strconv.ParseFloat(price, 64)
  11981. // pinyin := this.GetString("pinyin")
  11982. // wubi := this.GetString("wubi")
  11983. // tube_color, _ := this.GetInt64("tube_color")
  11984. // team_type, _ := this.GetInt64("team_type")
  11985. // remark := this.GetString("remark")
  11986. // ids := this.GetString("ids")
  11987. // item_id := this.GetString("item_id")
  11988. // projectTeam := models.XtHisProjectTeam{
  11989. // ProjectTeam: project_team,
  11990. // Price: price_float,
  11991. // Pinyin: pinyin,
  11992. // Wubi: wubi,
  11993. // TubeColor: tube_color,
  11994. // TeamType: team_type,
  11995. // Remark: remark,
  11996. // ProjectId: ids,
  11997. // ItemId: item_id,
  11998. // }
  11999. //
  12000. //
  12001. // dataBody := make(map[string]interface{}, 0)
  12002. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12003. // if err != nil {
  12004. // utils.ErrorLog(err.Error())
  12005. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12006. // return
  12007. // }
  12008. //
  12009. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12010. //
  12011. //
  12012. // if err != nil {
  12013. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12014. // return
  12015. // }
  12016. //
  12017. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12018. // infos, _ := dataBody["info"].([]interface{})
  12019. // if len(infos) > 0 {
  12020. // var ids []string
  12021. //
  12022. // for _, item := range infos {
  12023. // items := item.(map[string]interface{})
  12024. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12025. // utils.ErrorLog("id")
  12026. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12027. // return
  12028. // }
  12029. // id := int64(items["id"].(float64))
  12030. //
  12031. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12032. // utils.ErrorLog("type")
  12033. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12034. // return
  12035. // }
  12036. // types := int64(items["type"].(float64))
  12037. //
  12038. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12039. // utils.ErrorLog("number")
  12040. // }
  12041. //
  12042. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12043. //
  12044. // projectList := models.XtHisProjectList{
  12045. // Number: number,
  12046. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12047. // ProjectId: id,
  12048. // Status: 1,
  12049. // CreatedTime: time.Now().Unix(),
  12050. // UpdatedTime: time.Now().Unix(),
  12051. // TeamId: projectTeam.ID,
  12052. // Type: types,
  12053. // }
  12054. // list := projectList
  12055. //
  12056. // service.CreateProjectList(&list)
  12057. //
  12058. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12059. //
  12060. // }
  12061. // ids_str := strings.Join(ids, ",")
  12062. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12063. // service.SaveProjectTeam(&projectTeam)
  12064. // this.ServeSuccessJSON(map[string]interface{}{
  12065. // "projectTeam": projectTeam,
  12066. // })
  12067. // }
  12068. // }
  12069. //}
  12070. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12071. name := c.GetString("name")
  12072. mode_id, _ := c.GetInt64("mode", 0)
  12073. types, _ := c.GetInt64("type", 0)
  12074. patient_id, _ := c.GetInt64("patient_id", 0)
  12075. types = 1
  12076. adminInfo := c.GetAdminUserInfo()
  12077. template := &models.HisPrescriptionTemplate{
  12078. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12079. PatientId: patient_id,
  12080. Type: types,
  12081. Status: 1,
  12082. Ctime: time.Now().Unix(),
  12083. Mtime: time.Now().Unix(),
  12084. Name: name,
  12085. Mode: mode_id,
  12086. }
  12087. dataBody := make(map[string]interface{}, 0)
  12088. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12089. if err != nil {
  12090. utils.ErrorLog(err.Error())
  12091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12092. return
  12093. }
  12094. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12095. //如果已经存在记录则删除处方
  12096. if template_one.ID > 0 {
  12097. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12098. var ids []int64
  12099. var org_id int64
  12100. for _, item := range ps {
  12101. org_id = c.GetAdminUserInfo().CurrentOrgId
  12102. ids = append(ids, item.ID)
  12103. }
  12104. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12105. if err2 == nil {
  12106. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12107. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12108. if len(prescriptions) > 0 {
  12109. for _, item := range prescriptions {
  12110. items := item.(map[string]interface{})
  12111. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12112. utils.ErrorLog("type")
  12113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12114. return
  12115. }
  12116. types := int64(items["type"].(float64))
  12117. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12118. utils.ErrorLog("med_type")
  12119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12120. return
  12121. }
  12122. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12123. ctime := time.Now().Unix()
  12124. prescription := &models.HisPrescriptionInfoTemplate{
  12125. PatientId: patient_id,
  12126. UserOrgId: adminInfo.CurrentOrgId,
  12127. Ctime: ctime,
  12128. Mtime: ctime,
  12129. Type: types,
  12130. Modifier: adminInfo.AdminUser.Id,
  12131. Creator: adminInfo.AdminUser.Id,
  12132. Status: 1,
  12133. PTemplateId: template_one.ID,
  12134. MedType: med_type,
  12135. }
  12136. service.CreateHisPrescriptionInfoTemplate(prescription)
  12137. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12138. advices := items["advices"].([]interface{})
  12139. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12140. ctime := time.Now().Unix()
  12141. mtime := ctime
  12142. if len(advices) > 0 {
  12143. for _, advice := range advices {
  12144. var s models.HisPrescriptionAdviceTemplate
  12145. s.PrescriptionId = prescription.ID
  12146. s.AdviceType = 2
  12147. s.StopState = 2
  12148. s.ExecutionState = 2
  12149. s.Status = 1
  12150. s.UserOrgId = adminInfo.CurrentOrgId
  12151. s.CreatedTime = ctime
  12152. s.UpdatedTime = mtime
  12153. s.PatientId = patient_id
  12154. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12155. if errcode > 0 {
  12156. c.ServeFailJSONWithSGJErrorCode(errcode)
  12157. return
  12158. }
  12159. service.CreateHisPrescriptionAdviceTemplate(&s)
  12160. }
  12161. }
  12162. }
  12163. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12164. projects := items["project"].([]interface{})
  12165. if len(projects) > 0 {
  12166. for _, project := range projects {
  12167. var p models.HisPrescriptionProjectTemplate
  12168. p.PrescriptionId = prescription.ID
  12169. p.Ctime = time.Now().Unix()
  12170. p.Mtime = time.Now().Unix()
  12171. p.PatientId = patient_id
  12172. p.UserOrgId = adminInfo.CurrentOrgId
  12173. p.Status = 1
  12174. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12175. if errcode > 0 {
  12176. c.ServeFailJSONWithSGJErrorCode(errcode)
  12177. return
  12178. }
  12179. service.CreateHisPrescriptionProjectTemplate(&p)
  12180. }
  12181. }
  12182. }
  12183. }
  12184. c.ServeSuccessJSON(map[string]interface{}{
  12185. "msg": "创建成功",
  12186. })
  12187. }
  12188. }
  12189. } else {
  12190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12191. return
  12192. }
  12193. } else {
  12194. err3 := service.CreateHisPrescriptionTemplate(template)
  12195. if err3 == nil {
  12196. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12197. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12198. if len(prescriptions) > 0 {
  12199. for _, item := range prescriptions {
  12200. items := item.(map[string]interface{})
  12201. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12202. utils.ErrorLog("type")
  12203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12204. return
  12205. }
  12206. types := int64(items["type"].(float64))
  12207. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12208. utils.ErrorLog("med_type")
  12209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12210. return
  12211. }
  12212. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12213. ctime := time.Now().Unix()
  12214. prescription := &models.HisPrescriptionInfoTemplate{
  12215. PatientId: patient_id,
  12216. UserOrgId: adminInfo.CurrentOrgId,
  12217. Ctime: ctime,
  12218. Mtime: ctime,
  12219. Type: types,
  12220. Modifier: adminInfo.AdminUser.Id,
  12221. Creator: adminInfo.AdminUser.Id,
  12222. Status: 1,
  12223. PTemplateId: template.ID,
  12224. MedType: med_type,
  12225. }
  12226. service.CreateHisPrescriptionInfoTemplate(prescription)
  12227. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12228. advices := items["advices"].([]interface{})
  12229. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12230. ctime := time.Now().Unix()
  12231. mtime := ctime
  12232. if len(advices) > 0 {
  12233. for _, advice := range advices {
  12234. var s models.HisPrescriptionAdviceTemplate
  12235. s.PrescriptionId = prescription.ID
  12236. s.AdviceType = 2
  12237. s.StopState = 2
  12238. s.ExecutionState = 2
  12239. s.Status = 1
  12240. s.UserOrgId = adminInfo.CurrentOrgId
  12241. s.CreatedTime = ctime
  12242. s.UpdatedTime = mtime
  12243. s.PatientId = patient_id
  12244. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12245. if errcode > 0 {
  12246. c.ServeFailJSONWithSGJErrorCode(errcode)
  12247. return
  12248. }
  12249. service.CreateHisPrescriptionAdviceTemplate(&s)
  12250. }
  12251. }
  12252. }
  12253. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12254. projects := items["project"].([]interface{})
  12255. if len(projects) > 0 {
  12256. for _, project := range projects {
  12257. var p models.HisPrescriptionProjectTemplate
  12258. p.PrescriptionId = prescription.ID
  12259. p.Ctime = time.Now().Unix()
  12260. p.Mtime = time.Now().Unix()
  12261. p.PatientId = patient_id
  12262. p.UserOrgId = adminInfo.CurrentOrgId
  12263. p.Status = 1
  12264. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12265. if errcode > 0 {
  12266. c.ServeFailJSONWithSGJErrorCode(errcode)
  12267. return
  12268. }
  12269. service.CreateHisPrescriptionProjectTemplate(&p)
  12270. }
  12271. }
  12272. }
  12273. }
  12274. c.ServeSuccessJSON(map[string]interface{}{
  12275. "msg": "创建成功",
  12276. })
  12277. }
  12278. }
  12279. } else {
  12280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12281. return
  12282. }
  12283. }
  12284. }
  12285. func (c *HisApiController) PreSettle() {
  12286. id, _ := c.GetInt64("id")
  12287. record_time := c.GetString("record_time")
  12288. his_patient_id, _ := c.GetInt64("his_patient_id")
  12289. timeLayout := "2006-01-02"
  12290. loc, _ := time.LoadLocation("Local")
  12291. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12292. diagnosis_id := c.GetString("diagnosis")
  12293. sick_type, _ := c.GetInt64("sick_type")
  12294. reg_type, _ := c.GetInt64("p_type")
  12295. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12296. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12297. if err != nil {
  12298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12299. return
  12300. }
  12301. recordDateTime := theTime.Unix()
  12302. adminUser := c.GetAdminUserInfo()
  12303. var prescriptions []*models.HisPrescription
  12304. var start_time int64
  12305. var end_time int64
  12306. ids_str := c.GetString("ids")
  12307. ids_arr := strings.Split(ids_str, ",")
  12308. fmt.Println(reg_type)
  12309. if settle_accounts_type == 1 { //日结
  12310. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12311. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12312. } else {
  12313. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12314. }
  12315. fmt.Println(prescriptions)
  12316. } else { //月结
  12317. start_time_str := c.GetString("start_time")
  12318. end_time_str := c.GetString("end_time")
  12319. timeLayout := "2006-01-02"
  12320. loc, _ := time.LoadLocation("Local")
  12321. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12322. if err != nil {
  12323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12324. return
  12325. }
  12326. recordStartTime := theStartTime.Unix()
  12327. start_time = recordStartTime
  12328. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12329. if err != nil {
  12330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12331. return
  12332. }
  12333. recordEndTime := theEndTime.Unix()
  12334. end_time = recordEndTime
  12335. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12336. }
  12337. if reg_type == 1111 || reg_type == 1112 {
  12338. reg_type = 11
  12339. }
  12340. timestamp := time.Now().Unix()
  12341. tempTime := time.Unix(timestamp, 0)
  12342. timeFormat := tempTime.Format("20060102150405")
  12343. chrgBchno := rand.Intn(100000) + 10000
  12344. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12345. strconv.FormatInt(his.PatientId, 10)
  12346. var ids []int64
  12347. for _, item := range prescriptions {
  12348. ids = append(ids, item.ID)
  12349. }
  12350. fmt.Println(ids)
  12351. var total float64
  12352. for _, item := range prescriptions {
  12353. fmt.Println(item)
  12354. if item.Type == 1 { //药品
  12355. for _, subItem := range item.HisDoctorAdviceInfo {
  12356. total = total + (subItem.Price * subItem.PrescribingNumber)
  12357. }
  12358. }
  12359. if item.Type == 2 { //项目
  12360. for _, subItem := range item.HisPrescriptionProject {
  12361. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12362. total = total + (subItem.Price * cnt)
  12363. }
  12364. }
  12365. for _, subItem := range item.HisAdditionalCharge {
  12366. total = total + (subItem.Price * float64(subItem.Count))
  12367. }
  12368. }
  12369. allTotal := fmt.Sprintf("%.2f", total)
  12370. totals, _ := strconv.ParseFloat(allTotal, 64)
  12371. order := &models.HisOrder{
  12372. UserOrgId: adminUser.CurrentOrgId,
  12373. HisPatientId: his.ID,
  12374. PatientId: id,
  12375. SettleAccountsDate: recordDateTime,
  12376. Ctime: time.Now().Unix(),
  12377. Mtime: time.Now().Unix(),
  12378. Status: 1,
  12379. OrderStatus: 1,
  12380. MdtrtId: his.Number,
  12381. Number: chrg_bchno,
  12382. MedfeeSumamt: totals,
  12383. SettleEndTime: end_time,
  12384. SettleStartTime: start_time,
  12385. SettleType: settle_accounts_type,
  12386. PsnPartAmt: totals,
  12387. PsnCashPay: totals,
  12388. PType: 2,
  12389. IsPre: 1,
  12390. MedType: strconv.Itoa(int(reg_type)),
  12391. Diagnosis: diagnosis_id,
  12392. }
  12393. err = service.CreateOrder(order)
  12394. if err != nil {
  12395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12396. return
  12397. }
  12398. var customs []*Custom
  12399. for _, item := range prescriptions {
  12400. fmt.Println(item.Type)
  12401. if item.Type == 1 { //药品
  12402. for _, subItem := range item.HisDoctorAdviceInfo {
  12403. cus := &Custom{
  12404. AdviceId: subItem.ID,
  12405. ProjectId: 0,
  12406. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12407. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12408. FeedetlSn: subItem.FeedetlSn,
  12409. Price: fmt.Sprintf("%.2f", subItem.Price),
  12410. MedListCodg: subItem.MedListCodg,
  12411. Type: 1,
  12412. }
  12413. customs = append(customs, cus)
  12414. }
  12415. }
  12416. if item.Type == 2 { //项目
  12417. for _, subItem := range item.HisPrescriptionProject {
  12418. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12419. cus := &Custom{
  12420. AdviceId: 0,
  12421. ProjectId: subItem.ID,
  12422. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12423. Cut: fmt.Sprintf("%.2f", cnt),
  12424. FeedetlSn: subItem.FeedetlSn,
  12425. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12426. MedListCodg: subItem.MedListCodg,
  12427. Type: 2,
  12428. }
  12429. customs = append(customs, cus)
  12430. }
  12431. }
  12432. for _, item := range item.HisAdditionalCharge {
  12433. cus := &Custom{
  12434. ItemId: item.ID,
  12435. AdviceId: 0,
  12436. ProjectId: 0,
  12437. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12438. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12439. FeedetlSn: item.FeedetlSn,
  12440. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12441. MedListCodg: item.XtHisAddtionConfig.Code,
  12442. Type: 3,
  12443. }
  12444. customs = append(customs, cus)
  12445. }
  12446. }
  12447. fmt.Println(customs)
  12448. for _, item := range customs {
  12449. var advice_id int64 = 0
  12450. var project_id int64 = 0
  12451. var item_id int64 = 0
  12452. var types int64 = 0
  12453. if item.Type == 1 {
  12454. advice_id = item.AdviceId
  12455. project_id = 0
  12456. item_id = 0
  12457. } else if item.Type == 2 {
  12458. advice_id = 0
  12459. item_id = 0
  12460. project_id = item.ProjectId
  12461. } else if item.Type == 3 {
  12462. advice_id = 0
  12463. item_id = item.ItemId
  12464. project_id = 0
  12465. }
  12466. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12467. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12468. pric, _ := strconv.ParseFloat(item.Price, 32)
  12469. info := &models.HisOrderInfo{
  12470. OrderNumber: order.Number,
  12471. UploadDate: time.Now().Unix(),
  12472. AdviceId: advice_id,
  12473. DetItemFeeSumamt: detItemFeeSumamt,
  12474. Cnt: cut,
  12475. Pric: pric,
  12476. PatientId: id,
  12477. Status: 1,
  12478. Mtime: time.Now().Unix(),
  12479. Ctime: time.Now().Unix(),
  12480. UserOrgId: adminUser.CurrentOrgId,
  12481. HisPatientId: his.ID,
  12482. OrderId: order.ID,
  12483. ProjectId: project_id,
  12484. Type: types,
  12485. ItemId: item_id,
  12486. }
  12487. service.CreateOrderInfo(info)
  12488. }
  12489. his.SickType = sick_type
  12490. service.UpdataHisPateint(&his)
  12491. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12492. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12493. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12494. if err == nil {
  12495. c.ServeSuccessJSON(map[string]interface{}{
  12496. "msg": "结算成功",
  12497. })
  12498. }
  12499. }
  12500. type CustomOrderInfo struct {
  12501. Name string
  12502. Spec string
  12503. Unit string
  12504. Count float64
  12505. Price float64
  12506. Total float64
  12507. }
  12508. func (c *HisApiController) GetPrivateExpensesInfo() {
  12509. order_id, _ := c.GetInt64("id", 0)
  12510. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12511. order, _ := service.GetHisOrderByID(order_id)
  12512. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12513. if order.ID == 0 {
  12514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12515. return
  12516. }
  12517. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12518. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12519. org_id := c.GetAdminUserInfo().CurrentOrgId
  12520. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12521. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12522. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12523. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12524. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12525. //var orderInfos_four []*models.HisOrderInfoTwo
  12526. //for _, item := range orderInfos_three {
  12527. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12528. // item.HisPrescriptionProject.IsCheckTeam = 1
  12529. // orderInfos_four = append(orderInfos_four, item)
  12530. //
  12531. // }
  12532. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12533. // item.HisPrescriptionProject.IsCheckTeam = 2
  12534. // orderInfos_two = append(orderInfos_two, item)
  12535. // }
  12536. //}
  12537. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12538. //var cus_slice []CustomOrderInfo
  12539. //for _, item := range new_order_info {
  12540. // var cus CustomOrderInfo
  12541. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12542. // cus.Unit = ""
  12543. // cus.Spec = ""
  12544. // var total float64
  12545. // for _, subItem := range orderInfos_four {
  12546. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12547. // total = total + subItem.DetItemFeeSumamt
  12548. // fmt.Println(subItem.DetItemFeeSumamt)
  12549. // }
  12550. // }
  12551. // cus.Count = 1
  12552. // cus.Total = total
  12553. // cus_slice = append(cus_slice, cus)
  12554. //}
  12555. orderInfos = append(orderInfos, orderInfos_two...)
  12556. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12557. //orderInfos = append(orderInfos, orderInfos_three...)
  12558. //}/**/
  12559. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12560. c.ServeSuccessJSON(map[string]interface{}{
  12561. "order": order,
  12562. "order_info": orderInfos,
  12563. "patient": patient,
  12564. "admin_info": adminInfo,
  12565. "his": his,
  12566. "current_admin": role,
  12567. "org_config": miConfig,
  12568. //"new_order_info": cus_slice,
  12569. })
  12570. }
  12571. func (this *HisApiController) ChangeMedType() {
  12572. med_type := this.GetString("med_type")
  12573. old_med_type := this.GetString("old_med_type")
  12574. ids := this.GetString("ids")
  12575. settle_type, _ := this.GetInt64("settle_type")
  12576. start_time := this.GetString("start_time")
  12577. end_time := this.GetString("end_time")
  12578. ids_arr := strings.Split(ids, ",")
  12579. if settle_type == 1 { //日结
  12580. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12581. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12582. prescription.MedType = med_type
  12583. err := service.SaveHisPrescriptionTwo(&prescription)
  12584. if err == nil {
  12585. this.ServeSuccessJSON(map[string]interface{}{
  12586. "msg": "修改成功",
  12587. })
  12588. } else {
  12589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12590. return
  12591. }
  12592. } else if settle_type == 2 {
  12593. timeLayout := "2006-01-02"
  12594. loc, _ := time.LoadLocation("Local")
  12595. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12596. if err != nil {
  12597. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12598. return
  12599. }
  12600. recordStartTime := theStartTime.Unix()
  12601. start_time_timestamp := recordStartTime
  12602. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12603. if err != nil {
  12604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12605. return
  12606. }
  12607. recordEndTime := theEndTime.Unix()
  12608. end_time_timestamp := recordEndTime
  12609. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12610. if updateErr == nil {
  12611. this.ServeSuccessJSON(map[string]interface{}{
  12612. "msg": "修改成功",
  12613. })
  12614. } else {
  12615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12616. return
  12617. }
  12618. }
  12619. }
  12620. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12621. patient_id, _ := c.GetInt64("patient_id")
  12622. his_patient_id, _ := c.GetInt64("his_patient_id")
  12623. record_date := c.GetString("record_date")
  12624. start_time := c.GetString("start_time")
  12625. end_time := c.GetString("end_time")
  12626. order_status, _ := c.GetInt64("type", 0)
  12627. p_type, _ := c.GetInt64("p_type", 0)
  12628. order_id, _ := c.GetInt64("order_id", 0)
  12629. timeLayout := "2006-01-02"
  12630. loc, _ := time.LoadLocation("Local")
  12631. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12632. if err != nil {
  12633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12634. return
  12635. }
  12636. recordDateTime := theTime.Unix()
  12637. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12638. if err != nil {
  12639. }
  12640. startRecordDateTime := startTime.Unix()
  12641. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12642. if err != nil {
  12643. }
  12644. endRecordDateTime := endTime.Unix()
  12645. admin := c.GetAdminUserInfo()
  12646. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12647. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12648. order, _ := service.GetHisOrderByID(order_id)
  12649. var monthPrescriptions []*models.HisPrescription
  12650. if order_status == 1 || order_status == 0 {
  12651. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12652. } else if order_status == 2 {
  12653. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12654. }
  12655. var settle_total float64
  12656. for _, item := range monthPrescriptions {
  12657. if len(item.HisPrescriptionProject) > 0 {
  12658. for _, subItem := range item.HisPrescriptionProject {
  12659. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12660. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12661. settle_total = settle_total + total
  12662. }
  12663. }
  12664. if len(item.HisDoctorAdviceInfo) > 0 {
  12665. for _, subItem := range item.HisDoctorAdviceInfo {
  12666. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12667. settle_total = settle_total + total
  12668. }
  12669. }
  12670. }
  12671. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12672. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12673. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12674. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12675. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12676. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12677. //获取所有科室信息
  12678. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12679. var dia string
  12680. for _, item := range month_p_info {
  12681. if len(dia) == 0 {
  12682. dia = item.Diagnosis
  12683. } else {
  12684. dia = dia + "," + item.Diagnosis
  12685. }
  12686. }
  12687. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12688. dia_arr = removeEmptyStrings(dia_arr)
  12689. c.ServeSuccessJSON(map[string]interface{}{
  12690. "his_info": his_patient_info,
  12691. "xt_info": xt_patient_info,
  12692. "case_history": case_history,
  12693. "info": patientPrescriptionInfo,
  12694. "last_info": lastPatientPrescriptionInfo,
  12695. "month_prescriptions": monthPrescriptions,
  12696. "order": order,
  12697. "doctors": doctors,
  12698. "department": department,
  12699. "settle_total": settle_total,
  12700. "dia_arr": dia_arr,
  12701. })
  12702. return
  12703. }
  12704. func removeEmptyStrings(input []string) []string {
  12705. var output []string
  12706. for _, s := range input {
  12707. if s != "" {
  12708. output = append(output, s)
  12709. }
  12710. }
  12711. return output
  12712. }
  12713. func removeDuplicates(input []string) []string {
  12714. seen := make(map[string]bool)
  12715. output := []string{}
  12716. for _, s := range input {
  12717. if _, exists := seen[s]; !exists {
  12718. seen[s] = true
  12719. output = append(output, s)
  12720. }
  12721. }
  12722. return output
  12723. }
  12724. func (c *HisApiController) GetHisMonthPatientInfo() {
  12725. patient_id, _ := c.GetInt64("patient_id")
  12726. his_patient_id, _ := c.GetInt64("his_patient_id")
  12727. record_date := c.GetString("record_date")
  12728. number := c.GetString("number")
  12729. start_time := c.GetString("start_time")
  12730. end_time := c.GetString("end_time")
  12731. p_type, _ := c.GetInt64("p_type")
  12732. timeLayout := "2006-01-02"
  12733. loc, _ := time.LoadLocation("Local")
  12734. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12735. if err != nil {
  12736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12737. return
  12738. }
  12739. recordDateTime := theTime.Unix()
  12740. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12741. if err != nil {
  12742. }
  12743. startRecordDateTime := startTime.Unix()
  12744. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12745. if err != nil {
  12746. }
  12747. endRecordDateTime := endTime.Unix()
  12748. admin := c.GetAdminUserInfo()
  12749. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12750. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12751. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12752. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12753. var settle_total float64
  12754. for _, item := range monthPrescriptions {
  12755. if len(item.HisPrescriptionProject) > 0 {
  12756. for _, subItem := range item.HisPrescriptionProject {
  12757. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12758. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12759. settle_total = settle_total + total
  12760. }
  12761. }
  12762. if len(item.HisDoctorAdviceInfo) > 0 {
  12763. for _, subItem := range item.HisDoctorAdviceInfo {
  12764. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12765. settle_total = settle_total + total
  12766. }
  12767. }
  12768. }
  12769. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12770. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12771. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12772. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12773. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12774. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12775. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12776. //获取所有科室信息
  12777. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12778. c.ServeSuccessJSON(map[string]interface{}{
  12779. "his_info": his_patient_info,
  12780. "xt_info": xt_patient_info,
  12781. "case_history": case_history,
  12782. "info": patientPrescriptionInfo,
  12783. "month_prescriptions": monthPrescriptions,
  12784. "order": order,
  12785. "doctors": doctors,
  12786. "department": department,
  12787. "count": count,
  12788. "drugStockConfig": drugStockConfig,
  12789. "last_info": lastPatientPrescriptionInfo,
  12790. "settle_total": settle_total,
  12791. })
  12792. return
  12793. }
  12794. func (c *HisApiController) GetAllOrder() {
  12795. org_id := c.GetAdminUserInfo().CurrentOrgId
  12796. orders, _ := service.GetNewHisOrderList(org_id)
  12797. c.ServeSuccessJSON(map[string]interface{}{
  12798. "order": orders,
  12799. })
  12800. return
  12801. }
  12802. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12803. newArr = make([]*models.HisOrderInfoTwo, 0)
  12804. for i := 0; i < len(arr); i++ {
  12805. repeat := false
  12806. for j := i + 1; j < len(arr); j++ {
  12807. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12808. repeat = true
  12809. break
  12810. }
  12811. }
  12812. if !repeat {
  12813. newArr = append(newArr, arr[i])
  12814. }
  12815. }
  12816. return
  12817. }
  12818. // 修改处方退库操作 参数传修改之前的处方数据
  12819. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12820. if advice.ExecutionState == 1 {
  12821. //查询该病人该药品是否有库存记录
  12822. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12823. if errcode == gorm.ErrRecordNotFound {
  12824. } else {
  12825. //退库
  12826. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12827. if advice.PrescribingNumberUnit == drug.MinUnit {
  12828. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12829. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12830. //退库
  12831. warehouseInfo := models.DrugWarehouseInfo{
  12832. StockMinNumber: prescribingNumber,
  12833. }
  12834. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12835. operation_time := time.Now().Unix()
  12836. creater := advice.AdviceDoctor
  12837. ctime := time.Now().Unix()
  12838. timeStr := time.Now().Format("2006-01-02")
  12839. timeArr := strings.Split(timeStr, "-")
  12840. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12841. total = total + 1
  12842. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12843. cancelStock := models.DrugCancelStock{
  12844. OrderNumber: orderNumber,
  12845. OperaTime: operation_time,
  12846. OrgId: advice.UserOrgId,
  12847. Creater: creater,
  12848. Ctime: ctime,
  12849. Status: 1,
  12850. ReturnTime: advice.AdviceDate,
  12851. Dealer: info.Dealer,
  12852. Manufacturer: info.Manufacturer,
  12853. Type: 1,
  12854. }
  12855. service.AddSigleDrugCancelStock(&cancelStock)
  12856. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12857. dealer, _ := service.GetDealerById(info.Dealer)
  12858. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12859. cancelStockInfo := models.DrugCancelStockInfo{
  12860. OrderNumber: cancelInfo.OrderNumber,
  12861. CancelStockId: cancelInfo.ID,
  12862. DrugId: info.DrugId,
  12863. Count: info.Count,
  12864. Status: 1,
  12865. Ctime: ctime,
  12866. OrgId: advice.UserOrgId,
  12867. Type: 1,
  12868. Manufacturer: manufactureName.ManufacturerName,
  12869. Dealer: dealer.DealerName,
  12870. Total: 0,
  12871. RetailPrice: info.RetailPrice,
  12872. RetailTotalPrice: info.RetailTotalPrice,
  12873. Price: info.Price,
  12874. RegisterAccount: "",
  12875. Remark: info.Remark,
  12876. BatchNumber: info.BatchNumber,
  12877. MaxUnit: info.CountUnit,
  12878. ProductDate: info.ProductDate,
  12879. ExpiryDate: info.ExpiryDate,
  12880. BatchNumberId: info.WarehouseInfoId,
  12881. }
  12882. flow := models.DrugFlow{
  12883. WarehousingId: 0,
  12884. DrugId: info.DrugId,
  12885. Number: "",
  12886. BatchNumber: info.BatchNumber,
  12887. Count: info.Count,
  12888. UserOrgId: advice.UserOrgId,
  12889. PatientId: 0,
  12890. SystemTime: ctime,
  12891. ConsumableType: 4,
  12892. IsSys: 0,
  12893. WarehousingOrder: "",
  12894. WarehouseOutId: 0,
  12895. WarehouseOutOrderNumber: "",
  12896. IsEdit: 0,
  12897. CancelStockId: cancelStock.ID,
  12898. CancelOrderNumber: cancelStock.OrderNumber,
  12899. Manufacturer: info.Manufacturer,
  12900. Dealer: info.Dealer,
  12901. Creator: advice.UserOrgId,
  12902. UpdateCreator: 0,
  12903. Status: 1,
  12904. Ctime: time.Now().Unix(),
  12905. Mtime: 0,
  12906. Price: info.Price,
  12907. WarehousingDetailId: 0,
  12908. WarehouseOutDetailId: 0,
  12909. CancelOutDetailId: 0,
  12910. ExpireDate: info.ExpiryDate,
  12911. ProductDate: info.ProductDate,
  12912. MaxUnit: info.CountUnit,
  12913. MinUnit: "",
  12914. }
  12915. service.CreatedCancelStock(cancelStockInfo)
  12916. service.CreateDrugFlowOne(flow)
  12917. } else {
  12918. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12919. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12920. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12921. warehouseInfo := models.DrugWarehouseInfo{
  12922. StockMinNumber: prescribingNumber,
  12923. }
  12924. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12925. }
  12926. operation_time := time.Now().Unix()
  12927. creater := advice.AdviceDoctor
  12928. ctime := time.Now().Unix()
  12929. timeStr := time.Now().Format("2006-01-02")
  12930. timeArr := strings.Split(timeStr, "-")
  12931. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12932. total = total + 1
  12933. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12934. cancelStock := models.DrugCancelStock{
  12935. OrderNumber: orderNumber,
  12936. OperaTime: operation_time,
  12937. OrgId: advice.UserOrgId,
  12938. Creater: creater,
  12939. Ctime: ctime,
  12940. Status: 1,
  12941. ReturnTime: advice.AdviceDate,
  12942. Dealer: info.Dealer,
  12943. Manufacturer: info.Manufacturer,
  12944. Type: 1,
  12945. }
  12946. service.AddSigleDrugCancelStock(&cancelStock)
  12947. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12948. dealer, _ := service.GetDealerById(info.Dealer)
  12949. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12950. cancelStockInfo := models.DrugCancelStockInfo{
  12951. OrderNumber: cancelInfo.OrderNumber,
  12952. CancelStockId: cancelInfo.ID,
  12953. DrugId: info.DrugId,
  12954. Count: info.Count,
  12955. Status: 1,
  12956. Ctime: ctime,
  12957. OrgId: advice.UserOrgId,
  12958. Type: 1,
  12959. Manufacturer: manufactureName.ManufacturerName,
  12960. Dealer: dealer.DealerName,
  12961. Total: 0,
  12962. RetailPrice: info.RetailPrice,
  12963. RetailTotalPrice: info.RetailTotalPrice,
  12964. Price: info.Price,
  12965. RegisterAccount: "",
  12966. Remark: info.Remark,
  12967. BatchNumber: info.BatchNumber,
  12968. MaxUnit: info.CountUnit,
  12969. ProductDate: info.ProductDate,
  12970. ExpiryDate: info.ExpiryDate,
  12971. BatchNumberId: info.WarehouseInfoId,
  12972. }
  12973. flow := models.DrugFlow{
  12974. WarehousingId: 0,
  12975. DrugId: info.DrugId,
  12976. Number: "",
  12977. BatchNumber: info.BatchNumber,
  12978. Count: info.Count,
  12979. UserOrgId: advice.UserOrgId,
  12980. PatientId: 0,
  12981. SystemTime: ctime,
  12982. ConsumableType: 4,
  12983. IsSys: 0,
  12984. WarehousingOrder: "",
  12985. WarehouseOutId: 0,
  12986. WarehouseOutOrderNumber: "",
  12987. IsEdit: 0,
  12988. CancelStockId: cancelStock.ID,
  12989. CancelOrderNumber: cancelStock.OrderNumber,
  12990. Manufacturer: info.Manufacturer,
  12991. Dealer: info.Dealer,
  12992. Creator: advice.AdviceDoctor,
  12993. UpdateCreator: 0,
  12994. Status: 1,
  12995. Ctime: time.Now().Unix(),
  12996. Mtime: 0,
  12997. Price: info.Price,
  12998. WarehousingDetailId: 0,
  12999. WarehouseOutDetailId: 0,
  13000. CancelOutDetailId: 0,
  13001. ExpireDate: info.ExpiryDate,
  13002. ProductDate: info.ProductDate,
  13003. MaxUnit: info.CountUnit,
  13004. MinUnit: "",
  13005. }
  13006. service.CreatedCancelStock(cancelStockInfo)
  13007. service.CreateDrugFlowOne(flow)
  13008. }
  13009. }
  13010. }
  13011. return err
  13012. }
  13013. func (this *HisApiController) DeleteNCDS() {
  13014. id, _ := this.GetInt64("id", 0)
  13015. if id > 0 {
  13016. service.DeletePsnNCDSRecordById(id)
  13017. this.ServeSuccessJSON(map[string]interface{}{
  13018. "msg": "删除成功",
  13019. })
  13020. } else {
  13021. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13022. return
  13023. }
  13024. }
  13025. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13026. id, _ := c.GetInt64("id")
  13027. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13028. c.ServeSuccessJSON(map[string]interface{}{
  13029. "advice": advice,
  13030. })
  13031. return
  13032. }
  13033. func (c *HisApiController) GetHisMonthChargePatientList() {
  13034. record_date := c.GetString("record_date")
  13035. start_time := c.GetString("start_time")
  13036. end_time := c.GetString("end_time")
  13037. timeLayout := "2006-01-02"
  13038. loc, _ := time.LoadLocation("Local")
  13039. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13040. if err != nil {
  13041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13042. return
  13043. }
  13044. if err != nil {
  13045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13046. return
  13047. }
  13048. recordDateTime := theTime.Unix()
  13049. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13050. if err != nil {
  13051. }
  13052. startRecordDateTime := startTime.Unix()
  13053. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13054. if err != nil {
  13055. }
  13056. endRecordDateTime := endTime.Unix()
  13057. adminInfo := c.GetAdminUserInfo()
  13058. var tempMonthChargePatients []*service.MonthChargePatients
  13059. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13060. for _, item := range tempPatients {
  13061. //过滤没有处方的
  13062. if len(item.HisPrescription) == 0 {
  13063. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13064. }
  13065. }
  13066. c.ServeSuccessJSON(map[string]interface{}{
  13067. "list": tempMonthChargePatients,
  13068. })
  13069. }
  13070. // PrescriptionDifference 医嘱数量差值结构体
  13071. type PrescriptionDrugDifference struct {
  13072. DrugID int64 //基础库药品id
  13073. ID int64 //医嘱id
  13074. Difference float64 //差值
  13075. Unit string //单位
  13076. }
  13077. type PrescriptionGoodDifference struct {
  13078. GoodID int64 //基础库项目耗材id
  13079. ID int64 //医嘱id
  13080. Difference int64 //差值
  13081. Unit string //单位
  13082. Type int64 //类型
  13083. }
  13084. type EditCustomData struct {
  13085. adviceList []*models.HisDoctorAdviceInfo
  13086. projectList []*models.HisPrescriptionProject
  13087. }
  13088. type SrcCustomData struct {
  13089. adviceList []*models.HisDoctorAdviceInfo
  13090. projectList []*models.HisPrescriptionProject
  13091. }
  13092. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13093. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13094. differences := make([]*PrescriptionDrugDifference, 0)
  13095. // 创建一个 map 来存储第一个切片中的药品信息
  13096. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13097. for _, advice := range firstPrescription {
  13098. firstMap[advice.DrugId] = advice
  13099. }
  13100. // 遍历第二个切片中的药品信息,并比较数量差值
  13101. for _, advice := range secondPrescription {
  13102. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13103. diff := &PrescriptionDrugDifference{
  13104. DrugID: advice.DrugId,
  13105. ID: firstAdvice.ID,
  13106. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13107. Unit: firstAdvice.PrescribingNumberUnit,
  13108. }
  13109. differences = append(differences, diff)
  13110. }
  13111. }
  13112. return differences
  13113. }
  13114. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13115. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13116. differences := make([]*PrescriptionGoodDifference, 0)
  13117. // 创建一个 map 来存储第一个切片中的耗材信息
  13118. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13119. for _, good := range firstPrescription {
  13120. firstMap[good.ProjectId] = good
  13121. }
  13122. // 遍历第二个切片中的耗材信息,并比较数量差值
  13123. for _, good := range secondPrescription {
  13124. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13125. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13126. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13127. diff := &PrescriptionGoodDifference{
  13128. GoodID: good.ProjectId,
  13129. ID: firstGood.ID,
  13130. Difference: count - firstCount,
  13131. Unit: firstGood.Unit,
  13132. Type: firstGood.Type,
  13133. }
  13134. differences = append(differences, diff)
  13135. }
  13136. }
  13137. return differences
  13138. }
  13139. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13140. var adviceList []*models.HisDoctorAdviceInfo
  13141. var projectList []*models.HisPrescriptionProject
  13142. var advice_ids []int64
  13143. var project_ids []int64
  13144. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13145. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13146. //var tempPrescription *models.HisPrescriptionProjectscription
  13147. if len(prescriptions) > 0 {
  13148. for _, item := range prescriptions {
  13149. items := item.(map[string]interface{})
  13150. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13151. advices := items["advices"].([]interface{})
  13152. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13153. groupNo := int64(0)
  13154. ctime := time.Now().Unix()
  13155. mtime := ctime
  13156. if len(advices) > 0 {
  13157. for _, advice := range advices {
  13158. var s models.HisDoctorAdviceInfo
  13159. s.AdviceType = 2
  13160. s.StopState = 2
  13161. s.ExecutionState = 2
  13162. s.Status = 1
  13163. s.Groupno = groupNo
  13164. s.CreatedTime = ctime
  13165. s.UpdatedTime = mtime
  13166. s.IsSettle = 2
  13167. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13168. //存储切片中
  13169. if s.ID > 0 {
  13170. advice_ids = append(advice_ids, s.ID)
  13171. adviceList = append(adviceList, &s)
  13172. }
  13173. }
  13174. }
  13175. }
  13176. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13177. projects := items["project"].([]interface{})
  13178. if len(projects) > 0 {
  13179. for _, project := range projects {
  13180. var p models.HisPrescriptionProject
  13181. p.Ctime = time.Now().Unix()
  13182. p.Mtime = time.Now().Unix()
  13183. p.Status = 1
  13184. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13185. if p.ID > 0 {
  13186. project_ids = append(project_ids, p.ID)
  13187. projectList = append(projectList, &p)
  13188. }
  13189. }
  13190. }
  13191. }
  13192. }
  13193. }
  13194. }
  13195. editCustomData.projectList = projectList
  13196. editCustomData.adviceList = adviceList
  13197. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13198. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13199. srcCustomData.adviceList = list
  13200. srcCustomData.projectList = list2
  13201. return
  13202. }
  13203. func (c *HisApiController) GetAllGoodInforList() {
  13204. orgId := c.GetAdminUserInfo().CurrentOrgId
  13205. goodList, _ := service.GetAllGoodList(orgId)
  13206. c.ServeSuccessJSON(map[string]interface{}{
  13207. "goodList": goodList,
  13208. })
  13209. return
  13210. }
  13211. func (this *HisApiController) SaveGoodList() {
  13212. project_name := this.GetString("project_name")
  13213. sort, _ := this.GetInt64("sort")
  13214. orgId := this.GetAdminUserInfo().CurrentOrgId
  13215. dataBody := make(map[string]interface{}, 0)
  13216. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13217. if err != nil {
  13218. utils.ErrorLog(err.Error())
  13219. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13220. return
  13221. }
  13222. goodTeam := models.XtGoodTeam{
  13223. ProjectName: project_name,
  13224. Sort: sort,
  13225. UserOrgId: orgId,
  13226. Status: 1,
  13227. Ctime: time.Now().Unix(),
  13228. Mtime: time.Now().Unix(),
  13229. }
  13230. service.CreateGoodTeam(goodTeam)
  13231. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13232. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13233. infos, _ := dataBody["info"].([]interface{})
  13234. if len(infos) > 0 {
  13235. for _, item := range infos {
  13236. items := item.(map[string]interface{})
  13237. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13238. utils.ErrorLog("good_id")
  13239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13240. return
  13241. }
  13242. good_id := int64(items["good_id"].(float64))
  13243. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13244. utils.ErrorLog("number")
  13245. }
  13246. number := int64(items["number"].(float64))
  13247. xtGoodTeamList := models.XtGoodTeamList{
  13248. GoodId: good_id,
  13249. Count: number,
  13250. TeamId: lastGoodTeam.ID,
  13251. UserOrgId: orgId,
  13252. Status: 1,
  13253. Ctime: time.Now().Unix(),
  13254. Mtime: time.Now().Unix(),
  13255. }
  13256. service.CreateGoodList(xtGoodTeamList)
  13257. }
  13258. this.ServeSuccessJSON(map[string]interface{}{
  13259. "lastGoodTeam": lastGoodTeam,
  13260. })
  13261. }
  13262. }
  13263. return
  13264. }
  13265. func (this *HisApiController) GetGoodList() {
  13266. orgId := this.GetAdminUserInfo().CurrentOrgId
  13267. limit, _ := this.GetInt64("limit")
  13268. page, _ := this.GetInt64("page")
  13269. keyword := this.GetString("keyword")
  13270. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13271. this.ServeSuccessJSON(map[string]interface{}{
  13272. "list": list,
  13273. "total": total,
  13274. })
  13275. }
  13276. func (this *HisApiController) GetGoodNameDetail() {
  13277. id, _ := this.GetInt64("id")
  13278. orgId := this.GetAdminUserInfo().CurrentOrgId
  13279. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13280. goodList, _ := service.GetAllGoodList(orgId)
  13281. this.ServeSuccessJSON(map[string]interface{}{
  13282. "goodNameDetail": goodNameDetail,
  13283. "goodList": goodList,
  13284. })
  13285. }
  13286. func (this *HisApiController) UpdateGoodList() {
  13287. project_name := this.GetString("project_name")
  13288. sort, _ := this.GetInt64("sort")
  13289. id, _ := this.GetInt64("id")
  13290. orgId := this.GetAdminUserInfo().CurrentOrgId
  13291. dataBody := make(map[string]interface{}, 0)
  13292. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13293. if err != nil {
  13294. utils.ErrorLog(err.Error())
  13295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13296. return
  13297. }
  13298. goodTeam := models.XtGoodTeam{
  13299. ProjectName: project_name,
  13300. Sort: sort,
  13301. UserOrgId: orgId,
  13302. Status: 1,
  13303. Ctime: time.Now().Unix(),
  13304. Mtime: time.Now().Unix(),
  13305. ID: id,
  13306. }
  13307. service.SaveGoodTeam(goodTeam)
  13308. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13309. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13310. infos, _ := dataBody["info"].([]interface{})
  13311. if len(infos) > 0 {
  13312. for _, item := range infos {
  13313. items := item.(map[string]interface{})
  13314. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13315. utils.ErrorLog("good_id")
  13316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13317. return
  13318. }
  13319. good_id := int64(items["good_id"].(float64))
  13320. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13321. utils.ErrorLog("id")
  13322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13323. return
  13324. }
  13325. id := int64(items["id"].(float64))
  13326. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13327. utils.ErrorLog("number")
  13328. }
  13329. number := int64(items["number"].(float64))
  13330. xtGoodTeamList := models.XtGoodTeamList{
  13331. ID: id,
  13332. GoodId: good_id,
  13333. Count: number,
  13334. TeamId: lastGoodTeam.ID,
  13335. UserOrgId: orgId,
  13336. Status: 1,
  13337. Ctime: time.Now().Unix(),
  13338. Mtime: time.Now().Unix(),
  13339. }
  13340. service.SaveGoodList(xtGoodTeamList)
  13341. }
  13342. this.ServeSuccessJSON(map[string]interface{}{
  13343. "lastGoodTeam": lastGoodTeam,
  13344. })
  13345. }
  13346. }
  13347. return
  13348. }
  13349. func (this *HisApiController) DeleteGoodTeam() {
  13350. id, _ := this.GetInt64("id")
  13351. team, _ := service.DeleteGoodTeam(id)
  13352. this.ServeSuccessJSON(map[string]interface{}{
  13353. "team": team,
  13354. })
  13355. }
  13356. func (this *HisApiController) DeleteGood() {
  13357. id, _ := this.GetInt64("id")
  13358. good, _ := service.DeleteGood(id)
  13359. this.ServeSuccessJSON(map[string]interface{}{
  13360. "good": good,
  13361. })
  13362. }