his_api_controller.go 584KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031
  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 {
  2966. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2967. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2968. var tempPrescription *models.HisPrescription
  2969. if len(prescriptions) > 0 {
  2970. for _, item := range prescriptions {
  2971. // 开始外部循环的事务
  2972. tx := db.Begin()
  2973. // 在函数结束时处理事务回滚
  2974. defer func() {
  2975. if r := recover(); r != nil {
  2976. tx.Rollback()
  2977. }
  2978. }()
  2979. items := item.(map[string]interface{})
  2980. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2981. utils.ErrorLog("id")
  2982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2983. return
  2984. }
  2985. id := int64(items["id"].(float64))
  2986. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2987. tempPrescription = &new_prescription
  2988. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2989. utils.ErrorLog("type")
  2990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2991. return
  2992. }
  2993. types := int64(items["type"].(float64))
  2994. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2995. utils.ErrorLog("med_type")
  2996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2997. return
  2998. }
  2999. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3000. if med_type == "0" {
  3001. med_type = "14"
  3002. }
  3003. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3004. // utils.ErrorLog("diagnoses")
  3005. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3006. // return
  3007. //}
  3008. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3009. diagnoses, _ := items["diagnoses"].(string)
  3010. //if order_status == 0 {
  3011. // order_status = 1
  3012. //}
  3013. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3014. utils.ErrorLog("pre_time")
  3015. }
  3016. preTime, _ := items["pre_time"].(string)
  3017. fmt.Println("preTime", preTime)
  3018. timeLayout := "2006-01-02"
  3019. loc, _ := time.LoadLocation("Local")
  3020. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3021. //result := strings.Split(preTime, " ")
  3022. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3023. if err != nil {
  3024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3025. return
  3026. }
  3027. pTime := theTime2.Unix()
  3028. ctime := time.Now().Unix()
  3029. if tempPrescription.ID == 0 {
  3030. prescription := &models.HisPrescription{
  3031. ID: 0,
  3032. PatientId: patient_id,
  3033. UserOrgId: adminInfo.CurrentOrgId,
  3034. RecordDate: recordDateTime,
  3035. Ctime: ctime,
  3036. Mtime: ctime,
  3037. Type: types,
  3038. Modifier: adminInfo.AdminUser.Id,
  3039. Creator: adminInfo.AdminUser.Id,
  3040. Status: 1,
  3041. Doctor: role.UserName,
  3042. HisPatientId: his_patient_id,
  3043. OrderStatus: 1,
  3044. BatchNumber: "",
  3045. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3046. PreTime: pTime,
  3047. PType: p_type,
  3048. MedType: med_type,
  3049. Diagnose: diagnoses,
  3050. }
  3051. tempPrescription = prescription
  3052. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3053. redis := service.RedisClient()
  3054. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3055. redis.Set(key, "", time.Second)
  3056. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3057. redis.Set(keyOne, "", time.Second)
  3058. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3059. redis.Set(keySeven, "", time.Second)
  3060. defer redis.Close()
  3061. } else {
  3062. tempPrescription.ID = id
  3063. tempPrescription.Type = types
  3064. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3065. tempPrescription.Mtime = time.Now().Unix()
  3066. tempPrescription.Doctor = role.UserName
  3067. //tempPrescription.OrderStatus = order_status
  3068. tempPrescription.PreTime = pTime
  3069. tempPrescription.MedType = med_type
  3070. tempPrescription.Diagnose = diagnoses
  3071. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3072. redis := service.RedisClient()
  3073. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3074. redis.Set(key, "", time.Second)
  3075. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3076. redis.Set(keyOne, "", time.Second)
  3077. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3078. redis.Set(keySeven, "", time.Second)
  3079. defer redis.Close()
  3080. }
  3081. //service.SaveHisPrescription(prescription)
  3082. //更改患者挂号状态
  3083. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3084. fmt.Println("更改失败", err2)
  3085. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3086. advices := items["advices"].([]interface{})
  3087. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3088. groupNo := int64(0)
  3089. if len(advices) > 0 {
  3090. for _, advice := range advices {
  3091. tx := db.Begin()
  3092. // 在函数结束时处理事务回滚
  3093. defer func() {
  3094. if r := recover(); r != nil {
  3095. tx.Rollback()
  3096. }
  3097. }()
  3098. var s models.HisDoctorAdviceInfo
  3099. s.PrescriptionId = tempPrescription.ID
  3100. s.AdviceType = 2
  3101. s.AdviceDoctor = doctor_id
  3102. s.StopState = 2
  3103. s.ExecutionState = 2
  3104. s.AdviceDate = theTime3.Unix()
  3105. s.Status = 1
  3106. s.UserOrgId = adminInfo.CurrentOrgId
  3107. s.RecordDate = theTime3.Unix()
  3108. s.StartTime = tempPrescription.PreTime
  3109. s.Groupno = groupNo
  3110. s.PatientId = patient_id
  3111. s.HisPatientId = his_patient_id
  3112. s.StartTime = pTime
  3113. s.IsSettle = 2
  3114. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3115. if errcode > 0 {
  3116. c.ServeFailJSONWithSGJErrorCode(errcode)
  3117. return
  3118. }
  3119. s.StartTime = pTime
  3120. var total_count int64 //处方总库存
  3121. //查询改药品信息
  3122. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3123. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3124. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3125. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3126. total_count += prescribingNumberSeven * medical.MinNumber
  3127. }
  3128. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3129. total_count += prescribingNumberSeven
  3130. }
  3131. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3132. total_count += prescribingNumberSeven
  3133. }
  3134. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3135. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3136. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3137. if s.Price != lastWarehouse.RetailPrice {
  3138. s.Price = lastWarehouse.RetailPrice
  3139. }
  3140. if s.Price == 0 {
  3141. if lastWarehouse.ID == 0 {
  3142. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3143. s.Price = lastWarehouseTwo.RetailPrice
  3144. }
  3145. }
  3146. }
  3147. //查询保存处方出库开关是否打开
  3148. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3149. if s.PatientId != 30038 {
  3150. if drugOutConfig.IsOpen == 1 {
  3151. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3152. // 查询该药品最后一次出库记录
  3153. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3154. var is_user_total int64
  3155. var no_user_total int64
  3156. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3157. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3158. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3159. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3160. }
  3161. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3162. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3163. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3164. no_user_total += prescribingNumberSevenTy
  3165. }
  3166. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3167. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3168. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3169. no_user_total += prescribingNumberSevenTy
  3170. }
  3171. if len(druginfo) > 0 {
  3172. for _, it := range druginfo {
  3173. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3174. it.Count = it.Count * drug.MinNumber
  3175. is_user_total += it.Count
  3176. }
  3177. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3178. is_user_total += it.Count
  3179. }
  3180. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3181. is_user_total += it.Count
  3182. }
  3183. }
  3184. }
  3185. //fmt.Println("药品名称----------------------", drug.DrugName)
  3186. //fmt.Println("药品名称----------------------", drug.IsUse)
  3187. //fmt.Println("is_user_total-------------------------", is_user_total)
  3188. //fmt.Println("no_user_total-------------------------", no_user_total)
  3189. if is_user_total != no_user_total {
  3190. //出库
  3191. if drug.IsUse == 2 {
  3192. creater := adminInfo.AdminUser.Id
  3193. newadviceInfo := &models.HisDoctorAdviceInfo{
  3194. ID: s.ID,
  3195. UserOrgId: s.UserOrgId,
  3196. PatientId: s.PatientId,
  3197. HisPatientId: s.HisPatientId,
  3198. AdviceType: s.AdviceType,
  3199. AdviceDate: s.AdviceDate,
  3200. StartTime: s.StartTime,
  3201. AdviceName: s.AdviceName,
  3202. AdviceDesc: s.AdviceDesc,
  3203. ReminderDate: s.ReminderDate,
  3204. SingleDose: s.SingleDose,
  3205. SingleDoseUnit: s.SingleDoseUnit,
  3206. PrescribingNumber: s.PrescribingNumber,
  3207. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3208. DeliveryWay: s.DeliveryWay,
  3209. ExecutionFrequency: s.ExecutionFrequency,
  3210. AdviceDoctor: s.AdviceDoctor,
  3211. Status: s.Status,
  3212. CreatedTime: s.CreatedTime,
  3213. UpdatedTime: s.UpdatedTime,
  3214. AdviceAffirm: s.AdviceAffirm,
  3215. Remark: s.Remark,
  3216. StopTime: s.StopTime,
  3217. StopReason: s.StopReason,
  3218. StopDoctor: s.StopDoctor,
  3219. StopState: s.StopState,
  3220. ParentId: s.ParentId,
  3221. ExecutionTime: s.ExecutionTime,
  3222. ExecutionStaff: s.ExecutionStaff,
  3223. ExecutionState: s.ExecutionState,
  3224. Checker: s.Checker,
  3225. RecordDate: s.RecordDate,
  3226. DialysisOrderId: s.DialysisOrderId,
  3227. CheckTime: s.CheckTime,
  3228. CheckState: s.CheckState,
  3229. DrugSpec: s.DrugSpec,
  3230. DrugSpecUnit: s.DrugSpecUnit,
  3231. Groupno: s.Groupno,
  3232. RemindType: s.RemindType,
  3233. FrequencyType: s.FrequencyType,
  3234. DayCount: s.DayCount,
  3235. WeekDay: s.WeekDay,
  3236. TemplateId: s.TemplateId,
  3237. Modifier: s.Modifier,
  3238. DrugId: s.DrugId,
  3239. Price: s.Price,
  3240. PrescriptionId: s.PrescriptionId,
  3241. MedListCodg: s.MedListCodg,
  3242. FeedetlSn: s.FeedetlSn,
  3243. Day: s.DayCount,
  3244. ChildDoctorAdvice: nil,
  3245. Drug: models.Drug{},
  3246. Diagnosis: s.Diagnosis,
  3247. Way: s.Way,
  3248. HospApprFlag: s.HospApprFlag,
  3249. LmtUsedFlag: s.LmtUsedFlag,
  3250. HisOrderInfo: models.HisOrderInfo{},
  3251. IsMedicine: s.IsMedicine,
  3252. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3253. Child: nil,
  3254. IsSettle: s.IsSettle,
  3255. IsMobile: s.IsMobile,
  3256. IsSelfDrug: s.IsSelfDrug,
  3257. DrugWayCount: s.DrugWayCount,
  3258. }
  3259. var history_count int64
  3260. var local_count int64
  3261. //查找已经开过的医嘱信息
  3262. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3263. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3264. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3265. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3266. local_count += prescribingNumberSevenTy * drug.MinNumber
  3267. }
  3268. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3269. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3270. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3271. local_count += prescribingNumberSevenTy
  3272. }
  3273. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3274. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3275. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3276. local_count += prescribingNumberSevenTy
  3277. }
  3278. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3279. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3280. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3281. history_count += prescribingNumberSevenTy * drug.MinNumber
  3282. }
  3283. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3284. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3285. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3286. history_count += prescribingNumberSevenTy
  3287. }
  3288. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3289. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3290. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3291. history_count += prescribingNumberSevenTy
  3292. }
  3293. //如果当前出库数量大于历史出库数量则需要出库
  3294. if local_count > history_count {
  3295. //按最小单位出库
  3296. var cha_count = local_count - history_count
  3297. newadviceInfo.PrescribingNumber = float64(cha_count)
  3298. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3299. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3300. }
  3301. //如果当前出库数量小于历史出库数量则需要退库
  3302. if local_count < history_count {
  3303. var cha_count = history_count - local_count
  3304. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3305. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3306. }
  3307. if local_count == history_count {
  3308. if is_user_total == 0 {
  3309. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3310. }
  3311. }
  3312. }
  3313. //更新字典里面的库存
  3314. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3315. var sum_count int64
  3316. for _, its := range stockInfo {
  3317. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3318. if its.MaxUnit == baseDrug.MaxUnit {
  3319. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3320. }
  3321. sum_count += its.StockMaxNumber + its.StockMinNumber
  3322. }
  3323. //更新基础库存
  3324. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3325. //剩余库存
  3326. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3327. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3328. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3329. //创建医嘱
  3330. service.CreateHisDoctorAdviceOne(&s, tx)
  3331. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3332. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3333. if len(outInfoTwo) > 0 {
  3334. for _, item := range outInfoTwo {
  3335. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3336. }
  3337. }
  3338. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3339. if len(drugAutoDetail) > 0 {
  3340. for _, item := range drugAutoDetail {
  3341. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3342. }
  3343. }
  3344. }
  3345. }
  3346. }
  3347. //记录日志
  3348. byterequest, _ := json.Marshal(s)
  3349. adviceLog := models.XtDoctorAdviceLog{
  3350. UserOrgId: s.UserOrgId,
  3351. PatientId: s.PatientId,
  3352. AdminUserId: adminInfo.AdminUser.Id,
  3353. Module: 1,
  3354. ErrLog: string(byterequest),
  3355. Status: 1,
  3356. Ctime: time.Now().Unix(),
  3357. Mtime: 0,
  3358. Source: "电脑端新建his医嘱",
  3359. RecordDate: s.AdviceDate,
  3360. }
  3361. service.CreateDoctorAdviceLog(adviceLog)
  3362. //存储切片中
  3363. adviceList = append(adviceList, s)
  3364. redis := service.RedisClient()
  3365. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3366. redis.Set(key, "", time.Second)
  3367. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3368. redis.Set(keyOne, "", time.Second)
  3369. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3370. redis.Set(keySeven, "", time.Second)
  3371. var randNum int
  3372. randNum = rand.Intn(10000) + 1000
  3373. timestamp := time.Now().Unix()
  3374. tempTime := time.Unix(timestamp, 0)
  3375. timeFormat := tempTime.Format("20060102150405")
  3376. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3377. if s.UserOrgId != 10206 {
  3378. if s.ID == 0 {
  3379. //查询改药品是否已经停用
  3380. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3381. if base.ID > 0 {
  3382. tx.Rollback()
  3383. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3384. return
  3385. }
  3386. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3387. if drugMedical.SumCount == 0 {
  3388. tx.Rollback()
  3389. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3390. return
  3391. }
  3392. }
  3393. }
  3394. //赤峰
  3395. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3396. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3397. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3398. if info.RetailPrice > 0 {
  3399. if s.DeliveryWay == "口服" {
  3400. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3401. s.Price = drug.RetailPrice
  3402. }
  3403. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3404. s.Price = info.RetailPrice
  3405. }
  3406. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3407. s.Price = info.RetailPrice
  3408. }
  3409. }
  3410. }
  3411. }
  3412. service.CreateHisDoctorAdviceOne(&s, tx)
  3413. tx.Commit()
  3414. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3415. redis.Set(keySix, "", time.Second)
  3416. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3417. redis.Set(keyFive, "", time.Second)
  3418. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3419. redis.Set(keyEight, "", time.Second)
  3420. defer redis.Close()
  3421. }
  3422. }
  3423. }
  3424. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3425. projects := items["project"].([]interface{})
  3426. if len(projects) > 0 {
  3427. for _, project := range projects {
  3428. tx := db.Begin()
  3429. // 在函数结束时处理事务回滚
  3430. defer func() {
  3431. if r := recover(); r != nil {
  3432. tx.Rollback()
  3433. }
  3434. }()
  3435. var p models.HisPrescriptionProject
  3436. p.PrescriptionId = tempPrescription.ID
  3437. p.PatientId = patient_id
  3438. p.RecordDate = theTime3.Unix()
  3439. p.Doctor = doctor_id
  3440. p.UserOrgId = adminInfo.CurrentOrgId
  3441. p.HisPatientId = his_patient_id
  3442. p.Status = 1
  3443. p.StartTime = pTime
  3444. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3445. if errcode > 0 {
  3446. tx.Rollback()
  3447. c.ServeFailJSONWithSGJErrorCode(errcode)
  3448. return
  3449. }
  3450. if p.ID == 0 {
  3451. p.IsOut = 2
  3452. }
  3453. if p.ID > 0 {
  3454. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3455. p.IsOut = projectDetail.IsOut
  3456. }
  3457. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3458. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3459. if p.Type == 3 {
  3460. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3461. if p.Price != lastWarehouse.PackingPrice {
  3462. p.Price = lastWarehouse.PackingPrice
  3463. }
  3464. if p.Price == 0 {
  3465. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3466. p.Price = lastWarehouseTwo.PackingPrice
  3467. }
  3468. if p.Unit == "" {
  3469. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3470. p.Unit = goodInfoOne.PackingUnit
  3471. }
  3472. }
  3473. }
  3474. if adminInfo.CurrentOrgId != 10206 {
  3475. if p.Type == 3 {
  3476. if p.ID == 0 {
  3477. //查询该耗材是否停用
  3478. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3479. //表示该耗材已经停用,不能保存
  3480. if goodInfoSeven.ID == 0 {
  3481. tx.Rollback()
  3482. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3483. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3484. return
  3485. }
  3486. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3487. if goodInfoOne.SumCount == 0 {
  3488. tx.Rollback()
  3489. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3490. return
  3491. }
  3492. }
  3493. }
  3494. }
  3495. //查询保存耗材出库开关是否打开
  3496. if p.PatientId != 30038 {
  3497. //用机构ID区分
  3498. if adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10164 {
  3499. if goodOutConfig.IsOpen == 1 {
  3500. //耗材出库
  3501. if p.Type == 3 {
  3502. //对比当前数据和历史出库数据
  3503. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3504. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3505. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3506. //如果当前处方数量大于历史数据,则需要出库
  3507. if nowCount > historyCount {
  3508. var cha_count int64
  3509. cha_count = nowCount - historyCount
  3510. timeStr := time.Now().Format("2006-01-02")
  3511. timeArr := strings.Split(timeStr, "-")
  3512. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3513. total = total + 1
  3514. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3515. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3516. number = number + total
  3517. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3518. operation_time := time.Now().Unix()
  3519. creater := c.GetAdminUserInfo().AdminUser.Id
  3520. recordDateStr := time.Now().Format("2006-01-02")
  3521. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3522. nowtime := recordDate.Unix()
  3523. warehouseOut := models.WarehouseOut{
  3524. WarehouseOutOrderNumber: warehousing_out_order,
  3525. OperationTime: operation_time,
  3526. OrgId: adminInfo.CurrentOrgId,
  3527. Creater: creater,
  3528. Ctime: time.Now().Unix(),
  3529. Status: 1,
  3530. WarehouseOutTime: nowtime,
  3531. Type: 1,
  3532. StorehouseId: storeConfig.StorehouseOutInfo,
  3533. IsCheck: 1,
  3534. IsSys: 1,
  3535. }
  3536. //查询是否生成出库单
  3537. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3538. if out.ID == 0 {
  3539. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3540. }
  3541. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3542. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3543. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3544. dialyPrepareOne := models.DialysisBeforePrepare{
  3545. GoodTypeId: goodObj.GoodTypeId,
  3546. GoodId: p.ProjectId,
  3547. PatientId: p.PatientId,
  3548. RecordDate: p.RecordDate,
  3549. UserOrgId: adminInfo.CurrentOrgId,
  3550. Count: cha_count,
  3551. Ctime: time.Now().Unix(),
  3552. Creater: creater,
  3553. Status: 1,
  3554. StorehouseId: houseConfig.StorehouseOutInfo,
  3555. ProjectId: p.ID,
  3556. }
  3557. //出库
  3558. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3559. }
  3560. //如果当前处方数量小于历史数据,怎需要退库
  3561. if nowCount < historyCount {
  3562. var cha_count int64
  3563. cha_count = historyCount - nowCount
  3564. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3565. creater := c.GetAdminUserInfo().AdminUser.Id
  3566. newPrescriptionProject := &models.HisPrescriptionProject{
  3567. ID: p.ID,
  3568. ProjectId: p.ProjectId,
  3569. Price: p.Price,
  3570. UserOrgId: p.UserOrgId,
  3571. Status: 1,
  3572. Ctime: time.Now().Unix(),
  3573. Mtime: time.Now().Unix(),
  3574. PatientId: p.PatientId,
  3575. HisPatientId: p.HisPatientId,
  3576. RecordDate: p.RecordDate,
  3577. PrescriptionId: p.PrescriptionId,
  3578. Count: p.Count,
  3579. FeedetlSn: p.FeedetlSn,
  3580. MedListCodg: p.MedListCodg,
  3581. SingleDose: p.SingleDose,
  3582. DeliveryWay: p.DeliveryWay,
  3583. ExecutionFrequency: p.ExecutionFrequency,
  3584. Day: p.Day,
  3585. HisProject: models.HisProject{},
  3586. GoodInfo: models.GoodInfo{},
  3587. Remark: p.Remark,
  3588. Unit: p.Unit,
  3589. Type: p.Type,
  3590. Doctor: p.Doctor,
  3591. ExecutionTime: p.ExecutionTime,
  3592. ExecutionStaff: p.ExecutionStaff,
  3593. ExecutionState: p.ExecutionState,
  3594. CheckTime: p.CheckTime,
  3595. CheckState: p.CheckState,
  3596. Checker: p.Checker,
  3597. StartTime: p.StartTime,
  3598. TeamId: p.TeamId,
  3599. XtHisProjectTeam: models.XtHisProjectTeam{},
  3600. FrequencyType: p.FrequencyType,
  3601. DayCount: p.DayCount,
  3602. WeekDay: p.WeekDay,
  3603. IsCheckTeam: p.IsCheckTeam,
  3604. HisOrderInfo: models.HisOrderInfo{},
  3605. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3606. IsOut: p.IsOut,
  3607. YbSyncStatus: p.YbSyncStatus,
  3608. }
  3609. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3610. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3611. }
  3612. if nowCount == historyCount {
  3613. if historyCount == 0 {
  3614. recordDateStr := time.Now().Format("2006-01-02")
  3615. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3616. nowtime := recordDate.Unix()
  3617. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3618. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3619. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3620. creater := c.GetAdminUserInfo().AdminUser.Id
  3621. dialyPrepareOne := models.DialysisBeforePrepare{
  3622. GoodTypeId: goodObj.GoodTypeId,
  3623. GoodId: p.ProjectId,
  3624. PatientId: p.PatientId,
  3625. RecordDate: p.RecordDate,
  3626. UserOrgId: adminInfo.CurrentOrgId,
  3627. Count: nowCount,
  3628. Ctime: time.Now().Unix(),
  3629. Creater: creater,
  3630. Status: 1,
  3631. StorehouseId: houseConfig.StorehouseOutInfo,
  3632. ProjectId: p.ID,
  3633. }
  3634. //出库
  3635. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3636. }
  3637. }
  3638. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3639. //查询历史出库数据
  3640. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3641. var out_count_five int64
  3642. for _, item := range flowGood {
  3643. out_count_five += item.Count
  3644. }
  3645. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3646. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3647. if out_count_five != parseIntCount {
  3648. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3649. detail := models.AutomaticReduceDetail{
  3650. WarehouseOutId: 0,
  3651. WarehouseOutOrderNumber: "",
  3652. PatientId: p.PatientId,
  3653. Ctime: time.Now().Unix(),
  3654. Mtime: 0,
  3655. Status: 1,
  3656. RecordTime: p.RecordDate,
  3657. OrgId: p.UserOrgId,
  3658. GoodId: p.ProjectId,
  3659. GoodTypeId: 0,
  3660. Count: parseIntCount,
  3661. Type: 0,
  3662. ProjectId: lastHisProject.ID,
  3663. StorehouseId: 0,
  3664. }
  3665. service.CreateNewAutoDetail(detail, tx)
  3666. }
  3667. // //查询耗材最后一次出库记录
  3668. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3669. // //查询默认出库仓库库存
  3670. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3671. // if len(wareOut) > 0 {
  3672. //
  3673. // for _, it := range wareOut {
  3674. // //回退库存
  3675. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3676. //
  3677. // //删除出库记录
  3678. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3679. //
  3680. // }
  3681. // }
  3682. //
  3683. // timeStr := time.Now().Format("2006-01-02")
  3684. // timeArr := strings.Split(timeStr, "-")
  3685. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3686. //
  3687. // total = total + 1
  3688. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3689. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3690. // number = number + total
  3691. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3692. //
  3693. // operation_time := time.Now().Unix()
  3694. // creater := c.GetAdminUserInfo().AdminUser.Id
  3695. //
  3696. // recordDateStr := time.Now().Format("2006-01-02")
  3697. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3698. // nowtime := recordDate.Unix()
  3699. // warehouseOut := models.WarehouseOut{
  3700. // WarehouseOutOrderNumber: warehousing_out_order,
  3701. // OperationTime: operation_time,
  3702. // OrgId: adminInfo.CurrentOrgId,
  3703. // Creater: creater,
  3704. // Ctime: time.Now().Unix(),
  3705. // Status: 1,
  3706. // WarehouseOutTime: nowtime,
  3707. // Type: 1,
  3708. // StorehouseId: storeConfig.StorehouseOutInfo,
  3709. // IsCheck: 1,
  3710. // IsSys: 1,
  3711. // }
  3712. // //查询是否生成出库单
  3713. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3714. // if out.ID == 0 {
  3715. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3716. // }
  3717. //
  3718. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3719. //
  3720. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3721. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3722. //
  3723. // dialyPrepareOne := models.DialysisBeforePrepare{
  3724. // GoodTypeId: goodObj.GoodTypeId,
  3725. // GoodId: p.ProjectId,
  3726. // PatientId: p.PatientId,
  3727. // RecordDate: p.RecordDate,
  3728. // UserOrgId: adminInfo.CurrentOrgId,
  3729. // Count: parseIntCount,
  3730. // Ctime: time.Now().Unix(),
  3731. // Creater: creater,
  3732. // Status: 1,
  3733. // StorehouseId: houseConfig.StorehouseOutInfo,
  3734. // ProjectId: lastHisProject.ID,
  3735. // }
  3736. // //判断是否是零用耗材(非零用)
  3737. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3738. //
  3739. // //查询历史出库数据
  3740. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3741. // var out_count int64
  3742. // for _, item := range flowGood {
  3743. // out_count += item.Count
  3744. // }
  3745. // //如果历史数和当前数据不想等才进行退库出库
  3746. // if out_count != parseIntCount {
  3747. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3748. //
  3749. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3750. // detail := models.AutomaticReduceDetail{
  3751. // WarehouseOutId: 0,
  3752. // WarehouseOutOrderNumber: "",
  3753. // PatientId: p.PatientId,
  3754. // Ctime: time.Now().Unix(),
  3755. // Mtime: 0,
  3756. // Status: 1,
  3757. // RecordTime: p.RecordDate,
  3758. // OrgId: p.UserOrgId,
  3759. // GoodId: p.ProjectId,
  3760. // GoodTypeId: 0,
  3761. // Count: parseIntCount,
  3762. // Type: 0,
  3763. // ProjectId: lastHisProject.ID,
  3764. // StorehouseId: 0,
  3765. // }
  3766. //
  3767. // service.CreateNewAutoDetail(detail, tx)
  3768. //
  3769. // //查询剩余库存
  3770. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3771. // var sum_count int64
  3772. // for _, item := range goodList {
  3773. // sum_count += item.StockCount
  3774. // }
  3775. //
  3776. // //更新剩余库存
  3777. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3778. //
  3779. // //耗材
  3780. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3781. //
  3782. // }
  3783. // //判断是否是零用耗材(零用但是是出库耗材)
  3784. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3785. //
  3786. // //查询历史出库数据
  3787. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3788. // var out_count int64
  3789. // for _, item := range flowGood {
  3790. // out_count += item.Count
  3791. // }
  3792. // //如果历史数和当前数据不想等才进行退库出库
  3793. // if out_count != parseIntCount {
  3794. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3795. //
  3796. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3797. // detail := models.AutomaticReduceDetail{
  3798. // WarehouseOutId: 0,
  3799. // WarehouseOutOrderNumber: "",
  3800. // PatientId: p.PatientId,
  3801. // Ctime: time.Now().Unix(),
  3802. // Mtime: 0,
  3803. // Status: 1,
  3804. // RecordTime: p.RecordDate,
  3805. // OrgId: p.UserOrgId,
  3806. // GoodId: p.ProjectId,
  3807. // GoodTypeId: 0,
  3808. // Count: parseIntCount,
  3809. // Type: 0,
  3810. // ProjectId: p.ID,
  3811. // StorehouseId: 0,
  3812. // }
  3813. //
  3814. // service.CreateNewAutoDetail(detail, tx)
  3815. //
  3816. // //查询剩余库存
  3817. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3818. // var sum_count int64
  3819. // for _, item := range goodList {
  3820. // sum_count += item.StockCount
  3821. // }
  3822. //
  3823. // //更新剩余库存
  3824. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3825. //
  3826. // //耗材
  3827. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3828. // }
  3829. //
  3830. // }
  3831. //
  3832. // }
  3833. //
  3834. //}
  3835. //记录日志
  3836. byterequest, _ := json.Marshal(p)
  3837. adviceLog := models.XtDoctorAdviceLog{
  3838. UserOrgId: p.UserOrgId,
  3839. PatientId: p.PatientId,
  3840. AdminUserId: adminInfo.AdminUser.Id,
  3841. Module: 1,
  3842. ErrLog: string(byterequest),
  3843. Status: 1,
  3844. Ctime: time.Now().Unix(),
  3845. Mtime: 0,
  3846. Source: "电脑端新建his项目",
  3847. RecordDate: p.RecordDate,
  3848. }
  3849. service.CreateDoctorAdviceLog(adviceLog)
  3850. projectList = append(projectList, p)
  3851. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3852. //新增或者编辑项目,修改对应的标签数据
  3853. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3854. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3855. var label models.HisLabelPrintInfo
  3856. project, _ := service.GetProjectDetail(p.ProjectId)
  3857. if project.CostClassify == 3 { //类别为检验检查
  3858. if p.TeamId > 0 { //检验检查组套
  3859. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3860. if tempLabel.ID == 0 {
  3861. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3862. label.Number = tempPrescription.PrescriptionNumber
  3863. label.ProjectId = project.ID
  3864. label.Status = 1
  3865. label.IsPrint = 2
  3866. label.DoctorId = info.DoctorId
  3867. label.UserOrgId = p.UserOrgId
  3868. label.PatientId = patient_id
  3869. label.RecordDate = recordDateTime
  3870. label.Ctime = time.Now().Unix()
  3871. label.Mtime = time.Now().Unix()
  3872. label.ItemId = p.TeamId
  3873. label.FeedetlSn = p.FeedetlSn
  3874. label.PProjectId = p.ID
  3875. label.ProjectName = team.ProjectTeam
  3876. label.PatientName = patient.Name
  3877. service.CreateNewHisLabelRecord(&label, tx)
  3878. }
  3879. } else { //单条检验检查项目
  3880. label.Number = tempPrescription.PrescriptionNumber
  3881. label.ProjectId = project.ID
  3882. label.Status = 1
  3883. label.DoctorId = info.DoctorId
  3884. label.UserOrgId = p.UserOrgId
  3885. label.PatientId = patient_id
  3886. label.RecordDate = recordDateTime
  3887. label.IsPrint = 2
  3888. label.Ctime = time.Now().Unix()
  3889. label.Mtime = time.Now().Unix()
  3890. label.FeedetlSn = p.FeedetlSn
  3891. label.PProjectId = p.ID
  3892. label.ItemId = p.TeamId
  3893. label.ProjectName = project.ProjectName
  3894. label.PatientName = patient.Name
  3895. service.CreateNewHisLabelRecord(&label, tx)
  3896. }
  3897. }
  3898. }
  3899. }
  3900. }
  3901. }
  3902. }
  3903. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  3904. //耗材出库
  3905. if p.Type == 3 {
  3906. //对比当前数据和历史出库数据
  3907. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3908. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3909. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3910. //如果当前处方数量大于历史数据,则需要出库
  3911. if nowCount > historyCount {
  3912. var cha_count int64
  3913. cha_count = nowCount - historyCount
  3914. timeStr := time.Now().Format("2006-01-02")
  3915. timeArr := strings.Split(timeStr, "-")
  3916. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3917. total = total + 1
  3918. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3919. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3920. number = number + total
  3921. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3922. operation_time := time.Now().Unix()
  3923. creater := c.GetAdminUserInfo().AdminUser.Id
  3924. recordDateStr := time.Now().Format("2006-01-02")
  3925. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3926. nowtime := recordDate.Unix()
  3927. warehouseOut := models.WarehouseOut{
  3928. WarehouseOutOrderNumber: warehousing_out_order,
  3929. OperationTime: operation_time,
  3930. OrgId: adminInfo.CurrentOrgId,
  3931. Creater: creater,
  3932. Ctime: time.Now().Unix(),
  3933. Status: 1,
  3934. WarehouseOutTime: nowtime,
  3935. Type: 1,
  3936. StorehouseId: storeConfig.StorehouseOutInfo,
  3937. IsCheck: 1,
  3938. IsSys: 1,
  3939. }
  3940. //查询是否生成出库单
  3941. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3942. if out.ID == 0 {
  3943. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3944. }
  3945. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3946. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3947. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3948. dialyPrepareOne := models.DialysisBeforePrepare{
  3949. GoodTypeId: goodObj.GoodTypeId,
  3950. GoodId: p.ProjectId,
  3951. PatientId: p.PatientId,
  3952. RecordDate: p.RecordDate,
  3953. UserOrgId: adminInfo.CurrentOrgId,
  3954. Count: cha_count,
  3955. Ctime: time.Now().Unix(),
  3956. Creater: creater,
  3957. Status: 1,
  3958. StorehouseId: houseConfig.StorehouseOutInfo,
  3959. ProjectId: p.ID,
  3960. }
  3961. //出库
  3962. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3963. }
  3964. //如果当前处方数量小于历史数据,怎需要退库
  3965. if nowCount < historyCount {
  3966. var cha_count int64
  3967. cha_count = historyCount - nowCount
  3968. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3969. creater := c.GetAdminUserInfo().AdminUser.Id
  3970. newPrescriptionProject := &models.HisPrescriptionProject{
  3971. ID: p.ID,
  3972. ProjectId: p.ProjectId,
  3973. Price: p.Price,
  3974. UserOrgId: p.UserOrgId,
  3975. Status: 1,
  3976. Ctime: time.Now().Unix(),
  3977. Mtime: time.Now().Unix(),
  3978. PatientId: p.PatientId,
  3979. HisPatientId: p.HisPatientId,
  3980. RecordDate: p.RecordDate,
  3981. PrescriptionId: p.PrescriptionId,
  3982. Count: p.Count,
  3983. FeedetlSn: p.FeedetlSn,
  3984. MedListCodg: p.MedListCodg,
  3985. SingleDose: p.SingleDose,
  3986. DeliveryWay: p.DeliveryWay,
  3987. ExecutionFrequency: p.ExecutionFrequency,
  3988. Day: p.Day,
  3989. HisProject: models.HisProject{},
  3990. GoodInfo: models.GoodInfo{},
  3991. Remark: p.Remark,
  3992. Unit: p.Unit,
  3993. Type: p.Type,
  3994. Doctor: p.Doctor,
  3995. ExecutionTime: p.ExecutionTime,
  3996. ExecutionStaff: p.ExecutionStaff,
  3997. ExecutionState: p.ExecutionState,
  3998. CheckTime: p.CheckTime,
  3999. CheckState: p.CheckState,
  4000. Checker: p.Checker,
  4001. StartTime: p.StartTime,
  4002. TeamId: p.TeamId,
  4003. XtHisProjectTeam: models.XtHisProjectTeam{},
  4004. FrequencyType: p.FrequencyType,
  4005. DayCount: p.DayCount,
  4006. WeekDay: p.WeekDay,
  4007. IsCheckTeam: p.IsCheckTeam,
  4008. HisOrderInfo: models.HisOrderInfo{},
  4009. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4010. IsOut: p.IsOut,
  4011. YbSyncStatus: p.YbSyncStatus,
  4012. }
  4013. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4014. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4015. }
  4016. if nowCount == historyCount {
  4017. if historyCount == 0 {
  4018. recordDateStr := time.Now().Format("2006-01-02")
  4019. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4020. nowtime := recordDate.Unix()
  4021. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4022. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4023. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4024. creater := c.GetAdminUserInfo().AdminUser.Id
  4025. dialyPrepareOne := models.DialysisBeforePrepare{
  4026. GoodTypeId: goodObj.GoodTypeId,
  4027. GoodId: p.ProjectId,
  4028. PatientId: p.PatientId,
  4029. RecordDate: p.RecordDate,
  4030. UserOrgId: adminInfo.CurrentOrgId,
  4031. Count: nowCount,
  4032. Ctime: time.Now().Unix(),
  4033. Creater: creater,
  4034. Status: 1,
  4035. StorehouseId: houseConfig.StorehouseOutInfo,
  4036. ProjectId: p.ID,
  4037. }
  4038. //出库
  4039. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4040. }
  4041. }
  4042. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4043. //查询历史出库数据
  4044. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4045. var out_count_five int64
  4046. for _, item := range flowGood {
  4047. out_count_five += item.Count
  4048. }
  4049. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4050. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4051. if out_count_five != parseIntCount {
  4052. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4053. detail := models.AutomaticReduceDetail{
  4054. WarehouseOutId: 0,
  4055. WarehouseOutOrderNumber: "",
  4056. PatientId: p.PatientId,
  4057. Ctime: time.Now().Unix(),
  4058. Mtime: 0,
  4059. Status: 1,
  4060. RecordTime: p.RecordDate,
  4061. OrgId: p.UserOrgId,
  4062. GoodId: p.ProjectId,
  4063. GoodTypeId: 0,
  4064. Count: parseIntCount,
  4065. Type: 0,
  4066. ProjectId: lastHisProject.ID,
  4067. StorehouseId: 0,
  4068. }
  4069. service.CreateNewAutoDetail(detail, tx)
  4070. }
  4071. // //查询耗材最后一次出库记录
  4072. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4073. // //查询默认出库仓库库存
  4074. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4075. // if len(wareOut) > 0 {
  4076. //
  4077. // for _, it := range wareOut {
  4078. // //回退库存
  4079. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4080. //
  4081. // //删除出库记录
  4082. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4083. //
  4084. // }
  4085. // }
  4086. //
  4087. // timeStr := time.Now().Format("2006-01-02")
  4088. // timeArr := strings.Split(timeStr, "-")
  4089. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4090. //
  4091. // total = total + 1
  4092. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4093. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4094. // number = number + total
  4095. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4096. //
  4097. // operation_time := time.Now().Unix()
  4098. // creater := c.GetAdminUserInfo().AdminUser.Id
  4099. //
  4100. // recordDateStr := time.Now().Format("2006-01-02")
  4101. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4102. // nowtime := recordDate.Unix()
  4103. // warehouseOut := models.WarehouseOut{
  4104. // WarehouseOutOrderNumber: warehousing_out_order,
  4105. // OperationTime: operation_time,
  4106. // OrgId: adminInfo.CurrentOrgId,
  4107. // Creater: creater,
  4108. // Ctime: time.Now().Unix(),
  4109. // Status: 1,
  4110. // WarehouseOutTime: nowtime,
  4111. // Type: 1,
  4112. // StorehouseId: storeConfig.StorehouseOutInfo,
  4113. // IsCheck: 1,
  4114. // IsSys: 1,
  4115. // }
  4116. // //查询是否生成出库单
  4117. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4118. // if out.ID == 0 {
  4119. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4120. // }
  4121. //
  4122. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4123. //
  4124. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4125. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4126. //
  4127. // dialyPrepareOne := models.DialysisBeforePrepare{
  4128. // GoodTypeId: goodObj.GoodTypeId,
  4129. // GoodId: p.ProjectId,
  4130. // PatientId: p.PatientId,
  4131. // RecordDate: p.RecordDate,
  4132. // UserOrgId: adminInfo.CurrentOrgId,
  4133. // Count: parseIntCount,
  4134. // Ctime: time.Now().Unix(),
  4135. // Creater: creater,
  4136. // Status: 1,
  4137. // StorehouseId: houseConfig.StorehouseOutInfo,
  4138. // ProjectId: lastHisProject.ID,
  4139. // }
  4140. // //判断是否是零用耗材(非零用)
  4141. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4142. //
  4143. // //查询历史出库数据
  4144. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4145. // var out_count int64
  4146. // for _, item := range flowGood {
  4147. // out_count += item.Count
  4148. // }
  4149. // //如果历史数和当前数据不想等才进行退库出库
  4150. // if out_count != parseIntCount {
  4151. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4152. //
  4153. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4154. // detail := models.AutomaticReduceDetail{
  4155. // WarehouseOutId: 0,
  4156. // WarehouseOutOrderNumber: "",
  4157. // PatientId: p.PatientId,
  4158. // Ctime: time.Now().Unix(),
  4159. // Mtime: 0,
  4160. // Status: 1,
  4161. // RecordTime: p.RecordDate,
  4162. // OrgId: p.UserOrgId,
  4163. // GoodId: p.ProjectId,
  4164. // GoodTypeId: 0,
  4165. // Count: parseIntCount,
  4166. // Type: 0,
  4167. // ProjectId: lastHisProject.ID,
  4168. // StorehouseId: 0,
  4169. // }
  4170. //
  4171. // service.CreateNewAutoDetail(detail, tx)
  4172. //
  4173. // //查询剩余库存
  4174. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4175. // var sum_count int64
  4176. // for _, item := range goodList {
  4177. // sum_count += item.StockCount
  4178. // }
  4179. //
  4180. // //更新剩余库存
  4181. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4182. //
  4183. // //耗材
  4184. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4185. //
  4186. // }
  4187. // //判断是否是零用耗材(零用但是是出库耗材)
  4188. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4189. //
  4190. // //查询历史出库数据
  4191. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4192. // var out_count int64
  4193. // for _, item := range flowGood {
  4194. // out_count += item.Count
  4195. // }
  4196. // //如果历史数和当前数据不想等才进行退库出库
  4197. // if out_count != parseIntCount {
  4198. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4199. //
  4200. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4201. // detail := models.AutomaticReduceDetail{
  4202. // WarehouseOutId: 0,
  4203. // WarehouseOutOrderNumber: "",
  4204. // PatientId: p.PatientId,
  4205. // Ctime: time.Now().Unix(),
  4206. // Mtime: 0,
  4207. // Status: 1,
  4208. // RecordTime: p.RecordDate,
  4209. // OrgId: p.UserOrgId,
  4210. // GoodId: p.ProjectId,
  4211. // GoodTypeId: 0,
  4212. // Count: parseIntCount,
  4213. // Type: 0,
  4214. // ProjectId: p.ID,
  4215. // StorehouseId: 0,
  4216. // }
  4217. //
  4218. // service.CreateNewAutoDetail(detail, tx)
  4219. //
  4220. // //查询剩余库存
  4221. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4222. // var sum_count int64
  4223. // for _, item := range goodList {
  4224. // sum_count += item.StockCount
  4225. // }
  4226. //
  4227. // //更新剩余库存
  4228. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4229. //
  4230. // //耗材
  4231. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4232. // }
  4233. //
  4234. // }
  4235. //
  4236. // }
  4237. //
  4238. //}
  4239. //记录日志
  4240. byterequest, _ := json.Marshal(p)
  4241. adviceLog := models.XtDoctorAdviceLog{
  4242. UserOrgId: p.UserOrgId,
  4243. PatientId: p.PatientId,
  4244. AdminUserId: adminInfo.AdminUser.Id,
  4245. Module: 1,
  4246. ErrLog: string(byterequest),
  4247. Status: 1,
  4248. Ctime: time.Now().Unix(),
  4249. Mtime: 0,
  4250. Source: "电脑端新建his项目",
  4251. RecordDate: p.RecordDate,
  4252. }
  4253. service.CreateDoctorAdviceLog(adviceLog)
  4254. projectList = append(projectList, p)
  4255. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4256. //新增或者编辑项目,修改对应的标签数据
  4257. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4258. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4259. var label models.HisLabelPrintInfo
  4260. project, _ := service.GetProjectDetail(p.ProjectId)
  4261. if project.CostClassify == 3 { //类别为检验检查
  4262. if p.TeamId > 0 { //检验检查组套
  4263. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4264. if tempLabel.ID == 0 {
  4265. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4266. label.Number = tempPrescription.PrescriptionNumber
  4267. label.ProjectId = project.ID
  4268. label.Status = 1
  4269. label.IsPrint = 2
  4270. label.DoctorId = info.DoctorId
  4271. label.UserOrgId = p.UserOrgId
  4272. label.PatientId = patient_id
  4273. label.RecordDate = recordDateTime
  4274. label.Ctime = time.Now().Unix()
  4275. label.Mtime = time.Now().Unix()
  4276. label.ItemId = p.TeamId
  4277. label.FeedetlSn = p.FeedetlSn
  4278. label.PProjectId = p.ID
  4279. label.ProjectName = team.ProjectTeam
  4280. label.PatientName = patient.Name
  4281. service.CreateNewHisLabelRecord(&label, tx)
  4282. }
  4283. } else { //单条检验检查项目
  4284. label.Number = tempPrescription.PrescriptionNumber
  4285. label.ProjectId = project.ID
  4286. label.Status = 1
  4287. label.DoctorId = info.DoctorId
  4288. label.UserOrgId = p.UserOrgId
  4289. label.PatientId = patient_id
  4290. label.RecordDate = recordDateTime
  4291. label.IsPrint = 2
  4292. label.Ctime = time.Now().Unix()
  4293. label.Mtime = time.Now().Unix()
  4294. label.FeedetlSn = p.FeedetlSn
  4295. label.PProjectId = p.ID
  4296. label.ItemId = p.TeamId
  4297. label.ProjectName = project.ProjectName
  4298. label.PatientName = patient.Name
  4299. service.CreateNewHisLabelRecord(&label, tx)
  4300. }
  4301. }
  4302. }
  4303. }
  4304. }
  4305. }
  4306. }
  4307. //插入检验数据
  4308. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4309. //新增或者编辑项目,修改对应的标签数据
  4310. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4311. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4312. var label models.HisLabelPrintInfo
  4313. project, _ := service.GetProjectDetail(p.ProjectId)
  4314. if project.CostClassify == 3 { //类别为检验检查
  4315. if p.TeamId > 0 { //检验检查组套
  4316. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4317. if tempLabel.ID == 0 {
  4318. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4319. label.Number = tempPrescription.PrescriptionNumber
  4320. label.ProjectId = project.ID
  4321. label.Status = 1
  4322. label.IsPrint = 2
  4323. label.DoctorId = info.DoctorId
  4324. label.UserOrgId = p.UserOrgId
  4325. label.PatientId = patient_id
  4326. label.RecordDate = recordDateTime
  4327. label.Ctime = time.Now().Unix()
  4328. label.Mtime = time.Now().Unix()
  4329. label.ItemId = p.TeamId
  4330. label.FeedetlSn = p.FeedetlSn
  4331. label.PProjectId = p.ID
  4332. label.ProjectName = team.ProjectTeam
  4333. label.PatientName = patient.Name
  4334. service.CreateHisLabelRecord(&label)
  4335. }
  4336. } else { //单条检验检查项目
  4337. label.Number = tempPrescription.PrescriptionNumber
  4338. label.ProjectId = project.ID
  4339. label.Status = 1
  4340. label.DoctorId = info.DoctorId
  4341. label.UserOrgId = p.UserOrgId
  4342. label.PatientId = patient_id
  4343. label.RecordDate = recordDateTime
  4344. label.IsPrint = 2
  4345. label.Ctime = time.Now().Unix()
  4346. label.Mtime = time.Now().Unix()
  4347. label.FeedetlSn = p.FeedetlSn
  4348. label.PProjectId = p.ID
  4349. label.ItemId = p.TeamId
  4350. label.ProjectName = project.ProjectName
  4351. label.PatientName = patient.Name
  4352. service.CreateHisLabelRecord(&label)
  4353. }
  4354. }
  4355. }
  4356. }
  4357. service.CreateNewHisProjectTwo(&p, tx)
  4358. var randNum int
  4359. randNum = rand.Intn(10000) + 1000
  4360. timestamp := time.Now().Unix()
  4361. tempTime := time.Unix(timestamp, 0)
  4362. timeFormat := tempTime.Format("20060102150405")
  4363. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4364. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4365. if goodBase.ID > 0 {
  4366. tx.Rollback()
  4367. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4368. return
  4369. }
  4370. service.CreateNewHisProjectTwo(&p, tx)
  4371. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4372. //查询剩余库存
  4373. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4374. var sum_count int64
  4375. for _, item := range goodList {
  4376. sum_count += item.StockCount
  4377. }
  4378. //更新剩余库存
  4379. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4380. //耗材
  4381. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4382. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4383. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4384. if len(outInfoTwo) > 0 {
  4385. for _, item := range outInfoTwo {
  4386. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4387. }
  4388. }
  4389. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4390. if len(drugAutoDetail) > 0 {
  4391. for _, item := range drugAutoDetail {
  4392. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4393. }
  4394. }
  4395. tx.Commit()
  4396. }
  4397. }
  4398. }
  4399. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4400. // addition := items["addition"].([]interface{})
  4401. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4402. // ctime := time.Now().Unix()
  4403. // mtime := ctime
  4404. // if len(addition) > 0 {
  4405. // for _, item := range addition {
  4406. // var s models.HisAdditionalCharge
  4407. // s.PrescriptionId = tempPrescription.ID
  4408. // s.Status = 1
  4409. // s.UserOrgId = adminInfo.CurrentOrgId
  4410. // s.RecordDate = recordDateTime
  4411. // s.CreatedTime = ctime
  4412. // s.UpdatedTime = mtime
  4413. // s.PatientId = patient_id
  4414. // s.HisPatientId = his_patient_id
  4415. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4416. // if errcode > 0 {
  4417. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4418. // return
  4419. // }
  4420. // service.CreateAdditionalCharge(&s)
  4421. // var randNum int
  4422. // randNum = rand.Intn(10000) + 1000
  4423. // timestamp := time.Now().Unix()
  4424. // tempTime := time.Unix(timestamp, 0)
  4425. // timeFormat := tempTime.Format("20060102150405")
  4426. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4427. // service.CreateAdditionalCharge(&s)
  4428. //
  4429. // }
  4430. // }
  4431. //}
  4432. }
  4433. }
  4434. }
  4435. tx.Commit()
  4436. if err == nil {
  4437. c.ServeSuccessJSON(map[string]interface{}{
  4438. "msg": "保存成功",
  4439. })
  4440. return
  4441. } else {
  4442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4443. return
  4444. }
  4445. } else {
  4446. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4447. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4448. var tempPrescription *models.HisPrescription
  4449. if len(prescriptions) > 0 {
  4450. for _, item := range prescriptions {
  4451. items := item.(map[string]interface{})
  4452. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4453. utils.ErrorLog("id")
  4454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4455. return
  4456. }
  4457. id := int64(items["id"].(float64))
  4458. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4459. tempPrescription = &new_prescription
  4460. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4461. utils.ErrorLog("type")
  4462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4463. return
  4464. }
  4465. types := int64(items["type"].(float64))
  4466. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4467. utils.ErrorLog("med_type")
  4468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4469. return
  4470. }
  4471. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4472. if med_type == "0" {
  4473. med_type = "14"
  4474. }
  4475. //if order_status == 0 {
  4476. // order_status = 1
  4477. //}
  4478. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4479. // utils.ErrorLog("diagnoses")
  4480. //}
  4481. diagnoses, _ := items["diagnoses"].(string)
  4482. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4483. utils.ErrorLog("pre_time")
  4484. }
  4485. preTime, _ := items["pre_time"].(string)
  4486. timeLayout := "2006-01-02"
  4487. loc, _ := time.LoadLocation("Local")
  4488. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4489. //result := strings.Split(preTime, " ")
  4490. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4491. if err != nil {
  4492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4493. return
  4494. }
  4495. pTime := theTime2.Unix()
  4496. ctime := time.Now().Unix()
  4497. if tempPrescription.ID == 0 {
  4498. prescription := &models.HisPrescription{
  4499. ID: 0,
  4500. PatientId: patient_id,
  4501. UserOrgId: adminInfo.CurrentOrgId,
  4502. RecordDate: recordDateTime,
  4503. Ctime: ctime,
  4504. Mtime: ctime,
  4505. Type: types,
  4506. Modifier: adminInfo.AdminUser.Id,
  4507. Creator: adminInfo.AdminUser.Id,
  4508. Status: 1,
  4509. Doctor: role.UserName,
  4510. HisPatientId: his_patient_id,
  4511. OrderStatus: 1,
  4512. BatchNumber: "",
  4513. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4514. PreTime: pTime,
  4515. PType: p_type,
  4516. MedType: med_type,
  4517. Diagnose: diagnoses,
  4518. }
  4519. tempPrescription = prescription
  4520. service.SaveHisPrescription(tempPrescription)
  4521. redis := service.RedisClient()
  4522. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4523. redis.Set(key, "", time.Second)
  4524. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4525. redis.Set(keyOne, "", time.Second)
  4526. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4527. redis.Set(keySeven, "", time.Second)
  4528. defer redis.Close()
  4529. } else {
  4530. tempPrescription.ID = id
  4531. tempPrescription.Type = types
  4532. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4533. tempPrescription.Mtime = time.Now().Unix()
  4534. tempPrescription.Doctor = role.UserName
  4535. //tempPrescription.OrderStatus = order_status
  4536. tempPrescription.PreTime = pTime
  4537. tempPrescription.MedType = med_type
  4538. tempPrescription.Diagnose = diagnoses
  4539. service.SaveHisPrescription(tempPrescription)
  4540. redis := service.RedisClient()
  4541. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4542. redis.Set(key, "", time.Second)
  4543. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4544. redis.Set(keyOne, "", time.Second)
  4545. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4546. redis.Set(keySeven, "", time.Second)
  4547. defer redis.Close()
  4548. }
  4549. //service.SaveHisPrescription(prescription)
  4550. //更改患者挂号状态
  4551. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4552. fmt.Println("更改失败", err2)
  4553. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4554. advices := items["advices"].([]interface{})
  4555. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4556. groupNo := int64(0)
  4557. if len(advices) > 0 {
  4558. for _, advice := range advices {
  4559. var s models.HisDoctorAdviceInfo
  4560. s.PrescriptionId = tempPrescription.ID
  4561. s.AdviceType = 2
  4562. s.AdviceDoctor = doctor_id
  4563. s.StopState = 2
  4564. s.ExecutionState = 2
  4565. s.AdviceDate = theTime3.Unix()
  4566. s.Status = 1
  4567. s.UserOrgId = adminInfo.CurrentOrgId
  4568. s.RecordDate = theTime3.Unix()
  4569. s.StartTime = tempPrescription.PreTime
  4570. s.Groupno = groupNo
  4571. s.PatientId = patient_id
  4572. s.HisPatientId = his_patient_id
  4573. s.StartTime = pTime
  4574. s.IsSettle = 2
  4575. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4576. if errcode > 0 {
  4577. c.ServeFailJSONWithSGJErrorCode(errcode)
  4578. return
  4579. }
  4580. s.StartTime = pTime
  4581. var total_count int64 //处方总库存
  4582. //查询改药品信息
  4583. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4584. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4585. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4586. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4587. total_count += prescribingNumberSeven * medical.MinNumber
  4588. }
  4589. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4590. total_count += prescribingNumberSeven
  4591. }
  4592. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4593. total_count += prescribingNumberSeven
  4594. }
  4595. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4596. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4597. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4598. if s.Price != lastWarehouse.RetailPrice {
  4599. s.Price = lastWarehouse.RetailPrice
  4600. }
  4601. if s.Price == 0 {
  4602. if lastWarehouse.ID == 0 {
  4603. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4604. s.Price = lastWarehouseTwo.RetailPrice
  4605. }
  4606. }
  4607. }
  4608. if adminInfo.CurrentOrgId != 10206 {
  4609. if s.ID == 0 {
  4610. //查询改药品是否已经停用
  4611. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4612. if base.ID > 0 {
  4613. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4614. return
  4615. }
  4616. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4617. if drugMedical.SumCount == 0 {
  4618. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4619. return
  4620. }
  4621. }
  4622. }
  4623. //赤峰
  4624. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4625. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4626. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4627. if info.RetailPrice > 0 {
  4628. if s.DeliveryWay == "口服" {
  4629. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4630. s.Price = drug.RetailPrice
  4631. }
  4632. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4633. s.Price = info.RetailPrice
  4634. }
  4635. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4636. s.Price = info.RetailPrice
  4637. }
  4638. }
  4639. }
  4640. }
  4641. service.CreateHisDoctorAdvice(&s)
  4642. //记录日志
  4643. byterequest, _ := json.Marshal(s)
  4644. adviceLog := models.XtDoctorAdviceLog{
  4645. UserOrgId: s.UserOrgId,
  4646. PatientId: s.PatientId,
  4647. AdminUserId: adminInfo.AdminUser.Id,
  4648. Module: 1,
  4649. ErrLog: string(byterequest),
  4650. Status: 1,
  4651. Ctime: time.Now().Unix(),
  4652. Mtime: 0,
  4653. Source: "电脑端新建his医嘱",
  4654. RecordDate: s.AdviceDate,
  4655. }
  4656. service.CreateDoctorAdviceLog(adviceLog)
  4657. //存储切片中
  4658. adviceList = append(adviceList, s)
  4659. redis := service.RedisClient()
  4660. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4661. redis.Set(key, "", time.Second)
  4662. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4663. redis.Set(keyOne, "", time.Second)
  4664. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4665. redis.Set(keySeven, "", time.Second)
  4666. var randNum int
  4667. randNum = rand.Intn(10000) + 1000
  4668. timestamp := time.Now().Unix()
  4669. tempTime := time.Unix(timestamp, 0)
  4670. timeFormat := tempTime.Format("20060102150405")
  4671. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4672. service.CreateHisDoctorAdvice(&s)
  4673. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4674. redis.Set(keySix, "", time.Second)
  4675. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4676. redis.Set(keyFive, "", time.Second)
  4677. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4678. redis.Set(keyEight, "", time.Second)
  4679. defer redis.Close()
  4680. }
  4681. }
  4682. }
  4683. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4684. projects := items["project"].([]interface{})
  4685. if len(projects) > 0 {
  4686. for _, project := range projects {
  4687. var p models.HisPrescriptionProject
  4688. p.PrescriptionId = tempPrescription.ID
  4689. p.PatientId = patient_id
  4690. p.RecordDate = theTime3.Unix()
  4691. p.Doctor = doctor_id
  4692. p.UserOrgId = adminInfo.CurrentOrgId
  4693. p.HisPatientId = his_patient_id
  4694. p.Status = 1
  4695. p.StartTime = pTime
  4696. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4697. if errcode > 0 {
  4698. c.ServeFailJSONWithSGJErrorCode(errcode)
  4699. return
  4700. }
  4701. if p.ID == 0 {
  4702. p.IsOut = 2
  4703. }
  4704. if p.ID > 0 {
  4705. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4706. p.IsOut = projectDetail.IsOut
  4707. }
  4708. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4709. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4710. if p.Type == 3 {
  4711. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4712. if p.Price != lastWarehouse.PackingPrice {
  4713. p.Price = lastWarehouse.PackingPrice
  4714. }
  4715. if p.Price == 0 {
  4716. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4717. p.Price = lastWarehouseTwo.PackingPrice
  4718. }
  4719. if p.Unit == "" {
  4720. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4721. p.Unit = goodInfoOne.PackingUnit
  4722. }
  4723. }
  4724. }
  4725. if adminInfo.CurrentOrgId != 10206 {
  4726. if p.Type == 3 {
  4727. if p.ID == 0 {
  4728. //查询该耗材是否停用
  4729. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4730. //表示该耗材已经停用,不能保存
  4731. if goodInfoSeven.ID == 0 {
  4732. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4733. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4734. return
  4735. }
  4736. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4737. if goodInfoOne.SumCount == 0 {
  4738. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4739. return
  4740. }
  4741. }
  4742. }
  4743. }
  4744. service.CreateHisProjectTwo(&p)
  4745. //记录日志
  4746. byterequest, _ := json.Marshal(p)
  4747. adviceLog := models.XtDoctorAdviceLog{
  4748. UserOrgId: p.UserOrgId,
  4749. PatientId: p.PatientId,
  4750. AdminUserId: adminInfo.AdminUser.Id,
  4751. Module: 1,
  4752. ErrLog: string(byterequest),
  4753. Status: 1,
  4754. Ctime: time.Now().Unix(),
  4755. Mtime: 0,
  4756. Source: "电脑端新建his项目",
  4757. RecordDate: p.RecordDate,
  4758. }
  4759. service.CreateDoctorAdviceLog(adviceLog)
  4760. projectList = append(projectList, p)
  4761. var randNum int
  4762. randNum = rand.Intn(10000) + 1000
  4763. timestamp := time.Now().Unix()
  4764. tempTime := time.Unix(timestamp, 0)
  4765. timeFormat := tempTime.Format("20060102150405")
  4766. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4767. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4768. //新增或者编辑项目,修改对应的标签数据
  4769. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4770. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4771. var label models.HisLabelPrintInfo
  4772. project, _ := service.GetProjectDetail(p.ProjectId)
  4773. if project.CostClassify == 3 { //类别为检验检查
  4774. if p.TeamId > 0 { //检验检查组套
  4775. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4776. if tempLabel.ID == 0 {
  4777. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4778. label.Number = tempPrescription.PrescriptionNumber
  4779. label.ProjectId = project.ID
  4780. label.Status = 1
  4781. label.IsPrint = 2
  4782. label.DoctorId = info.DoctorId
  4783. label.UserOrgId = p.UserOrgId
  4784. label.PatientId = patient_id
  4785. label.RecordDate = recordDateTime
  4786. label.Ctime = time.Now().Unix()
  4787. label.Mtime = time.Now().Unix()
  4788. label.ItemId = p.TeamId
  4789. label.FeedetlSn = p.FeedetlSn
  4790. label.PProjectId = p.ID
  4791. label.ProjectName = team.ProjectTeam
  4792. label.PatientName = patient.Name
  4793. service.CreateHisLabelRecord(&label)
  4794. }
  4795. } else { //单条检验检查项目
  4796. label.Number = tempPrescription.PrescriptionNumber
  4797. label.ProjectId = project.ID
  4798. label.Status = 1
  4799. label.DoctorId = info.DoctorId
  4800. label.UserOrgId = p.UserOrgId
  4801. label.PatientId = patient_id
  4802. label.RecordDate = recordDateTime
  4803. label.IsPrint = 2
  4804. label.Ctime = time.Now().Unix()
  4805. label.Mtime = time.Now().Unix()
  4806. label.FeedetlSn = p.FeedetlSn
  4807. label.PProjectId = p.ID
  4808. label.ItemId = p.TeamId
  4809. label.ProjectName = project.ProjectName
  4810. label.PatientName = patient.Name
  4811. service.CreateHisLabelRecord(&label)
  4812. }
  4813. }
  4814. }
  4815. }
  4816. service.SaveHisProjectTwo(&p)
  4817. }
  4818. }
  4819. }
  4820. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4821. // addition := items["addition"].([]interface{})
  4822. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4823. // ctime := time.Now().Unix()
  4824. // mtime := ctime
  4825. // if len(addition) > 0 {
  4826. // for _, item := range addition {
  4827. // var s models.HisAdditionalCharge
  4828. // s.PrescriptionId = tempPrescription.ID
  4829. // s.Status = 1
  4830. // s.UserOrgId = adminInfo.CurrentOrgId
  4831. // s.RecordDate = recordDateTime
  4832. // s.CreatedTime = ctime
  4833. // s.UpdatedTime = mtime
  4834. // s.PatientId = patient_id
  4835. // s.HisPatientId = his_patient_id
  4836. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4837. // if errcode > 0 {
  4838. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4839. // return
  4840. // }
  4841. // service.CreateAdditionalCharge(&s)
  4842. // var randNum int
  4843. // randNum = rand.Intn(10000) + 1000
  4844. // timestamp := time.Now().Unix()
  4845. // tempTime := time.Unix(timestamp, 0)
  4846. // timeFormat := tempTime.Format("20060102150405")
  4847. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4848. // service.CreateAdditionalCharge(&s)
  4849. //
  4850. // }
  4851. // }
  4852. //}
  4853. }
  4854. }
  4855. //查询今日该患者开的药品处方
  4856. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4857. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4858. //药品出库
  4859. if drugOutConfig.IsOpen == 1 {
  4860. for _, item := range hisdoctorlist {
  4861. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4862. // 查询该药品最后一次出库记录
  4863. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4864. if len(druginfo) > 0 {
  4865. //回退库存
  4866. for _, it := range druginfo {
  4867. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4868. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4869. }
  4870. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4871. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4872. }
  4873. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4874. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4875. }
  4876. }
  4877. }
  4878. //删除记录
  4879. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4880. //查询最后一次数据
  4881. if drugOutConfig.IsOpen == 1 {
  4882. //出库
  4883. if drug.IsUse == 2 {
  4884. creater := adminInfo.AdminUser.Id
  4885. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4886. }
  4887. //更新字典里面的库存
  4888. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4889. var sum_count int64
  4890. for _, its := range stockInfo {
  4891. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4892. if its.MaxUnit == baseDrug.MaxUnit {
  4893. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4894. }
  4895. sum_count += its.StockMaxNumber + its.StockMinNumber
  4896. }
  4897. //更新基础库存
  4898. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4899. //剩余库存
  4900. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4901. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4902. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4903. }
  4904. }
  4905. }
  4906. //耗材保存处方出库
  4907. if goodOutConfig.IsOpen == 1 {
  4908. //查询今日耗材出库数量
  4909. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4910. for _, item := range hisgoodlist {
  4911. //查询历史出库数据
  4912. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4913. var out_count_five int64
  4914. for _, item := range flowGood {
  4915. out_count_five += item.Count
  4916. }
  4917. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4918. if out_count_five != parseIntCount {
  4919. //查询耗材最后一次出库记录
  4920. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4921. //查询默认出库仓库库存
  4922. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4923. if len(wareOut) > 0 {
  4924. for _, it := range wareOut {
  4925. //回退库存
  4926. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4927. //删除出库记录
  4928. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4929. }
  4930. }
  4931. timeStr := time.Now().Format("2006-01-02")
  4932. timeArr := strings.Split(timeStr, "-")
  4933. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4934. total = total + 1
  4935. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4936. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4937. number = number + total
  4938. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4939. operation_time := time.Now().Unix()
  4940. creater := c.GetAdminUserInfo().AdminUser.Id
  4941. recordDateStr := time.Now().Format("2006-01-02")
  4942. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4943. nowtime := recordDate.Unix()
  4944. warehouseOut := models.WarehouseOut{
  4945. WarehouseOutOrderNumber: warehousing_out_order,
  4946. OperationTime: operation_time,
  4947. OrgId: adminInfo.CurrentOrgId,
  4948. Creater: creater,
  4949. Ctime: time.Now().Unix(),
  4950. Status: 1,
  4951. WarehouseOutTime: nowtime,
  4952. Type: 1,
  4953. StorehouseId: storeConfig.StorehouseOutInfo,
  4954. IsCheck: 1,
  4955. IsSys: 1,
  4956. }
  4957. //查询是否生成出库单
  4958. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4959. if out.ID == 0 {
  4960. service.AddSigleWarehouseOut(&warehouseOut)
  4961. }
  4962. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4963. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4964. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4965. dialyPrepareOne := models.DialysisBeforePrepare{
  4966. GoodTypeId: goodObj.GoodTypeId,
  4967. GoodId: item.ProjectId,
  4968. PatientId: item.PatientId,
  4969. RecordDate: item.RecordDate,
  4970. UserOrgId: adminInfo.CurrentOrgId,
  4971. Count: parseIntCount,
  4972. Ctime: time.Now().Unix(),
  4973. Creater: creater,
  4974. Status: 1,
  4975. StorehouseId: houseConfig.StorehouseOutInfo,
  4976. ProjectId: item.ID,
  4977. }
  4978. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4979. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4980. //查询历史出库数据
  4981. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4982. var out_count int64
  4983. for _, item := range flowGood {
  4984. out_count += item.Count
  4985. }
  4986. //如果历史数和当前数据不想等才进行退库出库
  4987. if out_count != parseIntCount {
  4988. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4989. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4990. detail := models.AutomaticReduceDetail{
  4991. WarehouseOutId: 0,
  4992. WarehouseOutOrderNumber: "",
  4993. PatientId: item.PatientId,
  4994. Ctime: time.Now().Unix(),
  4995. Mtime: 0,
  4996. Status: 1,
  4997. RecordTime: item.RecordDate,
  4998. OrgId: item.UserOrgId,
  4999. GoodId: item.ProjectId,
  5000. GoodTypeId: 0,
  5001. Count: parseIntCount,
  5002. Type: 0,
  5003. ProjectId: item.ID,
  5004. StorehouseId: 0,
  5005. }
  5006. service.CreateAutoDetail(detail)
  5007. //查询剩余库存
  5008. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5009. var sum_count int64
  5010. for _, item := range goodList {
  5011. sum_count += item.StockCount
  5012. }
  5013. //更新剩余库存
  5014. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5015. //耗材
  5016. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5017. }
  5018. }
  5019. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5020. //查询历史出库数据
  5021. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5022. var out_count int64
  5023. for _, item := range flowGood {
  5024. out_count += item.Count
  5025. }
  5026. //如果历史数和当前数据不想等才进行退库出库
  5027. if out_count != parseIntCount {
  5028. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5029. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5030. detail := models.AutomaticReduceDetail{
  5031. WarehouseOutId: 0,
  5032. WarehouseOutOrderNumber: "",
  5033. PatientId: item.PatientId,
  5034. Ctime: time.Now().Unix(),
  5035. Mtime: 0,
  5036. Status: 1,
  5037. RecordTime: item.RecordDate,
  5038. OrgId: item.UserOrgId,
  5039. GoodId: item.ProjectId,
  5040. GoodTypeId: 0,
  5041. Count: parseIntCount,
  5042. Type: 0,
  5043. ProjectId: item.ID,
  5044. StorehouseId: 0,
  5045. }
  5046. service.CreateAutoDetail(detail)
  5047. //查询剩余库存
  5048. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5049. var sum_count int64
  5050. for _, item := range goodList {
  5051. sum_count += item.StockCount
  5052. }
  5053. //更新剩余库存
  5054. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5055. //耗材
  5056. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5057. }
  5058. }
  5059. }
  5060. }
  5061. }
  5062. ////同步到自备药
  5063. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5064. if selfPrescriptionOpen.IsOpen == 1 {
  5065. timeStr := time.Now().Format("2006-01-02")
  5066. timeArr := strings.Split(timeStr, "-")
  5067. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5068. total = total + 1
  5069. operation_time := time.Now().Unix()
  5070. creater := adminInfo.AdminUser.Id
  5071. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5072. warehousing := models.XtSelfDrugWarehouse{
  5073. WarehousingOrder: warehousing_order,
  5074. OperationTime: operation_time,
  5075. OrgId: adminInfo.CurrentOrgId,
  5076. Creater: creater,
  5077. Ctime: time.Now().Unix(),
  5078. Status: 1,
  5079. WarehousingTime: recordDateTime,
  5080. Type: 0,
  5081. StorehouseId: 0,
  5082. IsCheck: 1,
  5083. PatientId: patient_id,
  5084. IsSys: 1,
  5085. }
  5086. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5087. if selfDrugWarehouse.ID == 0 {
  5088. service.AddSelfDrugWarehouse(&warehousing, tx)
  5089. }
  5090. if selfDrugWarehouse.ID > 0 {
  5091. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5092. }
  5093. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5094. fmt.Println(info)
  5095. for _, item := range hisdoctorlist {
  5096. //查询该病人的该药品是否已经入库
  5097. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5098. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5099. var in_count int64
  5100. if len(selfdruginfo) > 0 {
  5101. for _, item := range selfdruginfo {
  5102. var in_count_one int64
  5103. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5104. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5105. }
  5106. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5107. in_count_one = item.WarehousingCount
  5108. }
  5109. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5110. in_count_one = item.WarehousingCount
  5111. }
  5112. in_count += in_count_one
  5113. }
  5114. }
  5115. if selfBasedrug.IsSelfDrug == 1 {
  5116. var total_count int64
  5117. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5118. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5119. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5120. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5121. }
  5122. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5123. total_count += prescribingNumberSeven
  5124. }
  5125. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5126. total_count += prescribingNumberSeven
  5127. }
  5128. //入库
  5129. if total_count > in_count {
  5130. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5131. WarehousingOrder: warehousing_order,
  5132. WarehousingId: info.ID,
  5133. DrugId: item.DrugId,
  5134. Number: "",
  5135. ProductDate: 0,
  5136. ExpiryDate: 0,
  5137. WarehousingCount: total_count - in_count,
  5138. WarehouseingUnit: selfBasedrug.MinUnit,
  5139. Price: 0,
  5140. TotalPrice: 0,
  5141. Status: 1,
  5142. Ctime: time.Now().Unix(),
  5143. Remark: "",
  5144. OrgId: adminInfo.CurrentOrgId,
  5145. Type: 0,
  5146. Manufacturer: selfBasedrug.Manufacturer,
  5147. Dealer: selfBasedrug.Dealer,
  5148. StockMaxNumber: total_count - in_count,
  5149. RetailTotalPrice: 0,
  5150. BatchNumber: "",
  5151. MaxUnit: selfBasedrug.MinUnit,
  5152. MinUnit: selfBasedrug.MinUnit,
  5153. RetailPrice: 0,
  5154. StorehouseId: 0,
  5155. IsCheck: 1,
  5156. StockMinNumber: 0,
  5157. PatientId: patient_id,
  5158. IsSys: 1,
  5159. RecordDate: item.RecordDate,
  5160. AdviceId: item.ID,
  5161. }
  5162. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5163. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5164. Creator := adminInfo.AdminUser.Id
  5165. //查询默认仓库剩余多少库存
  5166. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5167. var sum_count int64
  5168. for _, it := range list {
  5169. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5170. if it.MaxUnit == baseDrug.MaxUnit {
  5171. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5172. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5173. }
  5174. sum_count += it.StockMaxNumber + it.StockMinNumber
  5175. }
  5176. flow := &models.XtSelfDrugFlow{
  5177. WarehousingId: info.ID,
  5178. DrugId: item.DrugId,
  5179. Number: "",
  5180. BatchNumber: "",
  5181. Count: total_count - in_count,
  5182. UserOrgId: adminInfo.CurrentOrgId,
  5183. PatientId: item.PatientId,
  5184. SystemTime: time.Now().Unix(),
  5185. ConsumableType: 1,
  5186. IsSys: 1,
  5187. WarehousingOrder: warehousing_order,
  5188. WarehouseOutId: 0,
  5189. WarehouseOutOrderNumber: "",
  5190. IsEdit: 0,
  5191. CancelStockId: 0,
  5192. CancelOrderNumber: "",
  5193. Manufacturer: selfBasedrug.Manufacturer,
  5194. Dealer: selfBasedrug.Dealer,
  5195. Creator: Creator,
  5196. UpdateCreator: Creator,
  5197. Status: 1,
  5198. Ctime: item.AdviceDate,
  5199. Mtime: 0,
  5200. Price: item.Price,
  5201. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5202. WarehouseOutDetailId: 0,
  5203. CancelOutDetailId: 0,
  5204. ExpireDate: 0,
  5205. ProductDate: 0,
  5206. MaxUnit: selfBasedrug.MinUnit,
  5207. MinUnit: selfBasedrug.MinUnit,
  5208. StorehouseId: 0,
  5209. OverCount: sum_count,
  5210. OperateTime: time.Now().Unix(),
  5211. AdviceId: item.ID,
  5212. }
  5213. service.CreateSelfDrugFlow(flow, tx)
  5214. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5215. var total_count int64 // 入库总数量
  5216. var over_count int64 //剩余库存
  5217. for _, it := range drugInfolist {
  5218. if it.MaxUnit == selfBasedrug.MaxUnit {
  5219. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5220. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5221. }
  5222. }
  5223. for _, it := range drugInfolist {
  5224. total_count += it.WarehousingCount
  5225. over_count += it.StockMaxNumber + it.StockMinNumber
  5226. }
  5227. //查询该仓库是否有默认数据
  5228. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5229. if selfDrugStock.ID == 0 {
  5230. drugStock := models.XtSelfDrugStockCount{
  5231. UserOrgId: item.UserOrgId,
  5232. PatientId: item.PatientId,
  5233. SumInCount: total_count,
  5234. SumOutCount: 0,
  5235. SumCancelCount: 0,
  5236. DrugId: item.DrugId,
  5237. Ctime: time.Now().Unix(),
  5238. Mtime: 0,
  5239. Status: 1,
  5240. FlushCount: over_count,
  5241. SumActOutCount: 0,
  5242. }
  5243. service.CreateSelfDrugStockSum(drugStock, tx)
  5244. }
  5245. if selfDrugStock.ID > 0 {
  5246. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5247. }
  5248. }
  5249. //查询这个单据的出库数量
  5250. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5251. var his_out_count int64
  5252. for _, item := range drugFlowList {
  5253. his_out_count += item.Count
  5254. }
  5255. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5256. if (total_count + his_out_count) <= in_count {
  5257. // 出库
  5258. if total_count < in_count {
  5259. var cha_count int64
  5260. cha_count = in_count - total_count
  5261. var stock_number int64 = 0
  5262. //查询库存是否充足
  5263. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5264. // 将该批次的剩余库存数量转换为拆零数量
  5265. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5266. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5267. }
  5268. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5269. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5270. }
  5271. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5272. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5273. }
  5274. if stock_number >= cha_count {
  5275. var maxNumber int64 = 0
  5276. var minNumber int64 = 0
  5277. maxNumber = cha_count / selfBasedrug.MinNumber
  5278. minNumber = cha_count % selfBasedrug.MinNumber
  5279. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5280. minNumber = maxNumber
  5281. }
  5282. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5283. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5285. return
  5286. }
  5287. }
  5288. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5289. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5290. }
  5291. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5292. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5293. }
  5294. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5295. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5296. }
  5297. if warehouse.StockMaxNumber < 0 {
  5298. warehouse.StockMaxNumber = 0
  5299. }
  5300. if warehouse.StockMinNumber < 0 {
  5301. warehouse.StockMinNumber = 0
  5302. }
  5303. warehouse.Mtime = time.Now().Unix()
  5304. if warehouse.StockMinNumber < minNumber {
  5305. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5306. if warehouse.MaxUnit != warehouse.MinUnit {
  5307. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5308. }
  5309. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5310. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5311. }
  5312. } else {
  5313. if minNumber > 0 {
  5314. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5315. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5316. }
  5317. }
  5318. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5319. if warehouse.StockMinNumber > 0 {
  5320. if warehouse.StockMinNumber-cha_count >= 0 {
  5321. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5322. }
  5323. }
  5324. }
  5325. }
  5326. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5327. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5328. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5329. }
  5330. }
  5331. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5332. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5334. return
  5335. }
  5336. }
  5337. if warehouse.StockMinNumber <= 0 {
  5338. warehouse.StockMinNumber = 0
  5339. }
  5340. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5341. //查询该药品剩余库存
  5342. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5343. var over_count int64
  5344. for _, its := range infolist {
  5345. if its.MaxUnit == selfBasedrug.MaxUnit {
  5346. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5347. }
  5348. over_count += its.StockMaxNumber + its.StockMinNumber
  5349. }
  5350. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5351. drugflow := models.XtSelfDrugFlow{
  5352. WarehouseOutId: 0,
  5353. WarehouseOutOrderNumber: warehousing_order,
  5354. WarehousingOrder: warehousing_order,
  5355. DrugId: item.DrugId,
  5356. Number: warehouse.Number,
  5357. ProductDate: warehouse.ProductDate,
  5358. ExpireDate: warehouse.ExpiryDate,
  5359. Count: cha_count,
  5360. Price: warehouse.RetailPrice,
  5361. Status: 1,
  5362. Ctime: item.AdviceDate,
  5363. Mtime: time.Now().Unix(),
  5364. UserOrgId: item.UserOrgId,
  5365. Manufacturer: warehouse.Manufacturer,
  5366. Dealer: warehouse.Dealer,
  5367. BatchNumber: warehouse.BatchNumber,
  5368. MaxUnit: selfBasedrug.MinUnit,
  5369. ConsumableType: 20,
  5370. IsEdit: 1,
  5371. Creator: 0,
  5372. IsSys: 3,
  5373. WarehouseOutDetailId: drugWareInfo.ID,
  5374. AdviceId: item.ID,
  5375. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5376. StorehouseId: 0,
  5377. AdminUserId: creater,
  5378. LastPrice: warehouse.Price,
  5379. StockCount: "",
  5380. WarehousingDetailId: 0,
  5381. OverCount: over_count,
  5382. RetailPrice: item.Price, //手动出库出库价格
  5383. WarehousingId: warehouse.ID,
  5384. SystemTime: item.AdviceDate,
  5385. PatientId: item.PatientId,
  5386. Remark: "保存处方入库数据差",
  5387. OperateTime: time.Now().Unix(),
  5388. }
  5389. if warehouse.RetailPrice == 0 {
  5390. drugflow.Price = item.Price
  5391. }
  5392. service.CreateSelfDrugFlowOne(drugflow, tx)
  5393. var out_count int64
  5394. out_count = in_count - total_count
  5395. //
  5396. //fmt.Println("in_count------------------", in_count)
  5397. //fmt.Println("total_count------------------", total_count)
  5398. //添加出库数量
  5399. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5400. //查询剩余库存
  5401. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5402. var sum_count int64
  5403. for _, its := range stockInfo {
  5404. if its.MaxUnit == selfBasedrug.MaxUnit {
  5405. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5406. }
  5407. sum_count += its.StockMaxNumber + its.StockMinNumber
  5408. }
  5409. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5410. } else {
  5411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5412. return
  5413. }
  5414. }
  5415. }
  5416. }
  5417. }
  5418. }
  5419. }
  5420. tx.Commit()
  5421. if err == nil {
  5422. c.ServeSuccessJSON(map[string]interface{}{
  5423. "msg": "保存成功",
  5424. })
  5425. return
  5426. } else {
  5427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5428. return
  5429. }
  5430. }
  5431. }
  5432. //func (c *HisApiController) EditHisPrescription() {
  5433. // record_date := c.GetString("record_date")
  5434. // patient_id, _ := c.GetInt64("patient_id")
  5435. // reg_type, _ := c.GetInt64("reg_type")
  5436. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5437. // diagnose := c.GetString("diagnose")
  5438. // sick_type, _ := c.GetInt64("sick_type")
  5439. // sick_history := c.GetString("sick_history")
  5440. // doctor_id, _ := c.GetInt64("doctor", 0)
  5441. // department, _ := c.GetInt64("department", 0)
  5442. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5443. // p_type, _ := c.GetInt64("p_type")
  5444. //
  5445. // dataBody := make(map[string]interface{}, 0)
  5446. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5447. // if err != nil {
  5448. // utils.ErrorLog(err.Error())
  5449. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5450. // return
  5451. // }
  5452. //
  5453. // timeLayout := "2006-01-02"
  5454. // loc, _ := time.LoadLocation("Local")
  5455. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5456. // if err != nil {
  5457. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5458. // return
  5459. // }
  5460. // adminInfo := c.GetAdminUserInfo()
  5461. // recordDateTime := theTime.Unix()
  5462. //
  5463. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5464. //
  5465. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5466. // var hpInfo models.HisPrescriptionInfo
  5467. // if info.ID == 0 {
  5468. // var randNum int
  5469. // randNum = rand.Intn(10000) + 1000
  5470. // timestamp := time.Now().Unix()
  5471. // tempTime := time.Unix(timestamp, 0)
  5472. // timeFormat := tempTime.Format("20060102150405")
  5473. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5474. //
  5475. // hpInfo = models.HisPrescriptionInfo{
  5476. // UserOrgId: adminInfo.CurrentOrgId,
  5477. // RecordDate: theTime.Unix(),
  5478. // PatientId: patient_id,
  5479. // Status: 1,
  5480. // Ctime: time.Now().Unix(),
  5481. // Mtime: time.Now().Unix(),
  5482. // Creator: adminInfo.AdminUser.Id,
  5483. // Modifier: adminInfo.AdminUser.Id,
  5484. // Diagnosis: diagnose,
  5485. // SickHistory: sick_history,
  5486. // Departments: department,
  5487. // RegisterType: reg_type,
  5488. // PrescriptionNumber: p_number,
  5489. // PrescriptionStatus: 1,
  5490. // Doctor: role.UserName,
  5491. // DoctorId: doctor_id,
  5492. // SickType: sick_type,
  5493. // PType: p_type,
  5494. // }
  5495. // service.SavePatientPrescriptionInfo(hpInfo)
  5496. //
  5497. // } else {
  5498. // hpInfo = models.HisPrescriptionInfo{
  5499. // ID: info.ID,
  5500. // UserOrgId: adminInfo.CurrentOrgId,
  5501. // RecordDate: info.RecordDate,
  5502. // PatientId: info.PatientId,
  5503. // Status: 1,
  5504. // Ctime: info.Ctime,
  5505. // Mtime: time.Now().Unix(),
  5506. // Creator: info.Creator,
  5507. // Modifier: adminInfo.AdminUser.Id,
  5508. // Diagnosis: diagnose,
  5509. // SickHistory: sick_history,
  5510. // Departments: department,
  5511. // RegisterType: reg_type,
  5512. // PrescriptionNumber: info.PrescriptionNumber,
  5513. // Doctor: role.UserName,
  5514. // PrescriptionStatus: info.PrescriptionStatus,
  5515. // DoctorId: doctor_id,
  5516. // SickType: sick_type,
  5517. // PType: info.PType,
  5518. // }
  5519. // service.SavePatientPrescriptionInfo(hpInfo)
  5520. // }
  5521. //
  5522. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5523. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5524. //
  5525. // if len(prescriptions) > 0 {
  5526. // for _, item := range prescriptions {
  5527. // items := item.(map[string]interface{})
  5528. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5529. // utils.ErrorLog("id")
  5530. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5531. // return
  5532. // }
  5533. // id := int64(items["id"].(float64))
  5534. //
  5535. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5536. // utils.ErrorLog("type")
  5537. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5538. // return
  5539. // }
  5540. // types := int64(items["type"].(float64))
  5541. //
  5542. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5543. // utils.ErrorLog("med_type")
  5544. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5545. // return
  5546. // }
  5547. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5548. //
  5549. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5550. //
  5551. // ctime := time.Now().Unix()
  5552. //
  5553. // prescription := &models.HisPrescription{
  5554. // ID: id,
  5555. // PatientId: patient_id,
  5556. // UserOrgId: adminInfo.CurrentOrgId,
  5557. // RecordDate: recordDateTime,
  5558. // Ctime: ctime,
  5559. // Mtime: ctime,
  5560. // Type: types,
  5561. // Modifier: adminInfo.AdminUser.Id,
  5562. // Creator: adminInfo.AdminUser.Id,
  5563. // Status: 1,
  5564. // Doctor: role.UserName,
  5565. // HisPatientId: his_patient_id,
  5566. // OrderStatus: 1,
  5567. // BatchNumber: "",
  5568. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5569. // PType: hpInfo.PType,
  5570. // MedType: med_type,
  5571. // }
  5572. //
  5573. // if historyPrescription.ID > 0 {
  5574. // prescription.PreTime = historyPrescription.PreTime
  5575. //
  5576. // }
  5577. //
  5578. // service.SaveHisPrescription(prescription)
  5579. //
  5580. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5581. // advices := items["advices"].([]interface{})
  5582. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5583. // groupNo := int64(0)
  5584. // ctime := time.Now().Unix()
  5585. // mtime := ctime
  5586. // if len(advices) > 0 {
  5587. // for _, advice := range advices {
  5588. // var s models.HisDoctorAdviceInfo
  5589. // s.PrescriptionId = prescription.ID
  5590. // s.AdviceType = 2
  5591. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5592. // s.StopState = 2
  5593. // s.ExecutionState = 2
  5594. // s.AdviceDate = recordDateTime
  5595. // s.Status = 1
  5596. // s.UserOrgId = adminInfo.CurrentOrgId
  5597. // s.RecordDate = recordDateTime
  5598. // s.StartTime = prescription.PreTime
  5599. // s.Groupno = groupNo
  5600. // s.CreatedTime = ctime
  5601. // s.UpdatedTime = mtime
  5602. // s.PatientId = patient_id
  5603. // s.HisPatientId = his_patient_id
  5604. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5605. // if errcode > 0 {
  5606. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5607. // return
  5608. // }
  5609. //
  5610. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5611. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5612. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5613. // if s.Price == 0 {
  5614. // s.Price = lastWarehouse.RetailPrice
  5615. // }
  5616. // }
  5617. //
  5618. // service.CreateHisDoctorAdvice(&s)
  5619. // //记录日志
  5620. // byterequest, _ := json.Marshal(s)
  5621. // adviceLog := models.XtDoctorAdviceLog{
  5622. // UserOrgId: s.UserOrgId,
  5623. // PatientId: s.PatientId,
  5624. // AdminUserId: adminInfo.AdminUser.Id,
  5625. // Module: 1,
  5626. // ErrLog: string(byterequest),
  5627. // Status: 1,
  5628. // Ctime: time.Now().Unix(),
  5629. // Mtime: 0,
  5630. // Source: "电脑端his医嘱修改",
  5631. // RecordDate: s.AdviceDate,
  5632. // }
  5633. // service.CreateDoctorAdviceLog(adviceLog)
  5634. // redis := service.RedisClient()
  5635. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5636. // redis.Set(key, "", time.Second)
  5637. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5638. // fmt.Println("keyOne", keyOne)
  5639. // redis.Set(keyOne, "", time.Second)
  5640. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5641. // redis.Set(keySeven, "", time.Second)
  5642. // redis.Close()
  5643. //
  5644. // }
  5645. // }
  5646. // }
  5647. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5648. // projects := items["project"].([]interface{})
  5649. // if len(projects) > 0 {
  5650. // for _, project := range projects {
  5651. // var p models.HisPrescriptionProject
  5652. // p.PrescriptionId = prescription.ID
  5653. // p.Ctime = time.Now().Unix()
  5654. // p.Mtime = time.Now().Unix()
  5655. // p.PatientId = patient_id
  5656. // p.RecordDate = recordDateTime
  5657. // p.UserOrgId = adminInfo.CurrentOrgId
  5658. // p.HisPatientId = his_patient_id
  5659. // p.Status = 1
  5660. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5661. // if errcode > 0 {
  5662. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5663. // return
  5664. // }
  5665. // service.CreateHisProjectTwo(&p)
  5666. //
  5667. // //记录日志
  5668. // byterequest, _ := json.Marshal(p)
  5669. // adviceLog := models.XtDoctorAdviceLog{
  5670. // UserOrgId: p.UserOrgId,
  5671. // PatientId: p.PatientId,
  5672. // AdminUserId: adminInfo.AdminUser.Id,
  5673. // Module: 1,
  5674. // ErrLog: string(byterequest),
  5675. // Status: 1,
  5676. // Ctime: time.Now().Unix(),
  5677. // Mtime: 0,
  5678. // Source: "电脑端his项目修改",
  5679. // RecordDate: p.RecordDate,
  5680. // }
  5681. // service.CreateDoctorAdviceLog(adviceLog)
  5682. // }
  5683. // }
  5684. // }
  5685. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5686. // addition := items["addition"].([]interface{})
  5687. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5688. // ctime := time.Now().Unix()
  5689. // mtime := ctime
  5690. // if len(addition) > 0 {
  5691. // for _, item := range addition {
  5692. // var s models.HisAdditionalCharge
  5693. // s.PrescriptionId = prescription.ID
  5694. // s.Status = 1
  5695. // s.UserOrgId = adminInfo.CurrentOrgId
  5696. // s.RecordDate = recordDateTime
  5697. // s.CreatedTime = ctime
  5698. // s.UpdatedTime = mtime
  5699. // s.PatientId = patient_id
  5700. // s.HisPatientId = his_patient_id
  5701. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5702. // if errcode > 0 {
  5703. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5704. // return
  5705. // }
  5706. // service.CreateAdditionalCharge(&s)
  5707. // }
  5708. // }
  5709. // }
  5710. //
  5711. // }
  5712. // }
  5713. // }
  5714. // if err == nil {
  5715. // c.ServeSuccessJSON(map[string]interface{}{
  5716. // "msg": "保存成功",
  5717. // })
  5718. // return
  5719. //
  5720. // } else {
  5721. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5722. // return
  5723. // }
  5724. //}
  5725. func (c *HisApiController) DeletePrescription() {
  5726. prescription_id, _ := c.GetInt64("id")
  5727. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5728. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5729. ////同步到自备药
  5730. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5731. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5732. if selfPrescriptionOpen.IsOpen == 1 {
  5733. // 在函数结束时处理事务回滚
  5734. db := service.XTWriteDB()
  5735. tx := db.Begin()
  5736. defer func() {
  5737. if r := recover(); r != nil {
  5738. tx.Rollback()
  5739. } else {
  5740. tx.Commit()
  5741. }
  5742. }()
  5743. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5744. for _, item := range advicesList {
  5745. timeStr := time.Now().Format("2006-01-02")
  5746. timeArr := strings.Split(timeStr, "-")
  5747. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5748. total = total + 1
  5749. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5750. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5751. number = number + total
  5752. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5753. operation_time := time.Now().Unix()
  5754. creater := c.GetAdminUserInfo().AdminUser.Id
  5755. //创建一个出库单
  5756. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5757. WarehouseOutOrderNumber: warehousing_out_order,
  5758. OperationTime: operation_time,
  5759. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5760. Creater: creater,
  5761. Ctime: time.Now().Unix(),
  5762. Status: 1,
  5763. WarehouseOutTime: item.AdviceDate,
  5764. Type: 0,
  5765. PatientId: item.PatientId,
  5766. IsCheck: 1,
  5767. }
  5768. //查询今日是否有出库数据
  5769. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5770. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5771. if lastWarehouseOut.ID == 0 {
  5772. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5773. }
  5774. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5775. var total_count int64
  5776. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5777. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5778. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5779. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5780. }
  5781. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5782. total_count += prescribingNumberSeven
  5783. }
  5784. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5785. total_count += prescribingNumberSeven
  5786. }
  5787. //出库
  5788. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5789. WarehouseOutOrderNumber: warehousing_out_order,
  5790. WarehouseOutId: lastWarehouseOut.ID,
  5791. DrugId: item.DrugId,
  5792. Count: total_count,
  5793. Price: 0,
  5794. TotalPrice: 0,
  5795. Status: 1,
  5796. Ctime: item.AdviceDate,
  5797. Mtime: item.AdviceDate,
  5798. Remark: "",
  5799. OrgId: item.UserOrgId,
  5800. Type: 0,
  5801. Manufacturer: selfBasedrug.Manufacturer,
  5802. Dealer: selfBasedrug.Dealer,
  5803. RetailPrice: 0,
  5804. RetailTotalPrice: 0,
  5805. CountUnit: selfBasedrug.MinUnit,
  5806. ExpiryDate: 0,
  5807. ProductDate: 0,
  5808. Number: "",
  5809. BatchNumber: "",
  5810. IsSys: 1,
  5811. WarehouseInfoId: 0,
  5812. AdminUserId: 0,
  5813. StockCount: "",
  5814. IsCheck: 1,
  5815. SysRecordTime: item.AdviceDate,
  5816. PatientId: item.PatientId,
  5817. ClassType: "",
  5818. AdviceId: item.ID,
  5819. }
  5820. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5821. }
  5822. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5823. for _, it := range warehousingOutInfo {
  5824. //查询今日是否有出库数据
  5825. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5826. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5827. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5828. //出库逻辑
  5829. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5830. //查询剩余库存
  5831. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5832. var sum_count int64
  5833. for _, its := range stockInfo {
  5834. if its.MaxUnit == medical.MaxUnit {
  5835. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5836. }
  5837. sum_count += its.StockMaxNumber + its.StockMinNumber
  5838. }
  5839. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5840. }
  5841. }
  5842. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5843. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5844. //耗材保存处方出库
  5845. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5846. //已收费和已发药限制逻辑
  5847. isCharge := false
  5848. isMedicine := false
  5849. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5850. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5851. if new_prescription.IsMedicine == 1 {
  5852. isMedicine = true
  5853. }
  5854. for _, item := range new_prescriptions {
  5855. if item.OrderStatus == 4 {
  5856. isCharge = true
  5857. }
  5858. }
  5859. if p_err != nil {
  5860. if new_prescription.ID > 0 {
  5861. if new_prescription.OrderStatus == 2 {
  5862. isCharge = true
  5863. }
  5864. }
  5865. }
  5866. for _, item := range advices {
  5867. if item.IsMedicine == 1 {
  5868. isMedicine = true
  5869. }
  5870. }
  5871. if isCharge {
  5872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5873. return
  5874. }
  5875. if isMedicine {
  5876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5877. return
  5878. }
  5879. //已收费和已发药限制逻辑
  5880. if len(projects) > 0 {
  5881. for _, item := range projects {
  5882. service.DeletePrintInfo(item.ID) //删除打印信息
  5883. if goodOutConfig.IsOpen != 1 {
  5884. if stockConfig.IsOpen == 1 {
  5885. if item.Type == 3 && item.IsOut == 1 {
  5886. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5887. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5888. good.Total = good.Total + f_count
  5889. service.UpdateGoodInfo(&good)
  5890. operation_time := time.Now().Unix()
  5891. creater := c.GetAdminUserInfo().AdminUser.Id
  5892. //创建退库单
  5893. timeStr := time.Now().Format("2006-01-02")
  5894. timeArr := strings.Split(timeStr, "-")
  5895. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5896. total = total + 1
  5897. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5898. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5899. cancelStock := models.CancelStock{
  5900. OrderNumber: orderNumber,
  5901. OperaTime: operation_time,
  5902. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5903. Creater: creater,
  5904. Ctime: time.Now().Unix(),
  5905. Status: 1,
  5906. ReturnTime: item.RecordDate,
  5907. Type: 1,
  5908. StorehouseId: houseConfig.StorehouseOutInfo,
  5909. IsCheck: 1,
  5910. }
  5911. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5912. if msgerrkonde == gorm.ErrRecordNotFound {
  5913. service.AddSigleCancelStock(&cancelStock)
  5914. }
  5915. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5916. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5917. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5918. //查询该耗材是否出库
  5919. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5920. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5921. deaerler, _ := service.GetDealerById(info.Dealer)
  5922. var total_count int64
  5923. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5924. total_count += count
  5925. if info.ID > 0 {
  5926. if info.Count >= total_count {
  5927. //回退库存
  5928. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5929. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5930. var flush_count int64
  5931. for _, it := range goodList {
  5932. flush_count += it.StockCount
  5933. }
  5934. cancelStockInfo := models.CancelStockInfo{
  5935. GoodId: item.ProjectId,
  5936. CancelStockId: cancel.ID,
  5937. GoodTypeId: good.GoodTypeId,
  5938. Count: prescribingNumber,
  5939. Price: info.Price,
  5940. Total: 0,
  5941. ProductDate: info.ProductDate,
  5942. ExpiryDate: info.ExpiryDate,
  5943. Ctime: time.Now().Unix(),
  5944. Status: 1,
  5945. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5946. OrderNumber: cancel.OrderNumber,
  5947. Type: 0,
  5948. Dealer: deaerler.DealerName,
  5949. Manufacturer: manufacturer.ManufacturerName,
  5950. Number: info.Number,
  5951. RegisterAccount: "",
  5952. Remark: "",
  5953. WarehouseInfoId: info.WarehouseInfotId,
  5954. PatientId: info.PatientId,
  5955. RecordDate: info.SysRecordTime,
  5956. StorehouseId: houseConfig.StorehouseOutInfo,
  5957. IsCheck: 1,
  5958. }
  5959. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5960. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5961. flow := models.VmStockFlow{
  5962. WarehousingId: info.WarehouseInfotId,
  5963. GoodId: item.ProjectId,
  5964. Number: info.Number,
  5965. LicenseNumber: info.LicenseNumber,
  5966. Count: prescribingNumber,
  5967. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5968. PatientId: item.PatientId,
  5969. SystemTime: info.SysRecordTime,
  5970. ConsumableType: 7,
  5971. IsSys: 0,
  5972. WarehousingOrder: "",
  5973. WarehouseOutId: info.WarehouseOutId,
  5974. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5975. IsEdit: 0,
  5976. CancelStockId: cancel.ID,
  5977. CancelOrderNumber: cancel.OrderNumber,
  5978. Manufacturer: manufacturer.ID,
  5979. Dealer: 0,
  5980. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5981. UpdateCreator: 0,
  5982. Status: 1,
  5983. Ctime: time.Now().Unix(),
  5984. Mtime: 0,
  5985. Price: info.Price,
  5986. WarehousingDetailId: info.WarehouseInfotId,
  5987. WarehouseOutDetailId: info.ID,
  5988. CancelOutDetailId: cancelInfo.ID,
  5989. ProductDate: info.ProductDate,
  5990. ExpireDate: info.ExpiryDate,
  5991. StorehouseId: houseConfig.StorehouseOutInfo,
  5992. OverCount: flush_count,
  5993. OperateTime: time.Now().Unix(),
  5994. }
  5995. service.CreateStockFlowOne(flow)
  5996. //退库数量增加
  5997. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5998. //出库数量减少
  5999. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6000. }
  6001. if info.Count < total_count {
  6002. //回退库存
  6003. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6004. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6005. var flush_count int64
  6006. for _, it := range goodList {
  6007. flush_count += it.StockCount
  6008. }
  6009. cancelStockInfo := models.CancelStockInfo{
  6010. GoodId: item.ProjectId,
  6011. CancelStockId: cancel.ID,
  6012. GoodTypeId: good.GoodTypeId,
  6013. Count: info.Count,
  6014. Price: info.Price,
  6015. Total: 0,
  6016. ProductDate: info.ProductDate,
  6017. ExpiryDate: info.ExpiryDate,
  6018. Ctime: time.Now().Unix(),
  6019. Status: 1,
  6020. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6021. OrderNumber: cancel.OrderNumber,
  6022. Type: 0,
  6023. Dealer: deaerler.DealerName,
  6024. Manufacturer: manufacturer.ManufacturerName,
  6025. Number: info.Number,
  6026. RegisterAccount: "",
  6027. Remark: "",
  6028. WarehouseInfoId: info.WarehouseInfotId,
  6029. PatientId: info.PatientId,
  6030. RecordDate: info.SysRecordTime,
  6031. StorehouseId: houseConfig.StorehouseOutInfo,
  6032. IsCheck: 1,
  6033. }
  6034. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6035. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6036. flow := models.VmStockFlow{
  6037. WarehousingId: info.WarehouseInfotId,
  6038. GoodId: item.ProjectId,
  6039. Number: info.Number,
  6040. LicenseNumber: info.LicenseNumber,
  6041. Count: info.Count,
  6042. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6043. PatientId: item.PatientId,
  6044. SystemTime: info.SysRecordTime,
  6045. ConsumableType: 7,
  6046. IsSys: 0,
  6047. WarehousingOrder: "",
  6048. WarehouseOutId: info.WarehouseOutId,
  6049. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6050. IsEdit: 0,
  6051. CancelStockId: cancel.ID,
  6052. CancelOrderNumber: cancel.OrderNumber,
  6053. Manufacturer: manufacturer.ID,
  6054. Dealer: 0,
  6055. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6056. UpdateCreator: 0,
  6057. Status: 1,
  6058. Ctime: time.Now().Unix(),
  6059. Mtime: 0,
  6060. Price: info.Price,
  6061. WarehousingDetailId: info.WarehouseInfotId,
  6062. WarehouseOutDetailId: info.ID,
  6063. CancelOutDetailId: cancelInfo.ID,
  6064. ProductDate: info.ProductDate,
  6065. ExpireDate: info.ExpiryDate,
  6066. StorehouseId: houseConfig.StorehouseOutInfo,
  6067. OverCount: flush_count,
  6068. OperateTime: time.Now().Unix(),
  6069. }
  6070. service.CreateStockFlowOne(flow)
  6071. //退库数量增加
  6072. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6073. //出库数量减少
  6074. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6075. }
  6076. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6077. var flush_count int64
  6078. for _, it := range goodList {
  6079. flush_count += it.StockCount
  6080. }
  6081. //查询已出库数量
  6082. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6083. if prescribingNumber < dialysisInfo.Count {
  6084. //改变数量
  6085. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6086. }
  6087. if prescribingNumber >= dialysisInfo.Count {
  6088. //删除出库表
  6089. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6090. }
  6091. //更新库存
  6092. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6093. //更新基础库库存
  6094. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6095. }
  6096. }
  6097. }
  6098. }
  6099. //保存耗材出库
  6100. if goodOutConfig.IsOpen == 1 {
  6101. if item.Type == 3 {
  6102. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6103. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6104. good.Total = good.Total + f_count
  6105. service.UpdateGoodInfo(&good)
  6106. operation_time := time.Now().Unix()
  6107. creater := c.GetAdminUserInfo().AdminUser.Id
  6108. //创建退库单
  6109. timeStr := time.Now().Format("2006-01-02")
  6110. timeArr := strings.Split(timeStr, "-")
  6111. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6112. total = total + 1
  6113. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6114. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6115. cancelStock := models.CancelStock{
  6116. OrderNumber: orderNumber,
  6117. OperaTime: operation_time,
  6118. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6119. Creater: creater,
  6120. Ctime: time.Now().Unix(),
  6121. Status: 1,
  6122. ReturnTime: item.RecordDate,
  6123. Type: 1,
  6124. StorehouseId: houseConfig.StorehouseOutInfo,
  6125. IsCheck: 1,
  6126. }
  6127. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6128. if msgerrkonde == gorm.ErrRecordNotFound {
  6129. service.AddSigleCancelStock(&cancelStock)
  6130. }
  6131. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6132. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6133. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6134. //查询该耗材是否出库
  6135. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6136. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6137. deaerler, _ := service.GetDealerById(info.Dealer)
  6138. var total_count int64
  6139. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6140. total_count += count
  6141. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6142. var flush_count int64
  6143. for _, it := range goodList {
  6144. flush_count += it.StockCount
  6145. }
  6146. fmt.Println("历史出库数据", info.Count)
  6147. fmt.Println("出库数量", total_count)
  6148. if info.ID > 0 {
  6149. cancelStockInfo := models.CancelStockInfo{
  6150. GoodId: item.ProjectId,
  6151. CancelStockId: cancel.ID,
  6152. GoodTypeId: good.GoodTypeId,
  6153. Count: prescribingNumber,
  6154. Price: info.Price,
  6155. Total: 0,
  6156. ProductDate: info.ProductDate,
  6157. ExpiryDate: info.ExpiryDate,
  6158. Ctime: time.Now().Unix(),
  6159. Status: 1,
  6160. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6161. OrderNumber: cancel.OrderNumber,
  6162. Type: 0,
  6163. Dealer: deaerler.DealerName,
  6164. Manufacturer: manufacturer.ManufacturerName,
  6165. Number: info.Number,
  6166. RegisterAccount: "",
  6167. Remark: "",
  6168. WarehouseInfoId: info.WarehouseInfotId,
  6169. PatientId: info.PatientId,
  6170. RecordDate: info.SysRecordTime,
  6171. StorehouseId: houseConfig.StorehouseOutInfo,
  6172. IsCheck: 1,
  6173. }
  6174. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6175. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6176. //查询出库数量
  6177. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6178. //出库数据 大于 退库数量
  6179. if len(list) > 0 {
  6180. for _, it := range list {
  6181. //回退库存
  6182. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6183. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6184. var flush_count_one int64
  6185. for _, it := range goodList {
  6186. flush_count_one += it.StockCount
  6187. }
  6188. //查询该批次是否有退库数据
  6189. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6190. creater := c.GetAdminUserInfo().AdminUser.Id
  6191. flow := models.VmStockFlow{
  6192. WarehousingId: it.WarehouseInfotId,
  6193. GoodId: it.GoodId,
  6194. Number: it.Number,
  6195. LicenseNumber: it.LicenseNumber,
  6196. Count: it.Count,
  6197. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6198. PatientId: it.PatientId,
  6199. SystemTime: it.SysRecordTime,
  6200. ConsumableType: 7,
  6201. IsSys: 0,
  6202. WarehousingOrder: "",
  6203. WarehouseOutId: it.WarehouseOutId,
  6204. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6205. IsEdit: 0,
  6206. CancelStockId: cancel.ID,
  6207. CancelOrderNumber: cancel.OrderNumber,
  6208. Manufacturer: manufacturer.ID,
  6209. Dealer: 0,
  6210. Creator: creater,
  6211. UpdateCreator: 0,
  6212. Status: 1,
  6213. Ctime: time.Now().Unix(),
  6214. Mtime: 0,
  6215. Price: it.Price,
  6216. WarehousingDetailId: it.WarehouseInfotId,
  6217. WarehouseOutDetailId: it.ID,
  6218. CancelOutDetailId: cancelInfo.ID,
  6219. ProductDate: it.ProductDate,
  6220. ExpireDate: it.ExpiryDate,
  6221. StorehouseId: houseConfig.StorehouseOutInfo,
  6222. OverCount: flush_count_one,
  6223. }
  6224. service.CreateStockFlowOne(flow)
  6225. //if flow.ID > 0 {
  6226. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6227. //}
  6228. }
  6229. }
  6230. //flow := models.VmStockFlow{
  6231. // WarehousingId: info.WarehouseInfotId,
  6232. // GoodId: item.ProjectId,
  6233. // Number: info.Number,
  6234. // LicenseNumber: info.LicenseNumber,
  6235. // Count: prescribingNumber,
  6236. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6237. // PatientId: item.PatientId,
  6238. // SystemTime: info.SysRecordTime,
  6239. // ConsumableType: 7,
  6240. // IsSys: 0,
  6241. // WarehousingOrder: "",
  6242. // WarehouseOutId: info.WarehouseOutId,
  6243. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6244. // IsEdit: 0,
  6245. // CancelStockId: cancel.ID,
  6246. // CancelOrderNumber: cancel.OrderNumber,
  6247. // Manufacturer: manufacturer.ID,
  6248. // Dealer: 0,
  6249. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6250. // UpdateCreator: 0,
  6251. // Status: 1,
  6252. // Ctime: time.Now().Unix(),
  6253. // Mtime: 0,
  6254. // Price: info.Price,
  6255. // WarehousingDetailId: info.WarehouseInfotId,
  6256. // WarehouseOutDetailId: info.ID,
  6257. // CancelOutDetailId: cancelInfo.ID,
  6258. // ProductDate: info.ProductDate,
  6259. // ExpireDate: info.ExpiryDate,
  6260. // StorehouseId: houseConfig.StorehouseOutInfo,
  6261. // OverCount: flush_count,
  6262. //}
  6263. //service.CreateStockFlowOne(flow)
  6264. //退库数量增加
  6265. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6266. //出库数量减少
  6267. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6268. //查询已出库数量
  6269. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6270. if prescribingNumber < dialysisInfo.Count {
  6271. //改变数量
  6272. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6273. }
  6274. if prescribingNumber >= dialysisInfo.Count {
  6275. //删除出库表
  6276. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6277. }
  6278. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6279. var flush_count_one int64
  6280. for _, it := range goodList {
  6281. flush_count_one += it.StockCount
  6282. }
  6283. //更新库存
  6284. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6285. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6286. //更新基础库库存
  6287. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6288. }
  6289. }
  6290. }
  6291. }
  6292. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6293. fmt.Println(err)
  6294. }
  6295. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6296. fmt.Println(err)
  6297. if len(advices) > 0 {
  6298. for _, item := range advices {
  6299. redis := service.RedisClient()
  6300. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6301. redis.Set(keyFive, "", time.Second)
  6302. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6303. redis.Set(keyOne, "", time.Second)
  6304. redis.Close()
  6305. }
  6306. }
  6307. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6308. if len(advices) > 0 {
  6309. for _, item := range advices {
  6310. creater := c.GetAdminUserInfo().AdminUser.Id
  6311. service.DrugAutoAddCancelInfo(item, creater)
  6312. }
  6313. }
  6314. } else {
  6315. if drugOutConfig.IsOpen == 1 {
  6316. if len(advices) > 0 {
  6317. for _, item := range advices {
  6318. creater := c.GetAdminUserInfo().AdminUser.Id
  6319. service.DrugAutoAddCancelInfo(item, creater)
  6320. }
  6321. }
  6322. } else {
  6323. if len(advices) > 0 {
  6324. for _, item := range advices {
  6325. creater := c.GetAdminUserInfo().AdminUser.Id
  6326. service.DrugAutoAddCancelInfo(item, creater)
  6327. }
  6328. }
  6329. }
  6330. }
  6331. c.ServeSuccessJSON(map[string]interface{}{
  6332. "msg": "删除成功",
  6333. })
  6334. return
  6335. }
  6336. func (c *HisApiController) DeleteDoctorAdvice() {
  6337. id, _ := c.GetInt64("id")
  6338. advice, _ := service.GetHisDoctorAdvicesById(id)
  6339. ////同步到自备药
  6340. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6341. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6342. if selfPrescriptionOpen.IsOpen == 1 {
  6343. db := service.XTWriteDB()
  6344. tx := db.Begin()
  6345. defer func() {
  6346. if r := recover(); r != nil {
  6347. tx.Rollback()
  6348. } else {
  6349. tx.Commit()
  6350. }
  6351. }()
  6352. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6353. var total_count int64
  6354. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6355. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6356. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6357. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6358. }
  6359. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6360. total_count += prescribingNumberSeven
  6361. }
  6362. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6363. total_count += prescribingNumberSeven
  6364. }
  6365. timeStr := time.Now().Format("2006-01-02")
  6366. timeArr := strings.Split(timeStr, "-")
  6367. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6368. total = total + 1
  6369. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6370. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6371. number = number + total
  6372. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6373. operation_time := time.Now().Unix()
  6374. creater := c.GetAdminUserInfo().AdminUser.Id
  6375. //创建一个出库单
  6376. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6377. WarehouseOutOrderNumber: warehousing_out_order,
  6378. OperationTime: operation_time,
  6379. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6380. Creater: creater,
  6381. Ctime: time.Now().Unix(),
  6382. Status: 1,
  6383. WarehouseOutTime: advice.AdviceDate,
  6384. Type: 0,
  6385. PatientId: advice.PatientId,
  6386. IsCheck: 1,
  6387. }
  6388. //查询今日是否有出库数据
  6389. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6390. if lastWarehouseOut.ID == 0 {
  6391. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6392. }
  6393. //出库
  6394. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6395. WarehouseOutId: lastWarehouseOut.ID,
  6396. WarehouseOutOrderNumber: warehousing_out_order,
  6397. DrugId: advice.DrugId,
  6398. Count: total_count,
  6399. Price: 0,
  6400. TotalPrice: 0,
  6401. Status: 1,
  6402. Ctime: advice.AdviceDate,
  6403. Mtime: advice.AdviceDate,
  6404. Remark: "",
  6405. OrgId: advice.UserOrgId,
  6406. Type: 0,
  6407. Manufacturer: selfBasedrug.Manufacturer,
  6408. Dealer: selfBasedrug.Dealer,
  6409. RetailPrice: 0,
  6410. RetailTotalPrice: 0,
  6411. CountUnit: advice.PrescribingNumberUnit,
  6412. ExpiryDate: 0,
  6413. ProductDate: 0,
  6414. Number: "",
  6415. BatchNumber: "",
  6416. IsSys: 0,
  6417. WarehouseInfoId: 0,
  6418. AdminUserId: 0,
  6419. StockCount: "",
  6420. IsCheck: 1,
  6421. SysRecordTime: advice.AdviceDate,
  6422. PatientId: advice.PatientId,
  6423. AdviceId: advice.ID,
  6424. ClassType: "",
  6425. }
  6426. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6427. for _, it := range warehousingOutInfo {
  6428. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6429. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6430. //出库逻辑
  6431. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6432. //查询剩余库存
  6433. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6434. var sum_count int64
  6435. for _, its := range stockInfo {
  6436. if its.MaxUnit == medical.MaxUnit {
  6437. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6438. }
  6439. sum_count += its.StockMaxNumber + its.StockMinNumber
  6440. }
  6441. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6442. }
  6443. }
  6444. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6445. //已收费和已发药的限制逻辑
  6446. isCharge := false
  6447. isMedicine := false
  6448. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6449. //获取今天该患者所有处方,判断是否发药或者收费
  6450. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6451. //for _, item := range new_prescriptions {
  6452. if new_prescription.IsMedicine == 1 {
  6453. isMedicine = true
  6454. }
  6455. //}
  6456. for _, item := range new_prescriptions {
  6457. if item.OrderStatus == 4 {
  6458. isCharge = true
  6459. }
  6460. }
  6461. if isMedicine {
  6462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6463. return
  6464. }
  6465. if isCharge {
  6466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6467. return
  6468. }
  6469. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6470. for _, item := range advices {
  6471. if item.IsMedicine == 1 {
  6472. isMedicine = true
  6473. }
  6474. }
  6475. if isMedicine {
  6476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6477. return
  6478. }
  6479. if new_prescription.ID > 0 {
  6480. if new_prescription.OrderStatus == 2 {
  6481. isCharge = true
  6482. }
  6483. }
  6484. if isCharge {
  6485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6486. return
  6487. }
  6488. //已收费和已发药的限制逻辑
  6489. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6490. redis := service.RedisClient()
  6491. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6492. redis.Set(keyFive, "", time.Second)
  6493. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6494. redis.Set(keyOne, "", time.Second)
  6495. defer redis.Close()
  6496. if err == nil {
  6497. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6498. //查询是否在处方中出库
  6499. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6500. if openConfig.IsOpen != 1 {
  6501. //判断该医嘱是否执行了
  6502. if advice.ExecutionState == 1 {
  6503. creater := c.GetAdminUserInfo().AdminUser.Id
  6504. service.DrugAutoAddCancelInfo(&advice, creater)
  6505. }
  6506. }
  6507. //开启保存处方扣减功能
  6508. if openConfig.IsOpen == 1 {
  6509. creater := c.GetAdminUserInfo().AdminUser.Id
  6510. service.DrugAutoAddCancelInfo(&advice, creater)
  6511. }
  6512. } else {
  6513. if drugOutConfig.IsOpen == 1 {
  6514. //查询是否在处方中出库
  6515. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6516. if openConfig.IsOpen != 1 {
  6517. //判断该医嘱是否执行了
  6518. if advice.ExecutionState == 1 {
  6519. creater := c.GetAdminUserInfo().AdminUser.Id
  6520. service.DrugAutoAddCancelInfo(&advice, creater)
  6521. }
  6522. }
  6523. //开启保存处方扣减功能
  6524. if openConfig.IsOpen == 1 {
  6525. creater := c.GetAdminUserInfo().AdminUser.Id
  6526. service.DrugAutoAddCancelInfo(&advice, creater)
  6527. }
  6528. } else {
  6529. //判断该医嘱是否执行了
  6530. if advice.ExecutionState == 1 {
  6531. creater := c.GetAdminUserInfo().AdminUser.Id
  6532. service.DrugAutoAddCancelInfo(&advice, creater)
  6533. }
  6534. }
  6535. }
  6536. c.ServeSuccessJSON(map[string]interface{}{
  6537. "msg": "删除成功",
  6538. })
  6539. return
  6540. } else {
  6541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6542. return
  6543. }
  6544. }
  6545. func (c *HisApiController) DeleteProject() {
  6546. id, _ := c.GetInt64("id")
  6547. adminInfo := c.GetAdminUserInfo()
  6548. project, _ := service.GetHisProjectByID(id)
  6549. // var consumable models.DialysisBeforePrepare
  6550. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6551. //耗材保存处方出库
  6552. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6553. isCharge := false
  6554. isMedicine := false
  6555. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6556. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6557. for _, item := range new_prescriptions {
  6558. if item.IsMedicine == 1 {
  6559. isMedicine = true
  6560. }
  6561. }
  6562. for _, item := range new_prescriptions {
  6563. if item.OrderStatus == 4 {
  6564. isCharge = true
  6565. }
  6566. }
  6567. if isMedicine {
  6568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6569. return
  6570. }
  6571. if isCharge {
  6572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6573. return
  6574. }
  6575. if new_prescription.ID > 0 {
  6576. if new_prescription.OrderStatus == 2 {
  6577. isCharge = true
  6578. }
  6579. }
  6580. if isCharge {
  6581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6582. return
  6583. }
  6584. service.DeletePrintInfo(id)
  6585. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6586. label.Status = 0
  6587. service.CreateHisLabelRecordTwo(&label)
  6588. fmt.Println(goodOutConfig.IsOpen)
  6589. if goodOutConfig.IsOpen != 1 {
  6590. if stockConfig.IsOpen == 1 {
  6591. if project.Type == 2 {
  6592. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6593. fmt.Println(err)
  6594. }
  6595. if project.Type == 3 && project.IsOut == 1 {
  6596. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6597. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6598. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6599. operation_time := time.Now().Unix()
  6600. creater := adminInfo.AdminUser.Id
  6601. //创建退库单
  6602. timeStr := time.Now().Format("2006-01-02")
  6603. timeArr := strings.Split(timeStr, "-")
  6604. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6605. total = total + 1
  6606. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6607. cancelStock := models.CancelStock{
  6608. OrderNumber: orderNumber,
  6609. OperaTime: operation_time,
  6610. OrgId: adminInfo.CurrentOrgId,
  6611. Creater: creater,
  6612. Ctime: time.Now().Unix(),
  6613. Status: 1,
  6614. ReturnTime: project.RecordDate,
  6615. Type: 1,
  6616. StorehouseId: houseConfig.StorehouseOutInfo,
  6617. IsCheck: 1,
  6618. }
  6619. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6620. if msgerrkonde == gorm.ErrRecordNotFound {
  6621. service.AddSigleCancelStock(&cancelStock)
  6622. }
  6623. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6624. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6625. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6626. //查询是否有出库
  6627. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6628. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6629. deaerler, _ := service.GetDealerById(info.Dealer)
  6630. if info.ID > 0 {
  6631. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6632. if info.Count >= prescribingNumber {
  6633. cancelStockInfo := models.CancelStockInfo{
  6634. GoodId: project.ProjectId,
  6635. CancelStockId: cancel.ID,
  6636. GoodTypeId: good.GoodTypeId,
  6637. Count: prescribingNumber,
  6638. Price: info.Price,
  6639. Total: 0,
  6640. ProductDate: info.ProductDate,
  6641. ExpiryDate: info.ExpiryDate,
  6642. Ctime: time.Now().Unix(),
  6643. Status: 1,
  6644. OrgId: adminInfo.CurrentOrgId,
  6645. OrderNumber: cancel.OrderNumber,
  6646. Type: 0,
  6647. Dealer: deaerler.DealerName,
  6648. Manufacturer: manufacturer.ManufacturerName,
  6649. Number: info.Number,
  6650. RegisterAccount: "",
  6651. Remark: "",
  6652. WarehouseInfoId: info.WarehouseInfotId,
  6653. PatientId: info.PatientId,
  6654. RecordDate: info.SysRecordTime,
  6655. StorehouseId: houseConfig.StorehouseOutInfo,
  6656. IsCheck: 1,
  6657. }
  6658. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6659. //回退库存
  6660. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6661. //退库数量增加
  6662. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6663. //出库数量减少
  6664. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6665. }
  6666. if info.Count < prescribingNumber {
  6667. cancelStockInfo := models.CancelStockInfo{
  6668. GoodId: project.ProjectId,
  6669. CancelStockId: cancel.ID,
  6670. GoodTypeId: good.GoodTypeId,
  6671. Count: info.Count,
  6672. Price: info.Price,
  6673. Total: 0,
  6674. ProductDate: info.ProductDate,
  6675. ExpiryDate: info.ExpiryDate,
  6676. Ctime: time.Now().Unix(),
  6677. Status: 1,
  6678. OrgId: adminInfo.CurrentOrgId,
  6679. OrderNumber: cancel.OrderNumber,
  6680. Type: 0,
  6681. Dealer: deaerler.DealerName,
  6682. Manufacturer: manufacturer.ManufacturerName,
  6683. Number: info.Number,
  6684. RegisterAccount: "",
  6685. Remark: "",
  6686. WarehouseInfoId: info.WarehouseInfotId,
  6687. PatientId: info.PatientId,
  6688. RecordDate: info.SysRecordTime,
  6689. StorehouseId: houseConfig.StorehouseOutInfo,
  6690. IsCheck: 1,
  6691. }
  6692. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6693. //回退库存
  6694. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6695. //退库数量增加
  6696. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6697. //出库数量减少
  6698. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6699. }
  6700. //查询剩余库存
  6701. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6702. var over_count int64
  6703. for _, it := range goodList {
  6704. over_count += it.StockCount
  6705. }
  6706. //出库数据 大于 退库数量
  6707. if info.Count >= prescribingNumber {
  6708. flow := models.VmStockFlow{
  6709. WarehousingId: info.WarehouseInfotId,
  6710. GoodId: project.ProjectId,
  6711. Number: info.Number,
  6712. LicenseNumber: info.LicenseNumber,
  6713. Count: prescribingNumber,
  6714. UserOrgId: adminInfo.CurrentOrgId,
  6715. PatientId: project.PatientId,
  6716. SystemTime: info.SysRecordTime,
  6717. ConsumableType: 7,
  6718. IsSys: 0,
  6719. WarehousingOrder: "",
  6720. WarehouseOutId: info.WarehouseOutId,
  6721. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6722. IsEdit: 0,
  6723. CancelStockId: cancel.ID,
  6724. CancelOrderNumber: cancel.OrderNumber,
  6725. Manufacturer: manufacturer.ID,
  6726. Dealer: 0,
  6727. Creator: adminInfo.AdminUser.Id,
  6728. UpdateCreator: 0,
  6729. Status: 1,
  6730. Ctime: time.Now().Unix(),
  6731. Mtime: 0,
  6732. Price: info.Price,
  6733. WarehousingDetailId: info.WarehouseInfotId,
  6734. WarehouseOutDetailId: info.ID,
  6735. CancelOutDetailId: cancelInfo.ID,
  6736. ProductDate: info.ProductDate,
  6737. ExpireDate: info.ExpiryDate,
  6738. StorehouseId: houseConfig.StorehouseOutInfo,
  6739. OverCount: over_count,
  6740. OperateTime: time.Now().Unix(),
  6741. }
  6742. service.CreateStockFlowOne(flow)
  6743. }
  6744. //出库数据小于退库数据
  6745. if info.Count < prescribingNumber {
  6746. flow := models.VmStockFlow{
  6747. WarehousingId: info.WarehouseInfotId,
  6748. GoodId: project.ProjectId,
  6749. Number: info.Number,
  6750. LicenseNumber: info.LicenseNumber,
  6751. Count: info.Count,
  6752. UserOrgId: adminInfo.CurrentOrgId,
  6753. PatientId: project.PatientId,
  6754. SystemTime: info.SysRecordTime,
  6755. ConsumableType: 7,
  6756. IsSys: 0,
  6757. WarehousingOrder: "",
  6758. WarehouseOutId: info.WarehouseOutId,
  6759. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6760. IsEdit: 0,
  6761. CancelStockId: cancel.ID,
  6762. CancelOrderNumber: cancel.OrderNumber,
  6763. Manufacturer: manufacturer.ID,
  6764. Dealer: 0,
  6765. Creator: adminInfo.AdminUser.Id,
  6766. UpdateCreator: 0,
  6767. Status: 1,
  6768. Ctime: time.Now().Unix(),
  6769. Mtime: 0,
  6770. Price: info.Price,
  6771. WarehousingDetailId: info.WarehouseInfotId,
  6772. WarehouseOutDetailId: info.ID,
  6773. CancelOutDetailId: cancelInfo.ID,
  6774. ProductDate: info.ProductDate,
  6775. ExpireDate: info.ExpiryDate,
  6776. StorehouseId: houseConfig.StorehouseOutInfo,
  6777. OverCount: over_count,
  6778. OperateTime: time.Now().Unix(),
  6779. }
  6780. service.CreateStockFlowOne(flow)
  6781. }
  6782. //查询已出库数量
  6783. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6784. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6785. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6786. if prescribingNumber < dialysisInfo.Count {
  6787. //改变数量
  6788. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6789. }
  6790. if prescribingNumber >= dialysisInfo.Count {
  6791. //删除出库表
  6792. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6793. }
  6794. //更新剩余库存
  6795. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6796. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6797. var total_count_one int64
  6798. for _, it := range stockList {
  6799. total_count_one += it.StockCount
  6800. }
  6801. //基础库插入数据
  6802. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6803. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6804. var flush_count int64
  6805. for _, it := range goodListOne {
  6806. flush_count += it.StockCount
  6807. }
  6808. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6809. if errs != nil {
  6810. goodErrcode := models.XtGoodErrcode{
  6811. UserOrgId: project.UserOrgId,
  6812. Errcode: "手动出库更新剩余出库失败",
  6813. GoodId: project.ProjectId,
  6814. Status: 1,
  6815. Ctime: time.Now().Unix(),
  6816. Mtime: 0,
  6817. Count: 0,
  6818. StockCount: 0,
  6819. Creater: creater,
  6820. BatchNumberId: 0,
  6821. WarehouseOutId: 0,
  6822. }
  6823. service.CreateGoodErrcode(goodErrcode)
  6824. }
  6825. }
  6826. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6827. fmt.Println(err)
  6828. } else {
  6829. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6830. fmt.Println(err)
  6831. }
  6832. } else {
  6833. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6834. fmt.Println(err)
  6835. }
  6836. }
  6837. //保存处方出库
  6838. if goodOutConfig.IsOpen == 1 {
  6839. if project.Type == 3 {
  6840. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6841. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6842. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6843. operation_time := time.Now().Unix()
  6844. creater := adminInfo.AdminUser.Id
  6845. //创建退库单
  6846. timeStr := time.Now().Format("2006-01-02")
  6847. timeArr := strings.Split(timeStr, "-")
  6848. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6849. total = total + 1
  6850. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6851. cancelStock := models.CancelStock{
  6852. OrderNumber: orderNumber,
  6853. OperaTime: operation_time,
  6854. OrgId: adminInfo.CurrentOrgId,
  6855. Creater: creater,
  6856. Ctime: time.Now().Unix(),
  6857. Status: 1,
  6858. ReturnTime: project.RecordDate,
  6859. Type: 1,
  6860. StorehouseId: houseConfig.StorehouseOutInfo,
  6861. IsCheck: 1,
  6862. }
  6863. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6864. if msgerrkonde == gorm.ErrRecordNotFound {
  6865. service.AddSigleCancelStock(&cancelStock)
  6866. }
  6867. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6868. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6869. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6870. //获取出库数据
  6871. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6872. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6873. deaerler, _ := service.GetDealerById(info.Dealer)
  6874. if info.ID > 0 {
  6875. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6876. if info.Count >= prescribingNumber {
  6877. cancelStockInfo := models.CancelStockInfo{
  6878. GoodId: project.ProjectId,
  6879. CancelStockId: cancel.ID,
  6880. GoodTypeId: good.GoodTypeId,
  6881. Count: prescribingNumber,
  6882. Price: info.Price,
  6883. Total: 0,
  6884. ProductDate: info.ProductDate,
  6885. ExpiryDate: info.ExpiryDate,
  6886. Ctime: time.Now().Unix(),
  6887. Status: 1,
  6888. OrgId: adminInfo.CurrentOrgId,
  6889. OrderNumber: cancel.OrderNumber,
  6890. Type: 0,
  6891. Dealer: deaerler.DealerName,
  6892. Manufacturer: manufacturer.ManufacturerName,
  6893. Number: info.Number,
  6894. RegisterAccount: "",
  6895. Remark: "",
  6896. WarehouseInfoId: info.WarehouseInfotId,
  6897. PatientId: info.PatientId,
  6898. RecordDate: info.SysRecordTime,
  6899. StorehouseId: houseConfig.StorehouseOutInfo,
  6900. IsCheck: 1,
  6901. }
  6902. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6903. //退库数量增加
  6904. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6905. //出库数量减少
  6906. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6907. }
  6908. if info.Count < prescribingNumber {
  6909. cancelStockInfo := models.CancelStockInfo{
  6910. GoodId: project.ProjectId,
  6911. CancelStockId: cancel.ID,
  6912. GoodTypeId: good.GoodTypeId,
  6913. Count: prescribingNumber,
  6914. Price: info.Price,
  6915. Total: 0,
  6916. ProductDate: info.ProductDate,
  6917. ExpiryDate: info.ExpiryDate,
  6918. Ctime: time.Now().Unix(),
  6919. Status: 1,
  6920. OrgId: adminInfo.CurrentOrgId,
  6921. OrderNumber: cancel.OrderNumber,
  6922. Type: 0,
  6923. Dealer: deaerler.DealerName,
  6924. Manufacturer: manufacturer.ManufacturerName,
  6925. Number: info.Number,
  6926. RegisterAccount: "",
  6927. Remark: "",
  6928. WarehouseInfoId: info.WarehouseInfotId,
  6929. PatientId: info.PatientId,
  6930. RecordDate: info.SysRecordTime,
  6931. StorehouseId: houseConfig.StorehouseOutInfo,
  6932. IsCheck: 1,
  6933. }
  6934. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6935. //回退库存
  6936. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6937. }
  6938. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6939. var over_count int64
  6940. for _, it := range goodList {
  6941. over_count += it.StockCount
  6942. }
  6943. //查询出库数量
  6944. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6945. //出库数据 大于 退库数量
  6946. if len(list) > 0 {
  6947. for _, it := range list {
  6948. //回退库存
  6949. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6950. //退库数量增加
  6951. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6952. //出库数量减少
  6953. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6954. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6955. var over_count_one int64
  6956. for _, it := range goodList {
  6957. over_count_one += it.StockCount
  6958. }
  6959. //查询该批次是否有退库数据
  6960. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6961. flow := models.VmStockFlow{
  6962. WarehousingId: it.WarehouseInfotId,
  6963. GoodId: it.GoodId,
  6964. Number: it.Number,
  6965. LicenseNumber: it.LicenseNumber,
  6966. Count: it.Count,
  6967. UserOrgId: adminInfo.CurrentOrgId,
  6968. PatientId: it.PatientId,
  6969. SystemTime: it.SysRecordTime,
  6970. ConsumableType: 7,
  6971. IsSys: 0,
  6972. WarehousingOrder: "",
  6973. WarehouseOutId: it.WarehouseOutId,
  6974. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6975. IsEdit: 0,
  6976. CancelStockId: cancel.ID,
  6977. CancelOrderNumber: cancel.OrderNumber,
  6978. Manufacturer: manufacturer.ID,
  6979. Dealer: 0,
  6980. Creator: adminInfo.AdminUser.Id,
  6981. UpdateCreator: 0,
  6982. Status: 1,
  6983. Ctime: time.Now().Unix(),
  6984. Mtime: 0,
  6985. Price: it.Price,
  6986. WarehousingDetailId: it.WarehouseInfotId,
  6987. WarehouseOutDetailId: it.ID,
  6988. CancelOutDetailId: cancelInfo.ID,
  6989. ProductDate: it.ProductDate,
  6990. ExpireDate: it.ExpiryDate,
  6991. StorehouseId: houseConfig.StorehouseOutInfo,
  6992. OverCount: over_count_one,
  6993. OperateTime: time.Now().Unix(),
  6994. }
  6995. service.CreateStockFlowOne(flow)
  6996. }
  6997. }
  6998. //查询已出库数量
  6999. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7000. if prescribingNumber < dialysisInfo.Count {
  7001. //改变数量
  7002. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7003. }
  7004. if prescribingNumber >= dialysisInfo.Count {
  7005. //删除出库表
  7006. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7007. }
  7008. //更新剩余库存
  7009. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7010. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7011. var total_count_one int64
  7012. for _, it := range stockList {
  7013. total_count_one += it.StockCount
  7014. }
  7015. //基础库插入数据
  7016. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7017. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7018. var flush_count int64
  7019. for _, it := range goodListOne {
  7020. flush_count += it.StockCount
  7021. }
  7022. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7023. if errs != nil {
  7024. goodErrcode := models.XtGoodErrcode{
  7025. UserOrgId: project.UserOrgId,
  7026. Errcode: "手动出库更新剩余出库失败",
  7027. GoodId: project.ProjectId,
  7028. Status: 1,
  7029. Ctime: time.Now().Unix(),
  7030. Mtime: 0,
  7031. Count: 0,
  7032. StockCount: 0,
  7033. Creater: creater,
  7034. BatchNumberId: 0,
  7035. WarehouseOutId: 0,
  7036. }
  7037. service.CreateGoodErrcode(goodErrcode)
  7038. }
  7039. }
  7040. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7041. fmt.Println(err)
  7042. } else {
  7043. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7044. fmt.Println(err)
  7045. }
  7046. }
  7047. c.ServeSuccessJSON(map[string]interface{}{
  7048. "msg": "删除成功",
  7049. })
  7050. return
  7051. }
  7052. func (c *HisApiController) CreateHisAdditionalCharge() {
  7053. his_patient_id, _ := c.GetInt64("his_patient_id")
  7054. patient_id, _ := c.GetInt64("patient_id")
  7055. record_date := c.GetString("record_date")
  7056. timeLayout := "2006-01-02"
  7057. loc, _ := time.LoadLocation("Local")
  7058. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7059. if err != nil {
  7060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7061. return
  7062. }
  7063. adminInfo := c.GetAdminUserInfo()
  7064. recordDateTime := theTime.Unix()
  7065. dataBody := make(map[string]interface{}, 0)
  7066. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7067. if err != nil {
  7068. utils.ErrorLog(err.Error())
  7069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7070. return
  7071. }
  7072. var additions []*models.HisAdditionalCharge
  7073. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7074. additions, _ := dataBody["addition"].([]interface{})
  7075. if len(additions) > 0 {
  7076. for _, item := range additions {
  7077. items := item.(map[string]interface{})
  7078. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7079. utils.ErrorLog("item_id")
  7080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7081. return
  7082. }
  7083. item_id := int64(items["item_id"].(float64))
  7084. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7085. utils.ErrorLog("item_name")
  7086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7087. return
  7088. }
  7089. item_name := items["item_name"].(string)
  7090. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7091. utils.ErrorLog("price")
  7092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7093. return
  7094. }
  7095. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7096. ctime := time.Now().Unix()
  7097. additional := &models.HisAdditionalCharge{
  7098. PatientId: patient_id,
  7099. HisPatientId: his_patient_id,
  7100. UserOrgId: adminInfo.CurrentOrgId,
  7101. RecordDate: recordDateTime,
  7102. CreatedTime: ctime,
  7103. UpdatedTime: ctime,
  7104. Modifier: adminInfo.AdminUser.Id,
  7105. Creator: adminInfo.AdminUser.Id,
  7106. Price: price,
  7107. ItemName: item_name,
  7108. ItemId: item_id,
  7109. Status: 1,
  7110. }
  7111. additions = append(additions, additional)
  7112. }
  7113. }
  7114. }
  7115. for _, item := range additions {
  7116. service.CreateAddtionalCharge(item)
  7117. }
  7118. c.ServeSuccessJSON(map[string]interface{}{
  7119. "msg": "创建成功",
  7120. })
  7121. }
  7122. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7123. blood_fat := c.GetString("blood_fat")
  7124. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7125. blood_sugar := c.GetString("blood_sugar")
  7126. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7127. chief_conplaint := c.GetString("chief_conplaint")
  7128. dbp := c.GetString("dbp")
  7129. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7130. delivery_way, _ := c.GetInt64("delivery_way")
  7131. diagnostic := c.GetString("diagnostic")
  7132. family_history := c.GetString("family_history")
  7133. height := c.GetString("height")
  7134. history_of_present_illness := c.GetString("history_of_present_illness")
  7135. is_infect, _ := c.GetInt64("is_infect")
  7136. past_history := c.GetString("past_history")
  7137. patient_id, _ := c.GetInt64("patient_id")
  7138. his_patient_id, _ := c.GetInt64("his_patient_id")
  7139. personal_history := c.GetString("personal_history")
  7140. pulse := c.GetString("pulse")
  7141. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7142. sbp := c.GetString("sbp")
  7143. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7144. heightfloat, _ := strconv.ParseFloat(height, 64)
  7145. sicktype := c.GetString("sick_type")
  7146. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7147. symptom := c.GetString("symptom")
  7148. sick_date := c.GetString("sick_date")
  7149. temperatures := c.GetString("temperature")
  7150. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7151. record_date := c.GetString("record_date")
  7152. breathing := c.GetString("breathing")
  7153. doctor_advice := c.GetString("doctor_advice")
  7154. remark := c.GetString("remark")
  7155. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7156. sick, _ := c.GetInt64("sick")
  7157. diagnose, _ := c.GetInt64("diagnose")
  7158. //id, _ := c.GetInt64("id")
  7159. timeLayout := "2006-01-02"
  7160. loc, _ := time.LoadLocation("Local")
  7161. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7162. allergic_history := c.GetString("allergic_history")
  7163. if err != nil {
  7164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7165. return
  7166. }
  7167. recordDateTime := theTime.Unix()
  7168. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7169. if err != nil {
  7170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7171. return
  7172. }
  7173. sickTimes := sickTime.Unix()
  7174. ctime := time.Now().Unix()
  7175. primary_disease := c.GetString("primary_disease")
  7176. confirm_failure_date := c.GetString("confirm_failure_date")
  7177. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7178. drug_allergy_history := c.GetString("drug_allergy_history")
  7179. physical_examination := c.GetString("physical_examination")
  7180. special_inspection := c.GetString("special_inspection")
  7181. lab_apparatus := c.GetString("lab_apparatus")
  7182. caseHistory := models.HisPatientCaseHistory{
  7183. HisPatientId: his_patient_id,
  7184. PatientId: patient_id,
  7185. Temperature: temperature,
  7186. BloodSugar: bloodsugarfloat,
  7187. Pulse: pulsefloat,
  7188. Sbp: sbpfloat,
  7189. Dbp: dbpfloat,
  7190. Height: heightfloat,
  7191. BloodFat: bloodfatfloat,
  7192. SickType: sick_type,
  7193. Symptom: symptom,
  7194. SickDate: sickTimes,
  7195. IsInfect: is_infect,
  7196. HistoryOfPresentIllness: history_of_present_illness,
  7197. PastHistory: past_history,
  7198. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7199. ChiefConplaint: chief_conplaint,
  7200. PersonalHistory: personal_history,
  7201. FamilyHistory: family_history,
  7202. Diagnostic: diagnostic,
  7203. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7204. Status: 1,
  7205. Ctime: ctime,
  7206. Mtime: ctime,
  7207. RecordDate: recordDateTime,
  7208. DeliveryWay: delivery_way,
  7209. Breathing: breathingfloat,
  7210. DoctorAdvice: doctor_advice,
  7211. Remark: remark,
  7212. Sick: sick,
  7213. Diagnose: diagnose,
  7214. AllergicHistory: allergic_history,
  7215. PrimaryDisease: primary_disease,
  7216. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7217. DrugAllergyHistory: drug_allergy_history,
  7218. PhysicalExamination: physical_examination,
  7219. SpecialInspection: special_inspection,
  7220. LabApparatus: lab_apparatus,
  7221. }
  7222. //查询该患者是否有病历
  7223. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7224. if errcodes == gorm.ErrRecordNotFound {
  7225. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7226. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7227. if err != nil {
  7228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7229. return
  7230. }
  7231. c.ServeSuccessJSON(map[string]interface{}{
  7232. "caseHistory": caseHistory,
  7233. "historyInfo": historyInfo,
  7234. })
  7235. return
  7236. } else if errcodes == nil {
  7237. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7238. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7239. if err != nil {
  7240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7241. return
  7242. }
  7243. c.ServeSuccessJSON(map[string]interface{}{
  7244. "caseHistory": caseHistory,
  7245. "historyInfo": historyInfo,
  7246. })
  7247. }
  7248. //查询该患者是否有病历
  7249. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7250. //if errcode == gorm.ErrRecordNotFound {
  7251. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7252. // if err != nil {
  7253. // c.ServeSuccessJSON(map[string]interface{}{
  7254. // "msg": "保存成功",
  7255. // })
  7256. // }
  7257. //} else if errcode == nil {
  7258. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7259. // return
  7260. //}
  7261. }
  7262. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7263. patient_id, _ := c.GetInt64("patient_id", 0)
  7264. adminUser := c.GetAdminUserInfo()
  7265. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7266. c.ServeSuccessJSON(map[string]interface{}{
  7267. "list": caseHistorys,
  7268. })
  7269. }
  7270. func (c *HisApiController) GetHisPatientCaseHistory() {
  7271. record_date, _ := c.GetInt64("record_date", 0)
  7272. patient_id, _ := c.GetInt64("patient_id", 0)
  7273. admin := c.GetAdminUserInfo()
  7274. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7275. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7276. c.ServeSuccessJSON(map[string]interface{}{
  7277. "info": info,
  7278. "case_history": case_history,
  7279. })
  7280. }
  7281. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7282. template_name := c.GetString("template_name")
  7283. template_remark := c.GetString("template_remark")
  7284. doctor := c.GetAdminUserInfo().AdminUser.Id
  7285. diagnostic := c.GetString("diagnostic")
  7286. chief_conplaint := c.GetString("chief_conplain")
  7287. history_of_present_illness := c.GetString("history_of_present_illness")
  7288. past_history := c.GetString("past_history")
  7289. personal_history := c.GetString("personal_history")
  7290. family_history := c.GetString("family_history")
  7291. user_name := c.GetString("user_name")
  7292. doctor_advice := c.GetString("doctor_advice")
  7293. remark := c.GetString("remark")
  7294. //record_date := c.GetString("record_date")
  7295. //fmt.Println("record_date--------",record_date)
  7296. //timeLayout := "2006-01-02"
  7297. //loc, _ := time.LoadLocation("Local")
  7298. //
  7299. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7300. //if err != nil {
  7301. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7302. // return
  7303. //}
  7304. //recordDateTime := theTime.Unix()
  7305. ctime := time.Now().Unix()
  7306. template := models.HisCaseHistoryTemplate{
  7307. HistoryOfPresentIllness: history_of_present_illness,
  7308. PastHistory: past_history,
  7309. ChiefConplaint: chief_conplaint,
  7310. PersonalHistory: personal_history,
  7311. FamilyHistory: family_history,
  7312. Diagnostic: diagnostic,
  7313. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7314. Status: 1,
  7315. Ctime: ctime,
  7316. Mtime: ctime,
  7317. RecordDate: time.Now().Unix(),
  7318. TemplateName: template_name,
  7319. TemplateRemark: template_remark,
  7320. Creator: doctor,
  7321. Modifier: doctor,
  7322. UserName: user_name,
  7323. DoctorAdvice: doctor_advice,
  7324. Remark: remark,
  7325. }
  7326. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7327. if err == nil {
  7328. c.ServeSuccessJSON(map[string]interface{}{
  7329. "msg": "保存成功",
  7330. })
  7331. } else {
  7332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7333. return
  7334. }
  7335. }
  7336. func (c *HisApiController) GetCaseHistoryTemplate() {
  7337. timeLayout := "2006-01-02"
  7338. loc, _ := time.LoadLocation("Local")
  7339. keyword := c.GetString("keyword")
  7340. start_time := c.GetString("start_time")
  7341. end_time := c.GetString("end_time")
  7342. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7343. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7344. admin := c.GetAdminUserInfo()
  7345. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7346. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7347. c.ServeSuccessJSON(map[string]interface{}{
  7348. "template": template,
  7349. //"history": history,
  7350. })
  7351. }
  7352. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7353. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7354. utils.ErrorLog("drug_name")
  7355. return enums.ErrorCodeParamWrong
  7356. }
  7357. adviceName, _ := json["drug_name"].(string)
  7358. if len(adviceName) == 0 {
  7359. utils.ErrorLog("len(advice_name) == 0")
  7360. return enums.ErrorCodeParamWrong
  7361. }
  7362. advice.AdviceName = adviceName
  7363. adviceDesc, _ := json["advice_desc"].(string)
  7364. advice.AdviceDesc = adviceDesc
  7365. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7366. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7367. advice.DrugSpec = drugSpec
  7368. }
  7369. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7370. remark, _ := json["remark"].(string)
  7371. advice.Remark = remark
  7372. }
  7373. if json["id"] == nil {
  7374. advice.DrugId = 0
  7375. } else {
  7376. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7377. drug_id := int64(json["id"].(float64))
  7378. advice.DrugId = drug_id
  7379. }
  7380. }
  7381. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7382. advice_id := int64(json["advice_id"].(float64))
  7383. advice.ID = advice_id
  7384. if advice.ID > 0 {
  7385. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7386. if err == nil {
  7387. if hisAdvice.ID > 0 {
  7388. advice.ExecutionTime = hisAdvice.ExecutionTime
  7389. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7390. advice.ExecutionState = hisAdvice.ExecutionState
  7391. advice.CheckTime = hisAdvice.CheckTime
  7392. advice.Checker = hisAdvice.Checker
  7393. advice.CheckState = hisAdvice.CheckState
  7394. advice.StartTime = hisAdvice.StartTime
  7395. advice.FeedetlSn = hisAdvice.FeedetlSn
  7396. }
  7397. }
  7398. }
  7399. }
  7400. //
  7401. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7402. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7403. // advice.ExecutionTime = execution_time
  7404. //}
  7405. //
  7406. //
  7407. //
  7408. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7409. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7410. // advice.ExecutionStaff = execution_staff
  7411. //}
  7412. //
  7413. //
  7414. //
  7415. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7416. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7417. // advice.ExecutionState = execution_state
  7418. //}
  7419. //
  7420. //
  7421. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7422. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7423. // advice.CheckTime = check_time
  7424. //}
  7425. //
  7426. //
  7427. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7428. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7429. // advice.CheckState = check_state
  7430. //}
  7431. //
  7432. //
  7433. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7434. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7435. // advice.Checker = checker
  7436. //}
  7437. //
  7438. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7439. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7440. // advice.StartTime = start_time
  7441. //}
  7442. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7443. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7444. advice.IsSelfDrug = is_self_drug
  7445. }
  7446. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7447. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7448. drug_way_count, _ := json["drug_way_count"].(string)
  7449. advice.DrugWayCount = drug_way_count
  7450. }
  7451. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7452. drugSpecUnit, _ := json["min_unit"].(string)
  7453. advice.DrugSpecUnit = drugSpecUnit
  7454. }
  7455. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7456. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7457. advice.SingleDose = singleDose
  7458. }
  7459. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7460. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7461. advice.SingleDoseUnit = singleDoseUnit
  7462. }
  7463. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7464. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7465. advice.PrescribingNumber = prescribingNumber
  7466. }
  7467. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7468. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7469. advice.PrescribingNumberUnit = prescribingNumberUnit
  7470. }
  7471. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7472. deliveryWay, _ := json["delivery_way"].(string)
  7473. advice.DeliveryWay = deliveryWay
  7474. }
  7475. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7476. executionFrequency, _ := json["execution_frequency"].(string)
  7477. advice.ExecutionFrequency = executionFrequency
  7478. }
  7479. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7480. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7481. advice.Price = price
  7482. }
  7483. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7484. med_list_codg, _ := json["medical_insurance_number"].(string)
  7485. advice.MedListCodg = med_list_codg
  7486. }
  7487. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7488. day := int64(json["day"].(float64))
  7489. advice.Day = day
  7490. }
  7491. return 0
  7492. }
  7493. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7494. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7495. id := int64(json["id"].(float64))
  7496. project.ID = id
  7497. historyProject, _ := service.GetHisProjectByID(id)
  7498. project.FeedetlSn = historyProject.FeedetlSn
  7499. }
  7500. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7501. project_id := int64(json["project_id"].(float64))
  7502. project.ProjectId = project_id
  7503. }
  7504. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7505. // price := int64(json["price"].(float64))
  7506. // formatInt_price := strconv.FormatInt(price, 10)
  7507. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7508. // project.Price = float_price
  7509. // }
  7510. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7511. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7512. project.Price = price
  7513. }
  7514. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7515. total, _ := json["total"].(string)
  7516. project.Count = total
  7517. }
  7518. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7519. medical_code, _ := json["medical_code"].(string)
  7520. project.MedListCodg = medical_code
  7521. }
  7522. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7523. single_dose, _ := json["single_dose"].(string)
  7524. project.SingleDose = single_dose
  7525. }
  7526. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7527. delivery_way, _ := json["delivery_way"].(string)
  7528. project.DeliveryWay = delivery_way
  7529. }
  7530. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7531. execution_frequency, _ := json["execution_frequency"].(string)
  7532. project.ExecutionFrequency = execution_frequency
  7533. }
  7534. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7535. remark, _ := json["remark"].(string)
  7536. project.Remark = remark
  7537. }
  7538. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7539. day, _ := json["number_days"].(string)
  7540. project.Day = day
  7541. }
  7542. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7543. unit, _ := json["unit"].(string)
  7544. project.Unit = unit
  7545. }
  7546. return 0
  7547. }
  7548. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7549. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7550. id := int64(json["id"].(float64))
  7551. historyAddtions, _ := service.GetHisAdditionByID(id)
  7552. additionalCharge.ID = id
  7553. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7554. }
  7555. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7556. item_id := int64(json["item_id"].(float64))
  7557. additionalCharge.ItemId = item_id
  7558. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7559. if config.ID > 0 {
  7560. if len(config.Code) > 0 {
  7561. additionalCharge.MedListCodg = config.Code
  7562. }
  7563. }
  7564. }
  7565. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7566. // price := int64(json["price"].(float64))
  7567. // formatInt_price := strconv.FormatInt(price, 10)
  7568. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7569. // additionalCharge.Price = float_price
  7570. // }
  7571. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7572. // price := int64(json["price"].(float64))
  7573. // formatInt_price := strconv.FormatInt(price, 10)
  7574. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7575. // additionalCharge.Price = float_price
  7576. //}
  7577. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7578. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7579. additionalCharge.Price = price
  7580. }
  7581. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7582. count, _ := json["count"].(string)
  7583. counts, _ := strconv.ParseInt(count, 10, 64)
  7584. additionalCharge.Count = counts
  7585. }
  7586. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7587. item_name, _ := json["item_name"].(string)
  7588. additionalCharge.ItemName = item_name
  7589. }
  7590. return 0
  7591. }
  7592. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7593. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7594. utils.ErrorLog("drug_name")
  7595. return enums.ErrorCodeParamWrong
  7596. }
  7597. adviceName, _ := json["drug_name"].(string)
  7598. if len(adviceName) == 0 {
  7599. utils.ErrorLog("len(advice_name) == 0")
  7600. return enums.ErrorCodeParamWrong
  7601. }
  7602. advice.AdviceName = adviceName
  7603. adviceDesc, _ := json["advice_desc"].(string)
  7604. advice.AdviceDesc = adviceDesc
  7605. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7606. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7607. advice.DrugSpec = drugSpec
  7608. }
  7609. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7610. remark, _ := json["remark"].(string)
  7611. advice.Remark = remark
  7612. }
  7613. if json["id"] == nil {
  7614. advice.DrugId = 0
  7615. } else {
  7616. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7617. drug_id := int64(json["id"].(float64))
  7618. advice.DrugId = drug_id
  7619. }
  7620. }
  7621. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7622. groupno := int64(json["groupno"].(float64))
  7623. advice.Groupno = groupno
  7624. }
  7625. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7626. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7627. advice.IsSelfDrug = is_self_drug
  7628. }
  7629. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7630. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7631. drug_way_count, _ := json["drug_way_count"].(string)
  7632. advice.DrugWayCount = drug_way_count
  7633. }
  7634. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7635. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7636. advice.HospApprFlag = hosp_appr_flag
  7637. }
  7638. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7639. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7640. advice.PrescribingNumber = prescribingNumber
  7641. }
  7642. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7643. // frequency_type := int64(json["frequency_type"].(float64))
  7644. // advice.FrequencyType = frequency_type
  7645. //}
  7646. //
  7647. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7648. // day_count := int64(json["day_count"].(float64))
  7649. // advice.DayCount = day_count
  7650. //}
  7651. //
  7652. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7653. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7654. // week_day, _ := json["week_day"].(string)
  7655. // advice.WeekDay = week_day
  7656. //}
  7657. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7658. drugSpecUnit, _ := json["min_unit"].(string)
  7659. advice.DrugSpecUnit = drugSpecUnit
  7660. }
  7661. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7662. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7663. advice.SingleDose = singleDose
  7664. }
  7665. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7666. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7667. advice.SingleDoseUnit = singleDoseUnit
  7668. }
  7669. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7670. deliveryWay, _ := json["delivery_way"].(string)
  7671. advice.DeliveryWay = deliveryWay
  7672. }
  7673. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7674. executionFrequency, _ := json["execution_frequency"].(string)
  7675. advice.ExecutionFrequency = executionFrequency
  7676. }
  7677. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7678. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7679. advice.Price = price
  7680. }
  7681. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7682. med_list_codg, _ := json["medical_insurance_number"].(string)
  7683. advice.MedListCodg = med_list_codg
  7684. }
  7685. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7686. day := int64(json["day"].(float64))
  7687. advice.Day = day
  7688. }
  7689. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7690. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7691. advice.PrescribingNumberUnit = prescribingNumberUnit
  7692. }
  7693. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7694. advice_id := int64(json["advice_id"].(float64))
  7695. advice.ID = advice_id
  7696. if advice.ID > 0 {
  7697. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7698. if err == nil {
  7699. if hisAdvice.ID > 0 {
  7700. advice.ExecutionTime = hisAdvice.ExecutionTime
  7701. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7702. advice.ExecutionState = hisAdvice.ExecutionState
  7703. advice.CheckTime = hisAdvice.CheckTime
  7704. advice.Checker = hisAdvice.Checker
  7705. advice.CheckState = hisAdvice.CheckState
  7706. advice.StartTime = hisAdvice.StartTime
  7707. advice.HospApprFlag = hisAdvice.HospApprFlag
  7708. advice.IsMedicine = hisAdvice.IsMedicine
  7709. if hisAdvice.UserOrgId == 10028 {
  7710. 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 {
  7711. advice.ExecutionTime = 0
  7712. advice.ExecutionStaff = 0
  7713. advice.ExecutionState = 2
  7714. advice.CheckTime = 0
  7715. advice.Checker = 0
  7716. advice.CheckState = 2
  7717. }
  7718. } else {
  7719. 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 {
  7720. advice.ExecutionTime = 0
  7721. advice.ExecutionStaff = 0
  7722. advice.ExecutionState = 2
  7723. advice.CheckTime = 0
  7724. advice.Checker = 0
  7725. advice.CheckState = 2
  7726. advice.UpdatedTime = time.Now().Unix()
  7727. }
  7728. }
  7729. //advice.Groupno = hisAdvice.Groupno
  7730. }
  7731. }
  7732. }
  7733. }
  7734. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7735. //
  7736. //if drugStockConfig.IsOpen == 1 {
  7737. //
  7738. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7739. // if advice.ID == 0 { //医嘱不存在
  7740. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7741. // drug.Total = drug.Total - advice.PrescribingNumber
  7742. // service.UpdateBaseDrugLib(&drug)
  7743. //
  7744. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7745. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7746. // drug.Total = drug.Total - num
  7747. // service.UpdateBaseDrugLib(&drug)
  7748. // }
  7749. //
  7750. // } else if advice.ID > 0 { //医嘱存在
  7751. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7752. // var num float64
  7753. //
  7754. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7755. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7756. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7757. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7758. // drug.Total = drug.Total + num
  7759. // service.UpdateBaseDrugLib(&drug)
  7760. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7761. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7762. // drug.Total = drug.Total - num
  7763. // service.UpdateBaseDrugLib(&drug)
  7764. // }
  7765. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7766. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7767. // if num2 > advice.PrescribingNumber {
  7768. // num = num2 - advice.PrescribingNumber
  7769. // drug.Total = drug.Total + num
  7770. // service.UpdateBaseDrugLib(&drug)
  7771. // } else if num2 < advice.PrescribingNumber {
  7772. // num = advice.PrescribingNumber - num2
  7773. // drug.Total = drug.Total - num
  7774. // service.UpdateBaseDrugLib(&drug)
  7775. // }
  7776. //
  7777. // }
  7778. //
  7779. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7780. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7781. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7782. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7783. // if num1 > num2 {
  7784. // num = num1 - num2
  7785. // drug.Total = drug.Total + num
  7786. // service.UpdateBaseDrugLib(&drug)
  7787. // } else if num1 < num2 {
  7788. // num = num2 - num1
  7789. // drug.Total = drug.Total - num
  7790. // service.UpdateBaseDrugLib(&drug)
  7791. // }
  7792. //
  7793. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7794. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7795. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7796. // if hisAdvice.PrescribingNumber > num2 {
  7797. // num = hisAdvice.PrescribingNumber - num2
  7798. // drug.Total = drug.Total + num
  7799. // service.UpdateBaseDrugLib(&drug)
  7800. // } else if num2 < advice.PrescribingNumber {
  7801. // num = num2 - hisAdvice.PrescribingNumber
  7802. // drug.Total = drug.Total - num
  7803. // service.UpdateBaseDrugLib(&drug)
  7804. // }
  7805. //
  7806. // }
  7807. // }
  7808. // }
  7809. //}
  7810. //
  7811. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7812. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7813. // advice.ExecutionTime = execution_time
  7814. //}
  7815. //
  7816. //
  7817. //
  7818. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7819. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7820. // advice.ExecutionStaff = execution_staff
  7821. //}
  7822. //
  7823. //
  7824. //
  7825. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7826. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7827. // advice.ExecutionState = execution_state
  7828. //}
  7829. //
  7830. //
  7831. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7832. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7833. // advice.CheckTime = check_time
  7834. //}
  7835. //
  7836. //
  7837. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7838. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7839. // advice.CheckState = check_state
  7840. //}
  7841. //
  7842. //
  7843. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7844. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7845. // advice.Checker = checker
  7846. //}
  7847. //
  7848. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7849. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7850. // advice.StartTime = start_time
  7851. //}
  7852. return 0
  7853. }
  7854. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7855. project.ExecutionStaff = 0
  7856. project.ExecutionState = 2
  7857. project.ExecutionTime = 0
  7858. project.Checker = 0
  7859. project.CheckState = 2
  7860. project.CheckTime = 0
  7861. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7862. id := int64(json["id"].(float64))
  7863. project.ID = id
  7864. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7865. project.ExecutionStaff = temp_project.ExecutionStaff
  7866. project.ExecutionState = temp_project.ExecutionState
  7867. project.ExecutionTime = temp_project.ExecutionTime
  7868. project.Checker = temp_project.Checker
  7869. project.CheckState = temp_project.CheckState
  7870. project.CheckTime = temp_project.CheckTime
  7871. project.TeamId = temp_project.TeamId
  7872. }
  7873. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7874. types := int64(json["type"].(float64))
  7875. project.Type = types
  7876. }
  7877. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7878. project_id := int64(json["project_id"].(float64))
  7879. project.ProjectId = project_id
  7880. }
  7881. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7882. team_id := int64(json["team_id"].(float64))
  7883. project.TeamId = team_id
  7884. }
  7885. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7886. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7887. project.Price = price
  7888. }
  7889. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7890. total, _ := json["total"].(string)
  7891. //totals, _ := strconv.ParseInt(total, 10, 64)
  7892. project.Count = total
  7893. }
  7894. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7895. medical_code, _ := json["medical_code"].(string)
  7896. project.MedListCodg = medical_code
  7897. }
  7898. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7899. single_dose, _ := json["single_dose"].(string)
  7900. project.SingleDose = single_dose
  7901. }
  7902. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7903. delivery_way, _ := json["delivery_way"].(string)
  7904. project.DeliveryWay = delivery_way
  7905. }
  7906. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7907. execution_frequency, _ := json["execution_frequency"].(string)
  7908. project.ExecutionFrequency = execution_frequency
  7909. }
  7910. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7911. remark, _ := json["remark"].(string)
  7912. project.Remark = remark
  7913. }
  7914. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7915. day, _ := json["number_days"].(string)
  7916. project.Day = day
  7917. }
  7918. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7919. unit, _ := json["unit"].(string)
  7920. project.Unit = unit
  7921. }
  7922. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7923. // frequency_type := int64(json["frequency_type"].(float64))
  7924. // project.FrequencyType = frequency_type
  7925. //}
  7926. //
  7927. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7928. // day_count := int64(json["day_count"].(float64))
  7929. // project.DayCount = day_count
  7930. //}
  7931. //
  7932. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7933. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7934. // week_day, _ := json["week_day"].(string)
  7935. // project.WeekDay = week_day
  7936. //}
  7937. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7938. //
  7939. //if project.ID == 0 {
  7940. // if stockConfig.IsOpen == 1 {
  7941. // if project.Type == 3 {
  7942. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7943. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7944. // good.Total = good.Total - f_count
  7945. // service.UpdateGoodInfo(&good)
  7946. // }
  7947. // }
  7948. //
  7949. //} else {
  7950. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7951. //
  7952. // if stockConfig.IsOpen == 1 {
  7953. // if project.Type == 3 {
  7954. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7955. // if project.Count < temp_project.Count {
  7956. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7957. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7958. //
  7959. // other_count := f_count_two - f_count_one
  7960. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7961. // good.Total = good.Total + other_count_two
  7962. // service.UpdateGoodInfo(&good)
  7963. // } else if project.Count > temp_project.Count {
  7964. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7965. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7966. //
  7967. // other_count := f_count_one - f_count_two
  7968. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7969. // good.Total = good.Total - other_count_two
  7970. // service.UpdateGoodInfo(&good)
  7971. // }
  7972. //
  7973. // }
  7974. // }
  7975. //
  7976. //}
  7977. return 0
  7978. }
  7979. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7980. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7981. utils.ErrorLog("drug_name")
  7982. return enums.ErrorCodeParamWrong
  7983. }
  7984. adviceName, _ := json["drug_name"].(string)
  7985. if len(adviceName) == 0 {
  7986. utils.ErrorLog("len(advice_name) == 0")
  7987. return enums.ErrorCodeParamWrong
  7988. }
  7989. advice.AdviceName = adviceName
  7990. adviceDesc, _ := json["advice_desc"].(string)
  7991. advice.AdviceDesc = adviceDesc
  7992. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7993. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7994. advice.DrugSpec = drugSpec
  7995. }
  7996. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7997. remark, _ := json["remark"].(string)
  7998. advice.Remark = remark
  7999. }
  8000. if json["id"] == nil {
  8001. advice.DrugId = 0
  8002. } else {
  8003. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8004. drug_id := int64(json["id"].(float64))
  8005. advice.DrugId = drug_id
  8006. }
  8007. }
  8008. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8009. groupno := int64(json["groupno"].(float64))
  8010. advice.Groupno = groupno
  8011. }
  8012. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8013. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8014. advice.IsSelfDrug = is_self_drug
  8015. }
  8016. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8017. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8018. drug_way_count, _ := json["drug_way_count"].(string)
  8019. advice.DrugWayCount = drug_way_count
  8020. }
  8021. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8022. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8023. advice.HospApprFlag = hosp_appr_flag
  8024. }
  8025. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8026. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8027. advice.PrescribingNumber = prescribingNumber
  8028. }
  8029. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8030. // frequency_type := int64(json["frequency_type"].(float64))
  8031. // advice.FrequencyType = frequency_type
  8032. //}
  8033. //
  8034. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8035. // day_count := int64(json["day_count"].(float64))
  8036. // advice.DayCount = day_count
  8037. //}
  8038. //
  8039. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8040. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8041. // week_day, _ := json["week_day"].(string)
  8042. // advice.WeekDay = week_day
  8043. //}
  8044. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8045. drugSpecUnit, _ := json["min_unit"].(string)
  8046. advice.DrugSpecUnit = drugSpecUnit
  8047. }
  8048. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8049. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8050. advice.SingleDose = singleDose
  8051. }
  8052. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8053. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8054. advice.SingleDoseUnit = singleDoseUnit
  8055. }
  8056. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8057. deliveryWay, _ := json["delivery_way"].(string)
  8058. advice.DeliveryWay = deliveryWay
  8059. }
  8060. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8061. executionFrequency, _ := json["execution_frequency"].(string)
  8062. advice.ExecutionFrequency = executionFrequency
  8063. }
  8064. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8065. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8066. advice.Price = price
  8067. }
  8068. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8069. med_list_codg, _ := json["medical_insurance_number"].(string)
  8070. advice.MedListCodg = med_list_codg
  8071. }
  8072. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8073. day := int64(json["day"].(float64))
  8074. advice.Day = day
  8075. }
  8076. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8077. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8078. advice.PrescribingNumberUnit = prescribingNumberUnit
  8079. }
  8080. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8081. advice_id := int64(json["advice_id"].(float64))
  8082. advice.ID = advice_id
  8083. if advice.ID > 0 {
  8084. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8085. if err == nil {
  8086. if hisAdvice.ID > 0 {
  8087. advice.ExecutionTime = hisAdvice.ExecutionTime
  8088. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8089. advice.ExecutionState = hisAdvice.ExecutionState
  8090. advice.CheckTime = hisAdvice.CheckTime
  8091. advice.Checker = hisAdvice.Checker
  8092. advice.DrugCode = hisAdvice.DrugCode
  8093. advice.CheckState = hisAdvice.CheckState
  8094. advice.StartTime = hisAdvice.StartTime
  8095. advice.HospApprFlag = hisAdvice.HospApprFlag
  8096. advice.IsMedicine = hisAdvice.IsMedicine
  8097. if hisAdvice.UserOrgId == 10028 {
  8098. 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 {
  8099. advice.ExecutionTime = 0
  8100. advice.ExecutionStaff = 0
  8101. advice.ExecutionState = 2
  8102. advice.CheckTime = 0
  8103. advice.Checker = 0
  8104. advice.CheckState = 2
  8105. }
  8106. } else {
  8107. 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 {
  8108. advice.ExecutionTime = 0
  8109. advice.ExecutionStaff = 0
  8110. advice.ExecutionState = 2
  8111. advice.CheckTime = 0
  8112. advice.Checker = 0
  8113. advice.CheckState = 2
  8114. //advice.UpdatedTime = time.Now().Unix()
  8115. advice.CreatedTime = hisAdvice.CreatedTime
  8116. advice.UpdatedTime = time.Now().Unix()
  8117. } else {
  8118. advice.CreatedTime = hisAdvice.CreatedTime
  8119. advice.UpdatedTime = hisAdvice.UpdatedTime
  8120. }
  8121. }
  8122. //advice.Groupno = hisAdvice.Groupno
  8123. } else {
  8124. advice.IsMedicine = 0
  8125. ctime := time.Now().Unix()
  8126. advice.CreatedTime = ctime
  8127. advice.UpdatedTime = ctime
  8128. }
  8129. }
  8130. } else {
  8131. advice.IsMedicine = 0
  8132. ctime := time.Now().Unix()
  8133. advice.CreatedTime = ctime
  8134. advice.UpdatedTime = ctime
  8135. }
  8136. }
  8137. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8138. //
  8139. //if drugStockConfig.IsOpen == 1 {
  8140. //
  8141. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8142. // if advice.ID == 0 { //医嘱不存在
  8143. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8144. // drug.Total = drug.Total - advice.PrescribingNumber
  8145. // service.UpdateBaseDrugLib(&drug)
  8146. //
  8147. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8148. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8149. // drug.Total = drug.Total - num
  8150. // service.UpdateBaseDrugLib(&drug)
  8151. // }
  8152. //
  8153. // } else if advice.ID > 0 { //医嘱存在
  8154. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8155. // var num float64
  8156. //
  8157. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8158. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8159. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8160. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8161. // drug.Total = drug.Total + num
  8162. // service.UpdateBaseDrugLib(&drug)
  8163. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8164. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8165. // drug.Total = drug.Total - num
  8166. // service.UpdateBaseDrugLib(&drug)
  8167. // }
  8168. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8169. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8170. // if num2 > advice.PrescribingNumber {
  8171. // num = num2 - advice.PrescribingNumber
  8172. // drug.Total = drug.Total + num
  8173. // service.UpdateBaseDrugLib(&drug)
  8174. // } else if num2 < advice.PrescribingNumber {
  8175. // num = advice.PrescribingNumber - num2
  8176. // drug.Total = drug.Total - num
  8177. // service.UpdateBaseDrugLib(&drug)
  8178. // }
  8179. //
  8180. // }
  8181. //
  8182. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8183. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8184. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8185. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8186. // if num1 > num2 {
  8187. // num = num1 - num2
  8188. // drug.Total = drug.Total + num
  8189. // service.UpdateBaseDrugLib(&drug)
  8190. // } else if num1 < num2 {
  8191. // num = num2 - num1
  8192. // drug.Total = drug.Total - num
  8193. // service.UpdateBaseDrugLib(&drug)
  8194. // }
  8195. //
  8196. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8197. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8198. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8199. // if hisAdvice.PrescribingNumber > num2 {
  8200. // num = hisAdvice.PrescribingNumber - num2
  8201. // drug.Total = drug.Total + num
  8202. // service.UpdateBaseDrugLib(&drug)
  8203. // } else if num2 < advice.PrescribingNumber {
  8204. // num = num2 - hisAdvice.PrescribingNumber
  8205. // drug.Total = drug.Total - num
  8206. // service.UpdateBaseDrugLib(&drug)
  8207. // }
  8208. //
  8209. // }
  8210. // }
  8211. // }
  8212. //}
  8213. //
  8214. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8215. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8216. // advice.ExecutionTime = execution_time
  8217. //}
  8218. //
  8219. //
  8220. //
  8221. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8222. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8223. // advice.ExecutionStaff = execution_staff
  8224. //}
  8225. //
  8226. //
  8227. //
  8228. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8229. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8230. // advice.ExecutionState = execution_state
  8231. //}
  8232. //
  8233. //
  8234. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8235. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8236. // advice.CheckTime = check_time
  8237. //}
  8238. //
  8239. //
  8240. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8241. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8242. // advice.CheckState = check_state
  8243. //}
  8244. //
  8245. //
  8246. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8247. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8248. // advice.Checker = checker
  8249. //}
  8250. //
  8251. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8252. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8253. // advice.StartTime = start_time
  8254. //}
  8255. return 0
  8256. }
  8257. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8258. project.ExecutionStaff = 0
  8259. project.ExecutionState = 2
  8260. project.ExecutionTime = 0
  8261. project.Checker = 0
  8262. project.CheckState = 2
  8263. project.CheckTime = 0
  8264. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8265. id := int64(json["id"].(float64))
  8266. project.ID = id
  8267. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8268. project.ExecutionStaff = temp_project.ExecutionStaff
  8269. project.ExecutionState = temp_project.ExecutionState
  8270. project.ExecutionTime = temp_project.ExecutionTime
  8271. project.Checker = temp_project.Checker
  8272. project.CheckState = temp_project.CheckState
  8273. project.CheckTime = temp_project.CheckTime
  8274. project.TeamId = temp_project.TeamId
  8275. }
  8276. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8277. types := int64(json["type"].(float64))
  8278. project.Type = types
  8279. }
  8280. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8281. project_id := int64(json["project_id"].(float64))
  8282. project.ProjectId = project_id
  8283. }
  8284. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8285. team_id := int64(json["team_id"].(float64))
  8286. project.TeamId = team_id
  8287. }
  8288. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8289. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8290. project.Price = price
  8291. }
  8292. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8293. total, _ := json["total"].(string)
  8294. //totals, _ := strconv.ParseInt(total, 10, 64)
  8295. project.Count = total
  8296. }
  8297. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8298. medical_code, _ := json["medical_code"].(string)
  8299. project.MedListCodg = medical_code
  8300. }
  8301. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8302. single_dose, _ := json["single_dose"].(string)
  8303. project.SingleDose = single_dose
  8304. }
  8305. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8306. delivery_way, _ := json["delivery_way"].(string)
  8307. project.DeliveryWay = delivery_way
  8308. }
  8309. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8310. execution_frequency, _ := json["execution_frequency"].(string)
  8311. project.ExecutionFrequency = execution_frequency
  8312. }
  8313. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8314. remark, _ := json["remark"].(string)
  8315. project.Remark = remark
  8316. }
  8317. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8318. day, _ := json["number_days"].(string)
  8319. project.Day = day
  8320. }
  8321. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8322. unit, _ := json["unit"].(string)
  8323. project.Unit = unit
  8324. }
  8325. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8326. // frequency_type := int64(json["frequency_type"].(float64))
  8327. // project.FrequencyType = frequency_type
  8328. //}
  8329. //
  8330. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8331. // day_count := int64(json["day_count"].(float64))
  8332. // project.DayCount = day_count
  8333. //}
  8334. //
  8335. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8336. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8337. // week_day, _ := json["week_day"].(string)
  8338. // project.WeekDay = week_day
  8339. //}
  8340. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8341. //
  8342. //if project.ID == 0 {
  8343. // if stockConfig.IsOpen == 1 {
  8344. // if project.Type == 3 {
  8345. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8346. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8347. // good.Total = good.Total - f_count
  8348. // service.UpdateGoodInfo(&good)
  8349. // }
  8350. // }
  8351. //
  8352. //} else {
  8353. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8354. //
  8355. // if stockConfig.IsOpen == 1 {
  8356. // if project.Type == 3 {
  8357. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8358. // if project.Count < temp_project.Count {
  8359. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8360. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8361. //
  8362. // other_count := f_count_two - f_count_one
  8363. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8364. // good.Total = good.Total + other_count_two
  8365. // service.UpdateGoodInfo(&good)
  8366. // } else if project.Count > temp_project.Count {
  8367. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8368. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8369. //
  8370. // other_count := f_count_one - f_count_two
  8371. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8372. // good.Total = good.Total - other_count_two
  8373. // service.UpdateGoodInfo(&good)
  8374. // }
  8375. //
  8376. // }
  8377. // }
  8378. //
  8379. //}
  8380. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8381. id := int64(json["id"].(float64))
  8382. if id > 0 {
  8383. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8384. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8385. fmt.Println("666666")
  8386. project.Mtime = time.Now().Unix()
  8387. project.Ctime = temp_project.Ctime
  8388. } else {
  8389. project.Mtime = temp_project.Mtime
  8390. project.Ctime = temp_project.Ctime
  8391. }
  8392. } else {
  8393. ctime := time.Now().Unix()
  8394. project.Mtime = ctime
  8395. project.Ctime = ctime
  8396. }
  8397. }
  8398. return 0
  8399. }
  8400. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8401. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8402. id := int64(json["id"].(float64))
  8403. additionalCharge.ID = id
  8404. }
  8405. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8406. item_id := int64(json["item_id"].(float64))
  8407. additionalCharge.ItemId = item_id
  8408. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8409. if config.ID > 0 {
  8410. if len(config.Code) > 0 {
  8411. additionalCharge.MedListCodg = config.Code
  8412. }
  8413. }
  8414. }
  8415. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8416. // price := int64(json["price"].(float64))
  8417. // formatInt_price := strconv.FormatInt(price, 10)
  8418. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8419. // additionalCharge.Price = float_price
  8420. // }
  8421. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8422. // price := int64(json["price"].(float64))
  8423. // formatInt_price := strconv.FormatInt(price, 10)
  8424. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8425. // additionalCharge.Price = float_price
  8426. //}
  8427. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8428. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8429. additionalCharge.Price = price
  8430. }
  8431. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8432. count, _ := json["count"].(string)
  8433. counts, _ := strconv.ParseInt(count, 10, 64)
  8434. additionalCharge.Count = counts
  8435. }
  8436. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8437. item_name, _ := json["item_name"].(string)
  8438. additionalCharge.ItemName = item_name
  8439. }
  8440. return 0
  8441. }
  8442. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8443. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8444. utils.ErrorLog("drug_name")
  8445. return enums.ErrorCodeParamWrong
  8446. }
  8447. adviceName, _ := json["drug_name"].(string)
  8448. if len(adviceName) == 0 {
  8449. utils.ErrorLog("len(advice_name) == 0")
  8450. return enums.ErrorCodeParamWrong
  8451. }
  8452. advice.AdviceName = adviceName
  8453. adviceDesc, _ := json["advice_desc"].(string)
  8454. advice.AdviceDesc = adviceDesc
  8455. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8456. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8457. advice.DrugSpec = drugSpec
  8458. }
  8459. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8460. remark, _ := json["remark"].(string)
  8461. advice.Remark = remark
  8462. }
  8463. if json["id"] == nil {
  8464. advice.DrugId = 0
  8465. } else {
  8466. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8467. drug_id := int64(json["id"].(float64))
  8468. advice.DrugId = drug_id
  8469. }
  8470. }
  8471. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8472. groupno := int64(json["groupno"].(float64))
  8473. advice.Groupno = groupno
  8474. }
  8475. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8476. drugSpecUnit, _ := json["min_unit"].(string)
  8477. advice.DrugSpecUnit = drugSpecUnit
  8478. }
  8479. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8480. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8481. advice.SingleDose = singleDose
  8482. }
  8483. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8484. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8485. advice.SingleDoseUnit = singleDoseUnit
  8486. }
  8487. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8488. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8489. advice.PrescribingNumber = prescribingNumber
  8490. }
  8491. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8492. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8493. advice.PrescribingNumberUnit = prescribingNumberUnit
  8494. }
  8495. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8496. deliveryWay, _ := json["delivery_way"].(string)
  8497. advice.DeliveryWay = deliveryWay
  8498. }
  8499. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8500. executionFrequency, _ := json["execution_frequency"].(string)
  8501. advice.ExecutionFrequency = executionFrequency
  8502. }
  8503. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8504. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8505. advice.Price = price
  8506. }
  8507. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8508. med_list_codg, _ := json["medical_insurance_number"].(string)
  8509. advice.MedListCodg = med_list_codg
  8510. }
  8511. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8512. day := int64(json["day"].(float64))
  8513. advice.Day = day
  8514. }
  8515. advice.FrequencyType = 1
  8516. return 0
  8517. }
  8518. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8519. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8520. types := int64(json["type"].(float64))
  8521. project.Type = types
  8522. }
  8523. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8524. project_id := int64(json["project_id"].(float64))
  8525. project.ProjectId = project_id
  8526. }
  8527. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8528. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8529. project.Price = price
  8530. }
  8531. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8532. total, _ := json["total"].(string)
  8533. //totals, _ := strconv.ParseInt(total, 10, 64)
  8534. project.Count = total
  8535. }
  8536. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8537. medical_code, _ := json["medical_code"].(string)
  8538. project.MedListCodg = medical_code
  8539. }
  8540. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8541. single_dose, _ := json["single_dose"].(string)
  8542. project.SingleDose = single_dose
  8543. }
  8544. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8545. delivery_way, _ := json["delivery_way"].(string)
  8546. project.DeliveryWay = delivery_way
  8547. }
  8548. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8549. execution_frequency, _ := json["execution_frequency"].(string)
  8550. project.ExecutionFrequency = execution_frequency
  8551. }
  8552. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8553. remark, _ := json["remark"].(string)
  8554. project.Remark = remark
  8555. }
  8556. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8557. day, _ := json["number_days"].(string)
  8558. project.Day = day
  8559. }
  8560. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8561. unit, _ := json["unit"].(string)
  8562. project.Unit = unit
  8563. }
  8564. project.FrequencyType = 1
  8565. return 0
  8566. }
  8567. func (c *HisApiController) GetHisOrderListTwo() {
  8568. start_time := c.GetString("start_time")
  8569. end_time := c.GetString("end_time")
  8570. timeLayout := "2006-01-02"
  8571. loc, _ := time.LoadLocation("Local")
  8572. var startTime int64
  8573. if len(start_time) > 0 {
  8574. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8575. if err != nil {
  8576. //fmt.Println(err)
  8577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8578. return
  8579. }
  8580. startTime = theTime.Unix()
  8581. }
  8582. var endTime int64
  8583. if len(end_time) > 0 {
  8584. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8585. if err != nil {
  8586. utils.ErrorLog(err.Error())
  8587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8588. return
  8589. }
  8590. endTime = theTime.Unix()
  8591. }
  8592. adminUser := c.GetAdminUserInfo()
  8593. org_id := adminUser.CurrentOrgId
  8594. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8595. if err == nil {
  8596. c.ServeSuccessJSON(map[string]interface{}{
  8597. "order2": order,
  8598. })
  8599. } else {
  8600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8601. return
  8602. }
  8603. }
  8604. func (c *HisApiController) GetHisOrderList() {
  8605. page, _ := c.GetInt64("page", -1)
  8606. limit, _ := c.GetInt64("limit", -1)
  8607. start_time := c.GetString("start_time")
  8608. end_time := c.GetString("end_time")
  8609. types, _ := c.GetInt64("type", 0)
  8610. keywords := c.GetString("keywords")
  8611. p_type, _ := c.GetInt64("p_type", 0)
  8612. sort_type, _ := c.GetInt64("sort_type", 0)
  8613. charge_type, _ := c.GetInt64("charge_type", 0)
  8614. sch_type, _ := c.GetInt64("sch_type", 0)
  8615. zone_type, _ := c.GetInt64("zone_type", 0)
  8616. med_type, _ := c.GetInt64("med_type", 0)
  8617. timeLayout := "2006-01-02"
  8618. loc, _ := time.LoadLocation("Local")
  8619. var startTime int64
  8620. if len(start_time) > 0 {
  8621. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8622. if err != nil {
  8623. //fmt.Println(err)
  8624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8625. return
  8626. }
  8627. startTime = theTime.Unix()
  8628. }
  8629. var endTime int64
  8630. if len(end_time) > 0 {
  8631. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8632. if err != nil {
  8633. utils.ErrorLog(err.Error())
  8634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8635. return
  8636. }
  8637. endTime = theTime.Unix()
  8638. }
  8639. adminUser := c.GetAdminUserInfo()
  8640. org_id := adminUser.CurrentOrgId
  8641. 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)
  8642. for _, item := range order {
  8643. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8644. item.DoctorName = info.Doctor
  8645. item.DepartmentName = info.XtHisDepartment.Name
  8646. }
  8647. if err == nil {
  8648. c.ServeSuccessJSON(map[string]interface{}{
  8649. "order": order,
  8650. "total": total,
  8651. })
  8652. } else {
  8653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8654. return
  8655. }
  8656. }
  8657. func (c *HisApiController) GetHisOrder() {
  8658. patient_id, _ := c.GetInt64("patient_id", 0)
  8659. number := c.GetString("number")
  8660. adminInfo := c.GetAdminUserInfo()
  8661. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8662. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8663. if err == nil {
  8664. c.ServeSuccessJSON(map[string]interface{}{
  8665. "order": order,
  8666. "prescription": prescriptions,
  8667. })
  8668. } else {
  8669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8670. return
  8671. }
  8672. }
  8673. func (c *HisApiController) GetHisPrescriptionList() {
  8674. record_date := c.GetString("record_date")
  8675. keywords := c.GetString("keywords")
  8676. page, _ := c.GetInt64("page")
  8677. limit, _ := c.GetInt64("limit")
  8678. sch_type, _ := c.GetInt64("sch_type")
  8679. timeLayout := "2006-01-02"
  8680. loc, _ := time.LoadLocation("Local")
  8681. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8682. if err != nil {
  8683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8684. return
  8685. }
  8686. recordDateTime := theTime.Unix()
  8687. adminInfo := c.GetAdminUserInfo()
  8688. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8689. //adminInfo := c.GetAdminUserInfo()
  8690. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8691. //fmt.Println(prescriptionOrder)
  8692. if err == nil {
  8693. c.ServeSuccessJSON(map[string]interface{}{
  8694. "order": prescriptionOrder,
  8695. "total": total,
  8696. })
  8697. } else {
  8698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8699. return
  8700. }
  8701. }
  8702. func (c *HisApiController) GetHisPrescriptionInfo() {
  8703. id, _ := c.GetInt64("id")
  8704. adminInfo := c.GetAdminUserInfo()
  8705. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8706. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8707. if err == nil {
  8708. c.ServeSuccessJSON(map[string]interface{}{
  8709. "order": prescriptionOrder,
  8710. "prescription": prescription,
  8711. })
  8712. } else {
  8713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8714. return
  8715. }
  8716. }
  8717. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8718. adminUser := c.GetAdminUserInfo()
  8719. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8720. c.ServeSuccessJSON(map[string]interface{}{
  8721. "config": config,
  8722. })
  8723. }
  8724. type ResultTwo struct {
  8725. ErrMsg interface{} `json:"err_msg"`
  8726. InfRefmsgid string `json:"inf_refmsgid"`
  8727. Infcode int64 `json:"infcode"`
  8728. Output struct {
  8729. Baseinfo struct {
  8730. Age float64 `json:"age"`
  8731. Brdy string `json:"brdy"`
  8732. Certno string `json:"certno"`
  8733. Gend string `json:"gend"`
  8734. Naty string `json:"naty"`
  8735. PsnCertType string `json:"psn_cert_type"`
  8736. PsnName string `json:"psn_name"`
  8737. PsnNo string `json:"psn_no"`
  8738. } `json:"baseinfo"`
  8739. Idetinfo []interface{} `json:"idetinfo"`
  8740. Iinfo []struct {
  8741. Balc float64 `json:"balc"`
  8742. CvlservFlag string `json:"cvlserv_flag"`
  8743. EmpName string `json:"emp_name"`
  8744. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8745. Insutype string `json:"insutype"`
  8746. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8747. PausInsuDate interface{} `json:"paus_insu_date"`
  8748. PsnInsuDate string `json:"psn_insu_date"`
  8749. PsnInsuStas string `json:"psn_insu_stas"`
  8750. PsnType string `json:"psn_type"`
  8751. } `json:"insuinfo"`
  8752. } `json:"output"`
  8753. RefmsgTime string `json:"refmsg_time"`
  8754. RespondTime string `json:"respond_time"`
  8755. Signtype interface{} `json:"signtype"`
  8756. WarnInfo interface{} `json:"warn_info"`
  8757. }
  8758. type ResultThree struct {
  8759. Cainfo interface{} `json:"cainfo"`
  8760. ErrMsg interface{} `json:"err_msg"`
  8761. InfRefmsgid string `json:"inf_refmsgid"`
  8762. Infcode int64 `json:"infcode"`
  8763. Output struct {
  8764. Data struct {
  8765. IptOtpNo string `json:"ipt_otp_no"`
  8766. MdtrtID string `json:"mdtrt_id"`
  8767. PsnNo string `json:"psn_no"`
  8768. } `json:"data"`
  8769. } `json:"output"`
  8770. RefmsgTime string `json:"refmsg_time"`
  8771. RespondTime string `json:"respond_time"`
  8772. Signtype interface{} `json:"signtype"`
  8773. WarnMsg interface{} `json:"warn_msg"`
  8774. }
  8775. type ResultFour struct {
  8776. Cainfo string `json:"cainfo"`
  8777. ErrMsg string `json:"err_msg"`
  8778. InfRefmsgid string `json:"inf_refmsgid"`
  8779. Infcode int64 `json:"infcode"`
  8780. Output struct {
  8781. Result []struct {
  8782. BasMednFlag string `json:"bas_medn_flag"`
  8783. ChldMedcFlag string `json:"chld_medc_flag"`
  8784. ChrgitmLv string `json:"chrgitm_lv"`
  8785. Cnt float64 `json:"cnt"`
  8786. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8787. DrtReimFlag string `json:"drt_reim_flag"`
  8788. FeedetlSn string `json:"feedetl_sn"`
  8789. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8790. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8791. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8792. ListSpItemFlag string `json:"list_sp_item_flag"`
  8793. LmtUsedFlag string `json:"lmt_used_flag"`
  8794. MedChrgitmType string `json:"med_chrgitm_type"`
  8795. Memo string `json:"memo"`
  8796. OverlmtAmt float64 `json:"overlmt_amt"`
  8797. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8798. Pric float64 `json:"pric"`
  8799. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8800. SelfpayProp float64 `json:"selfpay_prop"`
  8801. } `json:"result"`
  8802. } `json:"output"`
  8803. RefmsgTime string `json:"refmsg_time"`
  8804. RespondTime string `json:"respond_time"`
  8805. Signtype string `json:"signtype"`
  8806. WarnMsg string `json:"warn_msg"`
  8807. }
  8808. type ResultFive struct {
  8809. Insutype string `json:"insutype"`
  8810. }
  8811. type ResultSix struct {
  8812. Cainfo interface{} `json:"cainfo"`
  8813. ErrMsg interface{} `json:"err_msg"`
  8814. InfRefmsgid string `json:"inf_refmsgid"`
  8815. Infcode int64 `json:"infcode"`
  8816. Output struct {
  8817. } `json:"output"`
  8818. RefmsgTime string `json:"refmsg_time"`
  8819. RespondTime string `json:"respond_time"`
  8820. Signtype interface{} `json:"signtype"`
  8821. WarnMsg interface{} `json:"warn_msg"`
  8822. }
  8823. type ResultSeven struct {
  8824. Cainfo string `json:"cainfo"`
  8825. ErrMsg string `json:"err_msg"`
  8826. InfRefmsgid string `json:"inf_refmsgid"`
  8827. Infcode int64 `json:"infcode"`
  8828. Output struct {
  8829. Setldetail []interface{} `json:"setldetail"`
  8830. Setlinfo struct {
  8831. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8832. AcctPay float64 `json:"acct_pay"`
  8833. ActPayDedc float64 `json:"act_pay_dedc"`
  8834. Age float64 `json:"age"`
  8835. Balc float64 `json:"balc"`
  8836. Brdy string `json:"brdy"`
  8837. Certno string `json:"certno"`
  8838. ClrOptins string `json:"clr_optins"`
  8839. ClrType string `json:"clr_type"`
  8840. ClrWay string `json:"clr_way"`
  8841. CvlservFlag string `json:"cvlserv_flag"`
  8842. CvlservPay float64 `json:"cvlserv_pay"`
  8843. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8844. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8845. Gend string `json:"gend"`
  8846. HifesPay float64 `json:"hifes_pay"`
  8847. HifmiPay float64 `json:"hifmi_pay"`
  8848. HifobPay float64 `json:"hifob_pay"`
  8849. HifpPay float64 `json:"hifp_pay"`
  8850. HospPartAmt float64 `json:"hosp_part_amt"`
  8851. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8852. Insutype string `json:"insutype"`
  8853. MafPay float64 `json:"maf_pay"`
  8854. MdtrtCertType string `json:"mdtrt_cert_type"`
  8855. MdtrtID string `json:"mdtrt_id"`
  8856. MedType string `json:"med_type"`
  8857. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8858. MedinsSetlID string `json:"medins_setl_id"`
  8859. Naty string `json:"naty"`
  8860. OthPay float64 `json:"oth_pay"`
  8861. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8862. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8863. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8864. PsnCashPay float64 `json:"psn_cash_pay"`
  8865. PsnCertType string `json:"psn_cert_type"`
  8866. PsnName string `json:"psn_name"`
  8867. PsnNo string `json:"psn_no"`
  8868. PsnPartAmt float64 `json:"psn_part_amt"`
  8869. PsnType string `json:"psn_type"`
  8870. SetlID string `json:"setl_id"`
  8871. SetlTime string `json:"setl_time"`
  8872. } `json:"setlinfo"`
  8873. } `json:"output"`
  8874. RefmsgTime string `json:"refmsg_time"`
  8875. RespondTime string `json:"respond_time"`
  8876. Signtype interface{} `json:"signtype"`
  8877. WarnMsg interface{} `json:"warn_msg"`
  8878. }
  8879. type ResultEight struct {
  8880. Cainfo string `json:"cainfo"`
  8881. ErrMsg string `json:"err_msg"`
  8882. InfRefmsgid string `json:"inf_refmsgid"`
  8883. Infcode int64 `json:"infcode"`
  8884. Output struct {
  8885. Stmtinfo struct {
  8886. SetlOptins string `json:"setl_optins"`
  8887. StmtRslt string `json:"stmt_rslt"`
  8888. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8889. } `json:"stmtinfo"`
  8890. } `json:"output"`
  8891. RefmsgTime string `json:"refmsg_time"`
  8892. RespondTime string `json:"respond_time"`
  8893. Signtype interface{} `json:"signtype"`
  8894. WarnMsg interface{} `json:"warn_msg"`
  8895. }
  8896. type ResultNine struct {
  8897. Cainfo string `json:"cainfo"`
  8898. ErrMsg string `json:"err_msg"`
  8899. InfRefmsgid string `json:"inf_refmsgid"`
  8900. Infcode int64 `json:"infcode"`
  8901. Output struct {
  8902. FileQuryNo string `json:"file_qury_no"`
  8903. } `json:"output"`
  8904. RefmsgTime string `json:"refmsg_time"`
  8905. RespondTime string `json:"respond_time"`
  8906. Signtype interface{} `json:"signtype"`
  8907. WarnMsg interface{} `json:"warn_msg"`
  8908. }
  8909. type ResultTen struct {
  8910. Cainfo string `json:"cainfo"`
  8911. ErrMsg string `json:"err_msg"`
  8912. InfRefmsgid string `json:"inf_refmsgid"`
  8913. Infcode int64 `json:"infcode"`
  8914. Output struct {
  8915. DldEndtime string `json:"dld_endtime"`
  8916. FileQuryNo string `json:"file_qury_no"`
  8917. Filename string `json:"filename"`
  8918. } `json:"output"`
  8919. RefmsgTime string `json:"refmsg_time"`
  8920. RespondTime string `json:"respond_time"`
  8921. Signtype interface{} `json:"signtype"`
  8922. WarnMsg interface{} `json:"warn_msg"`
  8923. }
  8924. type ResultEleven struct {
  8925. Cainfo string `json:"cainfo"`
  8926. ErrMsg string `json:"err_msg"`
  8927. InfRefmsgid string `json:"inf_refmsgid"`
  8928. Infcode int64 `json:"infcode"`
  8929. Output struct {
  8930. Setlinfo struct {
  8931. FixmedinsName string `json:"fixmedins_name"`
  8932. FixmedinsCode string `json:"fixmedins_code"`
  8933. PsnNo string `json:"psn_no"`
  8934. PsnName string `json:"psn_name"`
  8935. HifobPay float64 `json:"hifob_pay"`
  8936. Gend string `json:"gend"`
  8937. Brdy string `json:"brdy"`
  8938. PsnCertType string `json:"psn_cert_type"`
  8939. PsnType string `json:"psn_type"`
  8940. EmpName string `json:"emp_name"`
  8941. Certno string `json:"certno"`
  8942. Insutype string `json:"insutype"`
  8943. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8944. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8945. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8946. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8947. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8948. ActPayDedc float64 `json:"act_pay_dedc"`
  8949. HifpPay float64 `json:"hifp_pay"`
  8950. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8951. CvlservPay float64 `json:"cvlserv_pay"`
  8952. HifesPay float64 `json:"hifes_pay"`
  8953. HifmiPay float64 `json:"hifmi_pay"`
  8954. MafPay float64 `json:"maf_pay"`
  8955. OthPay float64 `json:"oth_pay"`
  8956. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8957. PsnPay float64 `json:"psn_pay"`
  8958. AcctPay float64 `json:"acct_pay"`
  8959. CashPayamt float64 `json:"cash_payamt"`
  8960. Balc float64 `json:"balc"`
  8961. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8962. MedinsSetlId string `json:"medins_setl_id"`
  8963. RefdSetlFlag string `json:"refd_setl_flag"`
  8964. SetlTime string `json:"setl_time"`
  8965. MedType string `json:"med_type"`
  8966. } `json:"setlinfo"`
  8967. } `json:"output"`
  8968. RefmsgTime string `json:"refmsg_time"`
  8969. RespondTime string `json:"respond_time"`
  8970. Signtype interface{} `json:"signtype"`
  8971. WarnMsg interface{} `json:"warn_msg"`
  8972. }
  8973. type Custom struct {
  8974. DetItemFeeSumamt string
  8975. Cut string
  8976. FeedetlSn string
  8977. Price string
  8978. MedListCodg string
  8979. Type int64
  8980. AdviceId int64
  8981. ProjectId int64
  8982. ItemId int64
  8983. CostType int64
  8984. }
  8985. // 获取个人信息----挂号-----上传就诊信息
  8986. func (c *HisApiController) GetRegisterInfo() {
  8987. id, _ := c.GetInt64("id")
  8988. record_time := c.GetString("record_time")
  8989. settlementValue, _ := c.GetInt64("settlement_value")
  8990. medical_insurance_card := c.GetString("medical_insurance_card")
  8991. name := c.GetString("name")
  8992. id_card_type, _ := c.GetInt64("id_card_type")
  8993. certificates, _ := c.GetInt64("certificates")
  8994. medical_care, _ := c.GetInt64("medical_care")
  8995. birthday := c.GetString("birthday")
  8996. age, _ := c.GetInt64("age")
  8997. id_card := c.GetString("id_card")
  8998. register_type, _ := c.GetInt64("register")
  8999. doctor, _ := c.GetInt64("doctor")
  9000. department, _ := c.GetInt64("department")
  9001. gender, _ := c.GetInt64("sex")
  9002. phone := c.GetString("phone")
  9003. registration_fee, _ := c.GetFloat("registration_fee")
  9004. medical_expenses, _ := c.GetFloat("medical_expenses")
  9005. social_type, _ := c.GetInt64("social_type")
  9006. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9007. diagnosis_ids := c.GetString("diagnosis")
  9008. sick_type, _ := c.GetInt64("sick_type")
  9009. reg_type := c.GetString("p_type")
  9010. timeLayout := "2006-01-02"
  9011. loc, _ := time.LoadLocation("Local")
  9012. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9013. birthUnix := birthdays.Unix()
  9014. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9015. if err != nil {
  9016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9017. return
  9018. }
  9019. recordDateTime := theTime.Unix()
  9020. adminInfo := c.GetAdminUserInfo()
  9021. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9022. if tempPatient.ID == 0 {
  9023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9024. return
  9025. }
  9026. var patient service.Patients
  9027. if id == 0 {
  9028. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9029. } else {
  9030. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9031. }
  9032. if patient.ID == 0 {
  9033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9034. return
  9035. }
  9036. if len(patient.IdCardNo) == 0 {
  9037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9038. return
  9039. }
  9040. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9041. if len(his) >= 1 {
  9042. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9043. if len(his) >= 1 && order.ID == 0 {
  9044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9045. return
  9046. }
  9047. }
  9048. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9049. fmt.Println(timeStr)
  9050. timeArr := strings.Split(timeStr, " ")
  9051. fmt.Println(timeArr)
  9052. timeArrTwo := strings.Split(timeArr[0], "-")
  9053. timeArrThree := strings.Split(timeArr[1], ":")
  9054. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9055. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9056. if len(lists) == 0 {
  9057. var hisPatient models.XtHisPatient
  9058. hisPatient = models.XtHisPatient{
  9059. Name: name,
  9060. Age: age,
  9061. Gender: gender,
  9062. Birthday: birthUnix,
  9063. Phone: phone,
  9064. MedicalTreatmentType: medical_care,
  9065. IdType: certificates,
  9066. IdCardNo: id_card,
  9067. BalanceAccountsType: settlementValue,
  9068. SocialType: social_type,
  9069. MedicalInsuranceNumber: medical_insurance_card,
  9070. RegisterType: register_type,
  9071. RegisterCost: registration_fee,
  9072. TreatmentCost: medical_expenses,
  9073. AdminUserId: adminInfo.AdminUser.Id,
  9074. UserOrgId: adminInfo.CurrentOrgId,
  9075. Status: 1,
  9076. RecordDate: recordDateTime,
  9077. IsReturn: 1,
  9078. PatientId: patient.ID,
  9079. Ctime: time.Now().Unix(),
  9080. Mtime: time.Now().Unix(),
  9081. Number: str,
  9082. IdCardType: id_card_type,
  9083. Departments: department,
  9084. Doctor: doctor,
  9085. PType: reg_type,
  9086. Diagnosis: diagnosis_ids,
  9087. SickType: sick_type,
  9088. }
  9089. service.CreateHisPatient(&hisPatient)
  9090. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9091. c.ServeSuccessJSON(map[string]interface{}{
  9092. "his_info": hisPatient,
  9093. })
  9094. } else {
  9095. //chrgBchno := rand.Intn(1000000) + 10000
  9096. var hisPatient models.XtHisPatient
  9097. hisPatient = models.XtHisPatient{
  9098. Name: name,
  9099. Age: age,
  9100. Gender: gender,
  9101. Birthday: birthUnix,
  9102. Phone: phone,
  9103. MedicalTreatmentType: medical_care,
  9104. IdType: certificates,
  9105. IdCardNo: id_card,
  9106. BalanceAccountsType: settlementValue,
  9107. SocialType: social_type,
  9108. MedicalInsuranceNumber: medical_insurance_card,
  9109. RegisterType: register_type,
  9110. RegisterCost: registration_fee,
  9111. TreatmentCost: medical_expenses,
  9112. AdminUserId: adminInfo.AdminUser.Id,
  9113. UserOrgId: adminInfo.CurrentOrgId,
  9114. Status: 1,
  9115. RecordDate: recordDateTime,
  9116. IsReturn: 1,
  9117. PatientId: patient.ID,
  9118. Ctime: time.Now().Unix(),
  9119. Mtime: time.Now().Unix(),
  9120. Number: str,
  9121. IdCardType: id_card_type,
  9122. Departments: department,
  9123. Doctor: doctor,
  9124. PType: reg_type,
  9125. Diagnosis: diagnosis_ids,
  9126. SickType: sick_type,
  9127. }
  9128. service.CreateHisPatient(&hisPatient)
  9129. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9130. c.ServeSuccessJSON(map[string]interface{}{
  9131. "his_info": hisPatient,
  9132. })
  9133. }
  9134. }
  9135. // 上传明细----结算
  9136. func (c *HisApiController) GetUploadInfo() {
  9137. id, _ := c.GetInt64("id")
  9138. record_time := c.GetString("record_time")
  9139. his_patient_id, _ := c.GetInt64("his_patient_id")
  9140. oth_desc := c.GetString("oth_desc")
  9141. pay_way, _ := c.GetInt64("pay_way")
  9142. pay_ways := c.GetString("pay_ways")
  9143. pay_price, _ := c.GetFloat("pay_price")
  9144. pay_card_no := c.GetString("pay_card_no")
  9145. discount_price, _ := c.GetFloat("discount_price")
  9146. preferential_price, _ := c.GetFloat("preferential_price")
  9147. reality_price, _ := c.GetFloat("reality_price")
  9148. found_price, _ := c.GetFloat("found_price")
  9149. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9150. private_price, _ := c.GetFloat("private_price")
  9151. timeLayout := "2006-01-02"
  9152. loc, _ := time.LoadLocation("Local")
  9153. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9154. fapiao_code := c.GetString("fapiao_code")
  9155. fapiao_number := c.GetString("fapiao_number")
  9156. diagnosis_id := c.GetString("diagnosis")
  9157. sick_type, _ := c.GetInt64("sick_type")
  9158. reg_type, _ := c.GetInt64("p_type")
  9159. order_id, _ := c.GetInt64("order_id")
  9160. cash_pay := c.GetString("cash_pay")
  9161. wechat_pay := c.GetString("wechat_pay")
  9162. ali_pay := c.GetString("ali_pay")
  9163. jifen_pay := c.GetString("jifen_pay")
  9164. band_card_pay := c.GetString("band_card_pay")
  9165. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9166. tmp_decimal := c.GetString("tmp_decimal")
  9167. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9168. var decimal float64 //本次使用的押金
  9169. var errmsg error
  9170. tx := service.XTWriteDB().Begin() //开了事务
  9171. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9172. defer func() {
  9173. if errmsg != nil {
  9174. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9175. tx.Rollback()
  9176. } else {
  9177. tx.Commit()
  9178. }
  9179. }()
  9180. fmt.Println("dec_way", dec_way)
  9181. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9182. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9183. return
  9184. }
  9185. if len(tmp_decimal) > 0 {
  9186. if tmp_decimal[0] == 45 {
  9187. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9188. return
  9189. }
  9190. }
  9191. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9192. fmt.Println(errs)
  9193. decimal = tt
  9194. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9195. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9196. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9197. if err != nil {
  9198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9199. return
  9200. }
  9201. recordDateTime := theTime.Unix()
  9202. adminUser := c.GetAdminUserInfo()
  9203. var prescriptions []*models.HisPrescription
  9204. var prescriptionsOne []*models.HisPrescription
  9205. var start_time int64
  9206. var end_time int64
  9207. ids_str := c.GetString("ids")
  9208. ids_arr := strings.Split(ids_str, ",")
  9209. if tempOrder.ID == 0 {
  9210. if settle_accounts_type == 1 { //日结
  9211. fmt.Println(reg_type)
  9212. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9213. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9214. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9215. } else {
  9216. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9217. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9218. }
  9219. } else { //月结
  9220. start_time_str := c.GetString("start_time")
  9221. end_time_str := c.GetString("end_time")
  9222. timeLayout := "2006-01-02"
  9223. loc, _ := time.LoadLocation("Local")
  9224. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9225. if err != nil {
  9226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9227. return
  9228. }
  9229. recordStartTime := theStartTime.Unix()
  9230. start_time = recordStartTime
  9231. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9232. if err != nil {
  9233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9234. return
  9235. }
  9236. recordEndTime := theEndTime.Unix()
  9237. end_time = recordEndTime
  9238. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9239. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9240. }
  9241. var goods []*models.DialysisBeforePrepareGoods
  9242. var newGoods []*models.NewDialysisBeforePrepareGoods
  9243. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9244. var infos []*models.HisDoctorAdviceInfo
  9245. var infoList []*models.HisDoctorAdviceInfo
  9246. var hisAdvice []*models.HisDoctorAdviceInfo
  9247. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9248. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9249. //判断库存不足
  9250. //结算出库开关
  9251. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9252. if settConfig.IsOpen == 1 {
  9253. //判断库存的地方
  9254. for _, info := range prescriptions {
  9255. if info.Type == 1 {
  9256. infos = append(infos, info.HisDoctorAdviceInfo...)
  9257. }
  9258. if info.Type == 2 {
  9259. for _, sumItem := range info.HisPrescriptionProject {
  9260. if sumItem.Type == 3 {
  9261. var good models.DialysisBeforePrepareGoods
  9262. var newGood models.NewDialysisBeforePrepareGoods
  9263. good.GoodId = sumItem.GoodInfo.ID
  9264. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9265. count, _ := strconv.Atoi(sumItem.Count)
  9266. good.Count = int64(count)
  9267. good.StorehouseId = houseConfig.StorehouseOutInfo
  9268. good.ProjectId = sumItem.ID
  9269. goods = append(goods, &good)
  9270. newGood.GoodId = sumItem.GoodInfo.ID
  9271. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9272. count2, _ := strconv.Atoi(sumItem.Count)
  9273. newGood.Count = int64(count2)
  9274. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9275. newGood.ProjectId = sumItem.ID
  9276. newGoods = append(newGoods, &newGood)
  9277. }
  9278. }
  9279. }
  9280. }
  9281. for _, info := range prescriptionsOne {
  9282. if info.Type == 1 {
  9283. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9284. }
  9285. if info.Type == 2 {
  9286. for _, sumItem := range info.HisPrescriptionProject {
  9287. if sumItem.Type == 3 {
  9288. var newGood models.NewDialysisBeforePrepareGoods
  9289. newGood.GoodId = sumItem.GoodInfo.ID
  9290. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9291. count2, _ := strconv.Atoi(sumItem.Count)
  9292. newGood.Count = int64(count2)
  9293. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9294. newGood.ProjectId = sumItem.ID
  9295. newGoodOne = append(newGoodOne, &newGood)
  9296. }
  9297. }
  9298. }
  9299. }
  9300. //判断
  9301. for _, itemOne := range infos {
  9302. for _, itemTwo := range hisAdvice {
  9303. if itemOne.DrugId == itemTwo.DrugId {
  9304. itemTwo.Child = append(itemTwo.Child, itemOne)
  9305. }
  9306. }
  9307. }
  9308. for _, itemTwo := range hisAdvice {
  9309. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9310. var sum_out_count int64
  9311. for _, itemThree := range itemTwo.Child {
  9312. var prescribing_number int64
  9313. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9314. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9315. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9316. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9317. }
  9318. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9319. prescribing_number = parseIntPrescribingNumber
  9320. }
  9321. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9322. prescribing_number = parseIntPrescribingNumber
  9323. }
  9324. sum_out_count += prescribing_number
  9325. }
  9326. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9327. if sum_out_count > drugStockOut.FlushCount {
  9328. c.ServeSuccessJSON(map[string]interface{}{
  9329. "msg": "2",
  9330. "drug": medical,
  9331. })
  9332. return
  9333. }
  9334. }
  9335. for _, itemOne := range newGoods {
  9336. for _, item := range newGoodOne {
  9337. if itemOne.GoodId == item.GoodId {
  9338. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9339. }
  9340. }
  9341. }
  9342. for _, item := range newGoodOne {
  9343. var sum_out_count_one int64
  9344. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9345. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9346. sum_out_count_one += itemOne.Count
  9347. }
  9348. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9349. fmt.Println("sum_out_count_one", sum_out_count_one)
  9350. fmt.Println("list.FlushCount", list.FlushCount)
  9351. if sum_out_count_one > list.FlushCount {
  9352. c.ServeSuccessJSON(map[string]interface{}{
  9353. "msg": "3",
  9354. "good": good,
  9355. })
  9356. return
  9357. }
  9358. }
  9359. }
  9360. timestamp := time.Now().Unix()
  9361. tempTime := time.Unix(timestamp, 0)
  9362. timeFormat := tempTime.Format("20060102150405")
  9363. chrgBchno := rand.Intn(100000) + 10000
  9364. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9365. strconv.FormatInt(his.PatientId, 10)
  9366. var ids []int64
  9367. for _, item := range prescriptions {
  9368. ids = append(ids, item.ID)
  9369. }
  9370. var total float64
  9371. for _, item := range prescriptions {
  9372. fmt.Println(item)
  9373. if item.Type == 1 { //药品
  9374. for _, subItem := range item.HisDoctorAdviceInfo {
  9375. total = total + (subItem.Price * subItem.PrescribingNumber)
  9376. }
  9377. }
  9378. if item.Type == 2 { //项目
  9379. for _, subItem := range item.HisPrescriptionProject {
  9380. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9381. total = total + (subItem.Price * cnt)
  9382. }
  9383. }
  9384. for _, subItem := range item.HisAdditionalCharge {
  9385. total = total + (subItem.Price * float64(subItem.Count))
  9386. }
  9387. }
  9388. if reg_type == 1111 || reg_type == 1112 {
  9389. reg_type = 11
  9390. }
  9391. tm := time.Unix(time.Now().Unix(), 0)
  9392. allTotal := fmt.Sprintf("%.4f", total)
  9393. totals, _ := strconv.ParseFloat(allTotal, 64)
  9394. order := &models.HisOrder{
  9395. UserOrgId: adminUser.CurrentOrgId,
  9396. HisPatientId: his.ID,
  9397. PatientId: id,
  9398. SettleAccountsDate: recordDateTime,
  9399. Ctime: time.Now().Unix(),
  9400. Mtime: time.Now().Unix(),
  9401. Status: 1,
  9402. OrderStatus: 2,
  9403. MdtrtId: his.Number,
  9404. Number: chrg_bchno,
  9405. MedfeeSumamt: totals,
  9406. PayWay: pay_way,
  9407. PayWays: pay_ways,
  9408. PayPrice: pay_price,
  9409. MedType: strconv.Itoa(int(reg_type)),
  9410. PayCardNo: pay_card_no,
  9411. DiscountPrice: discount_price,
  9412. PreferentialPrice: preferential_price,
  9413. RealityPrice: reality_price,
  9414. FoundPrice: found_price,
  9415. MedicalInsurancePrice: medical_insurance_price,
  9416. PrivatePrice: private_price,
  9417. SettleEndTime: end_time,
  9418. SettleStartTime: start_time,
  9419. PsnPartAmt: totals,
  9420. PsnCashPay: totals,
  9421. SettleType: settle_accounts_type,
  9422. FaPiaoCode: fapiao_code,
  9423. FaPiaoNumber: fapiao_number,
  9424. Diagnosis: diagnosis_id,
  9425. PType: 2,
  9426. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9427. Decimal: decimal,
  9428. OthDesc: oth_desc,
  9429. CashPay: cash_pay,
  9430. WechatPay: wechat_pay,
  9431. AliPay: ali_pay,
  9432. JifenPay: jifen_pay,
  9433. BandCardPay: band_card_pay,
  9434. Creator: adminUser.AdminUser.Id,
  9435. }
  9436. err = service.CreateOrderTX(order, tx)
  9437. if err != nil {
  9438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9439. return
  9440. }
  9441. var customs []*Custom
  9442. for _, item := range prescriptions {
  9443. if item.Type == 1 { //药品a
  9444. for _, subItem := range item.HisDoctorAdviceInfo {
  9445. cus := &Custom{
  9446. AdviceId: subItem.ID,
  9447. ProjectId: 0,
  9448. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9449. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9450. FeedetlSn: subItem.FeedetlSn,
  9451. Price: fmt.Sprintf("%.4f", subItem.Price),
  9452. MedListCodg: subItem.MedListCodg,
  9453. Type: 1,
  9454. CostType: 9,
  9455. }
  9456. customs = append(customs, cus)
  9457. }
  9458. }
  9459. if item.Type == 2 { //项目
  9460. for _, subItem := range item.HisPrescriptionProject {
  9461. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9462. cus := &Custom{
  9463. AdviceId: 0,
  9464. ProjectId: subItem.ID,
  9465. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9466. Cut: fmt.Sprintf("%.4f", cnt),
  9467. FeedetlSn: subItem.FeedetlSn,
  9468. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9469. MedListCodg: subItem.MedListCodg,
  9470. Type: 2,
  9471. CostType: subItem.HisProject.CostClassify,
  9472. }
  9473. customs = append(customs, cus)
  9474. }
  9475. }
  9476. for _, item := range item.HisAdditionalCharge {
  9477. cus := &Custom{
  9478. ItemId: item.ID,
  9479. AdviceId: 0,
  9480. ProjectId: 0,
  9481. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9482. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9483. FeedetlSn: item.FeedetlSn,
  9484. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9485. MedListCodg: item.XtHisAddtionConfig.Code,
  9486. Type: 3,
  9487. CostType: 5,
  9488. }
  9489. customs = append(customs, cus)
  9490. }
  9491. }
  9492. for _, item := range customs {
  9493. var advice_id int64 = 0
  9494. var project_id int64 = 0
  9495. var item_id int64 = 0
  9496. var types int64 = 0
  9497. var med_chrgitm_type string
  9498. if item.Type == 1 {
  9499. advice_id = item.AdviceId
  9500. project_id = 0
  9501. item_id = 0
  9502. med_chrgitm_type = "09"
  9503. } else if item.Type == 2 {
  9504. med_chrgitm_type = "05"
  9505. if item.CostType == 3 {
  9506. med_chrgitm_type = "04"
  9507. }
  9508. if item.CostType == 8 {
  9509. med_chrgitm_type = "03"
  9510. }
  9511. advice_id = 0
  9512. item_id = 0
  9513. project_id = item.ProjectId
  9514. } else if item.Type == 3 {
  9515. advice_id = 0
  9516. item_id = item.ItemId
  9517. project_id = 0
  9518. med_chrgitm_type = "08"
  9519. }
  9520. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9521. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9522. pric, _ := strconv.ParseFloat(item.Price, 32)
  9523. info := &models.HisOrderInfo{
  9524. OrderNumber: order.Number,
  9525. UploadDate: time.Now().Unix(),
  9526. AdviceId: advice_id,
  9527. DetItemFeeSumamt: detItemFeeSumamt,
  9528. MedChrgitmType: med_chrgitm_type,
  9529. Cnt: cut,
  9530. Pric: pric,
  9531. PatientId: id,
  9532. Status: 1,
  9533. Mtime: time.Now().Unix(),
  9534. Ctime: time.Now().Unix(),
  9535. UserOrgId: adminUser.CurrentOrgId,
  9536. HisPatientId: his.ID,
  9537. OrderId: order.ID,
  9538. ProjectId: project_id,
  9539. Type: types,
  9540. ItemId: item_id,
  9541. }
  9542. service.CreateOrderInfoTX(info, tx)
  9543. }
  9544. his.Diagnosis = diagnosis_id
  9545. his.SickType = sick_type
  9546. his.RegisterType = reg_type
  9547. his.MedicalTreatmentType = reg_type
  9548. service.UpdataHisPateintTX(&his, tx)
  9549. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9550. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9551. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9552. //判断是否使用了押金
  9553. if dec_way == "true" {
  9554. tmpstring := strconv.FormatInt(order.ID, 10)
  9555. //扣押金
  9556. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9557. order.Decimal = decimal
  9558. service.UpDateOrderTwo(order, tx)
  9559. if errmsg != nil {
  9560. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9561. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9562. return
  9563. }
  9564. }
  9565. if err == nil {
  9566. for _, info := range prescriptions {
  9567. if info.Type == 1 {
  9568. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9569. }
  9570. if info.Type == 2 {
  9571. for _, sumItem := range info.HisPrescriptionProject {
  9572. if sumItem.Type == 3 {
  9573. var good models.DialysisBeforePrepareGoods
  9574. var newGood models.NewDialysisBeforePrepareGoods
  9575. var oldGood models.OldDialysisBeforePrepareGoods
  9576. good.GoodId = sumItem.GoodInfo.ID
  9577. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9578. count, _ := strconv.Atoi(sumItem.Count)
  9579. good.Count = int64(count)
  9580. good.StorehouseId = houseConfig.StorehouseOutInfo
  9581. good.ProjectId = sumItem.ID
  9582. good.PatientId = sumItem.PatientId
  9583. goods = append(goods, &good)
  9584. newGood.GoodId = sumItem.GoodInfo.ID
  9585. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9586. count2, _ := strconv.Atoi(sumItem.Count)
  9587. newGood.Count = int64(count2)
  9588. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9589. newGood.ProjectId = sumItem.ID
  9590. newGood.PatientId = sumItem.HisPatientId
  9591. newGoods = append(newGoods, &newGood)
  9592. oldGood.GoodId = sumItem.GoodInfo.ID
  9593. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9594. count3, _ := strconv.Atoi(sumItem.Count)
  9595. oldGood.Count = int64(count3)
  9596. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9597. oldGood.ProjectId = sumItem.ID
  9598. oldGood.RecordDate = sumItem.RecordDate
  9599. oldGood.PatientId = sumItem.HisPatientId
  9600. oldGoods = append(oldGoods, &oldGood)
  9601. }
  9602. }
  9603. }
  9604. }
  9605. if settConfig.IsOpen == 1 {
  9606. for _, item := range infoList {
  9607. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9608. if medical.IsUse == 2 {
  9609. //药品出库
  9610. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9611. //查询默认仓库
  9612. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9613. //查询默认仓库剩余多少库存
  9614. var sum_count int64
  9615. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9616. for _, its := range stockInfo {
  9617. if its.MaxUnit == medical.MaxUnit {
  9618. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9619. }
  9620. sum_count += its.StockMaxNumber + its.StockMinNumber
  9621. }
  9622. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9623. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9624. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9625. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9626. }
  9627. }
  9628. orgId := c.GetAdminUserInfo().CurrentOrgId
  9629. if len(oldGoods) > 0 {
  9630. timeStr := time.Now().Format("2006-01-02")
  9631. timeArr := strings.Split(timeStr, "-")
  9632. total, _ := service.FindAllWarehouseOut(orgId)
  9633. total = total + 1
  9634. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9635. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9636. number = number + total
  9637. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9638. operation_time := time.Now().Unix()
  9639. creater := c.GetAdminUserInfo().AdminUser.Id
  9640. //查询默认出库仓库库存
  9641. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9642. recordDateStr := time.Now().Format("2006-01-02")
  9643. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9644. nowtime := recordDate.Unix()
  9645. warehouseOut := models.WarehouseOut{
  9646. WarehouseOutOrderNumber: warehousing_out_order,
  9647. OperationTime: operation_time,
  9648. OrgId: orgId,
  9649. Creater: creater,
  9650. Ctime: time.Now().Unix(),
  9651. Status: 1,
  9652. WarehouseOutTime: nowtime,
  9653. Type: 1,
  9654. StorehouseId: storeConfig.StorehouseOutInfo,
  9655. IsCheck: 1,
  9656. OrderId: order.ID,
  9657. IsSys: 5,
  9658. }
  9659. //查询是否生成出库单
  9660. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9661. if out.ID == 0 {
  9662. service.AddSigleWarehouseOut(&warehouseOut)
  9663. }
  9664. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9665. for _, item := range oldGoods {
  9666. dialyPrepareOne := models.DialysisBeforePrepare{
  9667. GoodTypeId: item.GoodTypeId,
  9668. GoodId: item.GoodId,
  9669. PatientId: his.PatientId,
  9670. RecordDate: item.RecordDate,
  9671. UserOrgId: adminUser.CurrentOrgId,
  9672. Count: item.Count,
  9673. Ctime: time.Now().Unix(),
  9674. Creater: adminUser.AdminUser.Id,
  9675. CommdityCode: item.CommdityCode,
  9676. Status: 1,
  9677. StorehouseId: houseConfig.StorehouseOutInfo,
  9678. }
  9679. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9680. //非零用
  9681. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9682. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9683. //查询剩余库存
  9684. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9685. var sum_count int64
  9686. for _, item := range goodList {
  9687. sum_count += item.StockCount
  9688. }
  9689. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9690. //耗材
  9691. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9692. }
  9693. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9694. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9695. //查询剩余库存
  9696. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9697. var sum_count int64
  9698. for _, item := range goodList {
  9699. sum_count += item.StockCount
  9700. }
  9701. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9702. //耗材
  9703. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9704. }
  9705. }
  9706. }
  9707. }
  9708. c.ServeSuccessJSON(map[string]interface{}{
  9709. "msg": "结算成功",
  9710. })
  9711. }
  9712. }
  9713. }
  9714. // 退款
  9715. func (c *HisApiController) Refund() {
  9716. order_id, _ := c.GetInt64("order_id")
  9717. order, _ := service.GetHisOrderByID(order_id)
  9718. adminUser := c.GetAdminUserInfo()
  9719. orgid := c.GetAdminUserInfo().CurrentOrgId
  9720. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9721. if err != nil {
  9722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9723. return
  9724. }
  9725. tmp := strconv.FormatInt(order.ID, 10)
  9726. //当押金不为零时产生退费记录
  9727. if order.Decimal != 0 {
  9728. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9729. if err != nil {
  9730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9731. return
  9732. }
  9733. }
  9734. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9735. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9736. var goods []*models.DialysisBeforePrepareGoods
  9737. var newGoods []*models.NewDialysisBeforePrepareGoods
  9738. var infos []*models.HisDoctorAdviceInfo
  9739. for _, info := range orders {
  9740. if info.AdviceId > 0 && info.ProjectId == 0 {
  9741. infos = append(infos, &info.HisDoctorAdviceInfo)
  9742. }
  9743. if info.ProjectId > 0 && info.AdviceId == 0 {
  9744. if info.HisPrescriptionProject.Type == 3 {
  9745. var good models.DialysisBeforePrepareGoods
  9746. var newGood models.NewDialysisBeforePrepareGoods
  9747. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9748. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9749. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9750. good.Count = int64(count)
  9751. good.StorehouseId = houseConfig.StorehouseOutInfo
  9752. good.ProjectId = info.HisPrescriptionProject.ID
  9753. good.PatientId = info.PatientId
  9754. good.OrderId = order_id
  9755. goods = append(goods, &good)
  9756. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9757. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9758. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9759. newGood.Count = int64(count2)
  9760. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9761. newGood.ProjectId = info.HisPrescriptionProject.ID
  9762. newGood.RecordDate = order.SettleAccountsDate
  9763. newGood.UserOrgId = order.UserOrgId
  9764. newGood.PatientId = info.PatientId
  9765. newGood.OrderId = order_id
  9766. newGoods = append(newGoods, &newGood)
  9767. }
  9768. }
  9769. }
  9770. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9771. if settConfig.IsOpen == 1 {
  9772. for _, item := range infos {
  9773. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9774. }
  9775. for _, item := range newGoods {
  9776. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9777. }
  9778. }
  9779. c.ServeSuccessJSON(map[string]interface{}{
  9780. "msg": "退费成功",
  9781. })
  9782. }
  9783. func (c *HisApiController) RefundNumber() {
  9784. his_patient_id, _ := c.GetInt64("id")
  9785. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9786. info.Status = 0
  9787. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9788. if count > 0 {
  9789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9790. return
  9791. }
  9792. err := service.SaveHisPatient(info)
  9793. if err == nil {
  9794. c.ServeSuccessJSON(map[string]interface{}{
  9795. "msg": "退号成功",
  9796. })
  9797. } else {
  9798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9799. return
  9800. }
  9801. }
  9802. func (this *HisApiController) AdditionalCharge() {
  9803. dataBody := make(map[string]interface{}, 0)
  9804. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9805. fmt.Println(err)
  9806. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9807. patient_id := int64(dataBody["patient_id"].(float64))
  9808. medicineData, _ := dataBody["medicineData"].([]interface{})
  9809. adminUserInfo := this.GetAdminUserInfo()
  9810. orgId := adminUserInfo.CurrentOrgId
  9811. admin_user_id := adminUserInfo.AdminUser.Id
  9812. timeStr := time.Now().Format("2006-01-02")
  9813. timeLayout := "2006-01-02 15:04:05"
  9814. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9815. timenow := timeStringToTime.Unix()
  9816. var additionalCharges []*models.HisAdditionalCharge
  9817. for _, item := range medicineData {
  9818. var randNum int
  9819. randNum = rand.Intn(10000) + 1000
  9820. timestamp := time.Now().Unix()
  9821. tempTime := time.Unix(timestamp, 0)
  9822. timeFormat := tempTime.Format("20060102150405")
  9823. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9824. items := item.(map[string]interface{})
  9825. money := items["price"].(string)
  9826. item_id_str := items["item_id"].(string)
  9827. name := items["name"].(string)
  9828. id_str := items["id"].(string)
  9829. moneys, _ := strconv.ParseInt(money, 10, 64)
  9830. monStr := strconv.FormatInt(moneys, 10)
  9831. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9832. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9833. id, _ := strconv.ParseInt(id_str, 10, 64)
  9834. additionalCharge := &models.HisAdditionalCharge{
  9835. ID: id,
  9836. HisPatientId: his_patient_id,
  9837. UserOrgId: orgId,
  9838. PatientId: patient_id,
  9839. RecordDate: timenow,
  9840. Price: monneyStr,
  9841. Status: 1,
  9842. ItemName: name,
  9843. ItemId: item_id,
  9844. AdminUserId: admin_user_id,
  9845. CreatedTime: time.Now().Unix(),
  9846. OrderStatus: 0,
  9847. PrescriptionNumber: "",
  9848. BatchNumber: "",
  9849. FeedetlSn: p_number,
  9850. }
  9851. service.CreateAdditionalCharge(additionalCharge)
  9852. additionalCharges = append(additionalCharges, additionalCharge)
  9853. }
  9854. this.ServeSuccessJSON(map[string]interface{}{
  9855. "msg": "添加成功",
  9856. "additional_charges": additionalCharges,
  9857. })
  9858. }
  9859. func (this *HisApiController) DeleteAddition() {
  9860. id, _ := this.GetInt64("id")
  9861. //TODO 需要判断是否已经结算
  9862. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9863. if err == nil {
  9864. this.ServeSuccessJSON(map[string]interface{}{
  9865. "msg": "删除成功",
  9866. })
  9867. return
  9868. } else {
  9869. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9870. return
  9871. }
  9872. }
  9873. func (this *HisApiController) GetAdminUsers() {
  9874. adminUser := this.GetAdminUserInfo()
  9875. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9876. this.ServeSuccessJSON(map[string]interface{}{
  9877. "doctors": doctors,
  9878. })
  9879. }
  9880. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9881. change_type, _ := this.GetInt64("type", 0)
  9882. record_date := this.GetString("record_time")
  9883. patient_id, _ := this.GetInt64("patient_id", 0)
  9884. p_type, _ := this.GetInt64("p_type", 0)
  9885. timeLayout := "2006-01-02"
  9886. loc, _ := time.LoadLocation("Local")
  9887. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9888. record_time := theAdviceRecordTime.Unix()
  9889. adminUserInfo := this.GetAdminUserInfo()
  9890. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9891. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9892. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9893. if config.ID > 0 && config.IsOpen == 1 {
  9894. for _, subitems := range prescriptions {
  9895. for _, item := range subitems.VMHisPrescription {
  9896. for _, subItem := range item.HisDoctorAdviceInfo {
  9897. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9898. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9899. if info.RetailPrice > 0 {
  9900. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9901. subItem.Drug.RetailPrice = drug.RetailPrice
  9902. }
  9903. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9904. subItem.Drug.MinPrice = info.RetailPrice
  9905. subItem.Drug.RetailPrice = info.RetailPrice
  9906. }
  9907. }
  9908. }
  9909. }
  9910. }
  9911. }
  9912. if config.ID > 0 && config.IsOpen == 1 {
  9913. for _, subitems := range prescriptions {
  9914. for _, item := range subitems.VMHisPrescription {
  9915. for _, subItem := range item.HisPrescriptionProject {
  9916. if subItem.Type == 3 {
  9917. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9918. if info.Price > 0 {
  9919. subItem.GoodInfo.PackingPrice = info.Price
  9920. }
  9921. }
  9922. }
  9923. }
  9924. }
  9925. }
  9926. }
  9927. if err == nil {
  9928. if len(prescriptions) == 0 {
  9929. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9930. return
  9931. } else {
  9932. this.ServeSuccessJSON(map[string]interface{}{
  9933. "prescriptions": prescriptions,
  9934. })
  9935. return
  9936. }
  9937. } else {
  9938. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9939. return
  9940. }
  9941. }
  9942. func (this *HisApiController) GetCallHisPrescription() {
  9943. patient_id, _ := this.GetInt64("patient_id", 0)
  9944. timeLayout := "2006-01-02"
  9945. loc, _ := time.LoadLocation("Local")
  9946. start_time := this.GetString("start_time")
  9947. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9948. end_time := this.GetString("end_time")
  9949. p_type, _ := this.GetInt64("p_type")
  9950. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9951. adminUserInfo := this.GetAdminUserInfo()
  9952. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9953. //if
  9954. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9955. //
  9956. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9957. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9958. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9959. if config.ID > 0 && config.IsOpen == 1 {
  9960. for _, subitems := range prescriptions {
  9961. for _, item := range subitems.VMHisPrescription {
  9962. for _, subItem := range item.HisDoctorAdviceInfo {
  9963. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9964. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9965. if info.RetailPrice > 0 {
  9966. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9967. subItem.Drug.RetailPrice = drug.RetailPrice
  9968. }
  9969. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9970. subItem.Drug.MinPrice = info.RetailPrice
  9971. subItem.Drug.RetailPrice = info.RetailPrice
  9972. }
  9973. }
  9974. }
  9975. }
  9976. }
  9977. }
  9978. if config.ID > 0 && config.IsOpen == 1 {
  9979. for _, subitems := range prescriptions {
  9980. for _, item := range subitems.VMHisPrescription {
  9981. for _, subItem := range item.HisPrescriptionProject {
  9982. if subItem.Type == 3 {
  9983. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9984. if info.Price > 0 {
  9985. subItem.GoodInfo.PackingPrice = info.Price
  9986. }
  9987. }
  9988. }
  9989. }
  9990. }
  9991. }
  9992. }
  9993. if err == nil {
  9994. this.ServeSuccessJSON(map[string]interface{}{
  9995. "prescriptions": prescriptions,
  9996. })
  9997. return
  9998. } else {
  9999. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10000. return
  10001. }
  10002. }
  10003. func (this *HisApiController) GetHisDayPrescription() {
  10004. timeLayout := "2006-01-02"
  10005. loc, _ := time.LoadLocation("Local")
  10006. start_time := this.GetString("start_time")
  10007. patient_id, _ := this.GetInt64("patient_id", 0)
  10008. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10009. end_time := this.GetString("end_time")
  10010. p_type, _ := this.GetInt64("p_type")
  10011. order_status, _ := this.GetInt64("type")
  10012. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10013. adminUserInfo := this.GetAdminUserInfo()
  10014. var dayHisPrescription []*models.HisPrescription
  10015. var err error
  10016. if order_status == 1 || order_status == 0 {
  10017. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10018. } else if order_status == 2 {
  10019. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10020. }
  10021. var settle_total float64
  10022. for _, item := range dayHisPrescription {
  10023. if len(item.HisPrescriptionProject) > 0 {
  10024. for _, subItem := range item.HisPrescriptionProject {
  10025. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10026. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10027. settle_total = settle_total + total
  10028. }
  10029. }
  10030. if len(item.HisDoctorAdviceInfo) > 0 {
  10031. for _, subItem := range item.HisDoctorAdviceInfo {
  10032. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10033. settle_total = settle_total + total
  10034. }
  10035. }
  10036. }
  10037. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10038. if err == nil {
  10039. this.ServeSuccessJSON(map[string]interface{}{
  10040. "day_prescription": dayHisPrescription,
  10041. "settle_total": settle_total,
  10042. })
  10043. return
  10044. } else {
  10045. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10046. return
  10047. }
  10048. }
  10049. func (c *HisApiController) GetHisChargePatientList() {
  10050. record_date := c.GetString("record_date")
  10051. order_status, _ := c.GetInt64("type")
  10052. sch_type, _ := c.GetInt64("sch_type")
  10053. timeLayout := "2006-01-02"
  10054. loc, _ := time.LoadLocation("Local")
  10055. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10056. if err != nil {
  10057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10058. return
  10059. }
  10060. recordDateTime := theTime.Unix()
  10061. adminInfo := c.GetAdminUserInfo()
  10062. var tempPatients []*service.NewTempPatients
  10063. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10064. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10065. if order_status != 2 {
  10066. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10067. } else {
  10068. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10069. }
  10070. } else {
  10071. if order_status != 2 {
  10072. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10073. } else {
  10074. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10075. }
  10076. }
  10077. var patients []*service.NewTempPatients
  10078. var patients_two []*service.NewTempPatients
  10079. for _, item := range tempPatients {
  10080. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10081. //过滤掉没挂号的和没开处方的
  10082. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10083. patients = append(patients, item)
  10084. }
  10085. //过滤掉没挂号的
  10086. if len(item.HisPatient) > 0 {
  10087. patients_two = append(patients_two, item)
  10088. }
  10089. } else {
  10090. if len(item.HisPrescription) > 0 {
  10091. patients = append(patients, item)
  10092. }
  10093. }
  10094. }
  10095. c.ServeSuccessJSON(map[string]interface{}{
  10096. "list": patients,
  10097. "list_two": patients_two,
  10098. })
  10099. }
  10100. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10101. record_date := c.GetString("record_date")
  10102. timeLayout := "2006-01-02"
  10103. loc, _ := time.LoadLocation("Local")
  10104. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10105. if err != nil {
  10106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10107. return
  10108. }
  10109. recordDateTime := theTime.Unix()
  10110. adminUser := c.GetAdminUserInfo()
  10111. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10112. var patients []*service.Patients
  10113. for _, item := range tempPatients {
  10114. if item.HisPatient.ID == 0 {
  10115. patients = append(patients, item)
  10116. }
  10117. }
  10118. c.ServeSuccessJSON(map[string]interface{}{
  10119. "list": patients,
  10120. //"list_two": patients_two,
  10121. })
  10122. }
  10123. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10124. newArr = make([]*service.Patients, 0)
  10125. for i := 0; i < len(patient); i++ {
  10126. repeat := false
  10127. for j := i + 1; j < len(patient); j++ {
  10128. if patient[i].ID == patient[j].ID {
  10129. repeat = true
  10130. break
  10131. }
  10132. }
  10133. if !repeat {
  10134. newArr = append(newArr, patient[i])
  10135. }
  10136. }
  10137. return
  10138. }
  10139. func (c *HisApiController) GetHisChargePatientInfo() {
  10140. patient_id, _ := c.GetInt64("patient_id")
  10141. his_patient_id, _ := c.GetInt64("his_patient_id")
  10142. record_date := c.GetString("record_date")
  10143. //start_time := c.GetString("start_time")
  10144. //end_time := c.GetString("end_time")
  10145. order_status, _ := c.GetInt64("type", 0)
  10146. p_type, _ := c.GetInt64("p_type", 0)
  10147. order_id, _ := c.GetInt64("order_id", 0)
  10148. timeLayout := "2006-01-02"
  10149. loc, _ := time.LoadLocation("Local")
  10150. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10151. if err != nil {
  10152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10153. return
  10154. }
  10155. recordDateTime := theTime.Unix()
  10156. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10157. //if err != nil {
  10158. //
  10159. //}
  10160. //startRecordDateTime := startTime.Unix()
  10161. //
  10162. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10163. //if err != nil {
  10164. //
  10165. //}
  10166. //endRecordDateTime := endTime.Unix()
  10167. admin := c.GetAdminUserInfo()
  10168. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10169. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10170. var prescriptions []*models.HisPrescription
  10171. //var unChargeMonthPrescriptions []*models.HisPrescription
  10172. order, _ := service.GetHisOrderByID(order_id)
  10173. if order_status == 1 || order_status == 0 {
  10174. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10175. } else if order_status == 2 {
  10176. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10177. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10178. }
  10179. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10180. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10181. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10182. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10183. //获取所有科室信息
  10184. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10185. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10186. c.ServeSuccessJSON(map[string]interface{}{
  10187. "his_info": his_patient_info,
  10188. "xt_info": xt_patient_info,
  10189. "prescription": prescriptions,
  10190. "case_history": case_history,
  10191. "info": patientPrescriptionInfo,
  10192. "last_info": lastPatientPrescriptionInfo,
  10193. "order": order,
  10194. "doctors": doctors,
  10195. "department": department,
  10196. "sch": sch,
  10197. })
  10198. return
  10199. }
  10200. func (c *HisApiController) GetAllOrderDetail() {
  10201. order_id, _ := c.GetInt64("id", 0)
  10202. order, _ := service.GetHisOrderByID(order_id)
  10203. if order.ID == 0 {
  10204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10205. return
  10206. }
  10207. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10208. org_id := c.GetAdminUserInfo().CurrentOrgId
  10209. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10210. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10211. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10212. c.ServeSuccessJSON(map[string]interface{}{
  10213. "order": order,
  10214. "order_info": order_info,
  10215. "patient": patient,
  10216. "admin_info": adminInfo,
  10217. "hospital_record": record,
  10218. })
  10219. return
  10220. }
  10221. func (c *HisApiController) GetAllOrderDetailCollect() {
  10222. order_id, _ := c.GetInt64("id", 0)
  10223. order, _ := service.GetHisOrderByID(order_id)
  10224. if order.ID == 0 {
  10225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10226. return
  10227. }
  10228. org_id := c.GetAdminUserInfo().CurrentOrgId
  10229. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10230. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10231. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10232. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10233. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10234. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10235. var bedCostTotal float64 = 0 //床位总费
  10236. //var bedCostSelfTotal float64 = 0 //床位自费
  10237. var operationCostTotal float64 = 0 //手术费
  10238. //var operationCostSelfTotal float64 = 0 //手术费
  10239. var otherCostTotal float64 = 0 //其他费用
  10240. //var otherCostSelfTotal float64 = 0 //其他费用
  10241. var materialCostTotal float64 = 0 //材料费
  10242. //var materialCostSelfTotal float64 = 0 //材料费
  10243. var westernMedicineCostTotal float64 = 0 //西药费
  10244. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10245. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10246. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10247. var checkCostTotal float64 = 0 //检查费
  10248. //var checkCostSelfTotal float64 = 0 //检查费
  10249. var laboratoryCostTotal float64 = 0 //化验费
  10250. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10251. var treatCostTotal float64 = 0 //治疗费用
  10252. //var treatCostSelfTotal float64 = 0 //治疗费用
  10253. var zhenChaCostTotal float64 = 0 //其他费用
  10254. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10255. decimal.DivisionPrecision = 2
  10256. var BalanceAccountsType int64
  10257. if his.ID > 0 {
  10258. BalanceAccountsType = his.BalanceAccountsType
  10259. } else {
  10260. BalanceAccountsType = record.BalanceAccountsType
  10261. }
  10262. if BalanceAccountsType != 2 {
  10263. for _, item := range order_info {
  10264. if org_id == 10215 {
  10265. if item.MedChrgitmType == "01" { //床位费
  10266. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10267. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10268. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10269. }
  10270. if item.MedChrgitmType == "02" { //诊察费
  10271. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10272. //zhenChaCostSelfTotal = zhenChaCostTotal
  10273. }
  10274. if item.MedChrgitmType == "03" { //检查费
  10275. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10276. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10277. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10278. }
  10279. //if item.MedChrgitmType == "02" { //检查费
  10280. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10281. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10282. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10283. //}
  10284. if item.MedChrgitmType == "04" { //化验费
  10285. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10286. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10287. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10288. }
  10289. if item.MedChrgitmType == "05" { //治疗费
  10290. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10291. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10292. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10293. }
  10294. if item.MedChrgitmType == "06" { //手术费
  10295. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10296. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10297. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10298. }
  10299. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10300. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10301. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10302. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10303. }
  10304. if item.MedChrgitmType == "09" { //西药费
  10305. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10306. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10307. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10308. }
  10309. if item.MedChrgitmType == "11" { //中成费
  10310. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10311. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10312. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10313. }
  10314. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10315. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10316. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10317. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10318. }
  10319. } else if org_id == 10188 || org_id == 10217 {
  10320. if item.MedChrgitmType == "01" { //床位费
  10321. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10322. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10323. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10324. }
  10325. if item.MedChrgitmType == "02" { //诊察费
  10326. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10327. //zhenChaCostSelfTotal = zhenChaCostTotal
  10328. }
  10329. if item.MedChrgitmType == "03" { //检查费
  10330. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10331. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10332. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10333. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10334. }
  10335. //if item.MedChrgitmType == "02" { //检查费
  10336. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10337. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10338. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10339. //}
  10340. if item.MedChrgitmType == "04" { //化验费
  10341. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10342. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10343. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10344. }
  10345. if item.MedChrgitmType == "05" { //治疗费
  10346. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10347. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10348. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10349. }
  10350. if item.MedChrgitmType == "06" { //手术费
  10351. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10352. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10353. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10354. }
  10355. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10356. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10357. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10358. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10359. }
  10360. if item.MedChrgitmType == "09" { //西药费
  10361. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10362. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10363. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10364. }
  10365. if item.MedChrgitmType == "11" { //中成费
  10366. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10367. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10368. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10369. }
  10370. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10371. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10372. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10373. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10374. }
  10375. } else {
  10376. if item.MedChrgitmType == "01" { //床位费
  10377. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10378. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10379. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10380. }
  10381. //if item.MedChrgitmType == "02" { //诊察费
  10382. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10383. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10384. //}
  10385. if item.MedChrgitmType == "03" { //检查费
  10386. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10387. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10388. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10389. }
  10390. //if item.MedChrgitmType == "02" { //检查费
  10391. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10392. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10393. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10394. //}
  10395. if item.MedChrgitmType == "04" { //化验费
  10396. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10397. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10398. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10399. }
  10400. if item.MedChrgitmType == "05" { //治疗费
  10401. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10402. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10403. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10404. }
  10405. if item.MedChrgitmType == "06" { //手术费
  10406. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10407. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10408. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10409. }
  10410. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10411. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10412. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10413. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10414. }
  10415. if item.MedChrgitmType == "09" { //西药费
  10416. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10417. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10418. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10419. }
  10420. if item.MedChrgitmType == "11" { //中成费
  10421. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10422. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10423. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10424. }
  10425. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10426. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10427. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10428. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10429. }
  10430. }
  10431. }
  10432. c.ServeSuccessJSON(map[string]interface{}{
  10433. "order": order,
  10434. "order_info": order_info,
  10435. "patient": patient,
  10436. "admin_info": adminInfo,
  10437. "his_hospital": record,
  10438. "bedCostTotal": bedCostTotal,
  10439. "operationCostTotal": operationCostTotal,
  10440. "otherCostTotal": otherCostTotal,
  10441. "materialCostTotal": materialCostTotal,
  10442. "westernMedicineCostTotal": westernMedicineCostTotal,
  10443. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10444. "checkCostTotal": checkCostTotal,
  10445. "zhenChaCostTotal": zhenChaCostTotal,
  10446. "laboratoryCostTotal": laboratoryCostTotal,
  10447. "treatCostTotal": treatCostTotal,
  10448. })
  10449. } else {
  10450. for _, item := range order_info {
  10451. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10452. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10453. item.MedChrgitmType = "09"
  10454. }
  10455. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10456. if item.HisPrescriptionProject.Type == 2 {
  10457. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10458. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10459. case 0:
  10460. item.MedChrgitmType = "0"
  10461. break
  10462. case 1:
  10463. item.MedChrgitmType = "14"
  10464. break
  10465. case 2:
  10466. item.MedChrgitmType = "05"
  10467. break
  10468. case 3:
  10469. item.MedChrgitmType = "03"
  10470. break
  10471. case 4:
  10472. item.MedChrgitmType = "03"
  10473. break
  10474. case 5:
  10475. item.MedChrgitmType = "08"
  10476. break
  10477. case 6:
  10478. item.MedChrgitmType = "14"
  10479. break
  10480. case 7:
  10481. item.MedChrgitmType = "14"
  10482. break
  10483. case 8:
  10484. item.MedChrgitmType = "03"
  10485. break
  10486. case 9:
  10487. item.MedChrgitmType = "14"
  10488. break
  10489. case 10:
  10490. item.MedChrgitmType = "14"
  10491. break
  10492. case 11:
  10493. item.MedChrgitmType = "06"
  10494. break
  10495. case 12:
  10496. item.MedChrgitmType = "12"
  10497. break
  10498. case 13:
  10499. item.MedChrgitmType = "01"
  10500. break
  10501. case 14:
  10502. item.MedChrgitmType = "04"
  10503. break
  10504. case 15:
  10505. item.MedChrgitmType = "14"
  10506. break
  10507. }
  10508. } else {
  10509. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10510. case 1:
  10511. item.MedChrgitmType = "14"
  10512. break
  10513. case 2:
  10514. item.MedChrgitmType = "05"
  10515. break
  10516. case 3:
  10517. item.MedChrgitmType = "04"
  10518. break
  10519. case 4:
  10520. item.MedChrgitmType = "14"
  10521. break
  10522. case 5:
  10523. item.MedChrgitmType = "08"
  10524. break
  10525. case 6:
  10526. item.MedChrgitmType = "14"
  10527. break
  10528. case 7:
  10529. item.MedChrgitmType = "14"
  10530. break
  10531. case 8:
  10532. item.MedChrgitmType = "03"
  10533. break
  10534. case 9:
  10535. item.MedChrgitmType = "14"
  10536. break
  10537. }
  10538. }
  10539. } else if item.HisPrescriptionProject.Type == 3 {
  10540. item.MedChrgitmType = "08"
  10541. }
  10542. }
  10543. }
  10544. for _, item := range order_info {
  10545. if org_id == 10215 {
  10546. if item.MedChrgitmType == "01" { //床位费
  10547. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10548. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10549. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10550. }
  10551. if item.MedChrgitmType == "02" { //诊察费
  10552. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10553. //zhenChaCostSelfTotal = zhenChaCostTotal
  10554. }
  10555. if item.MedChrgitmType == "03" { //检查费
  10556. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10557. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10558. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10559. }
  10560. //if item.MedChrgitmType == "02" { //检查费
  10561. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10562. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10563. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10564. //}
  10565. if item.MedChrgitmType == "04" { //化验费
  10566. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10567. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10568. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10569. }
  10570. if item.MedChrgitmType == "05" { //治疗费
  10571. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10572. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10573. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10574. }
  10575. if item.MedChrgitmType == "06" { //手术费
  10576. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10577. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10578. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10579. }
  10580. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10581. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10582. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10583. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10584. }
  10585. if item.MedChrgitmType == "09" { //西药费
  10586. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10587. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10588. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10589. }
  10590. if item.MedChrgitmType == "11" { //中成费
  10591. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10592. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10593. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10594. }
  10595. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10596. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10597. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10598. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10599. }
  10600. } else {
  10601. if item.MedChrgitmType == "01" { //床位费
  10602. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10603. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10604. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10605. }
  10606. //if item.MedChrgitmType == "02" { //诊察费
  10607. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10608. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10609. //}
  10610. if item.MedChrgitmType == "03" { //检查费
  10611. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10612. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10613. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10614. }
  10615. //if item.MedChrgitmType == "02" { //检查费
  10616. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10617. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10618. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10619. //}
  10620. if item.MedChrgitmType == "04" { //化验费
  10621. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10622. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10623. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10624. }
  10625. if item.MedChrgitmType == "05" { //治疗费
  10626. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10627. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10628. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10629. }
  10630. if item.MedChrgitmType == "06" { //手术费
  10631. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10632. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10633. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10634. }
  10635. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10636. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10637. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10638. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10639. }
  10640. if item.MedChrgitmType == "09" { //西药费
  10641. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10642. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10643. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10644. }
  10645. if item.MedChrgitmType == "11" { //中成费
  10646. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10647. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10648. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10649. }
  10650. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10651. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10652. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10653. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10654. }
  10655. }
  10656. }
  10657. c.ServeSuccessJSON(map[string]interface{}{
  10658. "order": order,
  10659. "order_info": order_info,
  10660. "patient": patient,
  10661. "admin_info": adminInfo,
  10662. "his_hospital": record,
  10663. "bedCostTotal": bedCostTotal,
  10664. "operationCostTotal": operationCostTotal,
  10665. "otherCostTotal": otherCostTotal,
  10666. "materialCostTotal": materialCostTotal,
  10667. "westernMedicineCostTotal": westernMedicineCostTotal,
  10668. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10669. "checkCostTotal": checkCostTotal,
  10670. "zhenChaCostTotal": zhenChaCostTotal,
  10671. "laboratoryCostTotal": laboratoryCostTotal,
  10672. "treatCostTotal": treatCostTotal,
  10673. })
  10674. }
  10675. }
  10676. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10677. page, _ := c.GetInt64("page")
  10678. limit, _ := c.GetInt64("limit")
  10679. keywords := c.GetString("keywords")
  10680. start_time := c.GetString("start_time")
  10681. end_time := c.GetString("end_time")
  10682. //clr_type := c.GetString("clr_type")
  10683. insutype := c.GetString("insutype")
  10684. timeLayout := "2006-01-02"
  10685. loc, _ := time.LoadLocation("Local")
  10686. var theStartTIme int64
  10687. if len(start_time) > 0 {
  10688. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10689. theStartTIme = theTime.Unix()
  10690. }
  10691. var theEndtTIme int64
  10692. if len(end_time) > 0 {
  10693. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10694. theEndtTIme = theTime.Unix()
  10695. }
  10696. if page <= 0 {
  10697. page = 1
  10698. }
  10699. if limit <= 0 {
  10700. limit = 10
  10701. }
  10702. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10703. c.ServeSuccessJSON(map[string]interface{}{
  10704. "total": total,
  10705. "list": list,
  10706. })
  10707. return
  10708. }
  10709. func (c *HisApiController) GetPutOnRecordList() {
  10710. page, _ := c.GetInt64("page")
  10711. limit, _ := c.GetInt64("limit")
  10712. keywords := c.GetString("keywords")
  10713. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10714. if page <= 0 {
  10715. page = 1
  10716. }
  10717. if limit <= 0 {
  10718. limit = 10
  10719. }
  10720. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10721. c.ServeSuccessJSON(map[string]interface{}{
  10722. "total": total,
  10723. "list": list,
  10724. })
  10725. return
  10726. }
  10727. func (c *HisApiController) GetCompareData() {
  10728. start_time := c.GetString("start_time")
  10729. end_time := c.GetString("end_time")
  10730. insutype := c.GetString("insutype")
  10731. clr_type := c.GetString("clr_type")
  10732. timeLayout := "2006-01-02"
  10733. loc, _ := time.LoadLocation("Local")
  10734. var theStartTIme int64
  10735. if len(start_time) > 0 {
  10736. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10737. if err != nil {
  10738. theStartTIme = 0
  10739. }
  10740. theStartTIme = theTime.Unix()
  10741. }
  10742. var theEndtTIme int64
  10743. if len(end_time) > 0 {
  10744. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10745. if err != nil {
  10746. theEndtTIme = 0
  10747. }
  10748. theEndtTIme = theTime.Unix()
  10749. }
  10750. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10751. fmt.Println(err)
  10752. if err == nil {
  10753. c.ServeSuccessJSON(map[string]interface{}{
  10754. "list": formData,
  10755. })
  10756. } else {
  10757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10758. return
  10759. }
  10760. }
  10761. func (c *HisApiController) GetFaPiaoData() {
  10762. order_id, _ := c.GetInt64("order_id")
  10763. patient_id, _ := c.GetInt64("patient_id")
  10764. //number := c.GetString("number")
  10765. adminUser := c.GetAdminUserInfo()
  10766. order, _ := service.GetHisOrderByID(order_id)
  10767. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10768. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10769. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10770. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10771. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10772. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10773. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10774. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10775. var bedCostTotal float64 = 0 //床位总费
  10776. var bedCostSelfTotal float64 = 0 //床位自费
  10777. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10778. var operationCostTotal float64 = 0 //手术费
  10779. var operationCostSelfTotal float64 = 0 //手术费
  10780. var operationCostPartSelfTotal float64 = 0 //手术费
  10781. var otherCostTotal float64 = 0 //其他费用
  10782. var otherCostSelfTotal float64 = 0 //其他费用
  10783. var otherCostPartSelfTotal float64 = 0 //其他费用
  10784. var materialCostTotal float64 = 0 //材料费
  10785. var materialCostSelfTotal float64 = 0 //材料费
  10786. var materialCostPartSelfTotal float64 = 0 //材料费
  10787. var westernMedicineCostTotal float64 = 0 //西药费
  10788. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10789. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10790. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10791. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10792. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10793. var checkCostTotal float64 = 0 //检查费
  10794. var checkCostSelfTotal float64 = 0 //检查费
  10795. var checkCostPartSelfTotal float64 = 0 //检查费
  10796. var hiliCostTotal float64 = 0 //护理费
  10797. var hiliCostSelfTotal float64 = 0 //护理费
  10798. var hiliCostPartSelfTotal float64 = 0 //护理费
  10799. var laboratoryCostTotal float64 = 0 //化验费
  10800. var laboratoryCostSelfTotal float64 = 0 //化验费
  10801. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10802. var treatCostTotal float64 = 0 //治疗费用
  10803. var treatCostSelfTotal float64 = 0 //治疗费用
  10804. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10805. var zhenChaCostTotal float64 = 0 //其他费用
  10806. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10807. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10808. decimal.DivisionPrecision = 2
  10809. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10810. var balanceAccountsType int64
  10811. if his.ID > 0 {
  10812. balanceAccountsType = his.BalanceAccountsType
  10813. } else {
  10814. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10815. }
  10816. if balanceAccountsType == 2 {
  10817. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10818. for _, item := range orderInfos_two {
  10819. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10820. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10821. item.MedChrgitmType = "09"
  10822. }
  10823. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10824. if item.HisPrescriptionProject.Type == 2 {
  10825. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10826. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10827. case 0:
  10828. item.MedChrgitmType = "0"
  10829. break
  10830. case 1:
  10831. item.MedChrgitmType = "14"
  10832. break
  10833. case 2:
  10834. item.MedChrgitmType = "05"
  10835. break
  10836. case 3:
  10837. item.MedChrgitmType = "03"
  10838. break
  10839. case 4:
  10840. item.MedChrgitmType = "03"
  10841. break
  10842. case 5:
  10843. item.MedChrgitmType = "08"
  10844. break
  10845. case 6:
  10846. item.MedChrgitmType = "14"
  10847. break
  10848. case 7:
  10849. item.MedChrgitmType = "14"
  10850. break
  10851. case 8:
  10852. item.MedChrgitmType = "03"
  10853. break
  10854. case 9:
  10855. item.MedChrgitmType = "14"
  10856. break
  10857. case 10:
  10858. item.MedChrgitmType = "14"
  10859. break
  10860. case 11:
  10861. item.MedChrgitmType = "06"
  10862. break
  10863. case 12:
  10864. item.MedChrgitmType = "12"
  10865. break
  10866. case 13:
  10867. item.MedChrgitmType = "01"
  10868. break
  10869. case 14:
  10870. item.MedChrgitmType = "04"
  10871. break
  10872. case 15:
  10873. item.MedChrgitmType = "02"
  10874. break
  10875. }
  10876. } else {
  10877. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10878. case 1:
  10879. item.MedChrgitmType = "14"
  10880. break
  10881. case 2:
  10882. item.MedChrgitmType = "05"
  10883. break
  10884. case 3:
  10885. item.MedChrgitmType = "04"
  10886. break
  10887. case 4:
  10888. item.MedChrgitmType = "03"
  10889. break
  10890. case 5:
  10891. item.MedChrgitmType = "08"
  10892. break
  10893. case 6:
  10894. item.MedChrgitmType = "14"
  10895. break
  10896. case 7:
  10897. item.MedChrgitmType = "14"
  10898. break
  10899. case 8:
  10900. item.MedChrgitmType = "03"
  10901. break
  10902. case 9:
  10903. item.MedChrgitmType = "14"
  10904. break
  10905. }
  10906. }
  10907. } else if item.HisPrescriptionProject.Type == 3 {
  10908. item.MedChrgitmType = "08"
  10909. }
  10910. }
  10911. }
  10912. for _, item := range orderInfos_two {
  10913. fmt.Println(item.MedChrgitmType)
  10914. if item.MedChrgitmType == "07" { //床位费
  10915. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10916. hiliCostSelfTotal = hiliCostTotal
  10917. }
  10918. if item.MedChrgitmType == "01" { //床位费
  10919. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10920. bedCostSelfTotal = bedCostTotal
  10921. }
  10922. if item.MedChrgitmType == "02" { //诊察费
  10923. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10924. zhenChaCostSelfTotal = zhenChaCostTotal
  10925. }
  10926. if item.MedChrgitmType == "03" { //检查费
  10927. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10928. checkCostSelfTotal = checkCostTotal
  10929. }
  10930. if item.MedChrgitmType == "04" { //化验费
  10931. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10932. laboratoryCostSelfTotal = laboratoryCostTotal
  10933. }
  10934. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10935. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10936. treatCostSelfTotal = treatCostTotal
  10937. }
  10938. if item.MedChrgitmType == "06" { //手术费
  10939. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10940. operationCostSelfTotal = treatCostTotal
  10941. }
  10942. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10943. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10944. materialCostSelfTotal = materialCostTotal
  10945. }
  10946. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10947. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10948. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10949. }
  10950. if item.MedChrgitmType == "11" { //中成费
  10951. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10952. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10953. }
  10954. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10955. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10956. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10957. otherCostSelfTotal = otherCostTotal
  10958. }
  10959. } else {
  10960. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10961. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10962. otherCostSelfTotal = otherCostTotal
  10963. }
  10964. }
  10965. }
  10966. } else {
  10967. for _, item := range orderInfos {
  10968. if item.MedChrgitmType == "01" { //床位费
  10969. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10970. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10971. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10972. }
  10973. if item.MedChrgitmType == "02" { //诊察费
  10974. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10975. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10976. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10977. }
  10978. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10979. if item.MedChrgitmType == "03" { //检查费
  10980. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10981. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10982. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10983. }
  10984. } else {
  10985. if item.MedChrgitmType == "03" { //检查费
  10986. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10987. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10988. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10989. }
  10990. }
  10991. if item.MedChrgitmType == "04" { //化验费
  10992. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10993. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10994. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10995. }
  10996. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10997. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10998. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10999. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11000. }
  11001. if item.MedChrgitmType == "06" { //手术费
  11002. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11003. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11004. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11005. }
  11006. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11007. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11008. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11009. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11010. }
  11011. if item.MedChrgitmType == "07" { //护理
  11012. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11013. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11014. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11015. }
  11016. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11017. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11018. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11019. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11020. }
  11021. if item.MedChrgitmType == "11" { //中成费
  11022. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11023. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11024. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11025. }
  11026. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11027. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11028. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11029. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11030. }
  11031. }
  11032. }
  11033. timeLayout := "2006-01-02"
  11034. loc, _ := time.LoadLocation("Local")
  11035. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11036. if err != nil {
  11037. }
  11038. startRecordDateTime := startTime.Unix()
  11039. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11040. if err != nil {
  11041. }
  11042. endRecordDateTime := endTime.Unix()
  11043. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11044. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11045. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11046. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11047. c.ServeSuccessJSON(map[string]interface{}{
  11048. "charge_admin_name": charge_admin.UserName,
  11049. "order_number": order.Number, //业务流水号
  11050. "id_card_no": his.IdCardNo, //社会保障号
  11051. "patient": patient,
  11052. "department_name": department.Name, //科室
  11053. "number": his.Number, //门诊号
  11054. "date": order.SettleAccountsDate, //结算日期
  11055. "name": order.PsnName, //姓名
  11056. "gender": patient.Gender, //性别
  11057. "psn_cash_money": order.PsnCashPay, //个人支付
  11058. "pay_way": "门诊", //结算方式
  11059. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11060. "admin_user_name": admin.UserName, //收款员
  11061. "order": order,
  11062. "order_info": orderInfos_two,
  11063. "his": his,
  11064. "bedCostTotal": bedCostTotal,
  11065. "bedCostSelfTotal": bedCostSelfTotal,
  11066. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11067. "operationCostTotal": operationCostTotal,
  11068. "operationCostSelfTotal": operationCostSelfTotal,
  11069. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11070. "otherCostTotal": otherCostTotal,
  11071. "otherCostSelfTotal": otherCostSelfTotal,
  11072. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11073. "materialCostTotal": materialCostTotal,
  11074. "materialCostSelfTotal": materialCostSelfTotal,
  11075. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11076. "westernMedicineCostTotal": westernMedicineCostTotal,
  11077. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11078. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11079. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11080. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11081. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11082. "checkCostTotal": checkCostTotal,
  11083. "checkCostSelfTotal": checkCostSelfTotal,
  11084. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11085. "laboratoryCostTotal": laboratoryCostTotal,
  11086. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11087. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11088. "treatCostTotal": treatCostTotal,
  11089. "treatCostSelfTotal": treatCostSelfTotal,
  11090. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11091. "zhenChaCostTotal": zhenChaCostTotal,
  11092. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11093. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11094. "his_hospital_record": his_hospital_record,
  11095. "pre_pay_money": pre_pay_money,
  11096. "refund_sum": sum,
  11097. "doctor_info": doctor_info,
  11098. "hiliCostTotal": hiliCostTotal,
  11099. "hiliCostSelfTotal": hiliCostSelfTotal,
  11100. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11101. })
  11102. }
  11103. //func (c *HisApiController) GetFaPiaoDatas() {
  11104. // order_ids := c.GetString("order_ids")
  11105. // patient_id, _ := c.GetInt64("patient_id")
  11106. // adminUser := c.GetAdminUserInfo()
  11107. //
  11108. // orders := strings.Split(order_ids, ",")
  11109. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11110. //
  11111. // for _, item := range orders {
  11112. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11113. // order, _ := service.GetHisOrderByID(order_id)
  11114. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11115. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11116. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11117. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11118. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11119. //
  11120. // }
  11121. //
  11122. // var bedCostTotal float64 = 0 //床位总费
  11123. // var bedCostSelfTotal float64 = 0 //床位自费
  11124. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11125. //
  11126. // var operationCostTotal float64 = 0 //手术费
  11127. // var operationCostSelfTotal float64 = 0 //手术费
  11128. // var operationCostPartSelfTotal float64 = 0 //手术费
  11129. //
  11130. // var otherCostTotal float64 = 0 //其他费用
  11131. // var otherCostSelfTotal float64 = 0 //其他费用
  11132. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11133. //
  11134. // var materialCostTotal float64 = 0 //材料费
  11135. // var materialCostSelfTotal float64 = 0 //材料费
  11136. // var materialCostPartSelfTotal float64 = 0 //材料费
  11137. //
  11138. // var westernMedicineCostTotal float64 = 0 //西药费
  11139. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11140. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11141. //
  11142. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11143. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11144. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11145. //
  11146. // var checkCostTotal float64 = 0 //检查费
  11147. // var checkCostSelfTotal float64 = 0 //检查费
  11148. // var checkCostPartSelfTotal float64 = 0 //检查费
  11149. //
  11150. // var laboratoryCostTotal float64 = 0 //化验费
  11151. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11152. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11153. //
  11154. // var treatCostTotal float64 = 0 //治疗费用
  11155. // var treatCostSelfTotal float64 = 0 //治疗费用
  11156. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11157. //
  11158. // var zhenChaCostTotal float64 = 0 //其他费用
  11159. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11160. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11161. //
  11162. // decimal.DivisionPrecision = 2
  11163. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11164. //
  11165. // var balanceAccountsType int64
  11166. // if his.ID > 0 {
  11167. // balanceAccountsType = his.BalanceAccountsType
  11168. // } else {
  11169. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11170. // }
  11171. // if balanceAccountsType == 2 {
  11172. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11173. // for _, item := range orderInfos_two {
  11174. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11175. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11176. // item.MedChrgitmType = "09"
  11177. // }
  11178. //
  11179. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11180. // if item.HisPrescriptionProject.Type == 2 {
  11181. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11182. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11183. // case 0:
  11184. // item.MedChrgitmType = "0"
  11185. // break
  11186. // case 1:
  11187. // item.MedChrgitmType = "14"
  11188. // break
  11189. // case 2:
  11190. // item.MedChrgitmType = "05"
  11191. //
  11192. // break
  11193. // case 3:
  11194. // item.MedChrgitmType = "03"
  11195. //
  11196. // break
  11197. // case 4:
  11198. // item.MedChrgitmType = "03"
  11199. //
  11200. // break
  11201. // case 5:
  11202. // item.MedChrgitmType = "08"
  11203. //
  11204. // break
  11205. // case 6:
  11206. // item.MedChrgitmType = "14"
  11207. //
  11208. // break
  11209. // case 7:
  11210. // item.MedChrgitmType = "14"
  11211. //
  11212. // break
  11213. // case 8:
  11214. // item.MedChrgitmType = "03"
  11215. // break
  11216. // case 9:
  11217. // item.MedChrgitmType = "14"
  11218. // break
  11219. // case 10:
  11220. // item.MedChrgitmType = "14"
  11221. // break
  11222. // case 11:
  11223. // item.MedChrgitmType = "06"
  11224. // break
  11225. // case 12:
  11226. // item.MedChrgitmType = "12"
  11227. // break
  11228. // case 13:
  11229. // item.MedChrgitmType = "01"
  11230. // break
  11231. // case 14:
  11232. // item.MedChrgitmType = "04"
  11233. // break
  11234. // case 15:
  11235. // item.MedChrgitmType = "02"
  11236. // break
  11237. //
  11238. // }
  11239. //
  11240. // } else {
  11241. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11242. //
  11243. // case 1:
  11244. // item.MedChrgitmType = "14"
  11245. // break
  11246. // case 2:
  11247. // item.MedChrgitmType = "05"
  11248. //
  11249. // break
  11250. // case 3:
  11251. // item.MedChrgitmType = "03"
  11252. //
  11253. // break
  11254. // case 4:
  11255. // item.MedChrgitmType = "03"
  11256. //
  11257. // break
  11258. // case 5:
  11259. // item.MedChrgitmType = "08"
  11260. //
  11261. // break
  11262. // case 6:
  11263. // item.MedChrgitmType = "14"
  11264. //
  11265. // break
  11266. // case 7:
  11267. // item.MedChrgitmType = "14"
  11268. //
  11269. // break
  11270. // case 8:
  11271. // item.MedChrgitmType = "03"
  11272. // break
  11273. // case 9:
  11274. // item.MedChrgitmType = "14"
  11275. // break
  11276. //
  11277. // }
  11278. //
  11279. // }
  11280. //
  11281. // } else if item.HisPrescriptionProject.Type == 3 {
  11282. // item.MedChrgitmType = "08"
  11283. // }
  11284. // }
  11285. // }
  11286. //
  11287. // for _, item := range orderInfos_two {
  11288. // fmt.Println(item.MedChrgitmType)
  11289. // if item.MedChrgitmType == "01" { //床位费
  11290. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11291. // bedCostSelfTotal = bedCostTotal
  11292. // }
  11293. //
  11294. // if item.MedChrgitmType == "02" { //诊察费
  11295. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11296. // zhenChaCostSelfTotal = zhenChaCostTotal
  11297. // }
  11298. //
  11299. // if item.MedChrgitmType == "03" { //检查费
  11300. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11301. // checkCostSelfTotal = checkCostTotal
  11302. // }
  11303. //
  11304. // if item.MedChrgitmType == "04" { //化验费
  11305. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11306. // laboratoryCostSelfTotal = laboratoryCostTotal
  11307. // }
  11308. //
  11309. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11310. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11311. // treatCostSelfTotal = treatCostTotal
  11312. // }
  11313. //
  11314. // if item.MedChrgitmType == "06" { //手术费
  11315. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11316. // operationCostSelfTotal = treatCostTotal
  11317. // }
  11318. //
  11319. // if item.MedChrgitmType == "08" { //材料费
  11320. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11321. // materialCostSelfTotal = materialCostTotal
  11322. // }
  11323. //
  11324. // if item.MedChrgitmType == "09" { //西药费
  11325. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11326. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11327. // }
  11328. //
  11329. // if item.MedChrgitmType == "11" { //中成费
  11330. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11331. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11332. // }
  11333. //
  11334. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11335. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11336. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11337. // otherCostSelfTotal = otherCostTotal
  11338. // }
  11339. // } else {
  11340. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11341. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11342. // otherCostSelfTotal = otherCostTotal
  11343. // }
  11344. //
  11345. // }
  11346. //
  11347. // }
  11348. //
  11349. // } else {
  11350. // for _, item := range orderInfos {
  11351. // if item.MedChrgitmType == "01" { //床位费
  11352. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11353. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11354. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11355. // }
  11356. //
  11357. // if item.MedChrgitmType == "02" { //诊察费
  11358. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11359. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11360. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11361. // }
  11362. //
  11363. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11364. // if item.MedChrgitmType == "03" { //检查费
  11365. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11366. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11367. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11368. //
  11369. // }
  11370. // } else {
  11371. // if item.MedChrgitmType == "03" { //检查费
  11372. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11373. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11374. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11375. // }
  11376. //
  11377. // }
  11378. //
  11379. // if item.MedChrgitmType == "04" { //化验费
  11380. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11381. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11382. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11383. //
  11384. // }
  11385. //
  11386. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11387. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11388. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11389. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11390. //
  11391. // }
  11392. //
  11393. // if item.MedChrgitmType == "06" { //手术费
  11394. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11395. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11396. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11397. // }
  11398. //
  11399. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11400. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11401. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11402. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11403. // }
  11404. //
  11405. // if item.MedChrgitmType == "09" { //西药费
  11406. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11407. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11408. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11409. // }
  11410. //
  11411. // if item.MedChrgitmType == "11" { //中成费
  11412. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11413. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11414. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11415. // }
  11416. //
  11417. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11418. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11419. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11420. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11421. // }
  11422. //
  11423. // }
  11424. // }
  11425. // timeLayout := "2006-01-02"
  11426. // loc, _ := time.LoadLocation("Local")
  11427. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11428. // if err != nil {
  11429. // }
  11430. // startRecordDateTime := startTime.Unix()
  11431. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11432. // if err != nil {
  11433. // }
  11434. // endRecordDateTime := endTime.Unix()
  11435. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11436. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11437. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11438. //
  11439. // c.ServeSuccessJSON(map[string]interface{}{
  11440. // "order_number": order.Number, //业务流水号
  11441. // "id_card_no": his.IdCardNo, //社会保障号
  11442. // "department_name": department.Name, //科室
  11443. // "number": his.Number, //门诊号
  11444. // "date": order.SettleAccountsDate, //结算日期
  11445. // "name": order.PsnName, //姓名
  11446. // "gender": patient.Gender, //性别
  11447. // "psn_cash_money": order.PsnCashPay, //个人支付
  11448. // "pay_way": "门诊", //结算方式
  11449. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11450. // "admin_user_name": admin.UserName, //收款员
  11451. // "order": order,
  11452. // "order_info": orderInfos_two,
  11453. // "his": his,
  11454. // "bedCostTotal": bedCostTotal,
  11455. // "bedCostSelfTotal": bedCostSelfTotal,
  11456. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11457. // "operationCostTotal": operationCostTotal,
  11458. // "operationCostSelfTotal": operationCostSelfTotal,
  11459. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11460. // "otherCostTotal": otherCostTotal,
  11461. // "otherCostSelfTotal": otherCostSelfTotal,
  11462. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11463. // "materialCostTotal": materialCostTotal,
  11464. // "materialCostSelfTotal": materialCostSelfTotal,
  11465. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11466. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11467. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11468. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11469. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11470. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11471. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11472. // "checkCostTotal": checkCostTotal,
  11473. // "checkCostSelfTotal": checkCostSelfTotal,
  11474. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11475. // "laboratoryCostTotal": laboratoryCostTotal,
  11476. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11477. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11478. // "treatCostTotal": treatCostTotal,
  11479. // "treatCostSelfTotal": treatCostSelfTotal,
  11480. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11481. // "zhenChaCostTotal": zhenChaCostTotal,
  11482. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11483. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11484. // "his_hospital_record": his_hospital_record,
  11485. // "pre_pay_money": pre_pay_money,
  11486. // "refund_sum": sum,
  11487. // })
  11488. //
  11489. //}
  11490. func (this *HisApiController) GetIncomeStatisticsData() {
  11491. start_time := this.GetString("start_time")
  11492. end_time := this.GetString("end_time")
  11493. key_words := this.GetString("key_words")
  11494. limit, _ := this.GetInt64("limit")
  11495. page, _ := this.GetInt64("page")
  11496. if page <= 0 {
  11497. page = 1
  11498. }
  11499. if limit <= 0 {
  11500. limit = 10
  11501. }
  11502. statistics_type, _ := this.GetInt64("statistics_type")
  11503. admin := this.GetAdminUserInfo()
  11504. timeLayout := "2006-01-02"
  11505. loc, _ := time.LoadLocation("Local")
  11506. var theStartTIme int64
  11507. if len(start_time) > 0 {
  11508. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11509. if err != nil {
  11510. theStartTIme = 0
  11511. }
  11512. theStartTIme = theTime.Unix()
  11513. }
  11514. var theEndtTIme int64
  11515. if len(end_time) > 0 {
  11516. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11517. if err != nil {
  11518. theEndtTIme = 0
  11519. }
  11520. theEndtTIme = theTime.Unix()
  11521. }
  11522. if statistics_type == 1 {
  11523. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11524. this.ServeSuccessJSON(map[string]interface{}{
  11525. "list": list,
  11526. "total": total,
  11527. })
  11528. } else {
  11529. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11530. this.ServeSuccessJSON(map[string]interface{}{
  11531. "list": list,
  11532. "total": total,
  11533. })
  11534. }
  11535. }
  11536. func (c *HisApiController) PostProjectInformation() {
  11537. adminUser := c.GetAdminUserInfo()
  11538. orgId := adminUser.CurrentOrgId
  11539. dataBody := make(map[string]interface{}, 0)
  11540. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11541. if err != nil {
  11542. utils.ErrorLog(err.Error())
  11543. return
  11544. }
  11545. utils.ErrorLog("%v", dataBody)
  11546. var projectList []*models.HisProject
  11547. var total_goods []interface{}
  11548. tempProjects := dataBody["projects"].([]interface{})
  11549. total_goods = tempProjects
  11550. for index, projectMap := range tempProjects {
  11551. projectM := projectMap.(map[string]interface{})
  11552. var project models.HisProject
  11553. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11554. utils.ErrorLog("project_name")
  11555. return
  11556. }
  11557. project_name, _ := projectM["project_name"].(string)
  11558. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11559. err_log := models.ExportErrLog{
  11560. LogType: 6,
  11561. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11562. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11563. Status: 1,
  11564. CreateTime: time.Now().Unix(),
  11565. UpdateTime: time.Now().Unix(),
  11566. ExportTime: time.Now().Unix(),
  11567. }
  11568. service.CreateExportErrLog(&err_log)
  11569. continue
  11570. }
  11571. project.ProjectName = project_name
  11572. prices := projectM["price"].(string)
  11573. price, _ := strconv.ParseFloat(prices, 64)
  11574. if price <= 0 { //名字为空则生成一条导入错误日志
  11575. err_log := models.ExportErrLog{
  11576. LogType: 6,
  11577. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11578. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11579. Status: 1,
  11580. CreateTime: time.Now().Unix(),
  11581. UpdateTime: time.Now().Unix(),
  11582. ExportTime: time.Now().Unix(),
  11583. }
  11584. service.CreateExportErrLog(&err_log)
  11585. continue
  11586. }
  11587. project.Price = price
  11588. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11589. utils.ErrorLog("unit_id")
  11590. return
  11591. }
  11592. unit := projectM["unit"].(string)
  11593. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11594. err_log := models.ExportErrLog{
  11595. LogType: 6,
  11596. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11597. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11598. Status: 1,
  11599. CreateTime: time.Now().Unix(),
  11600. UpdateTime: time.Now().Unix(),
  11601. ExportTime: time.Now().Unix(),
  11602. }
  11603. service.CreateExportErrLog(&err_log)
  11604. continue
  11605. }
  11606. project.Unit = unit
  11607. cost_classify := projectM["cost_classify"].(string)
  11608. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11609. err_log := models.ExportErrLog{
  11610. LogType: 6,
  11611. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11612. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11613. Status: 1,
  11614. CreateTime: time.Now().Unix(),
  11615. UpdateTime: time.Now().Unix(),
  11616. ExportTime: time.Now().Unix(),
  11617. }
  11618. service.CreateExportErrLog(&err_log)
  11619. continue
  11620. }
  11621. var costClassify = "费用类别"
  11622. var cost_classify_id int64
  11623. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11624. if len(cost_classify) != 0 {
  11625. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11626. if errcode == gorm.ErrRecordNotFound {
  11627. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11628. dataconfig := models.DictDataconfig{
  11629. ParentId: costClassifyConfig.ID,
  11630. Module: "system",
  11631. OrgId: orgId,
  11632. Name: cost_classify,
  11633. FieldName: "",
  11634. Value: costConfig.Value + 1,
  11635. CreatedTime: "",
  11636. UpdatedTime: "",
  11637. CreateUserId: adminUser.AdminUser.Id,
  11638. Status: 1,
  11639. Remark: "",
  11640. DeleteIdSystem: 0,
  11641. Title: "",
  11642. Content: "",
  11643. Order: 0,
  11644. Code: "",
  11645. }
  11646. service.CreatedDicConfig(&dataconfig)
  11647. }
  11648. }
  11649. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11650. for _, it := range costClassList {
  11651. if cost_classify == it.Name {
  11652. cost_classify_id = int64(it.Value)
  11653. }
  11654. }
  11655. project.CostClassify = cost_classify_id
  11656. executive_section := projectM["executive_section"].(string)
  11657. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11658. err_log := models.ExportErrLog{
  11659. LogType: 6,
  11660. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11661. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11662. Status: 1,
  11663. CreateTime: time.Now().Unix(),
  11664. UpdateTime: time.Now().Unix(),
  11665. ExportTime: time.Now().Unix(),
  11666. }
  11667. service.CreateExportErrLog(&err_log)
  11668. continue
  11669. }
  11670. if len(executive_section) != 0 {
  11671. //查找科室是否有内容
  11672. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11673. if errcodedepart == gorm.ErrRecordNotFound {
  11674. department := models.XtHisDepartment{
  11675. Name: executive_section,
  11676. Status: 1,
  11677. UserOrgId: adminUser.CurrentOrgId,
  11678. CreatedTime: time.Now().Unix(),
  11679. }
  11680. service.CreateDePartment(&department)
  11681. }
  11682. }
  11683. var executive_section_id int64
  11684. departMentList, _ := service.GetAllDepartMent(orgId)
  11685. for _, it := range departMentList {
  11686. if executive_section == it.Name {
  11687. executive_section_id = it.ID
  11688. }
  11689. }
  11690. project.ExecutiveSection = executive_section_id
  11691. medical_coverage := projectM["medical_coverage"].(string)
  11692. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11693. err_log := models.ExportErrLog{
  11694. LogType: 6,
  11695. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11696. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11697. Status: 1,
  11698. CreateTime: time.Now().Unix(),
  11699. UpdateTime: time.Now().Unix(),
  11700. ExportTime: time.Now().Unix(),
  11701. }
  11702. service.CreateExportErrLog(&err_log)
  11703. continue
  11704. }
  11705. var medicalCoverage = "医保等级"
  11706. var medical_coverage_id int64
  11707. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11708. if len(medical_coverage) != 0 {
  11709. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11710. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11711. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11712. dataconfig := models.DictDataconfig{
  11713. ParentId: medicalCoverageConfig.ID,
  11714. Module: "system",
  11715. OrgId: orgId,
  11716. Name: medical_coverage,
  11717. FieldName: "",
  11718. Value: medicalCoverageConfig.Value + 1,
  11719. CreatedTime: "",
  11720. UpdatedTime: "",
  11721. CreateUserId: adminUser.AdminUser.Id,
  11722. Status: 1,
  11723. Remark: "",
  11724. DeleteIdSystem: 0,
  11725. Title: "",
  11726. Content: "",
  11727. Order: 0,
  11728. Code: "",
  11729. }
  11730. service.CreatedDicConfig(&dataconfig)
  11731. }
  11732. }
  11733. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11734. for _, it := range medicalCoverageList {
  11735. if medical_coverage == it.Name {
  11736. medical_coverage_id = int64(it.Value)
  11737. }
  11738. }
  11739. project.MedicalCoverage = medical_coverage_id
  11740. pinyin := projectM["pinyin"].(string)
  11741. project.Pinyin = pinyin
  11742. wubi := projectM["wubi"].(string)
  11743. project.Wubi = wubi
  11744. statistical_classification := projectM["statistical_classification"].(string)
  11745. var statisticalClassification = "统计分类"
  11746. var statistical_classification_id int64
  11747. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11748. if len(statistical_classification) != 0 {
  11749. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11750. if classificationerrcodes == gorm.ErrRecordNotFound {
  11751. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11752. dataconfig := models.DictDataconfig{
  11753. ParentId: classiFication.ID,
  11754. Module: "system",
  11755. OrgId: orgId,
  11756. Name: statistical_classification,
  11757. FieldName: "",
  11758. Value: classiFicationConfig.Value + 1,
  11759. CreatedTime: "",
  11760. UpdatedTime: "",
  11761. CreateUserId: adminUser.AdminUser.Id,
  11762. Status: 1,
  11763. Remark: "",
  11764. DeleteIdSystem: 0,
  11765. Title: "",
  11766. Content: "",
  11767. Order: 0,
  11768. Code: "",
  11769. }
  11770. service.CreatedDicConfig(&dataconfig)
  11771. }
  11772. }
  11773. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11774. for _, it := range classiFicationList {
  11775. if statistical_classification == it.Name {
  11776. statistical_classification_id = int64(it.Value)
  11777. }
  11778. }
  11779. project.StatisticalClassification = statistical_classification_id
  11780. disease_directory := int64(projectM["disease_directory"].(float64))
  11781. project.DiseaseDirectory = disease_directory
  11782. is_record := int64(projectM["is_record"].(float64))
  11783. project.IsRecord = is_record
  11784. medical_code := projectM["medical_code"].(string)
  11785. project.MedicalCode = medical_code
  11786. tube_color := projectM["tube_color"].(string)
  11787. var tubeColor = "试管颜色"
  11788. var tube_color_id int64
  11789. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11790. if len(tube_color) != 0 {
  11791. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11792. if errcodetube == gorm.ErrRecordNotFound {
  11793. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11794. dataconfig := models.DictDataconfig{
  11795. ParentId: tubeColorConfig.ID,
  11796. Module: "system",
  11797. OrgId: orgId,
  11798. Name: tube_color,
  11799. FieldName: "",
  11800. Value: tubeConfig.Value + 1,
  11801. CreatedTime: "",
  11802. UpdatedTime: "",
  11803. CreateUserId: adminUser.AdminUser.Id,
  11804. Status: 1,
  11805. Remark: "",
  11806. DeleteIdSystem: 0,
  11807. Title: "",
  11808. Content: "",
  11809. Order: 0,
  11810. Code: "",
  11811. }
  11812. service.CreatedDicConfig(&dataconfig)
  11813. }
  11814. }
  11815. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11816. for _, it := range tubeColorList {
  11817. if tube_color == it.Name {
  11818. tube_color_id = int64(it.Value)
  11819. }
  11820. }
  11821. project.TubeColor = tube_color_id
  11822. single_dose := projectM["single_dose"].(string)
  11823. project.SingleDose = single_dose
  11824. execution_frequency := projectM["execution_frequency"].(string)
  11825. project.ExecutionFrequency = execution_frequency
  11826. delivery_way := projectM["delivery_way"].(string)
  11827. project.DeliveryWay = delivery_way
  11828. number_days := projectM["number_days"].(string)
  11829. project.NumberDays = number_days
  11830. total := projectM["total"].(string)
  11831. project.Total = total
  11832. medical_status := int64(projectM["medical_status"].(float64))
  11833. project.MedicalStatus = medical_status
  11834. category := int64(projectM["category"].(float64))
  11835. project.Category = category
  11836. specail_project := int64(projectM["specail_project"].(float64))
  11837. project.SpecailProject = specail_project
  11838. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11839. project.SocialSecurityDirectoryCode = social_security_directory_code
  11840. remark := projectM["remark"].(string)
  11841. project.Remark = remark
  11842. record_date := projectM["record_date"].(string)
  11843. timeLayout := "2006-01-02"
  11844. loc, _ := time.LoadLocation("Local")
  11845. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11846. project.RecordDate = theTime.Unix()
  11847. projectList = append(projectList, &project)
  11848. }
  11849. export_time := time.Now().Unix()
  11850. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11851. if len(projectList) > 0 {
  11852. for _, item := range projectList {
  11853. hans := item.ProjectName // 要转换的汉字字符串
  11854. // 创建一个拼音转换器
  11855. p := pinyin.NewArgs()
  11856. // 将汉字转为拼音
  11857. pinyinSlice := pinyin.Pinyin(hans, p)
  11858. // 输出拼音
  11859. fmt.Println("Pinyin:", pinyinSlice)
  11860. // 获取首字母
  11861. firstLetter := ""
  11862. for _, py := range pinyinSlice {
  11863. if len(py) > 0 {
  11864. firstLetter += string(py[0][0])
  11865. }
  11866. }
  11867. item.FirstLetter = firstLetter
  11868. project := models.HisProject{
  11869. ProjectName: item.ProjectName,
  11870. Price: item.Price,
  11871. Unit: item.Unit,
  11872. CostClassify: item.CostClassify,
  11873. ExecutiveSection: item.ExecutiveSection,
  11874. MedicalCoverage: item.MedicalCoverage,
  11875. UserOrgId: orgId,
  11876. Status: 1,
  11877. CreatedTime: time.Now().Unix(),
  11878. Pinyin: item.Pinyin,
  11879. Wubi: item.Wubi,
  11880. StatisticalClassification: item.StatisticalClassification,
  11881. DiseaseDirectory: item.DiseaseDirectory,
  11882. IsRecord: item.IsRecord,
  11883. MedicalCode: item.MedicalCode,
  11884. TubeColor: item.TubeColor,
  11885. SingleDose: item.SingleDose,
  11886. DeliveryWay: item.DeliveryWay,
  11887. NumberDays: item.NumberDays,
  11888. Total: item.Total,
  11889. Category: item.Category,
  11890. MedicalStatus: item.MedicalStatus,
  11891. SpecailProject: item.SpecailProject,
  11892. RecordDate: item.RecordDate,
  11893. Remark: item.Remark,
  11894. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11895. ExecutionFrequency: item.ExecutionFrequency,
  11896. FirstLetter: item.FirstLetter,
  11897. }
  11898. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11899. if errcodeproject == gorm.ErrRecordNotFound {
  11900. service.CreateProjectInfomation(&project)
  11901. } else if errcodeproject == nil {
  11902. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11903. }
  11904. log := models.ExportLog{
  11905. LogType: 6,
  11906. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11907. TotalNum: int64(len(total_goods)),
  11908. FailNum: int64(len(errLogs)),
  11909. SuccessNum: int64(len(projectList)),
  11910. CreateTime: time.Now().Unix(),
  11911. UpdateTime: time.Now().Unix(),
  11912. ExportTime: export_time,
  11913. Status: 1,
  11914. }
  11915. service.CreateExportLog(&log)
  11916. c.ServeSuccessJSON(map[string]interface{}{
  11917. "msg": "导入成功",
  11918. "total_num": len(total_goods),
  11919. "success_num": len(projectList),
  11920. "fail_num": int64(len(errLogs)),
  11921. })
  11922. }
  11923. } else {
  11924. log := models.ExportLog{
  11925. LogType: 6,
  11926. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11927. TotalNum: int64(len(total_goods)),
  11928. FailNum: int64(len(errLogs)),
  11929. SuccessNum: int64(len(projectList)),
  11930. CreateTime: time.Now().Unix(),
  11931. UpdateTime: time.Now().Unix(),
  11932. ExportTime: export_time,
  11933. Status: 1,
  11934. }
  11935. service.CreateExportLog(&log)
  11936. c.ServeSuccessJSON(map[string]interface{}{
  11937. "msg": "导入成功",
  11938. "total_num": len(total_goods),
  11939. "success_num": len(projectList),
  11940. "fail_num": int64(len(errLogs)),
  11941. })
  11942. }
  11943. }
  11944. //func (this *HisApiController) EditProjectInformation(){
  11945. //
  11946. // id, _ := this.GetInt64("id")
  11947. // project_team := this.GetString("project_team")
  11948. // price := this.GetString("price")
  11949. // price_float, _ := strconv.ParseFloat(price, 64)
  11950. // pinyin := this.GetString("pinyin")
  11951. // wubi := this.GetString("wubi")
  11952. // tube_color, _ := this.GetInt64("tube_color")
  11953. // team_type, _ := this.GetInt64("team_type")
  11954. // remark := this.GetString("remark")
  11955. // ids := this.GetString("ids")
  11956. // item_id := this.GetString("item_id")
  11957. // projectTeam := models.XtHisProjectTeam{
  11958. // ProjectTeam: project_team,
  11959. // Price: price_float,
  11960. // Pinyin: pinyin,
  11961. // Wubi: wubi,
  11962. // TubeColor: tube_color,
  11963. // TeamType: team_type,
  11964. // Remark: remark,
  11965. // ProjectId: ids,
  11966. // ItemId: item_id,
  11967. // }
  11968. //
  11969. //
  11970. // dataBody := make(map[string]interface{}, 0)
  11971. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11972. // if err != nil {
  11973. // utils.ErrorLog(err.Error())
  11974. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11975. // return
  11976. // }
  11977. //
  11978. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11979. //
  11980. //
  11981. // if err != nil {
  11982. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11983. // return
  11984. // }
  11985. //
  11986. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11987. // infos, _ := dataBody["info"].([]interface{})
  11988. // if len(infos) > 0 {
  11989. // var ids []string
  11990. //
  11991. // for _, item := range infos {
  11992. // items := item.(map[string]interface{})
  11993. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11994. // utils.ErrorLog("id")
  11995. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11996. // return
  11997. // }
  11998. // id := int64(items["id"].(float64))
  11999. //
  12000. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12001. // utils.ErrorLog("type")
  12002. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12003. // return
  12004. // }
  12005. // types := int64(items["type"].(float64))
  12006. //
  12007. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12008. // utils.ErrorLog("number")
  12009. // }
  12010. //
  12011. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12012. //
  12013. // projectList := models.XtHisProjectList{
  12014. // Number: number,
  12015. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12016. // ProjectId: id,
  12017. // Status: 1,
  12018. // CreatedTime: time.Now().Unix(),
  12019. // UpdatedTime: time.Now().Unix(),
  12020. // TeamId: projectTeam.ID,
  12021. // Type: types,
  12022. // }
  12023. // list := projectList
  12024. //
  12025. // service.CreateProjectList(&list)
  12026. //
  12027. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12028. //
  12029. // }
  12030. // ids_str := strings.Join(ids, ",")
  12031. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12032. // service.SaveProjectTeam(&projectTeam)
  12033. // this.ServeSuccessJSON(map[string]interface{}{
  12034. // "projectTeam": projectTeam,
  12035. // })
  12036. // }
  12037. // }
  12038. //}
  12039. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12040. name := c.GetString("name")
  12041. mode_id, _ := c.GetInt64("mode", 0)
  12042. types, _ := c.GetInt64("type", 0)
  12043. patient_id, _ := c.GetInt64("patient_id", 0)
  12044. types = 1
  12045. adminInfo := c.GetAdminUserInfo()
  12046. template := &models.HisPrescriptionTemplate{
  12047. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12048. PatientId: patient_id,
  12049. Type: types,
  12050. Status: 1,
  12051. Ctime: time.Now().Unix(),
  12052. Mtime: time.Now().Unix(),
  12053. Name: name,
  12054. Mode: mode_id,
  12055. }
  12056. dataBody := make(map[string]interface{}, 0)
  12057. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12058. if err != nil {
  12059. utils.ErrorLog(err.Error())
  12060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12061. return
  12062. }
  12063. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12064. //如果已经存在记录则删除处方
  12065. if template_one.ID > 0 {
  12066. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12067. var ids []int64
  12068. var org_id int64
  12069. for _, item := range ps {
  12070. org_id = c.GetAdminUserInfo().CurrentOrgId
  12071. ids = append(ids, item.ID)
  12072. }
  12073. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12074. if err2 == nil {
  12075. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12076. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12077. if len(prescriptions) > 0 {
  12078. for _, item := range prescriptions {
  12079. items := item.(map[string]interface{})
  12080. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12081. utils.ErrorLog("type")
  12082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12083. return
  12084. }
  12085. types := int64(items["type"].(float64))
  12086. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12087. utils.ErrorLog("med_type")
  12088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12089. return
  12090. }
  12091. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12092. ctime := time.Now().Unix()
  12093. prescription := &models.HisPrescriptionInfoTemplate{
  12094. PatientId: patient_id,
  12095. UserOrgId: adminInfo.CurrentOrgId,
  12096. Ctime: ctime,
  12097. Mtime: ctime,
  12098. Type: types,
  12099. Modifier: adminInfo.AdminUser.Id,
  12100. Creator: adminInfo.AdminUser.Id,
  12101. Status: 1,
  12102. PTemplateId: template_one.ID,
  12103. MedType: med_type,
  12104. }
  12105. service.CreateHisPrescriptionInfoTemplate(prescription)
  12106. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12107. advices := items["advices"].([]interface{})
  12108. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12109. ctime := time.Now().Unix()
  12110. mtime := ctime
  12111. if len(advices) > 0 {
  12112. for _, advice := range advices {
  12113. var s models.HisPrescriptionAdviceTemplate
  12114. s.PrescriptionId = prescription.ID
  12115. s.AdviceType = 2
  12116. s.StopState = 2
  12117. s.ExecutionState = 2
  12118. s.Status = 1
  12119. s.UserOrgId = adminInfo.CurrentOrgId
  12120. s.CreatedTime = ctime
  12121. s.UpdatedTime = mtime
  12122. s.PatientId = patient_id
  12123. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12124. if errcode > 0 {
  12125. c.ServeFailJSONWithSGJErrorCode(errcode)
  12126. return
  12127. }
  12128. service.CreateHisPrescriptionAdviceTemplate(&s)
  12129. }
  12130. }
  12131. }
  12132. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12133. projects := items["project"].([]interface{})
  12134. if len(projects) > 0 {
  12135. for _, project := range projects {
  12136. var p models.HisPrescriptionProjectTemplate
  12137. p.PrescriptionId = prescription.ID
  12138. p.Ctime = time.Now().Unix()
  12139. p.Mtime = time.Now().Unix()
  12140. p.PatientId = patient_id
  12141. p.UserOrgId = adminInfo.CurrentOrgId
  12142. p.Status = 1
  12143. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12144. if errcode > 0 {
  12145. c.ServeFailJSONWithSGJErrorCode(errcode)
  12146. return
  12147. }
  12148. service.CreateHisPrescriptionProjectTemplate(&p)
  12149. }
  12150. }
  12151. }
  12152. }
  12153. c.ServeSuccessJSON(map[string]interface{}{
  12154. "msg": "创建成功",
  12155. })
  12156. }
  12157. }
  12158. } else {
  12159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12160. return
  12161. }
  12162. } else {
  12163. err3 := service.CreateHisPrescriptionTemplate(template)
  12164. if err3 == nil {
  12165. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12166. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12167. if len(prescriptions) > 0 {
  12168. for _, item := range prescriptions {
  12169. items := item.(map[string]interface{})
  12170. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12171. utils.ErrorLog("type")
  12172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12173. return
  12174. }
  12175. types := int64(items["type"].(float64))
  12176. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12177. utils.ErrorLog("med_type")
  12178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12179. return
  12180. }
  12181. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12182. ctime := time.Now().Unix()
  12183. prescription := &models.HisPrescriptionInfoTemplate{
  12184. PatientId: patient_id,
  12185. UserOrgId: adminInfo.CurrentOrgId,
  12186. Ctime: ctime,
  12187. Mtime: ctime,
  12188. Type: types,
  12189. Modifier: adminInfo.AdminUser.Id,
  12190. Creator: adminInfo.AdminUser.Id,
  12191. Status: 1,
  12192. PTemplateId: template.ID,
  12193. MedType: med_type,
  12194. }
  12195. service.CreateHisPrescriptionInfoTemplate(prescription)
  12196. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12197. advices := items["advices"].([]interface{})
  12198. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12199. ctime := time.Now().Unix()
  12200. mtime := ctime
  12201. if len(advices) > 0 {
  12202. for _, advice := range advices {
  12203. var s models.HisPrescriptionAdviceTemplate
  12204. s.PrescriptionId = prescription.ID
  12205. s.AdviceType = 2
  12206. s.StopState = 2
  12207. s.ExecutionState = 2
  12208. s.Status = 1
  12209. s.UserOrgId = adminInfo.CurrentOrgId
  12210. s.CreatedTime = ctime
  12211. s.UpdatedTime = mtime
  12212. s.PatientId = patient_id
  12213. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12214. if errcode > 0 {
  12215. c.ServeFailJSONWithSGJErrorCode(errcode)
  12216. return
  12217. }
  12218. service.CreateHisPrescriptionAdviceTemplate(&s)
  12219. }
  12220. }
  12221. }
  12222. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12223. projects := items["project"].([]interface{})
  12224. if len(projects) > 0 {
  12225. for _, project := range projects {
  12226. var p models.HisPrescriptionProjectTemplate
  12227. p.PrescriptionId = prescription.ID
  12228. p.Ctime = time.Now().Unix()
  12229. p.Mtime = time.Now().Unix()
  12230. p.PatientId = patient_id
  12231. p.UserOrgId = adminInfo.CurrentOrgId
  12232. p.Status = 1
  12233. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12234. if errcode > 0 {
  12235. c.ServeFailJSONWithSGJErrorCode(errcode)
  12236. return
  12237. }
  12238. service.CreateHisPrescriptionProjectTemplate(&p)
  12239. }
  12240. }
  12241. }
  12242. }
  12243. c.ServeSuccessJSON(map[string]interface{}{
  12244. "msg": "创建成功",
  12245. })
  12246. }
  12247. }
  12248. } else {
  12249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12250. return
  12251. }
  12252. }
  12253. }
  12254. func (c *HisApiController) PreSettle() {
  12255. id, _ := c.GetInt64("id")
  12256. record_time := c.GetString("record_time")
  12257. his_patient_id, _ := c.GetInt64("his_patient_id")
  12258. timeLayout := "2006-01-02"
  12259. loc, _ := time.LoadLocation("Local")
  12260. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12261. diagnosis_id := c.GetString("diagnosis")
  12262. sick_type, _ := c.GetInt64("sick_type")
  12263. reg_type, _ := c.GetInt64("p_type")
  12264. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12265. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12266. if err != nil {
  12267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12268. return
  12269. }
  12270. recordDateTime := theTime.Unix()
  12271. adminUser := c.GetAdminUserInfo()
  12272. var prescriptions []*models.HisPrescription
  12273. var start_time int64
  12274. var end_time int64
  12275. ids_str := c.GetString("ids")
  12276. ids_arr := strings.Split(ids_str, ",")
  12277. fmt.Println(reg_type)
  12278. if settle_accounts_type == 1 { //日结
  12279. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12280. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12281. } else {
  12282. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12283. }
  12284. fmt.Println(prescriptions)
  12285. } else { //月结
  12286. start_time_str := c.GetString("start_time")
  12287. end_time_str := c.GetString("end_time")
  12288. timeLayout := "2006-01-02"
  12289. loc, _ := time.LoadLocation("Local")
  12290. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12291. if err != nil {
  12292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12293. return
  12294. }
  12295. recordStartTime := theStartTime.Unix()
  12296. start_time = recordStartTime
  12297. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12298. if err != nil {
  12299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12300. return
  12301. }
  12302. recordEndTime := theEndTime.Unix()
  12303. end_time = recordEndTime
  12304. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12305. }
  12306. if reg_type == 1111 || reg_type == 1112 {
  12307. reg_type = 11
  12308. }
  12309. timestamp := time.Now().Unix()
  12310. tempTime := time.Unix(timestamp, 0)
  12311. timeFormat := tempTime.Format("20060102150405")
  12312. chrgBchno := rand.Intn(100000) + 10000
  12313. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12314. strconv.FormatInt(his.PatientId, 10)
  12315. var ids []int64
  12316. for _, item := range prescriptions {
  12317. ids = append(ids, item.ID)
  12318. }
  12319. fmt.Println(ids)
  12320. var total float64
  12321. for _, item := range prescriptions {
  12322. fmt.Println(item)
  12323. if item.Type == 1 { //药品
  12324. for _, subItem := range item.HisDoctorAdviceInfo {
  12325. total = total + (subItem.Price * subItem.PrescribingNumber)
  12326. }
  12327. }
  12328. if item.Type == 2 { //项目
  12329. for _, subItem := range item.HisPrescriptionProject {
  12330. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12331. total = total + (subItem.Price * cnt)
  12332. }
  12333. }
  12334. for _, subItem := range item.HisAdditionalCharge {
  12335. total = total + (subItem.Price * float64(subItem.Count))
  12336. }
  12337. }
  12338. allTotal := fmt.Sprintf("%.2f", total)
  12339. totals, _ := strconv.ParseFloat(allTotal, 64)
  12340. order := &models.HisOrder{
  12341. UserOrgId: adminUser.CurrentOrgId,
  12342. HisPatientId: his.ID,
  12343. PatientId: id,
  12344. SettleAccountsDate: recordDateTime,
  12345. Ctime: time.Now().Unix(),
  12346. Mtime: time.Now().Unix(),
  12347. Status: 1,
  12348. OrderStatus: 1,
  12349. MdtrtId: his.Number,
  12350. Number: chrg_bchno,
  12351. MedfeeSumamt: totals,
  12352. SettleEndTime: end_time,
  12353. SettleStartTime: start_time,
  12354. SettleType: settle_accounts_type,
  12355. PsnPartAmt: totals,
  12356. PsnCashPay: totals,
  12357. PType: 2,
  12358. IsPre: 1,
  12359. MedType: strconv.Itoa(int(reg_type)),
  12360. Diagnosis: diagnosis_id,
  12361. }
  12362. err = service.CreateOrder(order)
  12363. if err != nil {
  12364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12365. return
  12366. }
  12367. var customs []*Custom
  12368. for _, item := range prescriptions {
  12369. fmt.Println(item.Type)
  12370. if item.Type == 1 { //药品
  12371. for _, subItem := range item.HisDoctorAdviceInfo {
  12372. cus := &Custom{
  12373. AdviceId: subItem.ID,
  12374. ProjectId: 0,
  12375. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12376. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12377. FeedetlSn: subItem.FeedetlSn,
  12378. Price: fmt.Sprintf("%.2f", subItem.Price),
  12379. MedListCodg: subItem.MedListCodg,
  12380. Type: 1,
  12381. }
  12382. customs = append(customs, cus)
  12383. }
  12384. }
  12385. if item.Type == 2 { //项目
  12386. for _, subItem := range item.HisPrescriptionProject {
  12387. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12388. cus := &Custom{
  12389. AdviceId: 0,
  12390. ProjectId: subItem.ID,
  12391. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12392. Cut: fmt.Sprintf("%.2f", cnt),
  12393. FeedetlSn: subItem.FeedetlSn,
  12394. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12395. MedListCodg: subItem.MedListCodg,
  12396. Type: 2,
  12397. }
  12398. customs = append(customs, cus)
  12399. }
  12400. }
  12401. for _, item := range item.HisAdditionalCharge {
  12402. cus := &Custom{
  12403. ItemId: item.ID,
  12404. AdviceId: 0,
  12405. ProjectId: 0,
  12406. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12407. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12408. FeedetlSn: item.FeedetlSn,
  12409. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12410. MedListCodg: item.XtHisAddtionConfig.Code,
  12411. Type: 3,
  12412. }
  12413. customs = append(customs, cus)
  12414. }
  12415. }
  12416. fmt.Println(customs)
  12417. for _, item := range customs {
  12418. var advice_id int64 = 0
  12419. var project_id int64 = 0
  12420. var item_id int64 = 0
  12421. var types int64 = 0
  12422. if item.Type == 1 {
  12423. advice_id = item.AdviceId
  12424. project_id = 0
  12425. item_id = 0
  12426. } else if item.Type == 2 {
  12427. advice_id = 0
  12428. item_id = 0
  12429. project_id = item.ProjectId
  12430. } else if item.Type == 3 {
  12431. advice_id = 0
  12432. item_id = item.ItemId
  12433. project_id = 0
  12434. }
  12435. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12436. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12437. pric, _ := strconv.ParseFloat(item.Price, 32)
  12438. info := &models.HisOrderInfo{
  12439. OrderNumber: order.Number,
  12440. UploadDate: time.Now().Unix(),
  12441. AdviceId: advice_id,
  12442. DetItemFeeSumamt: detItemFeeSumamt,
  12443. Cnt: cut,
  12444. Pric: pric,
  12445. PatientId: id,
  12446. Status: 1,
  12447. Mtime: time.Now().Unix(),
  12448. Ctime: time.Now().Unix(),
  12449. UserOrgId: adminUser.CurrentOrgId,
  12450. HisPatientId: his.ID,
  12451. OrderId: order.ID,
  12452. ProjectId: project_id,
  12453. Type: types,
  12454. ItemId: item_id,
  12455. }
  12456. service.CreateOrderInfo(info)
  12457. }
  12458. his.SickType = sick_type
  12459. service.UpdataHisPateint(&his)
  12460. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12461. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12462. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12463. if err == nil {
  12464. c.ServeSuccessJSON(map[string]interface{}{
  12465. "msg": "结算成功",
  12466. })
  12467. }
  12468. }
  12469. type CustomOrderInfo struct {
  12470. Name string
  12471. Spec string
  12472. Unit string
  12473. Count float64
  12474. Price float64
  12475. Total float64
  12476. }
  12477. func (c *HisApiController) GetPrivateExpensesInfo() {
  12478. order_id, _ := c.GetInt64("id", 0)
  12479. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12480. order, _ := service.GetHisOrderByID(order_id)
  12481. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12482. if order.ID == 0 {
  12483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12484. return
  12485. }
  12486. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12487. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12488. org_id := c.GetAdminUserInfo().CurrentOrgId
  12489. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12490. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12491. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12492. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12493. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12494. //var orderInfos_four []*models.HisOrderInfoTwo
  12495. //for _, item := range orderInfos_three {
  12496. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12497. // item.HisPrescriptionProject.IsCheckTeam = 1
  12498. // orderInfos_four = append(orderInfos_four, item)
  12499. //
  12500. // }
  12501. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12502. // item.HisPrescriptionProject.IsCheckTeam = 2
  12503. // orderInfos_two = append(orderInfos_two, item)
  12504. // }
  12505. //}
  12506. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12507. //var cus_slice []CustomOrderInfo
  12508. //for _, item := range new_order_info {
  12509. // var cus CustomOrderInfo
  12510. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12511. // cus.Unit = ""
  12512. // cus.Spec = ""
  12513. // var total float64
  12514. // for _, subItem := range orderInfos_four {
  12515. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12516. // total = total + subItem.DetItemFeeSumamt
  12517. // fmt.Println(subItem.DetItemFeeSumamt)
  12518. // }
  12519. // }
  12520. // cus.Count = 1
  12521. // cus.Total = total
  12522. // cus_slice = append(cus_slice, cus)
  12523. //}
  12524. orderInfos = append(orderInfos, orderInfos_two...)
  12525. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12526. //orderInfos = append(orderInfos, orderInfos_three...)
  12527. //}/**/
  12528. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12529. c.ServeSuccessJSON(map[string]interface{}{
  12530. "order": order,
  12531. "order_info": orderInfos,
  12532. "patient": patient,
  12533. "admin_info": adminInfo,
  12534. "his": his,
  12535. "current_admin": role,
  12536. "org_config": miConfig,
  12537. //"new_order_info": cus_slice,
  12538. })
  12539. }
  12540. func (this *HisApiController) ChangeMedType() {
  12541. med_type := this.GetString("med_type")
  12542. old_med_type := this.GetString("old_med_type")
  12543. ids := this.GetString("ids")
  12544. settle_type, _ := this.GetInt64("settle_type")
  12545. start_time := this.GetString("start_time")
  12546. end_time := this.GetString("end_time")
  12547. ids_arr := strings.Split(ids, ",")
  12548. if settle_type == 1 { //日结
  12549. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12550. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12551. prescription.MedType = med_type
  12552. err := service.SaveHisPrescriptionTwo(&prescription)
  12553. if err == nil {
  12554. this.ServeSuccessJSON(map[string]interface{}{
  12555. "msg": "修改成功",
  12556. })
  12557. } else {
  12558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12559. return
  12560. }
  12561. } else if settle_type == 2 {
  12562. timeLayout := "2006-01-02"
  12563. loc, _ := time.LoadLocation("Local")
  12564. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12565. if err != nil {
  12566. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12567. return
  12568. }
  12569. recordStartTime := theStartTime.Unix()
  12570. start_time_timestamp := recordStartTime
  12571. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12572. if err != nil {
  12573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12574. return
  12575. }
  12576. recordEndTime := theEndTime.Unix()
  12577. end_time_timestamp := recordEndTime
  12578. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12579. if updateErr == nil {
  12580. this.ServeSuccessJSON(map[string]interface{}{
  12581. "msg": "修改成功",
  12582. })
  12583. } else {
  12584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12585. return
  12586. }
  12587. }
  12588. }
  12589. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12590. patient_id, _ := c.GetInt64("patient_id")
  12591. his_patient_id, _ := c.GetInt64("his_patient_id")
  12592. record_date := c.GetString("record_date")
  12593. start_time := c.GetString("start_time")
  12594. end_time := c.GetString("end_time")
  12595. order_status, _ := c.GetInt64("type", 0)
  12596. p_type, _ := c.GetInt64("p_type", 0)
  12597. order_id, _ := c.GetInt64("order_id", 0)
  12598. timeLayout := "2006-01-02"
  12599. loc, _ := time.LoadLocation("Local")
  12600. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12601. if err != nil {
  12602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12603. return
  12604. }
  12605. recordDateTime := theTime.Unix()
  12606. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12607. if err != nil {
  12608. }
  12609. startRecordDateTime := startTime.Unix()
  12610. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12611. if err != nil {
  12612. }
  12613. endRecordDateTime := endTime.Unix()
  12614. admin := c.GetAdminUserInfo()
  12615. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12616. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12617. order, _ := service.GetHisOrderByID(order_id)
  12618. var monthPrescriptions []*models.HisPrescription
  12619. if order_status == 1 || order_status == 0 {
  12620. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12621. } else if order_status == 2 {
  12622. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12623. }
  12624. var settle_total float64
  12625. for _, item := range monthPrescriptions {
  12626. if len(item.HisPrescriptionProject) > 0 {
  12627. for _, subItem := range item.HisPrescriptionProject {
  12628. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12629. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12630. settle_total = settle_total + total
  12631. }
  12632. }
  12633. if len(item.HisDoctorAdviceInfo) > 0 {
  12634. for _, subItem := range item.HisDoctorAdviceInfo {
  12635. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12636. settle_total = settle_total + total
  12637. }
  12638. }
  12639. }
  12640. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12641. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12642. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12643. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12644. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12645. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12646. //获取所有科室信息
  12647. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12648. var dia string
  12649. for _, item := range month_p_info {
  12650. if len(dia) == 0 {
  12651. dia = item.Diagnosis
  12652. } else {
  12653. dia = dia + "," + item.Diagnosis
  12654. }
  12655. }
  12656. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12657. dia_arr = removeEmptyStrings(dia_arr)
  12658. c.ServeSuccessJSON(map[string]interface{}{
  12659. "his_info": his_patient_info,
  12660. "xt_info": xt_patient_info,
  12661. "case_history": case_history,
  12662. "info": patientPrescriptionInfo,
  12663. "last_info": lastPatientPrescriptionInfo,
  12664. "month_prescriptions": monthPrescriptions,
  12665. "order": order,
  12666. "doctors": doctors,
  12667. "department": department,
  12668. "settle_total": settle_total,
  12669. "dia_arr": dia_arr,
  12670. })
  12671. return
  12672. }
  12673. func removeEmptyStrings(input []string) []string {
  12674. var output []string
  12675. for _, s := range input {
  12676. if s != "" {
  12677. output = append(output, s)
  12678. }
  12679. }
  12680. return output
  12681. }
  12682. func removeDuplicates(input []string) []string {
  12683. seen := make(map[string]bool)
  12684. output := []string{}
  12685. for _, s := range input {
  12686. if _, exists := seen[s]; !exists {
  12687. seen[s] = true
  12688. output = append(output, s)
  12689. }
  12690. }
  12691. return output
  12692. }
  12693. func (c *HisApiController) GetHisMonthPatientInfo() {
  12694. patient_id, _ := c.GetInt64("patient_id")
  12695. his_patient_id, _ := c.GetInt64("his_patient_id")
  12696. record_date := c.GetString("record_date")
  12697. number := c.GetString("number")
  12698. start_time := c.GetString("start_time")
  12699. end_time := c.GetString("end_time")
  12700. p_type, _ := c.GetInt64("p_type")
  12701. timeLayout := "2006-01-02"
  12702. loc, _ := time.LoadLocation("Local")
  12703. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12704. if err != nil {
  12705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12706. return
  12707. }
  12708. recordDateTime := theTime.Unix()
  12709. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12710. if err != nil {
  12711. }
  12712. startRecordDateTime := startTime.Unix()
  12713. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12714. if err != nil {
  12715. }
  12716. endRecordDateTime := endTime.Unix()
  12717. admin := c.GetAdminUserInfo()
  12718. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12719. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12720. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12721. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12722. var settle_total float64
  12723. for _, item := range monthPrescriptions {
  12724. if len(item.HisPrescriptionProject) > 0 {
  12725. for _, subItem := range item.HisPrescriptionProject {
  12726. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12727. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12728. settle_total = settle_total + total
  12729. }
  12730. }
  12731. if len(item.HisDoctorAdviceInfo) > 0 {
  12732. for _, subItem := range item.HisDoctorAdviceInfo {
  12733. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12734. settle_total = settle_total + total
  12735. }
  12736. }
  12737. }
  12738. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12739. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12740. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12741. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12742. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12743. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12744. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12745. //获取所有科室信息
  12746. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12747. c.ServeSuccessJSON(map[string]interface{}{
  12748. "his_info": his_patient_info,
  12749. "xt_info": xt_patient_info,
  12750. "case_history": case_history,
  12751. "info": patientPrescriptionInfo,
  12752. "month_prescriptions": monthPrescriptions,
  12753. "order": order,
  12754. "doctors": doctors,
  12755. "department": department,
  12756. "count": count,
  12757. "drugStockConfig": drugStockConfig,
  12758. "last_info": lastPatientPrescriptionInfo,
  12759. "settle_total": settle_total,
  12760. })
  12761. return
  12762. }
  12763. func (c *HisApiController) GetAllOrder() {
  12764. org_id := c.GetAdminUserInfo().CurrentOrgId
  12765. orders, _ := service.GetNewHisOrderList(org_id)
  12766. c.ServeSuccessJSON(map[string]interface{}{
  12767. "order": orders,
  12768. })
  12769. return
  12770. }
  12771. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12772. newArr = make([]*models.HisOrderInfoTwo, 0)
  12773. for i := 0; i < len(arr); i++ {
  12774. repeat := false
  12775. for j := i + 1; j < len(arr); j++ {
  12776. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12777. repeat = true
  12778. break
  12779. }
  12780. }
  12781. if !repeat {
  12782. newArr = append(newArr, arr[i])
  12783. }
  12784. }
  12785. return
  12786. }
  12787. // 修改处方退库操作 参数传修改之前的处方数据
  12788. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12789. if advice.ExecutionState == 1 {
  12790. //查询该病人该药品是否有库存记录
  12791. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12792. if errcode == gorm.ErrRecordNotFound {
  12793. } else {
  12794. //退库
  12795. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12796. if advice.PrescribingNumberUnit == drug.MinUnit {
  12797. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12798. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12799. //退库
  12800. warehouseInfo := models.DrugWarehouseInfo{
  12801. StockMinNumber: prescribingNumber,
  12802. }
  12803. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12804. operation_time := time.Now().Unix()
  12805. creater := advice.AdviceDoctor
  12806. ctime := time.Now().Unix()
  12807. timeStr := time.Now().Format("2006-01-02")
  12808. timeArr := strings.Split(timeStr, "-")
  12809. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12810. total = total + 1
  12811. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12812. cancelStock := models.DrugCancelStock{
  12813. OrderNumber: orderNumber,
  12814. OperaTime: operation_time,
  12815. OrgId: advice.UserOrgId,
  12816. Creater: creater,
  12817. Ctime: ctime,
  12818. Status: 1,
  12819. ReturnTime: advice.AdviceDate,
  12820. Dealer: info.Dealer,
  12821. Manufacturer: info.Manufacturer,
  12822. Type: 1,
  12823. }
  12824. service.AddSigleDrugCancelStock(&cancelStock)
  12825. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12826. dealer, _ := service.GetDealerById(info.Dealer)
  12827. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12828. cancelStockInfo := models.DrugCancelStockInfo{
  12829. OrderNumber: cancelInfo.OrderNumber,
  12830. CancelStockId: cancelInfo.ID,
  12831. DrugId: info.DrugId,
  12832. Count: info.Count,
  12833. Status: 1,
  12834. Ctime: ctime,
  12835. OrgId: advice.UserOrgId,
  12836. Type: 1,
  12837. Manufacturer: manufactureName.ManufacturerName,
  12838. Dealer: dealer.DealerName,
  12839. Total: 0,
  12840. RetailPrice: info.RetailPrice,
  12841. RetailTotalPrice: info.RetailTotalPrice,
  12842. Price: info.Price,
  12843. RegisterAccount: "",
  12844. Remark: info.Remark,
  12845. BatchNumber: info.BatchNumber,
  12846. MaxUnit: info.CountUnit,
  12847. ProductDate: info.ProductDate,
  12848. ExpiryDate: info.ExpiryDate,
  12849. BatchNumberId: info.WarehouseInfoId,
  12850. }
  12851. flow := models.DrugFlow{
  12852. WarehousingId: 0,
  12853. DrugId: info.DrugId,
  12854. Number: "",
  12855. BatchNumber: info.BatchNumber,
  12856. Count: info.Count,
  12857. UserOrgId: advice.UserOrgId,
  12858. PatientId: 0,
  12859. SystemTime: ctime,
  12860. ConsumableType: 4,
  12861. IsSys: 0,
  12862. WarehousingOrder: "",
  12863. WarehouseOutId: 0,
  12864. WarehouseOutOrderNumber: "",
  12865. IsEdit: 0,
  12866. CancelStockId: cancelStock.ID,
  12867. CancelOrderNumber: cancelStock.OrderNumber,
  12868. Manufacturer: info.Manufacturer,
  12869. Dealer: info.Dealer,
  12870. Creator: advice.UserOrgId,
  12871. UpdateCreator: 0,
  12872. Status: 1,
  12873. Ctime: time.Now().Unix(),
  12874. Mtime: 0,
  12875. Price: info.Price,
  12876. WarehousingDetailId: 0,
  12877. WarehouseOutDetailId: 0,
  12878. CancelOutDetailId: 0,
  12879. ExpireDate: info.ExpiryDate,
  12880. ProductDate: info.ProductDate,
  12881. MaxUnit: info.CountUnit,
  12882. MinUnit: "",
  12883. }
  12884. service.CreatedCancelStock(cancelStockInfo)
  12885. service.CreateDrugFlowOne(flow)
  12886. } else {
  12887. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12888. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12889. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12890. warehouseInfo := models.DrugWarehouseInfo{
  12891. StockMinNumber: prescribingNumber,
  12892. }
  12893. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12894. }
  12895. operation_time := time.Now().Unix()
  12896. creater := advice.AdviceDoctor
  12897. ctime := time.Now().Unix()
  12898. timeStr := time.Now().Format("2006-01-02")
  12899. timeArr := strings.Split(timeStr, "-")
  12900. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12901. total = total + 1
  12902. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12903. cancelStock := models.DrugCancelStock{
  12904. OrderNumber: orderNumber,
  12905. OperaTime: operation_time,
  12906. OrgId: advice.UserOrgId,
  12907. Creater: creater,
  12908. Ctime: ctime,
  12909. Status: 1,
  12910. ReturnTime: advice.AdviceDate,
  12911. Dealer: info.Dealer,
  12912. Manufacturer: info.Manufacturer,
  12913. Type: 1,
  12914. }
  12915. service.AddSigleDrugCancelStock(&cancelStock)
  12916. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12917. dealer, _ := service.GetDealerById(info.Dealer)
  12918. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12919. cancelStockInfo := models.DrugCancelStockInfo{
  12920. OrderNumber: cancelInfo.OrderNumber,
  12921. CancelStockId: cancelInfo.ID,
  12922. DrugId: info.DrugId,
  12923. Count: info.Count,
  12924. Status: 1,
  12925. Ctime: ctime,
  12926. OrgId: advice.UserOrgId,
  12927. Type: 1,
  12928. Manufacturer: manufactureName.ManufacturerName,
  12929. Dealer: dealer.DealerName,
  12930. Total: 0,
  12931. RetailPrice: info.RetailPrice,
  12932. RetailTotalPrice: info.RetailTotalPrice,
  12933. Price: info.Price,
  12934. RegisterAccount: "",
  12935. Remark: info.Remark,
  12936. BatchNumber: info.BatchNumber,
  12937. MaxUnit: info.CountUnit,
  12938. ProductDate: info.ProductDate,
  12939. ExpiryDate: info.ExpiryDate,
  12940. BatchNumberId: info.WarehouseInfoId,
  12941. }
  12942. flow := models.DrugFlow{
  12943. WarehousingId: 0,
  12944. DrugId: info.DrugId,
  12945. Number: "",
  12946. BatchNumber: info.BatchNumber,
  12947. Count: info.Count,
  12948. UserOrgId: advice.UserOrgId,
  12949. PatientId: 0,
  12950. SystemTime: ctime,
  12951. ConsumableType: 4,
  12952. IsSys: 0,
  12953. WarehousingOrder: "",
  12954. WarehouseOutId: 0,
  12955. WarehouseOutOrderNumber: "",
  12956. IsEdit: 0,
  12957. CancelStockId: cancelStock.ID,
  12958. CancelOrderNumber: cancelStock.OrderNumber,
  12959. Manufacturer: info.Manufacturer,
  12960. Dealer: info.Dealer,
  12961. Creator: advice.AdviceDoctor,
  12962. UpdateCreator: 0,
  12963. Status: 1,
  12964. Ctime: time.Now().Unix(),
  12965. Mtime: 0,
  12966. Price: info.Price,
  12967. WarehousingDetailId: 0,
  12968. WarehouseOutDetailId: 0,
  12969. CancelOutDetailId: 0,
  12970. ExpireDate: info.ExpiryDate,
  12971. ProductDate: info.ProductDate,
  12972. MaxUnit: info.CountUnit,
  12973. MinUnit: "",
  12974. }
  12975. service.CreatedCancelStock(cancelStockInfo)
  12976. service.CreateDrugFlowOne(flow)
  12977. }
  12978. }
  12979. }
  12980. return err
  12981. }
  12982. func (this *HisApiController) DeleteNCDS() {
  12983. id, _ := this.GetInt64("id", 0)
  12984. if id > 0 {
  12985. service.DeletePsnNCDSRecordById(id)
  12986. this.ServeSuccessJSON(map[string]interface{}{
  12987. "msg": "删除成功",
  12988. })
  12989. } else {
  12990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12991. return
  12992. }
  12993. }
  12994. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12995. id, _ := c.GetInt64("id")
  12996. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12997. c.ServeSuccessJSON(map[string]interface{}{
  12998. "advice": advice,
  12999. })
  13000. return
  13001. }
  13002. func (c *HisApiController) GetHisMonthChargePatientList() {
  13003. record_date := c.GetString("record_date")
  13004. start_time := c.GetString("start_time")
  13005. end_time := c.GetString("end_time")
  13006. timeLayout := "2006-01-02"
  13007. loc, _ := time.LoadLocation("Local")
  13008. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13009. if err != nil {
  13010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13011. return
  13012. }
  13013. if err != nil {
  13014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13015. return
  13016. }
  13017. recordDateTime := theTime.Unix()
  13018. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13019. if err != nil {
  13020. }
  13021. startRecordDateTime := startTime.Unix()
  13022. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13023. if err != nil {
  13024. }
  13025. endRecordDateTime := endTime.Unix()
  13026. adminInfo := c.GetAdminUserInfo()
  13027. var tempMonthChargePatients []*service.MonthChargePatients
  13028. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13029. for _, item := range tempPatients {
  13030. //过滤没有处方的
  13031. if len(item.HisPrescription) == 0 {
  13032. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13033. }
  13034. }
  13035. c.ServeSuccessJSON(map[string]interface{}{
  13036. "list": tempMonthChargePatients,
  13037. })
  13038. }
  13039. // PrescriptionDifference 医嘱数量差值结构体
  13040. type PrescriptionDrugDifference struct {
  13041. DrugID int64 //基础库药品id
  13042. ID int64 //医嘱id
  13043. Difference float64 //差值
  13044. Unit string //单位
  13045. }
  13046. type PrescriptionGoodDifference struct {
  13047. GoodID int64 //基础库项目耗材id
  13048. ID int64 //医嘱id
  13049. Difference int64 //差值
  13050. Unit string //单位
  13051. Type int64 //类型
  13052. }
  13053. type EditCustomData struct {
  13054. adviceList []*models.HisDoctorAdviceInfo
  13055. projectList []*models.HisPrescriptionProject
  13056. }
  13057. type SrcCustomData struct {
  13058. adviceList []*models.HisDoctorAdviceInfo
  13059. projectList []*models.HisPrescriptionProject
  13060. }
  13061. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13062. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13063. differences := make([]*PrescriptionDrugDifference, 0)
  13064. // 创建一个 map 来存储第一个切片中的药品信息
  13065. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13066. for _, advice := range firstPrescription {
  13067. firstMap[advice.DrugId] = advice
  13068. }
  13069. // 遍历第二个切片中的药品信息,并比较数量差值
  13070. for _, advice := range secondPrescription {
  13071. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13072. diff := &PrescriptionDrugDifference{
  13073. DrugID: advice.DrugId,
  13074. ID: firstAdvice.ID,
  13075. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13076. Unit: firstAdvice.PrescribingNumberUnit,
  13077. }
  13078. differences = append(differences, diff)
  13079. }
  13080. }
  13081. return differences
  13082. }
  13083. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13084. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13085. differences := make([]*PrescriptionGoodDifference, 0)
  13086. // 创建一个 map 来存储第一个切片中的耗材信息
  13087. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13088. for _, good := range firstPrescription {
  13089. firstMap[good.ProjectId] = good
  13090. }
  13091. // 遍历第二个切片中的耗材信息,并比较数量差值
  13092. for _, good := range secondPrescription {
  13093. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13094. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13095. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13096. diff := &PrescriptionGoodDifference{
  13097. GoodID: good.ProjectId,
  13098. ID: firstGood.ID,
  13099. Difference: count - firstCount,
  13100. Unit: firstGood.Unit,
  13101. Type: firstGood.Type,
  13102. }
  13103. differences = append(differences, diff)
  13104. }
  13105. }
  13106. return differences
  13107. }
  13108. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13109. var adviceList []*models.HisDoctorAdviceInfo
  13110. var projectList []*models.HisPrescriptionProject
  13111. var advice_ids []int64
  13112. var project_ids []int64
  13113. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13114. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13115. //var tempPrescription *models.HisPrescriptionProjectscription
  13116. if len(prescriptions) > 0 {
  13117. for _, item := range prescriptions {
  13118. items := item.(map[string]interface{})
  13119. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13120. advices := items["advices"].([]interface{})
  13121. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13122. groupNo := int64(0)
  13123. ctime := time.Now().Unix()
  13124. mtime := ctime
  13125. if len(advices) > 0 {
  13126. for _, advice := range advices {
  13127. var s models.HisDoctorAdviceInfo
  13128. s.AdviceType = 2
  13129. s.StopState = 2
  13130. s.ExecutionState = 2
  13131. s.Status = 1
  13132. s.Groupno = groupNo
  13133. s.CreatedTime = ctime
  13134. s.UpdatedTime = mtime
  13135. s.IsSettle = 2
  13136. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13137. //存储切片中
  13138. if s.ID > 0 {
  13139. advice_ids = append(advice_ids, s.ID)
  13140. adviceList = append(adviceList, &s)
  13141. }
  13142. }
  13143. }
  13144. }
  13145. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13146. projects := items["project"].([]interface{})
  13147. if len(projects) > 0 {
  13148. for _, project := range projects {
  13149. var p models.HisPrescriptionProject
  13150. p.Ctime = time.Now().Unix()
  13151. p.Mtime = time.Now().Unix()
  13152. p.Status = 1
  13153. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13154. if p.ID > 0 {
  13155. project_ids = append(project_ids, p.ID)
  13156. projectList = append(projectList, &p)
  13157. }
  13158. }
  13159. }
  13160. }
  13161. }
  13162. }
  13163. }
  13164. editCustomData.projectList = projectList
  13165. editCustomData.adviceList = adviceList
  13166. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13167. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13168. srcCustomData.adviceList = list
  13169. srcCustomData.projectList = list2
  13170. return
  13171. }
  13172. func (c *HisApiController) GetAllGoodInforList() {
  13173. orgId := c.GetAdminUserInfo().CurrentOrgId
  13174. goodList, _ := service.GetAllGoodList(orgId)
  13175. c.ServeSuccessJSON(map[string]interface{}{
  13176. "goodList": goodList,
  13177. })
  13178. return
  13179. }
  13180. func (this *HisApiController) SaveGoodList() {
  13181. project_name := this.GetString("project_name")
  13182. sort, _ := this.GetInt64("sort")
  13183. orgId := this.GetAdminUserInfo().CurrentOrgId
  13184. dataBody := make(map[string]interface{}, 0)
  13185. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13186. if err != nil {
  13187. utils.ErrorLog(err.Error())
  13188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13189. return
  13190. }
  13191. goodTeam := models.XtGoodTeam{
  13192. ProjectName: project_name,
  13193. Sort: sort,
  13194. UserOrgId: orgId,
  13195. Status: 1,
  13196. Ctime: time.Now().Unix(),
  13197. Mtime: time.Now().Unix(),
  13198. }
  13199. service.CreateGoodTeam(goodTeam)
  13200. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13201. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13202. infos, _ := dataBody["info"].([]interface{})
  13203. if len(infos) > 0 {
  13204. for _, item := range infos {
  13205. items := item.(map[string]interface{})
  13206. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13207. utils.ErrorLog("good_id")
  13208. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13209. return
  13210. }
  13211. good_id := int64(items["good_id"].(float64))
  13212. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13213. utils.ErrorLog("number")
  13214. }
  13215. number := int64(items["number"].(float64))
  13216. xtGoodTeamList := models.XtGoodTeamList{
  13217. GoodId: good_id,
  13218. Count: number,
  13219. TeamId: lastGoodTeam.ID,
  13220. UserOrgId: orgId,
  13221. Status: 1,
  13222. Ctime: time.Now().Unix(),
  13223. Mtime: time.Now().Unix(),
  13224. }
  13225. service.CreateGoodList(xtGoodTeamList)
  13226. }
  13227. this.ServeSuccessJSON(map[string]interface{}{
  13228. "lastGoodTeam": lastGoodTeam,
  13229. })
  13230. }
  13231. }
  13232. return
  13233. }
  13234. func (this *HisApiController) GetGoodList() {
  13235. orgId := this.GetAdminUserInfo().CurrentOrgId
  13236. limit, _ := this.GetInt64("limit")
  13237. page, _ := this.GetInt64("page")
  13238. keyword := this.GetString("keyword")
  13239. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13240. this.ServeSuccessJSON(map[string]interface{}{
  13241. "list": list,
  13242. "total": total,
  13243. })
  13244. }
  13245. func (this *HisApiController) GetGoodNameDetail() {
  13246. id, _ := this.GetInt64("id")
  13247. orgId := this.GetAdminUserInfo().CurrentOrgId
  13248. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13249. goodList, _ := service.GetAllGoodList(orgId)
  13250. this.ServeSuccessJSON(map[string]interface{}{
  13251. "goodNameDetail": goodNameDetail,
  13252. "goodList": goodList,
  13253. })
  13254. }
  13255. func (this *HisApiController) UpdateGoodList() {
  13256. project_name := this.GetString("project_name")
  13257. sort, _ := this.GetInt64("sort")
  13258. id, _ := this.GetInt64("id")
  13259. orgId := this.GetAdminUserInfo().CurrentOrgId
  13260. dataBody := make(map[string]interface{}, 0)
  13261. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13262. if err != nil {
  13263. utils.ErrorLog(err.Error())
  13264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13265. return
  13266. }
  13267. goodTeam := models.XtGoodTeam{
  13268. ProjectName: project_name,
  13269. Sort: sort,
  13270. UserOrgId: orgId,
  13271. Status: 1,
  13272. Ctime: time.Now().Unix(),
  13273. Mtime: time.Now().Unix(),
  13274. ID: id,
  13275. }
  13276. service.SaveGoodTeam(goodTeam)
  13277. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13278. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13279. infos, _ := dataBody["info"].([]interface{})
  13280. if len(infos) > 0 {
  13281. for _, item := range infos {
  13282. items := item.(map[string]interface{})
  13283. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13284. utils.ErrorLog("good_id")
  13285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13286. return
  13287. }
  13288. good_id := int64(items["good_id"].(float64))
  13289. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13290. utils.ErrorLog("id")
  13291. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13292. return
  13293. }
  13294. id := int64(items["id"].(float64))
  13295. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13296. utils.ErrorLog("number")
  13297. }
  13298. number := int64(items["number"].(float64))
  13299. xtGoodTeamList := models.XtGoodTeamList{
  13300. ID: id,
  13301. GoodId: good_id,
  13302. Count: number,
  13303. TeamId: lastGoodTeam.ID,
  13304. UserOrgId: orgId,
  13305. Status: 1,
  13306. Ctime: time.Now().Unix(),
  13307. Mtime: time.Now().Unix(),
  13308. }
  13309. service.SaveGoodList(xtGoodTeamList)
  13310. }
  13311. this.ServeSuccessJSON(map[string]interface{}{
  13312. "lastGoodTeam": lastGoodTeam,
  13313. })
  13314. }
  13315. }
  13316. return
  13317. }
  13318. func (this *HisApiController) DeleteGoodTeam() {
  13319. id, _ := this.GetInt64("id")
  13320. team, _ := service.DeleteGoodTeam(id)
  13321. this.ServeSuccessJSON(map[string]interface{}{
  13322. "team": team,
  13323. })
  13324. }
  13325. func (this *HisApiController) DeleteGood() {
  13326. id, _ := this.GetInt64("id")
  13327. good, _ := service.DeleteGood(id)
  13328. this.ServeSuccessJSON(map[string]interface{}{
  13329. "good": good,
  13330. })
  13331. }