his_api_controller.go 601KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "card_desc":
  229. order.CardDesc = desc
  230. break
  231. case "band_card_pay":
  232. order.BandCardPay = desc
  233. break
  234. case "ali_pay":
  235. order.AliPay = desc
  236. break
  237. case "wechat_pay":
  238. order.WechatPay = desc
  239. break
  240. case "fa_piao_number":
  241. order.FaPiaoNumber = desc
  242. break
  243. case "fa_piao_code":
  244. order.FaPiaoCode = desc
  245. break
  246. }
  247. err := service.SaveHisOrder(&order)
  248. if err == nil {
  249. c.ServeSuccessJSON(map[string]interface{}{
  250. "msg": "修改成功",
  251. })
  252. return
  253. } else {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  255. return
  256. }
  257. }
  258. func (c *HisApiController) GetMonthHisPatient() {
  259. record_date := c.GetString("record_date")
  260. //order_status, _ := c.GetInt64("type")
  261. timeLayout := "2006-01-02"
  262. loc, _ := time.LoadLocation("Local")
  263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  264. if err != nil {
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. recordDateTime := theTime.Unix()
  269. adminInfo := c.GetAdminUserInfo()
  270. var tempPatients []service.NewTempPatients
  271. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  272. // 获取当前时间
  273. now := time.Now()
  274. // 获取本月的第一天
  275. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  276. // 获取下个月的第一天
  277. nextMonth := firstDay.AddDate(0, 1, 0)
  278. // 获取本月的最后一天
  279. lastDay := nextMonth.Add(-time.Nanosecond)
  280. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  281. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  282. var patients []service.NewTempPatients
  283. var patients_two []service.NewTempPatients
  284. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. patients_two = append(patients_two, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. //}
  294. }
  295. } else {
  296. for _, item := range tempPatients {
  297. //过滤掉没挂号的和没开处方的
  298. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  299. patients = append(patients, item)
  300. }
  301. ////过滤掉没挂号的
  302. //if len(item.HisPatient) > 0 {
  303. // patients_two = append(patients_two, item)
  304. //}
  305. }
  306. }
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "list": patients,
  309. "list_two": patients_two,
  310. "chargePatients": chargePatients,
  311. })
  312. }
  313. func (c *HisApiController) GetBatchSettleAccounts() {
  314. order_ids := c.GetString("order_ids")
  315. admin_user_id, _ := c.GetInt64("admin_user_id")
  316. adminUser := c.GetAdminUserInfo()
  317. orders := strings.Split(order_ids, ",")
  318. var newOrders []models.Orders
  319. for _, item := range orders {
  320. order, _ := service.GetHisOrderByIDTenOne(item)
  321. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  322. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  323. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  324. orderInfos = append(orderInfos, orderInfos_two...)
  325. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  326. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  327. var diagnosis_ids []string
  328. if his.ID > 0 {
  329. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  330. } else {
  331. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  332. }
  333. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  334. var dia_config []*models.HisXtDiagnoseConfig
  335. var name string
  336. for _, item := range diagnosis_ids {
  337. id, _ := strconv.ParseInt(item, 10, 64)
  338. diagnosisConfig, _ := service.FindDiagnoseById(id)
  339. dia_config = append(dia_config, diagnosisConfig)
  340. if len(name) == 0 {
  341. name = diagnosisConfig.ClassName
  342. } else {
  343. name = name + "," + diagnosisConfig.ClassName
  344. }
  345. }
  346. var bedCostTotal float64 = 0 //床位总费
  347. var bedCostSelfTotal float64 = 0 //床位自费
  348. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  349. var bedSelfTotal float64 = 0 //床位部分项目自费
  350. var bedInscpTotal float64 = 0 //床位部分项目自费
  351. var operationCostTotal float64 = 0 //手术费
  352. var operationCostSelfTotal float64 = 0 //手术费
  353. var operationCostPartSelfTotal float64 = 0 //手术费
  354. var operationSelfTotal float64 = 0 //床位部分项目自费
  355. var operationInscpTotal float64 = 0 //床位部分项目自费
  356. var otherCostTotal float64 = 0 //其他费用
  357. var otherCostSelfTotal float64 = 0 //其他费用
  358. var otherCostPartSelfTotal float64 = 0 //其他费用
  359. var otherSelfTotal float64 = 0 //床位部分项目自费
  360. var otherInscpTotal float64 = 0 //床位部分项目自费
  361. var materialCostTotal float64 = 0 //材料费
  362. var materialCostSelfTotal float64 = 0 //材料费
  363. var materialCostPartSelfTotal float64 = 0 //材料费
  364. var materialSelfTotal float64 = 0 //床位部分项目自费
  365. var materialInscpTotal float64 = 0 //床位部分项目自费
  366. var westernMedicineCostTotal float64 = 0 //西药费
  367. var westernMedicineCostSelfTotal float64 = 0 //西药费
  368. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  369. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  370. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  371. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  372. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  373. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  374. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  375. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  376. var checkCostTotal float64 = 0 //检查费
  377. var checkCostSelfTotal float64 = 0 //检查费
  378. var checkCostPartSelfTotal float64 = 0 //检查费
  379. var checkSelfTotal float64 = 0 //床位部分项目自费
  380. var checkInscpTotal float64 = 0 //床位部分项目自费
  381. var laboratoryCostTotal float64 = 0 //化验费
  382. var laboratoryCostSelfTotal float64 = 0 //化验费
  383. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  384. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  385. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  386. var treatCostTotal float64 = 0 //治疗费用
  387. var treatCostSelfTotal float64 = 0 //治疗费用
  388. var treatCostPartSelfTotal float64 = 0 //治疗费用
  389. var treatSelfTotal float64 = 0 //床位部分项目自费
  390. var treatInscpTotal float64 = 0 //床位部分项目自费
  391. decimal.DivisionPrecision = 2
  392. for _, item := range orderInfos {
  393. if item.MedChrgitmType == "01" { //床位费
  394. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  395. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  396. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  397. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  398. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  399. }
  400. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  401. if item.MedChrgitmType == "03" { //检查费
  402. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  403. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  404. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  405. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  406. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  407. }
  408. } else {
  409. if item.MedChrgitmType == "03" { //检查费
  410. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  411. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  412. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  413. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  414. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  415. }
  416. }
  417. if item.MedChrgitmType == "04" { //化验费
  418. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  419. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  420. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  421. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  422. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  423. }
  424. if item.MedChrgitmType == "05" { //治疗费
  425. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  426. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  427. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  428. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  429. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  430. }
  431. if item.MedChrgitmType == "06" { //手术费
  432. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  433. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  434. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  435. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  436. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  437. }
  438. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  439. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  440. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  441. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  442. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  443. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  444. }
  445. if item.MedChrgitmType == "09" { //西药费
  446. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  447. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  448. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  449. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  450. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  451. }
  452. if item.MedChrgitmType == "11" { //中成费
  453. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  454. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  455. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  456. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  457. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  458. }
  459. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  461. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  462. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  463. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  464. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  465. }
  466. }
  467. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  468. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  470. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  471. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  472. var doctor_name string
  473. if roles.ID == 0 {
  474. doctor_name = "管理员"
  475. } else {
  476. doctor_name = roles.UserName
  477. }
  478. yiliao_leibie := ""
  479. switch order.MedType {
  480. case "11":
  481. yiliao_leibie = "普通门诊"
  482. break
  483. case "12":
  484. yiliao_leibie = "门诊挂号"
  485. break
  486. case "13":
  487. yiliao_leibie = "急诊"
  488. break
  489. case "14":
  490. yiliao_leibie = "门诊特殊病"
  491. break
  492. case "15":
  493. yiliao_leibie = "门诊统筹"
  494. break
  495. case "16":
  496. yiliao_leibie = "门诊慢性病"
  497. break
  498. case "21":
  499. yiliao_leibie = "普通住院"
  500. break
  501. }
  502. var newOrder models.Orders
  503. newOrder.Diagnosis = name
  504. newOrder.OrderInfos = orderInfos
  505. newOrder.Number = order.MdtrtId
  506. newOrder.Date = order.SettleAccountsDate
  507. newOrder.ChargeAdmin = charge_admin
  508. newOrder.PrintorAdmin = printor_admin
  509. newOrder.Order = order
  510. newOrder.BedCostTotal = bedCostTotal
  511. newOrder.BedCostSelfTotal = bedCostSelfTotal
  512. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  513. newOrder.BedSelfTotal = bedSelfTotal
  514. newOrder.BedInscpTotal = bedInscpTotal
  515. newOrder.OperationCostTotal = operationCostTotal
  516. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  517. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  518. newOrder.OperationSelfTotal = operationSelfTotal
  519. newOrder.OperationInscpTotal = operationInscpTotal
  520. newOrder.OtherCostTotal = otherCostTotal
  521. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  522. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  523. newOrder.OtherSelfTotal = otherSelfTotal
  524. newOrder.OtherInscpTotal = otherInscpTotal
  525. newOrder.MaterialCostTotal = materialCostTotal
  526. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  527. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  528. newOrder.MaterialSelfTotal = materialSelfTotal
  529. newOrder.MaterialInscpTotal = materialInscpTotal
  530. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  531. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  532. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  533. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  534. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  535. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  536. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  537. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  538. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  539. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  540. newOrder.CheckCostTotal = checkCostTotal
  541. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  542. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  543. newOrder.CheckSelfTotal = checkSelfTotal
  544. newOrder.CheckInscpTotal = checkInscpTotal
  545. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  546. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  547. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  548. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  549. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  550. newOrder.TreatCostTotal = treatCostTotal
  551. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  552. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  553. newOrder.TreatSelfTotal = treatSelfTotal
  554. newOrder.TreatInscpTotal = treatInscpTotal
  555. newOrder.DoctorInfo = doctor_info
  556. newOrder.DoctorName = doctor_name
  557. newOrder.HealthCardNo = order.PsnNo
  558. newOrder.YiliaoLeibie = yiliao_leibie
  559. newOrder.Patient = patient
  560. newOrder.OrgName = miConfig.OrgName
  561. newOrder.OrgCode = miConfig.Code
  562. newOrder.OrderNumber = order.Number
  563. newOrder.HisPatient = his
  564. newOrder.DiaConfig = dia_config
  565. newOrders = append(newOrders, newOrder)
  566. }
  567. c.ServeSuccessJSON(map[string]interface{}{
  568. "orders": newOrders,
  569. })
  570. }
  571. func (c *HisApiController) GetTestOrder() {
  572. order_id, _ := c.GetInt64("order_id")
  573. admin_user_id, _ := c.GetInt64("admin_user_id")
  574. adminUser := c.GetAdminUserInfo()
  575. order, _ := service.GetHisOrderByID(order_id)
  576. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  577. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  578. orderInfos = append(orderInfos, orderInfos_two...)
  579. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  580. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  581. var dia_config []*models.HisXtDiagnoseConfig
  582. var name string
  583. var bedCostTotal float64 = 0 //床位总费
  584. var bedCostSelfTotal float64 = 0 //床位自费
  585. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  586. var bedSelfTotal float64 = 0 //床位部分项目自费
  587. var bedInscpTotal float64 = 0 //床位部分项目自费
  588. var operationCostTotal float64 = 0 //手术费
  589. var operationCostSelfTotal float64 = 0 //手术费
  590. var operationCostPartSelfTotal float64 = 0 //手术费
  591. var operationSelfTotal float64 = 0 //床位部分项目自费
  592. var operationInscpTotal float64 = 0 //床位部分项目自费
  593. var otherCostTotal float64 = 0 //其他费用
  594. var otherCostSelfTotal float64 = 0 //其他费用
  595. var otherCostPartSelfTotal float64 = 0 //其他费用
  596. var otherSelfTotal float64 = 0 //床位部分项目自费
  597. var otherInscpTotal float64 = 0 //床位部分项目自费
  598. var materialCostTotal float64 = 0 //材料费
  599. var materialCostSelfTotal float64 = 0 //材料费
  600. var materialCostPartSelfTotal float64 = 0 //材料费
  601. var materialSelfTotal float64 = 0 //床位部分项目自费
  602. var materialInscpTotal float64 = 0 //床位部分项目自费
  603. var westernMedicineCostTotal float64 = 0 //西药费
  604. var westernMedicineCostSelfTotal float64 = 0 //西药费
  605. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  606. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  607. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  608. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  609. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  610. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  611. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  612. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  613. var checkCostTotal float64 = 0 //检查费
  614. var checkCostSelfTotal float64 = 0 //检查费
  615. var checkCostPartSelfTotal float64 = 0 //检查费
  616. var checkSelfTotal float64 = 0 //床位部分项目自费
  617. var checkInscpTotal float64 = 0 //床位部分项目自费
  618. var laboratoryCostTotal float64 = 0 //化验费
  619. var laboratoryCostSelfTotal float64 = 0 //化验费
  620. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  621. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  622. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  623. var treatCostTotal float64 = 0 //治疗费用
  624. var treatCostSelfTotal float64 = 0 //治疗费用
  625. var treatCostPartSelfTotal float64 = 0 //治疗费用
  626. var treatSelfTotal float64 = 0 //床位部分项目自费
  627. var treatInscpTotal float64 = 0 //床位部分项目自费
  628. decimal.DivisionPrecision = 2
  629. for _, item := range orderInfos {
  630. if item.MedChrgitmType == "01" { //床位费
  631. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  632. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  633. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  634. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  635. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  636. }
  637. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  638. if item.MedChrgitmType == "03" { //检查费
  639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  640. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  641. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  642. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  643. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  644. }
  645. } else {
  646. if item.MedChrgitmType == "03" { //检查费
  647. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  648. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  649. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  650. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  651. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  652. }
  653. }
  654. if item.MedChrgitmType == "04" { //化验费
  655. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  656. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  657. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  658. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  659. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  660. }
  661. if item.MedChrgitmType == "05" { //治疗费
  662. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  663. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  664. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  665. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  666. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  667. }
  668. if item.MedChrgitmType == "06" { //手术费
  669. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  670. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  671. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  672. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  673. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  674. }
  675. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  676. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  677. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  678. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  679. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  680. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  681. }
  682. if item.MedChrgitmType == "09" { //西药费
  683. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  684. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  685. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  686. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  687. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  688. }
  689. if item.MedChrgitmType == "11" { //中成费
  690. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  691. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  692. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  693. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  694. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  695. }
  696. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  698. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  699. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  700. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  701. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  702. }
  703. }
  704. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  705. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  707. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  708. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  709. var doctor_name string
  710. if roles.ID == 0 {
  711. doctor_name = "管理员"
  712. } else {
  713. doctor_name = roles.UserName
  714. }
  715. yiliao_leibie := ""
  716. switch order.MedType {
  717. case "11":
  718. yiliao_leibie = "普通门诊"
  719. break
  720. case "12":
  721. yiliao_leibie = "门诊挂号"
  722. break
  723. case "13":
  724. yiliao_leibie = "急诊"
  725. break
  726. case "14":
  727. yiliao_leibie = "门诊特殊病"
  728. break
  729. case "15":
  730. yiliao_leibie = "门诊统筹"
  731. break
  732. case "16":
  733. yiliao_leibie = "门诊慢性病"
  734. break
  735. case "21":
  736. yiliao_leibie = "普通住院"
  737. break
  738. }
  739. c.ServeSuccessJSON(map[string]interface{}{
  740. "diagnosis": name,
  741. "order_infos": orderInfos,
  742. "number": order.MdtrtId,
  743. "date": order.SettleAccountsDate,
  744. "charge_admin": charge_admin,
  745. "printor_admin": printor_admin,
  746. "info": order,
  747. "order": order,
  748. "bedCostTotal": bedCostTotal,
  749. "bedCostSelfTotal": bedCostSelfTotal,
  750. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  751. "bedSelfTotal": bedSelfTotal,
  752. "bedInscpTotal": bedInscpTotal,
  753. "operationCostTotal": operationCostTotal,
  754. "operationCostSelfTotal": operationCostSelfTotal,
  755. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  756. "operationSelfTotal": operationSelfTotal,
  757. "operationInscpTotal": operationInscpTotal,
  758. "otherCostTotal": otherCostTotal,
  759. "otherCostSelfTotal": otherCostSelfTotal,
  760. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  761. "otherSelfTotal": otherSelfTotal,
  762. "otherInscpTotal": otherInscpTotal,
  763. "materialCostTotal": materialCostTotal,
  764. "materialCostSelfTotal": materialCostSelfTotal,
  765. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  766. "materialSelfTotal": materialSelfTotal,
  767. "materialInscpTotal": materialInscpTotal,
  768. "westernMedicineCostTotal": westernMedicineCostTotal,
  769. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  770. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  771. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  772. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  773. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  774. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  775. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  776. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  777. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  778. "checkCostTotal": checkCostTotal,
  779. "checkCostSelfTotal": checkCostSelfTotal,
  780. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  781. "checkSelfTotal": checkSelfTotal,
  782. "checkInscpTotal": checkInscpTotal,
  783. "laboratoryCostTotal": laboratoryCostTotal,
  784. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  785. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  786. "laboratorySelfTotal": laboratorySelfTotal,
  787. "laboratoryInscpTotal": laboratoryInscpTotal,
  788. "treatCostTotal": treatCostTotal,
  789. "treatCostSelfTotal": treatCostSelfTotal,
  790. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  791. "treatSelfTotal": treatSelfTotal,
  792. "treatInscpTotal": treatInscpTotal,
  793. "doctor_info": doctor_info,
  794. "doctor_name": doctor_name,
  795. "health_card_no": order.PsnNo,
  796. "yiliao_leibie": yiliao_leibie,
  797. "patient": patient,
  798. "org_name": miConfig.OrgName,
  799. "org_code": miConfig.Code,
  800. "order_number": order.Number,
  801. "his_hospital": his_hospital,
  802. "dia_config": dia_config,
  803. })
  804. }
  805. type CustomFundPay struct {
  806. FundPayType string `json:"fund_pay_type"`
  807. FundPayamt float64 `json:"fund_payamt"`
  808. InscpScpAmt float64 `json:"inscp_scp_amt"`
  809. }
  810. func (c *PublicApiController) GetBaiLinExportData() {
  811. data := service.GetBaiLinOrderData()
  812. fmt.Println(len(data))
  813. var new_data []*models.NewCustomHisOrder
  814. for _, item := range data {
  815. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  816. new_data = append(new_data, item)
  817. }
  818. }
  819. fmt.Println(len(new_data))
  820. c.ServeSuccessJSON(map[string]interface{}{
  821. "list": new_data,
  822. })
  823. }
  824. func (c *HisApiController) GetHisUnChargePatientList() {
  825. record_date := c.GetString("record_date")
  826. sch_type, _ := c.GetInt64("sch_type")
  827. timeLayout := "2006-01-02"
  828. loc, _ := time.LoadLocation("Local")
  829. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  830. if err != nil {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. recordDateTime := theTime.Unix()
  835. adminInfo := c.GetAdminUserInfo()
  836. var tempPatients []*service.NewTempPatients
  837. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  838. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  839. var patients []*service.NewTempPatients
  840. var patients_two []*service.NewTempPatients
  841. for _, item := range tempPatients {
  842. //过滤掉没挂号的和没开处方的
  843. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  844. patients = append(patients, item)
  845. }
  846. //过滤掉没挂号的
  847. if len(item.HisPatient) > 0 {
  848. patients_two = append(patients_two, item)
  849. }
  850. }
  851. c.ServeSuccessJSON(map[string]interface{}{
  852. "list": patients,
  853. "list_two": patients_two,
  854. })
  855. }
  856. func (c *HisApiController) GetPrivateExpensesOrder() {
  857. //id, _ := c.GetInt64("id")
  858. //record_time := c.GetString("record_time")
  859. order_id, _ := c.GetInt64("order_id")
  860. admin_user_id, _ := c.GetInt64("admin_user_id")
  861. //timeLayout := "2006-01-02"
  862. //loc, _ := time.LoadLocation("Local")
  863. //
  864. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  865. //if err != nil {
  866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. // return
  868. //}
  869. //recordDateTime := theTime.Unix()
  870. adminUser := c.GetAdminUserInfo()
  871. order, _ := service.GetHisOrderByID(order_id)
  872. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  873. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  874. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  875. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  876. //var config []*models.HisXtDiagnoseConfig
  877. var name string
  878. if order.PType == 1 {
  879. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  880. for _, item := range diagnosis_ids {
  881. id, _ := strconv.ParseInt(item, 10, 64)
  882. diagnosisConfig, _ := service.FindDiagnoseById(id)
  883. if len(name) == 0 {
  884. name = diagnosisConfig.ClassName
  885. } else {
  886. name = name + "," + diagnosisConfig.ClassName
  887. }
  888. }
  889. } else {
  890. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  891. for _, item := range diagnosis_ids {
  892. id, _ := strconv.ParseInt(item, 10, 64)
  893. diagnosisConfig, _ := service.FindDiagnoseById(id)
  894. if len(name) == 0 {
  895. name = diagnosisConfig.ClassName
  896. } else {
  897. name = name + "," + diagnosisConfig.ClassName
  898. }
  899. }
  900. }
  901. var bedCostTotal float64 = 0 //床位总费
  902. var bedCostSelfTotal float64 = 0 //床位自费
  903. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  904. var bedSelfTotal float64 = 0 //床位部分项目自费
  905. var bedInscpTotal float64 = 0 //床位部分项目自费
  906. var operationCostTotal float64 = 0 //手术费
  907. var operationCostSelfTotal float64 = 0 //手术费
  908. var operationCostPartSelfTotal float64 = 0 //手术费
  909. var operationSelfTotal float64 = 0 //床位部分项目自费
  910. var operationInscpTotal float64 = 0 //床位部分项目自费
  911. var otherCostTotal float64 = 0 //其他费用
  912. //var otherCostSelfTotal float64 = 0 //其他费用
  913. var otherCostPartSelfTotal float64 = 0 //其他费用
  914. //var otherSelfTotal float64 = 0 //床位部分项目自费
  915. //var otherInscpTotal float64 = 0 //床位部分项目自费
  916. var materialCostTotal float64 = 0 //材料费
  917. var materialCostSelfTotal float64 = 0 //材料费
  918. var materialCostPartSelfTotal float64 = 0 //材料费
  919. var materialSelfTotal float64 = 0 //床位部分项目自费
  920. var materialInscpTotal float64 = 0 //床位部分项目自费
  921. var westernMedicineCostTotal float64 = 0 //西药费
  922. var westernMedicineCostSelfTotal float64 = 0 //西药费
  923. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  924. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  925. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  926. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  927. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  928. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  929. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  930. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  931. var checkCostTotal float64 = 0 //检查费
  932. var checkCostSelfTotal float64 = 0 //检查费
  933. var checkCostPartSelfTotal float64 = 0 //检查费
  934. var checkSelfTotal float64 = 0 //床位部分项目自费
  935. var checkInscpTotal float64 = 0 //床位部分项目自费
  936. var laboratoryCostTotal float64 = 0 //化验费
  937. var laboratoryCostSelfTotal float64 = 0 //化验费
  938. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  939. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  940. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  941. var treatCostTotal float64 = 0 //治疗费用
  942. var treatCostSelfTotal float64 = 0 //治疗费用
  943. var treatCostPartSelfTotal float64 = 0 //治疗费用
  944. var treatSelfTotal float64 = 0 //床位部分项目自费
  945. var treatInscpTotal float64 = 0 //床位部分项目自费
  946. var zhenChaCostTotal float64 = 0 //其他费用
  947. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  948. decimal.DivisionPrecision = 2
  949. for _, item := range orderInfos {
  950. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  951. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  952. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  953. item.MedChrgitmType = "09"
  954. }
  955. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  956. if item.HisPrescriptionProject.Type == 2 {
  957. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  958. fmt.Println("CostClassify")
  959. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  960. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  961. case 0:
  962. item.MedChrgitmType = "0"
  963. break
  964. case 1:
  965. item.MedChrgitmType = "14"
  966. break
  967. case 2:
  968. item.MedChrgitmType = "05"
  969. break
  970. case 3:
  971. item.MedChrgitmType = "03"
  972. break
  973. case 4:
  974. item.MedChrgitmType = "03"
  975. break
  976. case 5:
  977. item.MedChrgitmType = "08"
  978. break
  979. case 6:
  980. item.MedChrgitmType = "14"
  981. break
  982. case 7:
  983. item.MedChrgitmType = "14"
  984. break
  985. case 8:
  986. item.MedChrgitmType = "03"
  987. break
  988. case 9:
  989. item.MedChrgitmType = "14"
  990. break
  991. case 10:
  992. item.MedChrgitmType = "14"
  993. break
  994. case 11:
  995. item.MedChrgitmType = "06"
  996. break
  997. case 12:
  998. item.MedChrgitmType = "12"
  999. break
  1000. case 13:
  1001. item.MedChrgitmType = "01"
  1002. break
  1003. case 14:
  1004. item.MedChrgitmType = "04"
  1005. break
  1006. case 15:
  1007. item.MedChrgitmType = "14"
  1008. break
  1009. }
  1010. } else {
  1011. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1012. case 1:
  1013. item.MedChrgitmType = "14"
  1014. break
  1015. case 2:
  1016. item.MedChrgitmType = "05"
  1017. break
  1018. case 3:
  1019. item.MedChrgitmType = "04"
  1020. break
  1021. case 4:
  1022. item.MedChrgitmType = "14"
  1023. break
  1024. case 5:
  1025. item.MedChrgitmType = "08"
  1026. break
  1027. case 6:
  1028. item.MedChrgitmType = "14"
  1029. break
  1030. case 7:
  1031. item.MedChrgitmType = "14"
  1032. break
  1033. case 8:
  1034. item.MedChrgitmType = "03"
  1035. break
  1036. case 9:
  1037. item.MedChrgitmType = "14"
  1038. break
  1039. default:
  1040. item.MedChrgitmType = "14"
  1041. break
  1042. }
  1043. }
  1044. } else if item.HisPrescriptionProject.Type == 3 {
  1045. item.MedChrgitmType = "08"
  1046. }
  1047. }
  1048. }
  1049. }
  1050. if order.IsMedicineInsurance != 1 {
  1051. order.PsnCashPay = order.MedfeeSumamt
  1052. }
  1053. for _, item := range orderInfos {
  1054. if item.MedChrgitmType == "01" { //床位费
  1055. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1059. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "02" { //诊察费
  1062. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //zhenChaCostSelfTotal = zhenChaCostTotal
  1064. }
  1065. if item.MedChrgitmType == "03" { //检查费
  1066. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1070. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1071. }
  1072. if item.MedChrgitmType == "02" { //检查费
  1073. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1074. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1075. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1076. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1077. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1078. }
  1079. if item.MedChrgitmType == "04" { //化验费
  1080. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1081. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1082. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1083. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1084. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1085. }
  1086. if item.MedChrgitmType == "05" { //治疗费
  1087. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1088. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1089. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1090. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1091. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1092. }
  1093. if item.MedChrgitmType == "06" { //手术费
  1094. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1095. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1096. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1097. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1098. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1099. }
  1100. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1101. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1102. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1103. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1104. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1105. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1106. }
  1107. if item.MedChrgitmType == "09" { //西药费
  1108. fmt.Println("FulamtOwnpayAmt")
  1109. fmt.Println(item.FulamtOwnpayAmt)
  1110. fmt.Println("FulamtOwnpayAmt")
  1111. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1112. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1113. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1114. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1115. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1116. }
  1117. if item.MedChrgitmType == "11" { //中成费
  1118. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1119. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1120. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1121. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1122. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1123. }
  1124. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1125. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1126. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1127. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1128. }
  1129. }
  1130. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1131. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1132. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1133. var dia_config []*models.HisXtDiagnoseConfig
  1134. var diagnosis_ids []string
  1135. if his.ID > 0 {
  1136. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1137. } else {
  1138. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1139. }
  1140. for _, item := range diagnosis_ids {
  1141. id, _ := strconv.ParseInt(item, 10, 64)
  1142. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1143. dia_config = append(dia_config, diagnosisConfig)
  1144. }
  1145. var rf []CustomFundPay
  1146. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1147. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "patient": patient,
  1150. "order_infos": orderInfos,
  1151. "diagnosis": name,
  1152. "bedCostTotal": bedCostTotal,
  1153. "bedCostSelfTotal": bedCostSelfTotal,
  1154. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1155. "bedSelfTotal": bedSelfTotal,
  1156. "bedInscpTotal": bedInscpTotal,
  1157. "operationCostTotal": operationCostTotal,
  1158. "operationCostSelfTotal": operationCostSelfTotal,
  1159. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1160. "operationInscpTotal": operationInscpTotal,
  1161. "operationSelfTotal": operationSelfTotal,
  1162. "otherCostTotal": otherCostTotal,
  1163. //"otherCostSelfTotal": otherCostSelfTotal,
  1164. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1165. "materialCostTotal": materialCostTotal,
  1166. "materialCostSelfTotal": materialCostSelfTotal,
  1167. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1168. "materialSelfTotal": materialSelfTotal,
  1169. "materialInscpTotal": materialInscpTotal,
  1170. "westernMedicineCostTotal": westernMedicineCostTotal,
  1171. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1172. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1173. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1174. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1175. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1176. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1177. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1178. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1179. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1180. "checkCostTotal": checkCostTotal,
  1181. "checkCostSelfTotal": checkCostSelfTotal,
  1182. "checkSelfTotal": checkSelfTotal,
  1183. "checkInscpTotal": checkInscpTotal,
  1184. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1185. "zhenChaCostTotal": zhenChaCostTotal,
  1186. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1187. "laboratoryCostTotal": laboratoryCostTotal,
  1188. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1189. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1190. "laboratorySelfTotal": laboratorySelfTotal,
  1191. "laboratoryInscpTotal": laboratoryInscpTotal,
  1192. "treatCostTotal": treatCostTotal,
  1193. "treatCostSelfTotal": treatCostSelfTotal,
  1194. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1195. "treatSelfTotal": treatSelfTotal,
  1196. "treatInscpTotal": treatInscpTotal,
  1197. "charge_admin": charge_admin,
  1198. "printor_admin": printor_admin,
  1199. "org_name": org.OrgName,
  1200. "org_code": miConfig.Code,
  1201. "name": patient.Name,
  1202. "number": order.MdtrtId,
  1203. "date": order.SettleAccountsDate,
  1204. "info": order,
  1205. "new_order": order,
  1206. "his_hospital": his_hospital,
  1207. "his": his,
  1208. "funds": rf,
  1209. "dia_config": dia_config,
  1210. })
  1211. }
  1212. func (c *HisApiController) RefudDetail() {
  1213. order_id, _ := c.GetInt64("order_id")
  1214. order, _ := service.GetHisOrderByID(order_id)
  1215. adminUser := c.GetAdminUserInfo()
  1216. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1217. c.ServeSuccessJSON(map[string]interface{}{
  1218. "msg": "撤销成功",
  1219. })
  1220. }
  1221. func (c *HisApiController) Sscard() {
  1222. //r := CardInit()
  1223. //if r == 0 {
  1224. // GetBaseInfo()
  1225. //}
  1226. //c.ServeSuccessJSON(map[string]interface{}{
  1227. // "list": "11",
  1228. //})
  1229. }
  1230. func GetBaseInfo() error {
  1231. //handle := syscall.MustLoadDLL("SSCard.dll")
  1232. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1233. //
  1234. //str := make([]byte, 256)
  1235. //str1 := make([]byte, 256)
  1236. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1237. //if ferr != nil {
  1238. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1239. // return ferr
  1240. //}
  1241. //
  1242. //fmt.Println(string(str))
  1243. //
  1244. //fmt.Println(r)
  1245. return nil
  1246. }
  1247. func CardInit() int {
  1248. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1249. //add := DllTestDef.MustFindProc("Init")
  1250. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1251. //if err != nil {
  1252. // fmt.Println("SSCard的运算结果为:", ret)
  1253. //}
  1254. //result := int(ret)
  1255. return 0
  1256. }
  1257. func IntPtr(n int) uintptr {
  1258. return uintptr(n)
  1259. }
  1260. func StrPtr(s string) uintptr {
  1261. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1262. }
  1263. func (c *HisApiController) GetHisPatientList() {
  1264. record_date := c.GetString("record_date")
  1265. sch_type, _ := c.GetInt64("sch_type")
  1266. patient_type, _ := c.GetInt64("patient_type")
  1267. fmt.Println("patient_type")
  1268. fmt.Println(patient_type)
  1269. timeLayout := "2006-01-02"
  1270. loc, _ := time.LoadLocation("Local")
  1271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1272. if err != nil {
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1274. return
  1275. }
  1276. recordDateTime := theTime.Unix()
  1277. adminInfo := c.GetAdminUserInfo()
  1278. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1279. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1280. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1281. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1282. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1283. fmt.Println(patients_three)
  1284. //获取当前用户的信息
  1285. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1286. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1287. //获取所有科室信息
  1288. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1289. //var aa []service.PatientThree
  1290. noElementsSlice := make([]service.PatientThree, 0)
  1291. c.ServeSuccessJSON(map[string]interface{}{
  1292. "list": patients_three,
  1293. "list_two": patients_four,
  1294. "list_three": noElementsSlice,
  1295. "info": adminUserInfo,
  1296. "doctors": doctors,
  1297. "department": department,
  1298. })
  1299. } else {
  1300. //获取当前用户的信息
  1301. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1302. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1303. //获取所有科室信息
  1304. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1305. //var aa []service.PatientThree
  1306. noElementsSlice := make([]service.PatientThree, 0)
  1307. c.ServeSuccessJSON(map[string]interface{}{
  1308. "list": patients,
  1309. "list_two": patients_two,
  1310. "list_three": noElementsSlice,
  1311. "info": adminUserInfo,
  1312. "doctors": doctors,
  1313. "department": department,
  1314. })
  1315. }
  1316. }
  1317. type CustomTemplate struct {
  1318. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1319. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1320. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1321. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1322. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1323. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1324. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1325. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1326. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1327. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1328. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1329. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1330. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1331. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1332. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1333. }
  1334. func (c *HisApiController) GetHisPatientInfo() {
  1335. patient_id, _ := c.GetInt64("patient_id")
  1336. his_patient_id, _ := c.GetInt64("his_patient_id")
  1337. record_date := c.GetString("record_date")
  1338. number := c.GetString("number")
  1339. //start_time := c.GetString("start_time")
  1340. //end_time := c.GetString("end_time")
  1341. p_type, _ := c.GetInt64("p_type")
  1342. timeLayout := "2006-01-02"
  1343. loc, _ := time.LoadLocation("Local")
  1344. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1345. if err != nil {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1347. return
  1348. }
  1349. recordDateTime := theTime.Unix()
  1350. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1351. //if err != nil {
  1352. //
  1353. //}
  1354. //startRecordDateTime := startTime.Unix()
  1355. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1356. //if err != nil {
  1357. //
  1358. //}
  1359. //endRecordDateTime := endTime.Unix()
  1360. admin := c.GetAdminUserInfo()
  1361. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1362. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1363. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1364. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1365. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1366. var prescriptions []*models.HisPrescription
  1367. var last_prescriptions []*models.HisPrescription
  1368. var sch_prescriptions []CustomTemplate
  1369. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1370. if p_type == 1 { //住院
  1371. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1372. for _, item := range prescriptions {
  1373. for _, subItem := range item.HisDoctorAdviceInfo {
  1374. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1375. if info.RetailPrice > 0 {
  1376. subItem.Drug.MinPrice = info.RetailPrice
  1377. }
  1378. }
  1379. }
  1380. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1381. } else { //门诊
  1382. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1383. for _, item := range prescriptions {
  1384. for _, subItem := range item.HisDoctorAdviceInfo {
  1385. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1386. if info.RetailPrice > 0 {
  1387. subItem.Drug.MinPrice = info.RetailPrice
  1388. }
  1389. }
  1390. }
  1391. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1392. }
  1393. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1394. if sch.ID > 0 {
  1395. var week string
  1396. t := time.Now()
  1397. switch t.Weekday().String() {
  1398. case "Monday":
  1399. week = "周一"
  1400. break
  1401. case "Tuesday":
  1402. week = "周二"
  1403. break
  1404. case "Wednesday":
  1405. week = "周三"
  1406. break
  1407. case "Thursday":
  1408. week = "周四"
  1409. break
  1410. case "Friday":
  1411. week = "周五"
  1412. break
  1413. case "Saturday":
  1414. week = "周六"
  1415. break
  1416. case "Sunday":
  1417. week = "周日"
  1418. break
  1419. }
  1420. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1421. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1422. //根据推送频率组装新的数组
  1423. for _, item := range temp_sch_prescriptions {
  1424. var cus CustomTemplate
  1425. cus.ID = item.ID
  1426. cus.UserOrgId = item.UserOrgId
  1427. cus.PatientId = item.PatientId
  1428. cus.MedType = item.MedType
  1429. cus.RecordDate = item.RecordDate
  1430. cus.Type = item.Type
  1431. cus.PType = item.PType
  1432. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1433. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1434. if subItem.FrequencyType == 1 { //每次必推
  1435. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1436. }
  1437. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1438. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1439. }
  1440. if subItem.FrequencyType == 2 { //按照天数频率
  1441. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1442. now := p.Unix()
  1443. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1444. dayStr2 := "-" + dayStr
  1445. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1446. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1447. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1448. if len(advices) == 0 {
  1449. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1450. }
  1451. }
  1452. }
  1453. }
  1454. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1455. if subItem.Type == 2 {
  1456. if subItem.XtHisProject.MedicalStatus != 1 {
  1457. if subItem.FrequencyType == 1 {
  1458. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1459. }
  1460. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1461. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1462. }
  1463. if subItem.FrequencyType == 2 {
  1464. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1465. now := p.Unix()
  1466. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1467. dayStr2 := "-" + dayStr
  1468. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1469. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1470. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1471. if len(projects) == 0 {
  1472. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1473. }
  1474. }
  1475. }
  1476. } else if subItem.Type == 3 {
  1477. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1478. if subItem.FrequencyType == 1 {
  1479. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1480. }
  1481. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1482. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1483. }
  1484. if subItem.FrequencyType == 2 {
  1485. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1486. now := p.Unix()
  1487. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1488. dayStr2 := "-" + dayStr
  1489. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1490. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1491. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1492. if len(projects) == 0 {
  1493. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1494. }
  1495. }
  1496. }
  1497. }
  1498. }
  1499. sch_prescriptions = append(sch_prescriptions, cus)
  1500. }
  1501. for _, item := range sch_prescriptions {
  1502. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1503. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1504. }
  1505. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1506. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1507. }
  1508. }
  1509. }
  1510. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1511. if config.ID > 0 && config.IsOpen == 1 {
  1512. for _, item := range sch_prescriptions {
  1513. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1514. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1515. if info.RetailPrice > 0 {
  1516. subItem.Drug.MinPrice = info.RetailPrice
  1517. if admin.CurrentOrgId != 10598 {
  1518. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1519. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1520. }
  1521. }
  1522. }
  1523. }
  1524. }
  1525. if config.ID > 0 && config.IsOpen == 1 {
  1526. for _, item := range sch_prescriptions {
  1527. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1528. if subItem.Type == 3 {
  1529. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1530. if info.Price > 0 {
  1531. subItem.GoodInfo.PackingPrice = info.Price
  1532. if admin.CurrentOrgId != 10598 {
  1533. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1534. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1535. }
  1536. }
  1537. }
  1538. }
  1539. }
  1540. }
  1541. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1542. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1543. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1544. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1545. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1546. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1547. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1548. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1551. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1552. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1553. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1554. fmt.Println(prescriptions)
  1555. fmt.Println(sch_prescriptions)
  1556. fmt.Println(last_prescriptions)
  1557. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1558. if len(sch_prescriptions) > 0 {
  1559. var index = 0
  1560. for subindex, item := range sch_prescriptions {
  1561. if item.Type == 2 {
  1562. index = subindex
  1563. }
  1564. }
  1565. fmt.Println(index)
  1566. fmt.Println(len(sch_prescriptions))
  1567. if index >= 0 && index < len(sch_prescriptions) {
  1568. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1569. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1570. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1571. if one.ID > 0 {
  1572. var hpt models.HisPrescriptionProjectTemplate
  1573. hpt.Type = 3
  1574. hpt.ID = 0
  1575. hpt.PatientId = sch_prescriptions[index].PatientId
  1576. hpt.Status = 1
  1577. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1578. hpt.Mtime = time.Now().Unix()
  1579. hpt.Ctime = time.Now().Unix()
  1580. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1581. hpt.Count = "1"
  1582. hpt.Price = one.RetailPrice
  1583. hpt.ProjectId = one.ID
  1584. hpt.FeedetlSn = ""
  1585. hpt.PrescriptionId = sch_prescriptions[index].ID
  1586. hpt.Unit = one.PackingUnit
  1587. hpt.Day = "1"
  1588. hpt.SingleDose = "1"
  1589. hpt.GoodInfo = one
  1590. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1591. }
  1592. if two.ID > 0 {
  1593. var hpt models.HisPrescriptionProjectTemplate
  1594. hpt.Type = 3
  1595. hpt.ID = 0
  1596. hpt.PatientId = sch_prescriptions[index].PatientId
  1597. hpt.Status = 1
  1598. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1599. hpt.Mtime = time.Now().Unix()
  1600. hpt.Ctime = time.Now().Unix()
  1601. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1602. hpt.Count = "1"
  1603. hpt.Price = two.RetailPrice
  1604. hpt.ProjectId = two.ID
  1605. hpt.FeedetlSn = ""
  1606. hpt.PrescriptionId = sch_prescriptions[index].ID
  1607. hpt.Unit = two.PackingUnit
  1608. hpt.Day = "1"
  1609. hpt.SingleDose = "1"
  1610. hpt.GoodInfo = two
  1611. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1612. }
  1613. //if three.ID > 0 {
  1614. // var hpt models.HisPrescriptionProjectTemplate
  1615. // hpt.Type = 3
  1616. // hpt.ID = 0
  1617. // hpt.PatientId = sch_prescriptions[index].PatientId
  1618. // hpt.Status = 1
  1619. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1620. // hpt.Mtime = time.Now().Unix()
  1621. // hpt.Ctime = time.Now().Unix()
  1622. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1623. // hpt.Count = "1"
  1624. // hpt.Price = three.RetailPrice
  1625. // hpt.ProjectId = three.ID
  1626. // hpt.FeedetlSn = ""
  1627. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1628. // hpt.Unit = three.PackingUnit
  1629. // hpt.Day = "1"
  1630. // hpt.SingleDose = "1"
  1631. // hpt.GoodInfo = three
  1632. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1633. //}
  1634. fmt.Println(sch_prescriptions)
  1635. }
  1636. } else {
  1637. if len(last_prescriptions) > 0 {
  1638. var index = 0
  1639. for subindex, item := range last_prescriptions {
  1640. if item.Type == 2 {
  1641. index = subindex
  1642. }
  1643. }
  1644. if index >= 0 && index < len(last_prescriptions) {
  1645. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1646. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1647. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1648. if one.ID > 0 {
  1649. var hpt models.HisPrescriptionProject
  1650. hpt.Type = 3
  1651. hpt.ID = 0
  1652. hpt.PatientId = last_prescriptions[index].PatientId
  1653. hpt.Status = 1
  1654. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1655. hpt.Mtime = time.Now().Unix()
  1656. hpt.Ctime = time.Now().Unix()
  1657. hpt.RecordDate = last_prescriptions[index].RecordDate
  1658. hpt.Count = "1"
  1659. hpt.Price = one.RetailPrice
  1660. hpt.ProjectId = one.ID
  1661. hpt.FeedetlSn = ""
  1662. hpt.PrescriptionId = last_prescriptions[index].ID
  1663. hpt.Unit = one.PackingUnit
  1664. hpt.Day = "1"
  1665. hpt.SingleDose = "1"
  1666. hpt.GoodInfo = one
  1667. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1668. }
  1669. if two.ID > 0 {
  1670. var hpt models.HisPrescriptionProject
  1671. hpt.Type = 3
  1672. hpt.ID = 0
  1673. hpt.PatientId = last_prescriptions[index].PatientId
  1674. hpt.Status = 1
  1675. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1676. hpt.Mtime = time.Now().Unix()
  1677. hpt.Ctime = time.Now().Unix()
  1678. hpt.RecordDate = last_prescriptions[index].RecordDate
  1679. hpt.Count = "1"
  1680. hpt.Price = two.RetailPrice
  1681. hpt.ProjectId = two.ID
  1682. hpt.FeedetlSn = ""
  1683. hpt.PrescriptionId = last_prescriptions[index].ID
  1684. hpt.Unit = two.PackingUnit
  1685. hpt.Day = "1"
  1686. hpt.SingleDose = "1"
  1687. hpt.GoodInfo = two
  1688. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1689. }
  1690. //if three.ID > 0 {
  1691. // var hpt models.HisPrescriptionProject
  1692. // hpt.Type = 3
  1693. // hpt.ID = 0
  1694. // hpt.PatientId = last_prescriptions[index].PatientId
  1695. // hpt.Status = 1
  1696. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1697. // hpt.Mtime = time.Now().Unix()
  1698. // hpt.Ctime = time.Now().Unix()
  1699. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1700. // hpt.Count = "1"
  1701. // hpt.Price = three.RetailPrice
  1702. // hpt.ProjectId = three.ID
  1703. // hpt.FeedetlSn = ""
  1704. // hpt.PrescriptionId = last_prescriptions[index].ID
  1705. // hpt.Unit = three.PackingUnit
  1706. // hpt.Day = "1"
  1707. // hpt.SingleDose = "1"
  1708. // hpt.GoodInfo = three
  1709. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1710. //}
  1711. }
  1712. }
  1713. }
  1714. }
  1715. c.ServeSuccessJSON(map[string]interface{}{
  1716. "his_info": his_patient_info,
  1717. "xt_info": xt_patient_info,
  1718. "prescription": prescriptions,
  1719. "case_history": case_history,
  1720. "info": patientPrescriptionInfo,
  1721. //"month_prescriptions": monthPrescriptions,
  1722. "order": order,
  1723. "doctors": doctors,
  1724. "department": department,
  1725. "sch_prescriptions": sch_prescriptions,
  1726. "last_prescriptions": last_prescriptions,
  1727. "schedule": sch,
  1728. "count": count,
  1729. "drugStockConfig": drugStockConfig,
  1730. "last_info": lastPatientPrescriptionInfo,
  1731. "befor": beforThrity,
  1732. "LastCaseHistory": LastCaseHistory,
  1733. "prescriptionInfo": prescriptionInfo,
  1734. })
  1735. return
  1736. }
  1737. func (c *HisApiController) GetHisPrescriptionConfig() {
  1738. adminInfo := c.GetAdminUserInfo()
  1739. //获取医嘱模版
  1740. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1741. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1742. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1743. //获取所有基础药
  1744. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1745. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1746. if config.ID > 0 && config.IsOpen == 1 {
  1747. for _, item := range drugs {
  1748. var index = 0
  1749. for _, subItem := range item.OtherDrugWarehouseInfo {
  1750. if index == 0 {
  1751. index = index + 1
  1752. if subItem.RetailPrice > 0 {
  1753. item.MinPrice = subItem.RetailPrice
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1760. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1761. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1762. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1763. //获取所有科室信息
  1764. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1765. //获取诊断信息
  1766. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1767. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1768. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1769. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1770. //获取是否开启保存耗材出库的开关
  1771. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1772. c.ServeSuccessJSON(map[string]interface{}{
  1773. "drugs": drugs,
  1774. "advices_template": advices,
  1775. "drugways": drugways,
  1776. "efs": efs,
  1777. "doctors": doctors,
  1778. "department": department,
  1779. "sick": sick,
  1780. "additions": additions,
  1781. "diagnose": diagnose,
  1782. "manufacturers": manufacturers,
  1783. "goodOutOpen": goodOutOpen,
  1784. "patientDiagnose": patientDiagnose,
  1785. })
  1786. }
  1787. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1788. //获取所有基础药
  1789. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1790. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1791. if config.ID > 0 && config.IsOpen == 1 {
  1792. for _, item := range drugs {
  1793. var index = 0
  1794. for _, subItem := range item.OtherDrugWarehouseInfo {
  1795. if index == 0 {
  1796. index = index + 1
  1797. if subItem.RetailPrice > 0 {
  1798. item.MinPrice = subItem.RetailPrice
  1799. }
  1800. }
  1801. }
  1802. }
  1803. }
  1804. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1805. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1806. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1807. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1808. //获取所有科室信息
  1809. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1810. //获取诊断信息
  1811. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1812. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1813. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1814. //获取是否开启保存耗材出库的开关
  1815. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1816. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1817. c.ServeSuccessJSON(map[string]interface{}{
  1818. "drugs": drugs,
  1819. "advices_template": advices,
  1820. "drugways": drugways,
  1821. "efs": efs,
  1822. "doctors": doctors,
  1823. "department": department,
  1824. "sick": sick,
  1825. "additions": additions,
  1826. "diagnose": diagnose,
  1827. "manufacturers": manufacturers,
  1828. "goodOutOpen": goodOutOpen,
  1829. "patientDiagnose": patientDiagnose,
  1830. })
  1831. }
  1832. }
  1833. func (c *HisApiController) CreateHisPrescription() {
  1834. record_date := c.GetString("record_date")
  1835. patient_id, _ := c.GetInt64("patient_id")
  1836. reg_type, _ := c.GetInt64("reg_type")
  1837. diagnose := c.GetString("diagnose")
  1838. sick_type, _ := c.GetInt64("sick_type")
  1839. sick_history := c.GetString("sick_history")
  1840. doctor_id, _ := c.GetInt64("doctor", 0)
  1841. department, _ := c.GetInt64("department", 0)
  1842. his_patient_id, _ := c.GetInt64("his_patient_id")
  1843. p_type, _ := c.GetInt64("p_type")
  1844. patient_diagnose := c.GetString("patient_diagnose")
  1845. dataBody := make(map[string]interface{}, 0)
  1846. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1847. if err != nil {
  1848. utils.ErrorLog(err.Error())
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1850. return
  1851. }
  1852. //edit, src := GetCompareData(dataBody)
  1853. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1854. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1855. //fmt.Println(drugResult)
  1856. //fmt.Println(goodResult)
  1857. timeLayout := "2006-01-02"
  1858. loc, _ := time.LoadLocation("Local")
  1859. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1860. if err != nil {
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. adminInfo := c.GetAdminUserInfo()
  1865. recordDateTime := theTime.Unix()
  1866. //查询默认出库仓库库存
  1867. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1868. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1869. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1870. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1871. if len(lists) == 1 {
  1872. his_patient_id = lists[0].ID
  1873. }
  1874. }
  1875. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1876. //自动出库的开关开启
  1877. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1878. //自动出库
  1879. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1880. //耗材保存处方出库
  1881. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1882. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1883. //已发药和已收费限制逻辑
  1884. isMidicine := false
  1885. isCharge := false
  1886. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1887. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1888. if len(prescriptions) > 0 {
  1889. for _, item := range prescriptions {
  1890. items := item.(map[string]interface{})
  1891. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1892. utils.ErrorLog("id")
  1893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1894. return
  1895. }
  1896. id := int64(items["id"].(float64))
  1897. if id > 0 {
  1898. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1899. if err != nil {
  1900. if new_prescription.OrderStatus == 4 {
  1901. isCharge = true
  1902. }
  1903. }
  1904. }
  1905. }
  1906. }
  1907. }
  1908. if isMidicine == true {
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1910. return
  1911. }
  1912. if isCharge == true {
  1913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1914. return
  1915. }
  1916. // 开始主事务
  1917. db := service.XTWriteDB()
  1918. tx := db.Begin()
  1919. // 在函数结束时处理事务回滚
  1920. defer func() {
  1921. if r := recover(); r != nil {
  1922. tx.Rollback()
  1923. }
  1924. }()
  1925. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1926. //药品发药出库
  1927. if pharmacyConfig.IsOpen == 1 {
  1928. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1929. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1930. if len(prescriptions) > 0 {
  1931. for _, item := range prescriptions {
  1932. items := item.(map[string]interface{})
  1933. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1934. advices := items["advices"].([]interface{})
  1935. if len(advices) > 0 {
  1936. for _, advice := range advices {
  1937. var drug_id int64
  1938. var prescribing_number float64
  1939. var prescribingNumberUnit string
  1940. var adviceId int64
  1941. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1942. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1943. }
  1944. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1945. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1946. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1947. }
  1948. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1949. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1950. }
  1951. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1952. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1953. }
  1954. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1955. if drug.ID == 0 {
  1956. tx.Rollback()
  1957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1958. return
  1959. }
  1960. //查询药品的所有库存
  1961. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1962. var total_count int64
  1963. for _, it := range list {
  1964. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1965. }
  1966. totals := strconv.FormatInt(total_count, 10)
  1967. //查询该药品是否存在开药记录
  1968. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1969. //新增处方盘点库存是否充足
  1970. if advicelist.ID == 0 {
  1971. all_count, _ := strconv.ParseFloat(totals, 64)
  1972. if prescribingNumberUnit == drug.MinUnit {
  1973. if drug.IsUse != 1 {
  1974. if drug.IsProject == 0 || drug.IsProject == 2 {
  1975. if all_count == 0 {
  1976. tx.Rollback()
  1977. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1978. return
  1979. }
  1980. if prescribing_number > all_count {
  1981. tx.Rollback()
  1982. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1983. return
  1984. }
  1985. }
  1986. }
  1987. }
  1988. if prescribingNumberUnit == drug.MaxUnit {
  1989. num := prescribing_number * float64(drug.MinNumber)
  1990. if drug.IsUse != 1 {
  1991. if drug.IsProject == 0 || drug.IsProject == 2 {
  1992. if all_count == 0 {
  1993. tx.Rollback()
  1994. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1995. return
  1996. }
  1997. if num > all_count {
  1998. tx.Rollback()
  1999. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2000. return
  2001. }
  2002. }
  2003. }
  2004. }
  2005. }
  2006. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2007. //不使用保存处方出库
  2008. if drugOutConfig.IsOpen != 1 {
  2009. //修改处方
  2010. for _, advice := range advices {
  2011. var drug_id int64
  2012. var prescribing_number float64
  2013. var prescribingNumberUnit string
  2014. var prescribingNumber string
  2015. var adviceId int64
  2016. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2017. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2018. }
  2019. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2020. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2021. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2022. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2023. }
  2024. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2025. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2026. }
  2027. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2028. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2029. }
  2030. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2031. if drug.ID == 0 {
  2032. tx.Rollback()
  2033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2034. return
  2035. }
  2036. //查询药品的所有库存
  2037. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2038. var total_count int64
  2039. for _, it := range list {
  2040. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2041. }
  2042. totals := strconv.FormatInt(total_count, 10)
  2043. //查询该药品是否存在开药记录
  2044. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2045. //新增处方
  2046. if advicelist.ID == 0 {
  2047. all_count, _ := strconv.ParseFloat(totals, 64)
  2048. if prescribingNumberUnit == drug.MinUnit {
  2049. if drug.IsUse != 1 {
  2050. if drug.IsProject == 0 || drug.IsProject == 2 {
  2051. if all_count == 0 {
  2052. tx.Rollback()
  2053. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2054. return
  2055. }
  2056. if prescribing_number > all_count {
  2057. tx.Rollback()
  2058. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2059. return
  2060. }
  2061. }
  2062. }
  2063. } else {
  2064. if prescribingNumberUnit == drug.MaxUnit {
  2065. num := prescribing_number * float64(drug.MinNumber)
  2066. if drug.IsUse != 1 {
  2067. if drug.IsProject == 0 || drug.IsProject == 2 {
  2068. if all_count == 0 {
  2069. tx.Rollback()
  2070. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2071. return
  2072. }
  2073. if num > all_count {
  2074. tx.Rollback()
  2075. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2076. return
  2077. }
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. //修改处方
  2084. if advicelist.ID > 0 {
  2085. var device_number int64
  2086. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2087. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2088. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2089. device_number = prescribingNumberInt * drug.MinNumber
  2090. }
  2091. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2092. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2093. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2094. device_number = prescribingNumberInt
  2095. }
  2096. var number_count int64
  2097. if prescribingNumberUnit == drug.MaxUnit {
  2098. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2099. number_count = prescribingNumberInt * drug.MinNumber
  2100. }
  2101. if prescribingNumberUnit == drug.MinUnit {
  2102. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2103. number_count = prescribingNumberInt
  2104. }
  2105. //如果修改的数量大于之前修改的数量
  2106. if (number_count - device_number) > 0 {
  2107. //如果修改的差数量 大于库存数量
  2108. if drug.IsUse != 1 {
  2109. if (number_count - device_number) > total_count {
  2110. tx.Rollback()
  2111. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2112. return
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. }
  2119. }
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125. }
  2126. //已发药和已收费限制逻辑
  2127. //执行出库的逻辑
  2128. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2129. //校验库存总量
  2130. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2131. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2132. if len(prescriptions) > 0 {
  2133. for _, item := range prescriptions {
  2134. items := item.(map[string]interface{})
  2135. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2136. advices := items["advices"].([]interface{})
  2137. if len(advices) > 0 {
  2138. for _, advice := range advices {
  2139. var drug_id int64
  2140. var prescribing_number float64
  2141. var prescribingNumberUnit string
  2142. var adviceId int64
  2143. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2144. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2145. }
  2146. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2147. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2148. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2149. }
  2150. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2151. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2152. }
  2153. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2154. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2155. }
  2156. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2157. if drug.ID == 0 {
  2158. tx.Rollback()
  2159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2160. return
  2161. }
  2162. //查询药品的所有库存
  2163. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2164. var total_count int64
  2165. for _, it := range list {
  2166. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2167. }
  2168. totals := strconv.FormatInt(total_count, 10)
  2169. //查询该药品是否存在开药记录
  2170. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2171. //查询最新批次库存
  2172. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2173. var batch_number_count int64
  2174. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2175. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2176. //新增处方
  2177. if advicelist.ID == 0 {
  2178. all_count, _ := strconv.ParseFloat(totals, 64)
  2179. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2180. if prescribingNumberUnit == drug.MinUnit {
  2181. if drug.IsUse != 1 {
  2182. if drug.IsProject == 0 || drug.IsProject == 2 {
  2183. if all_count == 0 {
  2184. tx.Rollback()
  2185. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2186. return
  2187. }
  2188. if prescribing_number > all_count {
  2189. tx.Rollback()
  2190. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2191. return
  2192. }
  2193. }
  2194. if adminInfo.CurrentOrgId == 10215 {
  2195. if prescribing_number > batch_number_all_count {
  2196. tx.Rollback()
  2197. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2198. return
  2199. }
  2200. }
  2201. }
  2202. }
  2203. if prescribingNumberUnit == drug.MaxUnit {
  2204. num := prescribing_number * float64(drug.MinNumber)
  2205. if drug.IsUse != 1 {
  2206. if drug.IsProject == 0 || drug.IsProject == 2 {
  2207. if all_count == 0 {
  2208. tx.Rollback()
  2209. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2210. return
  2211. }
  2212. if num > all_count {
  2213. tx.Rollback()
  2214. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2215. return
  2216. }
  2217. }
  2218. if adminInfo.CurrentOrgId == 10215 {
  2219. if num > batch_number_all_count {
  2220. tx.Rollback()
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2222. return
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. //不是保存处方出库
  2229. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2230. if drugOutConfig.IsOpen != 1 {
  2231. //修改处方
  2232. for _, advice := range advices {
  2233. var drug_id int64
  2234. var prescribing_number float64
  2235. var prescribingNumberUnit string
  2236. var prescribingNumber string
  2237. var adviceId int64
  2238. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2239. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2240. }
  2241. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2242. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2243. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2244. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2245. }
  2246. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2247. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2248. }
  2249. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2250. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2251. }
  2252. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2253. if drug.ID == 0 {
  2254. tx.Rollback()
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2256. return
  2257. }
  2258. //查询药品的所有库存
  2259. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2260. var total_count int64
  2261. for _, it := range list {
  2262. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2263. }
  2264. totals := strconv.FormatInt(total_count, 10)
  2265. //查询该药品是否存在开药记录
  2266. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2267. //新增处方
  2268. if advicelist.ID == 0 {
  2269. //查询最新批次库存
  2270. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2271. var batch_number_count int64
  2272. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2273. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2274. all_count, _ := strconv.ParseFloat(totals, 64)
  2275. if all_count == 0 {
  2276. tx.Rollback()
  2277. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2278. return
  2279. }
  2280. if prescribingNumberUnit == drug.MinUnit {
  2281. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2282. if drug.IsUse != 1 {
  2283. if drug.IsProject == 0 || drug.IsProject == 2 {
  2284. if all_count == 0 {
  2285. tx.Rollback()
  2286. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2287. return
  2288. }
  2289. if prescribing_number > all_count {
  2290. tx.Rollback()
  2291. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2292. return
  2293. }
  2294. }
  2295. if adminInfo.CurrentOrgId == 10215 {
  2296. if prescribing_number > batch_number_all_count {
  2297. tx.Rollback()
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2299. return
  2300. }
  2301. }
  2302. }
  2303. } else {
  2304. if prescribingNumberUnit == drug.MaxUnit {
  2305. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2306. num := prescribing_number * float64(drug.MinNumber)
  2307. if drug.IsUse != 1 {
  2308. if drug.IsProject == 0 || drug.IsProject == 2 {
  2309. if all_count == 0 {
  2310. tx.Rollback()
  2311. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2312. return
  2313. }
  2314. if num > all_count {
  2315. tx.Rollback()
  2316. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2317. return
  2318. }
  2319. }
  2320. if adminInfo.CurrentOrgId == 10215 {
  2321. if prescribing_number > batch_number_all_count {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2324. return
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. //修改处方
  2332. if advicelist.ID > 0 {
  2333. //查询最新批次库存
  2334. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2335. var batch_number_count int64
  2336. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2337. var device_number int64
  2338. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2339. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2340. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2341. device_number = prescribingNumberInt * drug.MinNumber
  2342. }
  2343. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2344. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2345. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2346. device_number = prescribingNumberInt
  2347. //回退库存
  2348. }
  2349. var number_count int64
  2350. if prescribingNumberUnit == drug.MaxUnit {
  2351. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2352. number_count = prescribingNumberInt * drug.MinNumber
  2353. //回退库存
  2354. }
  2355. if prescribingNumberUnit == drug.MinUnit {
  2356. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2357. number_count = prescribingNumberInt
  2358. //回退库存
  2359. }
  2360. //如果修改的数量大于之前修改的数量
  2361. if (number_count - device_number) > 0 {
  2362. //如果修改的差数量 大于库存数量
  2363. if drug.IsUse != 1 {
  2364. if drug.IsProject == 0 || drug.IsProject == 2 {
  2365. if total_count == 0 {
  2366. tx.Rollback()
  2367. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2368. return
  2369. }
  2370. if (number_count - device_number) > total_count {
  2371. tx.Rollback()
  2372. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2373. return
  2374. }
  2375. if (number_count - device_number) > batch_number_count {
  2376. tx.Rollback()
  2377. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2378. return
  2379. }
  2380. }
  2381. if adminInfo.CurrentOrgId == 10215 {
  2382. // 查询该药品最后一次出库记录
  2383. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2384. var out_count int64
  2385. var in_count int64
  2386. var stock_max_number int64
  2387. var stock_min_number int64
  2388. for _, it := range outInfo {
  2389. if it.CountUnit == drug.MaxUnit {
  2390. it.Count = it.Count * drug.MinNumber
  2391. }
  2392. out_count += it.Count
  2393. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2394. stock_max_number = warehouseInfoList.StockMaxNumber
  2395. stock_min_number = warehouseInfoList.StockMinNumber
  2396. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2397. }
  2398. if out_count > 0 {
  2399. if (number_count - device_number) > in_count {
  2400. tx.Rollback()
  2401. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2402. return
  2403. }
  2404. }
  2405. // 未出库
  2406. if out_count == 0 {
  2407. var sum_in_count int64
  2408. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2409. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2410. //如果修改的数量大于有库存的第一个批次
  2411. if number_count > sum_in_count {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2414. return
  2415. }
  2416. }
  2417. }
  2418. }
  2419. }
  2420. //药品发药
  2421. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2422. //不使用药品发药的功能
  2423. //if pharmacyConfig.IsOpen != 1 {
  2424. // if device_number != number_count {
  2425. //
  2426. // //查询该药品的出库记录
  2427. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2428. // if len(outListExport) > 0 {
  2429. // //
  2430. // for _, item := range outListExport {
  2431. // //回退库存
  2432. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2433. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2434. // }
  2435. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2436. // var stock_max_number int64
  2437. // var stock_min_number int64
  2438. //
  2439. // if number_count >= drug.MinNumber {
  2440. //
  2441. // stock_max_number = device_number / drug.MinNumber
  2442. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2443. //
  2444. // stock_min_number = device_number % drug.MinNumber
  2445. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2446. //
  2447. // } else {
  2448. //
  2449. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2450. //
  2451. // }
  2452. // }
  2453. //
  2454. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2455. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2456. // }
  2457. // }
  2458. // }
  2459. //
  2460. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2461. // var sum_count int64
  2462. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2463. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2464. // for _, its := range stockInfo {
  2465. // if its.MaxUnit == drug.MaxUnit {
  2466. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2467. // }
  2468. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2469. // }
  2470. // //更新字典里面的库存
  2471. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2472. //
  2473. // //剩余库存
  2474. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2475. //
  2476. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2477. // //减少出库数量
  2478. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2479. //
  2480. // }
  2481. //}
  2482. }
  2483. }
  2484. }
  2485. //保存处方开药
  2486. if drugOutConfig.IsOpen == 1 {
  2487. //修改处方
  2488. for _, advice := range advices {
  2489. var drug_id int64
  2490. var prescribing_number float64
  2491. var prescribingNumberUnit string
  2492. var prescribingNumber string
  2493. var adviceId int64
  2494. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2495. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2496. }
  2497. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2498. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2499. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2500. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2501. }
  2502. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2503. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2504. }
  2505. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2506. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2507. }
  2508. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2509. if drug.ID == 0 {
  2510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2511. return
  2512. }
  2513. //查询药品的所有库存
  2514. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2515. var total_count int64
  2516. for _, it := range list {
  2517. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2518. }
  2519. totals := strconv.FormatInt(total_count, 10)
  2520. //查询该药品是否存在开药记录
  2521. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2522. //新增处方
  2523. if advicelist.ID == 0 {
  2524. //查询最新批次库存
  2525. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2526. var batch_number_count int64
  2527. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2528. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2529. all_count, _ := strconv.ParseFloat(totals, 64)
  2530. if prescribingNumberUnit == drug.MinUnit {
  2531. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2532. if drug.IsUse != 1 {
  2533. if drug.IsProject == 0 || drug.IsProject == 2 {
  2534. if all_count == 0 {
  2535. tx.Rollback()
  2536. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2537. return
  2538. }
  2539. if prescribing_number > all_count {
  2540. tx.Rollback()
  2541. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2542. return
  2543. }
  2544. }
  2545. if adminInfo.CurrentOrgId == 10215 {
  2546. if prescribing_number > batch_number_all_count {
  2547. tx.Rollback()
  2548. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2549. return
  2550. }
  2551. }
  2552. }
  2553. } else {
  2554. if prescribingNumberUnit == drug.MaxUnit {
  2555. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2556. num := prescribing_number * float64(drug.MinNumber)
  2557. if drug.IsUse != 1 {
  2558. if drug.IsProject == 0 || drug.IsProject == 2 {
  2559. if all_count == 0 {
  2560. tx.Rollback()
  2561. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2562. return
  2563. }
  2564. if num > all_count {
  2565. tx.Rollback()
  2566. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2567. return
  2568. }
  2569. }
  2570. if adminInfo.CurrentOrgId == 10215 {
  2571. if prescribing_number > batch_number_all_count {
  2572. tx.Rollback()
  2573. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2574. return
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. //修改处方
  2582. if advicelist.ID > 0 {
  2583. //查询最新批次库存
  2584. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2585. var batch_number_count int64
  2586. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2587. var device_number int64
  2588. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2589. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2590. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2591. device_number = prescribingNumberInt * drug.MinNumber
  2592. }
  2593. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2594. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2595. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2596. device_number = prescribingNumberInt
  2597. }
  2598. var number_count int64
  2599. if prescribingNumberUnit == drug.MaxUnit {
  2600. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2601. number_count = prescribingNumberInt * drug.MinNumber
  2602. }
  2603. if prescribingNumberUnit == drug.MinUnit {
  2604. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2605. number_count = prescribingNumberInt
  2606. }
  2607. //如果修改的数量大于之前修改的数量
  2608. if (number_count - device_number) > 0 {
  2609. //如果修改的差数量 大于库存数量
  2610. if drug.IsUse != 1 {
  2611. if drug.IsProject == 0 || drug.IsProject == 2 {
  2612. if total_count == 0 {
  2613. tx.Rollback()
  2614. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2615. return
  2616. }
  2617. if (number_count - device_number) > total_count {
  2618. tx.Rollback()
  2619. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2620. return
  2621. }
  2622. }
  2623. if adminInfo.CurrentOrgId == 10215 {
  2624. if (number_count - device_number) > batch_number_count {
  2625. tx.Rollback()
  2626. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2627. return
  2628. }
  2629. }
  2630. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2631. //查询历史出库数据总批次
  2632. // 查询该药品最后一次出库记录
  2633. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2634. var out_count int64
  2635. var in_count int64
  2636. var stock_max_number int64
  2637. var stock_min_number int64
  2638. for _, it := range outInfo {
  2639. if it.CountUnit == drug.MaxUnit {
  2640. it.Count = it.Count * drug.MinNumber
  2641. }
  2642. out_count += it.Count
  2643. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2644. stock_max_number = warehouseInfoList.StockMaxNumber
  2645. stock_min_number = warehouseInfoList.StockMinNumber
  2646. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2647. }
  2648. if out_count > 0 {
  2649. if (number_count - device_number) > in_count {
  2650. tx.Rollback()
  2651. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2652. return
  2653. }
  2654. }
  2655. // 未出库
  2656. if out_count == 0 {
  2657. var sum_in_count int64
  2658. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2659. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2660. if sum_in_count == 0 {
  2661. tx.Rollback()
  2662. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2663. return
  2664. }
  2665. //如果修改的数量大于有库存的第一个批次
  2666. if number_count > sum_in_count {
  2667. tx.Rollback()
  2668. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2669. return
  2670. }
  2671. }
  2672. }
  2673. }
  2674. }
  2675. }
  2676. }
  2677. }
  2678. }
  2679. }
  2680. }
  2681. }
  2682. }
  2683. }
  2684. }
  2685. //校验耗材库存
  2686. if goodOutConfig.IsOpen == 1 {
  2687. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2688. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2689. if len(prescriptions) > 0 {
  2690. for _, item := range prescriptions {
  2691. items := item.(map[string]interface{})
  2692. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2693. projects := items["project"].([]interface{})
  2694. if len(projects) > 0 {
  2695. for _, project := range projects {
  2696. var project_id int64
  2697. var project_type int64
  2698. var totals float64
  2699. var project_name string
  2700. var parsetotal int64
  2701. var id int64
  2702. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2703. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2704. }
  2705. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2706. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2707. }
  2708. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2709. total, _ := project.(map[string]interface{})["total"].(string)
  2710. totals, _ = strconv.ParseFloat(total, 64)
  2711. }
  2712. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2713. project_name = project.(map[string]interface{})["project_name"].(string)
  2714. }
  2715. if project_type == 3 {
  2716. //查找该耗材的出库记录
  2717. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2718. if len(goodWarehouseInfo) == 0 {
  2719. //查询耗材库存
  2720. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2721. var stock_count int64
  2722. for _, it := range list {
  2723. stock_count += it.StockCount
  2724. }
  2725. stock_counts := strconv.FormatInt(stock_count, 10)
  2726. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2727. if stock_total_count == 0 {
  2728. tx.Rollback()
  2729. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2730. return
  2731. }
  2732. if totals > stock_total_count {
  2733. tx.Rollback()
  2734. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2735. return
  2736. }
  2737. }
  2738. if len(goodWarehouseInfo) > 0 {
  2739. //查询该患者耗材的历史数据
  2740. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2741. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2742. //数量发生改变
  2743. if parsetotal != count {
  2744. //如果现在的数量大于历史数量,就要看库存是否足够
  2745. if parsetotal > count {
  2746. //查询耗材所有库存
  2747. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2748. var stock_count int64
  2749. for _, it := range list {
  2750. stock_count += it.StockCount
  2751. }
  2752. //库存不足
  2753. if stock_count == 0 {
  2754. tx.Rollback()
  2755. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2756. return
  2757. }
  2758. if (parsetotal - count) > stock_count {
  2759. tx.Rollback()
  2760. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2761. return
  2762. }
  2763. }
  2764. }
  2765. }
  2766. }
  2767. }
  2768. }
  2769. }
  2770. }
  2771. }
  2772. }
  2773. }
  2774. //不使用耗材保存处方出库
  2775. if goodOutConfig.IsOpen != 1 {
  2776. if stockConfig.IsOpen == 1 {
  2777. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2778. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2779. if len(prescriptions) > 0 {
  2780. for _, item := range prescriptions {
  2781. items := item.(map[string]interface{})
  2782. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2783. projects := items["project"].([]interface{})
  2784. if len(projects) > 0 {
  2785. for _, project := range projects {
  2786. var project_id int64
  2787. var project_type int64
  2788. var totals float64
  2789. var project_name string
  2790. var parsetotal int64
  2791. var id int64
  2792. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2793. id = int64(project.(map[string]interface{})["id"].(float64))
  2794. }
  2795. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2796. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2797. }
  2798. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2799. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2800. }
  2801. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2802. total, _ := project.(map[string]interface{})["total"].(string)
  2803. totals, _ = strconv.ParseFloat(total, 64)
  2804. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2805. }
  2806. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2807. project_name = project.(map[string]interface{})["project_name"].(string)
  2808. }
  2809. if project_type == 3 {
  2810. //查找该耗材的出库记录
  2811. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2812. //没有出库记录
  2813. if len(goodWarehouseInfo) == 0 {
  2814. //查询耗材库存
  2815. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2816. var stock_count int64
  2817. for _, it := range list {
  2818. stock_count += it.StockCount
  2819. }
  2820. stock_counts := strconv.FormatInt(stock_count, 10)
  2821. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2822. if stock_total_count == 0 {
  2823. tx.Rollback()
  2824. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2825. return
  2826. }
  2827. if totals > stock_total_count {
  2828. tx.Rollback()
  2829. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2830. return
  2831. }
  2832. //查找今日该患者已经出库的所有耗材
  2833. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2834. for _, item := range goodList {
  2835. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2836. var flush_count int64
  2837. for _, it := range goodListSix {
  2838. flush_count += it.StockCount
  2839. }
  2840. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2841. creater := adminInfo.AdminUser.Id
  2842. if errs != nil {
  2843. goodErrcode := models.XtGoodErrcode{
  2844. UserOrgId: item.OrgId,
  2845. Errcode: "手动出库更新剩余出库失败",
  2846. GoodId: item.GoodId,
  2847. Status: 1,
  2848. Ctime: time.Now().Unix(),
  2849. Mtime: 0,
  2850. Count: 0,
  2851. StockCount: 0,
  2852. Creater: creater,
  2853. BatchNumberId: 0,
  2854. WarehouseOutId: 0,
  2855. }
  2856. service.CreateGoodErrcode(goodErrcode)
  2857. }
  2858. }
  2859. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2860. }
  2861. //有出库记录
  2862. if len(goodWarehouseInfo) > 0 {
  2863. //查询该患者耗材的历史数据
  2864. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2865. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2866. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2867. //数量发生改变
  2868. if parsetotal != count {
  2869. //查找今日该患者已经出库的所有耗材
  2870. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2871. for _, item := range goodList {
  2872. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2873. var flush_count int64
  2874. for _, it := range goodListSix {
  2875. flush_count += it.StockCount
  2876. }
  2877. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2878. //减少出库数量
  2879. creater := adminInfo.AdminUser.Id
  2880. if errs != nil {
  2881. goodErrcode := models.XtGoodErrcode{
  2882. UserOrgId: item.OrgId,
  2883. Errcode: "手动出库更新剩余出库失败",
  2884. GoodId: item.GoodId,
  2885. Status: 1,
  2886. Ctime: time.Now().Unix(),
  2887. Mtime: 0,
  2888. Count: 0,
  2889. StockCount: 0,
  2890. Creater: creater,
  2891. BatchNumberId: 0,
  2892. WarehouseOutId: 0,
  2893. }
  2894. service.CreateGoodErrcode(goodErrcode)
  2895. }
  2896. //查询默认仓库
  2897. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2898. var total_count int64
  2899. for _, it := range stockList {
  2900. total_count += it.StockCount
  2901. }
  2902. //基础库插入数据
  2903. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2904. }
  2905. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2906. }
  2907. }
  2908. }
  2909. }
  2910. }
  2911. }
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2918. var hpInfo models.HisPrescriptionInfo
  2919. if info.ID == 0 {
  2920. var randNum int
  2921. randNum = rand.Intn(10000) + 1000
  2922. timestamp := time.Now().Unix()
  2923. tempTime := time.Unix(timestamp, 0)
  2924. timeFormat := tempTime.Format("20060102150405")
  2925. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2926. hpInfo = models.HisPrescriptionInfo{
  2927. HisPatientId: his_patient_id,
  2928. UserOrgId: adminInfo.CurrentOrgId,
  2929. RecordDate: theTime.Unix(),
  2930. PatientId: patient_id,
  2931. Status: 1,
  2932. Ctime: time.Now().Unix(),
  2933. Mtime: time.Now().Unix(),
  2934. Creator: adminInfo.AdminUser.Id,
  2935. Modifier: adminInfo.AdminUser.Id,
  2936. Diagnosis: diagnose,
  2937. SickHistory: sick_history,
  2938. Departments: department,
  2939. RegisterType: reg_type,
  2940. PrescriptionNumber: p_number,
  2941. PrescriptionStatus: 1,
  2942. Doctor: role.UserName,
  2943. DoctorId: doctor_id,
  2944. SickType: sick_type,
  2945. PType: p_type,
  2946. PatientDiagnosis: patient_diagnose,
  2947. }
  2948. service.SavePatientPrescriptionInfo(hpInfo)
  2949. //创建步骤表
  2950. finish := models.XtDialysisFinish{
  2951. IsFinish: 1,
  2952. UserOrgId: adminInfo.CurrentOrgId,
  2953. Status: 1,
  2954. Ctime: time.Now().Unix(),
  2955. Mtime: 0,
  2956. Module: 4,
  2957. RecordDate: theTime.Unix(),
  2958. Sourse: 1,
  2959. PatientId: patient_id,
  2960. }
  2961. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2962. if dialysisFinish.ID == 0 {
  2963. service.CreateDialysisFinish(finish)
  2964. }
  2965. redis := service.RedisClient()
  2966. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2967. redis.Set(key, "", time.Second)
  2968. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2969. redis.Set(keyOne, "", time.Second)
  2970. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2971. redis.Set(keySeven, "", time.Second)
  2972. defer redis.Close()
  2973. } else {
  2974. hpInfo = models.HisPrescriptionInfo{
  2975. ID: info.ID,
  2976. UserOrgId: adminInfo.CurrentOrgId,
  2977. RecordDate: info.RecordDate,
  2978. PatientId: info.PatientId,
  2979. Status: 1,
  2980. Ctime: info.Ctime,
  2981. Mtime: time.Now().Unix(),
  2982. Creator: info.Creator,
  2983. Modifier: adminInfo.AdminUser.Id,
  2984. Diagnosis: diagnose,
  2985. SickHistory: sick_history,
  2986. Departments: department,
  2987. RegisterType: reg_type,
  2988. PrescriptionNumber: info.PrescriptionNumber,
  2989. Doctor: role.UserName,
  2990. PrescriptionStatus: info.PrescriptionStatus,
  2991. DoctorId: doctor_id,
  2992. SickType: sick_type,
  2993. PType: info.PType,
  2994. HisPatientId: info.HisPatientId,
  2995. PatientDiagnosis: patient_diagnose,
  2996. }
  2997. service.SavePatientPrescriptionInfo(hpInfo)
  2998. //创建步骤表
  2999. finish := models.XtDialysisFinish{
  3000. IsFinish: 1,
  3001. UserOrgId: adminInfo.CurrentOrgId,
  3002. Status: 1,
  3003. Ctime: time.Now().Unix(),
  3004. Mtime: 0,
  3005. Module: 4,
  3006. RecordDate: info.RecordDate,
  3007. Sourse: 1,
  3008. PatientId: info.PatientId,
  3009. }
  3010. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3011. if dialysisFinish.ID == 0 {
  3012. service.CreateDialysisFinish(finish)
  3013. }
  3014. redis := service.RedisClient()
  3015. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3016. redis.Set(key, "", time.Second)
  3017. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3018. redis.Set(keyOne, "", time.Second)
  3019. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3020. redis.Set(keySeven, "", time.Second)
  3021. defer redis.Close()
  3022. }
  3023. //定义切片
  3024. var adviceList []models.HisDoctorAdviceInfo
  3025. var projectList []models.HisPrescriptionProject
  3026. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10635 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 || adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10726 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10571 || adminInfo.CurrentOrgId == 10724 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10653 || adminInfo.CurrentOrgId == 10567 {
  3027. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3028. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3029. var tempPrescription *models.HisPrescription
  3030. if len(prescriptions) > 0 {
  3031. for _, item := range prescriptions {
  3032. // 开始外部循环的事务
  3033. tx := db.Begin()
  3034. // 在函数结束时处理事务回滚
  3035. defer func() {
  3036. if r := recover(); r != nil {
  3037. tx.Rollback()
  3038. }
  3039. }()
  3040. items := item.(map[string]interface{})
  3041. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3042. utils.ErrorLog("id")
  3043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3044. return
  3045. }
  3046. id := int64(items["id"].(float64))
  3047. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3048. tempPrescription = &new_prescription
  3049. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3050. utils.ErrorLog("type")
  3051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3052. return
  3053. }
  3054. types := int64(items["type"].(float64))
  3055. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3056. utils.ErrorLog("med_type")
  3057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3058. return
  3059. }
  3060. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3061. if med_type == "0" {
  3062. med_type = "14"
  3063. }
  3064. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3065. // utils.ErrorLog("diagnoses")
  3066. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3067. // return
  3068. //}
  3069. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3070. diagnoses, _ := items["diagnoses"].(string)
  3071. //if order_status == 0 {
  3072. // order_status = 1
  3073. //}
  3074. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3075. utils.ErrorLog("pre_time")
  3076. }
  3077. preTime, _ := items["pre_time"].(string)
  3078. fmt.Println("preTime", preTime)
  3079. timeLayout := "2006-01-02"
  3080. loc, _ := time.LoadLocation("Local")
  3081. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3082. //result := strings.Split(preTime, " ")
  3083. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3084. if err != nil {
  3085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3086. return
  3087. }
  3088. pTime := theTime2.Unix()
  3089. ctime := time.Now().Unix()
  3090. if tempPrescription.ID == 0 {
  3091. prescription := &models.HisPrescription{
  3092. ID: 0,
  3093. PatientId: patient_id,
  3094. UserOrgId: adminInfo.CurrentOrgId,
  3095. RecordDate: recordDateTime,
  3096. Ctime: ctime,
  3097. Mtime: ctime,
  3098. Type: types,
  3099. Modifier: adminInfo.AdminUser.Id,
  3100. Creator: adminInfo.AdminUser.Id,
  3101. Status: 1,
  3102. Doctor: role.UserName,
  3103. HisPatientId: his_patient_id,
  3104. OrderStatus: 1,
  3105. BatchNumber: "",
  3106. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3107. PreTime: pTime,
  3108. PType: p_type,
  3109. MedType: med_type,
  3110. Diagnose: diagnoses,
  3111. }
  3112. tempPrescription = prescription
  3113. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3114. redis := service.RedisClient()
  3115. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3116. redis.Set(key, "", time.Second)
  3117. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3118. redis.Set(keyOne, "", time.Second)
  3119. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3120. redis.Set(keySeven, "", time.Second)
  3121. defer redis.Close()
  3122. } else {
  3123. tempPrescription.ID = id
  3124. tempPrescription.Type = types
  3125. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3126. tempPrescription.Mtime = time.Now().Unix()
  3127. tempPrescription.Doctor = role.UserName
  3128. //tempPrescription.OrderStatus = order_status
  3129. tempPrescription.PreTime = pTime
  3130. tempPrescription.MedType = med_type
  3131. tempPrescription.Diagnose = diagnoses
  3132. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3133. redis := service.RedisClient()
  3134. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3135. redis.Set(key, "", time.Second)
  3136. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3137. redis.Set(keyOne, "", time.Second)
  3138. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3139. redis.Set(keySeven, "", time.Second)
  3140. defer redis.Close()
  3141. }
  3142. //service.SaveHisPrescription(prescription)
  3143. //更改患者挂号状态
  3144. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3145. fmt.Println("更改失败", err2)
  3146. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3147. advices := items["advices"].([]interface{})
  3148. groupNo := int64(0)
  3149. if len(advices) > 0 {
  3150. for _, advice := range advices {
  3151. tx := db.Begin()
  3152. // 在函数结束时处理事务回滚
  3153. defer func() {
  3154. if r := recover(); r != nil {
  3155. tx.Rollback()
  3156. }
  3157. }()
  3158. var s models.HisDoctorAdviceInfo
  3159. s.PrescriptionId = tempPrescription.ID
  3160. s.AdviceType = 2
  3161. s.AdviceDoctor = doctor_id
  3162. s.StopState = 2
  3163. s.ExecutionState = 2
  3164. s.AdviceDate = theTime3.Unix()
  3165. s.Status = 1
  3166. s.UserOrgId = adminInfo.CurrentOrgId
  3167. s.RecordDate = theTime3.Unix()
  3168. s.StartTime = tempPrescription.PreTime
  3169. s.Groupno = groupNo
  3170. s.PatientId = patient_id
  3171. s.HisPatientId = his_patient_id
  3172. s.StartTime = pTime
  3173. s.IsSettle = 2
  3174. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3175. if errcode > 0 {
  3176. c.ServeFailJSONWithSGJErrorCode(errcode)
  3177. return
  3178. }
  3179. s.StartTime = pTime
  3180. var total_count int64 //处方总库存
  3181. //查询改药品信息
  3182. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3183. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3184. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3185. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3186. total_count += prescribingNumberSeven * medical.MinNumber
  3187. }
  3188. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3189. total_count += prescribingNumberSeven
  3190. }
  3191. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3192. total_count += prescribingNumberSeven
  3193. }
  3194. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3195. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3196. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3197. if s.Price != lastWarehouse.RetailPrice {
  3198. s.Price = lastWarehouse.RetailPrice
  3199. }
  3200. if s.Price == 0 {
  3201. if lastWarehouse.ID == 0 {
  3202. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3203. s.Price = lastWarehouseTwo.RetailPrice
  3204. }
  3205. }
  3206. }
  3207. //查询保存处方出库开关是否打开
  3208. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3209. if s.PatientId != 30038 {
  3210. if drugOutConfig.IsOpen == 1 {
  3211. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3212. // 查询该药品最后一次出库记录
  3213. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3214. var is_user_total int64
  3215. var no_user_total int64
  3216. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3217. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3218. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3219. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3220. }
  3221. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3222. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3223. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3224. no_user_total += prescribingNumberSevenTy
  3225. }
  3226. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3227. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3228. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3229. no_user_total += prescribingNumberSevenTy
  3230. }
  3231. if len(druginfo) > 0 {
  3232. for _, it := range druginfo {
  3233. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3234. it.Count = it.Count * drug.MinNumber
  3235. is_user_total += it.Count
  3236. }
  3237. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3238. is_user_total += it.Count
  3239. }
  3240. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3241. is_user_total += it.Count
  3242. }
  3243. }
  3244. }
  3245. //库存不足
  3246. if s.UserOrgId != 10206 {
  3247. if s.ID == 0 {
  3248. //查询改药品是否已经停用
  3249. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3250. if base.ID > 0 {
  3251. tx.Rollback()
  3252. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3253. return
  3254. }
  3255. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3256. if drugMedical.SumCount == 0 {
  3257. tx.Rollback()
  3258. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3259. return
  3260. }
  3261. //针对康德
  3262. if s.UserOrgId == 10402 || s.UserOrgId == 10164 {
  3263. //获取该药品的总入库数量
  3264. drugWarehouseinfo, _ := service.GetAllDrugInfoList(s.DrugId, s.UserOrgId)
  3265. //获取该药品总共开了多少支医嘱
  3266. hisDocInfoList, _ := service.GetHisDocInfoList(s.DrugId, s.UserOrgId)
  3267. var in_count int64
  3268. var in_prescription_number_total int64
  3269. if len(drugWarehouseinfo) > 0 {
  3270. for _, item := range drugWarehouseinfo {
  3271. if item.MaxUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3272. in_count += item.WarehousingCount * drugMedical.MinNumber
  3273. }
  3274. if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3275. in_count += item.WarehousingCount
  3276. }
  3277. if item.MaxUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3278. in_count += item.WarehousingCount
  3279. }
  3280. }
  3281. }
  3282. if len(hisDocInfoList) > 0 {
  3283. for _, item := range hisDocInfoList {
  3284. if item.PrescribingNumberUnit == drugMedical.MaxUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3285. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3286. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3287. in_prescription_number_total += prescribingNumberSevenTy * drug.MinNumber
  3288. }
  3289. if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit != drugMedical.MinUnit {
  3290. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3291. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3292. in_prescription_number_total += prescribingNumberSevenTy
  3293. }
  3294. if item.PrescribingNumberUnit == drugMedical.MinUnit && drugMedical.MaxUnit == drugMedical.MinUnit {
  3295. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3296. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3297. in_prescription_number_total += prescribingNumberSevenTy
  3298. }
  3299. }
  3300. }
  3301. //
  3302. //fmt.Println("no_user_total------------------------------", no_user_total)
  3303. //fmt.Println("in_prescription_number_total---------------------------", in_prescription_number_total)
  3304. //fmt.Println("in_count----------------------------------", in_count)
  3305. //如果已经开过的医嘱 加上未开的医嘱数量 大于 入库总数量则提示库存不足
  3306. if no_user_total+in_prescription_number_total > in_count {
  3307. tx.Rollback()
  3308. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3309. return
  3310. }
  3311. }
  3312. //查询该药品所有入库数量
  3313. }
  3314. if s.ID > 0 {
  3315. //查询改药品是否已经停用
  3316. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3317. if base.ID > 0 {
  3318. tx.Rollback()
  3319. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3320. return
  3321. }
  3322. }
  3323. }
  3324. //fmt.Println("药品名称----------------------", drug.DrugName)
  3325. //fmt.Println("药品名称----------------------", drug.IsUse)
  3326. //fmt.Println("is_user_total-------------------------", is_user_total)
  3327. //fmt.Println("no_user_total-------------------------", no_user_total)
  3328. //fmt.Println("drug.IsUse---------------", drug.IsUse)
  3329. //fmt.Println("00000000000000000000", s.UserOrgId)
  3330. if is_user_total != no_user_total {
  3331. //出库
  3332. //针对御享天源
  3333. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  3334. creater := adminInfo.AdminUser.Id
  3335. newadviceInfo := &models.HisDoctorAdviceInfo{
  3336. ID: s.ID,
  3337. UserOrgId: s.UserOrgId,
  3338. PatientId: s.PatientId,
  3339. HisPatientId: s.HisPatientId,
  3340. AdviceType: s.AdviceType,
  3341. AdviceDate: s.AdviceDate,
  3342. StartTime: s.StartTime,
  3343. AdviceName: s.AdviceName,
  3344. AdviceDesc: s.AdviceDesc,
  3345. ReminderDate: s.ReminderDate,
  3346. SingleDose: s.SingleDose,
  3347. SingleDoseUnit: s.SingleDoseUnit,
  3348. PrescribingNumber: s.PrescribingNumber,
  3349. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3350. DeliveryWay: s.DeliveryWay,
  3351. ExecutionFrequency: s.ExecutionFrequency,
  3352. AdviceDoctor: s.AdviceDoctor,
  3353. Status: s.Status,
  3354. CreatedTime: s.CreatedTime,
  3355. UpdatedTime: s.UpdatedTime,
  3356. AdviceAffirm: s.AdviceAffirm,
  3357. Remark: s.Remark,
  3358. StopTime: s.StopTime,
  3359. StopReason: s.StopReason,
  3360. StopDoctor: s.StopDoctor,
  3361. StopState: s.StopState,
  3362. ParentId: s.ParentId,
  3363. ExecutionTime: s.ExecutionTime,
  3364. ExecutionStaff: s.ExecutionStaff,
  3365. ExecutionState: s.ExecutionState,
  3366. Checker: s.Checker,
  3367. RecordDate: s.RecordDate,
  3368. DialysisOrderId: s.DialysisOrderId,
  3369. CheckTime: s.CheckTime,
  3370. CheckState: s.CheckState,
  3371. DrugSpec: s.DrugSpec,
  3372. DrugSpecUnit: s.DrugSpecUnit,
  3373. Groupno: s.Groupno,
  3374. RemindType: s.RemindType,
  3375. FrequencyType: s.FrequencyType,
  3376. DayCount: s.DayCount,
  3377. WeekDay: s.WeekDay,
  3378. TemplateId: s.TemplateId,
  3379. Modifier: s.Modifier,
  3380. DrugId: s.DrugId,
  3381. Price: s.Price,
  3382. PrescriptionId: s.PrescriptionId,
  3383. MedListCodg: s.MedListCodg,
  3384. FeedetlSn: s.FeedetlSn,
  3385. Day: s.DayCount,
  3386. ChildDoctorAdvice: nil,
  3387. Drug: models.Drug{},
  3388. Diagnosis: s.Diagnosis,
  3389. Way: s.Way,
  3390. HospApprFlag: s.HospApprFlag,
  3391. LmtUsedFlag: s.LmtUsedFlag,
  3392. HisOrderInfo: models.HisOrderInfo{},
  3393. IsMedicine: s.IsMedicine,
  3394. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3395. Child: nil,
  3396. IsSettle: s.IsSettle,
  3397. IsMobile: s.IsMobile,
  3398. IsSelfDrug: s.IsSelfDrug,
  3399. DrugWayCount: s.DrugWayCount,
  3400. }
  3401. var history_count int64
  3402. var local_count int64
  3403. //查找已经开过的医嘱信息
  3404. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3405. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3406. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3407. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3408. local_count += prescribingNumberSevenTy * drug.MinNumber
  3409. }
  3410. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3411. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3412. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3413. local_count += prescribingNumberSevenTy
  3414. }
  3415. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3416. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3417. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3418. local_count += prescribingNumberSevenTy
  3419. }
  3420. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3421. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3422. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3423. history_count += prescribingNumberSevenTy * drug.MinNumber
  3424. }
  3425. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3426. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3427. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3428. history_count += prescribingNumberSevenTy
  3429. }
  3430. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3431. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3432. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3433. history_count += prescribingNumberSevenTy
  3434. }
  3435. fmt.Println("local_count---------------", local_count)
  3436. fmt.Println("history_count---------------", history_count)
  3437. //如果当前出库数量大于历史出库数量则需要出库
  3438. if local_count > history_count {
  3439. //按最小单位出库
  3440. var cha_count = local_count - history_count
  3441. newadviceInfo.PrescribingNumber = float64(cha_count)
  3442. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3443. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3444. }
  3445. //如果当前出库数量小于历史出库数量则需要退库
  3446. if local_count < history_count {
  3447. var cha_count = history_count - local_count
  3448. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3449. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3450. }
  3451. if local_count == history_count {
  3452. if is_user_total == 0 {
  3453. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3454. }
  3455. }
  3456. }
  3457. if drug.IsUse == 2 {
  3458. creater := adminInfo.AdminUser.Id
  3459. newadviceInfo := &models.HisDoctorAdviceInfo{
  3460. ID: s.ID,
  3461. UserOrgId: s.UserOrgId,
  3462. PatientId: s.PatientId,
  3463. HisPatientId: s.HisPatientId,
  3464. AdviceType: s.AdviceType,
  3465. AdviceDate: s.AdviceDate,
  3466. StartTime: s.StartTime,
  3467. AdviceName: s.AdviceName,
  3468. AdviceDesc: s.AdviceDesc,
  3469. ReminderDate: s.ReminderDate,
  3470. SingleDose: s.SingleDose,
  3471. SingleDoseUnit: s.SingleDoseUnit,
  3472. PrescribingNumber: s.PrescribingNumber,
  3473. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3474. DeliveryWay: s.DeliveryWay,
  3475. ExecutionFrequency: s.ExecutionFrequency,
  3476. AdviceDoctor: s.AdviceDoctor,
  3477. Status: s.Status,
  3478. CreatedTime: s.CreatedTime,
  3479. UpdatedTime: s.UpdatedTime,
  3480. AdviceAffirm: s.AdviceAffirm,
  3481. Remark: s.Remark,
  3482. StopTime: s.StopTime,
  3483. StopReason: s.StopReason,
  3484. StopDoctor: s.StopDoctor,
  3485. StopState: s.StopState,
  3486. ParentId: s.ParentId,
  3487. ExecutionTime: s.ExecutionTime,
  3488. ExecutionStaff: s.ExecutionStaff,
  3489. ExecutionState: s.ExecutionState,
  3490. Checker: s.Checker,
  3491. RecordDate: s.RecordDate,
  3492. DialysisOrderId: s.DialysisOrderId,
  3493. CheckTime: s.CheckTime,
  3494. CheckState: s.CheckState,
  3495. DrugSpec: s.DrugSpec,
  3496. DrugSpecUnit: s.DrugSpecUnit,
  3497. Groupno: s.Groupno,
  3498. RemindType: s.RemindType,
  3499. FrequencyType: s.FrequencyType,
  3500. DayCount: s.DayCount,
  3501. WeekDay: s.WeekDay,
  3502. TemplateId: s.TemplateId,
  3503. Modifier: s.Modifier,
  3504. DrugId: s.DrugId,
  3505. Price: s.Price,
  3506. PrescriptionId: s.PrescriptionId,
  3507. MedListCodg: s.MedListCodg,
  3508. FeedetlSn: s.FeedetlSn,
  3509. Day: s.DayCount,
  3510. ChildDoctorAdvice: nil,
  3511. Drug: models.Drug{},
  3512. Diagnosis: s.Diagnosis,
  3513. Way: s.Way,
  3514. HospApprFlag: s.HospApprFlag,
  3515. LmtUsedFlag: s.LmtUsedFlag,
  3516. HisOrderInfo: models.HisOrderInfo{},
  3517. IsMedicine: s.IsMedicine,
  3518. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3519. Child: nil,
  3520. IsSettle: s.IsSettle,
  3521. IsMobile: s.IsMobile,
  3522. IsSelfDrug: s.IsSelfDrug,
  3523. DrugWayCount: s.DrugWayCount,
  3524. }
  3525. var history_count int64
  3526. var local_count int64
  3527. //查找已经开过的医嘱信息
  3528. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3529. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3530. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3531. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3532. local_count += prescribingNumberSevenTy * drug.MinNumber
  3533. }
  3534. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3535. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3536. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3537. local_count += prescribingNumberSevenTy
  3538. }
  3539. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3540. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3541. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3542. local_count += prescribingNumberSevenTy
  3543. }
  3544. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3545. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3546. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3547. history_count += prescribingNumberSevenTy * drug.MinNumber
  3548. }
  3549. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3550. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3551. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3552. history_count += prescribingNumberSevenTy
  3553. }
  3554. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3555. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3556. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3557. history_count += prescribingNumberSevenTy
  3558. }
  3559. fmt.Println("local_count---------------", local_count)
  3560. fmt.Println("history_count---------------", history_count)
  3561. //如果当前出库数量大于历史出库数量则需要出库
  3562. if local_count > history_count {
  3563. //按最小单位出库
  3564. var cha_count = local_count - history_count
  3565. newadviceInfo.PrescribingNumber = float64(cha_count)
  3566. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3567. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3568. }
  3569. //如果当前出库数量小于历史出库数量则需要退库
  3570. if local_count < history_count {
  3571. var cha_count = history_count - local_count
  3572. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3573. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3574. }
  3575. if local_count == history_count {
  3576. if is_user_total == 0 {
  3577. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3578. }
  3579. }
  3580. }
  3581. //更新字典里面的库存
  3582. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3583. var sum_count int64
  3584. for _, its := range stockInfo {
  3585. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3586. if its.MaxUnit == baseDrug.MaxUnit {
  3587. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3588. }
  3589. sum_count += its.StockMaxNumber + its.StockMinNumber
  3590. }
  3591. //更新基础库存
  3592. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3593. //剩余库存
  3594. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3595. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3596. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3597. //创建医嘱
  3598. service.CreateHisDoctorAdviceOne(&s, tx)
  3599. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3600. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3601. if len(outInfoTwo) > 0 {
  3602. for _, item := range outInfoTwo {
  3603. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3604. }
  3605. }
  3606. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3607. if len(drugAutoDetail) > 0 {
  3608. for _, item := range drugAutoDetail {
  3609. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3610. }
  3611. }
  3612. }
  3613. }
  3614. }
  3615. //记录日志
  3616. byterequest, _ := json.Marshal(s)
  3617. adviceLog := models.XtDoctorAdviceLog{
  3618. UserOrgId: s.UserOrgId,
  3619. PatientId: s.PatientId,
  3620. AdminUserId: adminInfo.AdminUser.Id,
  3621. Module: 1,
  3622. ErrLog: string(byterequest),
  3623. Status: 1,
  3624. Ctime: time.Now().Unix(),
  3625. Mtime: 0,
  3626. Source: "电脑端新建his医嘱",
  3627. RecordDate: s.AdviceDate,
  3628. }
  3629. service.CreateDoctorAdviceLog(adviceLog)
  3630. //存储切片中
  3631. adviceList = append(adviceList, s)
  3632. redis := service.RedisClient()
  3633. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3634. redis.Set(key, "", time.Second)
  3635. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3636. redis.Set(keyOne, "", time.Second)
  3637. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3638. redis.Set(keySeven, "", time.Second)
  3639. var randNum int
  3640. randNum = rand.Intn(10000) + 1000
  3641. timestamp := time.Now().Unix()
  3642. tempTime := time.Unix(timestamp, 0)
  3643. timeFormat := tempTime.Format("20060102150405")
  3644. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3645. //赤峰
  3646. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3647. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3648. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3649. if info.RetailPrice > 0 {
  3650. if s.DeliveryWay == "口服" {
  3651. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3652. s.Price = drug.RetailPrice
  3653. }
  3654. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3655. s.Price = info.RetailPrice
  3656. }
  3657. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3658. s.Price = info.RetailPrice
  3659. }
  3660. }
  3661. }
  3662. }
  3663. service.CreateHisDoctorAdviceOne(&s, tx)
  3664. tx.Commit()
  3665. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3666. redis.Set(keySix, "", time.Second)
  3667. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3668. redis.Set(keyFive, "", time.Second)
  3669. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3670. redis.Set(keyEight, "", time.Second)
  3671. defer redis.Close()
  3672. }
  3673. }
  3674. }
  3675. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3676. projects := items["project"].([]interface{})
  3677. if len(projects) > 0 {
  3678. for _, project := range projects {
  3679. tx := db.Begin()
  3680. // 在函数结束时处理事务回滚
  3681. defer func() {
  3682. if r := recover(); r != nil {
  3683. tx.Rollback()
  3684. }
  3685. }()
  3686. var p models.HisPrescriptionProject
  3687. p.PrescriptionId = tempPrescription.ID
  3688. p.PatientId = patient_id
  3689. p.RecordDate = theTime3.Unix()
  3690. p.Doctor = doctor_id
  3691. p.UserOrgId = adminInfo.CurrentOrgId
  3692. p.HisPatientId = his_patient_id
  3693. p.Status = 1
  3694. p.StartTime = pTime
  3695. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3696. if errcode > 0 {
  3697. tx.Rollback()
  3698. c.ServeFailJSONWithSGJErrorCode(errcode)
  3699. return
  3700. }
  3701. if p.ID == 0 {
  3702. p.IsOut = 2
  3703. }
  3704. if p.ID > 0 {
  3705. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3706. p.IsOut = projectDetail.IsOut
  3707. }
  3708. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3709. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3710. if p.Type == 3 {
  3711. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3712. if p.Price != lastWarehouse.PackingPrice {
  3713. p.Price = lastWarehouse.PackingPrice
  3714. }
  3715. if p.Price == 0 {
  3716. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3717. p.Price = lastWarehouseTwo.PackingPrice
  3718. }
  3719. if p.Unit == "" {
  3720. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3721. p.Unit = goodInfoOne.PackingUnit
  3722. }
  3723. }
  3724. }
  3725. if adminInfo.CurrentOrgId != 10206 {
  3726. if p.Type == 3 {
  3727. if p.ID == 0 {
  3728. //查询该耗材是否停用
  3729. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3730. //表示该耗材已经停用,不能保存
  3731. if goodInfoSeven.ID == 0 {
  3732. tx.Rollback()
  3733. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3734. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3735. return
  3736. }
  3737. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3738. if goodInfoOne.SumCount == 0 {
  3739. tx.Rollback()
  3740. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3741. return
  3742. }
  3743. }
  3744. if p.ID > 0 {
  3745. //查询该耗材是否停用
  3746. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3747. //表示该耗材已经停用,不能保存
  3748. if goodInfoSeven.ID == 0 {
  3749. tx.Rollback()
  3750. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3751. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3752. return
  3753. }
  3754. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3755. if goodInfoOne.SumCount == 0 {
  3756. tx.Rollback()
  3757. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3758. return
  3759. }
  3760. }
  3761. }
  3762. }
  3763. //查询保存耗材出库开关是否打开
  3764. if p.PatientId != 30038 {
  3765. //用机构ID区分
  3766. if adminInfo.CurrentOrgId != 9671 {
  3767. if goodOutConfig.IsOpen == 1 {
  3768. //耗材出库
  3769. if p.Type == 3 {
  3770. //对比当前数据和历史出库数据
  3771. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3772. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3773. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3774. //针对康德
  3775. if p.UserOrgId == 10164 || p.UserOrgId == 10402 {
  3776. //查询耗材的总入库数量
  3777. warehouseInfo, _ := service.GetAllWarehouseInfo(p.ProjectId, adminInfo.CurrentOrgId)
  3778. //查询该耗材的总出库数量
  3779. prescriptionGood, _ := service.GetHisPrescriptionByGoodId(p.ProjectId, adminInfo.CurrentOrgId)
  3780. var all_good_count int64
  3781. var prescription_count int64
  3782. if len(warehouseInfo) > 0 {
  3783. for _, item := range warehouseInfo {
  3784. all_good_count += item.WarehousingCount
  3785. }
  3786. }
  3787. if len(prescriptionGood) > 0 {
  3788. for _, item := range prescriptionGood {
  3789. hisCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3790. prescription_count += hisCount
  3791. }
  3792. }
  3793. fmt.Println("prescription_count-------------------------", prescription_count)
  3794. fmt.Println("nowCount-------------------------", nowCount)
  3795. fmt.Println("all_good_count-------------------------", all_good_count)
  3796. if prescription_count+nowCount > all_good_count {
  3797. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3798. tx.Rollback()
  3799. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3800. return
  3801. }
  3802. }
  3803. //如果当前处方数量大于历史数据,则需要出库
  3804. if nowCount > historyCount {
  3805. var cha_count int64
  3806. cha_count = nowCount - historyCount
  3807. timeStr := time.Now().Format("2006-01-02")
  3808. timeArr := strings.Split(timeStr, "-")
  3809. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3810. total = total + 1
  3811. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3812. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3813. number = number + total
  3814. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3815. operation_time := time.Now().Unix()
  3816. creater := c.GetAdminUserInfo().AdminUser.Id
  3817. recordDateStr := time.Now().Format("2006-01-02")
  3818. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3819. nowtime := recordDate.Unix()
  3820. warehouseOut := models.WarehouseOut{
  3821. WarehouseOutOrderNumber: warehousing_out_order,
  3822. OperationTime: operation_time,
  3823. OrgId: adminInfo.CurrentOrgId,
  3824. Creater: creater,
  3825. Ctime: time.Now().Unix(),
  3826. Status: 1,
  3827. WarehouseOutTime: nowtime,
  3828. Type: 1,
  3829. StorehouseId: storeConfig.StorehouseOutInfo,
  3830. IsCheck: 1,
  3831. IsSys: 1,
  3832. }
  3833. //查询是否生成出库单
  3834. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3835. if out.ID == 0 {
  3836. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3837. }
  3838. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3839. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3840. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3841. dialyPrepareOne := models.DialysisBeforePrepare{
  3842. GoodTypeId: goodObj.GoodTypeId,
  3843. GoodId: p.ProjectId,
  3844. PatientId: p.PatientId,
  3845. RecordDate: p.RecordDate,
  3846. UserOrgId: adminInfo.CurrentOrgId,
  3847. Count: cha_count,
  3848. Ctime: time.Now().Unix(),
  3849. Creater: creater,
  3850. Status: 1,
  3851. StorehouseId: houseConfig.StorehouseOutInfo,
  3852. ProjectId: p.ID,
  3853. }
  3854. //出库
  3855. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3856. }
  3857. //如果当前处方数量小于历史数据,怎需要退库
  3858. if nowCount < historyCount {
  3859. var cha_count int64
  3860. cha_count = historyCount - nowCount
  3861. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3862. creater := c.GetAdminUserInfo().AdminUser.Id
  3863. newPrescriptionProject := &models.HisPrescriptionProject{
  3864. ID: p.ID,
  3865. ProjectId: p.ProjectId,
  3866. Price: p.Price,
  3867. UserOrgId: p.UserOrgId,
  3868. Status: 1,
  3869. Ctime: time.Now().Unix(),
  3870. Mtime: time.Now().Unix(),
  3871. PatientId: p.PatientId,
  3872. HisPatientId: p.HisPatientId,
  3873. RecordDate: p.RecordDate,
  3874. PrescriptionId: p.PrescriptionId,
  3875. Count: p.Count,
  3876. FeedetlSn: p.FeedetlSn,
  3877. MedListCodg: p.MedListCodg,
  3878. SingleDose: p.SingleDose,
  3879. DeliveryWay: p.DeliveryWay,
  3880. ExecutionFrequency: p.ExecutionFrequency,
  3881. Day: p.Day,
  3882. HisProject: models.HisProject{},
  3883. GoodInfo: models.GoodInfo{},
  3884. Remark: p.Remark,
  3885. Unit: p.Unit,
  3886. Type: p.Type,
  3887. Doctor: p.Doctor,
  3888. ExecutionTime: p.ExecutionTime,
  3889. ExecutionStaff: p.ExecutionStaff,
  3890. ExecutionState: p.ExecutionState,
  3891. CheckTime: p.CheckTime,
  3892. CheckState: p.CheckState,
  3893. Checker: p.Checker,
  3894. StartTime: p.StartTime,
  3895. TeamId: p.TeamId,
  3896. XtHisProjectTeam: models.XtHisProjectTeam{},
  3897. FrequencyType: p.FrequencyType,
  3898. DayCount: p.DayCount,
  3899. WeekDay: p.WeekDay,
  3900. IsCheckTeam: p.IsCheckTeam,
  3901. HisOrderInfo: models.HisOrderInfo{},
  3902. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3903. IsOut: p.IsOut,
  3904. YbSyncStatus: p.YbSyncStatus,
  3905. }
  3906. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3907. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3908. }
  3909. if nowCount == historyCount {
  3910. if historyCount == 0 {
  3911. recordDateStr := time.Now().Format("2006-01-02")
  3912. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3913. nowtime := recordDate.Unix()
  3914. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3915. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3916. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3917. creater := c.GetAdminUserInfo().AdminUser.Id
  3918. dialyPrepareOne := models.DialysisBeforePrepare{
  3919. GoodTypeId: goodObj.GoodTypeId,
  3920. GoodId: p.ProjectId,
  3921. PatientId: p.PatientId,
  3922. RecordDate: p.RecordDate,
  3923. UserOrgId: adminInfo.CurrentOrgId,
  3924. Count: nowCount,
  3925. Ctime: time.Now().Unix(),
  3926. Creater: creater,
  3927. Status: 1,
  3928. StorehouseId: houseConfig.StorehouseOutInfo,
  3929. ProjectId: p.ID,
  3930. }
  3931. //出库
  3932. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3933. }
  3934. }
  3935. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3936. //查询历史出库数据
  3937. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3938. var out_count_five int64
  3939. for _, item := range flowGood {
  3940. out_count_five += item.Count
  3941. }
  3942. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3943. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3944. if out_count_five != parseIntCount {
  3945. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3946. detail := models.AutomaticReduceDetail{
  3947. WarehouseOutId: 0,
  3948. WarehouseOutOrderNumber: "",
  3949. PatientId: p.PatientId,
  3950. Ctime: time.Now().Unix(),
  3951. Mtime: 0,
  3952. Status: 1,
  3953. RecordTime: p.RecordDate,
  3954. OrgId: p.UserOrgId,
  3955. GoodId: p.ProjectId,
  3956. GoodTypeId: 0,
  3957. Count: parseIntCount,
  3958. Type: 0,
  3959. ProjectId: lastHisProject.ID,
  3960. StorehouseId: 0,
  3961. }
  3962. service.CreateNewAutoDetail(detail, tx)
  3963. }
  3964. // //查询耗材最后一次出库记录
  3965. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3966. // //查询默认出库仓库库存
  3967. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3968. // if len(wareOut) > 0 {
  3969. //
  3970. // for _, it := range wareOut {
  3971. // //回退库存
  3972. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3973. //
  3974. // //删除出库记录
  3975. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3976. //
  3977. // }
  3978. // }
  3979. //
  3980. // timeStr := time.Now().Format("2006-01-02")
  3981. // timeArr := strings.Split(timeStr, "-")
  3982. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3983. //
  3984. // total = total + 1
  3985. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3986. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3987. // number = number + total
  3988. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3989. //
  3990. // operation_time := time.Now().Unix()
  3991. // creater := c.GetAdminUserInfo().AdminUser.Id
  3992. //
  3993. // recordDateStr := time.Now().Format("2006-01-02")
  3994. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3995. // nowtime := recordDate.Unix()
  3996. // warehouseOut := models.WarehouseOut{
  3997. // WarehouseOutOrderNumber: warehousing_out_order,
  3998. // OperationTime: operation_time,
  3999. // OrgId: adminInfo.CurrentOrgId,
  4000. // Creater: creater,
  4001. // Ctime: time.Now().Unix(),
  4002. // Status: 1,
  4003. // WarehouseOutTime: nowtime,
  4004. // Type: 1,
  4005. // StorehouseId: storeConfig.StorehouseOutInfo,
  4006. // IsCheck: 1,
  4007. // IsSys: 1,
  4008. // }
  4009. // //查询是否生成出库单
  4010. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4011. // if out.ID == 0 {
  4012. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4013. // }
  4014. //
  4015. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4016. //
  4017. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4018. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4019. //
  4020. // dialyPrepareOne := models.DialysisBeforePrepare{
  4021. // GoodTypeId: goodObj.GoodTypeId,
  4022. // GoodId: p.ProjectId,
  4023. // PatientId: p.PatientId,
  4024. // RecordDate: p.RecordDate,
  4025. // UserOrgId: adminInfo.CurrentOrgId,
  4026. // Count: parseIntCount,
  4027. // Ctime: time.Now().Unix(),
  4028. // Creater: creater,
  4029. // Status: 1,
  4030. // StorehouseId: houseConfig.StorehouseOutInfo,
  4031. // ProjectId: lastHisProject.ID,
  4032. // }
  4033. // //判断是否是零用耗材(非零用)
  4034. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4035. //
  4036. // //查询历史出库数据
  4037. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4038. // var out_count int64
  4039. // for _, item := range flowGood {
  4040. // out_count += item.Count
  4041. // }
  4042. // //如果历史数和当前数据不想等才进行退库出库
  4043. // if out_count != parseIntCount {
  4044. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4045. //
  4046. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4047. // detail := models.AutomaticReduceDetail{
  4048. // WarehouseOutId: 0,
  4049. // WarehouseOutOrderNumber: "",
  4050. // PatientId: p.PatientId,
  4051. // Ctime: time.Now().Unix(),
  4052. // Mtime: 0,
  4053. // Status: 1,
  4054. // RecordTime: p.RecordDate,
  4055. // OrgId: p.UserOrgId,
  4056. // GoodId: p.ProjectId,
  4057. // GoodTypeId: 0,
  4058. // Count: parseIntCount,
  4059. // Type: 0,
  4060. // ProjectId: lastHisProject.ID,
  4061. // StorehouseId: 0,
  4062. // }
  4063. //
  4064. // service.CreateNewAutoDetail(detail, tx)
  4065. //
  4066. // //查询剩余库存
  4067. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4068. // var sum_count int64
  4069. // for _, item := range goodList {
  4070. // sum_count += item.StockCount
  4071. // }
  4072. //
  4073. // //更新剩余库存
  4074. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4075. //
  4076. // //耗材
  4077. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4078. //
  4079. // }
  4080. // //判断是否是零用耗材(零用但是是出库耗材)
  4081. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4082. //
  4083. // //查询历史出库数据
  4084. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4085. // var out_count int64
  4086. // for _, item := range flowGood {
  4087. // out_count += item.Count
  4088. // }
  4089. // //如果历史数和当前数据不想等才进行退库出库
  4090. // if out_count != parseIntCount {
  4091. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4092. //
  4093. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4094. // detail := models.AutomaticReduceDetail{
  4095. // WarehouseOutId: 0,
  4096. // WarehouseOutOrderNumber: "",
  4097. // PatientId: p.PatientId,
  4098. // Ctime: time.Now().Unix(),
  4099. // Mtime: 0,
  4100. // Status: 1,
  4101. // RecordTime: p.RecordDate,
  4102. // OrgId: p.UserOrgId,
  4103. // GoodId: p.ProjectId,
  4104. // GoodTypeId: 0,
  4105. // Count: parseIntCount,
  4106. // Type: 0,
  4107. // ProjectId: p.ID,
  4108. // StorehouseId: 0,
  4109. // }
  4110. //
  4111. // service.CreateNewAutoDetail(detail, tx)
  4112. //
  4113. // //查询剩余库存
  4114. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4115. // var sum_count int64
  4116. // for _, item := range goodList {
  4117. // sum_count += item.StockCount
  4118. // }
  4119. //
  4120. // //更新剩余库存
  4121. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4122. //
  4123. // //耗材
  4124. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4125. // }
  4126. //
  4127. // }
  4128. //
  4129. // }
  4130. //
  4131. //}
  4132. //记录日志
  4133. byterequest, _ := json.Marshal(p)
  4134. adviceLog := models.XtDoctorAdviceLog{
  4135. UserOrgId: p.UserOrgId,
  4136. PatientId: p.PatientId,
  4137. AdminUserId: adminInfo.AdminUser.Id,
  4138. Module: 1,
  4139. ErrLog: string(byterequest),
  4140. Status: 1,
  4141. Ctime: time.Now().Unix(),
  4142. Mtime: 0,
  4143. Source: "电脑端新建his项目",
  4144. RecordDate: p.RecordDate,
  4145. }
  4146. service.CreateDoctorAdviceLog(adviceLog)
  4147. projectList = append(projectList, p)
  4148. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4149. //新增或者编辑项目,修改对应的标签数据
  4150. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4151. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4152. var label models.HisLabelPrintInfo
  4153. project, _ := service.GetProjectDetail(p.ProjectId)
  4154. if project.CostClassify == 3 { //类别为检验检查
  4155. if p.TeamId > 0 { //检验检查组套
  4156. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4157. if tempLabel.ID == 0 {
  4158. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4159. label.Number = tempPrescription.PrescriptionNumber
  4160. label.ProjectId = project.ID
  4161. label.Status = 1
  4162. label.IsPrint = 2
  4163. label.DoctorId = info.DoctorId
  4164. label.UserOrgId = p.UserOrgId
  4165. label.PatientId = patient_id
  4166. label.RecordDate = recordDateTime
  4167. label.Ctime = time.Now().Unix()
  4168. label.Mtime = time.Now().Unix()
  4169. label.ItemId = p.TeamId
  4170. label.FeedetlSn = p.FeedetlSn
  4171. label.PProjectId = p.ID
  4172. label.ProjectName = team.ProjectTeam
  4173. label.PatientName = patient.Name
  4174. service.CreateNewHisLabelRecord(&label, tx)
  4175. }
  4176. } else { //单条检验检查项目
  4177. label.Number = tempPrescription.PrescriptionNumber
  4178. label.ProjectId = project.ID
  4179. label.Status = 1
  4180. label.DoctorId = info.DoctorId
  4181. label.UserOrgId = p.UserOrgId
  4182. label.PatientId = patient_id
  4183. label.RecordDate = recordDateTime
  4184. label.IsPrint = 2
  4185. label.Ctime = time.Now().Unix()
  4186. label.Mtime = time.Now().Unix()
  4187. label.FeedetlSn = p.FeedetlSn
  4188. label.PProjectId = p.ID
  4189. label.ItemId = p.TeamId
  4190. label.ProjectName = project.ProjectName
  4191. label.PatientName = patient.Name
  4192. service.CreateNewHisLabelRecord(&label, tx)
  4193. }
  4194. }
  4195. }
  4196. }
  4197. }
  4198. }
  4199. }
  4200. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4201. //耗材出库
  4202. if p.Type == 3 {
  4203. //对比当前数据和历史出库数据
  4204. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4205. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4206. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4207. //如果当前处方数量大于历史数据,则需要出库
  4208. if nowCount > historyCount {
  4209. var cha_count int64
  4210. cha_count = nowCount - historyCount
  4211. timeStr := time.Now().Format("2006-01-02")
  4212. timeArr := strings.Split(timeStr, "-")
  4213. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4214. total = total + 1
  4215. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4216. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4217. number = number + total
  4218. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4219. operation_time := time.Now().Unix()
  4220. creater := c.GetAdminUserInfo().AdminUser.Id
  4221. recordDateStr := time.Now().Format("2006-01-02")
  4222. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4223. nowtime := recordDate.Unix()
  4224. warehouseOut := models.WarehouseOut{
  4225. WarehouseOutOrderNumber: warehousing_out_order,
  4226. OperationTime: operation_time,
  4227. OrgId: adminInfo.CurrentOrgId,
  4228. Creater: creater,
  4229. Ctime: time.Now().Unix(),
  4230. Status: 1,
  4231. WarehouseOutTime: nowtime,
  4232. Type: 1,
  4233. StorehouseId: storeConfig.StorehouseOutInfo,
  4234. IsCheck: 1,
  4235. IsSys: 1,
  4236. }
  4237. //查询是否生成出库单
  4238. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4239. if out.ID == 0 {
  4240. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4241. }
  4242. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4243. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4244. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4245. dialyPrepareOne := models.DialysisBeforePrepare{
  4246. GoodTypeId: goodObj.GoodTypeId,
  4247. GoodId: p.ProjectId,
  4248. PatientId: p.PatientId,
  4249. RecordDate: p.RecordDate,
  4250. UserOrgId: adminInfo.CurrentOrgId,
  4251. Count: cha_count,
  4252. Ctime: time.Now().Unix(),
  4253. Creater: creater,
  4254. Status: 1,
  4255. StorehouseId: houseConfig.StorehouseOutInfo,
  4256. ProjectId: p.ID,
  4257. }
  4258. //出库
  4259. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4260. }
  4261. //如果当前处方数量小于历史数据,怎需要退库
  4262. if nowCount < historyCount {
  4263. var cha_count int64
  4264. cha_count = historyCount - nowCount
  4265. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4266. creater := c.GetAdminUserInfo().AdminUser.Id
  4267. newPrescriptionProject := &models.HisPrescriptionProject{
  4268. ID: p.ID,
  4269. ProjectId: p.ProjectId,
  4270. Price: p.Price,
  4271. UserOrgId: p.UserOrgId,
  4272. Status: 1,
  4273. Ctime: time.Now().Unix(),
  4274. Mtime: time.Now().Unix(),
  4275. PatientId: p.PatientId,
  4276. HisPatientId: p.HisPatientId,
  4277. RecordDate: p.RecordDate,
  4278. PrescriptionId: p.PrescriptionId,
  4279. Count: p.Count,
  4280. FeedetlSn: p.FeedetlSn,
  4281. MedListCodg: p.MedListCodg,
  4282. SingleDose: p.SingleDose,
  4283. DeliveryWay: p.DeliveryWay,
  4284. ExecutionFrequency: p.ExecutionFrequency,
  4285. Day: p.Day,
  4286. HisProject: models.HisProject{},
  4287. GoodInfo: models.GoodInfo{},
  4288. Remark: p.Remark,
  4289. Unit: p.Unit,
  4290. Type: p.Type,
  4291. Doctor: p.Doctor,
  4292. ExecutionTime: p.ExecutionTime,
  4293. ExecutionStaff: p.ExecutionStaff,
  4294. ExecutionState: p.ExecutionState,
  4295. CheckTime: p.CheckTime,
  4296. CheckState: p.CheckState,
  4297. Checker: p.Checker,
  4298. StartTime: p.StartTime,
  4299. TeamId: p.TeamId,
  4300. XtHisProjectTeam: models.XtHisProjectTeam{},
  4301. FrequencyType: p.FrequencyType,
  4302. DayCount: p.DayCount,
  4303. WeekDay: p.WeekDay,
  4304. IsCheckTeam: p.IsCheckTeam,
  4305. HisOrderInfo: models.HisOrderInfo{},
  4306. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4307. IsOut: p.IsOut,
  4308. YbSyncStatus: p.YbSyncStatus,
  4309. }
  4310. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4311. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4312. }
  4313. if nowCount == historyCount {
  4314. if historyCount == 0 {
  4315. recordDateStr := time.Now().Format("2006-01-02")
  4316. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4317. nowtime := recordDate.Unix()
  4318. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4319. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4320. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4321. creater := c.GetAdminUserInfo().AdminUser.Id
  4322. dialyPrepareOne := models.DialysisBeforePrepare{
  4323. GoodTypeId: goodObj.GoodTypeId,
  4324. GoodId: p.ProjectId,
  4325. PatientId: p.PatientId,
  4326. RecordDate: p.RecordDate,
  4327. UserOrgId: adminInfo.CurrentOrgId,
  4328. Count: nowCount,
  4329. Ctime: time.Now().Unix(),
  4330. Creater: creater,
  4331. Status: 1,
  4332. StorehouseId: houseConfig.StorehouseOutInfo,
  4333. ProjectId: p.ID,
  4334. }
  4335. //出库
  4336. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4337. }
  4338. }
  4339. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4340. //查询历史出库数据
  4341. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4342. var out_count_five int64
  4343. for _, item := range flowGood {
  4344. out_count_five += item.Count
  4345. }
  4346. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4347. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4348. if out_count_five != parseIntCount {
  4349. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4350. detail := models.AutomaticReduceDetail{
  4351. WarehouseOutId: 0,
  4352. WarehouseOutOrderNumber: "",
  4353. PatientId: p.PatientId,
  4354. Ctime: time.Now().Unix(),
  4355. Mtime: 0,
  4356. Status: 1,
  4357. RecordTime: p.RecordDate,
  4358. OrgId: p.UserOrgId,
  4359. GoodId: p.ProjectId,
  4360. GoodTypeId: 0,
  4361. Count: parseIntCount,
  4362. Type: 0,
  4363. ProjectId: lastHisProject.ID,
  4364. StorehouseId: 0,
  4365. }
  4366. service.CreateNewAutoDetail(detail, tx)
  4367. }
  4368. // //查询耗材最后一次出库记录
  4369. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4370. // //查询默认出库仓库库存
  4371. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4372. // if len(wareOut) > 0 {
  4373. //
  4374. // for _, it := range wareOut {
  4375. // //回退库存
  4376. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4377. //
  4378. // //删除出库记录
  4379. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4380. //
  4381. // }
  4382. // }
  4383. //
  4384. // timeStr := time.Now().Format("2006-01-02")
  4385. // timeArr := strings.Split(timeStr, "-")
  4386. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4387. //
  4388. // total = total + 1
  4389. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4390. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4391. // number = number + total
  4392. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4393. //
  4394. // operation_time := time.Now().Unix()
  4395. // creater := c.GetAdminUserInfo().AdminUser.Id
  4396. //
  4397. // recordDateStr := time.Now().Format("2006-01-02")
  4398. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4399. // nowtime := recordDate.Unix()
  4400. // warehouseOut := models.WarehouseOut{
  4401. // WarehouseOutOrderNumber: warehousing_out_order,
  4402. // OperationTime: operation_time,
  4403. // OrgId: adminInfo.CurrentOrgId,
  4404. // Creater: creater,
  4405. // Ctime: time.Now().Unix(),
  4406. // Status: 1,
  4407. // WarehouseOutTime: nowtime,
  4408. // Type: 1,
  4409. // StorehouseId: storeConfig.StorehouseOutInfo,
  4410. // IsCheck: 1,
  4411. // IsSys: 1,
  4412. // }
  4413. // //查询是否生成出库单
  4414. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4415. // if out.ID == 0 {
  4416. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4417. // }
  4418. //
  4419. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4420. //
  4421. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4422. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4423. //
  4424. // dialyPrepareOne := models.DialysisBeforePrepare{
  4425. // GoodTypeId: goodObj.GoodTypeId,
  4426. // GoodId: p.ProjectId,
  4427. // PatientId: p.PatientId,
  4428. // RecordDate: p.RecordDate,
  4429. // UserOrgId: adminInfo.CurrentOrgId,
  4430. // Count: parseIntCount,
  4431. // Ctime: time.Now().Unix(),
  4432. // Creater: creater,
  4433. // Status: 1,
  4434. // StorehouseId: houseConfig.StorehouseOutInfo,
  4435. // ProjectId: lastHisProject.ID,
  4436. // }
  4437. // //判断是否是零用耗材(非零用)
  4438. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4439. //
  4440. // //查询历史出库数据
  4441. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4442. // var out_count int64
  4443. // for _, item := range flowGood {
  4444. // out_count += item.Count
  4445. // }
  4446. // //如果历史数和当前数据不想等才进行退库出库
  4447. // if out_count != parseIntCount {
  4448. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4449. //
  4450. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4451. // detail := models.AutomaticReduceDetail{
  4452. // WarehouseOutId: 0,
  4453. // WarehouseOutOrderNumber: "",
  4454. // PatientId: p.PatientId,
  4455. // Ctime: time.Now().Unix(),
  4456. // Mtime: 0,
  4457. // Status: 1,
  4458. // RecordTime: p.RecordDate,
  4459. // OrgId: p.UserOrgId,
  4460. // GoodId: p.ProjectId,
  4461. // GoodTypeId: 0,
  4462. // Count: parseIntCount,
  4463. // Type: 0,
  4464. // ProjectId: lastHisProject.ID,
  4465. // StorehouseId: 0,
  4466. // }
  4467. //
  4468. // service.CreateNewAutoDetail(detail, tx)
  4469. //
  4470. // //查询剩余库存
  4471. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4472. // var sum_count int64
  4473. // for _, item := range goodList {
  4474. // sum_count += item.StockCount
  4475. // }
  4476. //
  4477. // //更新剩余库存
  4478. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4479. //
  4480. // //耗材
  4481. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4482. //
  4483. // }
  4484. // //判断是否是零用耗材(零用但是是出库耗材)
  4485. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4486. //
  4487. // //查询历史出库数据
  4488. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4489. // var out_count int64
  4490. // for _, item := range flowGood {
  4491. // out_count += item.Count
  4492. // }
  4493. // //如果历史数和当前数据不想等才进行退库出库
  4494. // if out_count != parseIntCount {
  4495. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4496. //
  4497. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4498. // detail := models.AutomaticReduceDetail{
  4499. // WarehouseOutId: 0,
  4500. // WarehouseOutOrderNumber: "",
  4501. // PatientId: p.PatientId,
  4502. // Ctime: time.Now().Unix(),
  4503. // Mtime: 0,
  4504. // Status: 1,
  4505. // RecordTime: p.RecordDate,
  4506. // OrgId: p.UserOrgId,
  4507. // GoodId: p.ProjectId,
  4508. // GoodTypeId: 0,
  4509. // Count: parseIntCount,
  4510. // Type: 0,
  4511. // ProjectId: p.ID,
  4512. // StorehouseId: 0,
  4513. // }
  4514. //
  4515. // service.CreateNewAutoDetail(detail, tx)
  4516. //
  4517. // //查询剩余库存
  4518. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4519. // var sum_count int64
  4520. // for _, item := range goodList {
  4521. // sum_count += item.StockCount
  4522. // }
  4523. //
  4524. // //更新剩余库存
  4525. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4526. //
  4527. // //耗材
  4528. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4529. // }
  4530. //
  4531. // }
  4532. //
  4533. // }
  4534. //
  4535. //}
  4536. //记录日志
  4537. byterequest, _ := json.Marshal(p)
  4538. adviceLog := models.XtDoctorAdviceLog{
  4539. UserOrgId: p.UserOrgId,
  4540. PatientId: p.PatientId,
  4541. AdminUserId: adminInfo.AdminUser.Id,
  4542. Module: 1,
  4543. ErrLog: string(byterequest),
  4544. Status: 1,
  4545. Ctime: time.Now().Unix(),
  4546. Mtime: 0,
  4547. Source: "电脑端新建his项目",
  4548. RecordDate: p.RecordDate,
  4549. }
  4550. service.CreateDoctorAdviceLog(adviceLog)
  4551. projectList = append(projectList, p)
  4552. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4553. //新增或者编辑项目,修改对应的标签数据
  4554. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4555. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4556. var label models.HisLabelPrintInfo
  4557. project, _ := service.GetProjectDetail(p.ProjectId)
  4558. if project.CostClassify == 3 { //类别为检验检查
  4559. if p.TeamId > 0 { //检验检查组套
  4560. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4561. if tempLabel.ID == 0 {
  4562. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4563. label.Number = tempPrescription.PrescriptionNumber
  4564. label.ProjectId = project.ID
  4565. label.Status = 1
  4566. label.IsPrint = 2
  4567. label.DoctorId = info.DoctorId
  4568. label.UserOrgId = p.UserOrgId
  4569. label.PatientId = patient_id
  4570. label.RecordDate = recordDateTime
  4571. label.Ctime = time.Now().Unix()
  4572. label.Mtime = time.Now().Unix()
  4573. label.ItemId = p.TeamId
  4574. label.FeedetlSn = p.FeedetlSn
  4575. label.PProjectId = p.ID
  4576. label.ProjectName = team.ProjectTeam
  4577. label.PatientName = patient.Name
  4578. service.CreateNewHisLabelRecord(&label, tx)
  4579. }
  4580. } else { //单条检验检查项目
  4581. label.Number = tempPrescription.PrescriptionNumber
  4582. label.ProjectId = project.ID
  4583. label.Status = 1
  4584. label.DoctorId = info.DoctorId
  4585. label.UserOrgId = p.UserOrgId
  4586. label.PatientId = patient_id
  4587. label.RecordDate = recordDateTime
  4588. label.IsPrint = 2
  4589. label.Ctime = time.Now().Unix()
  4590. label.Mtime = time.Now().Unix()
  4591. label.FeedetlSn = p.FeedetlSn
  4592. label.PProjectId = p.ID
  4593. label.ItemId = p.TeamId
  4594. label.ProjectName = project.ProjectName
  4595. label.PatientName = patient.Name
  4596. service.CreateNewHisLabelRecord(&label, tx)
  4597. }
  4598. }
  4599. }
  4600. }
  4601. }
  4602. }
  4603. }
  4604. //插入检验数据
  4605. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4606. //新增或者编辑项目,修改对应的标签数据
  4607. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4608. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4609. var label models.HisLabelPrintInfo
  4610. project, _ := service.GetProjectDetail(p.ProjectId)
  4611. if project.CostClassify == 3 { //类别为检验检查
  4612. if p.TeamId > 0 { //检验检查组套
  4613. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4614. if tempLabel.ID == 0 {
  4615. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4616. label.Number = tempPrescription.PrescriptionNumber
  4617. label.ProjectId = project.ID
  4618. label.Status = 1
  4619. label.IsPrint = 2
  4620. label.DoctorId = info.DoctorId
  4621. label.UserOrgId = p.UserOrgId
  4622. label.PatientId = patient_id
  4623. label.RecordDate = recordDateTime
  4624. label.Ctime = time.Now().Unix()
  4625. label.Mtime = time.Now().Unix()
  4626. label.ItemId = p.TeamId
  4627. label.FeedetlSn = p.FeedetlSn
  4628. label.PProjectId = p.ID
  4629. label.ProjectName = team.ProjectTeam
  4630. label.PatientName = patient.Name
  4631. service.CreateHisLabelRecord(&label)
  4632. }
  4633. } else { //单条检验检查项目
  4634. label.Number = tempPrescription.PrescriptionNumber
  4635. label.ProjectId = project.ID
  4636. label.Status = 1
  4637. label.DoctorId = info.DoctorId
  4638. label.UserOrgId = p.UserOrgId
  4639. label.PatientId = patient_id
  4640. label.RecordDate = recordDateTime
  4641. label.IsPrint = 2
  4642. label.Ctime = time.Now().Unix()
  4643. label.Mtime = time.Now().Unix()
  4644. label.FeedetlSn = p.FeedetlSn
  4645. label.PProjectId = p.ID
  4646. label.ItemId = p.TeamId
  4647. label.ProjectName = project.ProjectName
  4648. label.PatientName = patient.Name
  4649. service.CreateHisLabelRecord(&label)
  4650. }
  4651. }
  4652. }
  4653. }
  4654. service.CreateNewHisProjectTwo(&p, tx)
  4655. var randNum int
  4656. randNum = rand.Intn(10000) + 1000
  4657. timestamp := time.Now().Unix()
  4658. tempTime := time.Unix(timestamp, 0)
  4659. timeFormat := tempTime.Format("20060102150405")
  4660. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4661. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4662. if goodBase.ID > 0 {
  4663. tx.Rollback()
  4664. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4665. return
  4666. }
  4667. service.CreateNewHisProjectTwo(&p, tx)
  4668. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4669. //查询剩余库存
  4670. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4671. var sum_count int64
  4672. for _, item := range goodList {
  4673. sum_count += item.StockCount
  4674. }
  4675. //更新剩余库存
  4676. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4677. //耗材
  4678. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4679. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4680. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4681. if len(outInfoTwo) > 0 {
  4682. for _, item := range outInfoTwo {
  4683. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4684. }
  4685. }
  4686. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4687. if len(drugAutoDetail) > 0 {
  4688. for _, item := range drugAutoDetail {
  4689. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4690. }
  4691. }
  4692. tx.Commit()
  4693. }
  4694. }
  4695. }
  4696. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4697. // addition := items["addition"].([]interface{})
  4698. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4699. // ctime := time.Now().Unix()
  4700. // mtime := ctime
  4701. // if len(addition) > 0 {
  4702. // for _, item := range addition {
  4703. // var s models.HisAdditionalCharge
  4704. // s.PrescriptionId = tempPrescription.ID
  4705. // s.Status = 1
  4706. // s.UserOrgId = adminInfo.CurrentOrgId
  4707. // s.RecordDate = recordDateTime
  4708. // s.CreatedTime = ctime
  4709. // s.UpdatedTime = mtime
  4710. // s.PatientId = patient_id
  4711. // s.HisPatientId = his_patient_id
  4712. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4713. // if errcode > 0 {
  4714. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4715. // return
  4716. // }
  4717. // service.CreateAdditionalCharge(&s)
  4718. // var randNum int
  4719. // randNum = rand.Intn(10000) + 1000
  4720. // timestamp := time.Now().Unix()
  4721. // tempTime := time.Unix(timestamp, 0)
  4722. // timeFormat := tempTime.Format("20060102150405")
  4723. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4724. // service.CreateAdditionalCharge(&s)
  4725. //
  4726. // }
  4727. // }
  4728. //}
  4729. }
  4730. }
  4731. }
  4732. tx.Commit()
  4733. if err == nil {
  4734. c.ServeSuccessJSON(map[string]interface{}{
  4735. "msg": "保存成功",
  4736. })
  4737. return
  4738. } else {
  4739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4740. return
  4741. }
  4742. } else {
  4743. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4744. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4745. var tempPrescription *models.HisPrescription
  4746. if len(prescriptions) > 0 {
  4747. for _, item := range prescriptions {
  4748. items := item.(map[string]interface{})
  4749. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4750. utils.ErrorLog("id")
  4751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4752. return
  4753. }
  4754. id := int64(items["id"].(float64))
  4755. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4756. tempPrescription = &new_prescription
  4757. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4758. utils.ErrorLog("type")
  4759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4760. return
  4761. }
  4762. types := int64(items["type"].(float64))
  4763. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4764. utils.ErrorLog("med_type")
  4765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4766. return
  4767. }
  4768. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4769. if med_type == "0" {
  4770. med_type = "14"
  4771. }
  4772. //if order_status == 0 {
  4773. // order_status = 1
  4774. //}
  4775. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4776. // utils.ErrorLog("diagnoses")
  4777. //}
  4778. diagnoses, _ := items["diagnoses"].(string)
  4779. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4780. utils.ErrorLog("pre_time")
  4781. }
  4782. preTime, _ := items["pre_time"].(string)
  4783. timeLayout := "2006-01-02"
  4784. loc, _ := time.LoadLocation("Local")
  4785. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4786. //result := strings.Split(preTime, " ")
  4787. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4788. if err != nil {
  4789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4790. return
  4791. }
  4792. pTime := theTime2.Unix()
  4793. ctime := time.Now().Unix()
  4794. if tempPrescription.ID == 0 {
  4795. prescription := &models.HisPrescription{
  4796. ID: 0,
  4797. PatientId: patient_id,
  4798. UserOrgId: adminInfo.CurrentOrgId,
  4799. RecordDate: recordDateTime,
  4800. Ctime: ctime,
  4801. Mtime: ctime,
  4802. Type: types,
  4803. Modifier: adminInfo.AdminUser.Id,
  4804. Creator: adminInfo.AdminUser.Id,
  4805. Status: 1,
  4806. Doctor: role.UserName,
  4807. HisPatientId: his_patient_id,
  4808. OrderStatus: 1,
  4809. BatchNumber: "",
  4810. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4811. PreTime: pTime,
  4812. PType: p_type,
  4813. MedType: med_type,
  4814. Diagnose: diagnoses,
  4815. }
  4816. tempPrescription = prescription
  4817. service.SaveHisPrescription(tempPrescription)
  4818. redis := service.RedisClient()
  4819. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4820. redis.Set(key, "", time.Second)
  4821. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4822. redis.Set(keyOne, "", time.Second)
  4823. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4824. redis.Set(keySeven, "", time.Second)
  4825. defer redis.Close()
  4826. } else {
  4827. tempPrescription.ID = id
  4828. tempPrescription.Type = types
  4829. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4830. tempPrescription.Mtime = time.Now().Unix()
  4831. tempPrescription.Doctor = role.UserName
  4832. //tempPrescription.OrderStatus = order_status
  4833. tempPrescription.PreTime = pTime
  4834. tempPrescription.MedType = med_type
  4835. tempPrescription.Diagnose = diagnoses
  4836. service.SaveHisPrescription(tempPrescription)
  4837. redis := service.RedisClient()
  4838. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4839. redis.Set(key, "", time.Second)
  4840. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4841. redis.Set(keyOne, "", time.Second)
  4842. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4843. redis.Set(keySeven, "", time.Second)
  4844. defer redis.Close()
  4845. }
  4846. //service.SaveHisPrescription(prescription)
  4847. //更改患者挂号状态
  4848. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4849. fmt.Println("更改失败", err2)
  4850. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4851. advices := items["advices"].([]interface{})
  4852. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4853. groupNo := int64(0)
  4854. if len(advices) > 0 {
  4855. for _, advice := range advices {
  4856. var s models.HisDoctorAdviceInfo
  4857. s.PrescriptionId = tempPrescription.ID
  4858. s.AdviceType = 2
  4859. s.AdviceDoctor = doctor_id
  4860. s.StopState = 2
  4861. s.ExecutionState = 2
  4862. s.AdviceDate = theTime3.Unix()
  4863. s.Status = 1
  4864. s.UserOrgId = adminInfo.CurrentOrgId
  4865. s.RecordDate = theTime3.Unix()
  4866. s.StartTime = tempPrescription.PreTime
  4867. s.Groupno = groupNo
  4868. s.PatientId = patient_id
  4869. s.HisPatientId = his_patient_id
  4870. s.StartTime = pTime
  4871. s.IsSettle = 2
  4872. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4873. if errcode > 0 {
  4874. c.ServeFailJSONWithSGJErrorCode(errcode)
  4875. return
  4876. }
  4877. s.StartTime = pTime
  4878. var total_count int64 //处方总库存
  4879. //查询改药品信息
  4880. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4881. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4882. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4883. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4884. total_count += prescribingNumberSeven * medical.MinNumber
  4885. }
  4886. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4887. total_count += prescribingNumberSeven
  4888. }
  4889. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4890. total_count += prescribingNumberSeven
  4891. }
  4892. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4893. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4894. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4895. if s.Price != lastWarehouse.RetailPrice {
  4896. s.Price = lastWarehouse.RetailPrice
  4897. }
  4898. if s.Price == 0 {
  4899. if lastWarehouse.ID == 0 {
  4900. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4901. s.Price = lastWarehouseTwo.RetailPrice
  4902. }
  4903. }
  4904. }
  4905. if adminInfo.CurrentOrgId != 10206 {
  4906. if s.ID == 0 {
  4907. //查询改药品是否已经停用
  4908. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4909. if base.ID > 0 {
  4910. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4911. return
  4912. }
  4913. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4914. if drugMedical.SumCount == 0 {
  4915. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4916. return
  4917. }
  4918. }
  4919. }
  4920. //赤峰
  4921. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4922. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4923. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4924. if info.RetailPrice > 0 {
  4925. if s.DeliveryWay == "口服" {
  4926. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4927. s.Price = drug.RetailPrice
  4928. }
  4929. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4930. s.Price = info.RetailPrice
  4931. }
  4932. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4933. s.Price = info.RetailPrice
  4934. }
  4935. }
  4936. }
  4937. }
  4938. service.CreateHisDoctorAdvice(&s)
  4939. //记录日志
  4940. byterequest, _ := json.Marshal(s)
  4941. adviceLog := models.XtDoctorAdviceLog{
  4942. UserOrgId: s.UserOrgId,
  4943. PatientId: s.PatientId,
  4944. AdminUserId: adminInfo.AdminUser.Id,
  4945. Module: 1,
  4946. ErrLog: string(byterequest),
  4947. Status: 1,
  4948. Ctime: time.Now().Unix(),
  4949. Mtime: 0,
  4950. Source: "电脑端新建his医嘱",
  4951. RecordDate: s.AdviceDate,
  4952. }
  4953. service.CreateDoctorAdviceLog(adviceLog)
  4954. //存储切片中
  4955. adviceList = append(adviceList, s)
  4956. redis := service.RedisClient()
  4957. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4958. redis.Set(key, "", time.Second)
  4959. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4960. redis.Set(keyOne, "", time.Second)
  4961. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4962. redis.Set(keySeven, "", time.Second)
  4963. var randNum int
  4964. randNum = rand.Intn(10000) + 1000
  4965. timestamp := time.Now().Unix()
  4966. tempTime := time.Unix(timestamp, 0)
  4967. timeFormat := tempTime.Format("20060102150405")
  4968. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4969. service.CreateHisDoctorAdvice(&s)
  4970. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4971. redis.Set(keySix, "", time.Second)
  4972. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4973. redis.Set(keyFive, "", time.Second)
  4974. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4975. redis.Set(keyEight, "", time.Second)
  4976. defer redis.Close()
  4977. }
  4978. }
  4979. }
  4980. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4981. projects := items["project"].([]interface{})
  4982. if len(projects) > 0 {
  4983. for _, project := range projects {
  4984. var p models.HisPrescriptionProject
  4985. p.PrescriptionId = tempPrescription.ID
  4986. p.PatientId = patient_id
  4987. p.RecordDate = theTime3.Unix()
  4988. p.Doctor = doctor_id
  4989. p.UserOrgId = adminInfo.CurrentOrgId
  4990. p.HisPatientId = his_patient_id
  4991. p.Status = 1
  4992. p.StartTime = pTime
  4993. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4994. if errcode > 0 {
  4995. c.ServeFailJSONWithSGJErrorCode(errcode)
  4996. return
  4997. }
  4998. if p.ID == 0 {
  4999. p.IsOut = 2
  5000. }
  5001. if p.ID > 0 {
  5002. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  5003. p.IsOut = projectDetail.IsOut
  5004. }
  5005. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5006. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5007. if p.Type == 3 {
  5008. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  5009. if p.Price != lastWarehouse.PackingPrice {
  5010. p.Price = lastWarehouse.PackingPrice
  5011. }
  5012. if p.Price == 0 {
  5013. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  5014. p.Price = lastWarehouseTwo.PackingPrice
  5015. }
  5016. if p.Unit == "" {
  5017. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5018. p.Unit = goodInfoOne.PackingUnit
  5019. }
  5020. }
  5021. }
  5022. if adminInfo.CurrentOrgId != 10206 {
  5023. if p.Type == 3 {
  5024. if p.ID == 0 {
  5025. //查询该耗材是否停用
  5026. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  5027. //表示该耗材已经停用,不能保存
  5028. if goodInfoSeven.ID == 0 {
  5029. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5030. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  5031. return
  5032. }
  5033. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  5034. if goodInfoOne.SumCount == 0 {
  5035. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  5036. return
  5037. }
  5038. }
  5039. }
  5040. }
  5041. service.CreateHisProjectTwo(&p)
  5042. //记录日志
  5043. byterequest, _ := json.Marshal(p)
  5044. adviceLog := models.XtDoctorAdviceLog{
  5045. UserOrgId: p.UserOrgId,
  5046. PatientId: p.PatientId,
  5047. AdminUserId: adminInfo.AdminUser.Id,
  5048. Module: 1,
  5049. ErrLog: string(byterequest),
  5050. Status: 1,
  5051. Ctime: time.Now().Unix(),
  5052. Mtime: 0,
  5053. Source: "电脑端新建his项目",
  5054. RecordDate: p.RecordDate,
  5055. }
  5056. service.CreateDoctorAdviceLog(adviceLog)
  5057. projectList = append(projectList, p)
  5058. var randNum int
  5059. randNum = rand.Intn(10000) + 1000
  5060. timestamp := time.Now().Unix()
  5061. tempTime := time.Unix(timestamp, 0)
  5062. timeFormat := tempTime.Format("20060102150405")
  5063. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  5064. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  5065. //新增或者编辑项目,修改对应的标签数据
  5066. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  5067. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  5068. var label models.HisLabelPrintInfo
  5069. project, _ := service.GetProjectDetail(p.ProjectId)
  5070. if project.CostClassify == 3 { //类别为检验检查
  5071. if p.TeamId > 0 { //检验检查组套
  5072. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  5073. if tempLabel.ID == 0 {
  5074. team, _ := service.GetProjectTeamDetail(p.TeamId)
  5075. label.Number = tempPrescription.PrescriptionNumber
  5076. label.ProjectId = project.ID
  5077. label.Status = 1
  5078. label.IsPrint = 2
  5079. label.DoctorId = info.DoctorId
  5080. label.UserOrgId = p.UserOrgId
  5081. label.PatientId = patient_id
  5082. label.RecordDate = recordDateTime
  5083. label.Ctime = time.Now().Unix()
  5084. label.Mtime = time.Now().Unix()
  5085. label.ItemId = p.TeamId
  5086. label.FeedetlSn = p.FeedetlSn
  5087. label.PProjectId = p.ID
  5088. label.ProjectName = team.ProjectTeam
  5089. label.PatientName = patient.Name
  5090. service.CreateHisLabelRecord(&label)
  5091. }
  5092. } else { //单条检验检查项目
  5093. label.Number = tempPrescription.PrescriptionNumber
  5094. label.ProjectId = project.ID
  5095. label.Status = 1
  5096. label.DoctorId = info.DoctorId
  5097. label.UserOrgId = p.UserOrgId
  5098. label.PatientId = patient_id
  5099. label.RecordDate = recordDateTime
  5100. label.IsPrint = 2
  5101. label.Ctime = time.Now().Unix()
  5102. label.Mtime = time.Now().Unix()
  5103. label.FeedetlSn = p.FeedetlSn
  5104. label.PProjectId = p.ID
  5105. label.ItemId = p.TeamId
  5106. label.ProjectName = project.ProjectName
  5107. label.PatientName = patient.Name
  5108. service.CreateHisLabelRecord(&label)
  5109. }
  5110. }
  5111. }
  5112. }
  5113. service.SaveHisProjectTwo(&p)
  5114. }
  5115. }
  5116. }
  5117. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5118. // addition := items["addition"].([]interface{})
  5119. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5120. // ctime := time.Now().Unix()
  5121. // mtime := ctime
  5122. // if len(addition) > 0 {
  5123. // for _, item := range addition {
  5124. // var s models.HisAdditionalCharge
  5125. // s.PrescriptionId = tempPrescription.ID
  5126. // s.Status = 1
  5127. // s.UserOrgId = adminInfo.CurrentOrgId
  5128. // s.RecordDate = recordDateTime
  5129. // s.CreatedTime = ctime
  5130. // s.UpdatedTime = mtime
  5131. // s.PatientId = patient_id
  5132. // s.HisPatientId = his_patient_id
  5133. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5134. // if errcode > 0 {
  5135. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5136. // return
  5137. // }
  5138. // service.CreateAdditionalCharge(&s)
  5139. // var randNum int
  5140. // randNum = rand.Intn(10000) + 1000
  5141. // timestamp := time.Now().Unix()
  5142. // tempTime := time.Unix(timestamp, 0)
  5143. // timeFormat := tempTime.Format("20060102150405")
  5144. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5145. // service.CreateAdditionalCharge(&s)
  5146. //
  5147. // }
  5148. // }
  5149. //}
  5150. }
  5151. }
  5152. //查询今日该患者开的药品处方
  5153. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5154. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5155. //药品出库
  5156. if drugOutConfig.IsOpen == 1 {
  5157. for _, item := range hisdoctorlist {
  5158. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5159. // 查询该药品最后一次出库记录
  5160. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5161. if len(druginfo) > 0 {
  5162. //回退库存
  5163. for _, it := range druginfo {
  5164. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5165. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5166. }
  5167. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5168. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5169. }
  5170. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5171. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5172. }
  5173. }
  5174. }
  5175. //删除记录
  5176. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5177. //查询最后一次数据
  5178. if drugOutConfig.IsOpen == 1 {
  5179. //出库
  5180. if drug.IsUse == 2 {
  5181. creater := adminInfo.AdminUser.Id
  5182. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5183. }
  5184. //更新字典里面的库存
  5185. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5186. var sum_count int64
  5187. for _, its := range stockInfo {
  5188. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5189. if its.MaxUnit == baseDrug.MaxUnit {
  5190. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5191. }
  5192. sum_count += its.StockMaxNumber + its.StockMinNumber
  5193. }
  5194. //更新基础库存
  5195. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5196. //剩余库存
  5197. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5198. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5199. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5200. }
  5201. }
  5202. }
  5203. //耗材保存处方出库
  5204. if goodOutConfig.IsOpen == 1 {
  5205. //查询今日耗材出库数量
  5206. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5207. for _, item := range hisgoodlist {
  5208. //查询历史出库数据
  5209. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5210. var out_count_five int64
  5211. for _, item := range flowGood {
  5212. out_count_five += item.Count
  5213. }
  5214. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5215. if out_count_five != parseIntCount {
  5216. //查询耗材最后一次出库记录
  5217. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5218. //查询默认出库仓库库存
  5219. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5220. if len(wareOut) > 0 {
  5221. for _, it := range wareOut {
  5222. //回退库存
  5223. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5224. //删除出库记录
  5225. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5226. }
  5227. }
  5228. timeStr := time.Now().Format("2006-01-02")
  5229. timeArr := strings.Split(timeStr, "-")
  5230. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5231. total = total + 1
  5232. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5233. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5234. number = number + total
  5235. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5236. operation_time := time.Now().Unix()
  5237. creater := c.GetAdminUserInfo().AdminUser.Id
  5238. recordDateStr := time.Now().Format("2006-01-02")
  5239. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5240. nowtime := recordDate.Unix()
  5241. warehouseOut := models.WarehouseOut{
  5242. WarehouseOutOrderNumber: warehousing_out_order,
  5243. OperationTime: operation_time,
  5244. OrgId: adminInfo.CurrentOrgId,
  5245. Creater: creater,
  5246. Ctime: time.Now().Unix(),
  5247. Status: 1,
  5248. WarehouseOutTime: nowtime,
  5249. Type: 1,
  5250. StorehouseId: storeConfig.StorehouseOutInfo,
  5251. IsCheck: 1,
  5252. IsSys: 1,
  5253. }
  5254. //查询是否生成出库单
  5255. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5256. if out.ID == 0 {
  5257. service.AddSigleWarehouseOutOne(&warehouseOut)
  5258. }
  5259. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5260. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5261. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5262. dialyPrepareOne := models.DialysisBeforePrepare{
  5263. GoodTypeId: goodObj.GoodTypeId,
  5264. GoodId: item.ProjectId,
  5265. PatientId: item.PatientId,
  5266. RecordDate: item.RecordDate,
  5267. UserOrgId: adminInfo.CurrentOrgId,
  5268. Count: parseIntCount,
  5269. Ctime: time.Now().Unix(),
  5270. Creater: creater,
  5271. Status: 1,
  5272. StorehouseId: houseConfig.StorehouseOutInfo,
  5273. ProjectId: item.ID,
  5274. }
  5275. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5276. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5277. //查询历史出库数据
  5278. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5279. var out_count int64
  5280. for _, item := range flowGood {
  5281. out_count += item.Count
  5282. }
  5283. //如果历史数和当前数据不想等才进行退库出库
  5284. if out_count != parseIntCount {
  5285. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5286. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5287. detail := models.AutomaticReduceDetail{
  5288. WarehouseOutId: 0,
  5289. WarehouseOutOrderNumber: "",
  5290. PatientId: item.PatientId,
  5291. Ctime: time.Now().Unix(),
  5292. Mtime: 0,
  5293. Status: 1,
  5294. RecordTime: item.RecordDate,
  5295. OrgId: item.UserOrgId,
  5296. GoodId: item.ProjectId,
  5297. GoodTypeId: 0,
  5298. Count: parseIntCount,
  5299. Type: 0,
  5300. ProjectId: item.ID,
  5301. StorehouseId: 0,
  5302. }
  5303. service.CreateAutoDetail(detail)
  5304. //查询剩余库存
  5305. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5306. var sum_count int64
  5307. for _, item := range goodList {
  5308. sum_count += item.StockCount
  5309. }
  5310. //更新剩余库存
  5311. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5312. //耗材
  5313. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5314. }
  5315. }
  5316. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5317. //查询历史出库数据
  5318. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5319. var out_count int64
  5320. for _, item := range flowGood {
  5321. out_count += item.Count
  5322. }
  5323. //如果历史数和当前数据不想等才进行退库出库
  5324. if out_count != parseIntCount {
  5325. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5326. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5327. detail := models.AutomaticReduceDetail{
  5328. WarehouseOutId: 0,
  5329. WarehouseOutOrderNumber: "",
  5330. PatientId: item.PatientId,
  5331. Ctime: time.Now().Unix(),
  5332. Mtime: 0,
  5333. Status: 1,
  5334. RecordTime: item.RecordDate,
  5335. OrgId: item.UserOrgId,
  5336. GoodId: item.ProjectId,
  5337. GoodTypeId: 0,
  5338. Count: parseIntCount,
  5339. Type: 0,
  5340. ProjectId: item.ID,
  5341. StorehouseId: 0,
  5342. }
  5343. service.CreateAutoDetail(detail)
  5344. //查询剩余库存
  5345. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5346. var sum_count int64
  5347. for _, item := range goodList {
  5348. sum_count += item.StockCount
  5349. }
  5350. //更新剩余库存
  5351. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5352. //耗材
  5353. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5354. }
  5355. }
  5356. }
  5357. }
  5358. }
  5359. ////同步到自备药
  5360. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5361. if selfPrescriptionOpen.IsOpen == 1 {
  5362. timeStr := time.Now().Format("2006-01-02")
  5363. timeArr := strings.Split(timeStr, "-")
  5364. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5365. total = total + 1
  5366. operation_time := time.Now().Unix()
  5367. creater := adminInfo.AdminUser.Id
  5368. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5369. warehousing := models.XtSelfDrugWarehouse{
  5370. WarehousingOrder: warehousing_order,
  5371. OperationTime: operation_time,
  5372. OrgId: adminInfo.CurrentOrgId,
  5373. Creater: creater,
  5374. Ctime: time.Now().Unix(),
  5375. Status: 1,
  5376. WarehousingTime: recordDateTime,
  5377. Type: 0,
  5378. StorehouseId: 0,
  5379. IsCheck: 1,
  5380. PatientId: patient_id,
  5381. IsSys: 1,
  5382. }
  5383. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5384. if selfDrugWarehouse.ID == 0 {
  5385. service.AddSelfDrugWarehouse(&warehousing, tx)
  5386. }
  5387. if selfDrugWarehouse.ID > 0 {
  5388. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5389. }
  5390. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5391. fmt.Println(info)
  5392. for _, item := range hisdoctorlist {
  5393. //查询该病人的该药品是否已经入库
  5394. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5395. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5396. var in_count int64
  5397. if len(selfdruginfo) > 0 {
  5398. for _, item := range selfdruginfo {
  5399. var in_count_one int64
  5400. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5401. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5402. }
  5403. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5404. in_count_one = item.WarehousingCount
  5405. }
  5406. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5407. in_count_one = item.WarehousingCount
  5408. }
  5409. in_count += in_count_one
  5410. }
  5411. }
  5412. if selfBasedrug.IsSelfDrug == 1 {
  5413. var total_count int64
  5414. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5415. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5416. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5417. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5418. }
  5419. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5420. total_count += prescribingNumberSeven
  5421. }
  5422. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5423. total_count += prescribingNumberSeven
  5424. }
  5425. //入库
  5426. if total_count > in_count {
  5427. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5428. WarehousingOrder: warehousing_order,
  5429. WarehousingId: info.ID,
  5430. DrugId: item.DrugId,
  5431. Number: "",
  5432. ProductDate: 0,
  5433. ExpiryDate: 0,
  5434. WarehousingCount: total_count - in_count,
  5435. WarehouseingUnit: selfBasedrug.MinUnit,
  5436. Price: 0,
  5437. TotalPrice: 0,
  5438. Status: 1,
  5439. Ctime: time.Now().Unix(),
  5440. Remark: "",
  5441. OrgId: adminInfo.CurrentOrgId,
  5442. Type: 0,
  5443. Manufacturer: selfBasedrug.Manufacturer,
  5444. Dealer: selfBasedrug.Dealer,
  5445. StockMaxNumber: total_count - in_count,
  5446. RetailTotalPrice: 0,
  5447. BatchNumber: "",
  5448. MaxUnit: selfBasedrug.MinUnit,
  5449. MinUnit: selfBasedrug.MinUnit,
  5450. RetailPrice: 0,
  5451. StorehouseId: 0,
  5452. IsCheck: 1,
  5453. StockMinNumber: 0,
  5454. PatientId: patient_id,
  5455. IsSys: 1,
  5456. RecordDate: item.RecordDate,
  5457. AdviceId: item.ID,
  5458. }
  5459. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5460. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5461. Creator := adminInfo.AdminUser.Id
  5462. //查询默认仓库剩余多少库存
  5463. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5464. var sum_count int64
  5465. for _, it := range list {
  5466. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5467. if it.MaxUnit == baseDrug.MaxUnit {
  5468. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5469. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5470. }
  5471. sum_count += it.StockMaxNumber + it.StockMinNumber
  5472. }
  5473. flow := &models.XtSelfDrugFlow{
  5474. WarehousingId: info.ID,
  5475. DrugId: item.DrugId,
  5476. Number: "",
  5477. BatchNumber: "",
  5478. Count: total_count - in_count,
  5479. UserOrgId: adminInfo.CurrentOrgId,
  5480. PatientId: item.PatientId,
  5481. SystemTime: time.Now().Unix(),
  5482. ConsumableType: 1,
  5483. IsSys: 1,
  5484. WarehousingOrder: warehousing_order,
  5485. WarehouseOutId: 0,
  5486. WarehouseOutOrderNumber: "",
  5487. IsEdit: 0,
  5488. CancelStockId: 0,
  5489. CancelOrderNumber: "",
  5490. Manufacturer: selfBasedrug.Manufacturer,
  5491. Dealer: selfBasedrug.Dealer,
  5492. Creator: Creator,
  5493. UpdateCreator: Creator,
  5494. Status: 1,
  5495. Ctime: item.AdviceDate,
  5496. Mtime: 0,
  5497. Price: item.Price,
  5498. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5499. WarehouseOutDetailId: 0,
  5500. CancelOutDetailId: 0,
  5501. ExpireDate: 0,
  5502. ProductDate: 0,
  5503. MaxUnit: selfBasedrug.MinUnit,
  5504. MinUnit: selfBasedrug.MinUnit,
  5505. StorehouseId: 0,
  5506. OverCount: sum_count,
  5507. OperateTime: time.Now().Unix(),
  5508. AdviceId: item.ID,
  5509. }
  5510. service.CreateSelfDrugFlow(flow, tx)
  5511. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5512. var total_count int64 // 入库总数量
  5513. var over_count int64 //剩余库存
  5514. for _, it := range drugInfolist {
  5515. if it.MaxUnit == selfBasedrug.MaxUnit {
  5516. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5517. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5518. }
  5519. }
  5520. for _, it := range drugInfolist {
  5521. total_count += it.WarehousingCount
  5522. over_count += it.StockMaxNumber + it.StockMinNumber
  5523. }
  5524. //查询该仓库是否有默认数据
  5525. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5526. if selfDrugStock.ID == 0 {
  5527. drugStock := models.XtSelfDrugStockCount{
  5528. UserOrgId: item.UserOrgId,
  5529. PatientId: item.PatientId,
  5530. SumInCount: total_count,
  5531. SumOutCount: 0,
  5532. SumCancelCount: 0,
  5533. DrugId: item.DrugId,
  5534. Ctime: time.Now().Unix(),
  5535. Mtime: 0,
  5536. Status: 1,
  5537. FlushCount: over_count,
  5538. SumActOutCount: 0,
  5539. }
  5540. service.CreateSelfDrugStockSum(drugStock, tx)
  5541. }
  5542. if selfDrugStock.ID > 0 {
  5543. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5544. }
  5545. }
  5546. //查询这个单据的出库数量
  5547. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5548. var his_out_count int64
  5549. for _, item := range drugFlowList {
  5550. his_out_count += item.Count
  5551. }
  5552. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5553. if (total_count + his_out_count) <= in_count {
  5554. // 出库
  5555. if total_count < in_count {
  5556. var cha_count int64
  5557. cha_count = in_count - total_count
  5558. var stock_number int64 = 0
  5559. //查询库存是否充足
  5560. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5561. // 将该批次的剩余库存数量转换为拆零数量
  5562. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5563. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5564. }
  5565. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5566. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5567. }
  5568. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5569. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5570. }
  5571. if stock_number >= cha_count {
  5572. var maxNumber int64 = 0
  5573. var minNumber int64 = 0
  5574. maxNumber = cha_count / selfBasedrug.MinNumber
  5575. minNumber = cha_count % selfBasedrug.MinNumber
  5576. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5577. minNumber = maxNumber
  5578. }
  5579. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5580. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5582. return
  5583. }
  5584. }
  5585. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5586. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5587. }
  5588. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5589. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5590. }
  5591. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5592. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5593. }
  5594. if warehouse.StockMaxNumber < 0 {
  5595. warehouse.StockMaxNumber = 0
  5596. }
  5597. if warehouse.StockMinNumber < 0 {
  5598. warehouse.StockMinNumber = 0
  5599. }
  5600. warehouse.Mtime = time.Now().Unix()
  5601. if warehouse.StockMinNumber < minNumber {
  5602. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5603. if warehouse.MaxUnit != warehouse.MinUnit {
  5604. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5605. }
  5606. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5607. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5608. }
  5609. } else {
  5610. if minNumber > 0 {
  5611. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5612. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5613. }
  5614. }
  5615. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5616. if warehouse.StockMinNumber > 0 {
  5617. if warehouse.StockMinNumber-cha_count >= 0 {
  5618. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5619. }
  5620. }
  5621. }
  5622. }
  5623. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5624. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5625. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5626. }
  5627. }
  5628. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5629. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5631. return
  5632. }
  5633. }
  5634. if warehouse.StockMinNumber <= 0 {
  5635. warehouse.StockMinNumber = 0
  5636. }
  5637. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5638. //查询该药品剩余库存
  5639. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5640. var over_count int64
  5641. for _, its := range infolist {
  5642. if its.MaxUnit == selfBasedrug.MaxUnit {
  5643. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5644. }
  5645. over_count += its.StockMaxNumber + its.StockMinNumber
  5646. }
  5647. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5648. drugflow := models.XtSelfDrugFlow{
  5649. WarehouseOutId: 0,
  5650. WarehouseOutOrderNumber: warehousing_order,
  5651. WarehousingOrder: warehousing_order,
  5652. DrugId: item.DrugId,
  5653. Number: warehouse.Number,
  5654. ProductDate: warehouse.ProductDate,
  5655. ExpireDate: warehouse.ExpiryDate,
  5656. Count: cha_count,
  5657. Price: warehouse.RetailPrice,
  5658. Status: 1,
  5659. Ctime: item.AdviceDate,
  5660. Mtime: time.Now().Unix(),
  5661. UserOrgId: item.UserOrgId,
  5662. Manufacturer: warehouse.Manufacturer,
  5663. Dealer: warehouse.Dealer,
  5664. BatchNumber: warehouse.BatchNumber,
  5665. MaxUnit: selfBasedrug.MinUnit,
  5666. ConsumableType: 20,
  5667. IsEdit: 1,
  5668. Creator: 0,
  5669. IsSys: 3,
  5670. WarehouseOutDetailId: drugWareInfo.ID,
  5671. AdviceId: item.ID,
  5672. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5673. StorehouseId: 0,
  5674. AdminUserId: creater,
  5675. LastPrice: warehouse.Price,
  5676. StockCount: "",
  5677. WarehousingDetailId: 0,
  5678. OverCount: over_count,
  5679. RetailPrice: item.Price, //手动出库出库价格
  5680. WarehousingId: warehouse.ID,
  5681. SystemTime: item.AdviceDate,
  5682. PatientId: item.PatientId,
  5683. Remark: "保存处方入库数据差",
  5684. OperateTime: time.Now().Unix(),
  5685. }
  5686. if warehouse.RetailPrice == 0 {
  5687. drugflow.Price = item.Price
  5688. }
  5689. service.CreateSelfDrugFlowOne(drugflow, tx)
  5690. var out_count int64
  5691. out_count = in_count - total_count
  5692. //
  5693. //fmt.Println("in_count------------------", in_count)
  5694. //fmt.Println("total_count------------------", total_count)
  5695. //添加出库数量
  5696. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5697. //查询剩余库存
  5698. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5699. var sum_count int64
  5700. for _, its := range stockInfo {
  5701. if its.MaxUnit == selfBasedrug.MaxUnit {
  5702. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5703. }
  5704. sum_count += its.StockMaxNumber + its.StockMinNumber
  5705. }
  5706. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5707. } else {
  5708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5709. return
  5710. }
  5711. }
  5712. }
  5713. }
  5714. }
  5715. }
  5716. }
  5717. tx.Commit()
  5718. if err == nil {
  5719. c.ServeSuccessJSON(map[string]interface{}{
  5720. "msg": "保存成功",
  5721. })
  5722. return
  5723. } else {
  5724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5725. return
  5726. }
  5727. }
  5728. }
  5729. //func (c *HisApiController) EditHisPrescription() {
  5730. // record_date := c.GetString("record_date")
  5731. // patient_id, _ := c.GetInt64("patient_id")
  5732. // reg_type, _ := c.GetInt64("reg_type")
  5733. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5734. // diagnose := c.GetString("diagnose")
  5735. // sick_type, _ := c.GetInt64("sick_type")
  5736. // sick_history := c.GetString("sick_history")
  5737. // doctor_id, _ := c.GetInt64("doctor", 0)
  5738. // department, _ := c.GetInt64("department", 0)
  5739. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5740. // p_type, _ := c.GetInt64("p_type")
  5741. //
  5742. // dataBody := make(map[string]interface{}, 0)
  5743. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5744. // if err != nil {
  5745. // utils.ErrorLog(err.Error())
  5746. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5747. // return
  5748. // }
  5749. //
  5750. // timeLayout := "2006-01-02"
  5751. // loc, _ := time.LoadLocation("Local")
  5752. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5753. // if err != nil {
  5754. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5755. // return
  5756. // }
  5757. // adminInfo := c.GetAdminUserInfo()
  5758. // recordDateTime := theTime.Unix()
  5759. //
  5760. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5761. //
  5762. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5763. // var hpInfo models.HisPrescriptionInfo
  5764. // if info.ID == 0 {
  5765. // var randNum int
  5766. // randNum = rand.Intn(10000) + 1000
  5767. // timestamp := time.Now().Unix()
  5768. // tempTime := time.Unix(timestamp, 0)
  5769. // timeFormat := tempTime.Format("20060102150405")
  5770. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5771. //
  5772. // hpInfo = models.HisPrescriptionInfo{
  5773. // UserOrgId: adminInfo.CurrentOrgId,
  5774. // RecordDate: theTime.Unix(),
  5775. // PatientId: patient_id,
  5776. // Status: 1,
  5777. // Ctime: time.Now().Unix(),
  5778. // Mtime: time.Now().Unix(),
  5779. // Creator: adminInfo.AdminUser.Id,
  5780. // Modifier: adminInfo.AdminUser.Id,
  5781. // Diagnosis: diagnose,
  5782. // SickHistory: sick_history,
  5783. // Departments: department,
  5784. // RegisterType: reg_type,
  5785. // PrescriptionNumber: p_number,
  5786. // PrescriptionStatus: 1,
  5787. // Doctor: role.UserName,
  5788. // DoctorId: doctor_id,
  5789. // SickType: sick_type,
  5790. // PType: p_type,
  5791. // }
  5792. // service.SavePatientPrescriptionInfo(hpInfo)
  5793. //
  5794. // } else {
  5795. // hpInfo = models.HisPrescriptionInfo{
  5796. // ID: info.ID,
  5797. // UserOrgId: adminInfo.CurrentOrgId,
  5798. // RecordDate: info.RecordDate,
  5799. // PatientId: info.PatientId,
  5800. // Status: 1,
  5801. // Ctime: info.Ctime,
  5802. // Mtime: time.Now().Unix(),
  5803. // Creator: info.Creator,
  5804. // Modifier: adminInfo.AdminUser.Id,
  5805. // Diagnosis: diagnose,
  5806. // SickHistory: sick_history,
  5807. // Departments: department,
  5808. // RegisterType: reg_type,
  5809. // PrescriptionNumber: info.PrescriptionNumber,
  5810. // Doctor: role.UserName,
  5811. // PrescriptionStatus: info.PrescriptionStatus,
  5812. // DoctorId: doctor_id,
  5813. // SickType: sick_type,
  5814. // PType: info.PType,
  5815. // }
  5816. // service.SavePatientPrescriptionInfo(hpInfo)
  5817. // }
  5818. //
  5819. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5820. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5821. //
  5822. // if len(prescriptions) > 0 {
  5823. // for _, item := range prescriptions {
  5824. // items := item.(map[string]interface{})
  5825. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5826. // utils.ErrorLog("id")
  5827. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5828. // return
  5829. // }
  5830. // id := int64(items["id"].(float64))
  5831. //
  5832. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5833. // utils.ErrorLog("type")
  5834. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5835. // return
  5836. // }
  5837. // types := int64(items["type"].(float64))
  5838. //
  5839. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5840. // utils.ErrorLog("med_type")
  5841. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5842. // return
  5843. // }
  5844. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5845. //
  5846. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5847. //
  5848. // ctime := time.Now().Unix()
  5849. //
  5850. // prescription := &models.HisPrescription{
  5851. // ID: id,
  5852. // PatientId: patient_id,
  5853. // UserOrgId: adminInfo.CurrentOrgId,
  5854. // RecordDate: recordDateTime,
  5855. // Ctime: ctime,
  5856. // Mtime: ctime,
  5857. // Type: types,
  5858. // Modifier: adminInfo.AdminUser.Id,
  5859. // Creator: adminInfo.AdminUser.Id,
  5860. // Status: 1,
  5861. // Doctor: role.UserName,
  5862. // HisPatientId: his_patient_id,
  5863. // OrderStatus: 1,
  5864. // BatchNumber: "",
  5865. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5866. // PType: hpInfo.PType,
  5867. // MedType: med_type,
  5868. // }
  5869. //
  5870. // if historyPrescription.ID > 0 {
  5871. // prescription.PreTime = historyPrescription.PreTime
  5872. //
  5873. // }
  5874. //
  5875. // service.SaveHisPrescription(prescription)
  5876. //
  5877. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5878. // advices := items["advices"].([]interface{})
  5879. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5880. // groupNo := int64(0)
  5881. // ctime := time.Now().Unix()
  5882. // mtime := ctime
  5883. // if len(advices) > 0 {
  5884. // for _, advice := range advices {
  5885. // var s models.HisDoctorAdviceInfo
  5886. // s.PrescriptionId = prescription.ID
  5887. // s.AdviceType = 2
  5888. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5889. // s.StopState = 2
  5890. // s.ExecutionState = 2
  5891. // s.AdviceDate = recordDateTime
  5892. // s.Status = 1
  5893. // s.UserOrgId = adminInfo.CurrentOrgId
  5894. // s.RecordDate = recordDateTime
  5895. // s.StartTime = prescription.PreTime
  5896. // s.Groupno = groupNo
  5897. // s.CreatedTime = ctime
  5898. // s.UpdatedTime = mtime
  5899. // s.PatientId = patient_id
  5900. // s.HisPatientId = his_patient_id
  5901. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5902. // if errcode > 0 {
  5903. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5904. // return
  5905. // }
  5906. //
  5907. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5908. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5909. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5910. // if s.Price == 0 {
  5911. // s.Price = lastWarehouse.RetailPrice
  5912. // }
  5913. // }
  5914. //
  5915. // service.CreateHisDoctorAdvice(&s)
  5916. // //记录日志
  5917. // byterequest, _ := json.Marshal(s)
  5918. // adviceLog := models.XtDoctorAdviceLog{
  5919. // UserOrgId: s.UserOrgId,
  5920. // PatientId: s.PatientId,
  5921. // AdminUserId: adminInfo.AdminUser.Id,
  5922. // Module: 1,
  5923. // ErrLog: string(byterequest),
  5924. // Status: 1,
  5925. // Ctime: time.Now().Unix(),
  5926. // Mtime: 0,
  5927. // Source: "电脑端his医嘱修改",
  5928. // RecordDate: s.AdviceDate,
  5929. // }
  5930. // service.CreateDoctorAdviceLog(adviceLog)
  5931. // redis := service.RedisClient()
  5932. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5933. // redis.Set(key, "", time.Second)
  5934. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5935. // fmt.Println("keyOne", keyOne)
  5936. // redis.Set(keyOne, "", time.Second)
  5937. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5938. // redis.Set(keySeven, "", time.Second)
  5939. // redis.Close()
  5940. //
  5941. // }
  5942. // }
  5943. // }
  5944. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5945. // projects := items["project"].([]interface{})
  5946. // if len(projects) > 0 {
  5947. // for _, project := range projects {
  5948. // var p models.HisPrescriptionProject
  5949. // p.PrescriptionId = prescription.ID
  5950. // p.Ctime = time.Now().Unix()
  5951. // p.Mtime = time.Now().Unix()
  5952. // p.PatientId = patient_id
  5953. // p.RecordDate = recordDateTime
  5954. // p.UserOrgId = adminInfo.CurrentOrgId
  5955. // p.HisPatientId = his_patient_id
  5956. // p.Status = 1
  5957. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5958. // if errcode > 0 {
  5959. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5960. // return
  5961. // }
  5962. // service.CreateHisProjectTwo(&p)
  5963. //
  5964. // //记录日志
  5965. // byterequest, _ := json.Marshal(p)
  5966. // adviceLog := models.XtDoctorAdviceLog{
  5967. // UserOrgId: p.UserOrgId,
  5968. // PatientId: p.PatientId,
  5969. // AdminUserId: adminInfo.AdminUser.Id,
  5970. // Module: 1,
  5971. // ErrLog: string(byterequest),
  5972. // Status: 1,
  5973. // Ctime: time.Now().Unix(),
  5974. // Mtime: 0,
  5975. // Source: "电脑端his项目修改",
  5976. // RecordDate: p.RecordDate,
  5977. // }
  5978. // service.CreateDoctorAdviceLog(adviceLog)
  5979. // }
  5980. // }
  5981. // }
  5982. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5983. // addition := items["addition"].([]interface{})
  5984. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5985. // ctime := time.Now().Unix()
  5986. // mtime := ctime
  5987. // if len(addition) > 0 {
  5988. // for _, item := range addition {
  5989. // var s models.HisAdditionalCharge
  5990. // s.PrescriptionId = prescription.ID
  5991. // s.Status = 1
  5992. // s.UserOrgId = adminInfo.CurrentOrgId
  5993. // s.RecordDate = recordDateTime
  5994. // s.CreatedTime = ctime
  5995. // s.UpdatedTime = mtime
  5996. // s.PatientId = patient_id
  5997. // s.HisPatientId = his_patient_id
  5998. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5999. // if errcode > 0 {
  6000. // c.ServeFailJSONWithSGJErrorCode(errcode)
  6001. // return
  6002. // }
  6003. // service.CreateAdditionalCharge(&s)
  6004. // }
  6005. // }
  6006. // }
  6007. //
  6008. // }
  6009. // }
  6010. // }
  6011. // if err == nil {
  6012. // c.ServeSuccessJSON(map[string]interface{}{
  6013. // "msg": "保存成功",
  6014. // })
  6015. // return
  6016. //
  6017. // } else {
  6018. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6019. // return
  6020. // }
  6021. //}
  6022. func (c *HisApiController) DeletePrescription() {
  6023. prescription_id, _ := c.GetInt64("id")
  6024. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  6025. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  6026. ////同步到自备药
  6027. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6028. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6029. if selfPrescriptionOpen.IsOpen == 1 {
  6030. // 在函数结束时处理事务回滚
  6031. db := service.XTWriteDB()
  6032. tx := db.Begin()
  6033. defer func() {
  6034. if r := recover(); r != nil {
  6035. tx.Rollback()
  6036. } else {
  6037. tx.Commit()
  6038. }
  6039. }()
  6040. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  6041. for _, item := range advicesList {
  6042. timeStr := time.Now().Format("2006-01-02")
  6043. timeArr := strings.Split(timeStr, "-")
  6044. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6045. total = total + 1
  6046. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6047. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6048. number = number + total
  6049. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6050. operation_time := time.Now().Unix()
  6051. creater := c.GetAdminUserInfo().AdminUser.Id
  6052. //创建一个出库单
  6053. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6054. WarehouseOutOrderNumber: warehousing_out_order,
  6055. OperationTime: operation_time,
  6056. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6057. Creater: creater,
  6058. Ctime: time.Now().Unix(),
  6059. Status: 1,
  6060. WarehouseOutTime: item.AdviceDate,
  6061. Type: 0,
  6062. PatientId: item.PatientId,
  6063. IsCheck: 1,
  6064. }
  6065. //查询今日是否有出库数据
  6066. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  6067. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  6068. if lastWarehouseOut.ID == 0 {
  6069. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6070. }
  6071. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  6072. var total_count int64
  6073. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  6074. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6075. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6076. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6077. }
  6078. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6079. total_count += prescribingNumberSeven
  6080. }
  6081. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6082. total_count += prescribingNumberSeven
  6083. }
  6084. //出库
  6085. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6086. WarehouseOutOrderNumber: warehousing_out_order,
  6087. WarehouseOutId: lastWarehouseOut.ID,
  6088. DrugId: item.DrugId,
  6089. Count: total_count,
  6090. Price: 0,
  6091. TotalPrice: 0,
  6092. Status: 1,
  6093. Ctime: item.AdviceDate,
  6094. Mtime: item.AdviceDate,
  6095. Remark: "",
  6096. OrgId: item.UserOrgId,
  6097. Type: 0,
  6098. Manufacturer: selfBasedrug.Manufacturer,
  6099. Dealer: selfBasedrug.Dealer,
  6100. RetailPrice: 0,
  6101. RetailTotalPrice: 0,
  6102. CountUnit: selfBasedrug.MinUnit,
  6103. ExpiryDate: 0,
  6104. ProductDate: 0,
  6105. Number: "",
  6106. BatchNumber: "",
  6107. IsSys: 1,
  6108. WarehouseInfoId: 0,
  6109. AdminUserId: 0,
  6110. StockCount: "",
  6111. IsCheck: 1,
  6112. SysRecordTime: item.AdviceDate,
  6113. PatientId: item.PatientId,
  6114. ClassType: "",
  6115. AdviceId: item.ID,
  6116. }
  6117. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6118. }
  6119. fmt.Println("长度-------------------------------", warehousingOutInfo)
  6120. for _, it := range warehousingOutInfo {
  6121. //查询今日是否有出库数据
  6122. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6123. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6124. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6125. //出库逻辑
  6126. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6127. //查询剩余库存
  6128. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6129. var sum_count int64
  6130. for _, its := range stockInfo {
  6131. if its.MaxUnit == medical.MaxUnit {
  6132. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6133. }
  6134. sum_count += its.StockMaxNumber + its.StockMinNumber
  6135. }
  6136. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6137. }
  6138. }
  6139. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6140. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6141. //耗材保存处方出库
  6142. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6143. //已收费和已发药限制逻辑
  6144. isCharge := false
  6145. isMedicine := false
  6146. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6147. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6148. if new_prescription.IsMedicine == 1 {
  6149. isMedicine = true
  6150. }
  6151. for _, item := range new_prescriptions {
  6152. if item.OrderStatus == 4 {
  6153. isCharge = true
  6154. }
  6155. }
  6156. if p_err != nil {
  6157. if new_prescription.ID > 0 {
  6158. if new_prescription.OrderStatus == 2 {
  6159. isCharge = true
  6160. }
  6161. }
  6162. }
  6163. for _, item := range advices {
  6164. if item.IsMedicine == 1 {
  6165. isMedicine = true
  6166. }
  6167. }
  6168. if isCharge {
  6169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6170. return
  6171. }
  6172. if isMedicine {
  6173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6174. return
  6175. }
  6176. //已收费和已发药限制逻辑
  6177. if len(projects) > 0 {
  6178. for _, item := range projects {
  6179. service.DeletePrintInfo(item.ID) //删除打印信息
  6180. if goodOutConfig.IsOpen != 1 {
  6181. if stockConfig.IsOpen == 1 {
  6182. if item.Type == 3 && item.IsOut == 1 {
  6183. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6184. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6185. good.Total = good.Total + f_count
  6186. service.UpdateGoodInfo(&good)
  6187. operation_time := time.Now().Unix()
  6188. creater := c.GetAdminUserInfo().AdminUser.Id
  6189. //创建退库单
  6190. timeStr := time.Now().Format("2006-01-02")
  6191. timeArr := strings.Split(timeStr, "-")
  6192. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6193. total = total + 1
  6194. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6195. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6196. cancelStock := models.CancelStock{
  6197. OrderNumber: orderNumber,
  6198. OperaTime: operation_time,
  6199. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6200. Creater: creater,
  6201. Ctime: time.Now().Unix(),
  6202. Status: 1,
  6203. ReturnTime: item.RecordDate,
  6204. Type: 1,
  6205. StorehouseId: houseConfig.StorehouseOutInfo,
  6206. IsCheck: 1,
  6207. }
  6208. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6209. if msgerrkonde == gorm.ErrRecordNotFound {
  6210. service.AddSigleCancelStock(&cancelStock)
  6211. }
  6212. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6213. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6214. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6215. //查询该耗材是否出库
  6216. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6217. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6218. deaerler, _ := service.GetDealerById(info.Dealer)
  6219. var total_count int64
  6220. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6221. total_count += count
  6222. if info.ID > 0 {
  6223. if info.Count >= total_count {
  6224. //回退库存
  6225. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6226. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6227. var flush_count int64
  6228. for _, it := range goodList {
  6229. flush_count += it.StockCount
  6230. }
  6231. cancelStockInfo := models.CancelStockInfo{
  6232. GoodId: item.ProjectId,
  6233. CancelStockId: cancel.ID,
  6234. GoodTypeId: good.GoodTypeId,
  6235. Count: prescribingNumber,
  6236. Price: info.Price,
  6237. Total: 0,
  6238. ProductDate: info.ProductDate,
  6239. ExpiryDate: info.ExpiryDate,
  6240. Ctime: time.Now().Unix(),
  6241. Status: 1,
  6242. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6243. OrderNumber: cancel.OrderNumber,
  6244. Type: 0,
  6245. Dealer: deaerler.DealerName,
  6246. Manufacturer: manufacturer.ManufacturerName,
  6247. Number: info.Number,
  6248. RegisterAccount: "",
  6249. Remark: "",
  6250. WarehouseInfoId: info.WarehouseInfotId,
  6251. PatientId: info.PatientId,
  6252. RecordDate: info.SysRecordTime,
  6253. StorehouseId: houseConfig.StorehouseOutInfo,
  6254. IsCheck: 1,
  6255. }
  6256. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6257. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6258. flow := models.VmStockFlow{
  6259. WarehousingId: info.WarehouseInfotId,
  6260. GoodId: item.ProjectId,
  6261. Number: info.Number,
  6262. LicenseNumber: info.LicenseNumber,
  6263. Count: prescribingNumber,
  6264. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6265. PatientId: item.PatientId,
  6266. SystemTime: info.SysRecordTime,
  6267. ConsumableType: 7,
  6268. IsSys: 0,
  6269. WarehousingOrder: "",
  6270. WarehouseOutId: info.WarehouseOutId,
  6271. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6272. IsEdit: 0,
  6273. CancelStockId: cancel.ID,
  6274. CancelOrderNumber: cancel.OrderNumber,
  6275. Manufacturer: manufacturer.ID,
  6276. Dealer: 0,
  6277. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6278. UpdateCreator: 0,
  6279. Status: 1,
  6280. Ctime: time.Now().Unix(),
  6281. Mtime: 0,
  6282. Price: info.Price,
  6283. WarehousingDetailId: info.WarehouseInfotId,
  6284. WarehouseOutDetailId: info.ID,
  6285. CancelOutDetailId: cancelInfo.ID,
  6286. ProductDate: info.ProductDate,
  6287. ExpireDate: info.ExpiryDate,
  6288. StorehouseId: houseConfig.StorehouseOutInfo,
  6289. OverCount: flush_count,
  6290. OperateTime: time.Now().Unix(),
  6291. }
  6292. service.CreateStockFlowOne(flow)
  6293. //退库数量增加
  6294. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6295. //出库数量减少
  6296. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6297. }
  6298. if info.Count < total_count {
  6299. //回退库存
  6300. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6301. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6302. var flush_count int64
  6303. for _, it := range goodList {
  6304. flush_count += it.StockCount
  6305. }
  6306. cancelStockInfo := models.CancelStockInfo{
  6307. GoodId: item.ProjectId,
  6308. CancelStockId: cancel.ID,
  6309. GoodTypeId: good.GoodTypeId,
  6310. Count: info.Count,
  6311. Price: info.Price,
  6312. Total: 0,
  6313. ProductDate: info.ProductDate,
  6314. ExpiryDate: info.ExpiryDate,
  6315. Ctime: time.Now().Unix(),
  6316. Status: 1,
  6317. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6318. OrderNumber: cancel.OrderNumber,
  6319. Type: 0,
  6320. Dealer: deaerler.DealerName,
  6321. Manufacturer: manufacturer.ManufacturerName,
  6322. Number: info.Number,
  6323. RegisterAccount: "",
  6324. Remark: "",
  6325. WarehouseInfoId: info.WarehouseInfotId,
  6326. PatientId: info.PatientId,
  6327. RecordDate: info.SysRecordTime,
  6328. StorehouseId: houseConfig.StorehouseOutInfo,
  6329. IsCheck: 1,
  6330. }
  6331. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6332. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6333. flow := models.VmStockFlow{
  6334. WarehousingId: info.WarehouseInfotId,
  6335. GoodId: item.ProjectId,
  6336. Number: info.Number,
  6337. LicenseNumber: info.LicenseNumber,
  6338. Count: info.Count,
  6339. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6340. PatientId: item.PatientId,
  6341. SystemTime: info.SysRecordTime,
  6342. ConsumableType: 7,
  6343. IsSys: 0,
  6344. WarehousingOrder: "",
  6345. WarehouseOutId: info.WarehouseOutId,
  6346. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6347. IsEdit: 0,
  6348. CancelStockId: cancel.ID,
  6349. CancelOrderNumber: cancel.OrderNumber,
  6350. Manufacturer: manufacturer.ID,
  6351. Dealer: 0,
  6352. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6353. UpdateCreator: 0,
  6354. Status: 1,
  6355. Ctime: time.Now().Unix(),
  6356. Mtime: 0,
  6357. Price: info.Price,
  6358. WarehousingDetailId: info.WarehouseInfotId,
  6359. WarehouseOutDetailId: info.ID,
  6360. CancelOutDetailId: cancelInfo.ID,
  6361. ProductDate: info.ProductDate,
  6362. ExpireDate: info.ExpiryDate,
  6363. StorehouseId: houseConfig.StorehouseOutInfo,
  6364. OverCount: flush_count,
  6365. OperateTime: time.Now().Unix(),
  6366. }
  6367. service.CreateStockFlowOne(flow)
  6368. //退库数量增加
  6369. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6370. //出库数量减少
  6371. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6372. }
  6373. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6374. var flush_count int64
  6375. for _, it := range goodList {
  6376. flush_count += it.StockCount
  6377. }
  6378. //查询已出库数量
  6379. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6380. if prescribingNumber < dialysisInfo.Count {
  6381. //改变数量
  6382. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6383. }
  6384. if prescribingNumber >= dialysisInfo.Count {
  6385. //删除出库表
  6386. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6387. }
  6388. //更新库存
  6389. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6390. //更新基础库库存
  6391. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6392. }
  6393. }
  6394. }
  6395. }
  6396. //保存耗材出库
  6397. if goodOutConfig.IsOpen == 1 {
  6398. if item.Type == 3 {
  6399. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6400. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6401. good.Total = good.Total + f_count
  6402. service.UpdateGoodInfo(&good)
  6403. operation_time := time.Now().Unix()
  6404. creater := c.GetAdminUserInfo().AdminUser.Id
  6405. //创建退库单
  6406. timeStr := time.Now().Format("2006-01-02")
  6407. timeArr := strings.Split(timeStr, "-")
  6408. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6409. total = total + 1
  6410. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6411. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6412. cancelStock := models.CancelStock{
  6413. OrderNumber: orderNumber,
  6414. OperaTime: operation_time,
  6415. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6416. Creater: creater,
  6417. Ctime: time.Now().Unix(),
  6418. Status: 1,
  6419. ReturnTime: item.RecordDate,
  6420. Type: 1,
  6421. StorehouseId: houseConfig.StorehouseOutInfo,
  6422. IsCheck: 1,
  6423. }
  6424. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6425. if msgerrkonde == gorm.ErrRecordNotFound {
  6426. service.AddSigleCancelStock(&cancelStock)
  6427. }
  6428. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6429. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6430. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6431. //查询该耗材是否出库
  6432. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6433. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6434. deaerler, _ := service.GetDealerById(info.Dealer)
  6435. var total_count int64
  6436. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6437. total_count += count
  6438. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6439. var flush_count int64
  6440. for _, it := range goodList {
  6441. flush_count += it.StockCount
  6442. }
  6443. fmt.Println("历史出库数据", info.Count)
  6444. fmt.Println("出库数量", total_count)
  6445. if info.ID > 0 {
  6446. cancelStockInfo := models.CancelStockInfo{
  6447. GoodId: item.ProjectId,
  6448. CancelStockId: cancel.ID,
  6449. GoodTypeId: good.GoodTypeId,
  6450. Count: prescribingNumber,
  6451. Price: info.Price,
  6452. Total: 0,
  6453. ProductDate: info.ProductDate,
  6454. ExpiryDate: info.ExpiryDate,
  6455. Ctime: time.Now().Unix(),
  6456. Status: 1,
  6457. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6458. OrderNumber: cancel.OrderNumber,
  6459. Type: 0,
  6460. Dealer: deaerler.DealerName,
  6461. Manufacturer: manufacturer.ManufacturerName,
  6462. Number: info.Number,
  6463. RegisterAccount: "",
  6464. Remark: "",
  6465. WarehouseInfoId: info.WarehouseInfotId,
  6466. PatientId: info.PatientId,
  6467. RecordDate: info.SysRecordTime,
  6468. StorehouseId: houseConfig.StorehouseOutInfo,
  6469. IsCheck: 1,
  6470. }
  6471. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6472. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6473. //查询出库数量
  6474. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6475. //出库数据 大于 退库数量
  6476. if len(list) > 0 {
  6477. for _, it := range list {
  6478. //回退库存
  6479. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6480. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6481. var flush_count_one int64
  6482. for _, it := range goodList {
  6483. flush_count_one += it.StockCount
  6484. }
  6485. //查询该批次是否有退库数据
  6486. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6487. creater := c.GetAdminUserInfo().AdminUser.Id
  6488. flow := models.VmStockFlow{
  6489. WarehousingId: it.WarehouseInfotId,
  6490. GoodId: it.GoodId,
  6491. Number: it.Number,
  6492. LicenseNumber: it.LicenseNumber,
  6493. Count: it.Count,
  6494. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6495. PatientId: it.PatientId,
  6496. SystemTime: it.SysRecordTime,
  6497. ConsumableType: 7,
  6498. IsSys: 0,
  6499. WarehousingOrder: "",
  6500. WarehouseOutId: it.WarehouseOutId,
  6501. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6502. IsEdit: 0,
  6503. CancelStockId: cancel.ID,
  6504. CancelOrderNumber: cancel.OrderNumber,
  6505. Manufacturer: manufacturer.ID,
  6506. Dealer: 0,
  6507. Creator: creater,
  6508. UpdateCreator: 0,
  6509. Status: 1,
  6510. Ctime: time.Now().Unix(),
  6511. Mtime: 0,
  6512. Price: it.Price,
  6513. WarehousingDetailId: it.WarehouseInfotId,
  6514. WarehouseOutDetailId: it.ID,
  6515. CancelOutDetailId: cancelInfo.ID,
  6516. ProductDate: it.ProductDate,
  6517. ExpireDate: it.ExpiryDate,
  6518. StorehouseId: houseConfig.StorehouseOutInfo,
  6519. OverCount: flush_count_one,
  6520. OperateTime: time.Now().Unix(),
  6521. }
  6522. service.CreateStockFlowOne(flow)
  6523. //if flow.ID > 0 {
  6524. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6525. //}
  6526. }
  6527. }
  6528. //flow := models.VmStockFlow{
  6529. // WarehousingId: info.WarehouseInfotId,
  6530. // GoodId: item.ProjectId,
  6531. // Number: info.Number,
  6532. // LicenseNumber: info.LicenseNumber,
  6533. // Count: prescribingNumber,
  6534. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6535. // PatientId: item.PatientId,
  6536. // SystemTime: info.SysRecordTime,
  6537. // ConsumableType: 7,
  6538. // IsSys: 0,
  6539. // WarehousingOrder: "",
  6540. // WarehouseOutId: info.WarehouseOutId,
  6541. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6542. // IsEdit: 0,
  6543. // CancelStockId: cancel.ID,
  6544. // CancelOrderNumber: cancel.OrderNumber,
  6545. // Manufacturer: manufacturer.ID,
  6546. // Dealer: 0,
  6547. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6548. // UpdateCreator: 0,
  6549. // Status: 1,
  6550. // Ctime: time.Now().Unix(),
  6551. // Mtime: 0,
  6552. // Price: info.Price,
  6553. // WarehousingDetailId: info.WarehouseInfotId,
  6554. // WarehouseOutDetailId: info.ID,
  6555. // CancelOutDetailId: cancelInfo.ID,
  6556. // ProductDate: info.ProductDate,
  6557. // ExpireDate: info.ExpiryDate,
  6558. // StorehouseId: houseConfig.StorehouseOutInfo,
  6559. // OverCount: flush_count,
  6560. //}
  6561. //service.CreateStockFlowOne(flow)
  6562. //退库数量增加
  6563. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6564. //出库数量减少
  6565. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6566. //查询已出库数量
  6567. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6568. if prescribingNumber < dialysisInfo.Count {
  6569. //改变数量
  6570. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6571. }
  6572. if prescribingNumber >= dialysisInfo.Count {
  6573. //删除出库表
  6574. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6575. }
  6576. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6577. var flush_count_one int64
  6578. for _, it := range goodList {
  6579. flush_count_one += it.StockCount
  6580. }
  6581. //更新库存
  6582. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6583. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6584. //更新基础库库存
  6585. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6586. }
  6587. }
  6588. }
  6589. }
  6590. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6591. fmt.Println(err)
  6592. }
  6593. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6594. fmt.Println(err)
  6595. if len(advices) > 0 {
  6596. for _, item := range advices {
  6597. redis := service.RedisClient()
  6598. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6599. redis.Set(keyFive, "", time.Second)
  6600. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6601. redis.Set(keyOne, "", time.Second)
  6602. redis.Close()
  6603. }
  6604. }
  6605. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6606. if len(advices) > 0 {
  6607. for _, item := range advices {
  6608. creater := c.GetAdminUserInfo().AdminUser.Id
  6609. service.DrugAutoAddCancelInfo(item, creater)
  6610. }
  6611. }
  6612. } else {
  6613. if drugOutConfig.IsOpen == 1 {
  6614. if len(advices) > 0 {
  6615. for _, item := range advices {
  6616. creater := c.GetAdminUserInfo().AdminUser.Id
  6617. service.DrugAutoAddCancelInfo(item, creater)
  6618. }
  6619. }
  6620. } else {
  6621. if len(advices) > 0 {
  6622. for _, item := range advices {
  6623. creater := c.GetAdminUserInfo().AdminUser.Id
  6624. service.DrugAutoAddCancelInfo(item, creater)
  6625. }
  6626. }
  6627. }
  6628. }
  6629. c.ServeSuccessJSON(map[string]interface{}{
  6630. "msg": "删除成功",
  6631. })
  6632. return
  6633. }
  6634. func (c *HisApiController) DeleteDoctorAdvice() {
  6635. id, _ := c.GetInt64("id")
  6636. advice, _ := service.GetHisDoctorAdvicesById(id)
  6637. ////同步到自备药
  6638. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6639. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6640. if selfPrescriptionOpen.IsOpen == 1 {
  6641. db := service.XTWriteDB()
  6642. tx := db.Begin()
  6643. defer func() {
  6644. if r := recover(); r != nil {
  6645. tx.Rollback()
  6646. } else {
  6647. tx.Commit()
  6648. }
  6649. }()
  6650. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6651. var total_count int64
  6652. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6653. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6654. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6655. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6656. }
  6657. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6658. total_count += prescribingNumberSeven
  6659. }
  6660. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6661. total_count += prescribingNumberSeven
  6662. }
  6663. timeStr := time.Now().Format("2006-01-02")
  6664. timeArr := strings.Split(timeStr, "-")
  6665. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6666. total = total + 1
  6667. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6668. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6669. number = number + total
  6670. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6671. operation_time := time.Now().Unix()
  6672. creater := c.GetAdminUserInfo().AdminUser.Id
  6673. //创建一个出库单
  6674. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6675. WarehouseOutOrderNumber: warehousing_out_order,
  6676. OperationTime: operation_time,
  6677. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6678. Creater: creater,
  6679. Ctime: time.Now().Unix(),
  6680. Status: 1,
  6681. WarehouseOutTime: advice.AdviceDate,
  6682. Type: 0,
  6683. PatientId: advice.PatientId,
  6684. IsCheck: 1,
  6685. }
  6686. //查询今日是否有出库数据
  6687. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6688. if lastWarehouseOut.ID == 0 {
  6689. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6690. }
  6691. //出库
  6692. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6693. WarehouseOutId: lastWarehouseOut.ID,
  6694. WarehouseOutOrderNumber: warehousing_out_order,
  6695. DrugId: advice.DrugId,
  6696. Count: total_count,
  6697. Price: 0,
  6698. TotalPrice: 0,
  6699. Status: 1,
  6700. Ctime: advice.AdviceDate,
  6701. Mtime: advice.AdviceDate,
  6702. Remark: "",
  6703. OrgId: advice.UserOrgId,
  6704. Type: 0,
  6705. Manufacturer: selfBasedrug.Manufacturer,
  6706. Dealer: selfBasedrug.Dealer,
  6707. RetailPrice: 0,
  6708. RetailTotalPrice: 0,
  6709. CountUnit: advice.PrescribingNumberUnit,
  6710. ExpiryDate: 0,
  6711. ProductDate: 0,
  6712. Number: "",
  6713. BatchNumber: "",
  6714. IsSys: 0,
  6715. WarehouseInfoId: 0,
  6716. AdminUserId: 0,
  6717. StockCount: "",
  6718. IsCheck: 1,
  6719. SysRecordTime: advice.AdviceDate,
  6720. PatientId: advice.PatientId,
  6721. AdviceId: advice.ID,
  6722. ClassType: "",
  6723. }
  6724. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6725. for _, it := range warehousingOutInfo {
  6726. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6727. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6728. //出库逻辑
  6729. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6730. //查询剩余库存
  6731. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6732. var sum_count int64
  6733. for _, its := range stockInfo {
  6734. if its.MaxUnit == medical.MaxUnit {
  6735. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6736. }
  6737. sum_count += its.StockMaxNumber + its.StockMinNumber
  6738. }
  6739. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6740. }
  6741. }
  6742. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6743. //已收费和已发药的限制逻辑
  6744. isCharge := false
  6745. isMedicine := false
  6746. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6747. //获取今天该患者所有处方,判断是否发药或者收费
  6748. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6749. //for _, item := range new_prescriptions {
  6750. if new_prescription.IsMedicine == 1 {
  6751. isMedicine = true
  6752. }
  6753. //}
  6754. for _, item := range new_prescriptions {
  6755. if item.OrderStatus == 4 {
  6756. isCharge = true
  6757. }
  6758. }
  6759. if isMedicine {
  6760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6761. return
  6762. }
  6763. if isCharge {
  6764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6765. return
  6766. }
  6767. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6768. for _, item := range advices {
  6769. if item.IsMedicine == 1 {
  6770. isMedicine = true
  6771. }
  6772. }
  6773. if isMedicine {
  6774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6775. return
  6776. }
  6777. if new_prescription.ID > 0 {
  6778. if new_prescription.OrderStatus == 2 {
  6779. isCharge = true
  6780. }
  6781. }
  6782. if isCharge {
  6783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6784. return
  6785. }
  6786. //已收费和已发药的限制逻辑
  6787. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6788. redis := service.RedisClient()
  6789. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6790. redis.Set(keyFive, "", time.Second)
  6791. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6792. redis.Set(keyOne, "", time.Second)
  6793. defer redis.Close()
  6794. if err == nil {
  6795. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6796. //查询是否在处方中出库
  6797. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6798. if openConfig.IsOpen != 1 {
  6799. //判断该医嘱是否执行了
  6800. if advice.ExecutionState == 1 {
  6801. creater := c.GetAdminUserInfo().AdminUser.Id
  6802. service.DrugAutoAddCancelInfo(&advice, creater)
  6803. }
  6804. }
  6805. //开启保存处方扣减功能
  6806. if openConfig.IsOpen == 1 {
  6807. creater := c.GetAdminUserInfo().AdminUser.Id
  6808. service.DrugAutoAddCancelInfo(&advice, creater)
  6809. }
  6810. } else {
  6811. if drugOutConfig.IsOpen == 1 {
  6812. //查询是否在处方中出库
  6813. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6814. if openConfig.IsOpen != 1 {
  6815. //判断该医嘱是否执行了
  6816. if advice.ExecutionState == 1 {
  6817. creater := c.GetAdminUserInfo().AdminUser.Id
  6818. service.DrugAutoAddCancelInfo(&advice, creater)
  6819. }
  6820. }
  6821. //开启保存处方扣减功能
  6822. if openConfig.IsOpen == 1 {
  6823. creater := c.GetAdminUserInfo().AdminUser.Id
  6824. service.DrugAutoAddCancelInfo(&advice, creater)
  6825. }
  6826. } else {
  6827. //判断该医嘱是否执行了
  6828. if advice.ExecutionState == 1 {
  6829. creater := c.GetAdminUserInfo().AdminUser.Id
  6830. service.DrugAutoAddCancelInfo(&advice, creater)
  6831. }
  6832. }
  6833. }
  6834. c.ServeSuccessJSON(map[string]interface{}{
  6835. "msg": "删除成功",
  6836. })
  6837. return
  6838. } else {
  6839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6840. return
  6841. }
  6842. }
  6843. func (c *HisApiController) DeleteProject() {
  6844. id, _ := c.GetInt64("id")
  6845. adminInfo := c.GetAdminUserInfo()
  6846. project, _ := service.GetHisProjectByID(id)
  6847. // var consumable models.DialysisBeforePrepare
  6848. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6849. //耗材保存处方出库
  6850. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6851. isCharge := false
  6852. isMedicine := false
  6853. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6854. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6855. for _, item := range new_prescriptions {
  6856. if item.IsMedicine == 1 {
  6857. isMedicine = true
  6858. }
  6859. }
  6860. for _, item := range new_prescriptions {
  6861. if item.OrderStatus == 4 {
  6862. isCharge = true
  6863. }
  6864. }
  6865. if isMedicine {
  6866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6867. return
  6868. }
  6869. if isCharge {
  6870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6871. return
  6872. }
  6873. if new_prescription.ID > 0 {
  6874. if new_prescription.OrderStatus == 2 {
  6875. isCharge = true
  6876. }
  6877. }
  6878. if isCharge {
  6879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6880. return
  6881. }
  6882. service.DeletePrintInfo(id)
  6883. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6884. label.Status = 0
  6885. service.CreateHisLabelRecordTwo(&label)
  6886. fmt.Println(goodOutConfig.IsOpen)
  6887. if goodOutConfig.IsOpen != 1 {
  6888. if stockConfig.IsOpen == 1 {
  6889. if project.Type == 2 {
  6890. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6891. fmt.Println(err)
  6892. }
  6893. if project.Type == 3 && project.IsOut == 1 {
  6894. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6895. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6896. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6897. operation_time := time.Now().Unix()
  6898. creater := adminInfo.AdminUser.Id
  6899. //创建退库单
  6900. timeStr := time.Now().Format("2006-01-02")
  6901. timeArr := strings.Split(timeStr, "-")
  6902. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6903. total = total + 1
  6904. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6905. cancelStock := models.CancelStock{
  6906. OrderNumber: orderNumber,
  6907. OperaTime: operation_time,
  6908. OrgId: adminInfo.CurrentOrgId,
  6909. Creater: creater,
  6910. Ctime: time.Now().Unix(),
  6911. Status: 1,
  6912. ReturnTime: project.RecordDate,
  6913. Type: 1,
  6914. StorehouseId: houseConfig.StorehouseOutInfo,
  6915. IsCheck: 1,
  6916. }
  6917. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6918. if msgerrkonde == gorm.ErrRecordNotFound {
  6919. service.AddSigleCancelStock(&cancelStock)
  6920. }
  6921. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6922. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6923. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6924. //查询是否有出库
  6925. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6926. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6927. deaerler, _ := service.GetDealerById(info.Dealer)
  6928. if info.ID > 0 {
  6929. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6930. if info.Count >= prescribingNumber {
  6931. cancelStockInfo := models.CancelStockInfo{
  6932. GoodId: project.ProjectId,
  6933. CancelStockId: cancel.ID,
  6934. GoodTypeId: good.GoodTypeId,
  6935. Count: prescribingNumber,
  6936. Price: info.Price,
  6937. Total: 0,
  6938. ProductDate: info.ProductDate,
  6939. ExpiryDate: info.ExpiryDate,
  6940. Ctime: time.Now().Unix(),
  6941. Status: 1,
  6942. OrgId: adminInfo.CurrentOrgId,
  6943. OrderNumber: cancel.OrderNumber,
  6944. Type: 0,
  6945. Dealer: deaerler.DealerName,
  6946. Manufacturer: manufacturer.ManufacturerName,
  6947. Number: info.Number,
  6948. RegisterAccount: "",
  6949. Remark: "",
  6950. WarehouseInfoId: info.WarehouseInfotId,
  6951. PatientId: info.PatientId,
  6952. RecordDate: info.SysRecordTime,
  6953. StorehouseId: houseConfig.StorehouseOutInfo,
  6954. IsCheck: 1,
  6955. }
  6956. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6957. //回退库存
  6958. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6959. //退库数量增加
  6960. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6961. //出库数量减少
  6962. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6963. }
  6964. if info.Count < prescribingNumber {
  6965. cancelStockInfo := models.CancelStockInfo{
  6966. GoodId: project.ProjectId,
  6967. CancelStockId: cancel.ID,
  6968. GoodTypeId: good.GoodTypeId,
  6969. Count: info.Count,
  6970. Price: info.Price,
  6971. Total: 0,
  6972. ProductDate: info.ProductDate,
  6973. ExpiryDate: info.ExpiryDate,
  6974. Ctime: time.Now().Unix(),
  6975. Status: 1,
  6976. OrgId: adminInfo.CurrentOrgId,
  6977. OrderNumber: cancel.OrderNumber,
  6978. Type: 0,
  6979. Dealer: deaerler.DealerName,
  6980. Manufacturer: manufacturer.ManufacturerName,
  6981. Number: info.Number,
  6982. RegisterAccount: "",
  6983. Remark: "",
  6984. WarehouseInfoId: info.WarehouseInfotId,
  6985. PatientId: info.PatientId,
  6986. RecordDate: info.SysRecordTime,
  6987. StorehouseId: houseConfig.StorehouseOutInfo,
  6988. IsCheck: 1,
  6989. }
  6990. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6991. //回退库存
  6992. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6993. //退库数量增加
  6994. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6995. //出库数量减少
  6996. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6997. }
  6998. //查询剩余库存
  6999. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7000. var over_count int64
  7001. for _, it := range goodList {
  7002. over_count += it.StockCount
  7003. }
  7004. //出库数据 大于 退库数量
  7005. if info.Count >= prescribingNumber {
  7006. flow := models.VmStockFlow{
  7007. WarehousingId: info.WarehouseInfotId,
  7008. GoodId: project.ProjectId,
  7009. Number: info.Number,
  7010. LicenseNumber: info.LicenseNumber,
  7011. Count: prescribingNumber,
  7012. UserOrgId: adminInfo.CurrentOrgId,
  7013. PatientId: project.PatientId,
  7014. SystemTime: info.SysRecordTime,
  7015. ConsumableType: 7,
  7016. IsSys: 0,
  7017. WarehousingOrder: "",
  7018. WarehouseOutId: info.WarehouseOutId,
  7019. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7020. IsEdit: 0,
  7021. CancelStockId: cancel.ID,
  7022. CancelOrderNumber: cancel.OrderNumber,
  7023. Manufacturer: manufacturer.ID,
  7024. Dealer: 0,
  7025. Creator: adminInfo.AdminUser.Id,
  7026. UpdateCreator: 0,
  7027. Status: 1,
  7028. Ctime: time.Now().Unix(),
  7029. Mtime: 0,
  7030. Price: info.Price,
  7031. WarehousingDetailId: info.WarehouseInfotId,
  7032. WarehouseOutDetailId: info.ID,
  7033. CancelOutDetailId: cancelInfo.ID,
  7034. ProductDate: info.ProductDate,
  7035. ExpireDate: info.ExpiryDate,
  7036. StorehouseId: houseConfig.StorehouseOutInfo,
  7037. OverCount: over_count,
  7038. OperateTime: time.Now().Unix(),
  7039. }
  7040. service.CreateStockFlowOne(flow)
  7041. }
  7042. //出库数据小于退库数据
  7043. if info.Count < prescribingNumber {
  7044. flow := models.VmStockFlow{
  7045. WarehousingId: info.WarehouseInfotId,
  7046. GoodId: project.ProjectId,
  7047. Number: info.Number,
  7048. LicenseNumber: info.LicenseNumber,
  7049. Count: info.Count,
  7050. UserOrgId: adminInfo.CurrentOrgId,
  7051. PatientId: project.PatientId,
  7052. SystemTime: info.SysRecordTime,
  7053. ConsumableType: 7,
  7054. IsSys: 0,
  7055. WarehousingOrder: "",
  7056. WarehouseOutId: info.WarehouseOutId,
  7057. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7058. IsEdit: 0,
  7059. CancelStockId: cancel.ID,
  7060. CancelOrderNumber: cancel.OrderNumber,
  7061. Manufacturer: manufacturer.ID,
  7062. Dealer: 0,
  7063. Creator: adminInfo.AdminUser.Id,
  7064. UpdateCreator: 0,
  7065. Status: 1,
  7066. Ctime: time.Now().Unix(),
  7067. Mtime: 0,
  7068. Price: info.Price,
  7069. WarehousingDetailId: info.WarehouseInfotId,
  7070. WarehouseOutDetailId: info.ID,
  7071. CancelOutDetailId: cancelInfo.ID,
  7072. ProductDate: info.ProductDate,
  7073. ExpireDate: info.ExpiryDate,
  7074. StorehouseId: houseConfig.StorehouseOutInfo,
  7075. OverCount: over_count,
  7076. OperateTime: time.Now().Unix(),
  7077. }
  7078. service.CreateStockFlowOne(flow)
  7079. }
  7080. //查询已出库数量
  7081. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7082. if prescribingNumber < dialysisInfo.Count {
  7083. //改变数量
  7084. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7085. }
  7086. if prescribingNumber >= dialysisInfo.Count {
  7087. //删除出库表
  7088. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7089. }
  7090. //更新剩余库存
  7091. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7092. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7093. var total_count_one int64
  7094. for _, it := range stockList {
  7095. total_count_one += it.StockCount
  7096. }
  7097. //基础库插入数据
  7098. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7099. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7100. var flush_count int64
  7101. for _, it := range goodListOne {
  7102. flush_count += it.StockCount
  7103. }
  7104. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7105. if errs != nil {
  7106. goodErrcode := models.XtGoodErrcode{
  7107. UserOrgId: project.UserOrgId,
  7108. Errcode: "手动出库更新剩余出库失败",
  7109. GoodId: project.ProjectId,
  7110. Status: 1,
  7111. Ctime: time.Now().Unix(),
  7112. Mtime: 0,
  7113. Count: 0,
  7114. StockCount: 0,
  7115. Creater: creater,
  7116. BatchNumberId: 0,
  7117. WarehouseOutId: 0,
  7118. }
  7119. service.CreateGoodErrcode(goodErrcode)
  7120. }
  7121. }
  7122. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7123. fmt.Println(err)
  7124. } else {
  7125. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7126. fmt.Println(err)
  7127. }
  7128. } else {
  7129. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7130. fmt.Println(err)
  7131. }
  7132. }
  7133. //保存处方出库
  7134. if goodOutConfig.IsOpen == 1 {
  7135. if project.Type == 3 {
  7136. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7137. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7138. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7139. operation_time := time.Now().Unix()
  7140. creater := adminInfo.AdminUser.Id
  7141. //创建退库单
  7142. timeStr := time.Now().Format("2006-01-02")
  7143. timeArr := strings.Split(timeStr, "-")
  7144. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7145. total = total + 1
  7146. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7147. cancelStock := models.CancelStock{
  7148. OrderNumber: orderNumber,
  7149. OperaTime: operation_time,
  7150. OrgId: adminInfo.CurrentOrgId,
  7151. Creater: creater,
  7152. Ctime: time.Now().Unix(),
  7153. Status: 1,
  7154. ReturnTime: project.RecordDate,
  7155. Type: 1,
  7156. StorehouseId: houseConfig.StorehouseOutInfo,
  7157. IsCheck: 1,
  7158. }
  7159. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7160. if msgerrkonde == gorm.ErrRecordNotFound {
  7161. service.AddSigleCancelStock(&cancelStock)
  7162. }
  7163. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7164. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7165. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7166. //获取出库数据
  7167. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7168. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7169. deaerler, _ := service.GetDealerById(info.Dealer)
  7170. if info.ID > 0 {
  7171. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7172. if info.Count >= prescribingNumber {
  7173. cancelStockInfo := models.CancelStockInfo{
  7174. GoodId: project.ProjectId,
  7175. CancelStockId: cancel.ID,
  7176. GoodTypeId: good.GoodTypeId,
  7177. Count: prescribingNumber,
  7178. Price: info.Price,
  7179. Total: 0,
  7180. ProductDate: info.ProductDate,
  7181. ExpiryDate: info.ExpiryDate,
  7182. Ctime: time.Now().Unix(),
  7183. Status: 1,
  7184. OrgId: adminInfo.CurrentOrgId,
  7185. OrderNumber: cancel.OrderNumber,
  7186. Type: 0,
  7187. Dealer: deaerler.DealerName,
  7188. Manufacturer: manufacturer.ManufacturerName,
  7189. Number: info.Number,
  7190. RegisterAccount: "",
  7191. Remark: "",
  7192. WarehouseInfoId: info.WarehouseInfotId,
  7193. PatientId: info.PatientId,
  7194. RecordDate: info.SysRecordTime,
  7195. StorehouseId: houseConfig.StorehouseOutInfo,
  7196. IsCheck: 1,
  7197. }
  7198. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7199. //退库数量增加
  7200. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7201. //出库数量减少
  7202. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7203. }
  7204. if info.Count < prescribingNumber {
  7205. cancelStockInfo := models.CancelStockInfo{
  7206. GoodId: project.ProjectId,
  7207. CancelStockId: cancel.ID,
  7208. GoodTypeId: good.GoodTypeId,
  7209. Count: prescribingNumber,
  7210. Price: info.Price,
  7211. Total: 0,
  7212. ProductDate: info.ProductDate,
  7213. ExpiryDate: info.ExpiryDate,
  7214. Ctime: time.Now().Unix(),
  7215. Status: 1,
  7216. OrgId: adminInfo.CurrentOrgId,
  7217. OrderNumber: cancel.OrderNumber,
  7218. Type: 0,
  7219. Dealer: deaerler.DealerName,
  7220. Manufacturer: manufacturer.ManufacturerName,
  7221. Number: info.Number,
  7222. RegisterAccount: "",
  7223. Remark: "",
  7224. WarehouseInfoId: info.WarehouseInfotId,
  7225. PatientId: info.PatientId,
  7226. RecordDate: info.SysRecordTime,
  7227. StorehouseId: houseConfig.StorehouseOutInfo,
  7228. IsCheck: 1,
  7229. }
  7230. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7231. //回退库存
  7232. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7233. }
  7234. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7235. var over_count int64
  7236. for _, it := range goodList {
  7237. over_count += it.StockCount
  7238. }
  7239. //查询出库数量
  7240. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7241. //出库数据 大于 退库数量
  7242. if len(list) > 0 {
  7243. for _, it := range list {
  7244. //回退库存
  7245. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7246. //退库数量增加
  7247. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7248. //出库数量减少
  7249. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7250. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7251. var over_count_one int64
  7252. for _, it := range goodList {
  7253. over_count_one += it.StockCount
  7254. }
  7255. //查询该批次是否有退库数据
  7256. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7257. flow := models.VmStockFlow{
  7258. WarehousingId: it.WarehouseInfotId,
  7259. GoodId: it.GoodId,
  7260. Number: it.Number,
  7261. LicenseNumber: it.LicenseNumber,
  7262. Count: it.Count,
  7263. UserOrgId: adminInfo.CurrentOrgId,
  7264. PatientId: it.PatientId,
  7265. SystemTime: it.SysRecordTime,
  7266. ConsumableType: 7,
  7267. IsSys: 0,
  7268. WarehousingOrder: "",
  7269. WarehouseOutId: it.WarehouseOutId,
  7270. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7271. IsEdit: 0,
  7272. CancelStockId: cancel.ID,
  7273. CancelOrderNumber: cancel.OrderNumber,
  7274. Manufacturer: manufacturer.ID,
  7275. Dealer: 0,
  7276. Creator: adminInfo.AdminUser.Id,
  7277. UpdateCreator: 0,
  7278. Status: 1,
  7279. Ctime: time.Now().Unix(),
  7280. Mtime: 0,
  7281. Price: it.Price,
  7282. WarehousingDetailId: it.WarehouseInfotId,
  7283. WarehouseOutDetailId: it.ID,
  7284. CancelOutDetailId: cancelInfo.ID,
  7285. ProductDate: it.ProductDate,
  7286. ExpireDate: it.ExpiryDate,
  7287. StorehouseId: houseConfig.StorehouseOutInfo,
  7288. OverCount: over_count_one,
  7289. OperateTime: time.Now().Unix(),
  7290. }
  7291. service.CreateStockFlowOne(flow)
  7292. }
  7293. }
  7294. //查询已出库数量
  7295. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7296. if prescribingNumber < dialysisInfo.Count {
  7297. //改变数量
  7298. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7299. }
  7300. if prescribingNumber >= dialysisInfo.Count {
  7301. //删除出库表
  7302. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7303. }
  7304. //更新剩余库存
  7305. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7306. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7307. var total_count_one int64
  7308. for _, it := range stockList {
  7309. total_count_one += it.StockCount
  7310. }
  7311. //基础库插入数据
  7312. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7313. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7314. var flush_count int64
  7315. for _, it := range goodListOne {
  7316. flush_count += it.StockCount
  7317. }
  7318. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7319. if errs != nil {
  7320. goodErrcode := models.XtGoodErrcode{
  7321. UserOrgId: project.UserOrgId,
  7322. Errcode: "手动出库更新剩余出库失败",
  7323. GoodId: project.ProjectId,
  7324. Status: 1,
  7325. Ctime: time.Now().Unix(),
  7326. Mtime: 0,
  7327. Count: 0,
  7328. StockCount: 0,
  7329. Creater: creater,
  7330. BatchNumberId: 0,
  7331. WarehouseOutId: 0,
  7332. }
  7333. service.CreateGoodErrcode(goodErrcode)
  7334. }
  7335. }
  7336. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7337. fmt.Println(err)
  7338. } else {
  7339. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7340. fmt.Println(err)
  7341. }
  7342. }
  7343. c.ServeSuccessJSON(map[string]interface{}{
  7344. "msg": "删除成功",
  7345. })
  7346. return
  7347. }
  7348. func (c *HisApiController) CreateHisAdditionalCharge() {
  7349. his_patient_id, _ := c.GetInt64("his_patient_id")
  7350. patient_id, _ := c.GetInt64("patient_id")
  7351. record_date := c.GetString("record_date")
  7352. timeLayout := "2006-01-02"
  7353. loc, _ := time.LoadLocation("Local")
  7354. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7355. if err != nil {
  7356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7357. return
  7358. }
  7359. adminInfo := c.GetAdminUserInfo()
  7360. recordDateTime := theTime.Unix()
  7361. dataBody := make(map[string]interface{}, 0)
  7362. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7363. if err != nil {
  7364. utils.ErrorLog(err.Error())
  7365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7366. return
  7367. }
  7368. var additions []*models.HisAdditionalCharge
  7369. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7370. additions, _ := dataBody["addition"].([]interface{})
  7371. if len(additions) > 0 {
  7372. for _, item := range additions {
  7373. items := item.(map[string]interface{})
  7374. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7375. utils.ErrorLog("item_id")
  7376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7377. return
  7378. }
  7379. item_id := int64(items["item_id"].(float64))
  7380. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7381. utils.ErrorLog("item_name")
  7382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7383. return
  7384. }
  7385. item_name := items["item_name"].(string)
  7386. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7387. utils.ErrorLog("price")
  7388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7389. return
  7390. }
  7391. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7392. ctime := time.Now().Unix()
  7393. additional := &models.HisAdditionalCharge{
  7394. PatientId: patient_id,
  7395. HisPatientId: his_patient_id,
  7396. UserOrgId: adminInfo.CurrentOrgId,
  7397. RecordDate: recordDateTime,
  7398. CreatedTime: ctime,
  7399. UpdatedTime: ctime,
  7400. Modifier: adminInfo.AdminUser.Id,
  7401. Creator: adminInfo.AdminUser.Id,
  7402. Price: price,
  7403. ItemName: item_name,
  7404. ItemId: item_id,
  7405. Status: 1,
  7406. }
  7407. additions = append(additions, additional)
  7408. }
  7409. }
  7410. }
  7411. for _, item := range additions {
  7412. service.CreateAddtionalCharge(item)
  7413. }
  7414. c.ServeSuccessJSON(map[string]interface{}{
  7415. "msg": "创建成功",
  7416. })
  7417. }
  7418. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7419. blood_fat := c.GetString("blood_fat")
  7420. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7421. blood_sugar := c.GetString("blood_sugar")
  7422. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7423. chief_conplaint := c.GetString("chief_conplaint")
  7424. dbp := c.GetString("dbp")
  7425. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7426. delivery_way, _ := c.GetInt64("delivery_way")
  7427. diagnostic := c.GetString("diagnostic")
  7428. family_history := c.GetString("family_history")
  7429. height := c.GetString("height")
  7430. history_of_present_illness := c.GetString("history_of_present_illness")
  7431. is_infect, _ := c.GetInt64("is_infect")
  7432. past_history := c.GetString("past_history")
  7433. patient_id, _ := c.GetInt64("patient_id")
  7434. his_patient_id, _ := c.GetInt64("his_patient_id")
  7435. personal_history := c.GetString("personal_history")
  7436. pulse := c.GetString("pulse")
  7437. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7438. sbp := c.GetString("sbp")
  7439. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7440. heightfloat, _ := strconv.ParseFloat(height, 64)
  7441. sicktype := c.GetString("sick_type")
  7442. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7443. symptom := c.GetString("symptom")
  7444. sick_date := c.GetString("sick_date")
  7445. temperatures := c.GetString("temperature")
  7446. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7447. record_date := c.GetString("record_date")
  7448. breathing := c.GetString("breathing")
  7449. doctor_advice := c.GetString("doctor_advice")
  7450. remark := c.GetString("remark")
  7451. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7452. sick, _ := c.GetInt64("sick")
  7453. diagnose, _ := c.GetInt64("diagnose")
  7454. //id, _ := c.GetInt64("id")
  7455. timeLayout := "2006-01-02"
  7456. loc, _ := time.LoadLocation("Local")
  7457. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7458. allergic_history := c.GetString("allergic_history")
  7459. if err != nil {
  7460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7461. return
  7462. }
  7463. recordDateTime := theTime.Unix()
  7464. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7465. if err != nil {
  7466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7467. return
  7468. }
  7469. sickTimes := sickTime.Unix()
  7470. ctime := time.Now().Unix()
  7471. primary_disease := c.GetString("primary_disease")
  7472. confirm_failure_date := c.GetString("confirm_failure_date")
  7473. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7474. drug_allergy_history := c.GetString("drug_allergy_history")
  7475. physical_examination := c.GetString("physical_examination")
  7476. special_inspection := c.GetString("special_inspection")
  7477. lab_apparatus := c.GetString("lab_apparatus")
  7478. caseHistory := models.HisPatientCaseHistory{
  7479. HisPatientId: his_patient_id,
  7480. PatientId: patient_id,
  7481. Temperature: temperature,
  7482. BloodSugar: bloodsugarfloat,
  7483. Pulse: pulsefloat,
  7484. Sbp: sbpfloat,
  7485. Dbp: dbpfloat,
  7486. Height: heightfloat,
  7487. BloodFat: bloodfatfloat,
  7488. SickType: sick_type,
  7489. Symptom: symptom,
  7490. SickDate: sickTimes,
  7491. IsInfect: is_infect,
  7492. HistoryOfPresentIllness: history_of_present_illness,
  7493. PastHistory: past_history,
  7494. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7495. ChiefConplaint: chief_conplaint,
  7496. PersonalHistory: personal_history,
  7497. FamilyHistory: family_history,
  7498. Diagnostic: diagnostic,
  7499. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7500. Status: 1,
  7501. Ctime: ctime,
  7502. Mtime: ctime,
  7503. RecordDate: recordDateTime,
  7504. DeliveryWay: delivery_way,
  7505. Breathing: breathingfloat,
  7506. DoctorAdvice: doctor_advice,
  7507. Remark: remark,
  7508. Sick: sick,
  7509. Diagnose: diagnose,
  7510. AllergicHistory: allergic_history,
  7511. PrimaryDisease: primary_disease,
  7512. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7513. DrugAllergyHistory: drug_allergy_history,
  7514. PhysicalExamination: physical_examination,
  7515. SpecialInspection: special_inspection,
  7516. LabApparatus: lab_apparatus,
  7517. }
  7518. //查询该患者是否有病历
  7519. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7520. if errcodes == gorm.ErrRecordNotFound {
  7521. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7522. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7523. if err != nil {
  7524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7525. return
  7526. }
  7527. c.ServeSuccessJSON(map[string]interface{}{
  7528. "caseHistory": caseHistory,
  7529. "historyInfo": historyInfo,
  7530. })
  7531. return
  7532. } else if errcodes == nil {
  7533. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7534. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7535. if err != nil {
  7536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7537. return
  7538. }
  7539. c.ServeSuccessJSON(map[string]interface{}{
  7540. "caseHistory": caseHistory,
  7541. "historyInfo": historyInfo,
  7542. })
  7543. }
  7544. //查询该患者是否有病历
  7545. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7546. //if errcode == gorm.ErrRecordNotFound {
  7547. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7548. // if err != nil {
  7549. // c.ServeSuccessJSON(map[string]interface{}{
  7550. // "msg": "保存成功",
  7551. // })
  7552. // }
  7553. //} else if errcode == nil {
  7554. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7555. // return
  7556. //}
  7557. }
  7558. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7559. patient_id, _ := c.GetInt64("patient_id", 0)
  7560. adminUser := c.GetAdminUserInfo()
  7561. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7562. c.ServeSuccessJSON(map[string]interface{}{
  7563. "list": caseHistorys,
  7564. })
  7565. }
  7566. func (c *HisApiController) GetHisPatientCaseHistory() {
  7567. record_date, _ := c.GetInt64("record_date", 0)
  7568. patient_id, _ := c.GetInt64("patient_id", 0)
  7569. admin := c.GetAdminUserInfo()
  7570. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7571. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7572. c.ServeSuccessJSON(map[string]interface{}{
  7573. "info": info,
  7574. "case_history": case_history,
  7575. })
  7576. }
  7577. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7578. template_name := c.GetString("template_name")
  7579. template_remark := c.GetString("template_remark")
  7580. doctor := c.GetAdminUserInfo().AdminUser.Id
  7581. diagnostic := c.GetString("diagnostic")
  7582. chief_conplaint := c.GetString("chief_conplain")
  7583. history_of_present_illness := c.GetString("history_of_present_illness")
  7584. past_history := c.GetString("past_history")
  7585. personal_history := c.GetString("personal_history")
  7586. family_history := c.GetString("family_history")
  7587. user_name := c.GetString("user_name")
  7588. doctor_advice := c.GetString("doctor_advice")
  7589. remark := c.GetString("remark")
  7590. //record_date := c.GetString("record_date")
  7591. //fmt.Println("record_date--------",record_date)
  7592. //timeLayout := "2006-01-02"
  7593. //loc, _ := time.LoadLocation("Local")
  7594. //
  7595. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7596. //if err != nil {
  7597. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7598. // return
  7599. //}
  7600. //recordDateTime := theTime.Unix()
  7601. ctime := time.Now().Unix()
  7602. template := models.HisCaseHistoryTemplate{
  7603. HistoryOfPresentIllness: history_of_present_illness,
  7604. PastHistory: past_history,
  7605. ChiefConplaint: chief_conplaint,
  7606. PersonalHistory: personal_history,
  7607. FamilyHistory: family_history,
  7608. Diagnostic: diagnostic,
  7609. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7610. Status: 1,
  7611. Ctime: ctime,
  7612. Mtime: ctime,
  7613. RecordDate: time.Now().Unix(),
  7614. TemplateName: template_name,
  7615. TemplateRemark: template_remark,
  7616. Creator: doctor,
  7617. Modifier: doctor,
  7618. UserName: user_name,
  7619. DoctorAdvice: doctor_advice,
  7620. Remark: remark,
  7621. }
  7622. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7623. if err == nil {
  7624. c.ServeSuccessJSON(map[string]interface{}{
  7625. "msg": "保存成功",
  7626. })
  7627. } else {
  7628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7629. return
  7630. }
  7631. }
  7632. func (c *HisApiController) GetCaseHistoryTemplate() {
  7633. timeLayout := "2006-01-02"
  7634. loc, _ := time.LoadLocation("Local")
  7635. keyword := c.GetString("keyword")
  7636. start_time := c.GetString("start_time")
  7637. end_time := c.GetString("end_time")
  7638. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7639. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7640. admin := c.GetAdminUserInfo()
  7641. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7642. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7643. c.ServeSuccessJSON(map[string]interface{}{
  7644. "template": template,
  7645. //"history": history,
  7646. })
  7647. }
  7648. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7649. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7650. utils.ErrorLog("drug_name")
  7651. return enums.ErrorCodeParamWrong
  7652. }
  7653. adviceName, _ := json["drug_name"].(string)
  7654. if len(adviceName) == 0 {
  7655. utils.ErrorLog("len(advice_name) == 0")
  7656. return enums.ErrorCodeParamWrong
  7657. }
  7658. advice.AdviceName = adviceName
  7659. adviceDesc, _ := json["advice_desc"].(string)
  7660. advice.AdviceDesc = adviceDesc
  7661. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7662. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7663. advice.DrugSpec = drugSpec
  7664. }
  7665. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7666. remark, _ := json["remark"].(string)
  7667. advice.Remark = remark
  7668. }
  7669. if json["id"] == nil {
  7670. advice.DrugId = 0
  7671. } else {
  7672. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7673. drug_id := int64(json["id"].(float64))
  7674. advice.DrugId = drug_id
  7675. }
  7676. }
  7677. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7678. advice_id := int64(json["advice_id"].(float64))
  7679. advice.ID = advice_id
  7680. if advice.ID > 0 {
  7681. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7682. if err == nil {
  7683. if hisAdvice.ID > 0 {
  7684. advice.ExecutionTime = hisAdvice.ExecutionTime
  7685. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7686. advice.ExecutionState = hisAdvice.ExecutionState
  7687. advice.CheckTime = hisAdvice.CheckTime
  7688. advice.Checker = hisAdvice.Checker
  7689. advice.CheckState = hisAdvice.CheckState
  7690. advice.StartTime = hisAdvice.StartTime
  7691. advice.FeedetlSn = hisAdvice.FeedetlSn
  7692. }
  7693. }
  7694. }
  7695. }
  7696. //
  7697. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7698. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7699. // advice.ExecutionTime = execution_time
  7700. //}
  7701. //
  7702. //
  7703. //
  7704. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7705. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7706. // advice.ExecutionStaff = execution_staff
  7707. //}
  7708. //
  7709. //
  7710. //
  7711. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7712. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7713. // advice.ExecutionState = execution_state
  7714. //}
  7715. //
  7716. //
  7717. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7718. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7719. // advice.CheckTime = check_time
  7720. //}
  7721. //
  7722. //
  7723. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7724. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7725. // advice.CheckState = check_state
  7726. //}
  7727. //
  7728. //
  7729. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7730. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7731. // advice.Checker = checker
  7732. //}
  7733. //
  7734. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7735. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7736. // advice.StartTime = start_time
  7737. //}
  7738. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7739. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7740. advice.IsSelfDrug = is_self_drug
  7741. }
  7742. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7743. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7744. drug_way_count, _ := json["drug_way_count"].(string)
  7745. advice.DrugWayCount = drug_way_count
  7746. }
  7747. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7748. drugSpecUnit, _ := json["min_unit"].(string)
  7749. advice.DrugSpecUnit = drugSpecUnit
  7750. }
  7751. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7752. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7753. advice.SingleDose = singleDose
  7754. }
  7755. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7756. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7757. advice.SingleDoseUnit = singleDoseUnit
  7758. }
  7759. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7760. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7761. advice.PrescribingNumber = prescribingNumber
  7762. }
  7763. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7764. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7765. advice.PrescribingNumberUnit = prescribingNumberUnit
  7766. }
  7767. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7768. deliveryWay, _ := json["delivery_way"].(string)
  7769. advice.DeliveryWay = deliveryWay
  7770. }
  7771. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7772. executionFrequency, _ := json["execution_frequency"].(string)
  7773. advice.ExecutionFrequency = executionFrequency
  7774. }
  7775. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7776. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7777. advice.Price = price
  7778. }
  7779. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7780. med_list_codg, _ := json["medical_insurance_number"].(string)
  7781. advice.MedListCodg = med_list_codg
  7782. }
  7783. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7784. day := int64(json["day"].(float64))
  7785. advice.Day = day
  7786. }
  7787. return 0
  7788. }
  7789. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7790. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7791. id := int64(json["id"].(float64))
  7792. project.ID = id
  7793. historyProject, _ := service.GetHisProjectByID(id)
  7794. project.FeedetlSn = historyProject.FeedetlSn
  7795. }
  7796. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7797. project_id := int64(json["project_id"].(float64))
  7798. project.ProjectId = project_id
  7799. }
  7800. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7801. // price := int64(json["price"].(float64))
  7802. // formatInt_price := strconv.FormatInt(price, 10)
  7803. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7804. // project.Price = float_price
  7805. // }
  7806. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7807. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7808. project.Price = price
  7809. }
  7810. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7811. total, _ := json["total"].(string)
  7812. project.Count = total
  7813. }
  7814. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7815. medical_code, _ := json["medical_code"].(string)
  7816. project.MedListCodg = medical_code
  7817. }
  7818. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7819. single_dose, _ := json["single_dose"].(string)
  7820. project.SingleDose = single_dose
  7821. }
  7822. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7823. delivery_way, _ := json["delivery_way"].(string)
  7824. project.DeliveryWay = delivery_way
  7825. }
  7826. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7827. execution_frequency, _ := json["execution_frequency"].(string)
  7828. project.ExecutionFrequency = execution_frequency
  7829. }
  7830. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7831. remark, _ := json["remark"].(string)
  7832. project.Remark = remark
  7833. }
  7834. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7835. day, _ := json["number_days"].(string)
  7836. project.Day = day
  7837. }
  7838. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7839. unit, _ := json["unit"].(string)
  7840. project.Unit = unit
  7841. }
  7842. return 0
  7843. }
  7844. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7845. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7846. id := int64(json["id"].(float64))
  7847. historyAddtions, _ := service.GetHisAdditionByID(id)
  7848. additionalCharge.ID = id
  7849. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7850. }
  7851. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7852. item_id := int64(json["item_id"].(float64))
  7853. additionalCharge.ItemId = item_id
  7854. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7855. if config.ID > 0 {
  7856. if len(config.Code) > 0 {
  7857. additionalCharge.MedListCodg = config.Code
  7858. }
  7859. }
  7860. }
  7861. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7862. // price := int64(json["price"].(float64))
  7863. // formatInt_price := strconv.FormatInt(price, 10)
  7864. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7865. // additionalCharge.Price = float_price
  7866. // }
  7867. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7868. // price := int64(json["price"].(float64))
  7869. // formatInt_price := strconv.FormatInt(price, 10)
  7870. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7871. // additionalCharge.Price = float_price
  7872. //}
  7873. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7874. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7875. additionalCharge.Price = price
  7876. }
  7877. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7878. count, _ := json["count"].(string)
  7879. counts, _ := strconv.ParseInt(count, 10, 64)
  7880. additionalCharge.Count = counts
  7881. }
  7882. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7883. item_name, _ := json["item_name"].(string)
  7884. additionalCharge.ItemName = item_name
  7885. }
  7886. return 0
  7887. }
  7888. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7889. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7890. utils.ErrorLog("drug_name")
  7891. return enums.ErrorCodeParamWrong
  7892. }
  7893. adviceName, _ := json["drug_name"].(string)
  7894. if len(adviceName) == 0 {
  7895. utils.ErrorLog("len(advice_name) == 0")
  7896. return enums.ErrorCodeParamWrong
  7897. }
  7898. advice.AdviceName = adviceName
  7899. adviceDesc, _ := json["advice_desc"].(string)
  7900. advice.AdviceDesc = adviceDesc
  7901. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7902. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7903. advice.DrugSpec = drugSpec
  7904. }
  7905. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7906. remark, _ := json["remark"].(string)
  7907. advice.Remark = remark
  7908. }
  7909. if json["id"] == nil {
  7910. advice.DrugId = 0
  7911. } else {
  7912. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7913. drug_id := int64(json["id"].(float64))
  7914. advice.DrugId = drug_id
  7915. }
  7916. }
  7917. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7918. groupno := int64(json["groupno"].(float64))
  7919. advice.Groupno = groupno
  7920. }
  7921. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7922. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7923. advice.IsSelfDrug = is_self_drug
  7924. }
  7925. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7926. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7927. drug_way_count, _ := json["drug_way_count"].(string)
  7928. advice.DrugWayCount = drug_way_count
  7929. }
  7930. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7931. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7932. advice.HospApprFlag = hosp_appr_flag
  7933. }
  7934. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7935. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7936. advice.PrescribingNumber = prescribingNumber
  7937. }
  7938. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7939. // frequency_type := int64(json["frequency_type"].(float64))
  7940. // advice.FrequencyType = frequency_type
  7941. //}
  7942. //
  7943. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7944. // day_count := int64(json["day_count"].(float64))
  7945. // advice.DayCount = day_count
  7946. //}
  7947. //
  7948. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7949. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7950. // week_day, _ := json["week_day"].(string)
  7951. // advice.WeekDay = week_day
  7952. //}
  7953. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7954. drugSpecUnit, _ := json["min_unit"].(string)
  7955. advice.DrugSpecUnit = drugSpecUnit
  7956. }
  7957. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7958. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7959. advice.SingleDose = singleDose
  7960. }
  7961. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7962. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7963. advice.SingleDoseUnit = singleDoseUnit
  7964. }
  7965. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7966. deliveryWay, _ := json["delivery_way"].(string)
  7967. advice.DeliveryWay = deliveryWay
  7968. }
  7969. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7970. executionFrequency, _ := json["execution_frequency"].(string)
  7971. advice.ExecutionFrequency = executionFrequency
  7972. }
  7973. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7974. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7975. advice.Price = price
  7976. }
  7977. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7978. med_list_codg, _ := json["medical_insurance_number"].(string)
  7979. advice.MedListCodg = med_list_codg
  7980. }
  7981. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7982. day := int64(json["day"].(float64))
  7983. advice.Day = day
  7984. }
  7985. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7986. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7987. advice.PrescribingNumberUnit = prescribingNumberUnit
  7988. }
  7989. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7990. advice_id := int64(json["advice_id"].(float64))
  7991. advice.ID = advice_id
  7992. if advice.ID > 0 {
  7993. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7994. if err == nil {
  7995. if hisAdvice.ID > 0 {
  7996. advice.ExecutionTime = hisAdvice.ExecutionTime
  7997. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7998. advice.ExecutionState = hisAdvice.ExecutionState
  7999. advice.CheckTime = hisAdvice.CheckTime
  8000. advice.Checker = hisAdvice.Checker
  8001. advice.CheckState = hisAdvice.CheckState
  8002. advice.StartTime = hisAdvice.StartTime
  8003. advice.HospApprFlag = hisAdvice.HospApprFlag
  8004. advice.IsMedicine = hisAdvice.IsMedicine
  8005. if hisAdvice.UserOrgId == 10028 {
  8006. 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 {
  8007. advice.ExecutionTime = 0
  8008. advice.ExecutionStaff = 0
  8009. advice.ExecutionState = 2
  8010. advice.CheckTime = 0
  8011. advice.Checker = 0
  8012. advice.CheckState = 2
  8013. }
  8014. } else {
  8015. 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 {
  8016. advice.ExecutionTime = 0
  8017. advice.ExecutionStaff = 0
  8018. advice.ExecutionState = 2
  8019. advice.CheckTime = 0
  8020. advice.Checker = 0
  8021. advice.CheckState = 2
  8022. advice.UpdatedTime = time.Now().Unix()
  8023. }
  8024. }
  8025. //advice.Groupno = hisAdvice.Groupno
  8026. }
  8027. }
  8028. }
  8029. }
  8030. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8031. //
  8032. //if drugStockConfig.IsOpen == 1 {
  8033. //
  8034. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8035. // if advice.ID == 0 { //医嘱不存在
  8036. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8037. // drug.Total = drug.Total - advice.PrescribingNumber
  8038. // service.UpdateBaseDrugLib(&drug)
  8039. //
  8040. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8041. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8042. // drug.Total = drug.Total - num
  8043. // service.UpdateBaseDrugLib(&drug)
  8044. // }
  8045. //
  8046. // } else if advice.ID > 0 { //医嘱存在
  8047. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8048. // var num float64
  8049. //
  8050. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8051. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8052. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8053. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8054. // drug.Total = drug.Total + num
  8055. // service.UpdateBaseDrugLib(&drug)
  8056. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8057. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8058. // drug.Total = drug.Total - num
  8059. // service.UpdateBaseDrugLib(&drug)
  8060. // }
  8061. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8062. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8063. // if num2 > advice.PrescribingNumber {
  8064. // num = num2 - advice.PrescribingNumber
  8065. // drug.Total = drug.Total + num
  8066. // service.UpdateBaseDrugLib(&drug)
  8067. // } else if num2 < advice.PrescribingNumber {
  8068. // num = advice.PrescribingNumber - num2
  8069. // drug.Total = drug.Total - num
  8070. // service.UpdateBaseDrugLib(&drug)
  8071. // }
  8072. //
  8073. // }
  8074. //
  8075. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8076. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8077. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8078. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8079. // if num1 > num2 {
  8080. // num = num1 - num2
  8081. // drug.Total = drug.Total + num
  8082. // service.UpdateBaseDrugLib(&drug)
  8083. // } else if num1 < num2 {
  8084. // num = num2 - num1
  8085. // drug.Total = drug.Total - num
  8086. // service.UpdateBaseDrugLib(&drug)
  8087. // }
  8088. //
  8089. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8090. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8091. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8092. // if hisAdvice.PrescribingNumber > num2 {
  8093. // num = hisAdvice.PrescribingNumber - num2
  8094. // drug.Total = drug.Total + num
  8095. // service.UpdateBaseDrugLib(&drug)
  8096. // } else if num2 < advice.PrescribingNumber {
  8097. // num = num2 - hisAdvice.PrescribingNumber
  8098. // drug.Total = drug.Total - num
  8099. // service.UpdateBaseDrugLib(&drug)
  8100. // }
  8101. //
  8102. // }
  8103. // }
  8104. // }
  8105. //}
  8106. //
  8107. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8108. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8109. // advice.ExecutionTime = execution_time
  8110. //}
  8111. //
  8112. //
  8113. //
  8114. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8115. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8116. // advice.ExecutionStaff = execution_staff
  8117. //}
  8118. //
  8119. //
  8120. //
  8121. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8122. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8123. // advice.ExecutionState = execution_state
  8124. //}
  8125. //
  8126. //
  8127. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8128. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8129. // advice.CheckTime = check_time
  8130. //}
  8131. //
  8132. //
  8133. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8134. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8135. // advice.CheckState = check_state
  8136. //}
  8137. //
  8138. //
  8139. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8140. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8141. // advice.Checker = checker
  8142. //}
  8143. //
  8144. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8145. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8146. // advice.StartTime = start_time
  8147. //}
  8148. return 0
  8149. }
  8150. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8151. project.ExecutionStaff = 0
  8152. project.ExecutionState = 2
  8153. project.ExecutionTime = 0
  8154. project.Checker = 0
  8155. project.CheckState = 2
  8156. project.CheckTime = 0
  8157. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8158. id := int64(json["id"].(float64))
  8159. project.ID = id
  8160. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8161. project.ExecutionStaff = temp_project.ExecutionStaff
  8162. project.ExecutionState = temp_project.ExecutionState
  8163. project.ExecutionTime = temp_project.ExecutionTime
  8164. project.Checker = temp_project.Checker
  8165. project.CheckState = temp_project.CheckState
  8166. project.CheckTime = temp_project.CheckTime
  8167. project.TeamId = temp_project.TeamId
  8168. }
  8169. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8170. types := int64(json["type"].(float64))
  8171. project.Type = types
  8172. }
  8173. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8174. project_id := int64(json["project_id"].(float64))
  8175. project.ProjectId = project_id
  8176. }
  8177. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8178. team_id := int64(json["team_id"].(float64))
  8179. project.TeamId = team_id
  8180. }
  8181. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8182. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8183. project.Price = price
  8184. }
  8185. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8186. total, _ := json["total"].(string)
  8187. //totals, _ := strconv.ParseInt(total, 10, 64)
  8188. project.Count = total
  8189. }
  8190. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8191. medical_code, _ := json["medical_code"].(string)
  8192. project.MedListCodg = medical_code
  8193. }
  8194. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8195. single_dose, _ := json["single_dose"].(string)
  8196. project.SingleDose = single_dose
  8197. }
  8198. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8199. delivery_way, _ := json["delivery_way"].(string)
  8200. project.DeliveryWay = delivery_way
  8201. }
  8202. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8203. execution_frequency, _ := json["execution_frequency"].(string)
  8204. project.ExecutionFrequency = execution_frequency
  8205. }
  8206. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8207. remark, _ := json["remark"].(string)
  8208. project.Remark = remark
  8209. }
  8210. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8211. day, _ := json["number_days"].(string)
  8212. project.Day = day
  8213. }
  8214. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8215. unit, _ := json["unit"].(string)
  8216. project.Unit = unit
  8217. }
  8218. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8219. // frequency_type := int64(json["frequency_type"].(float64))
  8220. // project.FrequencyType = frequency_type
  8221. //}
  8222. //
  8223. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8224. // day_count := int64(json["day_count"].(float64))
  8225. // project.DayCount = day_count
  8226. //}
  8227. //
  8228. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8229. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8230. // week_day, _ := json["week_day"].(string)
  8231. // project.WeekDay = week_day
  8232. //}
  8233. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8234. //
  8235. //if project.ID == 0 {
  8236. // if stockConfig.IsOpen == 1 {
  8237. // if project.Type == 3 {
  8238. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8239. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8240. // good.Total = good.Total - f_count
  8241. // service.UpdateGoodInfo(&good)
  8242. // }
  8243. // }
  8244. //
  8245. //} else {
  8246. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8247. //
  8248. // if stockConfig.IsOpen == 1 {
  8249. // if project.Type == 3 {
  8250. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8251. // if project.Count < temp_project.Count {
  8252. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8253. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8254. //
  8255. // other_count := f_count_two - f_count_one
  8256. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8257. // good.Total = good.Total + other_count_two
  8258. // service.UpdateGoodInfo(&good)
  8259. // } else if project.Count > temp_project.Count {
  8260. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8261. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8262. //
  8263. // other_count := f_count_one - f_count_two
  8264. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8265. // good.Total = good.Total - other_count_two
  8266. // service.UpdateGoodInfo(&good)
  8267. // }
  8268. //
  8269. // }
  8270. // }
  8271. //
  8272. //}
  8273. return 0
  8274. }
  8275. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8276. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8277. utils.ErrorLog("drug_name")
  8278. return enums.ErrorCodeParamWrong
  8279. }
  8280. adviceName, _ := json["drug_name"].(string)
  8281. if len(adviceName) == 0 {
  8282. utils.ErrorLog("len(advice_name) == 0")
  8283. return enums.ErrorCodeParamWrong
  8284. }
  8285. advice.AdviceName = adviceName
  8286. adviceDesc, _ := json["advice_desc"].(string)
  8287. advice.AdviceDesc = adviceDesc
  8288. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8289. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8290. advice.DrugSpec = drugSpec
  8291. }
  8292. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8293. remark, _ := json["remark"].(string)
  8294. advice.Remark = remark
  8295. }
  8296. if json["id"] == nil {
  8297. advice.DrugId = 0
  8298. } else {
  8299. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8300. drug_id := int64(json["id"].(float64))
  8301. advice.DrugId = drug_id
  8302. }
  8303. }
  8304. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8305. groupno := int64(json["groupno"].(float64))
  8306. advice.Groupno = groupno
  8307. }
  8308. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8309. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8310. advice.IsSelfDrug = is_self_drug
  8311. }
  8312. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8313. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8314. drug_way_count, _ := json["drug_way_count"].(string)
  8315. advice.DrugWayCount = drug_way_count
  8316. }
  8317. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8318. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8319. advice.HospApprFlag = hosp_appr_flag
  8320. }
  8321. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8322. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8323. advice.PrescribingNumber = prescribingNumber
  8324. }
  8325. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8326. // frequency_type := int64(json["frequency_type"].(float64))
  8327. // advice.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. // advice.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. // advice.WeekDay = week_day
  8339. //}
  8340. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8341. drugSpecUnit, _ := json["min_unit"].(string)
  8342. advice.DrugSpecUnit = drugSpecUnit
  8343. }
  8344. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8345. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8346. advice.SingleDose = singleDose
  8347. }
  8348. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8349. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8350. advice.SingleDoseUnit = singleDoseUnit
  8351. }
  8352. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8353. deliveryWay, _ := json["delivery_way"].(string)
  8354. advice.DeliveryWay = deliveryWay
  8355. }
  8356. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8357. executionFrequency, _ := json["execution_frequency"].(string)
  8358. advice.ExecutionFrequency = executionFrequency
  8359. }
  8360. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8361. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8362. advice.Price = price
  8363. }
  8364. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8365. med_list_codg, _ := json["medical_insurance_number"].(string)
  8366. advice.MedListCodg = med_list_codg
  8367. }
  8368. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8369. day := int64(json["day"].(float64))
  8370. advice.Day = day
  8371. }
  8372. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8373. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8374. advice.PrescribingNumberUnit = prescribingNumberUnit
  8375. }
  8376. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8377. advice_id := int64(json["advice_id"].(float64))
  8378. advice.ID = advice_id
  8379. if advice.ID > 0 {
  8380. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8381. if err == nil {
  8382. if hisAdvice.ID > 0 {
  8383. advice.ExecutionTime = hisAdvice.ExecutionTime
  8384. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8385. advice.ExecutionState = hisAdvice.ExecutionState
  8386. advice.CheckTime = hisAdvice.CheckTime
  8387. advice.Checker = hisAdvice.Checker
  8388. advice.DrugCode = hisAdvice.DrugCode
  8389. advice.CheckState = hisAdvice.CheckState
  8390. advice.StartTime = hisAdvice.StartTime
  8391. advice.HospApprFlag = hisAdvice.HospApprFlag
  8392. advice.IsMedicine = hisAdvice.IsMedicine
  8393. if hisAdvice.UserOrgId == 10028 {
  8394. 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 {
  8395. advice.ExecutionTime = 0
  8396. advice.ExecutionStaff = 0
  8397. advice.ExecutionState = 2
  8398. advice.CheckTime = 0
  8399. advice.Checker = 0
  8400. advice.CheckState = 2
  8401. }
  8402. } else {
  8403. 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 {
  8404. advice.ExecutionTime = 0
  8405. advice.ExecutionStaff = 0
  8406. advice.ExecutionState = 2
  8407. advice.CheckTime = 0
  8408. advice.Checker = 0
  8409. advice.CheckState = 2
  8410. //advice.UpdatedTime = time.Now().Unix()
  8411. advice.CreatedTime = hisAdvice.CreatedTime
  8412. advice.UpdatedTime = time.Now().Unix()
  8413. } else {
  8414. advice.CreatedTime = hisAdvice.CreatedTime
  8415. advice.UpdatedTime = hisAdvice.UpdatedTime
  8416. }
  8417. }
  8418. //advice.Groupno = hisAdvice.Groupno
  8419. } else {
  8420. advice.IsMedicine = 0
  8421. ctime := time.Now().Unix()
  8422. advice.CreatedTime = ctime
  8423. advice.UpdatedTime = ctime
  8424. }
  8425. }
  8426. } else {
  8427. advice.IsMedicine = 0
  8428. ctime := time.Now().Unix()
  8429. advice.CreatedTime = ctime
  8430. advice.UpdatedTime = ctime
  8431. }
  8432. }
  8433. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8434. //
  8435. //if drugStockConfig.IsOpen == 1 {
  8436. //
  8437. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8438. // if advice.ID == 0 { //医嘱不存在
  8439. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8440. // drug.Total = drug.Total - advice.PrescribingNumber
  8441. // service.UpdateBaseDrugLib(&drug)
  8442. //
  8443. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8444. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8445. // drug.Total = drug.Total - num
  8446. // service.UpdateBaseDrugLib(&drug)
  8447. // }
  8448. //
  8449. // } else if advice.ID > 0 { //医嘱存在
  8450. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8451. // var num float64
  8452. //
  8453. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8454. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8455. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8456. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8457. // drug.Total = drug.Total + num
  8458. // service.UpdateBaseDrugLib(&drug)
  8459. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8460. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8461. // drug.Total = drug.Total - num
  8462. // service.UpdateBaseDrugLib(&drug)
  8463. // }
  8464. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8465. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8466. // if num2 > advice.PrescribingNumber {
  8467. // num = num2 - advice.PrescribingNumber
  8468. // drug.Total = drug.Total + num
  8469. // service.UpdateBaseDrugLib(&drug)
  8470. // } else if num2 < advice.PrescribingNumber {
  8471. // num = advice.PrescribingNumber - num2
  8472. // drug.Total = drug.Total - num
  8473. // service.UpdateBaseDrugLib(&drug)
  8474. // }
  8475. //
  8476. // }
  8477. //
  8478. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8479. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8480. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8481. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8482. // if num1 > num2 {
  8483. // num = num1 - num2
  8484. // drug.Total = drug.Total + num
  8485. // service.UpdateBaseDrugLib(&drug)
  8486. // } else if num1 < num2 {
  8487. // num = num2 - num1
  8488. // drug.Total = drug.Total - num
  8489. // service.UpdateBaseDrugLib(&drug)
  8490. // }
  8491. //
  8492. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8493. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8494. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8495. // if hisAdvice.PrescribingNumber > num2 {
  8496. // num = hisAdvice.PrescribingNumber - num2
  8497. // drug.Total = drug.Total + num
  8498. // service.UpdateBaseDrugLib(&drug)
  8499. // } else if num2 < advice.PrescribingNumber {
  8500. // num = num2 - hisAdvice.PrescribingNumber
  8501. // drug.Total = drug.Total - num
  8502. // service.UpdateBaseDrugLib(&drug)
  8503. // }
  8504. //
  8505. // }
  8506. // }
  8507. // }
  8508. //}
  8509. //
  8510. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8511. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8512. // advice.ExecutionTime = execution_time
  8513. //}
  8514. //
  8515. //
  8516. //
  8517. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8518. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8519. // advice.ExecutionStaff = execution_staff
  8520. //}
  8521. //
  8522. //
  8523. //
  8524. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8525. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8526. // advice.ExecutionState = execution_state
  8527. //}
  8528. //
  8529. //
  8530. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8531. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8532. // advice.CheckTime = check_time
  8533. //}
  8534. //
  8535. //
  8536. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8537. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8538. // advice.CheckState = check_state
  8539. //}
  8540. //
  8541. //
  8542. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8543. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8544. // advice.Checker = checker
  8545. //}
  8546. //
  8547. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8548. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8549. // advice.StartTime = start_time
  8550. //}
  8551. return 0
  8552. }
  8553. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8554. project.ExecutionStaff = 0
  8555. project.ExecutionState = 2
  8556. project.ExecutionTime = 0
  8557. project.Checker = 0
  8558. project.CheckState = 2
  8559. project.CheckTime = 0
  8560. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8561. id := int64(json["id"].(float64))
  8562. project.ID = id
  8563. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8564. project.ExecutionStaff = temp_project.ExecutionStaff
  8565. project.ExecutionState = temp_project.ExecutionState
  8566. project.ExecutionTime = temp_project.ExecutionTime
  8567. project.Checker = temp_project.Checker
  8568. project.CheckState = temp_project.CheckState
  8569. project.CheckTime = temp_project.CheckTime
  8570. project.TeamId = temp_project.TeamId
  8571. }
  8572. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8573. types := int64(json["type"].(float64))
  8574. project.Type = types
  8575. }
  8576. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8577. project_id := int64(json["project_id"].(float64))
  8578. project.ProjectId = project_id
  8579. }
  8580. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8581. team_id := int64(json["team_id"].(float64))
  8582. project.TeamId = team_id
  8583. }
  8584. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8585. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8586. project.Price = price
  8587. }
  8588. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8589. total, _ := json["total"].(string)
  8590. //totals, _ := strconv.ParseInt(total, 10, 64)
  8591. project.Count = total
  8592. }
  8593. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8594. medical_code, _ := json["medical_code"].(string)
  8595. project.MedListCodg = medical_code
  8596. }
  8597. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8598. single_dose, _ := json["single_dose"].(string)
  8599. project.SingleDose = single_dose
  8600. }
  8601. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8602. delivery_way, _ := json["delivery_way"].(string)
  8603. project.DeliveryWay = delivery_way
  8604. }
  8605. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8606. execution_frequency, _ := json["execution_frequency"].(string)
  8607. project.ExecutionFrequency = execution_frequency
  8608. }
  8609. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8610. remark, _ := json["remark"].(string)
  8611. project.Remark = remark
  8612. }
  8613. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8614. day, _ := json["number_days"].(string)
  8615. project.Day = day
  8616. }
  8617. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8618. unit, _ := json["unit"].(string)
  8619. project.Unit = unit
  8620. }
  8621. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8622. // frequency_type := int64(json["frequency_type"].(float64))
  8623. // project.FrequencyType = frequency_type
  8624. //}
  8625. //
  8626. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8627. // day_count := int64(json["day_count"].(float64))
  8628. // project.DayCount = day_count
  8629. //}
  8630. //
  8631. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8632. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8633. // week_day, _ := json["week_day"].(string)
  8634. // project.WeekDay = week_day
  8635. //}
  8636. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8637. //
  8638. //if project.ID == 0 {
  8639. // if stockConfig.IsOpen == 1 {
  8640. // if project.Type == 3 {
  8641. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8642. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8643. // good.Total = good.Total - f_count
  8644. // service.UpdateGoodInfo(&good)
  8645. // }
  8646. // }
  8647. //
  8648. //} else {
  8649. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8650. //
  8651. // if stockConfig.IsOpen == 1 {
  8652. // if project.Type == 3 {
  8653. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8654. // if project.Count < temp_project.Count {
  8655. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8656. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8657. //
  8658. // other_count := f_count_two - f_count_one
  8659. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8660. // good.Total = good.Total + other_count_two
  8661. // service.UpdateGoodInfo(&good)
  8662. // } else if project.Count > temp_project.Count {
  8663. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8664. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8665. //
  8666. // other_count := f_count_one - f_count_two
  8667. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8668. // good.Total = good.Total - other_count_two
  8669. // service.UpdateGoodInfo(&good)
  8670. // }
  8671. //
  8672. // }
  8673. // }
  8674. //
  8675. //}
  8676. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8677. id := int64(json["id"].(float64))
  8678. if id > 0 {
  8679. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8680. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8681. fmt.Println("666666")
  8682. project.Mtime = time.Now().Unix()
  8683. project.Ctime = temp_project.Ctime
  8684. } else {
  8685. project.Mtime = temp_project.Mtime
  8686. project.Ctime = temp_project.Ctime
  8687. }
  8688. } else {
  8689. ctime := time.Now().Unix()
  8690. project.Mtime = ctime
  8691. project.Ctime = ctime
  8692. }
  8693. }
  8694. return 0
  8695. }
  8696. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8697. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8698. id := int64(json["id"].(float64))
  8699. additionalCharge.ID = id
  8700. }
  8701. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8702. item_id := int64(json["item_id"].(float64))
  8703. additionalCharge.ItemId = item_id
  8704. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8705. if config.ID > 0 {
  8706. if len(config.Code) > 0 {
  8707. additionalCharge.MedListCodg = config.Code
  8708. }
  8709. }
  8710. }
  8711. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8712. // price := int64(json["price"].(float64))
  8713. // formatInt_price := strconv.FormatInt(price, 10)
  8714. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8715. // additionalCharge.Price = float_price
  8716. // }
  8717. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8718. // price := int64(json["price"].(float64))
  8719. // formatInt_price := strconv.FormatInt(price, 10)
  8720. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8721. // additionalCharge.Price = float_price
  8722. //}
  8723. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8724. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8725. additionalCharge.Price = price
  8726. }
  8727. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8728. count, _ := json["count"].(string)
  8729. counts, _ := strconv.ParseInt(count, 10, 64)
  8730. additionalCharge.Count = counts
  8731. }
  8732. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8733. item_name, _ := json["item_name"].(string)
  8734. additionalCharge.ItemName = item_name
  8735. }
  8736. return 0
  8737. }
  8738. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8739. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8740. utils.ErrorLog("drug_name")
  8741. return enums.ErrorCodeParamWrong
  8742. }
  8743. adviceName, _ := json["drug_name"].(string)
  8744. if len(adviceName) == 0 {
  8745. utils.ErrorLog("len(advice_name) == 0")
  8746. return enums.ErrorCodeParamWrong
  8747. }
  8748. advice.AdviceName = adviceName
  8749. adviceDesc, _ := json["advice_desc"].(string)
  8750. advice.AdviceDesc = adviceDesc
  8751. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8752. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8753. advice.DrugSpec = drugSpec
  8754. }
  8755. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8756. remark, _ := json["remark"].(string)
  8757. advice.Remark = remark
  8758. }
  8759. if json["id"] == nil {
  8760. advice.DrugId = 0
  8761. } else {
  8762. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8763. drug_id := int64(json["id"].(float64))
  8764. advice.DrugId = drug_id
  8765. }
  8766. }
  8767. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8768. groupno := int64(json["groupno"].(float64))
  8769. advice.Groupno = groupno
  8770. }
  8771. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8772. drugSpecUnit, _ := json["min_unit"].(string)
  8773. advice.DrugSpecUnit = drugSpecUnit
  8774. }
  8775. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8776. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8777. advice.SingleDose = singleDose
  8778. }
  8779. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8780. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8781. advice.SingleDoseUnit = singleDoseUnit
  8782. }
  8783. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8784. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8785. advice.PrescribingNumber = prescribingNumber
  8786. }
  8787. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8788. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8789. advice.PrescribingNumberUnit = prescribingNumberUnit
  8790. }
  8791. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8792. deliveryWay, _ := json["delivery_way"].(string)
  8793. advice.DeliveryWay = deliveryWay
  8794. }
  8795. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8796. executionFrequency, _ := json["execution_frequency"].(string)
  8797. advice.ExecutionFrequency = executionFrequency
  8798. }
  8799. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8800. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8801. advice.Price = price
  8802. }
  8803. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8804. med_list_codg, _ := json["medical_insurance_number"].(string)
  8805. advice.MedListCodg = med_list_codg
  8806. }
  8807. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8808. day := int64(json["day"].(float64))
  8809. advice.Day = day
  8810. }
  8811. advice.FrequencyType = 1
  8812. return 0
  8813. }
  8814. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8815. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8816. types := int64(json["type"].(float64))
  8817. project.Type = types
  8818. }
  8819. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8820. project_id := int64(json["project_id"].(float64))
  8821. project.ProjectId = project_id
  8822. }
  8823. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8824. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8825. project.Price = price
  8826. }
  8827. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8828. total, _ := json["total"].(string)
  8829. //totals, _ := strconv.ParseInt(total, 10, 64)
  8830. project.Count = total
  8831. }
  8832. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8833. medical_code, _ := json["medical_code"].(string)
  8834. project.MedListCodg = medical_code
  8835. }
  8836. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8837. single_dose, _ := json["single_dose"].(string)
  8838. project.SingleDose = single_dose
  8839. }
  8840. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8841. delivery_way, _ := json["delivery_way"].(string)
  8842. project.DeliveryWay = delivery_way
  8843. }
  8844. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8845. execution_frequency, _ := json["execution_frequency"].(string)
  8846. project.ExecutionFrequency = execution_frequency
  8847. }
  8848. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8849. remark, _ := json["remark"].(string)
  8850. project.Remark = remark
  8851. }
  8852. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8853. day, _ := json["number_days"].(string)
  8854. project.Day = day
  8855. }
  8856. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8857. unit, _ := json["unit"].(string)
  8858. project.Unit = unit
  8859. }
  8860. project.FrequencyType = 1
  8861. return 0
  8862. }
  8863. func (c *HisApiController) GetHisOrderListTwo() {
  8864. start_time := c.GetString("start_time")
  8865. end_time := c.GetString("end_time")
  8866. timeLayout := "2006-01-02"
  8867. loc, _ := time.LoadLocation("Local")
  8868. var startTime int64
  8869. if len(start_time) > 0 {
  8870. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8871. if err != nil {
  8872. //fmt.Println(err)
  8873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8874. return
  8875. }
  8876. startTime = theTime.Unix()
  8877. }
  8878. var endTime int64
  8879. if len(end_time) > 0 {
  8880. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8881. if err != nil {
  8882. utils.ErrorLog(err.Error())
  8883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8884. return
  8885. }
  8886. endTime = theTime.Unix()
  8887. }
  8888. adminUser := c.GetAdminUserInfo()
  8889. org_id := adminUser.CurrentOrgId
  8890. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8891. if err == nil {
  8892. c.ServeSuccessJSON(map[string]interface{}{
  8893. "order2": order,
  8894. })
  8895. } else {
  8896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8897. return
  8898. }
  8899. }
  8900. func (c *HisApiController) GetHisOrderList() {
  8901. page, _ := c.GetInt64("page", -1)
  8902. limit, _ := c.GetInt64("limit", -1)
  8903. start_time := c.GetString("start_time")
  8904. end_time := c.GetString("end_time")
  8905. types, _ := c.GetInt64("type", 0)
  8906. keywords := c.GetString("keywords")
  8907. p_type, _ := c.GetInt64("p_type", 0)
  8908. sort_type, _ := c.GetInt64("sort_type", 0)
  8909. charge_type, _ := c.GetInt64("charge_type", 0)
  8910. sch_type, _ := c.GetInt64("sch_type", 0)
  8911. zone_type, _ := c.GetInt64("zone_type", 0)
  8912. med_type, _ := c.GetInt64("med_type", 0)
  8913. timeLayout := "2006-01-02"
  8914. loc, _ := time.LoadLocation("Local")
  8915. var startTime int64
  8916. if len(start_time) > 0 {
  8917. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8918. if err != nil {
  8919. //fmt.Println(err)
  8920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8921. return
  8922. }
  8923. startTime = theTime.Unix()
  8924. }
  8925. var endTime int64
  8926. if len(end_time) > 0 {
  8927. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8928. if err != nil {
  8929. utils.ErrorLog(err.Error())
  8930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8931. return
  8932. }
  8933. endTime = theTime.Unix()
  8934. }
  8935. adminUser := c.GetAdminUserInfo()
  8936. org_id := adminUser.CurrentOrgId
  8937. 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)
  8938. for _, item := range order {
  8939. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8940. item.DoctorName = info.Doctor
  8941. item.DepartmentName = info.XtHisDepartment.Name
  8942. }
  8943. if err == nil {
  8944. c.ServeSuccessJSON(map[string]interface{}{
  8945. "order": order,
  8946. "total": total,
  8947. })
  8948. } else {
  8949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8950. return
  8951. }
  8952. }
  8953. func (c *HisApiController) GetHisOrder() {
  8954. patient_id, _ := c.GetInt64("patient_id", 0)
  8955. number := c.GetString("number")
  8956. adminInfo := c.GetAdminUserInfo()
  8957. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8958. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8959. if err == nil {
  8960. c.ServeSuccessJSON(map[string]interface{}{
  8961. "order": order,
  8962. "prescription": prescriptions,
  8963. })
  8964. } else {
  8965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8966. return
  8967. }
  8968. }
  8969. func (c *HisApiController) GetHisPrescriptionList() {
  8970. record_date := c.GetString("record_date")
  8971. keywords := c.GetString("keywords")
  8972. page, _ := c.GetInt64("page")
  8973. limit, _ := c.GetInt64("limit")
  8974. sch_type, _ := c.GetInt64("sch_type")
  8975. timeLayout := "2006-01-02"
  8976. loc, _ := time.LoadLocation("Local")
  8977. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8978. if err != nil {
  8979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8980. return
  8981. }
  8982. recordDateTime := theTime.Unix()
  8983. adminInfo := c.GetAdminUserInfo()
  8984. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8985. //adminInfo := c.GetAdminUserInfo()
  8986. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8987. //fmt.Println(prescriptionOrder)
  8988. if err == nil {
  8989. c.ServeSuccessJSON(map[string]interface{}{
  8990. "order": prescriptionOrder,
  8991. "total": total,
  8992. })
  8993. } else {
  8994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8995. return
  8996. }
  8997. }
  8998. func (c *HisApiController) GetHisPrescriptionInfo() {
  8999. id, _ := c.GetInt64("id")
  9000. adminInfo := c.GetAdminUserInfo()
  9001. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  9002. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  9003. if err == nil {
  9004. c.ServeSuccessJSON(map[string]interface{}{
  9005. "order": prescriptionOrder,
  9006. "prescription": prescription,
  9007. })
  9008. } else {
  9009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9010. return
  9011. }
  9012. }
  9013. func (c *HisApiController) GetMedicalInsuranceConfig() {
  9014. adminUser := c.GetAdminUserInfo()
  9015. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  9016. c.ServeSuccessJSON(map[string]interface{}{
  9017. "config": config,
  9018. })
  9019. }
  9020. type ResultTwo struct {
  9021. ErrMsg interface{} `json:"err_msg"`
  9022. InfRefmsgid string `json:"inf_refmsgid"`
  9023. Infcode int64 `json:"infcode"`
  9024. Output struct {
  9025. Baseinfo struct {
  9026. Age float64 `json:"age"`
  9027. Brdy string `json:"brdy"`
  9028. Certno string `json:"certno"`
  9029. Gend string `json:"gend"`
  9030. Naty string `json:"naty"`
  9031. PsnCertType string `json:"psn_cert_type"`
  9032. PsnName string `json:"psn_name"`
  9033. PsnNo string `json:"psn_no"`
  9034. } `json:"baseinfo"`
  9035. Idetinfo []interface{} `json:"idetinfo"`
  9036. Iinfo []struct {
  9037. Balc float64 `json:"balc"`
  9038. CvlservFlag string `json:"cvlserv_flag"`
  9039. EmpName string `json:"emp_name"`
  9040. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  9041. Insutype string `json:"insutype"`
  9042. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  9043. PausInsuDate interface{} `json:"paus_insu_date"`
  9044. PsnInsuDate string `json:"psn_insu_date"`
  9045. PsnInsuStas string `json:"psn_insu_stas"`
  9046. PsnType string `json:"psn_type"`
  9047. } `json:"insuinfo"`
  9048. } `json:"output"`
  9049. RefmsgTime string `json:"refmsg_time"`
  9050. RespondTime string `json:"respond_time"`
  9051. Signtype interface{} `json:"signtype"`
  9052. WarnInfo interface{} `json:"warn_info"`
  9053. }
  9054. type ResultThree struct {
  9055. Cainfo interface{} `json:"cainfo"`
  9056. ErrMsg interface{} `json:"err_msg"`
  9057. InfRefmsgid string `json:"inf_refmsgid"`
  9058. Infcode int64 `json:"infcode"`
  9059. Output struct {
  9060. Data struct {
  9061. IptOtpNo string `json:"ipt_otp_no"`
  9062. MdtrtID string `json:"mdtrt_id"`
  9063. PsnNo string `json:"psn_no"`
  9064. } `json:"data"`
  9065. } `json:"output"`
  9066. RefmsgTime string `json:"refmsg_time"`
  9067. RespondTime string `json:"respond_time"`
  9068. Signtype interface{} `json:"signtype"`
  9069. WarnMsg interface{} `json:"warn_msg"`
  9070. }
  9071. type ResultFour struct {
  9072. Cainfo string `json:"cainfo"`
  9073. ErrMsg string `json:"err_msg"`
  9074. InfRefmsgid string `json:"inf_refmsgid"`
  9075. Infcode int64 `json:"infcode"`
  9076. Output struct {
  9077. Result []struct {
  9078. BasMednFlag string `json:"bas_medn_flag"`
  9079. ChldMedcFlag string `json:"chld_medc_flag"`
  9080. ChrgitmLv string `json:"chrgitm_lv"`
  9081. Cnt float64 `json:"cnt"`
  9082. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9083. DrtReimFlag string `json:"drt_reim_flag"`
  9084. FeedetlSn string `json:"feedetl_sn"`
  9085. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9086. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9087. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9088. ListSpItemFlag string `json:"list_sp_item_flag"`
  9089. LmtUsedFlag string `json:"lmt_used_flag"`
  9090. MedChrgitmType string `json:"med_chrgitm_type"`
  9091. Memo string `json:"memo"`
  9092. OverlmtAmt float64 `json:"overlmt_amt"`
  9093. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9094. Pric float64 `json:"pric"`
  9095. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9096. SelfpayProp float64 `json:"selfpay_prop"`
  9097. } `json:"result"`
  9098. } `json:"output"`
  9099. RefmsgTime string `json:"refmsg_time"`
  9100. RespondTime string `json:"respond_time"`
  9101. Signtype string `json:"signtype"`
  9102. WarnMsg string `json:"warn_msg"`
  9103. }
  9104. type ResultFive struct {
  9105. Insutype string `json:"insutype"`
  9106. }
  9107. type ResultSix struct {
  9108. Cainfo interface{} `json:"cainfo"`
  9109. ErrMsg interface{} `json:"err_msg"`
  9110. InfRefmsgid string `json:"inf_refmsgid"`
  9111. Infcode int64 `json:"infcode"`
  9112. Output struct {
  9113. } `json:"output"`
  9114. RefmsgTime string `json:"refmsg_time"`
  9115. RespondTime string `json:"respond_time"`
  9116. Signtype interface{} `json:"signtype"`
  9117. WarnMsg interface{} `json:"warn_msg"`
  9118. }
  9119. type ResultSeven struct {
  9120. Cainfo string `json:"cainfo"`
  9121. ErrMsg string `json:"err_msg"`
  9122. InfRefmsgid string `json:"inf_refmsgid"`
  9123. Infcode int64 `json:"infcode"`
  9124. Output struct {
  9125. Setldetail []interface{} `json:"setldetail"`
  9126. Setlinfo struct {
  9127. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9128. AcctPay float64 `json:"acct_pay"`
  9129. ActPayDedc float64 `json:"act_pay_dedc"`
  9130. Age float64 `json:"age"`
  9131. Balc float64 `json:"balc"`
  9132. Brdy string `json:"brdy"`
  9133. Certno string `json:"certno"`
  9134. ClrOptins string `json:"clr_optins"`
  9135. ClrType string `json:"clr_type"`
  9136. ClrWay string `json:"clr_way"`
  9137. CvlservFlag string `json:"cvlserv_flag"`
  9138. CvlservPay float64 `json:"cvlserv_pay"`
  9139. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9140. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9141. Gend string `json:"gend"`
  9142. HifesPay float64 `json:"hifes_pay"`
  9143. HifmiPay float64 `json:"hifmi_pay"`
  9144. HifobPay float64 `json:"hifob_pay"`
  9145. HifpPay float64 `json:"hifp_pay"`
  9146. HospPartAmt float64 `json:"hosp_part_amt"`
  9147. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9148. Insutype string `json:"insutype"`
  9149. MafPay float64 `json:"maf_pay"`
  9150. MdtrtCertType string `json:"mdtrt_cert_type"`
  9151. MdtrtID string `json:"mdtrt_id"`
  9152. MedType string `json:"med_type"`
  9153. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9154. MedinsSetlID string `json:"medins_setl_id"`
  9155. Naty string `json:"naty"`
  9156. OthPay float64 `json:"oth_pay"`
  9157. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9158. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9159. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9160. PsnCashPay float64 `json:"psn_cash_pay"`
  9161. PsnCertType string `json:"psn_cert_type"`
  9162. PsnName string `json:"psn_name"`
  9163. PsnNo string `json:"psn_no"`
  9164. PsnPartAmt float64 `json:"psn_part_amt"`
  9165. PsnType string `json:"psn_type"`
  9166. SetlID string `json:"setl_id"`
  9167. SetlTime string `json:"setl_time"`
  9168. } `json:"setlinfo"`
  9169. } `json:"output"`
  9170. RefmsgTime string `json:"refmsg_time"`
  9171. RespondTime string `json:"respond_time"`
  9172. Signtype interface{} `json:"signtype"`
  9173. WarnMsg interface{} `json:"warn_msg"`
  9174. }
  9175. type ResultEight struct {
  9176. Cainfo string `json:"cainfo"`
  9177. ErrMsg string `json:"err_msg"`
  9178. InfRefmsgid string `json:"inf_refmsgid"`
  9179. Infcode int64 `json:"infcode"`
  9180. Output struct {
  9181. Stmtinfo struct {
  9182. SetlOptins string `json:"setl_optins"`
  9183. StmtRslt string `json:"stmt_rslt"`
  9184. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9185. } `json:"stmtinfo"`
  9186. } `json:"output"`
  9187. RefmsgTime string `json:"refmsg_time"`
  9188. RespondTime string `json:"respond_time"`
  9189. Signtype interface{} `json:"signtype"`
  9190. WarnMsg interface{} `json:"warn_msg"`
  9191. }
  9192. type ResultNine struct {
  9193. Cainfo string `json:"cainfo"`
  9194. ErrMsg string `json:"err_msg"`
  9195. InfRefmsgid string `json:"inf_refmsgid"`
  9196. Infcode int64 `json:"infcode"`
  9197. Output struct {
  9198. FileQuryNo string `json:"file_qury_no"`
  9199. } `json:"output"`
  9200. RefmsgTime string `json:"refmsg_time"`
  9201. RespondTime string `json:"respond_time"`
  9202. Signtype interface{} `json:"signtype"`
  9203. WarnMsg interface{} `json:"warn_msg"`
  9204. }
  9205. type ResultTen struct {
  9206. Cainfo string `json:"cainfo"`
  9207. ErrMsg string `json:"err_msg"`
  9208. InfRefmsgid string `json:"inf_refmsgid"`
  9209. Infcode int64 `json:"infcode"`
  9210. Output struct {
  9211. DldEndtime string `json:"dld_endtime"`
  9212. FileQuryNo string `json:"file_qury_no"`
  9213. Filename string `json:"filename"`
  9214. } `json:"output"`
  9215. RefmsgTime string `json:"refmsg_time"`
  9216. RespondTime string `json:"respond_time"`
  9217. Signtype interface{} `json:"signtype"`
  9218. WarnMsg interface{} `json:"warn_msg"`
  9219. }
  9220. type ResultEleven struct {
  9221. Cainfo string `json:"cainfo"`
  9222. ErrMsg string `json:"err_msg"`
  9223. InfRefmsgid string `json:"inf_refmsgid"`
  9224. Infcode int64 `json:"infcode"`
  9225. Output struct {
  9226. Setlinfo struct {
  9227. FixmedinsName string `json:"fixmedins_name"`
  9228. FixmedinsCode string `json:"fixmedins_code"`
  9229. PsnNo string `json:"psn_no"`
  9230. PsnName string `json:"psn_name"`
  9231. HifobPay float64 `json:"hifob_pay"`
  9232. Gend string `json:"gend"`
  9233. Brdy string `json:"brdy"`
  9234. PsnCertType string `json:"psn_cert_type"`
  9235. PsnType string `json:"psn_type"`
  9236. EmpName string `json:"emp_name"`
  9237. Certno string `json:"certno"`
  9238. Insutype string `json:"insutype"`
  9239. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9240. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9241. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9242. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9243. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9244. ActPayDedc float64 `json:"act_pay_dedc"`
  9245. HifpPay float64 `json:"hifp_pay"`
  9246. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9247. CvlservPay float64 `json:"cvlserv_pay"`
  9248. HifesPay float64 `json:"hifes_pay"`
  9249. HifmiPay float64 `json:"hifmi_pay"`
  9250. MafPay float64 `json:"maf_pay"`
  9251. OthPay float64 `json:"oth_pay"`
  9252. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9253. PsnPay float64 `json:"psn_pay"`
  9254. AcctPay float64 `json:"acct_pay"`
  9255. CashPayamt float64 `json:"cash_payamt"`
  9256. Balc float64 `json:"balc"`
  9257. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9258. MedinsSetlId string `json:"medins_setl_id"`
  9259. RefdSetlFlag string `json:"refd_setl_flag"`
  9260. SetlTime string `json:"setl_time"`
  9261. MedType string `json:"med_type"`
  9262. } `json:"setlinfo"`
  9263. } `json:"output"`
  9264. RefmsgTime string `json:"refmsg_time"`
  9265. RespondTime string `json:"respond_time"`
  9266. Signtype interface{} `json:"signtype"`
  9267. WarnMsg interface{} `json:"warn_msg"`
  9268. }
  9269. type Custom struct {
  9270. DetItemFeeSumamt string
  9271. Cut string
  9272. FeedetlSn string
  9273. Price string
  9274. MedListCodg string
  9275. Type int64
  9276. AdviceId int64
  9277. ProjectId int64
  9278. ItemId int64
  9279. CostType int64
  9280. }
  9281. // 获取个人信息----挂号-----上传就诊信息
  9282. func (c *HisApiController) GetRegisterInfo() {
  9283. id, _ := c.GetInt64("id")
  9284. record_time := c.GetString("record_time")
  9285. settlementValue, _ := c.GetInt64("settlement_value")
  9286. medical_insurance_card := c.GetString("medical_insurance_card")
  9287. name := c.GetString("name")
  9288. id_card_type, _ := c.GetInt64("id_card_type")
  9289. certificates, _ := c.GetInt64("certificates")
  9290. medical_care, _ := c.GetInt64("medical_care")
  9291. birthday := c.GetString("birthday")
  9292. age, _ := c.GetInt64("age")
  9293. id_card := c.GetString("id_card")
  9294. register_type, _ := c.GetInt64("register")
  9295. doctor, _ := c.GetInt64("doctor")
  9296. department, _ := c.GetInt64("department")
  9297. gender, _ := c.GetInt64("sex")
  9298. phone := c.GetString("phone")
  9299. registration_fee, _ := c.GetFloat("registration_fee")
  9300. medical_expenses, _ := c.GetFloat("medical_expenses")
  9301. social_type, _ := c.GetInt64("social_type")
  9302. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9303. diagnosis_ids := c.GetString("diagnosis")
  9304. sick_type, _ := c.GetInt64("sick_type")
  9305. reg_type := c.GetString("p_type")
  9306. timeLayout := "2006-01-02"
  9307. loc, _ := time.LoadLocation("Local")
  9308. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9309. birthUnix := birthdays.Unix()
  9310. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9311. if err != nil {
  9312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9313. return
  9314. }
  9315. recordDateTime := theTime.Unix()
  9316. adminInfo := c.GetAdminUserInfo()
  9317. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9318. if tempPatient.ID == 0 {
  9319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9320. return
  9321. }
  9322. var patient service.Patients
  9323. if id == 0 {
  9324. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9325. } else {
  9326. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9327. }
  9328. if patient.ID == 0 {
  9329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9330. return
  9331. }
  9332. if len(patient.IdCardNo) == 0 {
  9333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9334. return
  9335. }
  9336. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9337. if len(his) >= 1 {
  9338. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9339. if len(his) >= 1 && order.ID == 0 {
  9340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9341. return
  9342. }
  9343. }
  9344. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9345. fmt.Println(timeStr)
  9346. timeArr := strings.Split(timeStr, " ")
  9347. fmt.Println(timeArr)
  9348. timeArrTwo := strings.Split(timeArr[0], "-")
  9349. timeArrThree := strings.Split(timeArr[1], ":")
  9350. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9351. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9352. if len(lists) == 0 {
  9353. var hisPatient models.XtHisPatient
  9354. hisPatient = models.XtHisPatient{
  9355. Name: name,
  9356. Age: age,
  9357. Gender: gender,
  9358. Birthday: birthUnix,
  9359. Phone: phone,
  9360. MedicalTreatmentType: medical_care,
  9361. IdType: certificates,
  9362. IdCardNo: id_card,
  9363. BalanceAccountsType: settlementValue,
  9364. SocialType: social_type,
  9365. MedicalInsuranceNumber: medical_insurance_card,
  9366. RegisterType: register_type,
  9367. RegisterCost: registration_fee,
  9368. TreatmentCost: medical_expenses,
  9369. AdminUserId: adminInfo.AdminUser.Id,
  9370. UserOrgId: adminInfo.CurrentOrgId,
  9371. Status: 1,
  9372. RecordDate: recordDateTime,
  9373. IsReturn: 1,
  9374. PatientId: patient.ID,
  9375. Ctime: time.Now().Unix(),
  9376. Mtime: time.Now().Unix(),
  9377. Number: str,
  9378. IdCardType: id_card_type,
  9379. Departments: department,
  9380. Doctor: doctor,
  9381. PType: reg_type,
  9382. Diagnosis: diagnosis_ids,
  9383. SickType: sick_type,
  9384. }
  9385. service.CreateHisPatient(&hisPatient)
  9386. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9387. c.ServeSuccessJSON(map[string]interface{}{
  9388. "his_info": hisPatient,
  9389. })
  9390. } else {
  9391. //chrgBchno := rand.Intn(1000000) + 10000
  9392. var hisPatient models.XtHisPatient
  9393. hisPatient = models.XtHisPatient{
  9394. Name: name,
  9395. Age: age,
  9396. Gender: gender,
  9397. Birthday: birthUnix,
  9398. Phone: phone,
  9399. MedicalTreatmentType: medical_care,
  9400. IdType: certificates,
  9401. IdCardNo: id_card,
  9402. BalanceAccountsType: settlementValue,
  9403. SocialType: social_type,
  9404. MedicalInsuranceNumber: medical_insurance_card,
  9405. RegisterType: register_type,
  9406. RegisterCost: registration_fee,
  9407. TreatmentCost: medical_expenses,
  9408. AdminUserId: adminInfo.AdminUser.Id,
  9409. UserOrgId: adminInfo.CurrentOrgId,
  9410. Status: 1,
  9411. RecordDate: recordDateTime,
  9412. IsReturn: 1,
  9413. PatientId: patient.ID,
  9414. Ctime: time.Now().Unix(),
  9415. Mtime: time.Now().Unix(),
  9416. Number: str,
  9417. IdCardType: id_card_type,
  9418. Departments: department,
  9419. Doctor: doctor,
  9420. PType: reg_type,
  9421. Diagnosis: diagnosis_ids,
  9422. SickType: sick_type,
  9423. }
  9424. service.CreateHisPatient(&hisPatient)
  9425. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9426. c.ServeSuccessJSON(map[string]interface{}{
  9427. "his_info": hisPatient,
  9428. })
  9429. }
  9430. }
  9431. // 上传明细----结算
  9432. func (c *HisApiController) GetUploadInfo() {
  9433. id, _ := c.GetInt64("id")
  9434. record_time := c.GetString("record_time")
  9435. his_patient_id, _ := c.GetInt64("his_patient_id")
  9436. oth_desc := c.GetString("oth_desc")
  9437. pay_way, _ := c.GetInt64("pay_way")
  9438. pay_ways := c.GetString("pay_ways")
  9439. pay_price, _ := c.GetFloat("pay_price")
  9440. pay_card_no := c.GetString("pay_card_no")
  9441. discount_price, _ := c.GetFloat("discount_price")
  9442. preferential_price, _ := c.GetFloat("preferential_price")
  9443. reality_price, _ := c.GetFloat("reality_price")
  9444. found_price, _ := c.GetFloat("found_price")
  9445. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9446. private_price, _ := c.GetFloat("private_price")
  9447. timeLayout := "2006-01-02"
  9448. loc, _ := time.LoadLocation("Local")
  9449. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9450. fapiao_code := c.GetString("fapiao_code")
  9451. fapiao_number := c.GetString("fapiao_number")
  9452. diagnosis_id := c.GetString("diagnosis")
  9453. sick_type, _ := c.GetInt64("sick_type")
  9454. reg_type, _ := c.GetInt64("p_type")
  9455. order_id, _ := c.GetInt64("order_id")
  9456. cash_pay := c.GetString("cash_pay")
  9457. wechat_pay := c.GetString("wechat_pay")
  9458. ali_pay := c.GetString("ali_pay")
  9459. jifen_pay := c.GetString("jifen_pay")
  9460. card_desc := c.GetString("card_desc")
  9461. band_card_pay := c.GetString("band_card_pay")
  9462. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9463. tmp_decimal := c.GetString("tmp_decimal")
  9464. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9465. var decimal float64 //本次使用的押金
  9466. var errmsg error
  9467. tx := service.XTWriteDB().Begin() //开了事务
  9468. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9469. defer func() {
  9470. if errmsg != nil {
  9471. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9472. tx.Rollback()
  9473. } else {
  9474. tx.Commit()
  9475. }
  9476. }()
  9477. fmt.Println("dec_way", dec_way)
  9478. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9479. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9480. return
  9481. }
  9482. if len(tmp_decimal) > 0 {
  9483. if tmp_decimal[0] == 45 {
  9484. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9485. return
  9486. }
  9487. }
  9488. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9489. fmt.Println(errs)
  9490. decimal = tt
  9491. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9492. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9493. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9494. if err != nil {
  9495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9496. return
  9497. }
  9498. recordDateTime := theTime.Unix()
  9499. adminUser := c.GetAdminUserInfo()
  9500. var prescriptions []*models.HisPrescription
  9501. var prescriptionsOne []*models.HisPrescription
  9502. var start_time int64
  9503. var end_time int64
  9504. ids_str := c.GetString("ids")
  9505. ids_arr := strings.Split(ids_str, ",")
  9506. if tempOrder.ID == 0 {
  9507. if settle_accounts_type == 1 { //日结
  9508. fmt.Println(reg_type)
  9509. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9510. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9511. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9512. } else {
  9513. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9514. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9515. }
  9516. } else { //月结
  9517. start_time_str := c.GetString("start_time")
  9518. end_time_str := c.GetString("end_time")
  9519. timeLayout := "2006-01-02"
  9520. loc, _ := time.LoadLocation("Local")
  9521. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9522. if err != nil {
  9523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9524. return
  9525. }
  9526. recordStartTime := theStartTime.Unix()
  9527. start_time = recordStartTime
  9528. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9529. if err != nil {
  9530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9531. return
  9532. }
  9533. recordEndTime := theEndTime.Unix()
  9534. end_time = recordEndTime
  9535. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9536. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9537. }
  9538. var goods []*models.DialysisBeforePrepareGoods
  9539. var newGoods []*models.NewDialysisBeforePrepareGoods
  9540. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9541. var infos []*models.HisDoctorAdviceInfo
  9542. var infoList []*models.HisDoctorAdviceInfo
  9543. var hisAdvice []*models.HisDoctorAdviceInfo
  9544. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9545. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9546. //判断库存不足
  9547. //结算出库开关
  9548. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9549. if settConfig.IsOpen == 1 {
  9550. //判断库存的地方
  9551. for _, info := range prescriptions {
  9552. if info.Type == 1 {
  9553. infos = append(infos, info.HisDoctorAdviceInfo...)
  9554. }
  9555. if info.Type == 2 {
  9556. for _, sumItem := range info.HisPrescriptionProject {
  9557. if sumItem.Type == 3 {
  9558. var good models.DialysisBeforePrepareGoods
  9559. var newGood models.NewDialysisBeforePrepareGoods
  9560. good.GoodId = sumItem.GoodInfo.ID
  9561. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9562. count, _ := strconv.Atoi(sumItem.Count)
  9563. good.Count = int64(count)
  9564. good.StorehouseId = houseConfig.StorehouseOutInfo
  9565. good.ProjectId = sumItem.ID
  9566. goods = append(goods, &good)
  9567. newGood.GoodId = sumItem.GoodInfo.ID
  9568. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9569. count2, _ := strconv.Atoi(sumItem.Count)
  9570. newGood.Count = int64(count2)
  9571. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9572. newGood.ProjectId = sumItem.ID
  9573. newGoods = append(newGoods, &newGood)
  9574. }
  9575. }
  9576. }
  9577. }
  9578. for _, info := range prescriptionsOne {
  9579. if info.Type == 1 {
  9580. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9581. }
  9582. if info.Type == 2 {
  9583. for _, sumItem := range info.HisPrescriptionProject {
  9584. if sumItem.Type == 3 {
  9585. var newGood models.NewDialysisBeforePrepareGoods
  9586. newGood.GoodId = sumItem.GoodInfo.ID
  9587. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9588. count2, _ := strconv.Atoi(sumItem.Count)
  9589. newGood.Count = int64(count2)
  9590. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9591. newGood.ProjectId = sumItem.ID
  9592. newGoodOne = append(newGoodOne, &newGood)
  9593. }
  9594. }
  9595. }
  9596. }
  9597. //判断
  9598. for _, itemOne := range infos {
  9599. for _, itemTwo := range hisAdvice {
  9600. if itemOne.DrugId == itemTwo.DrugId {
  9601. itemTwo.Child = append(itemTwo.Child, itemOne)
  9602. }
  9603. }
  9604. }
  9605. for _, itemTwo := range hisAdvice {
  9606. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9607. var sum_out_count int64
  9608. for _, itemThree := range itemTwo.Child {
  9609. var prescribing_number int64
  9610. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9611. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9612. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9613. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9614. }
  9615. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9616. prescribing_number = parseIntPrescribingNumber
  9617. }
  9618. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9619. prescribing_number = parseIntPrescribingNumber
  9620. }
  9621. sum_out_count += prescribing_number
  9622. }
  9623. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9624. if sum_out_count > drugStockOut.FlushCount {
  9625. c.ServeSuccessJSON(map[string]interface{}{
  9626. "msg": "2",
  9627. "drug": medical,
  9628. })
  9629. return
  9630. }
  9631. }
  9632. for _, itemOne := range newGoods {
  9633. for _, item := range newGoodOne {
  9634. if itemOne.GoodId == item.GoodId {
  9635. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9636. }
  9637. }
  9638. }
  9639. for _, item := range newGoodOne {
  9640. var sum_out_count_one int64
  9641. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9642. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9643. sum_out_count_one += itemOne.Count
  9644. }
  9645. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9646. fmt.Println("sum_out_count_one", sum_out_count_one)
  9647. fmt.Println("list.FlushCount", list.FlushCount)
  9648. if sum_out_count_one > list.FlushCount {
  9649. c.ServeSuccessJSON(map[string]interface{}{
  9650. "msg": "3",
  9651. "good": good,
  9652. })
  9653. return
  9654. }
  9655. }
  9656. }
  9657. timestamp := time.Now().Unix()
  9658. tempTime := time.Unix(timestamp, 0)
  9659. timeFormat := tempTime.Format("20060102150405")
  9660. chrgBchno := rand.Intn(100000) + 10000
  9661. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9662. strconv.FormatInt(his.PatientId, 10)
  9663. var ids []int64
  9664. for _, item := range prescriptions {
  9665. ids = append(ids, item.ID)
  9666. }
  9667. var total float64
  9668. for _, item := range prescriptions {
  9669. fmt.Println(item)
  9670. if item.Type == 1 { //药品
  9671. for _, subItem := range item.HisDoctorAdviceInfo {
  9672. if subItem.Drug.IsUser != 1 {
  9673. total = total + (subItem.Price * subItem.PrescribingNumber)
  9674. }
  9675. }
  9676. }
  9677. if item.Type == 2 { //项目
  9678. for _, subItem := range item.HisPrescriptionProject {
  9679. if subItem.Type == 2 {
  9680. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9681. total = total + (subItem.Price * cnt)
  9682. } else {
  9683. if subItem.GoodInfo.IsUser != 1 {
  9684. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9685. total = total + (subItem.Price * cnt)
  9686. }
  9687. }
  9688. }
  9689. }
  9690. for _, subItem := range item.HisAdditionalCharge {
  9691. total = total + (subItem.Price * float64(subItem.Count))
  9692. }
  9693. }
  9694. if reg_type == 1111 || reg_type == 1112 {
  9695. reg_type = 11
  9696. }
  9697. tm := time.Unix(time.Now().Unix(), 0)
  9698. allTotal := fmt.Sprintf("%.4f", total)
  9699. totals, _ := strconv.ParseFloat(allTotal, 64)
  9700. order := &models.HisOrder{
  9701. UserOrgId: adminUser.CurrentOrgId,
  9702. HisPatientId: his.ID,
  9703. PatientId: id,
  9704. SettleAccountsDate: recordDateTime,
  9705. Ctime: time.Now().Unix(),
  9706. Mtime: time.Now().Unix(),
  9707. Status: 1,
  9708. OrderStatus: 2,
  9709. MdtrtId: his.Number,
  9710. Number: chrg_bchno,
  9711. MedfeeSumamt: totals,
  9712. PayWay: pay_way,
  9713. PayWays: pay_ways,
  9714. PayPrice: pay_price,
  9715. MedType: strconv.Itoa(int(reg_type)),
  9716. PayCardNo: pay_card_no,
  9717. DiscountPrice: discount_price,
  9718. PreferentialPrice: preferential_price,
  9719. RealityPrice: reality_price,
  9720. FoundPrice: found_price,
  9721. MedicalInsurancePrice: medical_insurance_price,
  9722. PrivatePrice: private_price,
  9723. SettleEndTime: end_time,
  9724. SettleStartTime: start_time,
  9725. PsnPartAmt: totals,
  9726. PsnCashPay: totals,
  9727. SettleType: settle_accounts_type,
  9728. FaPiaoCode: fapiao_code,
  9729. FaPiaoNumber: fapiao_number,
  9730. Diagnosis: diagnosis_id,
  9731. PType: 2,
  9732. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9733. Decimal: decimal,
  9734. OthDesc: oth_desc,
  9735. CashPay: cash_pay,
  9736. WechatPay: wechat_pay,
  9737. AliPay: ali_pay,
  9738. JifenPay: jifen_pay,
  9739. BandCardPay: band_card_pay,
  9740. Creator: adminUser.AdminUser.Id,
  9741. CardDesc: card_desc,
  9742. }
  9743. err = service.CreateOrderTX(order, tx)
  9744. if err != nil {
  9745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9746. return
  9747. }
  9748. var customs []*Custom
  9749. for _, item := range prescriptions {
  9750. if item.Type == 1 { //药品a
  9751. for _, subItem := range item.HisDoctorAdviceInfo {
  9752. if subItem.Drug.IsUser != 1 {
  9753. cus := &Custom{
  9754. AdviceId: subItem.ID,
  9755. ProjectId: 0,
  9756. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9757. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9758. FeedetlSn: subItem.FeedetlSn,
  9759. Price: fmt.Sprintf("%.4f", subItem.Price),
  9760. MedListCodg: subItem.MedListCodg,
  9761. Type: 1,
  9762. CostType: 9,
  9763. }
  9764. customs = append(customs, cus)
  9765. }
  9766. }
  9767. }
  9768. if item.Type == 2 { //项目
  9769. for _, subItem := range item.HisPrescriptionProject {
  9770. if subItem.Type == 2 {
  9771. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9772. cus := &Custom{
  9773. AdviceId: 0,
  9774. ProjectId: subItem.ID,
  9775. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9776. Cut: fmt.Sprintf("%.4f", cnt),
  9777. FeedetlSn: subItem.FeedetlSn,
  9778. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9779. MedListCodg: subItem.MedListCodg,
  9780. Type: 2,
  9781. CostType: subItem.HisProject.CostClassify,
  9782. }
  9783. customs = append(customs, cus)
  9784. } else {
  9785. if subItem.GoodInfo.IsUser != 1 {
  9786. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9787. cus := &Custom{
  9788. AdviceId: 0,
  9789. ProjectId: subItem.ID,
  9790. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9791. Cut: fmt.Sprintf("%.4f", cnt),
  9792. FeedetlSn: subItem.FeedetlSn,
  9793. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9794. MedListCodg: subItem.MedListCodg,
  9795. Type: 2,
  9796. CostType: subItem.HisProject.CostClassify,
  9797. }
  9798. customs = append(customs, cus)
  9799. }
  9800. }
  9801. }
  9802. }
  9803. for _, item := range item.HisAdditionalCharge {
  9804. cus := &Custom{
  9805. ItemId: item.ID,
  9806. AdviceId: 0,
  9807. ProjectId: 0,
  9808. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9809. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9810. FeedetlSn: item.FeedetlSn,
  9811. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9812. MedListCodg: item.XtHisAddtionConfig.Code,
  9813. Type: 3,
  9814. CostType: 5,
  9815. }
  9816. customs = append(customs, cus)
  9817. }
  9818. }
  9819. for _, item := range customs {
  9820. var advice_id int64 = 0
  9821. var project_id int64 = 0
  9822. var item_id int64 = 0
  9823. var types int64 = 0
  9824. var med_chrgitm_type string
  9825. if item.Type == 1 {
  9826. advice_id = item.AdviceId
  9827. project_id = 0
  9828. item_id = 0
  9829. med_chrgitm_type = "09"
  9830. } else if item.Type == 2 {
  9831. med_chrgitm_type = "05"
  9832. if item.CostType == 3 {
  9833. med_chrgitm_type = "04"
  9834. }
  9835. if item.CostType == 8 {
  9836. med_chrgitm_type = "03"
  9837. }
  9838. advice_id = 0
  9839. item_id = 0
  9840. project_id = item.ProjectId
  9841. } else if item.Type == 3 {
  9842. advice_id = 0
  9843. item_id = item.ItemId
  9844. project_id = 0
  9845. med_chrgitm_type = "08"
  9846. }
  9847. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9848. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9849. pric, _ := strconv.ParseFloat(item.Price, 32)
  9850. info := &models.HisOrderInfo{
  9851. OrderNumber: order.Number,
  9852. UploadDate: time.Now().Unix(),
  9853. AdviceId: advice_id,
  9854. DetItemFeeSumamt: detItemFeeSumamt,
  9855. MedChrgitmType: med_chrgitm_type,
  9856. Cnt: cut,
  9857. Pric: pric,
  9858. PatientId: id,
  9859. Status: 1,
  9860. Mtime: time.Now().Unix(),
  9861. Ctime: time.Now().Unix(),
  9862. UserOrgId: adminUser.CurrentOrgId,
  9863. HisPatientId: his.ID,
  9864. OrderId: order.ID,
  9865. ProjectId: project_id,
  9866. Type: types,
  9867. ItemId: item_id,
  9868. }
  9869. service.CreateOrderInfoTX(info, tx)
  9870. }
  9871. his.Diagnosis = diagnosis_id
  9872. his.SickType = sick_type
  9873. his.RegisterType = reg_type
  9874. his.MedicalTreatmentType = reg_type
  9875. service.UpdataHisPateintTX(&his, tx)
  9876. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9877. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9878. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9879. //判断是否使用了押金
  9880. if dec_way == "true" {
  9881. tmpstring := strconv.FormatInt(order.ID, 10)
  9882. //扣押金
  9883. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9884. order.Decimal = decimal
  9885. service.UpDateOrderTwo(order, tx)
  9886. if errmsg != nil {
  9887. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9888. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9889. return
  9890. }
  9891. }
  9892. if err == nil {
  9893. for _, info := range prescriptions {
  9894. if info.Type == 1 {
  9895. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9896. }
  9897. if info.Type == 2 {
  9898. for _, sumItem := range info.HisPrescriptionProject {
  9899. if sumItem.Type == 3 {
  9900. var good models.DialysisBeforePrepareGoods
  9901. var newGood models.NewDialysisBeforePrepareGoods
  9902. var oldGood models.OldDialysisBeforePrepareGoods
  9903. good.GoodId = sumItem.GoodInfo.ID
  9904. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9905. count, _ := strconv.Atoi(sumItem.Count)
  9906. good.Count = int64(count)
  9907. good.StorehouseId = houseConfig.StorehouseOutInfo
  9908. good.ProjectId = sumItem.ID
  9909. good.PatientId = sumItem.PatientId
  9910. goods = append(goods, &good)
  9911. newGood.GoodId = sumItem.GoodInfo.ID
  9912. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9913. count2, _ := strconv.Atoi(sumItem.Count)
  9914. newGood.Count = int64(count2)
  9915. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9916. newGood.ProjectId = sumItem.ID
  9917. newGood.PatientId = sumItem.HisPatientId
  9918. newGoods = append(newGoods, &newGood)
  9919. oldGood.GoodId = sumItem.GoodInfo.ID
  9920. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9921. count3, _ := strconv.Atoi(sumItem.Count)
  9922. oldGood.Count = int64(count3)
  9923. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9924. oldGood.ProjectId = sumItem.ID
  9925. oldGood.RecordDate = sumItem.RecordDate
  9926. oldGood.PatientId = sumItem.HisPatientId
  9927. oldGoods = append(oldGoods, &oldGood)
  9928. }
  9929. }
  9930. }
  9931. }
  9932. if settConfig.IsOpen == 1 {
  9933. for _, item := range infoList {
  9934. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9935. if medical.IsUse == 2 {
  9936. //药品出库
  9937. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9938. //查询默认仓库
  9939. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9940. //查询默认仓库剩余多少库存
  9941. var sum_count int64
  9942. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9943. for _, its := range stockInfo {
  9944. if its.MaxUnit == medical.MaxUnit {
  9945. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9946. }
  9947. sum_count += its.StockMaxNumber + its.StockMinNumber
  9948. }
  9949. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9950. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9951. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9952. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9953. }
  9954. }
  9955. orgId := c.GetAdminUserInfo().CurrentOrgId
  9956. if len(oldGoods) > 0 {
  9957. timeStr := time.Now().Format("2006-01-02")
  9958. timeArr := strings.Split(timeStr, "-")
  9959. total, _ := service.FindAllWarehouseOut(orgId)
  9960. total = total + 1
  9961. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9962. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9963. number = number + total
  9964. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9965. operation_time := time.Now().Unix()
  9966. creater := c.GetAdminUserInfo().AdminUser.Id
  9967. //查询默认出库仓库库存
  9968. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9969. recordDateStr := time.Now().Format("2006-01-02")
  9970. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9971. nowtime := recordDate.Unix()
  9972. warehouseOut := models.WarehouseOut{
  9973. WarehouseOutOrderNumber: warehousing_out_order,
  9974. OperationTime: operation_time,
  9975. OrgId: orgId,
  9976. Creater: creater,
  9977. Ctime: time.Now().Unix(),
  9978. Status: 1,
  9979. WarehouseOutTime: nowtime,
  9980. Type: 1,
  9981. StorehouseId: storeConfig.StorehouseOutInfo,
  9982. IsCheck: 1,
  9983. OrderId: order.ID,
  9984. IsSys: 5,
  9985. }
  9986. //查询是否生成出库单
  9987. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9988. if out.ID == 0 {
  9989. service.AddSigleWarehouseOutOne(&warehouseOut)
  9990. }
  9991. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9992. for _, item := range oldGoods {
  9993. dialyPrepareOne := models.DialysisBeforePrepare{
  9994. GoodTypeId: item.GoodTypeId,
  9995. GoodId: item.GoodId,
  9996. PatientId: his.PatientId,
  9997. RecordDate: item.RecordDate,
  9998. UserOrgId: adminUser.CurrentOrgId,
  9999. Count: item.Count,
  10000. Ctime: time.Now().Unix(),
  10001. Creater: adminUser.AdminUser.Id,
  10002. CommdityCode: item.CommdityCode,
  10003. Status: 1,
  10004. StorehouseId: houseConfig.StorehouseOutInfo,
  10005. }
  10006. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  10007. //非零用
  10008. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  10009. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10010. //查询剩余库存
  10011. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10012. var sum_count int64
  10013. for _, item := range goodList {
  10014. sum_count += item.StockCount
  10015. }
  10016. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10017. //耗材
  10018. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10019. }
  10020. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  10021. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  10022. //查询剩余库存
  10023. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  10024. var sum_count int64
  10025. for _, item := range goodList {
  10026. sum_count += item.StockCount
  10027. }
  10028. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  10029. //耗材
  10030. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  10031. }
  10032. }
  10033. }
  10034. }
  10035. c.ServeSuccessJSON(map[string]interface{}{
  10036. "msg": "结算成功",
  10037. })
  10038. }
  10039. }
  10040. }
  10041. // 退款
  10042. func (c *HisApiController) Refund() {
  10043. order_id, _ := c.GetInt64("order_id")
  10044. order, _ := service.GetHisOrderByID(order_id)
  10045. adminUser := c.GetAdminUserInfo()
  10046. orgid := c.GetAdminUserInfo().CurrentOrgId
  10047. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  10048. if err != nil {
  10049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10050. return
  10051. }
  10052. tmp := strconv.FormatInt(order.ID, 10)
  10053. //当押金不为零时产生退费记录
  10054. if order.Decimal != 0 {
  10055. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  10056. if err != nil {
  10057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10058. return
  10059. }
  10060. }
  10061. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  10062. if fapiao.ID > 0 {
  10063. c.ServeSuccessJSON(map[string]interface{}{
  10064. "failed_code": -10,
  10065. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  10066. })
  10067. return
  10068. }
  10069. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  10070. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  10071. var goods []*models.DialysisBeforePrepareGoods
  10072. var newGoods []*models.NewDialysisBeforePrepareGoods
  10073. var infos []*models.HisDoctorAdviceInfo
  10074. for _, info := range orders {
  10075. if info.AdviceId > 0 && info.ProjectId == 0 {
  10076. infos = append(infos, &info.HisDoctorAdviceInfo)
  10077. }
  10078. if info.ProjectId > 0 && info.AdviceId == 0 {
  10079. if info.HisPrescriptionProject.Type == 3 {
  10080. var good models.DialysisBeforePrepareGoods
  10081. var newGood models.NewDialysisBeforePrepareGoods
  10082. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10083. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10084. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10085. good.Count = int64(count)
  10086. good.StorehouseId = houseConfig.StorehouseOutInfo
  10087. good.ProjectId = info.HisPrescriptionProject.ID
  10088. good.PatientId = info.PatientId
  10089. good.OrderId = order_id
  10090. goods = append(goods, &good)
  10091. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10092. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10093. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10094. newGood.Count = int64(count2)
  10095. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10096. newGood.ProjectId = info.HisPrescriptionProject.ID
  10097. newGood.RecordDate = order.SettleAccountsDate
  10098. newGood.UserOrgId = order.UserOrgId
  10099. newGood.PatientId = info.PatientId
  10100. newGood.OrderId = order_id
  10101. newGoods = append(newGoods, &newGood)
  10102. }
  10103. }
  10104. }
  10105. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10106. if settConfig.IsOpen == 1 {
  10107. for _, item := range infos {
  10108. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10109. }
  10110. for _, item := range newGoods {
  10111. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10112. }
  10113. }
  10114. c.ServeSuccessJSON(map[string]interface{}{
  10115. "msg": "退费成功",
  10116. })
  10117. }
  10118. func (c *HisApiController) RefundNumber() {
  10119. his_patient_id, _ := c.GetInt64("id")
  10120. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10121. info.Status = 0
  10122. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10123. if count > 0 {
  10124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10125. return
  10126. }
  10127. err := service.SaveHisPatient(info)
  10128. if err == nil {
  10129. c.ServeSuccessJSON(map[string]interface{}{
  10130. "msg": "退号成功",
  10131. })
  10132. } else {
  10133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10134. return
  10135. }
  10136. }
  10137. func (this *HisApiController) AdditionalCharge() {
  10138. dataBody := make(map[string]interface{}, 0)
  10139. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10140. fmt.Println(err)
  10141. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10142. patient_id := int64(dataBody["patient_id"].(float64))
  10143. medicineData, _ := dataBody["medicineData"].([]interface{})
  10144. adminUserInfo := this.GetAdminUserInfo()
  10145. orgId := adminUserInfo.CurrentOrgId
  10146. admin_user_id := adminUserInfo.AdminUser.Id
  10147. timeStr := time.Now().Format("2006-01-02")
  10148. timeLayout := "2006-01-02 15:04:05"
  10149. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10150. timenow := timeStringToTime.Unix()
  10151. var additionalCharges []*models.HisAdditionalCharge
  10152. for _, item := range medicineData {
  10153. var randNum int
  10154. randNum = rand.Intn(10000) + 1000
  10155. timestamp := time.Now().Unix()
  10156. tempTime := time.Unix(timestamp, 0)
  10157. timeFormat := tempTime.Format("20060102150405")
  10158. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10159. items := item.(map[string]interface{})
  10160. money := items["price"].(string)
  10161. item_id_str := items["item_id"].(string)
  10162. name := items["name"].(string)
  10163. id_str := items["id"].(string)
  10164. moneys, _ := strconv.ParseInt(money, 10, 64)
  10165. monStr := strconv.FormatInt(moneys, 10)
  10166. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10167. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10168. id, _ := strconv.ParseInt(id_str, 10, 64)
  10169. additionalCharge := &models.HisAdditionalCharge{
  10170. ID: id,
  10171. HisPatientId: his_patient_id,
  10172. UserOrgId: orgId,
  10173. PatientId: patient_id,
  10174. RecordDate: timenow,
  10175. Price: monneyStr,
  10176. Status: 1,
  10177. ItemName: name,
  10178. ItemId: item_id,
  10179. AdminUserId: admin_user_id,
  10180. CreatedTime: time.Now().Unix(),
  10181. OrderStatus: 0,
  10182. PrescriptionNumber: "",
  10183. BatchNumber: "",
  10184. FeedetlSn: p_number,
  10185. }
  10186. service.CreateAdditionalCharge(additionalCharge)
  10187. additionalCharges = append(additionalCharges, additionalCharge)
  10188. }
  10189. this.ServeSuccessJSON(map[string]interface{}{
  10190. "msg": "添加成功",
  10191. "additional_charges": additionalCharges,
  10192. })
  10193. }
  10194. func (this *HisApiController) DeleteAddition() {
  10195. id, _ := this.GetInt64("id")
  10196. //TODO 需要判断是否已经结算
  10197. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10198. if err == nil {
  10199. this.ServeSuccessJSON(map[string]interface{}{
  10200. "msg": "删除成功",
  10201. })
  10202. return
  10203. } else {
  10204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10205. return
  10206. }
  10207. }
  10208. func (this *HisApiController) GetAdminUsers() {
  10209. adminUser := this.GetAdminUserInfo()
  10210. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10211. this.ServeSuccessJSON(map[string]interface{}{
  10212. "doctors": doctors,
  10213. })
  10214. }
  10215. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10216. change_type, _ := this.GetInt64("type", 0)
  10217. record_date := this.GetString("record_time")
  10218. patient_id, _ := this.GetInt64("patient_id", 0)
  10219. p_type, _ := this.GetInt64("p_type", 0)
  10220. timeLayout := "2006-01-02"
  10221. loc, _ := time.LoadLocation("Local")
  10222. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10223. record_time := theAdviceRecordTime.Unix()
  10224. adminUserInfo := this.GetAdminUserInfo()
  10225. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10226. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10227. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10228. if config.ID > 0 && config.IsOpen == 1 {
  10229. for _, subitems := range prescriptions {
  10230. for _, item := range subitems.VMHisPrescription {
  10231. for _, subItem := range item.HisDoctorAdviceInfo {
  10232. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10233. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10234. if info.RetailPrice > 0 {
  10235. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10236. subItem.Drug.RetailPrice = drug.RetailPrice
  10237. }
  10238. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10239. subItem.Drug.MinPrice = info.RetailPrice
  10240. subItem.Drug.RetailPrice = info.RetailPrice
  10241. }
  10242. }
  10243. }
  10244. }
  10245. }
  10246. }
  10247. if config.ID > 0 && config.IsOpen == 1 {
  10248. for _, subitems := range prescriptions {
  10249. for _, item := range subitems.VMHisPrescription {
  10250. for _, subItem := range item.HisPrescriptionProject {
  10251. if subItem.Type == 3 {
  10252. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10253. if info.Price > 0 {
  10254. subItem.GoodInfo.PackingPrice = info.Price
  10255. }
  10256. }
  10257. }
  10258. }
  10259. }
  10260. }
  10261. }
  10262. if err == nil {
  10263. if len(prescriptions) == 0 {
  10264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10265. return
  10266. } else {
  10267. this.ServeSuccessJSON(map[string]interface{}{
  10268. "prescriptions": prescriptions,
  10269. })
  10270. return
  10271. }
  10272. } else {
  10273. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10274. return
  10275. }
  10276. }
  10277. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10278. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10279. for i := 0; i < len(arr); i++ {
  10280. repeat := false
  10281. for j := i + 1; j < len(arr); j++ {
  10282. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10283. repeat = true
  10284. break
  10285. }
  10286. }
  10287. if !repeat {
  10288. newArr = append(newArr, arr[i])
  10289. }
  10290. }
  10291. return
  10292. }
  10293. func (this *HisApiController) GetCallHisPrescription() {
  10294. patient_id, _ := this.GetInt64("patient_id", 0)
  10295. timeLayout := "2006-01-02"
  10296. loc, _ := time.LoadLocation("Local")
  10297. start_time := this.GetString("start_time")
  10298. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10299. end_time := this.GetString("end_time")
  10300. p_type, _ := this.GetInt64("p_type")
  10301. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10302. adminUserInfo := this.GetAdminUserInfo()
  10303. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10304. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10305. //if
  10306. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10307. //
  10308. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10309. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10310. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10311. if config.ID > 0 && config.IsOpen == 1 {
  10312. for _, subitems := range prescriptions {
  10313. for _, item := range subitems.VMHisPrescription {
  10314. for _, subItem := range item.HisDoctorAdviceInfo {
  10315. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10316. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10317. if info.RetailPrice > 0 {
  10318. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10319. subItem.Drug.RetailPrice = drug.RetailPrice
  10320. }
  10321. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10322. subItem.Drug.MinPrice = info.RetailPrice
  10323. subItem.Drug.RetailPrice = info.RetailPrice
  10324. }
  10325. }
  10326. }
  10327. }
  10328. }
  10329. }
  10330. if config.ID > 0 && config.IsOpen == 1 {
  10331. for _, subitems := range prescriptions {
  10332. for _, item := range subitems.VMHisPrescription {
  10333. for _, subItem := range item.HisPrescriptionProject {
  10334. if subItem.Type == 3 {
  10335. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10336. if info.Price > 0 {
  10337. subItem.GoodInfo.PackingPrice = info.Price
  10338. }
  10339. }
  10340. }
  10341. }
  10342. }
  10343. }
  10344. }
  10345. if err == nil {
  10346. this.ServeSuccessJSON(map[string]interface{}{
  10347. "prescriptions": prescriptions,
  10348. })
  10349. return
  10350. } else {
  10351. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10352. return
  10353. }
  10354. }
  10355. func (this *HisApiController) GetHisDayPrescription() {
  10356. timeLayout := "2006-01-02"
  10357. loc, _ := time.LoadLocation("Local")
  10358. start_time := this.GetString("start_time")
  10359. patient_id, _ := this.GetInt64("patient_id", 0)
  10360. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10361. end_time := this.GetString("end_time")
  10362. p_type, _ := this.GetInt64("p_type")
  10363. order_status, _ := this.GetInt64("type")
  10364. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10365. adminUserInfo := this.GetAdminUserInfo()
  10366. var dayHisPrescription []*models.HisPrescription
  10367. var err error
  10368. if order_status == 1 || order_status == 0 {
  10369. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10370. } else if order_status == 2 {
  10371. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10372. }
  10373. var settle_total float64
  10374. for _, item := range dayHisPrescription {
  10375. if len(item.HisPrescriptionProject) > 0 {
  10376. for _, subItem := range item.HisPrescriptionProject {
  10377. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10378. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10379. settle_total = settle_total + total
  10380. }
  10381. }
  10382. if len(item.HisDoctorAdviceInfo) > 0 {
  10383. for _, subItem := range item.HisDoctorAdviceInfo {
  10384. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10385. settle_total = settle_total + total
  10386. }
  10387. }
  10388. }
  10389. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10390. if err == nil {
  10391. this.ServeSuccessJSON(map[string]interface{}{
  10392. "day_prescription": dayHisPrescription,
  10393. "settle_total": settle_total,
  10394. })
  10395. return
  10396. } else {
  10397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10398. return
  10399. }
  10400. }
  10401. func (c *HisApiController) GetHisChargePatientList() {
  10402. record_date := c.GetString("record_date")
  10403. order_status, _ := c.GetInt64("type")
  10404. sch_type, _ := c.GetInt64("sch_type")
  10405. timeLayout := "2006-01-02"
  10406. loc, _ := time.LoadLocation("Local")
  10407. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10408. if err != nil {
  10409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10410. return
  10411. }
  10412. recordDateTime := theTime.Unix()
  10413. adminInfo := c.GetAdminUserInfo()
  10414. var tempPatients []*service.NewTempPatients
  10415. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10416. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10417. if order_status != 2 {
  10418. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10419. } else {
  10420. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10421. }
  10422. } else {
  10423. if order_status != 2 {
  10424. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10425. } else {
  10426. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10427. }
  10428. }
  10429. var patients []*service.NewTempPatients
  10430. var patients_two []*service.NewTempPatients
  10431. for _, item := range tempPatients {
  10432. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10433. //过滤掉没挂号的和没开处方的
  10434. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10435. patients = append(patients, item)
  10436. }
  10437. //过滤掉没挂号的
  10438. if len(item.HisPatient) > 0 {
  10439. patients_two = append(patients_two, item)
  10440. }
  10441. } else {
  10442. if len(item.HisPrescription) > 0 {
  10443. patients = append(patients, item)
  10444. }
  10445. }
  10446. }
  10447. c.ServeSuccessJSON(map[string]interface{}{
  10448. "list": patients,
  10449. "list_two": patients_two,
  10450. })
  10451. }
  10452. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10453. record_date := c.GetString("record_date")
  10454. timeLayout := "2006-01-02"
  10455. loc, _ := time.LoadLocation("Local")
  10456. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10457. if err != nil {
  10458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10459. return
  10460. }
  10461. recordDateTime := theTime.Unix()
  10462. adminUser := c.GetAdminUserInfo()
  10463. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10464. var patients []*service.Patients
  10465. for _, item := range tempPatients {
  10466. if item.HisPatient.ID == 0 {
  10467. patients = append(patients, item)
  10468. }
  10469. }
  10470. c.ServeSuccessJSON(map[string]interface{}{
  10471. "list": patients,
  10472. //"list_two": patients_two,
  10473. })
  10474. }
  10475. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10476. newArr = make([]*service.Patients, 0)
  10477. for i := 0; i < len(patient); i++ {
  10478. repeat := false
  10479. for j := i + 1; j < len(patient); j++ {
  10480. if patient[i].ID == patient[j].ID {
  10481. repeat = true
  10482. break
  10483. }
  10484. }
  10485. if !repeat {
  10486. newArr = append(newArr, patient[i])
  10487. }
  10488. }
  10489. return
  10490. }
  10491. func (c *HisApiController) GetHisChargePatientInfo() {
  10492. patient_id, _ := c.GetInt64("patient_id")
  10493. his_patient_id, _ := c.GetInt64("his_patient_id")
  10494. record_date := c.GetString("record_date")
  10495. //start_time := c.GetString("start_time")
  10496. //end_time := c.GetString("end_time")
  10497. order_status, _ := c.GetInt64("type", 0)
  10498. p_type, _ := c.GetInt64("p_type", 0)
  10499. order_id, _ := c.GetInt64("order_id", 0)
  10500. timeLayout := "2006-01-02"
  10501. loc, _ := time.LoadLocation("Local")
  10502. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10503. if err != nil {
  10504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10505. return
  10506. }
  10507. recordDateTime := theTime.Unix()
  10508. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10509. //if err != nil {
  10510. //
  10511. //}
  10512. //startRecordDateTime := startTime.Unix()
  10513. //
  10514. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10515. //if err != nil {
  10516. //
  10517. //}
  10518. //endRecordDateTime := endTime.Unix()
  10519. admin := c.GetAdminUserInfo()
  10520. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10521. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10522. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10523. var prescriptions []*models.HisPrescription
  10524. //var unChargeMonthPrescriptions []*models.HisPrescription
  10525. order, _ := service.GetHisOrderByID(order_id)
  10526. if order_status == 1 || order_status == 0 {
  10527. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10528. } else if order_status == 2 {
  10529. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10530. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10531. }
  10532. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10533. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10534. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10535. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10536. //获取所有科室信息
  10537. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10538. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10539. c.ServeSuccessJSON(map[string]interface{}{
  10540. "his_info": his_patient_info,
  10541. "last_his_patient_info": last_his_patient_info,
  10542. "xt_info": xt_patient_info,
  10543. "prescription": prescriptions,
  10544. "case_history": case_history,
  10545. "info": patientPrescriptionInfo,
  10546. "last_info": lastPatientPrescriptionInfo,
  10547. "order": order,
  10548. "doctors": doctors,
  10549. "department": department,
  10550. "sch": sch,
  10551. })
  10552. return
  10553. }
  10554. func (c *HisApiController) GetAllOrderDetail() {
  10555. order_id, _ := c.GetInt64("id", 0)
  10556. order, _ := service.GetHisOrderByID(order_id)
  10557. if order.ID == 0 {
  10558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10559. return
  10560. }
  10561. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10562. org_id := c.GetAdminUserInfo().CurrentOrgId
  10563. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10564. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10565. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10566. c.ServeSuccessJSON(map[string]interface{}{
  10567. "order": order,
  10568. "order_info": order_info,
  10569. "patient": patient,
  10570. "admin_info": adminInfo,
  10571. "hospital_record": record,
  10572. })
  10573. return
  10574. }
  10575. func (c *HisApiController) GetAllOrderDetailCollect() {
  10576. order_id, _ := c.GetInt64("id", 0)
  10577. order, _ := service.GetHisOrderByID(order_id)
  10578. if order.ID == 0 {
  10579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10580. return
  10581. }
  10582. org_id := c.GetAdminUserInfo().CurrentOrgId
  10583. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10584. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10585. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10586. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10587. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10588. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10589. var bedCostTotal float64 = 0 //床位总费
  10590. //var bedCostSelfTotal float64 = 0 //床位自费
  10591. var operationCostTotal float64 = 0 //手术费
  10592. //var operationCostSelfTotal float64 = 0 //手术费
  10593. var otherCostTotal float64 = 0 //其他费用
  10594. //var otherCostSelfTotal float64 = 0 //其他费用
  10595. var materialCostTotal float64 = 0 //材料费
  10596. //var materialCostSelfTotal float64 = 0 //材料费
  10597. var westernMedicineCostTotal float64 = 0 //西药费
  10598. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10600. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10601. var checkCostTotal float64 = 0 //检查费
  10602. //var checkCostSelfTotal float64 = 0 //检查费
  10603. var laboratoryCostTotal float64 = 0 //化验费
  10604. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10605. var treatCostTotal float64 = 0 //治疗费用
  10606. //var treatCostSelfTotal float64 = 0 //治疗费用
  10607. var zhenChaCostTotal float64 = 0 //其他费用
  10608. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10609. decimal.DivisionPrecision = 2
  10610. var BalanceAccountsType int64
  10611. if his.ID > 0 {
  10612. BalanceAccountsType = his.BalanceAccountsType
  10613. } else {
  10614. BalanceAccountsType = record.BalanceAccountsType
  10615. }
  10616. if BalanceAccountsType != 2 {
  10617. for _, item := range order_info {
  10618. if org_id == 10215 {
  10619. if item.MedChrgitmType == "01" { //床位费
  10620. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10621. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10622. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10623. }
  10624. if item.MedChrgitmType == "02" { //诊察费
  10625. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10626. //zhenChaCostSelfTotal = zhenChaCostTotal
  10627. }
  10628. if item.MedChrgitmType == "03" { //检查费
  10629. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10630. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10631. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10632. }
  10633. //if item.MedChrgitmType == "02" { //检查费
  10634. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10635. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10636. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10637. //}
  10638. if item.MedChrgitmType == "04" { //化验费
  10639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10640. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10641. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10642. }
  10643. if item.MedChrgitmType == "05" { //治疗费
  10644. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10645. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10646. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10647. }
  10648. if item.MedChrgitmType == "06" { //手术费
  10649. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10650. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10651. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10652. }
  10653. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10654. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10655. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10656. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10657. }
  10658. if item.MedChrgitmType == "09" { //西药费
  10659. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10660. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10661. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10662. }
  10663. if item.MedChrgitmType == "11" { //中成费
  10664. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10665. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10666. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10667. }
  10668. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10669. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10670. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10671. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10672. }
  10673. } else if org_id == 10188 || org_id == 10217 {
  10674. if item.MedChrgitmType == "01" { //床位费
  10675. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10676. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10677. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10678. }
  10679. if item.MedChrgitmType == "02" { //诊察费
  10680. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10681. //zhenChaCostSelfTotal = zhenChaCostTotal
  10682. }
  10683. if item.MedChrgitmType == "03" { //检查费
  10684. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10685. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10686. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10687. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10688. }
  10689. //if item.MedChrgitmType == "02" { //检查费
  10690. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10691. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10692. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10693. //}
  10694. if item.MedChrgitmType == "04" { //化验费
  10695. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10696. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10697. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10698. }
  10699. if item.MedChrgitmType == "05" { //治疗费
  10700. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10701. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10702. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10703. }
  10704. if item.MedChrgitmType == "06" { //手术费
  10705. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10706. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10707. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10708. }
  10709. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10710. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10711. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10712. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10713. }
  10714. if item.MedChrgitmType == "09" { //西药费
  10715. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10716. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10717. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10718. }
  10719. if item.MedChrgitmType == "11" { //中成费
  10720. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10721. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10722. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10723. }
  10724. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10725. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10726. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10727. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10728. }
  10729. } else {
  10730. if item.MedChrgitmType == "01" { //床位费
  10731. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10732. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10733. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10734. }
  10735. //if item.MedChrgitmType == "02" { //诊察费
  10736. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10737. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10738. //}
  10739. if item.MedChrgitmType == "03" { //检查费
  10740. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10741. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10742. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10743. }
  10744. //if item.MedChrgitmType == "02" { //检查费
  10745. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10746. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10747. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10748. //}
  10749. if item.MedChrgitmType == "04" { //化验费
  10750. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10751. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10752. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10753. }
  10754. if item.MedChrgitmType == "05" { //治疗费
  10755. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10756. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10757. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10758. }
  10759. if item.MedChrgitmType == "06" { //手术费
  10760. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10761. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10762. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10763. }
  10764. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10765. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10766. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10767. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10768. }
  10769. if item.MedChrgitmType == "09" { //西药费
  10770. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10771. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10772. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10773. }
  10774. if item.MedChrgitmType == "11" { //中成费
  10775. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10776. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10777. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10778. }
  10779. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10780. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10781. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10782. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10783. }
  10784. }
  10785. }
  10786. c.ServeSuccessJSON(map[string]interface{}{
  10787. "order": order,
  10788. "order_info": order_info,
  10789. "patient": patient,
  10790. "admin_info": adminInfo,
  10791. "his_hospital": record,
  10792. "bedCostTotal": bedCostTotal,
  10793. "operationCostTotal": operationCostTotal,
  10794. "otherCostTotal": otherCostTotal,
  10795. "materialCostTotal": materialCostTotal,
  10796. "westernMedicineCostTotal": westernMedicineCostTotal,
  10797. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10798. "checkCostTotal": checkCostTotal,
  10799. "zhenChaCostTotal": zhenChaCostTotal,
  10800. "laboratoryCostTotal": laboratoryCostTotal,
  10801. "treatCostTotal": treatCostTotal,
  10802. })
  10803. } else {
  10804. for _, item := range order_info {
  10805. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10806. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10807. item.MedChrgitmType = "09"
  10808. }
  10809. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10810. if item.HisPrescriptionProject.Type == 2 {
  10811. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10812. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10813. case 0:
  10814. item.MedChrgitmType = "0"
  10815. break
  10816. case 1:
  10817. item.MedChrgitmType = "14"
  10818. break
  10819. case 2:
  10820. item.MedChrgitmType = "05"
  10821. break
  10822. case 3:
  10823. item.MedChrgitmType = "03"
  10824. break
  10825. case 4:
  10826. item.MedChrgitmType = "03"
  10827. break
  10828. case 5:
  10829. item.MedChrgitmType = "08"
  10830. break
  10831. case 6:
  10832. item.MedChrgitmType = "14"
  10833. break
  10834. case 7:
  10835. item.MedChrgitmType = "14"
  10836. break
  10837. case 8:
  10838. item.MedChrgitmType = "03"
  10839. break
  10840. case 9:
  10841. item.MedChrgitmType = "14"
  10842. break
  10843. case 10:
  10844. item.MedChrgitmType = "14"
  10845. break
  10846. case 11:
  10847. item.MedChrgitmType = "06"
  10848. break
  10849. case 12:
  10850. item.MedChrgitmType = "12"
  10851. break
  10852. case 13:
  10853. item.MedChrgitmType = "01"
  10854. break
  10855. case 14:
  10856. item.MedChrgitmType = "04"
  10857. break
  10858. case 15:
  10859. item.MedChrgitmType = "14"
  10860. break
  10861. }
  10862. } else {
  10863. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10864. case 1:
  10865. item.MedChrgitmType = "14"
  10866. break
  10867. case 2:
  10868. item.MedChrgitmType = "05"
  10869. break
  10870. case 3:
  10871. item.MedChrgitmType = "04"
  10872. break
  10873. case 4:
  10874. item.MedChrgitmType = "14"
  10875. break
  10876. case 5:
  10877. item.MedChrgitmType = "08"
  10878. break
  10879. case 6:
  10880. item.MedChrgitmType = "14"
  10881. break
  10882. case 7:
  10883. item.MedChrgitmType = "14"
  10884. break
  10885. case 8:
  10886. item.MedChrgitmType = "03"
  10887. break
  10888. case 9:
  10889. item.MedChrgitmType = "14"
  10890. break
  10891. }
  10892. }
  10893. } else if item.HisPrescriptionProject.Type == 3 {
  10894. item.MedChrgitmType = "08"
  10895. }
  10896. }
  10897. }
  10898. for _, item := range order_info {
  10899. if org_id == 10215 {
  10900. if item.MedChrgitmType == "01" { //床位费
  10901. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10902. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10903. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10904. }
  10905. if item.MedChrgitmType == "02" { //诊察费
  10906. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10907. //zhenChaCostSelfTotal = zhenChaCostTotal
  10908. }
  10909. if item.MedChrgitmType == "03" { //检查费
  10910. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10911. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10912. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10913. }
  10914. //if item.MedChrgitmType == "02" { //检查费
  10915. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10916. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10917. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10918. //}
  10919. if item.MedChrgitmType == "04" { //化验费
  10920. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10921. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10922. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10923. }
  10924. if item.MedChrgitmType == "05" { //治疗费
  10925. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10926. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10927. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10928. }
  10929. if item.MedChrgitmType == "06" { //手术费
  10930. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10931. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10932. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10933. }
  10934. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10935. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10936. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10937. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10938. }
  10939. if item.MedChrgitmType == "09" { //西药费
  10940. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10941. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10942. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10943. }
  10944. if item.MedChrgitmType == "11" { //中成费
  10945. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10946. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10947. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10948. }
  10949. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10950. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10951. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10952. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10953. }
  10954. } else {
  10955. if item.MedChrgitmType == "01" { //床位费
  10956. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10957. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10958. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10959. }
  10960. //if item.MedChrgitmType == "02" { //诊察费
  10961. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10962. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10963. //}
  10964. if item.MedChrgitmType == "03" { //检查费
  10965. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10966. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10967. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10968. }
  10969. //if item.MedChrgitmType == "02" { //检查费
  10970. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10971. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10972. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10973. //}
  10974. if item.MedChrgitmType == "04" { //化验费
  10975. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10976. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10977. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10978. }
  10979. if item.MedChrgitmType == "05" { //治疗费
  10980. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10981. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10982. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10983. }
  10984. if item.MedChrgitmType == "06" { //手术费
  10985. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10986. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10987. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10988. }
  10989. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10990. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10991. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10992. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10993. }
  10994. if item.MedChrgitmType == "09" { //西药费
  10995. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10996. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10997. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10998. }
  10999. if item.MedChrgitmType == "11" { //中成费
  11000. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11001. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11002. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11003. }
  11004. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11005. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11006. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11007. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11008. }
  11009. }
  11010. }
  11011. c.ServeSuccessJSON(map[string]interface{}{
  11012. "order": order,
  11013. "order_info": order_info,
  11014. "patient": patient,
  11015. "admin_info": adminInfo,
  11016. "his_hospital": record,
  11017. "bedCostTotal": bedCostTotal,
  11018. "operationCostTotal": operationCostTotal,
  11019. "otherCostTotal": otherCostTotal,
  11020. "materialCostTotal": materialCostTotal,
  11021. "westernMedicineCostTotal": westernMedicineCostTotal,
  11022. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11023. "checkCostTotal": checkCostTotal,
  11024. "zhenChaCostTotal": zhenChaCostTotal,
  11025. "laboratoryCostTotal": laboratoryCostTotal,
  11026. "treatCostTotal": treatCostTotal,
  11027. })
  11028. }
  11029. }
  11030. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  11031. page, _ := c.GetInt64("page")
  11032. limit, _ := c.GetInt64("limit")
  11033. keywords := c.GetString("keywords")
  11034. start_time := c.GetString("start_time")
  11035. end_time := c.GetString("end_time")
  11036. //clr_type := c.GetString("clr_type")
  11037. insutype := c.GetString("insutype")
  11038. timeLayout := "2006-01-02"
  11039. loc, _ := time.LoadLocation("Local")
  11040. var theStartTIme int64
  11041. if len(start_time) > 0 {
  11042. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11043. theStartTIme = theTime.Unix()
  11044. }
  11045. var theEndtTIme int64
  11046. if len(end_time) > 0 {
  11047. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11048. theEndtTIme = theTime.Unix()
  11049. }
  11050. if page <= 0 {
  11051. page = 1
  11052. }
  11053. if limit <= 0 {
  11054. limit = 10
  11055. }
  11056. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  11057. c.ServeSuccessJSON(map[string]interface{}{
  11058. "total": total,
  11059. "list": list,
  11060. })
  11061. return
  11062. }
  11063. func (c *HisApiController) GetPutOnRecordList() {
  11064. page, _ := c.GetInt64("page")
  11065. limit, _ := c.GetInt64("limit")
  11066. keywords := c.GetString("keywords")
  11067. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  11068. if page <= 0 {
  11069. page = 1
  11070. }
  11071. if limit <= 0 {
  11072. limit = 10
  11073. }
  11074. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  11075. c.ServeSuccessJSON(map[string]interface{}{
  11076. "total": total,
  11077. "list": list,
  11078. })
  11079. return
  11080. }
  11081. func (c *HisApiController) GetCompareData() {
  11082. start_time := c.GetString("start_time")
  11083. end_time := c.GetString("end_time")
  11084. insutype := c.GetString("insutype")
  11085. clr_type := c.GetString("clr_type")
  11086. timeLayout := "2006-01-02"
  11087. loc, _ := time.LoadLocation("Local")
  11088. var theStartTIme int64
  11089. if len(start_time) > 0 {
  11090. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11091. if err != nil {
  11092. theStartTIme = 0
  11093. }
  11094. theStartTIme = theTime.Unix()
  11095. }
  11096. var theEndtTIme int64
  11097. if len(end_time) > 0 {
  11098. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11099. if err != nil {
  11100. theEndtTIme = 0
  11101. }
  11102. theEndtTIme = theTime.Unix()
  11103. }
  11104. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11105. fmt.Println(err)
  11106. if err == nil {
  11107. c.ServeSuccessJSON(map[string]interface{}{
  11108. "list": formData,
  11109. })
  11110. } else {
  11111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11112. return
  11113. }
  11114. }
  11115. func (c *HisApiController) GetFaPiaoData() {
  11116. order_id, _ := c.GetInt64("order_id")
  11117. patient_id, _ := c.GetInt64("patient_id")
  11118. //number := c.GetString("number")
  11119. adminUser := c.GetAdminUserInfo()
  11120. order, _ := service.GetHisOrderByID(order_id)
  11121. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11122. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11123. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11124. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11125. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11126. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11127. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11128. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11129. var bedCostTotal float64 = 0 //床位总费
  11130. var bedCostSelfTotal float64 = 0 //床位自费
  11131. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11132. var operationCostTotal float64 = 0 //手术费
  11133. var operationCostSelfTotal float64 = 0 //手术费
  11134. var operationCostPartSelfTotal float64 = 0 //手术费
  11135. var otherCostTotal float64 = 0 //其他费用
  11136. var otherCostSelfTotal float64 = 0 //其他费用
  11137. var otherCostPartSelfTotal float64 = 0 //其他费用
  11138. var materialCostTotal float64 = 0 //材料费
  11139. var materialCostSelfTotal float64 = 0 //材料费
  11140. var materialCostPartSelfTotal float64 = 0 //材料费
  11141. var westernMedicineCostTotal float64 = 0 //西药费
  11142. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11143. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11144. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11145. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11146. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11147. var checkCostTotal float64 = 0 //检查费
  11148. var checkCostSelfTotal float64 = 0 //检查费
  11149. var checkCostPartSelfTotal float64 = 0 //检查费
  11150. var hiliCostTotal float64 = 0 //护理费
  11151. var hiliCostSelfTotal float64 = 0 //护理费
  11152. var hiliCostPartSelfTotal float64 = 0 //护理费
  11153. var laboratoryCostTotal float64 = 0 //化验费
  11154. var laboratoryCostSelfTotal float64 = 0 //化验费
  11155. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11156. var treatCostTotal float64 = 0 //治疗费用
  11157. var treatCostSelfTotal float64 = 0 //治疗费用
  11158. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11159. var zhenChaCostTotal float64 = 0 //其他费用
  11160. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11161. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11162. decimal.DivisionPrecision = 2
  11163. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11164. var balanceAccountsType int64
  11165. if his.ID > 0 {
  11166. balanceAccountsType = his.BalanceAccountsType
  11167. } else {
  11168. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11169. }
  11170. if balanceAccountsType == 2 {
  11171. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11172. for _, item := range orderInfos_two {
  11173. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11174. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11175. item.MedChrgitmType = "09"
  11176. }
  11177. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11178. if item.HisPrescriptionProject.Type == 2 {
  11179. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11180. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11181. case 0:
  11182. item.MedChrgitmType = "0"
  11183. break
  11184. case 1:
  11185. item.MedChrgitmType = "14"
  11186. break
  11187. case 2:
  11188. item.MedChrgitmType = "05"
  11189. break
  11190. case 3:
  11191. item.MedChrgitmType = "03"
  11192. break
  11193. case 4:
  11194. item.MedChrgitmType = "03"
  11195. break
  11196. case 5:
  11197. item.MedChrgitmType = "08"
  11198. break
  11199. case 6:
  11200. item.MedChrgitmType = "14"
  11201. break
  11202. case 7:
  11203. item.MedChrgitmType = "14"
  11204. break
  11205. case 8:
  11206. item.MedChrgitmType = "03"
  11207. break
  11208. case 9:
  11209. item.MedChrgitmType = "14"
  11210. break
  11211. case 10:
  11212. item.MedChrgitmType = "14"
  11213. break
  11214. case 11:
  11215. item.MedChrgitmType = "06"
  11216. break
  11217. case 12:
  11218. item.MedChrgitmType = "12"
  11219. break
  11220. case 13:
  11221. item.MedChrgitmType = "01"
  11222. break
  11223. case 14:
  11224. item.MedChrgitmType = "04"
  11225. break
  11226. case 15:
  11227. item.MedChrgitmType = "02"
  11228. break
  11229. }
  11230. } else {
  11231. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11232. case 1:
  11233. item.MedChrgitmType = "14"
  11234. break
  11235. case 2:
  11236. item.MedChrgitmType = "05"
  11237. break
  11238. case 3:
  11239. item.MedChrgitmType = "04"
  11240. break
  11241. case 4:
  11242. item.MedChrgitmType = "03"
  11243. break
  11244. case 5:
  11245. item.MedChrgitmType = "08"
  11246. break
  11247. case 6:
  11248. item.MedChrgitmType = "14"
  11249. break
  11250. case 7:
  11251. item.MedChrgitmType = "14"
  11252. break
  11253. case 8:
  11254. item.MedChrgitmType = "03"
  11255. break
  11256. case 9:
  11257. item.MedChrgitmType = "14"
  11258. break
  11259. }
  11260. }
  11261. } else if item.HisPrescriptionProject.Type == 3 {
  11262. item.MedChrgitmType = "08"
  11263. }
  11264. }
  11265. }
  11266. for _, item := range orderInfos_two {
  11267. fmt.Println(item.MedChrgitmType)
  11268. if item.MedChrgitmType == "07" { //床位费
  11269. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11270. hiliCostSelfTotal = hiliCostTotal
  11271. }
  11272. if item.MedChrgitmType == "01" { //床位费
  11273. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11274. bedCostSelfTotal = bedCostTotal
  11275. }
  11276. if item.MedChrgitmType == "02" { //诊察费
  11277. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11278. zhenChaCostSelfTotal = zhenChaCostTotal
  11279. }
  11280. if item.MedChrgitmType == "03" { //检查费
  11281. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11282. checkCostSelfTotal = checkCostTotal
  11283. }
  11284. if item.MedChrgitmType == "04" { //化验费
  11285. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11286. laboratoryCostSelfTotal = laboratoryCostTotal
  11287. }
  11288. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11289. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11290. treatCostSelfTotal = treatCostTotal
  11291. }
  11292. if item.MedChrgitmType == "06" { //手术费
  11293. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11294. operationCostSelfTotal = treatCostTotal
  11295. }
  11296. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11297. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11298. materialCostSelfTotal = materialCostTotal
  11299. }
  11300. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11301. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11302. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11303. }
  11304. if item.MedChrgitmType == "11" { //中成费
  11305. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11306. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11307. }
  11308. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11309. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11310. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11311. otherCostSelfTotal = otherCostTotal
  11312. }
  11313. } else {
  11314. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11315. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11316. otherCostSelfTotal = otherCostTotal
  11317. }
  11318. }
  11319. }
  11320. } else {
  11321. for _, item := range orderInfos {
  11322. if item.MedChrgitmType == "01" { //床位费
  11323. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11324. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11325. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11326. }
  11327. if item.MedChrgitmType == "02" { //诊察费
  11328. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11329. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11330. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11331. }
  11332. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11333. if item.MedChrgitmType == "03" { //检查费
  11334. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11335. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11336. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11337. }
  11338. } else {
  11339. if item.MedChrgitmType == "03" { //检查费
  11340. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11341. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11342. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11343. }
  11344. }
  11345. if item.MedChrgitmType == "04" { //化验费
  11346. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11347. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11348. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11349. }
  11350. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11351. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11352. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11353. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11354. }
  11355. if item.MedChrgitmType == "06" { //手术费
  11356. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11357. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11358. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11359. }
  11360. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11361. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11362. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11363. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11364. }
  11365. if item.MedChrgitmType == "07" { //护理
  11366. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11367. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11368. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11369. }
  11370. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11371. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11372. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11373. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11374. }
  11375. if item.MedChrgitmType == "11" { //中成费
  11376. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11377. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11378. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11379. }
  11380. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11381. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11382. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11383. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11384. }
  11385. }
  11386. }
  11387. timeLayout := "2006-01-02"
  11388. loc, _ := time.LoadLocation("Local")
  11389. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11390. if err != nil {
  11391. }
  11392. startRecordDateTime := startTime.Unix()
  11393. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11394. if err != nil {
  11395. }
  11396. endRecordDateTime := endTime.Unix()
  11397. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11398. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11399. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11400. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11401. c.ServeSuccessJSON(map[string]interface{}{
  11402. "charge_admin_name": charge_admin.UserName,
  11403. "order_number": order.Number, //业务流水号
  11404. "id_card_no": his.IdCardNo, //社会保障号
  11405. "patient": patient,
  11406. "department_name": department.Name, //科室
  11407. "number": his.Number, //门诊号
  11408. "date": order.SettleAccountsDate, //结算日期
  11409. "name": order.PsnName, //姓名
  11410. "gender": patient.Gender, //性别
  11411. "psn_cash_money": order.PsnCashPay, //个人支付
  11412. "pay_way": "门诊", //结算方式
  11413. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11414. "admin_user_name": admin.UserName, //收款员
  11415. "order": order,
  11416. "order_info": orderInfos_two,
  11417. "his": his,
  11418. "bedCostTotal": bedCostTotal,
  11419. "bedCostSelfTotal": bedCostSelfTotal,
  11420. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11421. "operationCostTotal": operationCostTotal,
  11422. "operationCostSelfTotal": operationCostSelfTotal,
  11423. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11424. "otherCostTotal": otherCostTotal,
  11425. "otherCostSelfTotal": otherCostSelfTotal,
  11426. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11427. "materialCostTotal": materialCostTotal,
  11428. "materialCostSelfTotal": materialCostSelfTotal,
  11429. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11430. "westernMedicineCostTotal": westernMedicineCostTotal,
  11431. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11432. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11433. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11434. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11435. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11436. "checkCostTotal": checkCostTotal,
  11437. "checkCostSelfTotal": checkCostSelfTotal,
  11438. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11439. "laboratoryCostTotal": laboratoryCostTotal,
  11440. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11441. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11442. "treatCostTotal": treatCostTotal,
  11443. "treatCostSelfTotal": treatCostSelfTotal,
  11444. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11445. "zhenChaCostTotal": zhenChaCostTotal,
  11446. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11447. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11448. "his_hospital_record": his_hospital_record,
  11449. "pre_pay_money": pre_pay_money,
  11450. "refund_sum": sum,
  11451. "doctor_info": doctor_info,
  11452. "hiliCostTotal": hiliCostTotal,
  11453. "hiliCostSelfTotal": hiliCostSelfTotal,
  11454. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11455. })
  11456. }
  11457. //func (c *HisApiController) GetFaPiaoDatas() {
  11458. // order_ids := c.GetString("order_ids")
  11459. // patient_id, _ := c.GetInt64("patient_id")
  11460. // adminUser := c.GetAdminUserInfo()
  11461. //
  11462. // orders := strings.Split(order_ids, ",")
  11463. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11464. //
  11465. // for _, item := range orders {
  11466. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11467. // order, _ := service.GetHisOrderByID(order_id)
  11468. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11469. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11470. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11471. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11472. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11473. //
  11474. // }
  11475. //
  11476. // var bedCostTotal float64 = 0 //床位总费
  11477. // var bedCostSelfTotal float64 = 0 //床位自费
  11478. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11479. //
  11480. // var operationCostTotal float64 = 0 //手术费
  11481. // var operationCostSelfTotal float64 = 0 //手术费
  11482. // var operationCostPartSelfTotal float64 = 0 //手术费
  11483. //
  11484. // var otherCostTotal float64 = 0 //其他费用
  11485. // var otherCostSelfTotal float64 = 0 //其他费用
  11486. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11487. //
  11488. // var materialCostTotal float64 = 0 //材料费
  11489. // var materialCostSelfTotal float64 = 0 //材料费
  11490. // var materialCostPartSelfTotal float64 = 0 //材料费
  11491. //
  11492. // var westernMedicineCostTotal float64 = 0 //西药费
  11493. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11494. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11495. //
  11496. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11497. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11498. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11499. //
  11500. // var checkCostTotal float64 = 0 //检查费
  11501. // var checkCostSelfTotal float64 = 0 //检查费
  11502. // var checkCostPartSelfTotal float64 = 0 //检查费
  11503. //
  11504. // var laboratoryCostTotal float64 = 0 //化验费
  11505. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11506. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11507. //
  11508. // var treatCostTotal float64 = 0 //治疗费用
  11509. // var treatCostSelfTotal float64 = 0 //治疗费用
  11510. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11511. //
  11512. // var zhenChaCostTotal float64 = 0 //其他费用
  11513. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11514. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11515. //
  11516. // decimal.DivisionPrecision = 2
  11517. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11518. //
  11519. // var balanceAccountsType int64
  11520. // if his.ID > 0 {
  11521. // balanceAccountsType = his.BalanceAccountsType
  11522. // } else {
  11523. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11524. // }
  11525. // if balanceAccountsType == 2 {
  11526. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11527. // for _, item := range orderInfos_two {
  11528. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11529. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11530. // item.MedChrgitmType = "09"
  11531. // }
  11532. //
  11533. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11534. // if item.HisPrescriptionProject.Type == 2 {
  11535. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11536. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11537. // case 0:
  11538. // item.MedChrgitmType = "0"
  11539. // break
  11540. // case 1:
  11541. // item.MedChrgitmType = "14"
  11542. // break
  11543. // case 2:
  11544. // item.MedChrgitmType = "05"
  11545. //
  11546. // break
  11547. // case 3:
  11548. // item.MedChrgitmType = "03"
  11549. //
  11550. // break
  11551. // case 4:
  11552. // item.MedChrgitmType = "03"
  11553. //
  11554. // break
  11555. // case 5:
  11556. // item.MedChrgitmType = "08"
  11557. //
  11558. // break
  11559. // case 6:
  11560. // item.MedChrgitmType = "14"
  11561. //
  11562. // break
  11563. // case 7:
  11564. // item.MedChrgitmType = "14"
  11565. //
  11566. // break
  11567. // case 8:
  11568. // item.MedChrgitmType = "03"
  11569. // break
  11570. // case 9:
  11571. // item.MedChrgitmType = "14"
  11572. // break
  11573. // case 10:
  11574. // item.MedChrgitmType = "14"
  11575. // break
  11576. // case 11:
  11577. // item.MedChrgitmType = "06"
  11578. // break
  11579. // case 12:
  11580. // item.MedChrgitmType = "12"
  11581. // break
  11582. // case 13:
  11583. // item.MedChrgitmType = "01"
  11584. // break
  11585. // case 14:
  11586. // item.MedChrgitmType = "04"
  11587. // break
  11588. // case 15:
  11589. // item.MedChrgitmType = "02"
  11590. // break
  11591. //
  11592. // }
  11593. //
  11594. // } else {
  11595. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11596. //
  11597. // case 1:
  11598. // item.MedChrgitmType = "14"
  11599. // break
  11600. // case 2:
  11601. // item.MedChrgitmType = "05"
  11602. //
  11603. // break
  11604. // case 3:
  11605. // item.MedChrgitmType = "03"
  11606. //
  11607. // break
  11608. // case 4:
  11609. // item.MedChrgitmType = "03"
  11610. //
  11611. // break
  11612. // case 5:
  11613. // item.MedChrgitmType = "08"
  11614. //
  11615. // break
  11616. // case 6:
  11617. // item.MedChrgitmType = "14"
  11618. //
  11619. // break
  11620. // case 7:
  11621. // item.MedChrgitmType = "14"
  11622. //
  11623. // break
  11624. // case 8:
  11625. // item.MedChrgitmType = "03"
  11626. // break
  11627. // case 9:
  11628. // item.MedChrgitmType = "14"
  11629. // break
  11630. //
  11631. // }
  11632. //
  11633. // }
  11634. //
  11635. // } else if item.HisPrescriptionProject.Type == 3 {
  11636. // item.MedChrgitmType = "08"
  11637. // }
  11638. // }
  11639. // }
  11640. //
  11641. // for _, item := range orderInfos_two {
  11642. // fmt.Println(item.MedChrgitmType)
  11643. // if item.MedChrgitmType == "01" { //床位费
  11644. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11645. // bedCostSelfTotal = bedCostTotal
  11646. // }
  11647. //
  11648. // if item.MedChrgitmType == "02" { //诊察费
  11649. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11650. // zhenChaCostSelfTotal = zhenChaCostTotal
  11651. // }
  11652. //
  11653. // if item.MedChrgitmType == "03" { //检查费
  11654. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11655. // checkCostSelfTotal = checkCostTotal
  11656. // }
  11657. //
  11658. // if item.MedChrgitmType == "04" { //化验费
  11659. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11660. // laboratoryCostSelfTotal = laboratoryCostTotal
  11661. // }
  11662. //
  11663. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11664. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11665. // treatCostSelfTotal = treatCostTotal
  11666. // }
  11667. //
  11668. // if item.MedChrgitmType == "06" { //手术费
  11669. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11670. // operationCostSelfTotal = treatCostTotal
  11671. // }
  11672. //
  11673. // if item.MedChrgitmType == "08" { //材料费
  11674. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11675. // materialCostSelfTotal = materialCostTotal
  11676. // }
  11677. //
  11678. // if item.MedChrgitmType == "09" { //西药费
  11679. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11680. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11681. // }
  11682. //
  11683. // if item.MedChrgitmType == "11" { //中成费
  11684. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11685. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11686. // }
  11687. //
  11688. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11689. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11690. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11691. // otherCostSelfTotal = otherCostTotal
  11692. // }
  11693. // } else {
  11694. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11695. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11696. // otherCostSelfTotal = otherCostTotal
  11697. // }
  11698. //
  11699. // }
  11700. //
  11701. // }
  11702. //
  11703. // } else {
  11704. // for _, item := range orderInfos {
  11705. // if item.MedChrgitmType == "01" { //床位费
  11706. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11707. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11708. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11709. // }
  11710. //
  11711. // if item.MedChrgitmType == "02" { //诊察费
  11712. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11713. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11714. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11715. // }
  11716. //
  11717. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11718. // if item.MedChrgitmType == "03" { //检查费
  11719. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11720. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11721. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11722. //
  11723. // }
  11724. // } else {
  11725. // if item.MedChrgitmType == "03" { //检查费
  11726. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11727. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11728. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11729. // }
  11730. //
  11731. // }
  11732. //
  11733. // if item.MedChrgitmType == "04" { //化验费
  11734. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11735. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11736. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11737. //
  11738. // }
  11739. //
  11740. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11741. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11742. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11743. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11744. //
  11745. // }
  11746. //
  11747. // if item.MedChrgitmType == "06" { //手术费
  11748. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11749. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11750. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11751. // }
  11752. //
  11753. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11754. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11755. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11756. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11757. // }
  11758. //
  11759. // if item.MedChrgitmType == "09" { //西药费
  11760. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11761. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11762. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11763. // }
  11764. //
  11765. // if item.MedChrgitmType == "11" { //中成费
  11766. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11767. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11768. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11769. // }
  11770. //
  11771. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11772. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11773. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11774. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11775. // }
  11776. //
  11777. // }
  11778. // }
  11779. // timeLayout := "2006-01-02"
  11780. // loc, _ := time.LoadLocation("Local")
  11781. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11782. // if err != nil {
  11783. // }
  11784. // startRecordDateTime := startTime.Unix()
  11785. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11786. // if err != nil {
  11787. // }
  11788. // endRecordDateTime := endTime.Unix()
  11789. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11790. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11791. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11792. //
  11793. // c.ServeSuccessJSON(map[string]interface{}{
  11794. // "order_number": order.Number, //业务流水号
  11795. // "id_card_no": his.IdCardNo, //社会保障号
  11796. // "department_name": department.Name, //科室
  11797. // "number": his.Number, //门诊号
  11798. // "date": order.SettleAccountsDate, //结算日期
  11799. // "name": order.PsnName, //姓名
  11800. // "gender": patient.Gender, //性别
  11801. // "psn_cash_money": order.PsnCashPay, //个人支付
  11802. // "pay_way": "门诊", //结算方式
  11803. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11804. // "admin_user_name": admin.UserName, //收款员
  11805. // "order": order,
  11806. // "order_info": orderInfos_two,
  11807. // "his": his,
  11808. // "bedCostTotal": bedCostTotal,
  11809. // "bedCostSelfTotal": bedCostSelfTotal,
  11810. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11811. // "operationCostTotal": operationCostTotal,
  11812. // "operationCostSelfTotal": operationCostSelfTotal,
  11813. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11814. // "otherCostTotal": otherCostTotal,
  11815. // "otherCostSelfTotal": otherCostSelfTotal,
  11816. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11817. // "materialCostTotal": materialCostTotal,
  11818. // "materialCostSelfTotal": materialCostSelfTotal,
  11819. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11820. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11821. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11822. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11823. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11824. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11825. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11826. // "checkCostTotal": checkCostTotal,
  11827. // "checkCostSelfTotal": checkCostSelfTotal,
  11828. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11829. // "laboratoryCostTotal": laboratoryCostTotal,
  11830. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11831. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11832. // "treatCostTotal": treatCostTotal,
  11833. // "treatCostSelfTotal": treatCostSelfTotal,
  11834. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11835. // "zhenChaCostTotal": zhenChaCostTotal,
  11836. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11837. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11838. // "his_hospital_record": his_hospital_record,
  11839. // "pre_pay_money": pre_pay_money,
  11840. // "refund_sum": sum,
  11841. // })
  11842. //
  11843. //}
  11844. func (this *HisApiController) GetIncomeStatisticsData() {
  11845. start_time := this.GetString("start_time")
  11846. end_time := this.GetString("end_time")
  11847. key_words := this.GetString("key_words")
  11848. limit, _ := this.GetInt64("limit")
  11849. page, _ := this.GetInt64("page")
  11850. if page <= 0 {
  11851. page = 1
  11852. }
  11853. if limit <= 0 {
  11854. limit = 10
  11855. }
  11856. statistics_type, _ := this.GetInt64("statistics_type")
  11857. admin := this.GetAdminUserInfo()
  11858. timeLayout := "2006-01-02"
  11859. loc, _ := time.LoadLocation("Local")
  11860. var theStartTIme int64
  11861. if len(start_time) > 0 {
  11862. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11863. if err != nil {
  11864. theStartTIme = 0
  11865. }
  11866. theStartTIme = theTime.Unix()
  11867. }
  11868. var theEndtTIme int64
  11869. if len(end_time) > 0 {
  11870. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11871. if err != nil {
  11872. theEndtTIme = 0
  11873. }
  11874. theEndtTIme = theTime.Unix()
  11875. }
  11876. if statistics_type == 1 {
  11877. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11878. this.ServeSuccessJSON(map[string]interface{}{
  11879. "list": list,
  11880. "total": total,
  11881. })
  11882. } else {
  11883. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11884. this.ServeSuccessJSON(map[string]interface{}{
  11885. "list": list,
  11886. "total": total,
  11887. })
  11888. }
  11889. }
  11890. func (c *HisApiController) PostProjectInformation() {
  11891. adminUser := c.GetAdminUserInfo()
  11892. orgId := adminUser.CurrentOrgId
  11893. dataBody := make(map[string]interface{}, 0)
  11894. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11895. if err != nil {
  11896. utils.ErrorLog(err.Error())
  11897. return
  11898. }
  11899. utils.ErrorLog("%v", dataBody)
  11900. var projectList []*models.HisProject
  11901. var total_goods []interface{}
  11902. tempProjects := dataBody["projects"].([]interface{})
  11903. total_goods = tempProjects
  11904. for index, projectMap := range tempProjects {
  11905. projectM := projectMap.(map[string]interface{})
  11906. var project models.HisProject
  11907. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11908. utils.ErrorLog("project_name")
  11909. return
  11910. }
  11911. project_name, _ := projectM["project_name"].(string)
  11912. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11913. err_log := models.ExportErrLog{
  11914. LogType: 6,
  11915. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11916. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11917. Status: 1,
  11918. CreateTime: time.Now().Unix(),
  11919. UpdateTime: time.Now().Unix(),
  11920. ExportTime: time.Now().Unix(),
  11921. }
  11922. service.CreateExportErrLog(&err_log)
  11923. continue
  11924. }
  11925. project.ProjectName = project_name
  11926. prices := projectM["price"].(string)
  11927. price, _ := strconv.ParseFloat(prices, 64)
  11928. if price <= 0 { //名字为空则生成一条导入错误日志
  11929. err_log := models.ExportErrLog{
  11930. LogType: 6,
  11931. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11932. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11933. Status: 1,
  11934. CreateTime: time.Now().Unix(),
  11935. UpdateTime: time.Now().Unix(),
  11936. ExportTime: time.Now().Unix(),
  11937. }
  11938. service.CreateExportErrLog(&err_log)
  11939. continue
  11940. }
  11941. project.Price = price
  11942. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11943. utils.ErrorLog("unit_id")
  11944. return
  11945. }
  11946. unit := projectM["unit"].(string)
  11947. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11948. err_log := models.ExportErrLog{
  11949. LogType: 6,
  11950. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11951. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11952. Status: 1,
  11953. CreateTime: time.Now().Unix(),
  11954. UpdateTime: time.Now().Unix(),
  11955. ExportTime: time.Now().Unix(),
  11956. }
  11957. service.CreateExportErrLog(&err_log)
  11958. continue
  11959. }
  11960. project.Unit = unit
  11961. cost_classify := projectM["cost_classify"].(string)
  11962. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11963. err_log := models.ExportErrLog{
  11964. LogType: 6,
  11965. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11966. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11967. Status: 1,
  11968. CreateTime: time.Now().Unix(),
  11969. UpdateTime: time.Now().Unix(),
  11970. ExportTime: time.Now().Unix(),
  11971. }
  11972. service.CreateExportErrLog(&err_log)
  11973. continue
  11974. }
  11975. var costClassify = "费用类别"
  11976. var cost_classify_id int64
  11977. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11978. if len(cost_classify) != 0 {
  11979. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11980. if errcode == gorm.ErrRecordNotFound {
  11981. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11982. dataconfig := models.DictDataconfig{
  11983. ParentId: costClassifyConfig.ID,
  11984. Module: "system",
  11985. OrgId: orgId,
  11986. Name: cost_classify,
  11987. FieldName: "",
  11988. Value: costConfig.Value + 1,
  11989. CreatedTime: "",
  11990. UpdatedTime: "",
  11991. CreateUserId: adminUser.AdminUser.Id,
  11992. Status: 1,
  11993. Remark: "",
  11994. DeleteIdSystem: 0,
  11995. Title: "",
  11996. Content: "",
  11997. Order: 0,
  11998. Code: "",
  11999. }
  12000. service.CreatedDicConfig(&dataconfig)
  12001. }
  12002. }
  12003. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  12004. for _, it := range costClassList {
  12005. if cost_classify == it.Name {
  12006. cost_classify_id = int64(it.Value)
  12007. }
  12008. }
  12009. project.CostClassify = cost_classify_id
  12010. executive_section := projectM["executive_section"].(string)
  12011. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  12012. err_log := models.ExportErrLog{
  12013. LogType: 6,
  12014. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12015. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  12016. Status: 1,
  12017. CreateTime: time.Now().Unix(),
  12018. UpdateTime: time.Now().Unix(),
  12019. ExportTime: time.Now().Unix(),
  12020. }
  12021. service.CreateExportErrLog(&err_log)
  12022. continue
  12023. }
  12024. if len(executive_section) != 0 {
  12025. //查找科室是否有内容
  12026. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  12027. if errcodedepart == gorm.ErrRecordNotFound {
  12028. department := models.XtHisDepartment{
  12029. Name: executive_section,
  12030. Status: 1,
  12031. UserOrgId: adminUser.CurrentOrgId,
  12032. CreatedTime: time.Now().Unix(),
  12033. }
  12034. service.CreateDePartment(&department)
  12035. }
  12036. }
  12037. var executive_section_id int64
  12038. departMentList, _ := service.GetAllDepartMent(orgId)
  12039. for _, it := range departMentList {
  12040. if executive_section == it.Name {
  12041. executive_section_id = it.ID
  12042. }
  12043. }
  12044. project.ExecutiveSection = executive_section_id
  12045. medical_coverage := projectM["medical_coverage"].(string)
  12046. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  12047. err_log := models.ExportErrLog{
  12048. LogType: 6,
  12049. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12050. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  12051. Status: 1,
  12052. CreateTime: time.Now().Unix(),
  12053. UpdateTime: time.Now().Unix(),
  12054. ExportTime: time.Now().Unix(),
  12055. }
  12056. service.CreateExportErrLog(&err_log)
  12057. continue
  12058. }
  12059. var medicalCoverage = "医保等级"
  12060. var medical_coverage_id int64
  12061. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  12062. if len(medical_coverage) != 0 {
  12063. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  12064. if errormedicalcoverage == gorm.ErrRecordNotFound {
  12065. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  12066. dataconfig := models.DictDataconfig{
  12067. ParentId: medicalCoverageConfig.ID,
  12068. Module: "system",
  12069. OrgId: orgId,
  12070. Name: medical_coverage,
  12071. FieldName: "",
  12072. Value: medicalCoverageConfig.Value + 1,
  12073. CreatedTime: "",
  12074. UpdatedTime: "",
  12075. CreateUserId: adminUser.AdminUser.Id,
  12076. Status: 1,
  12077. Remark: "",
  12078. DeleteIdSystem: 0,
  12079. Title: "",
  12080. Content: "",
  12081. Order: 0,
  12082. Code: "",
  12083. }
  12084. service.CreatedDicConfig(&dataconfig)
  12085. }
  12086. }
  12087. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12088. for _, it := range medicalCoverageList {
  12089. if medical_coverage == it.Name {
  12090. medical_coverage_id = int64(it.Value)
  12091. }
  12092. }
  12093. project.MedicalCoverage = medical_coverage_id
  12094. pinyin := projectM["pinyin"].(string)
  12095. project.Pinyin = pinyin
  12096. wubi := projectM["wubi"].(string)
  12097. project.Wubi = wubi
  12098. statistical_classification := projectM["statistical_classification"].(string)
  12099. var statisticalClassification = "统计分类"
  12100. var statistical_classification_id int64
  12101. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12102. if len(statistical_classification) != 0 {
  12103. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12104. if classificationerrcodes == gorm.ErrRecordNotFound {
  12105. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12106. dataconfig := models.DictDataconfig{
  12107. ParentId: classiFication.ID,
  12108. Module: "system",
  12109. OrgId: orgId,
  12110. Name: statistical_classification,
  12111. FieldName: "",
  12112. Value: classiFicationConfig.Value + 1,
  12113. CreatedTime: "",
  12114. UpdatedTime: "",
  12115. CreateUserId: adminUser.AdminUser.Id,
  12116. Status: 1,
  12117. Remark: "",
  12118. DeleteIdSystem: 0,
  12119. Title: "",
  12120. Content: "",
  12121. Order: 0,
  12122. Code: "",
  12123. }
  12124. service.CreatedDicConfig(&dataconfig)
  12125. }
  12126. }
  12127. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12128. for _, it := range classiFicationList {
  12129. if statistical_classification == it.Name {
  12130. statistical_classification_id = int64(it.Value)
  12131. }
  12132. }
  12133. project.StatisticalClassification = statistical_classification_id
  12134. disease_directory := int64(projectM["disease_directory"].(float64))
  12135. project.DiseaseDirectory = disease_directory
  12136. is_record := int64(projectM["is_record"].(float64))
  12137. project.IsRecord = is_record
  12138. medical_code := projectM["medical_code"].(string)
  12139. project.MedicalCode = medical_code
  12140. tube_color := projectM["tube_color"].(string)
  12141. var tubeColor = "试管颜色"
  12142. var tube_color_id int64
  12143. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12144. if len(tube_color) != 0 {
  12145. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12146. if errcodetube == gorm.ErrRecordNotFound {
  12147. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12148. dataconfig := models.DictDataconfig{
  12149. ParentId: tubeColorConfig.ID,
  12150. Module: "system",
  12151. OrgId: orgId,
  12152. Name: tube_color,
  12153. FieldName: "",
  12154. Value: tubeConfig.Value + 1,
  12155. CreatedTime: "",
  12156. UpdatedTime: "",
  12157. CreateUserId: adminUser.AdminUser.Id,
  12158. Status: 1,
  12159. Remark: "",
  12160. DeleteIdSystem: 0,
  12161. Title: "",
  12162. Content: "",
  12163. Order: 0,
  12164. Code: "",
  12165. }
  12166. service.CreatedDicConfig(&dataconfig)
  12167. }
  12168. }
  12169. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12170. for _, it := range tubeColorList {
  12171. if tube_color == it.Name {
  12172. tube_color_id = int64(it.Value)
  12173. }
  12174. }
  12175. project.TubeColor = tube_color_id
  12176. single_dose := projectM["single_dose"].(string)
  12177. project.SingleDose = single_dose
  12178. execution_frequency := projectM["execution_frequency"].(string)
  12179. project.ExecutionFrequency = execution_frequency
  12180. delivery_way := projectM["delivery_way"].(string)
  12181. project.DeliveryWay = delivery_way
  12182. number_days := projectM["number_days"].(string)
  12183. project.NumberDays = number_days
  12184. total := projectM["total"].(string)
  12185. project.Total = total
  12186. medical_status := int64(projectM["medical_status"].(float64))
  12187. project.MedicalStatus = medical_status
  12188. category := int64(projectM["category"].(float64))
  12189. project.Category = category
  12190. specail_project := int64(projectM["specail_project"].(float64))
  12191. project.SpecailProject = specail_project
  12192. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12193. project.SocialSecurityDirectoryCode = social_security_directory_code
  12194. remark := projectM["remark"].(string)
  12195. project.Remark = remark
  12196. record_date := projectM["record_date"].(string)
  12197. timeLayout := "2006-01-02"
  12198. loc, _ := time.LoadLocation("Local")
  12199. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12200. project.RecordDate = theTime.Unix()
  12201. projectList = append(projectList, &project)
  12202. }
  12203. export_time := time.Now().Unix()
  12204. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12205. if len(projectList) > 0 {
  12206. for _, item := range projectList {
  12207. hans := item.ProjectName // 要转换的汉字字符串
  12208. // 创建一个拼音转换器
  12209. p := pinyin.NewArgs()
  12210. // 将汉字转为拼音
  12211. pinyinSlice := pinyin.Pinyin(hans, p)
  12212. // 输出拼音
  12213. fmt.Println("Pinyin:", pinyinSlice)
  12214. // 获取首字母
  12215. firstLetter := ""
  12216. for _, py := range pinyinSlice {
  12217. if len(py) > 0 {
  12218. firstLetter += string(py[0][0])
  12219. }
  12220. }
  12221. item.FirstLetter = firstLetter
  12222. project := models.HisProject{
  12223. ProjectName: item.ProjectName,
  12224. Price: item.Price,
  12225. Unit: item.Unit,
  12226. CostClassify: item.CostClassify,
  12227. ExecutiveSection: item.ExecutiveSection,
  12228. MedicalCoverage: item.MedicalCoverage,
  12229. UserOrgId: orgId,
  12230. Status: 1,
  12231. CreatedTime: time.Now().Unix(),
  12232. Pinyin: item.Pinyin,
  12233. Wubi: item.Wubi,
  12234. StatisticalClassification: item.StatisticalClassification,
  12235. DiseaseDirectory: item.DiseaseDirectory,
  12236. IsRecord: item.IsRecord,
  12237. MedicalCode: item.MedicalCode,
  12238. TubeColor: item.TubeColor,
  12239. SingleDose: item.SingleDose,
  12240. DeliveryWay: item.DeliveryWay,
  12241. NumberDays: item.NumberDays,
  12242. Total: item.Total,
  12243. Category: item.Category,
  12244. MedicalStatus: item.MedicalStatus,
  12245. SpecailProject: item.SpecailProject,
  12246. RecordDate: item.RecordDate,
  12247. Remark: item.Remark,
  12248. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12249. ExecutionFrequency: item.ExecutionFrequency,
  12250. FirstLetter: item.FirstLetter,
  12251. }
  12252. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12253. if errcodeproject == gorm.ErrRecordNotFound {
  12254. service.CreateProjectInfomation(&project)
  12255. } else if errcodeproject == nil {
  12256. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12257. }
  12258. log := models.ExportLog{
  12259. LogType: 6,
  12260. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12261. TotalNum: int64(len(total_goods)),
  12262. FailNum: int64(len(errLogs)),
  12263. SuccessNum: int64(len(projectList)),
  12264. CreateTime: time.Now().Unix(),
  12265. UpdateTime: time.Now().Unix(),
  12266. ExportTime: export_time,
  12267. Status: 1,
  12268. }
  12269. service.CreateExportLog(&log)
  12270. c.ServeSuccessJSON(map[string]interface{}{
  12271. "msg": "导入成功",
  12272. "total_num": len(total_goods),
  12273. "success_num": len(projectList),
  12274. "fail_num": int64(len(errLogs)),
  12275. })
  12276. }
  12277. } else {
  12278. log := models.ExportLog{
  12279. LogType: 6,
  12280. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12281. TotalNum: int64(len(total_goods)),
  12282. FailNum: int64(len(errLogs)),
  12283. SuccessNum: int64(len(projectList)),
  12284. CreateTime: time.Now().Unix(),
  12285. UpdateTime: time.Now().Unix(),
  12286. ExportTime: export_time,
  12287. Status: 1,
  12288. }
  12289. service.CreateExportLog(&log)
  12290. c.ServeSuccessJSON(map[string]interface{}{
  12291. "msg": "导入成功",
  12292. "total_num": len(total_goods),
  12293. "success_num": len(projectList),
  12294. "fail_num": int64(len(errLogs)),
  12295. })
  12296. }
  12297. }
  12298. //func (this *HisApiController) EditProjectInformation(){
  12299. //
  12300. // id, _ := this.GetInt64("id")
  12301. // project_team := this.GetString("project_team")
  12302. // price := this.GetString("price")
  12303. // price_float, _ := strconv.ParseFloat(price, 64)
  12304. // pinyin := this.GetString("pinyin")
  12305. // wubi := this.GetString("wubi")
  12306. // tube_color, _ := this.GetInt64("tube_color")
  12307. // team_type, _ := this.GetInt64("team_type")
  12308. // remark := this.GetString("remark")
  12309. // ids := this.GetString("ids")
  12310. // item_id := this.GetString("item_id")
  12311. // projectTeam := models.XtHisProjectTeam{
  12312. // ProjectTeam: project_team,
  12313. // Price: price_float,
  12314. // Pinyin: pinyin,
  12315. // Wubi: wubi,
  12316. // TubeColor: tube_color,
  12317. // TeamType: team_type,
  12318. // Remark: remark,
  12319. // ProjectId: ids,
  12320. // ItemId: item_id,
  12321. // }
  12322. //
  12323. //
  12324. // dataBody := make(map[string]interface{}, 0)
  12325. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12326. // if err != nil {
  12327. // utils.ErrorLog(err.Error())
  12328. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12329. // return
  12330. // }
  12331. //
  12332. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12333. //
  12334. //
  12335. // if err != nil {
  12336. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12337. // return
  12338. // }
  12339. //
  12340. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12341. // infos, _ := dataBody["info"].([]interface{})
  12342. // if len(infos) > 0 {
  12343. // var ids []string
  12344. //
  12345. // for _, item := range infos {
  12346. // items := item.(map[string]interface{})
  12347. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12348. // utils.ErrorLog("id")
  12349. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12350. // return
  12351. // }
  12352. // id := int64(items["id"].(float64))
  12353. //
  12354. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12355. // utils.ErrorLog("type")
  12356. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12357. // return
  12358. // }
  12359. // types := int64(items["type"].(float64))
  12360. //
  12361. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12362. // utils.ErrorLog("number")
  12363. // }
  12364. //
  12365. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12366. //
  12367. // projectList := models.XtHisProjectList{
  12368. // Number: number,
  12369. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12370. // ProjectId: id,
  12371. // Status: 1,
  12372. // CreatedTime: time.Now().Unix(),
  12373. // UpdatedTime: time.Now().Unix(),
  12374. // TeamId: projectTeam.ID,
  12375. // Type: types,
  12376. // }
  12377. // list := projectList
  12378. //
  12379. // service.CreateProjectList(&list)
  12380. //
  12381. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12382. //
  12383. // }
  12384. // ids_str := strings.Join(ids, ",")
  12385. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12386. // service.SaveProjectTeam(&projectTeam)
  12387. // this.ServeSuccessJSON(map[string]interface{}{
  12388. // "projectTeam": projectTeam,
  12389. // })
  12390. // }
  12391. // }
  12392. //}
  12393. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12394. name := c.GetString("name")
  12395. mode_id, _ := c.GetInt64("mode", 0)
  12396. types, _ := c.GetInt64("type", 0)
  12397. patient_id, _ := c.GetInt64("patient_id", 0)
  12398. types = 1
  12399. adminInfo := c.GetAdminUserInfo()
  12400. template := &models.HisPrescriptionTemplate{
  12401. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12402. PatientId: patient_id,
  12403. Type: types,
  12404. Status: 1,
  12405. Ctime: time.Now().Unix(),
  12406. Mtime: time.Now().Unix(),
  12407. Name: name,
  12408. Mode: mode_id,
  12409. }
  12410. dataBody := make(map[string]interface{}, 0)
  12411. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12412. if err != nil {
  12413. utils.ErrorLog(err.Error())
  12414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12415. return
  12416. }
  12417. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12418. //如果已经存在记录则删除处方
  12419. if template_one.ID > 0 {
  12420. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12421. var ids []int64
  12422. var org_id int64
  12423. for _, item := range ps {
  12424. org_id = c.GetAdminUserInfo().CurrentOrgId
  12425. ids = append(ids, item.ID)
  12426. }
  12427. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12428. if err2 == nil {
  12429. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12430. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12431. if len(prescriptions) > 0 {
  12432. for _, item := range prescriptions {
  12433. items := item.(map[string]interface{})
  12434. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12435. utils.ErrorLog("type")
  12436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12437. return
  12438. }
  12439. types := int64(items["type"].(float64))
  12440. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12441. utils.ErrorLog("med_type")
  12442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12443. return
  12444. }
  12445. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12446. ctime := time.Now().Unix()
  12447. prescription := &models.HisPrescriptionInfoTemplate{
  12448. PatientId: patient_id,
  12449. UserOrgId: adminInfo.CurrentOrgId,
  12450. Ctime: ctime,
  12451. Mtime: ctime,
  12452. Type: types,
  12453. Modifier: adminInfo.AdminUser.Id,
  12454. Creator: adminInfo.AdminUser.Id,
  12455. Status: 1,
  12456. PTemplateId: template_one.ID,
  12457. MedType: med_type,
  12458. }
  12459. service.CreateHisPrescriptionInfoTemplate(prescription)
  12460. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12461. advices := items["advices"].([]interface{})
  12462. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12463. ctime := time.Now().Unix()
  12464. mtime := ctime
  12465. if len(advices) > 0 {
  12466. for _, advice := range advices {
  12467. var s models.HisPrescriptionAdviceTemplate
  12468. s.PrescriptionId = prescription.ID
  12469. s.AdviceType = 2
  12470. s.StopState = 2
  12471. s.ExecutionState = 2
  12472. s.Status = 1
  12473. s.UserOrgId = adminInfo.CurrentOrgId
  12474. s.CreatedTime = ctime
  12475. s.UpdatedTime = mtime
  12476. s.PatientId = patient_id
  12477. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12478. if errcode > 0 {
  12479. c.ServeFailJSONWithSGJErrorCode(errcode)
  12480. return
  12481. }
  12482. service.CreateHisPrescriptionAdviceTemplate(&s)
  12483. }
  12484. }
  12485. }
  12486. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12487. projects := items["project"].([]interface{})
  12488. if len(projects) > 0 {
  12489. for _, project := range projects {
  12490. var p models.HisPrescriptionProjectTemplate
  12491. p.PrescriptionId = prescription.ID
  12492. p.Ctime = time.Now().Unix()
  12493. p.Mtime = time.Now().Unix()
  12494. p.PatientId = patient_id
  12495. p.UserOrgId = adminInfo.CurrentOrgId
  12496. p.Status = 1
  12497. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12498. if errcode > 0 {
  12499. c.ServeFailJSONWithSGJErrorCode(errcode)
  12500. return
  12501. }
  12502. service.CreateHisPrescriptionProjectTemplate(&p)
  12503. }
  12504. }
  12505. }
  12506. }
  12507. c.ServeSuccessJSON(map[string]interface{}{
  12508. "msg": "创建成功",
  12509. })
  12510. }
  12511. }
  12512. } else {
  12513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12514. return
  12515. }
  12516. } else {
  12517. err3 := service.CreateHisPrescriptionTemplate(template)
  12518. if err3 == nil {
  12519. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12520. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12521. if len(prescriptions) > 0 {
  12522. for _, item := range prescriptions {
  12523. items := item.(map[string]interface{})
  12524. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12525. utils.ErrorLog("type")
  12526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12527. return
  12528. }
  12529. types := int64(items["type"].(float64))
  12530. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12531. utils.ErrorLog("med_type")
  12532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12533. return
  12534. }
  12535. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12536. ctime := time.Now().Unix()
  12537. prescription := &models.HisPrescriptionInfoTemplate{
  12538. PatientId: patient_id,
  12539. UserOrgId: adminInfo.CurrentOrgId,
  12540. Ctime: ctime,
  12541. Mtime: ctime,
  12542. Type: types,
  12543. Modifier: adminInfo.AdminUser.Id,
  12544. Creator: adminInfo.AdminUser.Id,
  12545. Status: 1,
  12546. PTemplateId: template.ID,
  12547. MedType: med_type,
  12548. }
  12549. service.CreateHisPrescriptionInfoTemplate(prescription)
  12550. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12551. advices := items["advices"].([]interface{})
  12552. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12553. ctime := time.Now().Unix()
  12554. mtime := ctime
  12555. if len(advices) > 0 {
  12556. for _, advice := range advices {
  12557. var s models.HisPrescriptionAdviceTemplate
  12558. s.PrescriptionId = prescription.ID
  12559. s.AdviceType = 2
  12560. s.StopState = 2
  12561. s.ExecutionState = 2
  12562. s.Status = 1
  12563. s.UserOrgId = adminInfo.CurrentOrgId
  12564. s.CreatedTime = ctime
  12565. s.UpdatedTime = mtime
  12566. s.PatientId = patient_id
  12567. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12568. if errcode > 0 {
  12569. c.ServeFailJSONWithSGJErrorCode(errcode)
  12570. return
  12571. }
  12572. service.CreateHisPrescriptionAdviceTemplate(&s)
  12573. }
  12574. }
  12575. }
  12576. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12577. projects := items["project"].([]interface{})
  12578. if len(projects) > 0 {
  12579. for _, project := range projects {
  12580. var p models.HisPrescriptionProjectTemplate
  12581. p.PrescriptionId = prescription.ID
  12582. p.Ctime = time.Now().Unix()
  12583. p.Mtime = time.Now().Unix()
  12584. p.PatientId = patient_id
  12585. p.UserOrgId = adminInfo.CurrentOrgId
  12586. p.Status = 1
  12587. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12588. if errcode > 0 {
  12589. c.ServeFailJSONWithSGJErrorCode(errcode)
  12590. return
  12591. }
  12592. service.CreateHisPrescriptionProjectTemplate(&p)
  12593. }
  12594. }
  12595. }
  12596. }
  12597. c.ServeSuccessJSON(map[string]interface{}{
  12598. "msg": "创建成功",
  12599. })
  12600. }
  12601. }
  12602. } else {
  12603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12604. return
  12605. }
  12606. }
  12607. }
  12608. func (c *HisApiController) PreSettle() {
  12609. id, _ := c.GetInt64("id")
  12610. record_time := c.GetString("record_time")
  12611. his_patient_id, _ := c.GetInt64("his_patient_id")
  12612. timeLayout := "2006-01-02"
  12613. loc, _ := time.LoadLocation("Local")
  12614. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12615. diagnosis_id := c.GetString("diagnosis")
  12616. sick_type, _ := c.GetInt64("sick_type")
  12617. reg_type, _ := c.GetInt64("p_type")
  12618. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12619. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12620. if err != nil {
  12621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12622. return
  12623. }
  12624. recordDateTime := theTime.Unix()
  12625. adminUser := c.GetAdminUserInfo()
  12626. var prescriptions []*models.HisPrescription
  12627. var start_time int64
  12628. var end_time int64
  12629. ids_str := c.GetString("ids")
  12630. ids_arr := strings.Split(ids_str, ",")
  12631. fmt.Println(reg_type)
  12632. if settle_accounts_type == 1 { //日结
  12633. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12634. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12635. } else {
  12636. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12637. }
  12638. fmt.Println(prescriptions)
  12639. } else { //月结
  12640. start_time_str := c.GetString("start_time")
  12641. end_time_str := c.GetString("end_time")
  12642. timeLayout := "2006-01-02"
  12643. loc, _ := time.LoadLocation("Local")
  12644. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12645. if err != nil {
  12646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12647. return
  12648. }
  12649. recordStartTime := theStartTime.Unix()
  12650. start_time = recordStartTime
  12651. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12652. if err != nil {
  12653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12654. return
  12655. }
  12656. recordEndTime := theEndTime.Unix()
  12657. end_time = recordEndTime
  12658. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12659. }
  12660. if reg_type == 1111 || reg_type == 1112 {
  12661. reg_type = 11
  12662. }
  12663. timestamp := time.Now().Unix()
  12664. tempTime := time.Unix(timestamp, 0)
  12665. timeFormat := tempTime.Format("20060102150405")
  12666. chrgBchno := rand.Intn(100000) + 10000
  12667. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12668. strconv.FormatInt(his.PatientId, 10)
  12669. var ids []int64
  12670. for _, item := range prescriptions {
  12671. ids = append(ids, item.ID)
  12672. }
  12673. fmt.Println(ids)
  12674. var total float64
  12675. for _, item := range prescriptions {
  12676. fmt.Println(item)
  12677. if item.Type == 1 { //药品
  12678. for _, subItem := range item.HisDoctorAdviceInfo {
  12679. total = total + (subItem.Price * subItem.PrescribingNumber)
  12680. }
  12681. }
  12682. if item.Type == 2 { //项目
  12683. for _, subItem := range item.HisPrescriptionProject {
  12684. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12685. total = total + (subItem.Price * cnt)
  12686. }
  12687. }
  12688. for _, subItem := range item.HisAdditionalCharge {
  12689. total = total + (subItem.Price * float64(subItem.Count))
  12690. }
  12691. }
  12692. allTotal := fmt.Sprintf("%.2f", total)
  12693. totals, _ := strconv.ParseFloat(allTotal, 64)
  12694. order := &models.HisOrder{
  12695. UserOrgId: adminUser.CurrentOrgId,
  12696. HisPatientId: his.ID,
  12697. PatientId: id,
  12698. SettleAccountsDate: recordDateTime,
  12699. Ctime: time.Now().Unix(),
  12700. Mtime: time.Now().Unix(),
  12701. Status: 1,
  12702. OrderStatus: 1,
  12703. MdtrtId: his.Number,
  12704. Number: chrg_bchno,
  12705. MedfeeSumamt: totals,
  12706. SettleEndTime: end_time,
  12707. SettleStartTime: start_time,
  12708. SettleType: settle_accounts_type,
  12709. PsnPartAmt: totals,
  12710. PsnCashPay: totals,
  12711. PType: 2,
  12712. IsPre: 1,
  12713. MedType: strconv.Itoa(int(reg_type)),
  12714. Diagnosis: diagnosis_id,
  12715. }
  12716. err = service.CreateOrder(order)
  12717. if err != nil {
  12718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12719. return
  12720. }
  12721. var customs []*Custom
  12722. for _, item := range prescriptions {
  12723. fmt.Println(item.Type)
  12724. if item.Type == 1 { //药品
  12725. for _, subItem := range item.HisDoctorAdviceInfo {
  12726. cus := &Custom{
  12727. AdviceId: subItem.ID,
  12728. ProjectId: 0,
  12729. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12730. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12731. FeedetlSn: subItem.FeedetlSn,
  12732. Price: fmt.Sprintf("%.2f", subItem.Price),
  12733. MedListCodg: subItem.MedListCodg,
  12734. Type: 1,
  12735. }
  12736. customs = append(customs, cus)
  12737. }
  12738. }
  12739. if item.Type == 2 { //项目
  12740. for _, subItem := range item.HisPrescriptionProject {
  12741. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12742. cus := &Custom{
  12743. AdviceId: 0,
  12744. ProjectId: subItem.ID,
  12745. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12746. Cut: fmt.Sprintf("%.2f", cnt),
  12747. FeedetlSn: subItem.FeedetlSn,
  12748. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12749. MedListCodg: subItem.MedListCodg,
  12750. Type: 2,
  12751. }
  12752. customs = append(customs, cus)
  12753. }
  12754. }
  12755. for _, item := range item.HisAdditionalCharge {
  12756. cus := &Custom{
  12757. ItemId: item.ID,
  12758. AdviceId: 0,
  12759. ProjectId: 0,
  12760. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12761. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12762. FeedetlSn: item.FeedetlSn,
  12763. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12764. MedListCodg: item.XtHisAddtionConfig.Code,
  12765. Type: 3,
  12766. }
  12767. customs = append(customs, cus)
  12768. }
  12769. }
  12770. fmt.Println(customs)
  12771. for _, item := range customs {
  12772. var advice_id int64 = 0
  12773. var project_id int64 = 0
  12774. var item_id int64 = 0
  12775. var types int64 = 0
  12776. if item.Type == 1 {
  12777. advice_id = item.AdviceId
  12778. project_id = 0
  12779. item_id = 0
  12780. } else if item.Type == 2 {
  12781. advice_id = 0
  12782. item_id = 0
  12783. project_id = item.ProjectId
  12784. } else if item.Type == 3 {
  12785. advice_id = 0
  12786. item_id = item.ItemId
  12787. project_id = 0
  12788. }
  12789. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12790. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12791. pric, _ := strconv.ParseFloat(item.Price, 32)
  12792. info := &models.HisOrderInfo{
  12793. OrderNumber: order.Number,
  12794. UploadDate: time.Now().Unix(),
  12795. AdviceId: advice_id,
  12796. DetItemFeeSumamt: detItemFeeSumamt,
  12797. Cnt: cut,
  12798. Pric: pric,
  12799. PatientId: id,
  12800. Status: 1,
  12801. Mtime: time.Now().Unix(),
  12802. Ctime: time.Now().Unix(),
  12803. UserOrgId: adminUser.CurrentOrgId,
  12804. HisPatientId: his.ID,
  12805. OrderId: order.ID,
  12806. ProjectId: project_id,
  12807. Type: types,
  12808. ItemId: item_id,
  12809. }
  12810. service.CreateOrderInfo(info)
  12811. }
  12812. his.SickType = sick_type
  12813. service.UpdataHisPateint(&his)
  12814. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12815. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12816. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12817. if err == nil {
  12818. c.ServeSuccessJSON(map[string]interface{}{
  12819. "msg": "结算成功",
  12820. })
  12821. }
  12822. }
  12823. type CustomOrderInfo struct {
  12824. Name string
  12825. Spec string
  12826. Unit string
  12827. Count float64
  12828. Price float64
  12829. Total float64
  12830. }
  12831. func (c *HisApiController) GetPrivateExpensesInfo() {
  12832. order_id, _ := c.GetInt64("id", 0)
  12833. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12834. order, _ := service.GetHisOrderByID(order_id)
  12835. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12836. if order.ID == 0 {
  12837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12838. return
  12839. }
  12840. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12841. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12842. org_id := c.GetAdminUserInfo().CurrentOrgId
  12843. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12844. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12845. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12846. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12847. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12848. //var orderInfos_four []*models.HisOrderInfoTwo
  12849. //for _, item := range orderInfos_three {
  12850. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12851. // item.HisPrescriptionProject.IsCheckTeam = 1
  12852. // orderInfos_four = append(orderInfos_four, item)
  12853. //
  12854. // }
  12855. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12856. // item.HisPrescriptionProject.IsCheckTeam = 2
  12857. // orderInfos_two = append(orderInfos_two, item)
  12858. // }
  12859. //}
  12860. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12861. //var cus_slice []CustomOrderInfo
  12862. //for _, item := range new_order_info {
  12863. // var cus CustomOrderInfo
  12864. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12865. // cus.Unit = ""
  12866. // cus.Spec = ""
  12867. // var total float64
  12868. // for _, subItem := range orderInfos_four {
  12869. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12870. // total = total + subItem.DetItemFeeSumamt
  12871. // fmt.Println(subItem.DetItemFeeSumamt)
  12872. // }
  12873. // }
  12874. // cus.Count = 1
  12875. // cus.Total = total
  12876. // cus_slice = append(cus_slice, cus)
  12877. //}
  12878. orderInfos = append(orderInfos, orderInfos_two...)
  12879. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12880. //orderInfos = append(orderInfos, orderInfos_three...)
  12881. //}/**/
  12882. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12883. c.ServeSuccessJSON(map[string]interface{}{
  12884. "order": order,
  12885. "order_info": orderInfos,
  12886. "patient": patient,
  12887. "admin_info": adminInfo,
  12888. "his": his,
  12889. "current_admin": role,
  12890. "org_config": miConfig,
  12891. //"new_order_info": cus_slice,
  12892. })
  12893. }
  12894. func (this *HisApiController) ChangeMedType() {
  12895. med_type := this.GetString("med_type")
  12896. old_med_type := this.GetString("old_med_type")
  12897. ids := this.GetString("ids")
  12898. settle_type, _ := this.GetInt64("settle_type")
  12899. start_time := this.GetString("start_time")
  12900. end_time := this.GetString("end_time")
  12901. ids_arr := strings.Split(ids, ",")
  12902. if settle_type == 1 { //日结
  12903. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12904. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12905. prescription.MedType = med_type
  12906. err := service.SaveHisPrescriptionTwo(&prescription)
  12907. if err == nil {
  12908. this.ServeSuccessJSON(map[string]interface{}{
  12909. "msg": "修改成功",
  12910. })
  12911. } else {
  12912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12913. return
  12914. }
  12915. } else if settle_type == 2 {
  12916. timeLayout := "2006-01-02"
  12917. loc, _ := time.LoadLocation("Local")
  12918. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12919. if err != nil {
  12920. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12921. return
  12922. }
  12923. recordStartTime := theStartTime.Unix()
  12924. start_time_timestamp := recordStartTime
  12925. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12926. if err != nil {
  12927. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12928. return
  12929. }
  12930. recordEndTime := theEndTime.Unix()
  12931. end_time_timestamp := recordEndTime
  12932. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12933. if updateErr == nil {
  12934. this.ServeSuccessJSON(map[string]interface{}{
  12935. "msg": "修改成功",
  12936. })
  12937. } else {
  12938. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12939. return
  12940. }
  12941. }
  12942. }
  12943. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12944. patient_id, _ := c.GetInt64("patient_id")
  12945. his_patient_id, _ := c.GetInt64("his_patient_id")
  12946. record_date := c.GetString("record_date")
  12947. start_time := c.GetString("start_time")
  12948. end_time := c.GetString("end_time")
  12949. order_status, _ := c.GetInt64("type", 0)
  12950. p_type, _ := c.GetInt64("p_type", 0)
  12951. order_id, _ := c.GetInt64("order_id", 0)
  12952. timeLayout := "2006-01-02"
  12953. loc, _ := time.LoadLocation("Local")
  12954. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12955. if err != nil {
  12956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12957. return
  12958. }
  12959. recordDateTime := theTime.Unix()
  12960. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12961. if err != nil {
  12962. }
  12963. startRecordDateTime := startTime.Unix()
  12964. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12965. if err != nil {
  12966. }
  12967. endRecordDateTime := endTime.Unix()
  12968. admin := c.GetAdminUserInfo()
  12969. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12970. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12971. order, _ := service.GetHisOrderByID(order_id)
  12972. var monthPrescriptions []*models.HisPrescription
  12973. if order_status == 1 || order_status == 0 {
  12974. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12975. } else if order_status == 2 {
  12976. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12977. }
  12978. var settle_total float64
  12979. for _, item := range monthPrescriptions {
  12980. if len(item.HisPrescriptionProject) > 0 {
  12981. for _, subItem := range item.HisPrescriptionProject {
  12982. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12983. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12984. settle_total = settle_total + total
  12985. }
  12986. }
  12987. if len(item.HisDoctorAdviceInfo) > 0 {
  12988. for _, subItem := range item.HisDoctorAdviceInfo {
  12989. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12990. settle_total = settle_total + total
  12991. }
  12992. }
  12993. }
  12994. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12995. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12996. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12997. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12998. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12999. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13000. //获取所有科室信息
  13001. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13002. var dia string
  13003. for _, item := range month_p_info {
  13004. if len(dia) == 0 {
  13005. dia = item.Diagnosis
  13006. } else {
  13007. dia = dia + "," + item.Diagnosis
  13008. }
  13009. }
  13010. dia_arr := removeDuplicates(strings.Split(dia, ","))
  13011. dia_arr = removeEmptyStrings(dia_arr)
  13012. c.ServeSuccessJSON(map[string]interface{}{
  13013. "his_info": his_patient_info,
  13014. "xt_info": xt_patient_info,
  13015. "case_history": case_history,
  13016. "info": patientPrescriptionInfo,
  13017. "last_info": lastPatientPrescriptionInfo,
  13018. "month_prescriptions": monthPrescriptions,
  13019. "order": order,
  13020. "doctors": doctors,
  13021. "department": department,
  13022. "settle_total": settle_total,
  13023. "dia_arr": dia_arr,
  13024. })
  13025. return
  13026. }
  13027. func removeEmptyStrings(input []string) []string {
  13028. var output []string
  13029. for _, s := range input {
  13030. if s != "" {
  13031. output = append(output, s)
  13032. }
  13033. }
  13034. return output
  13035. }
  13036. func removeDuplicates(input []string) []string {
  13037. seen := make(map[string]bool)
  13038. output := []string{}
  13039. for _, s := range input {
  13040. if _, exists := seen[s]; !exists {
  13041. seen[s] = true
  13042. output = append(output, s)
  13043. }
  13044. }
  13045. return output
  13046. }
  13047. func (c *HisApiController) GetHisMonthPatientInfo() {
  13048. patient_id, _ := c.GetInt64("patient_id")
  13049. his_patient_id, _ := c.GetInt64("his_patient_id")
  13050. record_date := c.GetString("record_date")
  13051. number := c.GetString("number")
  13052. start_time := c.GetString("start_time")
  13053. end_time := c.GetString("end_time")
  13054. p_type, _ := c.GetInt64("p_type")
  13055. timeLayout := "2006-01-02"
  13056. loc, _ := time.LoadLocation("Local")
  13057. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13058. if err != nil {
  13059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13060. return
  13061. }
  13062. recordDateTime := theTime.Unix()
  13063. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13064. if err != nil {
  13065. }
  13066. startRecordDateTime := startTime.Unix()
  13067. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13068. if err != nil {
  13069. }
  13070. endRecordDateTime := endTime.Unix()
  13071. admin := c.GetAdminUserInfo()
  13072. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  13073. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  13074. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  13075. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  13076. var settle_total float64
  13077. for _, item := range monthPrescriptions {
  13078. if len(item.HisPrescriptionProject) > 0 {
  13079. for _, subItem := range item.HisPrescriptionProject {
  13080. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13081. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13082. settle_total = settle_total + total
  13083. }
  13084. }
  13085. if len(item.HisDoctorAdviceInfo) > 0 {
  13086. for _, subItem := range item.HisDoctorAdviceInfo {
  13087. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13088. settle_total = settle_total + total
  13089. }
  13090. }
  13091. }
  13092. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13093. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13094. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13095. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13096. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13097. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13098. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13099. //获取所有科室信息
  13100. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13101. c.ServeSuccessJSON(map[string]interface{}{
  13102. "his_info": his_patient_info,
  13103. "xt_info": xt_patient_info,
  13104. "case_history": case_history,
  13105. "info": patientPrescriptionInfo,
  13106. "month_prescriptions": monthPrescriptions,
  13107. "order": order,
  13108. "doctors": doctors,
  13109. "department": department,
  13110. "count": count,
  13111. "drugStockConfig": drugStockConfig,
  13112. "last_info": lastPatientPrescriptionInfo,
  13113. "settle_total": settle_total,
  13114. })
  13115. return
  13116. }
  13117. func (c *HisApiController) GetAllOrder() {
  13118. org_id := c.GetAdminUserInfo().CurrentOrgId
  13119. orders, _ := service.GetNewHisOrderList(org_id)
  13120. c.ServeSuccessJSON(map[string]interface{}{
  13121. "order": orders,
  13122. })
  13123. return
  13124. }
  13125. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13126. newArr = make([]*models.HisOrderInfoTwo, 0)
  13127. for i := 0; i < len(arr); i++ {
  13128. repeat := false
  13129. for j := i + 1; j < len(arr); j++ {
  13130. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13131. repeat = true
  13132. break
  13133. }
  13134. }
  13135. if !repeat {
  13136. newArr = append(newArr, arr[i])
  13137. }
  13138. }
  13139. return
  13140. }
  13141. // 修改处方退库操作 参数传修改之前的处方数据
  13142. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13143. if advice.ExecutionState == 1 {
  13144. //查询该病人该药品是否有库存记录
  13145. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13146. if errcode == gorm.ErrRecordNotFound {
  13147. } else {
  13148. //退库
  13149. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13150. if advice.PrescribingNumberUnit == drug.MinUnit {
  13151. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13152. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13153. //退库
  13154. warehouseInfo := models.DrugWarehouseInfo{
  13155. StockMinNumber: prescribingNumber,
  13156. }
  13157. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13158. operation_time := time.Now().Unix()
  13159. creater := advice.AdviceDoctor
  13160. ctime := time.Now().Unix()
  13161. timeStr := time.Now().Format("2006-01-02")
  13162. timeArr := strings.Split(timeStr, "-")
  13163. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13164. total = total + 1
  13165. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13166. cancelStock := models.DrugCancelStock{
  13167. OrderNumber: orderNumber,
  13168. OperaTime: operation_time,
  13169. OrgId: advice.UserOrgId,
  13170. Creater: creater,
  13171. Ctime: ctime,
  13172. Status: 1,
  13173. ReturnTime: advice.AdviceDate,
  13174. Dealer: info.Dealer,
  13175. Manufacturer: info.Manufacturer,
  13176. Type: 1,
  13177. }
  13178. service.AddSigleDrugCancelStock(&cancelStock)
  13179. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13180. dealer, _ := service.GetDealerById(info.Dealer)
  13181. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13182. cancelStockInfo := models.DrugCancelStockInfo{
  13183. OrderNumber: cancelInfo.OrderNumber,
  13184. CancelStockId: cancelInfo.ID,
  13185. DrugId: info.DrugId,
  13186. Count: info.Count,
  13187. Status: 1,
  13188. Ctime: ctime,
  13189. OrgId: advice.UserOrgId,
  13190. Type: 1,
  13191. Manufacturer: manufactureName.ManufacturerName,
  13192. Dealer: dealer.DealerName,
  13193. Total: 0,
  13194. RetailPrice: info.RetailPrice,
  13195. RetailTotalPrice: info.RetailTotalPrice,
  13196. Price: info.Price,
  13197. RegisterAccount: "",
  13198. Remark: info.Remark,
  13199. BatchNumber: info.BatchNumber,
  13200. MaxUnit: info.CountUnit,
  13201. ProductDate: info.ProductDate,
  13202. ExpiryDate: info.ExpiryDate,
  13203. BatchNumberId: info.WarehouseInfoId,
  13204. }
  13205. flow := models.DrugFlow{
  13206. WarehousingId: 0,
  13207. DrugId: info.DrugId,
  13208. Number: "",
  13209. BatchNumber: info.BatchNumber,
  13210. Count: info.Count,
  13211. UserOrgId: advice.UserOrgId,
  13212. PatientId: 0,
  13213. SystemTime: ctime,
  13214. ConsumableType: 4,
  13215. IsSys: 0,
  13216. WarehousingOrder: "",
  13217. WarehouseOutId: 0,
  13218. WarehouseOutOrderNumber: "",
  13219. IsEdit: 0,
  13220. CancelStockId: cancelStock.ID,
  13221. CancelOrderNumber: cancelStock.OrderNumber,
  13222. Manufacturer: info.Manufacturer,
  13223. Dealer: info.Dealer,
  13224. Creator: advice.UserOrgId,
  13225. UpdateCreator: 0,
  13226. Status: 1,
  13227. Ctime: time.Now().Unix(),
  13228. Mtime: 0,
  13229. Price: info.Price,
  13230. WarehousingDetailId: 0,
  13231. WarehouseOutDetailId: 0,
  13232. CancelOutDetailId: 0,
  13233. ExpireDate: info.ExpiryDate,
  13234. ProductDate: info.ProductDate,
  13235. MaxUnit: info.CountUnit,
  13236. MinUnit: "",
  13237. }
  13238. service.CreatedCancelStock(cancelStockInfo)
  13239. service.CreateDrugFlowOne(flow)
  13240. } else {
  13241. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13242. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13243. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13244. warehouseInfo := models.DrugWarehouseInfo{
  13245. StockMinNumber: prescribingNumber,
  13246. }
  13247. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13248. }
  13249. operation_time := time.Now().Unix()
  13250. creater := advice.AdviceDoctor
  13251. ctime := time.Now().Unix()
  13252. timeStr := time.Now().Format("2006-01-02")
  13253. timeArr := strings.Split(timeStr, "-")
  13254. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13255. total = total + 1
  13256. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13257. cancelStock := models.DrugCancelStock{
  13258. OrderNumber: orderNumber,
  13259. OperaTime: operation_time,
  13260. OrgId: advice.UserOrgId,
  13261. Creater: creater,
  13262. Ctime: ctime,
  13263. Status: 1,
  13264. ReturnTime: advice.AdviceDate,
  13265. Dealer: info.Dealer,
  13266. Manufacturer: info.Manufacturer,
  13267. Type: 1,
  13268. }
  13269. service.AddSigleDrugCancelStock(&cancelStock)
  13270. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13271. dealer, _ := service.GetDealerById(info.Dealer)
  13272. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13273. cancelStockInfo := models.DrugCancelStockInfo{
  13274. OrderNumber: cancelInfo.OrderNumber,
  13275. CancelStockId: cancelInfo.ID,
  13276. DrugId: info.DrugId,
  13277. Count: info.Count,
  13278. Status: 1,
  13279. Ctime: ctime,
  13280. OrgId: advice.UserOrgId,
  13281. Type: 1,
  13282. Manufacturer: manufactureName.ManufacturerName,
  13283. Dealer: dealer.DealerName,
  13284. Total: 0,
  13285. RetailPrice: info.RetailPrice,
  13286. RetailTotalPrice: info.RetailTotalPrice,
  13287. Price: info.Price,
  13288. RegisterAccount: "",
  13289. Remark: info.Remark,
  13290. BatchNumber: info.BatchNumber,
  13291. MaxUnit: info.CountUnit,
  13292. ProductDate: info.ProductDate,
  13293. ExpiryDate: info.ExpiryDate,
  13294. BatchNumberId: info.WarehouseInfoId,
  13295. }
  13296. flow := models.DrugFlow{
  13297. WarehousingId: 0,
  13298. DrugId: info.DrugId,
  13299. Number: "",
  13300. BatchNumber: info.BatchNumber,
  13301. Count: info.Count,
  13302. UserOrgId: advice.UserOrgId,
  13303. PatientId: 0,
  13304. SystemTime: ctime,
  13305. ConsumableType: 4,
  13306. IsSys: 0,
  13307. WarehousingOrder: "",
  13308. WarehouseOutId: 0,
  13309. WarehouseOutOrderNumber: "",
  13310. IsEdit: 0,
  13311. CancelStockId: cancelStock.ID,
  13312. CancelOrderNumber: cancelStock.OrderNumber,
  13313. Manufacturer: info.Manufacturer,
  13314. Dealer: info.Dealer,
  13315. Creator: advice.AdviceDoctor,
  13316. UpdateCreator: 0,
  13317. Status: 1,
  13318. Ctime: time.Now().Unix(),
  13319. Mtime: 0,
  13320. Price: info.Price,
  13321. WarehousingDetailId: 0,
  13322. WarehouseOutDetailId: 0,
  13323. CancelOutDetailId: 0,
  13324. ExpireDate: info.ExpiryDate,
  13325. ProductDate: info.ProductDate,
  13326. MaxUnit: info.CountUnit,
  13327. MinUnit: "",
  13328. }
  13329. service.CreatedCancelStock(cancelStockInfo)
  13330. service.CreateDrugFlowOne(flow)
  13331. }
  13332. }
  13333. }
  13334. return err
  13335. }
  13336. func (this *HisApiController) DeleteNCDS() {
  13337. id, _ := this.GetInt64("id", 0)
  13338. if id > 0 {
  13339. service.DeletePsnNCDSRecordById(id)
  13340. this.ServeSuccessJSON(map[string]interface{}{
  13341. "msg": "删除成功",
  13342. })
  13343. } else {
  13344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13345. return
  13346. }
  13347. }
  13348. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13349. id, _ := c.GetInt64("id")
  13350. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13351. c.ServeSuccessJSON(map[string]interface{}{
  13352. "advice": advice,
  13353. })
  13354. return
  13355. }
  13356. func (c *HisApiController) GetHisMonthChargePatientList() {
  13357. record_date := c.GetString("record_date")
  13358. start_time := c.GetString("start_time")
  13359. end_time := c.GetString("end_time")
  13360. timeLayout := "2006-01-02"
  13361. loc, _ := time.LoadLocation("Local")
  13362. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13363. if err != nil {
  13364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13365. return
  13366. }
  13367. if err != nil {
  13368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13369. return
  13370. }
  13371. recordDateTime := theTime.Unix()
  13372. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13373. if err != nil {
  13374. }
  13375. startRecordDateTime := startTime.Unix()
  13376. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13377. if err != nil {
  13378. }
  13379. endRecordDateTime := endTime.Unix()
  13380. adminInfo := c.GetAdminUserInfo()
  13381. var tempMonthChargePatients []*service.MonthChargePatients
  13382. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13383. for _, item := range tempPatients {
  13384. //过滤没有处方的
  13385. if len(item.HisPrescription) == 0 {
  13386. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13387. }
  13388. }
  13389. c.ServeSuccessJSON(map[string]interface{}{
  13390. "list": tempMonthChargePatients,
  13391. })
  13392. }
  13393. // PrescriptionDifference 医嘱数量差值结构体
  13394. type PrescriptionDrugDifference struct {
  13395. DrugID int64 //基础库药品id
  13396. ID int64 //医嘱id
  13397. Difference float64 //差值
  13398. Unit string //单位
  13399. }
  13400. type PrescriptionGoodDifference struct {
  13401. GoodID int64 //基础库项目耗材id
  13402. ID int64 //医嘱id
  13403. Difference int64 //差值
  13404. Unit string //单位
  13405. Type int64 //类型
  13406. }
  13407. type EditCustomData struct {
  13408. adviceList []*models.HisDoctorAdviceInfo
  13409. projectList []*models.HisPrescriptionProject
  13410. }
  13411. type SrcCustomData struct {
  13412. adviceList []*models.HisDoctorAdviceInfo
  13413. projectList []*models.HisPrescriptionProject
  13414. }
  13415. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13416. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13417. differences := make([]*PrescriptionDrugDifference, 0)
  13418. // 创建一个 map 来存储第一个切片中的药品信息
  13419. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13420. for _, advice := range firstPrescription {
  13421. firstMap[advice.DrugId] = advice
  13422. }
  13423. // 遍历第二个切片中的药品信息,并比较数量差值
  13424. for _, advice := range secondPrescription {
  13425. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13426. diff := &PrescriptionDrugDifference{
  13427. DrugID: advice.DrugId,
  13428. ID: firstAdvice.ID,
  13429. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13430. Unit: firstAdvice.PrescribingNumberUnit,
  13431. }
  13432. differences = append(differences, diff)
  13433. }
  13434. }
  13435. return differences
  13436. }
  13437. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13438. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13439. differences := make([]*PrescriptionGoodDifference, 0)
  13440. // 创建一个 map 来存储第一个切片中的耗材信息
  13441. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13442. for _, good := range firstPrescription {
  13443. firstMap[good.ProjectId] = good
  13444. }
  13445. // 遍历第二个切片中的耗材信息,并比较数量差值
  13446. for _, good := range secondPrescription {
  13447. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13448. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13449. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13450. diff := &PrescriptionGoodDifference{
  13451. GoodID: good.ProjectId,
  13452. ID: firstGood.ID,
  13453. Difference: count - firstCount,
  13454. Unit: firstGood.Unit,
  13455. Type: firstGood.Type,
  13456. }
  13457. differences = append(differences, diff)
  13458. }
  13459. }
  13460. return differences
  13461. }
  13462. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13463. var adviceList []*models.HisDoctorAdviceInfo
  13464. var projectList []*models.HisPrescriptionProject
  13465. var advice_ids []int64
  13466. var project_ids []int64
  13467. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13468. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13469. //var tempPrescription *models.HisPrescriptionProjectscription
  13470. if len(prescriptions) > 0 {
  13471. for _, item := range prescriptions {
  13472. items := item.(map[string]interface{})
  13473. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13474. advices := items["advices"].([]interface{})
  13475. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13476. groupNo := int64(0)
  13477. ctime := time.Now().Unix()
  13478. mtime := ctime
  13479. if len(advices) > 0 {
  13480. for _, advice := range advices {
  13481. var s models.HisDoctorAdviceInfo
  13482. s.AdviceType = 2
  13483. s.StopState = 2
  13484. s.ExecutionState = 2
  13485. s.Status = 1
  13486. s.Groupno = groupNo
  13487. s.CreatedTime = ctime
  13488. s.UpdatedTime = mtime
  13489. s.IsSettle = 2
  13490. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13491. //存储切片中
  13492. if s.ID > 0 {
  13493. advice_ids = append(advice_ids, s.ID)
  13494. adviceList = append(adviceList, &s)
  13495. }
  13496. }
  13497. }
  13498. }
  13499. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13500. projects := items["project"].([]interface{})
  13501. if len(projects) > 0 {
  13502. for _, project := range projects {
  13503. var p models.HisPrescriptionProject
  13504. p.Ctime = time.Now().Unix()
  13505. p.Mtime = time.Now().Unix()
  13506. p.Status = 1
  13507. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13508. if p.ID > 0 {
  13509. project_ids = append(project_ids, p.ID)
  13510. projectList = append(projectList, &p)
  13511. }
  13512. }
  13513. }
  13514. }
  13515. }
  13516. }
  13517. }
  13518. editCustomData.projectList = projectList
  13519. editCustomData.adviceList = adviceList
  13520. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13521. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13522. srcCustomData.adviceList = list
  13523. srcCustomData.projectList = list2
  13524. return
  13525. }
  13526. func (c *HisApiController) GetAllGoodInforList() {
  13527. orgId := c.GetAdminUserInfo().CurrentOrgId
  13528. goodList, _ := service.GetAllGoodList(orgId)
  13529. c.ServeSuccessJSON(map[string]interface{}{
  13530. "goodList": goodList,
  13531. })
  13532. return
  13533. }
  13534. func (this *HisApiController) SaveGoodList() {
  13535. project_name := this.GetString("project_name")
  13536. sort, _ := this.GetInt64("sort")
  13537. orgId := this.GetAdminUserInfo().CurrentOrgId
  13538. dataBody := make(map[string]interface{}, 0)
  13539. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13540. if err != nil {
  13541. utils.ErrorLog(err.Error())
  13542. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13543. return
  13544. }
  13545. goodTeam := models.XtGoodTeam{
  13546. ProjectName: project_name,
  13547. Sort: sort,
  13548. UserOrgId: orgId,
  13549. Status: 1,
  13550. Ctime: time.Now().Unix(),
  13551. Mtime: time.Now().Unix(),
  13552. }
  13553. service.CreateGoodTeam(goodTeam)
  13554. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13555. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13556. infos, _ := dataBody["info"].([]interface{})
  13557. if len(infos) > 0 {
  13558. for _, item := range infos {
  13559. items := item.(map[string]interface{})
  13560. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13561. utils.ErrorLog("good_id")
  13562. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13563. return
  13564. }
  13565. good_id := int64(items["good_id"].(float64))
  13566. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13567. utils.ErrorLog("number")
  13568. }
  13569. number := int64(items["number"].(float64))
  13570. xtGoodTeamList := models.XtGoodTeamList{
  13571. GoodId: good_id,
  13572. Count: number,
  13573. TeamId: lastGoodTeam.ID,
  13574. UserOrgId: orgId,
  13575. Status: 1,
  13576. Ctime: time.Now().Unix(),
  13577. Mtime: time.Now().Unix(),
  13578. }
  13579. service.CreateGoodList(xtGoodTeamList)
  13580. }
  13581. this.ServeSuccessJSON(map[string]interface{}{
  13582. "lastGoodTeam": lastGoodTeam,
  13583. })
  13584. }
  13585. }
  13586. return
  13587. }
  13588. func (this *HisApiController) GetGoodList() {
  13589. orgId := this.GetAdminUserInfo().CurrentOrgId
  13590. limit, _ := this.GetInt64("limit")
  13591. page, _ := this.GetInt64("page")
  13592. keyword := this.GetString("keyword")
  13593. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13594. this.ServeSuccessJSON(map[string]interface{}{
  13595. "list": list,
  13596. "total": total,
  13597. })
  13598. }
  13599. func (this *HisApiController) GetGoodNameDetail() {
  13600. id, _ := this.GetInt64("id")
  13601. orgId := this.GetAdminUserInfo().CurrentOrgId
  13602. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13603. goodList, _ := service.GetAllGoodList(orgId)
  13604. this.ServeSuccessJSON(map[string]interface{}{
  13605. "goodNameDetail": goodNameDetail,
  13606. "goodList": goodList,
  13607. })
  13608. }
  13609. func (this *HisApiController) UpdateGoodList() {
  13610. project_name := this.GetString("project_name")
  13611. sort, _ := this.GetInt64("sort")
  13612. id, _ := this.GetInt64("id")
  13613. orgId := this.GetAdminUserInfo().CurrentOrgId
  13614. dataBody := make(map[string]interface{}, 0)
  13615. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13616. if err != nil {
  13617. utils.ErrorLog(err.Error())
  13618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13619. return
  13620. }
  13621. goodTeam := models.XtGoodTeam{
  13622. ProjectName: project_name,
  13623. Sort: sort,
  13624. UserOrgId: orgId,
  13625. Status: 1,
  13626. Ctime: time.Now().Unix(),
  13627. Mtime: time.Now().Unix(),
  13628. ID: id,
  13629. }
  13630. service.SaveGoodTeam(goodTeam)
  13631. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13632. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13633. infos, _ := dataBody["info"].([]interface{})
  13634. if len(infos) > 0 {
  13635. for _, item := range infos {
  13636. items := item.(map[string]interface{})
  13637. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13638. utils.ErrorLog("good_id")
  13639. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13640. return
  13641. }
  13642. good_id := int64(items["good_id"].(float64))
  13643. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13644. utils.ErrorLog("id")
  13645. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13646. return
  13647. }
  13648. id := int64(items["id"].(float64))
  13649. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13650. utils.ErrorLog("number")
  13651. }
  13652. number := int64(items["number"].(float64))
  13653. xtGoodTeamList := models.XtGoodTeamList{
  13654. ID: id,
  13655. GoodId: good_id,
  13656. Count: number,
  13657. TeamId: lastGoodTeam.ID,
  13658. UserOrgId: orgId,
  13659. Status: 1,
  13660. Ctime: time.Now().Unix(),
  13661. Mtime: time.Now().Unix(),
  13662. }
  13663. service.SaveGoodList(xtGoodTeamList)
  13664. }
  13665. this.ServeSuccessJSON(map[string]interface{}{
  13666. "lastGoodTeam": lastGoodTeam,
  13667. })
  13668. }
  13669. }
  13670. return
  13671. }
  13672. func (this *HisApiController) DeleteGoodTeam() {
  13673. id, _ := this.GetInt64("id")
  13674. team, _ := service.DeleteGoodTeam(id)
  13675. this.ServeSuccessJSON(map[string]interface{}{
  13676. "team": team,
  13677. })
  13678. }
  13679. func (this *HisApiController) DeleteGood() {
  13680. id, _ := this.GetInt64("id")
  13681. good, _ := service.DeleteGood(id)
  13682. this.ServeSuccessJSON(map[string]interface{}{
  13683. "good": good,
  13684. })
  13685. }