his_api_controller.go 557KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "band_card_pay":
  229. order.BandCardPay = desc
  230. break
  231. case "ali_pay":
  232. order.AliPay = desc
  233. break
  234. case "wechat_pay":
  235. order.WechatPay = desc
  236. break
  237. case "fa_piao_number":
  238. order.FaPiaoNumber = desc
  239. break
  240. case "fa_piao_code":
  241. order.FaPiaoCode = desc
  242. break
  243. }
  244. err := service.SaveHisOrder(&order)
  245. if err == nil {
  246. c.ServeSuccessJSON(map[string]interface{}{
  247. "msg": "修改成功",
  248. })
  249. return
  250. } else {
  251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  252. return
  253. }
  254. }
  255. func (c *HisApiController) GetMonthHisPatient() {
  256. record_date := c.GetString("record_date")
  257. //order_status, _ := c.GetInt64("type")
  258. timeLayout := "2006-01-02"
  259. loc, _ := time.LoadLocation("Local")
  260. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  261. if err != nil {
  262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  263. return
  264. }
  265. recordDateTime := theTime.Unix()
  266. adminInfo := c.GetAdminUserInfo()
  267. var tempPatients []service.NewTempPatients
  268. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  269. // 获取当前时间
  270. now := time.Now()
  271. // 获取本月的第一天
  272. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  273. // 获取下个月的第一天
  274. nextMonth := firstDay.AddDate(0, 1, 0)
  275. // 获取本月的最后一天
  276. lastDay := nextMonth.Add(-time.Nanosecond)
  277. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  278. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  279. var patients []service.NewTempPatients
  280. var patients_two []service.NewTempPatients
  281. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  282. for _, item := range tempPatients {
  283. //过滤掉没挂号的和没开处方的
  284. if len(item.HisPrescription) > 0 {
  285. patients = append(patients, item)
  286. patients_two = append(patients_two, item)
  287. }
  288. ////过滤掉没挂号的
  289. //if len(item.HisPatient) > 0 {
  290. //}
  291. }
  292. } else {
  293. for _, item := range tempPatients {
  294. //过滤掉没挂号的和没开处方的
  295. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  296. patients = append(patients, item)
  297. }
  298. ////过滤掉没挂号的
  299. //if len(item.HisPatient) > 0 {
  300. // patients_two = append(patients_two, item)
  301. //}
  302. }
  303. }
  304. c.ServeSuccessJSON(map[string]interface{}{
  305. "list": patients,
  306. "list_two": patients_two,
  307. "chargePatients": chargePatients,
  308. })
  309. }
  310. func (c *HisApiController) GetBatchSettleAccounts() {
  311. order_ids := c.GetString("order_ids")
  312. admin_user_id, _ := c.GetInt64("admin_user_id")
  313. adminUser := c.GetAdminUserInfo()
  314. orders := strings.Split(order_ids, ",")
  315. var newOrders []models.Orders
  316. for _, item := range orders {
  317. order, _ := service.GetHisOrderByIDTenOne(item)
  318. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  319. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  320. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  321. orderInfos = append(orderInfos, orderInfos_two...)
  322. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  323. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  324. var diagnosis_ids []string
  325. if his.ID > 0 {
  326. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  327. } else {
  328. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  329. }
  330. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  331. var dia_config []*models.HisXtDiagnoseConfig
  332. var name string
  333. for _, item := range diagnosis_ids {
  334. id, _ := strconv.ParseInt(item, 10, 64)
  335. diagnosisConfig, _ := service.FindDiagnoseById(id)
  336. dia_config = append(dia_config, diagnosisConfig)
  337. if len(name) == 0 {
  338. name = diagnosisConfig.ClassName
  339. } else {
  340. name = name + "," + diagnosisConfig.ClassName
  341. }
  342. }
  343. var bedCostTotal float64 = 0 //床位总费
  344. var bedCostSelfTotal float64 = 0 //床位自费
  345. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  346. var bedSelfTotal float64 = 0 //床位部分项目自费
  347. var bedInscpTotal float64 = 0 //床位部分项目自费
  348. var operationCostTotal float64 = 0 //手术费
  349. var operationCostSelfTotal float64 = 0 //手术费
  350. var operationCostPartSelfTotal float64 = 0 //手术费
  351. var operationSelfTotal float64 = 0 //床位部分项目自费
  352. var operationInscpTotal float64 = 0 //床位部分项目自费
  353. var otherCostTotal float64 = 0 //其他费用
  354. var otherCostSelfTotal float64 = 0 //其他费用
  355. var otherCostPartSelfTotal float64 = 0 //其他费用
  356. var otherSelfTotal float64 = 0 //床位部分项目自费
  357. var otherInscpTotal float64 = 0 //床位部分项目自费
  358. var materialCostTotal float64 = 0 //材料费
  359. var materialCostSelfTotal float64 = 0 //材料费
  360. var materialCostPartSelfTotal float64 = 0 //材料费
  361. var materialSelfTotal float64 = 0 //床位部分项目自费
  362. var materialInscpTotal float64 = 0 //床位部分项目自费
  363. var westernMedicineCostTotal float64 = 0 //西药费
  364. var westernMedicineCostSelfTotal float64 = 0 //西药费
  365. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  366. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  367. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  368. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  369. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  370. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  371. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  372. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  373. var checkCostTotal float64 = 0 //检查费
  374. var checkCostSelfTotal float64 = 0 //检查费
  375. var checkCostPartSelfTotal float64 = 0 //检查费
  376. var checkSelfTotal float64 = 0 //床位部分项目自费
  377. var checkInscpTotal float64 = 0 //床位部分项目自费
  378. var laboratoryCostTotal float64 = 0 //化验费
  379. var laboratoryCostSelfTotal float64 = 0 //化验费
  380. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  381. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  382. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  383. var treatCostTotal float64 = 0 //治疗费用
  384. var treatCostSelfTotal float64 = 0 //治疗费用
  385. var treatCostPartSelfTotal float64 = 0 //治疗费用
  386. var treatSelfTotal float64 = 0 //床位部分项目自费
  387. var treatInscpTotal float64 = 0 //床位部分项目自费
  388. decimal.DivisionPrecision = 2
  389. for _, item := range orderInfos {
  390. if item.MedChrgitmType == "01" { //床位费
  391. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  392. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  393. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  394. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  395. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  396. }
  397. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  398. if item.MedChrgitmType == "03" { //检查费
  399. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  400. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  401. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  402. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  403. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  404. }
  405. } else {
  406. if item.MedChrgitmType == "03" { //检查费
  407. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  408. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  409. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  410. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  411. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  412. }
  413. }
  414. if item.MedChrgitmType == "04" { //化验费
  415. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "05" { //治疗费
  422. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "06" { //手术费
  429. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  436. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "09" { //西药费
  443. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "11" { //中成费
  450. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  457. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  458. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  459. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  460. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  461. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  462. }
  463. }
  464. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  465. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  466. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  467. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  468. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. var doctor_name string
  470. if roles.ID == 0 {
  471. doctor_name = "管理员"
  472. } else {
  473. doctor_name = roles.UserName
  474. }
  475. yiliao_leibie := ""
  476. switch order.MedType {
  477. case "11":
  478. yiliao_leibie = "普通门诊"
  479. break
  480. case "12":
  481. yiliao_leibie = "门诊挂号"
  482. break
  483. case "13":
  484. yiliao_leibie = "急诊"
  485. break
  486. case "14":
  487. yiliao_leibie = "门诊特殊病"
  488. break
  489. case "15":
  490. yiliao_leibie = "门诊统筹"
  491. break
  492. case "16":
  493. yiliao_leibie = "门诊慢性病"
  494. break
  495. case "21":
  496. yiliao_leibie = "普通住院"
  497. break
  498. }
  499. var newOrder models.Orders
  500. newOrder.Diagnosis = name
  501. newOrder.OrderInfos = orderInfos
  502. newOrder.Number = order.MdtrtId
  503. newOrder.Date = order.SettleAccountsDate
  504. newOrder.ChargeAdmin = charge_admin
  505. newOrder.PrintorAdmin = printor_admin
  506. newOrder.Order = order
  507. newOrder.BedCostTotal = bedCostTotal
  508. newOrder.BedCostSelfTotal = bedCostSelfTotal
  509. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  510. newOrder.BedSelfTotal = bedSelfTotal
  511. newOrder.BedInscpTotal = bedInscpTotal
  512. newOrder.OperationCostTotal = operationCostTotal
  513. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  514. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  515. newOrder.OperationSelfTotal = operationSelfTotal
  516. newOrder.OperationInscpTotal = operationInscpTotal
  517. newOrder.OtherCostTotal = otherCostTotal
  518. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  519. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  520. newOrder.OtherSelfTotal = otherSelfTotal
  521. newOrder.OtherInscpTotal = otherInscpTotal
  522. newOrder.MaterialCostTotal = materialCostTotal
  523. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  524. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  525. newOrder.MaterialSelfTotal = materialSelfTotal
  526. newOrder.MaterialInscpTotal = materialInscpTotal
  527. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  528. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  529. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  530. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  531. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  532. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  533. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  534. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  535. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  536. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  537. newOrder.CheckCostTotal = checkCostTotal
  538. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  539. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  540. newOrder.CheckSelfTotal = checkSelfTotal
  541. newOrder.CheckInscpTotal = checkInscpTotal
  542. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  543. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  544. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  545. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  546. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  547. newOrder.TreatCostTotal = treatCostTotal
  548. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  549. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  550. newOrder.TreatSelfTotal = treatSelfTotal
  551. newOrder.TreatInscpTotal = treatInscpTotal
  552. newOrder.DoctorInfo = doctor_info
  553. newOrder.DoctorName = doctor_name
  554. newOrder.HealthCardNo = order.PsnNo
  555. newOrder.YiliaoLeibie = yiliao_leibie
  556. newOrder.Patient = patient
  557. newOrder.OrgName = miConfig.OrgName
  558. newOrder.OrgCode = miConfig.Code
  559. newOrder.OrderNumber = order.Number
  560. newOrder.HisPatient = his
  561. newOrder.DiaConfig = dia_config
  562. newOrders = append(newOrders, newOrder)
  563. }
  564. c.ServeSuccessJSON(map[string]interface{}{
  565. "orders": newOrders,
  566. })
  567. }
  568. func (c *HisApiController) GetTestOrder() {
  569. order_id, _ := c.GetInt64("order_id")
  570. admin_user_id, _ := c.GetInt64("admin_user_id")
  571. adminUser := c.GetAdminUserInfo()
  572. order, _ := service.GetHisOrderByID(order_id)
  573. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  574. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  575. orderInfos = append(orderInfos, orderInfos_two...)
  576. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  577. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  578. var dia_config []*models.HisXtDiagnoseConfig
  579. var name string
  580. var bedCostTotal float64 = 0 //床位总费
  581. var bedCostSelfTotal float64 = 0 //床位自费
  582. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  583. var bedSelfTotal float64 = 0 //床位部分项目自费
  584. var bedInscpTotal float64 = 0 //床位部分项目自费
  585. var operationCostTotal float64 = 0 //手术费
  586. var operationCostSelfTotal float64 = 0 //手术费
  587. var operationCostPartSelfTotal float64 = 0 //手术费
  588. var operationSelfTotal float64 = 0 //床位部分项目自费
  589. var operationInscpTotal float64 = 0 //床位部分项目自费
  590. var otherCostTotal float64 = 0 //其他费用
  591. var otherCostSelfTotal float64 = 0 //其他费用
  592. var otherCostPartSelfTotal float64 = 0 //其他费用
  593. var otherSelfTotal float64 = 0 //床位部分项目自费
  594. var otherInscpTotal float64 = 0 //床位部分项目自费
  595. var materialCostTotal float64 = 0 //材料费
  596. var materialCostSelfTotal float64 = 0 //材料费
  597. var materialCostPartSelfTotal float64 = 0 //材料费
  598. var materialSelfTotal float64 = 0 //床位部分项目自费
  599. var materialInscpTotal float64 = 0 //床位部分项目自费
  600. var westernMedicineCostTotal float64 = 0 //西药费
  601. var westernMedicineCostSelfTotal float64 = 0 //西药费
  602. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  603. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  604. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  605. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  606. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  607. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  608. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  609. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  610. var checkCostTotal float64 = 0 //检查费
  611. var checkCostSelfTotal float64 = 0 //检查费
  612. var checkCostPartSelfTotal float64 = 0 //检查费
  613. var checkSelfTotal float64 = 0 //床位部分项目自费
  614. var checkInscpTotal float64 = 0 //床位部分项目自费
  615. var laboratoryCostTotal float64 = 0 //化验费
  616. var laboratoryCostSelfTotal float64 = 0 //化验费
  617. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  618. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  619. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  620. var treatCostTotal float64 = 0 //治疗费用
  621. var treatCostSelfTotal float64 = 0 //治疗费用
  622. var treatCostPartSelfTotal float64 = 0 //治疗费用
  623. var treatSelfTotal float64 = 0 //床位部分项目自费
  624. var treatInscpTotal float64 = 0 //床位部分项目自费
  625. decimal.DivisionPrecision = 2
  626. for _, item := range orderInfos {
  627. if item.MedChrgitmType == "01" { //床位费
  628. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  629. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  630. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  631. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  632. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  633. }
  634. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  635. if item.MedChrgitmType == "03" { //检查费
  636. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  637. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  638. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  639. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  640. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  641. }
  642. } else {
  643. if item.MedChrgitmType == "03" { //检查费
  644. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  645. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  646. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  647. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  648. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  649. }
  650. }
  651. if item.MedChrgitmType == "04" { //化验费
  652. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "05" { //治疗费
  659. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "06" { //手术费
  666. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  673. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "09" { //西药费
  680. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "11" { //中成费
  687. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  694. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  695. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  696. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  697. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  698. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  699. }
  700. }
  701. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  702. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  703. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  704. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  705. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. var doctor_name string
  707. if roles.ID == 0 {
  708. doctor_name = "管理员"
  709. } else {
  710. doctor_name = roles.UserName
  711. }
  712. yiliao_leibie := ""
  713. switch order.MedType {
  714. case "11":
  715. yiliao_leibie = "普通门诊"
  716. break
  717. case "12":
  718. yiliao_leibie = "门诊挂号"
  719. break
  720. case "13":
  721. yiliao_leibie = "急诊"
  722. break
  723. case "14":
  724. yiliao_leibie = "门诊特殊病"
  725. break
  726. case "15":
  727. yiliao_leibie = "门诊统筹"
  728. break
  729. case "16":
  730. yiliao_leibie = "门诊慢性病"
  731. break
  732. case "21":
  733. yiliao_leibie = "普通住院"
  734. break
  735. }
  736. c.ServeSuccessJSON(map[string]interface{}{
  737. "diagnosis": name,
  738. "order_infos": orderInfos,
  739. "number": order.MdtrtId,
  740. "date": order.SettleAccountsDate,
  741. "charge_admin": charge_admin,
  742. "printor_admin": printor_admin,
  743. "info": order,
  744. "order": order,
  745. "bedCostTotal": bedCostTotal,
  746. "bedCostSelfTotal": bedCostSelfTotal,
  747. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  748. "bedSelfTotal": bedSelfTotal,
  749. "bedInscpTotal": bedInscpTotal,
  750. "operationCostTotal": operationCostTotal,
  751. "operationCostSelfTotal": operationCostSelfTotal,
  752. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  753. "operationSelfTotal": operationSelfTotal,
  754. "operationInscpTotal": operationInscpTotal,
  755. "otherCostTotal": otherCostTotal,
  756. "otherCostSelfTotal": otherCostSelfTotal,
  757. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  758. "otherSelfTotal": otherSelfTotal,
  759. "otherInscpTotal": otherInscpTotal,
  760. "materialCostTotal": materialCostTotal,
  761. "materialCostSelfTotal": materialCostSelfTotal,
  762. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  763. "materialSelfTotal": materialSelfTotal,
  764. "materialInscpTotal": materialInscpTotal,
  765. "westernMedicineCostTotal": westernMedicineCostTotal,
  766. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  767. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  768. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  769. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  770. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  771. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  772. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  773. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  774. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  775. "checkCostTotal": checkCostTotal,
  776. "checkCostSelfTotal": checkCostSelfTotal,
  777. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  778. "checkSelfTotal": checkSelfTotal,
  779. "checkInscpTotal": checkInscpTotal,
  780. "laboratoryCostTotal": laboratoryCostTotal,
  781. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  782. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  783. "laboratorySelfTotal": laboratorySelfTotal,
  784. "laboratoryInscpTotal": laboratoryInscpTotal,
  785. "treatCostTotal": treatCostTotal,
  786. "treatCostSelfTotal": treatCostSelfTotal,
  787. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  788. "treatSelfTotal": treatSelfTotal,
  789. "treatInscpTotal": treatInscpTotal,
  790. "doctor_info": doctor_info,
  791. "doctor_name": doctor_name,
  792. "health_card_no": order.PsnNo,
  793. "yiliao_leibie": yiliao_leibie,
  794. "patient": patient,
  795. "org_name": miConfig.OrgName,
  796. "org_code": miConfig.Code,
  797. "order_number": order.Number,
  798. "his_hospital": his_hospital,
  799. "dia_config": dia_config,
  800. })
  801. }
  802. type CustomFundPay struct {
  803. FundPayType string `json:"fund_pay_type"`
  804. FundPayamt float64 `json:"fund_payamt"`
  805. InscpScpAmt float64 `json:"inscp_scp_amt"`
  806. }
  807. func (c *PublicApiController) GetBaiLinExportData() {
  808. data := service.GetBaiLinOrderData()
  809. fmt.Println(len(data))
  810. var new_data []*models.NewCustomHisOrder
  811. for _, item := range data {
  812. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  813. new_data = append(new_data, item)
  814. }
  815. }
  816. fmt.Println(len(new_data))
  817. c.ServeSuccessJSON(map[string]interface{}{
  818. "list": new_data,
  819. })
  820. }
  821. func (c *HisApiController) GetHisUnChargePatientList() {
  822. record_date := c.GetString("record_date")
  823. sch_type, _ := c.GetInt64("sch_type")
  824. timeLayout := "2006-01-02"
  825. loc, _ := time.LoadLocation("Local")
  826. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  827. if err != nil {
  828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  829. return
  830. }
  831. recordDateTime := theTime.Unix()
  832. adminInfo := c.GetAdminUserInfo()
  833. var tempPatients []*service.NewTempPatients
  834. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  835. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  836. var patients []*service.NewTempPatients
  837. var patients_two []*service.NewTempPatients
  838. for _, item := range tempPatients {
  839. //过滤掉没挂号的和没开处方的
  840. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  841. patients = append(patients, item)
  842. }
  843. //过滤掉没挂号的
  844. if len(item.HisPatient) > 0 {
  845. patients_two = append(patients_two, item)
  846. }
  847. }
  848. c.ServeSuccessJSON(map[string]interface{}{
  849. "list": patients,
  850. "list_two": patients_two,
  851. })
  852. }
  853. func (c *HisApiController) GetPrivateExpensesOrder() {
  854. //id, _ := c.GetInt64("id")
  855. //record_time := c.GetString("record_time")
  856. order_id, _ := c.GetInt64("order_id")
  857. admin_user_id, _ := c.GetInt64("admin_user_id")
  858. //timeLayout := "2006-01-02"
  859. //loc, _ := time.LoadLocation("Local")
  860. //
  861. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  862. //if err != nil {
  863. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  864. // return
  865. //}
  866. //recordDateTime := theTime.Unix()
  867. adminUser := c.GetAdminUserInfo()
  868. order, _ := service.GetHisOrderByID(order_id)
  869. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  870. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  871. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  872. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  873. //var config []*models.HisXtDiagnoseConfig
  874. var name string
  875. if order.PType == 1 {
  876. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  877. for _, item := range diagnosis_ids {
  878. id, _ := strconv.ParseInt(item, 10, 64)
  879. diagnosisConfig, _ := service.FindDiagnoseById(id)
  880. if len(name) == 0 {
  881. name = diagnosisConfig.ClassName
  882. } else {
  883. name = name + "," + diagnosisConfig.ClassName
  884. }
  885. }
  886. } else {
  887. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  888. for _, item := range diagnosis_ids {
  889. id, _ := strconv.ParseInt(item, 10, 64)
  890. diagnosisConfig, _ := service.FindDiagnoseById(id)
  891. if len(name) == 0 {
  892. name = diagnosisConfig.ClassName
  893. } else {
  894. name = name + "," + diagnosisConfig.ClassName
  895. }
  896. }
  897. }
  898. var bedCostTotal float64 = 0 //床位总费
  899. //var bedCostSelfTotal float64 = 0 //床位自费
  900. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  901. var operationCostTotal float64 = 0 //手术费
  902. //var operationCostSelfTotal float64 = 0 //手术费
  903. var operationCostPartSelfTotal float64 = 0 //手术费
  904. var otherCostTotal float64 = 0 //其他费用
  905. //var otherCostSelfTotal float64 = 0 //其他费用
  906. var otherCostPartSelfTotal float64 = 0 //其他费用
  907. var materialCostTotal float64 = 0 //材料费
  908. //var materialCostSelfTotal float64 = 0 //材料费
  909. var materialCostPartSelfTotal float64 = 0 //材料费
  910. var westernMedicineCostTotal float64 = 0 //西药费
  911. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  912. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  913. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  914. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  915. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  916. var checkCostTotal float64 = 0 //检查费
  917. //var checkCostSelfTotal float64 = 0 //检查费
  918. var checkCostPartSelfTotal float64 = 0 //检查费
  919. var laboratoryCostTotal float64 = 0 //化验费
  920. //var laboratoryCostSelfTotal float64 = 0 //化验费
  921. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  922. var treatCostTotal float64 = 0 //治疗费用
  923. //var treatCostSelfTotal float64 = 0 //治疗费用
  924. var treatCostPartSelfTotal float64 = 0 //治疗费用
  925. var zhenChaCostTotal float64 = 0 //其他费用
  926. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  927. decimal.DivisionPrecision = 2
  928. for _, item := range orderInfos {
  929. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  930. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  931. item.MedChrgitmType = "09"
  932. }
  933. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  934. if item.HisPrescriptionProject.Type == 2 {
  935. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  936. fmt.Println("CostClassify")
  937. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  938. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  939. case 0:
  940. item.MedChrgitmType = "0"
  941. break
  942. case 1:
  943. item.MedChrgitmType = "14"
  944. break
  945. case 2:
  946. item.MedChrgitmType = "05"
  947. break
  948. case 3:
  949. item.MedChrgitmType = "03"
  950. break
  951. case 4:
  952. item.MedChrgitmType = "03"
  953. break
  954. case 5:
  955. item.MedChrgitmType = "08"
  956. break
  957. case 6:
  958. item.MedChrgitmType = "14"
  959. break
  960. case 7:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 8:
  964. item.MedChrgitmType = "03"
  965. break
  966. case 9:
  967. item.MedChrgitmType = "14"
  968. break
  969. case 10:
  970. item.MedChrgitmType = "14"
  971. break
  972. case 11:
  973. item.MedChrgitmType = "06"
  974. break
  975. case 12:
  976. item.MedChrgitmType = "12"
  977. break
  978. case 13:
  979. item.MedChrgitmType = "01"
  980. break
  981. case 14:
  982. item.MedChrgitmType = "04"
  983. break
  984. case 15:
  985. item.MedChrgitmType = "14"
  986. break
  987. }
  988. } else {
  989. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  990. case 1:
  991. item.MedChrgitmType = "14"
  992. break
  993. case 2:
  994. item.MedChrgitmType = "05"
  995. break
  996. case 3:
  997. item.MedChrgitmType = "04"
  998. break
  999. case 4:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 5:
  1003. item.MedChrgitmType = "08"
  1004. break
  1005. case 6:
  1006. item.MedChrgitmType = "14"
  1007. break
  1008. case 7:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. case 8:
  1012. item.MedChrgitmType = "03"
  1013. break
  1014. case 9:
  1015. item.MedChrgitmType = "14"
  1016. break
  1017. default:
  1018. item.MedChrgitmType = "14"
  1019. break
  1020. }
  1021. }
  1022. } else if item.HisPrescriptionProject.Type == 3 {
  1023. item.MedChrgitmType = "08"
  1024. }
  1025. }
  1026. }
  1027. if order.IsMedicineInsurance != 1 {
  1028. order.PsnCashPay = order.MedfeeSumamt
  1029. }
  1030. for _, item := range orderInfos {
  1031. if item.MedChrgitmType == "01" { //床位费
  1032. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "02" { //诊察费
  1037. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //zhenChaCostSelfTotal = zhenChaCostTotal
  1039. }
  1040. if item.MedChrgitmType == "03" { //检查费
  1041. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1042. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1043. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1044. }
  1045. if item.MedChrgitmType == "02" { //检查费
  1046. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1047. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1048. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1049. }
  1050. if item.MedChrgitmType == "04" { //化验费
  1051. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1052. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1053. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1054. }
  1055. if item.MedChrgitmType == "05" { //治疗费
  1056. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1057. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1058. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1059. }
  1060. if item.MedChrgitmType == "06" { //手术费
  1061. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1062. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1063. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1064. }
  1065. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1066. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. }
  1070. if item.MedChrgitmType == "09" { //西药费
  1071. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1072. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1073. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1074. }
  1075. if item.MedChrgitmType == "11" { //中成费
  1076. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1077. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1078. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1079. }
  1080. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1081. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1082. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1083. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1084. }
  1085. }
  1086. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1087. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1088. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1089. var dia_config []*models.HisXtDiagnoseConfig
  1090. var diagnosis_ids []string
  1091. if his.ID > 0 {
  1092. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1093. } else {
  1094. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1095. }
  1096. for _, item := range diagnosis_ids {
  1097. id, _ := strconv.ParseInt(item, 10, 64)
  1098. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1099. dia_config = append(dia_config, diagnosisConfig)
  1100. }
  1101. var rf []CustomFundPay
  1102. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1103. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1104. c.ServeSuccessJSON(map[string]interface{}{
  1105. "patient": patient,
  1106. "order_infos": orderInfos,
  1107. "diagnosis": name,
  1108. "bedCostTotal": bedCostTotal,
  1109. "bedCostSelfTotal": bedCostTotal,
  1110. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1111. "operationCostTotal": operationCostTotal,
  1112. "operationCostSelfTotal": operationCostTotal,
  1113. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1114. "otherCostTotal": otherCostTotal,
  1115. "otherCostSelfTotal": otherCostTotal,
  1116. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1117. "materialCostTotal": materialCostTotal,
  1118. "materialCostSelfTotal": materialCostTotal,
  1119. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1120. "westernMedicineCostTotal": westernMedicineCostTotal,
  1121. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1122. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1123. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1124. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1125. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1126. "checkCostTotal": checkCostTotal,
  1127. "checkCostSelfTotal": checkCostTotal,
  1128. "zhenChaCostTotal": zhenChaCostTotal,
  1129. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1130. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1131. "laboratoryCostTotal": laboratoryCostTotal,
  1132. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1133. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1134. "treatCostTotal": treatCostTotal,
  1135. "treatCostSelfTotal": treatCostTotal,
  1136. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1137. "charge_admin": charge_admin,
  1138. "printor_admin": printor_admin,
  1139. "org_name": org.OrgName,
  1140. "org_code": miConfig.Code,
  1141. "name": patient.Name,
  1142. "number": order.MdtrtId,
  1143. "date": order.SettleAccountsDate,
  1144. "info": order,
  1145. "new_order": order,
  1146. "his_hospital": his_hospital,
  1147. "his": his,
  1148. "funds": rf,
  1149. "dia_config": dia_config,
  1150. })
  1151. }
  1152. func (c *HisApiController) RefudDetail() {
  1153. order_id, _ := c.GetInt64("order_id")
  1154. order, _ := service.GetHisOrderByID(order_id)
  1155. adminUser := c.GetAdminUserInfo()
  1156. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1157. c.ServeSuccessJSON(map[string]interface{}{
  1158. "msg": "撤销成功",
  1159. })
  1160. }
  1161. func (c *HisApiController) Sscard() {
  1162. //r := CardInit()
  1163. //if r == 0 {
  1164. // GetBaseInfo()
  1165. //}
  1166. //c.ServeSuccessJSON(map[string]interface{}{
  1167. // "list": "11",
  1168. //})
  1169. }
  1170. func GetBaseInfo() error {
  1171. //handle := syscall.MustLoadDLL("SSCard.dll")
  1172. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1173. //
  1174. //str := make([]byte, 256)
  1175. //str1 := make([]byte, 256)
  1176. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1177. //if ferr != nil {
  1178. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1179. // return ferr
  1180. //}
  1181. //
  1182. //fmt.Println(string(str))
  1183. //
  1184. //fmt.Println(r)
  1185. return nil
  1186. }
  1187. func CardInit() int {
  1188. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1189. //add := DllTestDef.MustFindProc("Init")
  1190. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1191. //if err != nil {
  1192. // fmt.Println("SSCard的运算结果为:", ret)
  1193. //}
  1194. //result := int(ret)
  1195. return 0
  1196. }
  1197. func IntPtr(n int) uintptr {
  1198. return uintptr(n)
  1199. }
  1200. func StrPtr(s string) uintptr {
  1201. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1202. }
  1203. func (c *HisApiController) GetHisPatientList() {
  1204. //types, _ := c.GetInt64("type", 0)
  1205. record_date := c.GetString("record_date")
  1206. sch_type, _ := c.GetInt64("sch_type")
  1207. timeLayout := "2006-01-02"
  1208. loc, _ := time.LoadLocation("Local")
  1209. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1210. if err != nil {
  1211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1212. return
  1213. }
  1214. recordDateTime := theTime.Unix()
  1215. adminInfo := c.GetAdminUserInfo()
  1216. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1217. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1218. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1219. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1220. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1221. //获取当前用户的信息
  1222. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1223. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1224. //获取所有科室信息
  1225. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1226. //var aa []service.PatientThree
  1227. noElementsSlice := make([]service.PatientThree, 0)
  1228. c.ServeSuccessJSON(map[string]interface{}{
  1229. "list": patients,
  1230. "list_two": patients_two,
  1231. "list_three": noElementsSlice,
  1232. "info": adminUserInfo,
  1233. "doctors": doctors,
  1234. "department": department,
  1235. })
  1236. }
  1237. type CustomTemplate struct {
  1238. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1239. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1240. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1241. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1242. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1243. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1244. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1245. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1246. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1247. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1248. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1249. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1250. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1251. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1252. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1253. }
  1254. func (c *HisApiController) GetHisPatientInfo() {
  1255. patient_id, _ := c.GetInt64("patient_id")
  1256. his_patient_id, _ := c.GetInt64("his_patient_id")
  1257. record_date := c.GetString("record_date")
  1258. number := c.GetString("number")
  1259. //start_time := c.GetString("start_time")
  1260. //end_time := c.GetString("end_time")
  1261. p_type, _ := c.GetInt64("p_type")
  1262. timeLayout := "2006-01-02"
  1263. loc, _ := time.LoadLocation("Local")
  1264. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1265. if err != nil {
  1266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1267. return
  1268. }
  1269. recordDateTime := theTime.Unix()
  1270. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1271. //if err != nil {
  1272. //
  1273. //}
  1274. //startRecordDateTime := startTime.Unix()
  1275. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1276. //if err != nil {
  1277. //
  1278. //}
  1279. //endRecordDateTime := endTime.Unix()
  1280. admin := c.GetAdminUserInfo()
  1281. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1282. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1283. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1284. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1285. var prescriptions []*models.HisPrescription
  1286. var last_prescriptions []*models.HisPrescription
  1287. var sch_prescriptions []CustomTemplate
  1288. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1289. if p_type == 1 { //住院
  1290. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1291. for _, item := range prescriptions {
  1292. for _, subItem := range item.HisDoctorAdviceInfo {
  1293. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1294. if info.RetailPrice > 0 {
  1295. subItem.Drug.MinPrice = info.RetailPrice
  1296. }
  1297. }
  1298. }
  1299. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1300. } else { //门诊
  1301. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1302. for _, item := range prescriptions {
  1303. for _, subItem := range item.HisDoctorAdviceInfo {
  1304. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1305. if info.RetailPrice > 0 {
  1306. subItem.Drug.MinPrice = info.RetailPrice
  1307. }
  1308. }
  1309. }
  1310. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1311. }
  1312. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1313. if sch.ID > 0 {
  1314. var week string
  1315. t := time.Now()
  1316. switch t.Weekday().String() {
  1317. case "Monday":
  1318. week = "周一"
  1319. break
  1320. case "Tuesday":
  1321. week = "周二"
  1322. break
  1323. case "Wednesday":
  1324. week = "周三"
  1325. break
  1326. case "Thursday":
  1327. week = "周四"
  1328. break
  1329. case "Friday":
  1330. week = "周五"
  1331. break
  1332. case "Saturday":
  1333. week = "周六"
  1334. break
  1335. case "Sunday":
  1336. week = "周日"
  1337. break
  1338. }
  1339. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1340. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1341. //根据推送频率组装新的数组
  1342. for _, item := range temp_sch_prescriptions {
  1343. var cus CustomTemplate
  1344. cus.ID = item.ID
  1345. cus.UserOrgId = item.UserOrgId
  1346. cus.PatientId = item.PatientId
  1347. cus.MedType = item.MedType
  1348. cus.RecordDate = item.RecordDate
  1349. cus.Type = item.Type
  1350. cus.PType = item.PType
  1351. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1352. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1353. if subItem.FrequencyType == 1 { //每次必推
  1354. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1355. }
  1356. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1357. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1358. }
  1359. if subItem.FrequencyType == 2 { //按照天数频率
  1360. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1361. now := p.Unix()
  1362. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1363. dayStr2 := "-" + dayStr
  1364. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1365. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1366. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1367. if len(advices) == 0 {
  1368. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1369. }
  1370. }
  1371. }
  1372. }
  1373. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1374. if subItem.Type == 2 {
  1375. if subItem.XtHisProject.MedicalStatus != 1 {
  1376. if subItem.FrequencyType == 1 {
  1377. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1378. }
  1379. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1380. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1381. }
  1382. if subItem.FrequencyType == 2 {
  1383. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1384. now := p.Unix()
  1385. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1386. dayStr2 := "-" + dayStr
  1387. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1388. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1389. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1390. if len(projects) == 0 {
  1391. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1392. }
  1393. }
  1394. }
  1395. } else if subItem.Type == 3 {
  1396. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1397. if subItem.FrequencyType == 1 {
  1398. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1399. }
  1400. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. if subItem.FrequencyType == 2 {
  1404. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1405. now := p.Unix()
  1406. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1407. dayStr2 := "-" + dayStr
  1408. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1409. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1410. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1411. if len(projects) == 0 {
  1412. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1413. }
  1414. }
  1415. }
  1416. }
  1417. }
  1418. sch_prescriptions = append(sch_prescriptions, cus)
  1419. }
  1420. for _, item := range sch_prescriptions {
  1421. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1422. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1423. }
  1424. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1425. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1426. }
  1427. }
  1428. }
  1429. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1430. if config.ID > 0 && config.IsOpen == 1 {
  1431. for _, item := range sch_prescriptions {
  1432. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1433. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1434. if info.RetailPrice > 0 {
  1435. subItem.Drug.MinPrice = info.RetailPrice
  1436. if admin.CurrentOrgId != 10598 {
  1437. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1438. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1439. }
  1440. }
  1441. }
  1442. }
  1443. }
  1444. if config.ID > 0 && config.IsOpen == 1 {
  1445. for _, item := range sch_prescriptions {
  1446. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1447. if subItem.Type == 3 {
  1448. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1449. if info.Price > 0 {
  1450. subItem.GoodInfo.PackingPrice = info.Price
  1451. if admin.CurrentOrgId != 10598 {
  1452. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1453. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1454. }
  1455. }
  1456. }
  1457. }
  1458. }
  1459. }
  1460. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1461. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1462. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1463. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1464. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1465. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1466. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1467. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1468. //获取所有科室信息
  1469. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1470. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1471. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1472. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1473. c.ServeSuccessJSON(map[string]interface{}{
  1474. "his_info": his_patient_info,
  1475. "xt_info": xt_patient_info,
  1476. "prescription": prescriptions,
  1477. "case_history": case_history,
  1478. "info": patientPrescriptionInfo,
  1479. //"month_prescriptions": monthPrescriptions,
  1480. "order": order,
  1481. "doctors": doctors,
  1482. "department": department,
  1483. "sch_prescriptions": sch_prescriptions,
  1484. "last_prescriptions": last_prescriptions,
  1485. "schedule": sch,
  1486. "count": count,
  1487. "drugStockConfig": drugStockConfig,
  1488. "last_info": lastPatientPrescriptionInfo,
  1489. "befor": beforThrity,
  1490. "LastCaseHistory": LastCaseHistory,
  1491. "prescriptionInfo": prescriptionInfo,
  1492. })
  1493. return
  1494. }
  1495. func (c *HisApiController) GetHisPrescriptionConfig() {
  1496. adminInfo := c.GetAdminUserInfo()
  1497. //获取医嘱模版
  1498. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1499. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1500. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1501. //获取所有基础药
  1502. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1503. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1504. if config.ID > 0 && config.IsOpen == 1 {
  1505. for _, item := range drugs {
  1506. var index = 0
  1507. for _, subItem := range item.OtherDrugWarehouseInfo {
  1508. if index == 0 {
  1509. index = index + 1
  1510. if subItem.RetailPrice > 0 {
  1511. item.MinPrice = subItem.RetailPrice
  1512. }
  1513. }
  1514. }
  1515. }
  1516. }
  1517. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1518. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1519. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1520. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1521. //获取所有科室信息
  1522. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1523. //获取诊断信息
  1524. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1525. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1526. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1527. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1528. //获取是否开启保存耗材出库的开关
  1529. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1530. c.ServeSuccessJSON(map[string]interface{}{
  1531. "drugs": drugs,
  1532. "advices_template": advices,
  1533. "drugways": drugways,
  1534. "efs": efs,
  1535. "doctors": doctors,
  1536. "department": department,
  1537. "sick": sick,
  1538. "additions": additions,
  1539. "diagnose": diagnose,
  1540. "manufacturers": manufacturers,
  1541. "goodOutOpen": goodOutOpen,
  1542. "patientDiagnose": patientDiagnose,
  1543. })
  1544. }
  1545. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1546. //获取所有基础药
  1547. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1548. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1549. if config.ID > 0 && config.IsOpen == 1 {
  1550. for _, item := range drugs {
  1551. var index = 0
  1552. for _, subItem := range item.OtherDrugWarehouseInfo {
  1553. if index == 0 {
  1554. index = index + 1
  1555. if subItem.RetailPrice > 0 {
  1556. item.MinPrice = subItem.RetailPrice
  1557. }
  1558. }
  1559. }
  1560. }
  1561. }
  1562. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1563. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1564. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1565. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1566. //获取所有科室信息
  1567. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1568. //获取诊断信息
  1569. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1570. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1571. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1572. //获取是否开启保存耗材出库的开关
  1573. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1574. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1575. c.ServeSuccessJSON(map[string]interface{}{
  1576. "drugs": drugs,
  1577. "advices_template": advices,
  1578. "drugways": drugways,
  1579. "efs": efs,
  1580. "doctors": doctors,
  1581. "department": department,
  1582. "sick": sick,
  1583. "additions": additions,
  1584. "diagnose": diagnose,
  1585. "manufacturers": manufacturers,
  1586. "goodOutOpen": goodOutOpen,
  1587. "patientDiagnose": patientDiagnose,
  1588. })
  1589. }
  1590. }
  1591. func (c *HisApiController) CreateHisPrescription() {
  1592. record_date := c.GetString("record_date")
  1593. patient_id, _ := c.GetInt64("patient_id")
  1594. reg_type, _ := c.GetInt64("reg_type")
  1595. diagnose := c.GetString("diagnose")
  1596. sick_type, _ := c.GetInt64("sick_type")
  1597. sick_history := c.GetString("sick_history")
  1598. doctor_id, _ := c.GetInt64("doctor", 0)
  1599. department, _ := c.GetInt64("department", 0)
  1600. his_patient_id, _ := c.GetInt64("his_patient_id")
  1601. p_type, _ := c.GetInt64("p_type")
  1602. patient_diagnose := c.GetString("patient_diagnose")
  1603. dataBody := make(map[string]interface{}, 0)
  1604. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1605. if err != nil {
  1606. utils.ErrorLog(err.Error())
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1608. return
  1609. }
  1610. //edit, src := GetCompareData(dataBody)
  1611. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1612. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1613. //fmt.Println(drugResult)
  1614. //fmt.Println(goodResult)
  1615. timeLayout := "2006-01-02"
  1616. loc, _ := time.LoadLocation("Local")
  1617. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1618. if err != nil {
  1619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1620. return
  1621. }
  1622. adminInfo := c.GetAdminUserInfo()
  1623. recordDateTime := theTime.Unix()
  1624. //查询默认出库仓库库存
  1625. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1626. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1627. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1628. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1629. if len(lists) == 1 {
  1630. his_patient_id = lists[0].ID
  1631. }
  1632. }
  1633. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1634. //自动出库的开关开启
  1635. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1636. //自动出库
  1637. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1638. //耗材保存处方出库
  1639. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1640. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1641. //已发药和已收费限制逻辑
  1642. isMidicine := false
  1643. isCharge := false
  1644. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1645. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1646. if len(prescriptions) > 0 {
  1647. for _, item := range prescriptions {
  1648. items := item.(map[string]interface{})
  1649. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1650. utils.ErrorLog("id")
  1651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1652. return
  1653. }
  1654. id := int64(items["id"].(float64))
  1655. if id > 0 {
  1656. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1657. if err != nil {
  1658. if new_prescription.OrderStatus == 4 {
  1659. isCharge = true
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. }
  1666. if isMidicine == true {
  1667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1668. return
  1669. }
  1670. if isCharge == true {
  1671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1672. return
  1673. }
  1674. // 开始主事务
  1675. db := service.XTWriteDB()
  1676. tx := db.Begin()
  1677. // 在函数结束时处理事务回滚
  1678. defer func() {
  1679. if r := recover(); r != nil {
  1680. tx.Rollback()
  1681. }
  1682. }()
  1683. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1684. //药品发药出库
  1685. if pharmacyConfig.IsOpen == 1 {
  1686. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1687. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1688. if len(prescriptions) > 0 {
  1689. for _, item := range prescriptions {
  1690. items := item.(map[string]interface{})
  1691. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1692. advices := items["advices"].([]interface{})
  1693. if len(advices) > 0 {
  1694. for _, advice := range advices {
  1695. var drug_id int64
  1696. var prescribing_number float64
  1697. var prescribingNumberUnit string
  1698. var adviceId int64
  1699. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1700. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1701. }
  1702. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1703. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1704. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1705. }
  1706. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1707. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1708. }
  1709. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1710. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1711. }
  1712. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1713. if drug.ID == 0 {
  1714. tx.Rollback()
  1715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1716. return
  1717. }
  1718. //查询药品的所有库存
  1719. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1720. var total_count int64
  1721. for _, it := range list {
  1722. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1723. }
  1724. totals := strconv.FormatInt(total_count, 10)
  1725. //查询该药品是否存在开药记录
  1726. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1727. //新增处方盘点库存是否充足
  1728. if advicelist.ID == 0 {
  1729. all_count, _ := strconv.ParseFloat(totals, 64)
  1730. if prescribingNumberUnit == drug.MinUnit {
  1731. if drug.IsUse != 1 {
  1732. if drug.IsProject == 0 || drug.IsProject == 2 {
  1733. if all_count == 0 {
  1734. tx.Rollback()
  1735. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1736. return
  1737. }
  1738. if prescribing_number > all_count {
  1739. tx.Rollback()
  1740. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1741. return
  1742. }
  1743. }
  1744. }
  1745. }
  1746. if prescribingNumberUnit == drug.MaxUnit {
  1747. num := prescribing_number * float64(drug.MinNumber)
  1748. if drug.IsUse != 1 {
  1749. if drug.IsProject == 0 || drug.IsProject == 2 {
  1750. if all_count == 0 {
  1751. tx.Rollback()
  1752. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1753. return
  1754. }
  1755. if num > all_count {
  1756. tx.Rollback()
  1757. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1758. return
  1759. }
  1760. }
  1761. }
  1762. }
  1763. }
  1764. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1765. //不使用保存处方出库
  1766. if drugOutConfig.IsOpen != 1 {
  1767. //修改处方
  1768. for _, advice := range advices {
  1769. var drug_id int64
  1770. var prescribing_number float64
  1771. var prescribingNumberUnit string
  1772. var prescribingNumber string
  1773. var adviceId int64
  1774. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1775. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1776. }
  1777. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1778. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1779. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1780. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1781. }
  1782. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1783. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1784. }
  1785. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1786. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1787. }
  1788. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1789. if drug.ID == 0 {
  1790. tx.Rollback()
  1791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1792. return
  1793. }
  1794. //查询药品的所有库存
  1795. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1796. var total_count int64
  1797. for _, it := range list {
  1798. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1799. }
  1800. totals := strconv.FormatInt(total_count, 10)
  1801. //查询该药品是否存在开药记录
  1802. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1803. //新增处方
  1804. if advicelist.ID == 0 {
  1805. all_count, _ := strconv.ParseFloat(totals, 64)
  1806. if prescribingNumberUnit == drug.MinUnit {
  1807. if drug.IsUse != 1 {
  1808. if drug.IsProject == 0 || drug.IsProject == 2 {
  1809. if all_count == 0 {
  1810. tx.Rollback()
  1811. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1812. return
  1813. }
  1814. if prescribing_number > all_count {
  1815. tx.Rollback()
  1816. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1817. return
  1818. }
  1819. }
  1820. }
  1821. } else {
  1822. if prescribingNumberUnit == drug.MaxUnit {
  1823. num := prescribing_number * float64(drug.MinNumber)
  1824. if drug.IsUse != 1 {
  1825. if drug.IsProject == 0 || drug.IsProject == 2 {
  1826. if all_count == 0 {
  1827. tx.Rollback()
  1828. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1829. return
  1830. }
  1831. if num > all_count {
  1832. tx.Rollback()
  1833. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1834. return
  1835. }
  1836. }
  1837. }
  1838. }
  1839. }
  1840. }
  1841. //修改处方
  1842. if advicelist.ID > 0 {
  1843. var device_number int64
  1844. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1845. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1846. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1847. device_number = prescribingNumberInt * drug.MinNumber
  1848. }
  1849. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1850. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1851. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1852. device_number = prescribingNumberInt
  1853. }
  1854. var number_count int64
  1855. if prescribingNumberUnit == drug.MaxUnit {
  1856. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1857. number_count = prescribingNumberInt * drug.MinNumber
  1858. }
  1859. if prescribingNumberUnit == drug.MinUnit {
  1860. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1861. number_count = prescribingNumberInt
  1862. }
  1863. //如果修改的数量大于之前修改的数量
  1864. if (number_count - device_number) > 0 {
  1865. //如果修改的差数量 大于库存数量
  1866. if drug.IsUse != 1 {
  1867. if (number_count - device_number) > total_count {
  1868. tx.Rollback()
  1869. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1870. return
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. }
  1877. }
  1878. }
  1879. }
  1880. }
  1881. }
  1882. }
  1883. }
  1884. //已发药和已收费限制逻辑
  1885. //执行出库的逻辑
  1886. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1887. //校验库存总量
  1888. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1889. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1890. if len(prescriptions) > 0 {
  1891. for _, item := range prescriptions {
  1892. items := item.(map[string]interface{})
  1893. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1894. advices := items["advices"].([]interface{})
  1895. if len(advices) > 0 {
  1896. for _, advice := range advices {
  1897. var drug_id int64
  1898. var prescribing_number float64
  1899. var prescribingNumberUnit string
  1900. var adviceId int64
  1901. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1902. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1903. }
  1904. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1905. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1906. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1907. }
  1908. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1909. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1910. }
  1911. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1912. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1913. }
  1914. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1915. if drug.ID == 0 {
  1916. tx.Rollback()
  1917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1918. return
  1919. }
  1920. //查询药品的所有库存
  1921. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1922. var total_count int64
  1923. for _, it := range list {
  1924. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1925. }
  1926. totals := strconv.FormatInt(total_count, 10)
  1927. //查询该药品是否存在开药记录
  1928. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1929. //查询最新批次库存
  1930. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1931. var batch_number_count int64
  1932. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1933. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1934. //新增处方
  1935. if advicelist.ID == 0 {
  1936. all_count, _ := strconv.ParseFloat(totals, 64)
  1937. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1938. if prescribingNumberUnit == drug.MinUnit {
  1939. if drug.IsUse != 1 {
  1940. if drug.IsProject == 0 || drug.IsProject == 2 {
  1941. if all_count == 0 {
  1942. tx.Rollback()
  1943. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1944. return
  1945. }
  1946. if prescribing_number > all_count {
  1947. tx.Rollback()
  1948. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1949. return
  1950. }
  1951. }
  1952. if adminInfo.CurrentOrgId == 10215 {
  1953. if prescribing_number > batch_number_all_count {
  1954. tx.Rollback()
  1955. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1956. return
  1957. }
  1958. }
  1959. }
  1960. }
  1961. if prescribingNumberUnit == drug.MaxUnit {
  1962. num := prescribing_number * float64(drug.MinNumber)
  1963. if drug.IsUse != 1 {
  1964. if drug.IsProject == 0 || drug.IsProject == 2 {
  1965. if all_count == 0 {
  1966. tx.Rollback()
  1967. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1968. return
  1969. }
  1970. if num > all_count {
  1971. tx.Rollback()
  1972. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1973. return
  1974. }
  1975. }
  1976. if adminInfo.CurrentOrgId == 10215 {
  1977. if num > batch_number_all_count {
  1978. tx.Rollback()
  1979. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1980. return
  1981. }
  1982. }
  1983. }
  1984. }
  1985. }
  1986. //不是保存处方出库
  1987. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1988. if drugOutConfig.IsOpen != 1 {
  1989. //修改处方
  1990. for _, advice := range advices {
  1991. var drug_id int64
  1992. var prescribing_number float64
  1993. var prescribingNumberUnit string
  1994. var prescribingNumber string
  1995. var adviceId int64
  1996. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1997. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1998. }
  1999. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2000. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2001. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2002. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2003. }
  2004. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2005. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2006. }
  2007. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2008. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2009. }
  2010. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2011. if drug.ID == 0 {
  2012. tx.Rollback()
  2013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2014. return
  2015. }
  2016. //查询药品的所有库存
  2017. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2018. var total_count int64
  2019. for _, it := range list {
  2020. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2021. }
  2022. totals := strconv.FormatInt(total_count, 10)
  2023. //查询该药品是否存在开药记录
  2024. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2025. //新增处方
  2026. if advicelist.ID == 0 {
  2027. //查询最新批次库存
  2028. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2029. var batch_number_count int64
  2030. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2031. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2032. all_count, _ := strconv.ParseFloat(totals, 64)
  2033. if all_count == 0 {
  2034. tx.Rollback()
  2035. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2036. return
  2037. }
  2038. if prescribingNumberUnit == drug.MinUnit {
  2039. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2040. if drug.IsUse != 1 {
  2041. if drug.IsProject == 0 || drug.IsProject == 2 {
  2042. if all_count == 0 {
  2043. tx.Rollback()
  2044. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2045. return
  2046. }
  2047. if prescribing_number > all_count {
  2048. tx.Rollback()
  2049. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2050. return
  2051. }
  2052. }
  2053. if adminInfo.CurrentOrgId == 10215 {
  2054. if prescribing_number > batch_number_all_count {
  2055. tx.Rollback()
  2056. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2057. return
  2058. }
  2059. }
  2060. }
  2061. } else {
  2062. if prescribingNumberUnit == drug.MaxUnit {
  2063. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2064. num := prescribing_number * float64(drug.MinNumber)
  2065. if drug.IsUse != 1 {
  2066. if drug.IsProject == 0 || drug.IsProject == 2 {
  2067. if all_count == 0 {
  2068. tx.Rollback()
  2069. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2070. return
  2071. }
  2072. if num > all_count {
  2073. tx.Rollback()
  2074. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2075. return
  2076. }
  2077. }
  2078. if adminInfo.CurrentOrgId == 10215 {
  2079. if prescribing_number > batch_number_all_count {
  2080. tx.Rollback()
  2081. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2082. return
  2083. }
  2084. }
  2085. }
  2086. }
  2087. }
  2088. }
  2089. //修改处方
  2090. if advicelist.ID > 0 {
  2091. //查询最新批次库存
  2092. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2093. var batch_number_count int64
  2094. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2095. var device_number int64
  2096. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2097. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2098. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2099. device_number = prescribingNumberInt * drug.MinNumber
  2100. }
  2101. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2102. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2103. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2104. device_number = prescribingNumberInt
  2105. //回退库存
  2106. }
  2107. var number_count int64
  2108. if prescribingNumberUnit == drug.MaxUnit {
  2109. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2110. number_count = prescribingNumberInt * drug.MinNumber
  2111. //回退库存
  2112. }
  2113. if prescribingNumberUnit == drug.MinUnit {
  2114. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2115. number_count = prescribingNumberInt
  2116. //回退库存
  2117. }
  2118. //如果修改的数量大于之前修改的数量
  2119. if (number_count - device_number) > 0 {
  2120. //如果修改的差数量 大于库存数量
  2121. if drug.IsUse != 1 {
  2122. if drug.IsProject == 0 || drug.IsProject == 2 {
  2123. if total_count == 0 {
  2124. tx.Rollback()
  2125. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2126. return
  2127. }
  2128. if (number_count - device_number) > total_count {
  2129. tx.Rollback()
  2130. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2131. return
  2132. }
  2133. if (number_count - device_number) > batch_number_count {
  2134. tx.Rollback()
  2135. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2136. return
  2137. }
  2138. }
  2139. if adminInfo.CurrentOrgId == 10215 {
  2140. // 查询该药品最后一次出库记录
  2141. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2142. var out_count int64
  2143. var in_count int64
  2144. var stock_max_number int64
  2145. var stock_min_number int64
  2146. for _, it := range outInfo {
  2147. if it.CountUnit == drug.MaxUnit {
  2148. it.Count = it.Count * drug.MinNumber
  2149. }
  2150. out_count += it.Count
  2151. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2152. stock_max_number = warehouseInfoList.StockMaxNumber
  2153. stock_min_number = warehouseInfoList.StockMinNumber
  2154. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2155. }
  2156. if out_count > 0 {
  2157. if (number_count - device_number) > in_count {
  2158. tx.Rollback()
  2159. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2160. return
  2161. }
  2162. }
  2163. // 未出库
  2164. if out_count == 0 {
  2165. var sum_in_count int64
  2166. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2167. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2168. //如果修改的数量大于有库存的第一个批次
  2169. if number_count > sum_in_count {
  2170. tx.Rollback()
  2171. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2172. return
  2173. }
  2174. }
  2175. }
  2176. }
  2177. }
  2178. //药品发药
  2179. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2180. //不使用药品发药的功能
  2181. //if pharmacyConfig.IsOpen != 1 {
  2182. // if device_number != number_count {
  2183. //
  2184. // //查询该药品的出库记录
  2185. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2186. // if len(outListExport) > 0 {
  2187. // //
  2188. // for _, item := range outListExport {
  2189. // //回退库存
  2190. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2191. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2192. // }
  2193. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2194. // var stock_max_number int64
  2195. // var stock_min_number int64
  2196. //
  2197. // if number_count >= drug.MinNumber {
  2198. //
  2199. // stock_max_number = device_number / drug.MinNumber
  2200. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2201. //
  2202. // stock_min_number = device_number % drug.MinNumber
  2203. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2204. //
  2205. // } else {
  2206. //
  2207. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2208. //
  2209. // }
  2210. // }
  2211. //
  2212. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2213. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2214. // }
  2215. // }
  2216. // }
  2217. //
  2218. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2219. // var sum_count int64
  2220. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2221. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2222. // for _, its := range stockInfo {
  2223. // if its.MaxUnit == drug.MaxUnit {
  2224. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2225. // }
  2226. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2227. // }
  2228. // //更新字典里面的库存
  2229. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2230. //
  2231. // //剩余库存
  2232. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2233. //
  2234. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2235. // //减少出库数量
  2236. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2237. //
  2238. // }
  2239. //}
  2240. }
  2241. }
  2242. }
  2243. //保存处方开药
  2244. if drugOutConfig.IsOpen == 1 {
  2245. //修改处方
  2246. for _, advice := range advices {
  2247. var drug_id int64
  2248. var prescribing_number float64
  2249. var prescribingNumberUnit string
  2250. var prescribingNumber string
  2251. var adviceId int64
  2252. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2253. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2254. }
  2255. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2256. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2257. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2258. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2259. }
  2260. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2261. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2262. }
  2263. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2264. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2265. }
  2266. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2267. if drug.ID == 0 {
  2268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2269. return
  2270. }
  2271. //查询药品的所有库存
  2272. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2273. var total_count int64
  2274. for _, it := range list {
  2275. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2276. }
  2277. totals := strconv.FormatInt(total_count, 10)
  2278. //查询该药品是否存在开药记录
  2279. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2280. //新增处方
  2281. if advicelist.ID == 0 {
  2282. //查询最新批次库存
  2283. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2284. var batch_number_count int64
  2285. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2286. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2287. all_count, _ := strconv.ParseFloat(totals, 64)
  2288. if prescribingNumberUnit == drug.MinUnit {
  2289. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2290. if drug.IsUse != 1 {
  2291. if drug.IsProject == 0 || drug.IsProject == 2 {
  2292. if all_count == 0 {
  2293. tx.Rollback()
  2294. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2295. return
  2296. }
  2297. if prescribing_number > all_count {
  2298. tx.Rollback()
  2299. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2300. return
  2301. }
  2302. }
  2303. if adminInfo.CurrentOrgId == 10215 {
  2304. if prescribing_number > batch_number_all_count {
  2305. tx.Rollback()
  2306. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2307. return
  2308. }
  2309. }
  2310. }
  2311. } else {
  2312. if prescribingNumberUnit == drug.MaxUnit {
  2313. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2314. num := prescribing_number * float64(drug.MinNumber)
  2315. if drug.IsUse != 1 {
  2316. if drug.IsProject == 0 || drug.IsProject == 2 {
  2317. if all_count == 0 {
  2318. tx.Rollback()
  2319. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2320. return
  2321. }
  2322. if num > all_count {
  2323. tx.Rollback()
  2324. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2325. return
  2326. }
  2327. }
  2328. if adminInfo.CurrentOrgId == 10215 {
  2329. if prescribing_number > batch_number_all_count {
  2330. tx.Rollback()
  2331. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2332. return
  2333. }
  2334. }
  2335. }
  2336. }
  2337. }
  2338. }
  2339. //修改处方
  2340. if advicelist.ID > 0 {
  2341. //查询最新批次库存
  2342. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2343. var batch_number_count int64
  2344. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2345. var device_number int64
  2346. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2347. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2348. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2349. device_number = prescribingNumberInt * drug.MinNumber
  2350. }
  2351. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2352. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2353. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2354. device_number = prescribingNumberInt
  2355. }
  2356. var number_count int64
  2357. if prescribingNumberUnit == drug.MaxUnit {
  2358. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2359. number_count = prescribingNumberInt * drug.MinNumber
  2360. }
  2361. if prescribingNumberUnit == drug.MinUnit {
  2362. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2363. number_count = prescribingNumberInt
  2364. }
  2365. //如果修改的数量大于之前修改的数量
  2366. if (number_count - device_number) > 0 {
  2367. //如果修改的差数量 大于库存数量
  2368. if drug.IsUse != 1 {
  2369. if drug.IsProject == 0 || drug.IsProject == 2 {
  2370. if total_count == 0 {
  2371. tx.Rollback()
  2372. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2373. return
  2374. }
  2375. if (number_count - device_number) > total_count {
  2376. tx.Rollback()
  2377. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2378. return
  2379. }
  2380. }
  2381. if adminInfo.CurrentOrgId == 10215 {
  2382. if (number_count - device_number) > batch_number_count {
  2383. tx.Rollback()
  2384. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2385. return
  2386. }
  2387. }
  2388. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2389. //查询历史出库数据总批次
  2390. // 查询该药品最后一次出库记录
  2391. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2392. var out_count int64
  2393. var in_count int64
  2394. var stock_max_number int64
  2395. var stock_min_number int64
  2396. for _, it := range outInfo {
  2397. if it.CountUnit == drug.MaxUnit {
  2398. it.Count = it.Count * drug.MinNumber
  2399. }
  2400. out_count += it.Count
  2401. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2402. stock_max_number = warehouseInfoList.StockMaxNumber
  2403. stock_min_number = warehouseInfoList.StockMinNumber
  2404. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2405. }
  2406. if out_count > 0 {
  2407. if (number_count - device_number) > in_count {
  2408. tx.Rollback()
  2409. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2410. return
  2411. }
  2412. }
  2413. // 未出库
  2414. if out_count == 0 {
  2415. var sum_in_count int64
  2416. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2417. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2418. if sum_in_count == 0 {
  2419. tx.Rollback()
  2420. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2421. return
  2422. }
  2423. //如果修改的数量大于有库存的第一个批次
  2424. if number_count > sum_in_count {
  2425. tx.Rollback()
  2426. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2427. return
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. }
  2437. }
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. //校验耗材库存
  2444. if goodOutConfig.IsOpen == 1 {
  2445. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2446. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2447. if len(prescriptions) > 0 {
  2448. for _, item := range prescriptions {
  2449. items := item.(map[string]interface{})
  2450. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2451. projects := items["project"].([]interface{})
  2452. if len(projects) > 0 {
  2453. for _, project := range projects {
  2454. var project_id int64
  2455. var project_type int64
  2456. var totals float64
  2457. var project_name string
  2458. var parsetotal int64
  2459. var id int64
  2460. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2461. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2462. }
  2463. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2464. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2465. }
  2466. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2467. total, _ := project.(map[string]interface{})["total"].(string)
  2468. totals, _ = strconv.ParseFloat(total, 64)
  2469. }
  2470. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2471. project_name = project.(map[string]interface{})["project_name"].(string)
  2472. }
  2473. if project_type == 3 {
  2474. //查找该耗材的出库记录
  2475. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2476. if len(goodWarehouseInfo) == 0 {
  2477. //查询耗材库存
  2478. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2479. var stock_count int64
  2480. for _, it := range list {
  2481. stock_count += it.StockCount
  2482. }
  2483. stock_counts := strconv.FormatInt(stock_count, 10)
  2484. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2485. if stock_total_count == 0 {
  2486. tx.Rollback()
  2487. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2488. return
  2489. }
  2490. if totals > stock_total_count {
  2491. tx.Rollback()
  2492. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2493. return
  2494. }
  2495. }
  2496. if len(goodWarehouseInfo) > 0 {
  2497. //查询该患者耗材的历史数据
  2498. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2499. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2500. //数量发生改变
  2501. if parsetotal != count {
  2502. //如果现在的数量大于历史数量,就要看库存是否足够
  2503. if parsetotal > count {
  2504. //查询耗材所有库存
  2505. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2506. var stock_count int64
  2507. for _, it := range list {
  2508. stock_count += it.StockCount
  2509. }
  2510. //库存不足
  2511. if stock_count == 0 {
  2512. tx.Rollback()
  2513. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2514. return
  2515. }
  2516. if (parsetotal - count) > stock_count {
  2517. tx.Rollback()
  2518. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2519. return
  2520. }
  2521. }
  2522. }
  2523. }
  2524. }
  2525. }
  2526. }
  2527. }
  2528. }
  2529. }
  2530. }
  2531. }
  2532. //不使用耗材保存处方出库
  2533. if goodOutConfig.IsOpen != 1 {
  2534. if stockConfig.IsOpen == 1 {
  2535. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2536. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2537. if len(prescriptions) > 0 {
  2538. for _, item := range prescriptions {
  2539. items := item.(map[string]interface{})
  2540. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2541. projects := items["project"].([]interface{})
  2542. if len(projects) > 0 {
  2543. for _, project := range projects {
  2544. var project_id int64
  2545. var project_type int64
  2546. var totals float64
  2547. var project_name string
  2548. var parsetotal int64
  2549. var id int64
  2550. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2551. id = int64(project.(map[string]interface{})["id"].(float64))
  2552. }
  2553. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2554. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2555. }
  2556. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2557. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2558. }
  2559. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2560. total, _ := project.(map[string]interface{})["total"].(string)
  2561. totals, _ = strconv.ParseFloat(total, 64)
  2562. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2563. }
  2564. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2565. project_name = project.(map[string]interface{})["project_name"].(string)
  2566. }
  2567. if project_type == 3 {
  2568. //查找该耗材的出库记录
  2569. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2570. //没有出库记录
  2571. if len(goodWarehouseInfo) == 0 {
  2572. //查询耗材库存
  2573. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2574. var stock_count int64
  2575. for _, it := range list {
  2576. stock_count += it.StockCount
  2577. }
  2578. stock_counts := strconv.FormatInt(stock_count, 10)
  2579. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2580. if stock_total_count == 0 {
  2581. tx.Rollback()
  2582. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2583. return
  2584. }
  2585. if totals > stock_total_count {
  2586. tx.Rollback()
  2587. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2588. return
  2589. }
  2590. //查找今日该患者已经出库的所有耗材
  2591. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2592. for _, item := range goodList {
  2593. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2594. var flush_count int64
  2595. for _, it := range goodListSix {
  2596. flush_count += it.StockCount
  2597. }
  2598. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2599. creater := adminInfo.AdminUser.Id
  2600. if errs != nil {
  2601. goodErrcode := models.XtGoodErrcode{
  2602. UserOrgId: item.OrgId,
  2603. Errcode: "手动出库更新剩余出库失败",
  2604. GoodId: item.GoodId,
  2605. Status: 1,
  2606. Ctime: time.Now().Unix(),
  2607. Mtime: 0,
  2608. Count: 0,
  2609. StockCount: 0,
  2610. Creater: creater,
  2611. BatchNumberId: 0,
  2612. WarehouseOutId: 0,
  2613. }
  2614. service.CreateGoodErrcode(goodErrcode)
  2615. }
  2616. }
  2617. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2618. }
  2619. //有出库记录
  2620. if len(goodWarehouseInfo) > 0 {
  2621. //查询该患者耗材的历史数据
  2622. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2623. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2624. //数量发生改变
  2625. if parsetotal != count {
  2626. //查找今日该患者已经出库的所有耗材
  2627. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2628. for _, item := range goodList {
  2629. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2630. var flush_count int64
  2631. for _, it := range goodListSix {
  2632. flush_count += it.StockCount
  2633. }
  2634. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2635. //减少出库数量
  2636. creater := adminInfo.AdminUser.Id
  2637. if errs != nil {
  2638. goodErrcode := models.XtGoodErrcode{
  2639. UserOrgId: item.OrgId,
  2640. Errcode: "手动出库更新剩余出库失败",
  2641. GoodId: item.GoodId,
  2642. Status: 1,
  2643. Ctime: time.Now().Unix(),
  2644. Mtime: 0,
  2645. Count: 0,
  2646. StockCount: 0,
  2647. Creater: creater,
  2648. BatchNumberId: 0,
  2649. WarehouseOutId: 0,
  2650. }
  2651. service.CreateGoodErrcode(goodErrcode)
  2652. }
  2653. //查询默认仓库
  2654. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2655. var total_count int64
  2656. for _, it := range stockList {
  2657. total_count += it.StockCount
  2658. }
  2659. //基础库插入数据
  2660. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2661. }
  2662. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2663. }
  2664. }
  2665. }
  2666. }
  2667. }
  2668. }
  2669. }
  2670. }
  2671. }
  2672. }
  2673. }
  2674. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2675. var hpInfo models.HisPrescriptionInfo
  2676. if info.ID == 0 {
  2677. var randNum int
  2678. randNum = rand.Intn(10000) + 1000
  2679. timestamp := time.Now().Unix()
  2680. tempTime := time.Unix(timestamp, 0)
  2681. timeFormat := tempTime.Format("20060102150405")
  2682. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2683. hpInfo = models.HisPrescriptionInfo{
  2684. HisPatientId: his_patient_id,
  2685. UserOrgId: adminInfo.CurrentOrgId,
  2686. RecordDate: theTime.Unix(),
  2687. PatientId: patient_id,
  2688. Status: 1,
  2689. Ctime: time.Now().Unix(),
  2690. Mtime: time.Now().Unix(),
  2691. Creator: adminInfo.AdminUser.Id,
  2692. Modifier: adminInfo.AdminUser.Id,
  2693. Diagnosis: diagnose,
  2694. SickHistory: sick_history,
  2695. Departments: department,
  2696. RegisterType: reg_type,
  2697. PrescriptionNumber: p_number,
  2698. PrescriptionStatus: 1,
  2699. Doctor: role.UserName,
  2700. DoctorId: doctor_id,
  2701. SickType: sick_type,
  2702. PType: p_type,
  2703. PatientDiagnosis: patient_diagnose,
  2704. }
  2705. service.SavePatientPrescriptionInfo(hpInfo)
  2706. //创建步骤表
  2707. finish := models.XtDialysisFinish{
  2708. IsFinish: 1,
  2709. UserOrgId: adminInfo.CurrentOrgId,
  2710. Status: 1,
  2711. Ctime: time.Now().Unix(),
  2712. Mtime: 0,
  2713. Module: 4,
  2714. RecordDate: theTime.Unix(),
  2715. Sourse: 1,
  2716. PatientId: patient_id,
  2717. }
  2718. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2719. if dialysisFinish.ID == 0 {
  2720. service.CreateDialysisFinish(finish)
  2721. }
  2722. redis := service.RedisClient()
  2723. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2724. redis.Set(key, "", time.Second)
  2725. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2726. redis.Set(keyOne, "", time.Second)
  2727. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2728. redis.Set(keySeven, "", time.Second)
  2729. defer redis.Close()
  2730. } else {
  2731. hpInfo = models.HisPrescriptionInfo{
  2732. ID: info.ID,
  2733. UserOrgId: adminInfo.CurrentOrgId,
  2734. RecordDate: info.RecordDate,
  2735. PatientId: info.PatientId,
  2736. Status: 1,
  2737. Ctime: info.Ctime,
  2738. Mtime: time.Now().Unix(),
  2739. Creator: info.Creator,
  2740. Modifier: adminInfo.AdminUser.Id,
  2741. Diagnosis: diagnose,
  2742. SickHistory: sick_history,
  2743. Departments: department,
  2744. RegisterType: reg_type,
  2745. PrescriptionNumber: info.PrescriptionNumber,
  2746. Doctor: role.UserName,
  2747. PrescriptionStatus: info.PrescriptionStatus,
  2748. DoctorId: doctor_id,
  2749. SickType: sick_type,
  2750. PType: info.PType,
  2751. HisPatientId: info.HisPatientId,
  2752. PatientDiagnosis: patient_diagnose,
  2753. }
  2754. service.SavePatientPrescriptionInfo(hpInfo)
  2755. //创建步骤表
  2756. finish := models.XtDialysisFinish{
  2757. IsFinish: 1,
  2758. UserOrgId: adminInfo.CurrentOrgId,
  2759. Status: 1,
  2760. Ctime: time.Now().Unix(),
  2761. Mtime: 0,
  2762. Module: 4,
  2763. RecordDate: info.RecordDate,
  2764. Sourse: 1,
  2765. PatientId: info.PatientId,
  2766. }
  2767. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2768. if dialysisFinish.ID == 0 {
  2769. service.CreateDialysisFinish(finish)
  2770. }
  2771. redis := service.RedisClient()
  2772. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2773. redis.Set(key, "", time.Second)
  2774. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2775. redis.Set(keyOne, "", time.Second)
  2776. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2777. redis.Set(keySeven, "", time.Second)
  2778. defer redis.Close()
  2779. }
  2780. //定义切片
  2781. var adviceList []models.HisDoctorAdviceInfo
  2782. var projectList []models.HisPrescriptionProject
  2783. 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 {
  2784. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2785. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2786. var tempPrescription *models.HisPrescription
  2787. if len(prescriptions) > 0 {
  2788. for _, item := range prescriptions {
  2789. // 开始外部循环的事务
  2790. tx := db.Begin()
  2791. // 在函数结束时处理事务回滚
  2792. defer func() {
  2793. if r := recover(); r != nil {
  2794. tx.Rollback()
  2795. }
  2796. }()
  2797. items := item.(map[string]interface{})
  2798. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2799. utils.ErrorLog("id")
  2800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2801. return
  2802. }
  2803. id := int64(items["id"].(float64))
  2804. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2805. tempPrescription = &new_prescription
  2806. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2807. utils.ErrorLog("type")
  2808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2809. return
  2810. }
  2811. types := int64(items["type"].(float64))
  2812. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2813. utils.ErrorLog("med_type")
  2814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2815. return
  2816. }
  2817. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2818. if med_type == "0" {
  2819. med_type = "14"
  2820. }
  2821. //if order_status == 0 {
  2822. // order_status = 1
  2823. //}
  2824. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2825. utils.ErrorLog("pre_time")
  2826. }
  2827. preTime, _ := items["pre_time"].(string)
  2828. fmt.Println("preTime", preTime)
  2829. timeLayout := "2006-01-02"
  2830. loc, _ := time.LoadLocation("Local")
  2831. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2832. //result := strings.Split(preTime, " ")
  2833. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2834. if err != nil {
  2835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2836. return
  2837. }
  2838. pTime := theTime2.Unix()
  2839. ctime := time.Now().Unix()
  2840. if tempPrescription.ID == 0 {
  2841. prescription := &models.HisPrescription{
  2842. ID: 0,
  2843. PatientId: patient_id,
  2844. UserOrgId: adminInfo.CurrentOrgId,
  2845. RecordDate: recordDateTime,
  2846. Ctime: ctime,
  2847. Mtime: ctime,
  2848. Type: types,
  2849. Modifier: adminInfo.AdminUser.Id,
  2850. Creator: adminInfo.AdminUser.Id,
  2851. Status: 1,
  2852. Doctor: role.UserName,
  2853. HisPatientId: his_patient_id,
  2854. OrderStatus: 1,
  2855. BatchNumber: "",
  2856. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2857. PreTime: pTime,
  2858. PType: p_type,
  2859. MedType: med_type,
  2860. }
  2861. tempPrescription = prescription
  2862. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2863. redis := service.RedisClient()
  2864. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2865. redis.Set(key, "", time.Second)
  2866. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2867. redis.Set(keyOne, "", time.Second)
  2868. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2869. redis.Set(keySeven, "", time.Second)
  2870. defer redis.Close()
  2871. } else {
  2872. tempPrescription.ID = id
  2873. tempPrescription.Type = types
  2874. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2875. tempPrescription.Mtime = time.Now().Unix()
  2876. tempPrescription.Doctor = role.UserName
  2877. //tempPrescription.OrderStatus = order_status
  2878. tempPrescription.PreTime = pTime
  2879. tempPrescription.MedType = med_type
  2880. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2881. redis := service.RedisClient()
  2882. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2883. redis.Set(key, "", time.Second)
  2884. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2885. redis.Set(keyOne, "", time.Second)
  2886. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2887. redis.Set(keySeven, "", time.Second)
  2888. defer redis.Close()
  2889. }
  2890. //service.SaveHisPrescription(prescription)
  2891. //更改患者挂号状态
  2892. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2893. fmt.Println("更改失败", err2)
  2894. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2895. advices := items["advices"].([]interface{})
  2896. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2897. groupNo := int64(0)
  2898. if len(advices) > 0 {
  2899. for _, advice := range advices {
  2900. tx := db.Begin()
  2901. // 在函数结束时处理事务回滚
  2902. defer func() {
  2903. if r := recover(); r != nil {
  2904. tx.Rollback()
  2905. }
  2906. }()
  2907. var s models.HisDoctorAdviceInfo
  2908. s.PrescriptionId = tempPrescription.ID
  2909. s.AdviceType = 2
  2910. s.AdviceDoctor = doctor_id
  2911. s.StopState = 2
  2912. s.ExecutionState = 2
  2913. s.AdviceDate = theTime3.Unix()
  2914. s.Status = 1
  2915. s.UserOrgId = adminInfo.CurrentOrgId
  2916. s.RecordDate = theTime3.Unix()
  2917. s.StartTime = tempPrescription.PreTime
  2918. s.Groupno = groupNo
  2919. s.PatientId = patient_id
  2920. s.HisPatientId = his_patient_id
  2921. s.StartTime = pTime
  2922. s.IsSettle = 2
  2923. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2924. if errcode > 0 {
  2925. c.ServeFailJSONWithSGJErrorCode(errcode)
  2926. return
  2927. }
  2928. s.StartTime = pTime
  2929. var total_count int64 //处方总库存
  2930. //查询改药品信息
  2931. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2932. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2933. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2934. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2935. total_count += prescribingNumberSeven * medical.MinNumber
  2936. }
  2937. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2938. total_count += prescribingNumberSeven
  2939. }
  2940. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2941. total_count += prescribingNumberSeven
  2942. }
  2943. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2944. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2945. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2946. if s.Price != lastWarehouse.RetailPrice {
  2947. s.Price = lastWarehouse.RetailPrice
  2948. }
  2949. if s.Price == 0 {
  2950. if lastWarehouse.ID == 0 {
  2951. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2952. s.Price = lastWarehouseTwo.RetailPrice
  2953. }
  2954. }
  2955. }
  2956. //查询保存处方出库开关是否打开
  2957. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2958. if s.PatientId != 30038 {
  2959. if drugOutConfig.IsOpen == 1 {
  2960. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2961. // 查询该药品最后一次出库记录
  2962. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2963. var is_user_total int64
  2964. var no_user_total int64
  2965. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2966. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2967. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2968. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2969. }
  2970. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2971. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2972. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2973. no_user_total += prescribingNumberSevenTy
  2974. }
  2975. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2976. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2977. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2978. no_user_total += prescribingNumberSevenTy
  2979. }
  2980. if len(druginfo) > 0 {
  2981. for _, it := range druginfo {
  2982. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2983. it.Count = it.Count * drug.MinNumber
  2984. is_user_total += it.Count
  2985. }
  2986. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2987. is_user_total += it.Count
  2988. }
  2989. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2990. is_user_total += it.Count
  2991. }
  2992. }
  2993. }
  2994. //fmt.Println("药品名称----------------------", drug.DrugName)
  2995. //fmt.Println("药品名称----------------------", drug.IsUse)
  2996. //fmt.Println("is_user_total-------------------------", is_user_total)
  2997. //fmt.Println("no_user_total-------------------------", no_user_total)
  2998. if is_user_total != no_user_total {
  2999. //出库
  3000. if drug.IsUse == 2 {
  3001. creater := adminInfo.AdminUser.Id
  3002. newadviceInfo := &models.HisDoctorAdviceInfo{
  3003. ID: s.ID,
  3004. UserOrgId: s.UserOrgId,
  3005. PatientId: s.PatientId,
  3006. HisPatientId: s.HisPatientId,
  3007. AdviceType: s.AdviceType,
  3008. AdviceDate: s.AdviceDate,
  3009. StartTime: s.StartTime,
  3010. AdviceName: s.AdviceName,
  3011. AdviceDesc: s.AdviceDesc,
  3012. ReminderDate: s.ReminderDate,
  3013. SingleDose: s.SingleDose,
  3014. SingleDoseUnit: s.SingleDoseUnit,
  3015. PrescribingNumber: s.PrescribingNumber,
  3016. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3017. DeliveryWay: s.DeliveryWay,
  3018. ExecutionFrequency: s.ExecutionFrequency,
  3019. AdviceDoctor: s.AdviceDoctor,
  3020. Status: s.Status,
  3021. CreatedTime: s.CreatedTime,
  3022. UpdatedTime: s.UpdatedTime,
  3023. AdviceAffirm: s.AdviceAffirm,
  3024. Remark: s.Remark,
  3025. StopTime: s.StopTime,
  3026. StopReason: s.StopReason,
  3027. StopDoctor: s.StopDoctor,
  3028. StopState: s.StopState,
  3029. ParentId: s.ParentId,
  3030. ExecutionTime: s.ExecutionTime,
  3031. ExecutionStaff: s.ExecutionStaff,
  3032. ExecutionState: s.ExecutionState,
  3033. Checker: s.Checker,
  3034. RecordDate: s.RecordDate,
  3035. DialysisOrderId: s.DialysisOrderId,
  3036. CheckTime: s.CheckTime,
  3037. CheckState: s.CheckState,
  3038. DrugSpec: s.DrugSpec,
  3039. DrugSpecUnit: s.DrugSpecUnit,
  3040. Groupno: s.Groupno,
  3041. RemindType: s.RemindType,
  3042. FrequencyType: s.FrequencyType,
  3043. DayCount: s.DayCount,
  3044. WeekDay: s.WeekDay,
  3045. TemplateId: s.TemplateId,
  3046. Modifier: s.Modifier,
  3047. DrugId: s.DrugId,
  3048. Price: s.Price,
  3049. PrescriptionId: s.PrescriptionId,
  3050. MedListCodg: s.MedListCodg,
  3051. FeedetlSn: s.FeedetlSn,
  3052. Day: s.DayCount,
  3053. ChildDoctorAdvice: nil,
  3054. Drug: models.Drug{},
  3055. Diagnosis: s.Diagnosis,
  3056. Way: s.Way,
  3057. HospApprFlag: s.HospApprFlag,
  3058. LmtUsedFlag: s.LmtUsedFlag,
  3059. HisOrderInfo: models.HisOrderInfo{},
  3060. IsMedicine: s.IsMedicine,
  3061. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3062. Child: nil,
  3063. IsSettle: s.IsSettle,
  3064. IsMobile: s.IsMobile,
  3065. IsSelfDrug: s.IsSelfDrug,
  3066. DrugWayCount: s.DrugWayCount,
  3067. }
  3068. var history_count int64
  3069. var local_count int64
  3070. //查找已经开过的医嘱信息
  3071. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3072. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3073. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3074. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3075. local_count += prescribingNumberSevenTy * drug.MinNumber
  3076. }
  3077. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3078. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3079. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3080. local_count += prescribingNumberSevenTy
  3081. }
  3082. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3083. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3084. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3085. local_count += prescribingNumberSevenTy
  3086. }
  3087. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3088. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3089. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3090. history_count += prescribingNumberSevenTy * drug.MinNumber
  3091. }
  3092. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3093. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3094. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3095. history_count += prescribingNumberSevenTy
  3096. }
  3097. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3098. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3099. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3100. history_count += prescribingNumberSevenTy
  3101. }
  3102. //如果当前出库数量大于历史出库数量则需要出库
  3103. if local_count > history_count {
  3104. //按最小单位出库
  3105. var cha_count = local_count - history_count
  3106. newadviceInfo.PrescribingNumber = float64(cha_count)
  3107. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3108. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3109. }
  3110. //如果当前出库数量小于历史出库数量则需要退库
  3111. if local_count < history_count {
  3112. var cha_count = history_count - local_count
  3113. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3114. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3115. }
  3116. if local_count == history_count {
  3117. if is_user_total == 0 {
  3118. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3119. }
  3120. }
  3121. }
  3122. //更新字典里面的库存
  3123. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3124. var sum_count int64
  3125. for _, its := range stockInfo {
  3126. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3127. if its.MaxUnit == baseDrug.MaxUnit {
  3128. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3129. }
  3130. sum_count += its.StockMaxNumber + its.StockMinNumber
  3131. }
  3132. //更新基础库存
  3133. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3134. //剩余库存
  3135. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3136. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3137. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3138. //创建医嘱
  3139. service.CreateHisDoctorAdviceOne(&s, tx)
  3140. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3141. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3142. if len(outInfoTwo) > 0 {
  3143. for _, item := range outInfoTwo {
  3144. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3145. }
  3146. }
  3147. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3148. if len(drugAutoDetail) > 0 {
  3149. for _, item := range drugAutoDetail {
  3150. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3151. }
  3152. }
  3153. }
  3154. }
  3155. }
  3156. //记录日志
  3157. byterequest, _ := json.Marshal(s)
  3158. adviceLog := models.XtDoctorAdviceLog{
  3159. UserOrgId: s.UserOrgId,
  3160. PatientId: s.PatientId,
  3161. AdminUserId: adminInfo.AdminUser.Id,
  3162. Module: 1,
  3163. ErrLog: string(byterequest),
  3164. Status: 1,
  3165. Ctime: time.Now().Unix(),
  3166. Mtime: 0,
  3167. Source: "电脑端新建his医嘱",
  3168. RecordDate: s.AdviceDate,
  3169. }
  3170. service.CreateDoctorAdviceLog(adviceLog)
  3171. //存储切片中
  3172. adviceList = append(adviceList, s)
  3173. redis := service.RedisClient()
  3174. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3175. redis.Set(key, "", time.Second)
  3176. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3177. redis.Set(keyOne, "", time.Second)
  3178. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3179. redis.Set(keySeven, "", time.Second)
  3180. var randNum int
  3181. randNum = rand.Intn(10000) + 1000
  3182. timestamp := time.Now().Unix()
  3183. tempTime := time.Unix(timestamp, 0)
  3184. timeFormat := tempTime.Format("20060102150405")
  3185. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3186. if s.UserOrgId != 10206 {
  3187. if s.ID == 0 {
  3188. //查询改药品是否已经停用
  3189. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3190. if base.ID > 0 {
  3191. tx.Rollback()
  3192. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3193. return
  3194. }
  3195. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3196. if drugMedical.SumCount == 0 {
  3197. tx.Rollback()
  3198. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3199. return
  3200. }
  3201. }
  3202. }
  3203. //赤峰
  3204. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3205. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3206. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3207. if info.RetailPrice > 0 {
  3208. if s.DeliveryWay == "口服" {
  3209. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3210. s.Price = drug.RetailPrice
  3211. }
  3212. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3213. s.Price = info.RetailPrice
  3214. }
  3215. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3216. s.Price = info.RetailPrice
  3217. }
  3218. }
  3219. }
  3220. }
  3221. service.CreateHisDoctorAdviceOne(&s, tx)
  3222. tx.Commit()
  3223. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3224. redis.Set(keySix, "", time.Second)
  3225. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3226. redis.Set(keyFive, "", time.Second)
  3227. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3228. redis.Set(keyEight, "", time.Second)
  3229. defer redis.Close()
  3230. }
  3231. }
  3232. }
  3233. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3234. projects := items["project"].([]interface{})
  3235. if len(projects) > 0 {
  3236. for _, project := range projects {
  3237. tx := db.Begin()
  3238. // 在函数结束时处理事务回滚
  3239. defer func() {
  3240. if r := recover(); r != nil {
  3241. tx.Rollback()
  3242. }
  3243. }()
  3244. var p models.HisPrescriptionProject
  3245. p.PrescriptionId = tempPrescription.ID
  3246. p.PatientId = patient_id
  3247. p.RecordDate = theTime3.Unix()
  3248. p.Doctor = doctor_id
  3249. p.UserOrgId = adminInfo.CurrentOrgId
  3250. p.HisPatientId = his_patient_id
  3251. p.Status = 1
  3252. p.StartTime = pTime
  3253. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3254. if errcode > 0 {
  3255. tx.Rollback()
  3256. c.ServeFailJSONWithSGJErrorCode(errcode)
  3257. return
  3258. }
  3259. if p.ID == 0 {
  3260. p.IsOut = 2
  3261. }
  3262. if p.ID > 0 {
  3263. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3264. p.IsOut = projectDetail.IsOut
  3265. }
  3266. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3267. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3268. if p.Type == 3 {
  3269. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3270. if p.Price != lastWarehouse.PackingPrice {
  3271. p.Price = lastWarehouse.PackingPrice
  3272. }
  3273. if p.Price == 0 {
  3274. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3275. p.Price = lastWarehouseTwo.PackingPrice
  3276. }
  3277. if p.Unit == "" {
  3278. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3279. p.Unit = goodInfoOne.PackingUnit
  3280. }
  3281. }
  3282. }
  3283. if adminInfo.CurrentOrgId != 10206 {
  3284. if p.Type == 3 {
  3285. if p.ID == 0 {
  3286. //查询该耗材是否停用
  3287. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3288. //表示该耗材已经停用,不能保存
  3289. if goodInfoSeven.ID == 0 {
  3290. tx.Rollback()
  3291. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3292. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3293. return
  3294. }
  3295. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3296. if goodInfoOne.SumCount == 0 {
  3297. tx.Rollback()
  3298. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3299. return
  3300. }
  3301. }
  3302. }
  3303. }
  3304. //查询保存耗材出库开关是否打开
  3305. if p.PatientId != 30038 {
  3306. if goodOutConfig.IsOpen == 1 {
  3307. //耗材出库
  3308. if p.Type == 3 {
  3309. //对比当前数据和历史出库数据
  3310. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3311. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3312. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3313. //fmt.Println("p----------------------------------------------------", p.ProjectId)
  3314. //fmt.Println("p----------------------------------------------------", nowCount)
  3315. //fmt.Println("p----------------------------------------------------", historyCount)
  3316. //如果当前处方数量大于历史数据,则需要出库
  3317. if nowCount > historyCount {
  3318. var cha_count int64
  3319. cha_count = nowCount - historyCount
  3320. timeStr := time.Now().Format("2006-01-02")
  3321. timeArr := strings.Split(timeStr, "-")
  3322. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3323. total = total + 1
  3324. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3325. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3326. number = number + total
  3327. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3328. operation_time := time.Now().Unix()
  3329. creater := c.GetAdminUserInfo().AdminUser.Id
  3330. recordDateStr := time.Now().Format("2006-01-02")
  3331. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3332. nowtime := recordDate.Unix()
  3333. warehouseOut := models.WarehouseOut{
  3334. WarehouseOutOrderNumber: warehousing_out_order,
  3335. OperationTime: operation_time,
  3336. OrgId: adminInfo.CurrentOrgId,
  3337. Creater: creater,
  3338. Ctime: time.Now().Unix(),
  3339. Status: 1,
  3340. WarehouseOutTime: nowtime,
  3341. Type: 1,
  3342. StorehouseId: storeConfig.StorehouseOutInfo,
  3343. IsCheck: 1,
  3344. IsSys: 1,
  3345. }
  3346. //查询是否生成出库单
  3347. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3348. if out.ID == 0 {
  3349. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3350. }
  3351. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3352. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3353. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3354. dialyPrepareOne := models.DialysisBeforePrepare{
  3355. GoodTypeId: goodObj.GoodTypeId,
  3356. GoodId: p.ProjectId,
  3357. PatientId: p.PatientId,
  3358. RecordDate: p.RecordDate,
  3359. UserOrgId: adminInfo.CurrentOrgId,
  3360. Count: cha_count,
  3361. Ctime: time.Now().Unix(),
  3362. Creater: creater,
  3363. Status: 1,
  3364. StorehouseId: houseConfig.StorehouseOutInfo,
  3365. ProjectId: p.ID,
  3366. }
  3367. //出库
  3368. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3369. }
  3370. //如果当前处方数量小于历史数据,怎需要退库
  3371. if nowCount < historyCount {
  3372. var cha_count int64
  3373. cha_count = historyCount - nowCount
  3374. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3375. creater := c.GetAdminUserInfo().AdminUser.Id
  3376. newPrescriptionProject := &models.HisPrescriptionProject{
  3377. ID: p.ID,
  3378. ProjectId: p.ProjectId,
  3379. Price: p.Price,
  3380. UserOrgId: p.UserOrgId,
  3381. Status: 1,
  3382. Ctime: time.Now().Unix(),
  3383. Mtime: time.Now().Unix(),
  3384. PatientId: p.PatientId,
  3385. HisPatientId: p.HisPatientId,
  3386. RecordDate: p.RecordDate,
  3387. PrescriptionId: p.PrescriptionId,
  3388. Count: p.Count,
  3389. FeedetlSn: p.FeedetlSn,
  3390. MedListCodg: p.MedListCodg,
  3391. SingleDose: p.SingleDose,
  3392. DeliveryWay: p.DeliveryWay,
  3393. ExecutionFrequency: p.ExecutionFrequency,
  3394. Day: p.Day,
  3395. HisProject: models.HisProject{},
  3396. GoodInfo: models.GoodInfo{},
  3397. Remark: p.Remark,
  3398. Unit: p.Unit,
  3399. Type: p.Type,
  3400. Doctor: p.Doctor,
  3401. ExecutionTime: p.ExecutionTime,
  3402. ExecutionStaff: p.ExecutionStaff,
  3403. ExecutionState: p.ExecutionState,
  3404. CheckTime: p.CheckTime,
  3405. CheckState: p.CheckState,
  3406. Checker: p.Checker,
  3407. StartTime: p.StartTime,
  3408. TeamId: p.TeamId,
  3409. XtHisProjectTeam: models.XtHisProjectTeam{},
  3410. FrequencyType: p.FrequencyType,
  3411. DayCount: p.DayCount,
  3412. WeekDay: p.WeekDay,
  3413. IsCheckTeam: p.IsCheckTeam,
  3414. HisOrderInfo: models.HisOrderInfo{},
  3415. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3416. IsOut: p.IsOut,
  3417. YbSyncStatus: p.YbSyncStatus,
  3418. }
  3419. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3420. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3421. }
  3422. if nowCount == historyCount {
  3423. if historyCount == 0 {
  3424. recordDateStr := time.Now().Format("2006-01-02")
  3425. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3426. nowtime := recordDate.Unix()
  3427. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3428. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3429. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3430. creater := c.GetAdminUserInfo().AdminUser.Id
  3431. dialyPrepareOne := models.DialysisBeforePrepare{
  3432. GoodTypeId: goodObj.GoodTypeId,
  3433. GoodId: p.ProjectId,
  3434. PatientId: p.PatientId,
  3435. RecordDate: p.RecordDate,
  3436. UserOrgId: adminInfo.CurrentOrgId,
  3437. Count: nowCount,
  3438. Ctime: time.Now().Unix(),
  3439. Creater: creater,
  3440. Status: 1,
  3441. StorehouseId: houseConfig.StorehouseOutInfo,
  3442. ProjectId: p.ID,
  3443. }
  3444. //出库
  3445. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3446. }
  3447. }
  3448. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3449. //查询历史出库数据
  3450. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3451. var out_count_five int64
  3452. for _, item := range flowGood {
  3453. out_count_five += item.Count
  3454. }
  3455. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3456. //fmt.Println("p.ProjectId-----------------", p.ProjectId)
  3457. //fmt.Println("out_count_five===============", out_count_five)
  3458. //fmt.Println("parseIntCount===============", parseIntCount)
  3459. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3460. if out_count_five != parseIntCount {
  3461. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3462. detail := models.AutomaticReduceDetail{
  3463. WarehouseOutId: 0,
  3464. WarehouseOutOrderNumber: "",
  3465. PatientId: p.PatientId,
  3466. Ctime: time.Now().Unix(),
  3467. Mtime: 0,
  3468. Status: 1,
  3469. RecordTime: p.RecordDate,
  3470. OrgId: p.UserOrgId,
  3471. GoodId: p.ProjectId,
  3472. GoodTypeId: 0,
  3473. Count: parseIntCount,
  3474. Type: 0,
  3475. ProjectId: lastHisProject.ID,
  3476. StorehouseId: 0,
  3477. }
  3478. service.CreateNewAutoDetail(detail, tx)
  3479. }
  3480. // //查询耗材最后一次出库记录
  3481. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3482. // //查询默认出库仓库库存
  3483. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3484. // if len(wareOut) > 0 {
  3485. //
  3486. // for _, it := range wareOut {
  3487. // //回退库存
  3488. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3489. //
  3490. // //删除出库记录
  3491. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3492. //
  3493. // }
  3494. // }
  3495. //
  3496. // timeStr := time.Now().Format("2006-01-02")
  3497. // timeArr := strings.Split(timeStr, "-")
  3498. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3499. //
  3500. // total = total + 1
  3501. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3502. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3503. // number = number + total
  3504. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3505. //
  3506. // operation_time := time.Now().Unix()
  3507. // creater := c.GetAdminUserInfo().AdminUser.Id
  3508. //
  3509. // recordDateStr := time.Now().Format("2006-01-02")
  3510. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3511. // nowtime := recordDate.Unix()
  3512. // warehouseOut := models.WarehouseOut{
  3513. // WarehouseOutOrderNumber: warehousing_out_order,
  3514. // OperationTime: operation_time,
  3515. // OrgId: adminInfo.CurrentOrgId,
  3516. // Creater: creater,
  3517. // Ctime: time.Now().Unix(),
  3518. // Status: 1,
  3519. // WarehouseOutTime: nowtime,
  3520. // Type: 1,
  3521. // StorehouseId: storeConfig.StorehouseOutInfo,
  3522. // IsCheck: 1,
  3523. // IsSys: 1,
  3524. // }
  3525. // //查询是否生成出库单
  3526. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3527. // if out.ID == 0 {
  3528. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3529. // }
  3530. //
  3531. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3532. //
  3533. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3534. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3535. //
  3536. // dialyPrepareOne := models.DialysisBeforePrepare{
  3537. // GoodTypeId: goodObj.GoodTypeId,
  3538. // GoodId: p.ProjectId,
  3539. // PatientId: p.PatientId,
  3540. // RecordDate: p.RecordDate,
  3541. // UserOrgId: adminInfo.CurrentOrgId,
  3542. // Count: parseIntCount,
  3543. // Ctime: time.Now().Unix(),
  3544. // Creater: creater,
  3545. // Status: 1,
  3546. // StorehouseId: houseConfig.StorehouseOutInfo,
  3547. // ProjectId: lastHisProject.ID,
  3548. // }
  3549. // //判断是否是零用耗材(非零用)
  3550. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3551. //
  3552. // //查询历史出库数据
  3553. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3554. // var out_count int64
  3555. // for _, item := range flowGood {
  3556. // out_count += item.Count
  3557. // }
  3558. // //如果历史数和当前数据不想等才进行退库出库
  3559. // if out_count != parseIntCount {
  3560. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3561. //
  3562. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3563. // detail := models.AutomaticReduceDetail{
  3564. // WarehouseOutId: 0,
  3565. // WarehouseOutOrderNumber: "",
  3566. // PatientId: p.PatientId,
  3567. // Ctime: time.Now().Unix(),
  3568. // Mtime: 0,
  3569. // Status: 1,
  3570. // RecordTime: p.RecordDate,
  3571. // OrgId: p.UserOrgId,
  3572. // GoodId: p.ProjectId,
  3573. // GoodTypeId: 0,
  3574. // Count: parseIntCount,
  3575. // Type: 0,
  3576. // ProjectId: lastHisProject.ID,
  3577. // StorehouseId: 0,
  3578. // }
  3579. //
  3580. // service.CreateNewAutoDetail(detail, tx)
  3581. //
  3582. // //查询剩余库存
  3583. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3584. // var sum_count int64
  3585. // for _, item := range goodList {
  3586. // sum_count += item.StockCount
  3587. // }
  3588. //
  3589. // //更新剩余库存
  3590. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3591. //
  3592. // //耗材
  3593. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3594. //
  3595. // }
  3596. // //判断是否是零用耗材(零用但是是出库耗材)
  3597. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3598. //
  3599. // //查询历史出库数据
  3600. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3601. // var out_count int64
  3602. // for _, item := range flowGood {
  3603. // out_count += item.Count
  3604. // }
  3605. // //如果历史数和当前数据不想等才进行退库出库
  3606. // if out_count != parseIntCount {
  3607. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3608. //
  3609. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3610. // detail := models.AutomaticReduceDetail{
  3611. // WarehouseOutId: 0,
  3612. // WarehouseOutOrderNumber: "",
  3613. // PatientId: p.PatientId,
  3614. // Ctime: time.Now().Unix(),
  3615. // Mtime: 0,
  3616. // Status: 1,
  3617. // RecordTime: p.RecordDate,
  3618. // OrgId: p.UserOrgId,
  3619. // GoodId: p.ProjectId,
  3620. // GoodTypeId: 0,
  3621. // Count: parseIntCount,
  3622. // Type: 0,
  3623. // ProjectId: p.ID,
  3624. // StorehouseId: 0,
  3625. // }
  3626. //
  3627. // service.CreateNewAutoDetail(detail, tx)
  3628. //
  3629. // //查询剩余库存
  3630. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3631. // var sum_count int64
  3632. // for _, item := range goodList {
  3633. // sum_count += item.StockCount
  3634. // }
  3635. //
  3636. // //更新剩余库存
  3637. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3638. //
  3639. // //耗材
  3640. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3641. // }
  3642. //
  3643. // }
  3644. //
  3645. // }
  3646. //
  3647. //}
  3648. //记录日志
  3649. byterequest, _ := json.Marshal(p)
  3650. adviceLog := models.XtDoctorAdviceLog{
  3651. UserOrgId: p.UserOrgId,
  3652. PatientId: p.PatientId,
  3653. AdminUserId: adminInfo.AdminUser.Id,
  3654. Module: 1,
  3655. ErrLog: string(byterequest),
  3656. Status: 1,
  3657. Ctime: time.Now().Unix(),
  3658. Mtime: 0,
  3659. Source: "电脑端新建his项目",
  3660. RecordDate: p.RecordDate,
  3661. }
  3662. service.CreateDoctorAdviceLog(adviceLog)
  3663. projectList = append(projectList, p)
  3664. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3665. //新增或者编辑项目,修改对应的标签数据
  3666. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3667. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3668. var label models.HisLabelPrintInfo
  3669. project, _ := service.GetProjectDetail(p.ProjectId)
  3670. if project.CostClassify == 3 { //类别为检验检查
  3671. if p.TeamId > 0 { //检验检查组套
  3672. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3673. if tempLabel.ID == 0 {
  3674. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3675. label.Number = tempPrescription.PrescriptionNumber
  3676. label.ProjectId = project.ID
  3677. label.Status = 1
  3678. label.IsPrint = 2
  3679. label.DoctorId = info.DoctorId
  3680. label.UserOrgId = p.UserOrgId
  3681. label.PatientId = patient_id
  3682. label.RecordDate = recordDateTime
  3683. label.Ctime = time.Now().Unix()
  3684. label.Mtime = time.Now().Unix()
  3685. label.ItemId = p.TeamId
  3686. label.FeedetlSn = p.FeedetlSn
  3687. label.PProjectId = p.ID
  3688. label.ProjectName = team.ProjectTeam
  3689. label.PatientName = patient.Name
  3690. service.CreateNewHisLabelRecord(&label, tx)
  3691. }
  3692. } else { //单条检验检查项目
  3693. label.Number = tempPrescription.PrescriptionNumber
  3694. label.ProjectId = project.ID
  3695. label.Status = 1
  3696. label.DoctorId = info.DoctorId
  3697. label.UserOrgId = p.UserOrgId
  3698. label.PatientId = patient_id
  3699. label.RecordDate = recordDateTime
  3700. label.IsPrint = 2
  3701. label.Ctime = time.Now().Unix()
  3702. label.Mtime = time.Now().Unix()
  3703. label.FeedetlSn = p.FeedetlSn
  3704. label.PProjectId = p.ID
  3705. label.ItemId = p.TeamId
  3706. label.ProjectName = project.ProjectName
  3707. label.PatientName = patient.Name
  3708. service.CreateNewHisLabelRecord(&label, tx)
  3709. }
  3710. }
  3711. }
  3712. }
  3713. }
  3714. }
  3715. }
  3716. //插入检验数据
  3717. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3718. //新增或者编辑项目,修改对应的标签数据
  3719. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3720. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3721. var label models.HisLabelPrintInfo
  3722. project, _ := service.GetProjectDetail(p.ProjectId)
  3723. if project.CostClassify == 3 { //类别为检验检查
  3724. if p.TeamId > 0 { //检验检查组套
  3725. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3726. if tempLabel.ID == 0 {
  3727. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3728. label.Number = tempPrescription.PrescriptionNumber
  3729. label.ProjectId = project.ID
  3730. label.Status = 1
  3731. label.IsPrint = 2
  3732. label.DoctorId = info.DoctorId
  3733. label.UserOrgId = p.UserOrgId
  3734. label.PatientId = patient_id
  3735. label.RecordDate = recordDateTime
  3736. label.Ctime = time.Now().Unix()
  3737. label.Mtime = time.Now().Unix()
  3738. label.ItemId = p.TeamId
  3739. label.FeedetlSn = p.FeedetlSn
  3740. label.PProjectId = p.ID
  3741. label.ProjectName = team.ProjectTeam
  3742. label.PatientName = patient.Name
  3743. service.CreateHisLabelRecord(&label)
  3744. }
  3745. } else { //单条检验检查项目
  3746. label.Number = tempPrescription.PrescriptionNumber
  3747. label.ProjectId = project.ID
  3748. label.Status = 1
  3749. label.DoctorId = info.DoctorId
  3750. label.UserOrgId = p.UserOrgId
  3751. label.PatientId = patient_id
  3752. label.RecordDate = recordDateTime
  3753. label.IsPrint = 2
  3754. label.Ctime = time.Now().Unix()
  3755. label.Mtime = time.Now().Unix()
  3756. label.FeedetlSn = p.FeedetlSn
  3757. label.PProjectId = p.ID
  3758. label.ItemId = p.TeamId
  3759. label.ProjectName = project.ProjectName
  3760. label.PatientName = patient.Name
  3761. service.CreateHisLabelRecord(&label)
  3762. }
  3763. }
  3764. }
  3765. }
  3766. service.CreateNewHisProjectTwo(&p, tx)
  3767. var randNum int
  3768. randNum = rand.Intn(10000) + 1000
  3769. timestamp := time.Now().Unix()
  3770. tempTime := time.Unix(timestamp, 0)
  3771. timeFormat := tempTime.Format("20060102150405")
  3772. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3773. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3774. if goodBase.ID > 0 {
  3775. tx.Rollback()
  3776. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3777. return
  3778. }
  3779. service.CreateNewHisProjectTwo(&p, tx)
  3780. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3781. //查询剩余库存
  3782. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3783. var sum_count int64
  3784. for _, item := range goodList {
  3785. sum_count += item.StockCount
  3786. }
  3787. //更新剩余库存
  3788. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3789. //耗材
  3790. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3791. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3792. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3793. if len(outInfoTwo) > 0 {
  3794. for _, item := range outInfoTwo {
  3795. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3796. }
  3797. }
  3798. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3799. if len(drugAutoDetail) > 0 {
  3800. for _, item := range drugAutoDetail {
  3801. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3802. }
  3803. }
  3804. tx.Commit()
  3805. }
  3806. }
  3807. }
  3808. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3809. // addition := items["addition"].([]interface{})
  3810. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3811. // ctime := time.Now().Unix()
  3812. // mtime := ctime
  3813. // if len(addition) > 0 {
  3814. // for _, item := range addition {
  3815. // var s models.HisAdditionalCharge
  3816. // s.PrescriptionId = tempPrescription.ID
  3817. // s.Status = 1
  3818. // s.UserOrgId = adminInfo.CurrentOrgId
  3819. // s.RecordDate = recordDateTime
  3820. // s.CreatedTime = ctime
  3821. // s.UpdatedTime = mtime
  3822. // s.PatientId = patient_id
  3823. // s.HisPatientId = his_patient_id
  3824. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3825. // if errcode > 0 {
  3826. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3827. // return
  3828. // }
  3829. // service.CreateAdditionalCharge(&s)
  3830. // var randNum int
  3831. // randNum = rand.Intn(10000) + 1000
  3832. // timestamp := time.Now().Unix()
  3833. // tempTime := time.Unix(timestamp, 0)
  3834. // timeFormat := tempTime.Format("20060102150405")
  3835. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3836. // service.CreateAdditionalCharge(&s)
  3837. //
  3838. // }
  3839. // }
  3840. //}
  3841. }
  3842. }
  3843. }
  3844. tx.Commit()
  3845. if err == nil {
  3846. c.ServeSuccessJSON(map[string]interface{}{
  3847. "msg": "保存成功",
  3848. })
  3849. return
  3850. } else {
  3851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3852. return
  3853. }
  3854. } else {
  3855. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3856. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3857. var tempPrescription *models.HisPrescription
  3858. if len(prescriptions) > 0 {
  3859. for _, item := range prescriptions {
  3860. items := item.(map[string]interface{})
  3861. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3862. utils.ErrorLog("id")
  3863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3864. return
  3865. }
  3866. id := int64(items["id"].(float64))
  3867. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3868. tempPrescription = &new_prescription
  3869. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3870. utils.ErrorLog("type")
  3871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3872. return
  3873. }
  3874. types := int64(items["type"].(float64))
  3875. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3876. utils.ErrorLog("med_type")
  3877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3878. return
  3879. }
  3880. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3881. if med_type == "0" {
  3882. med_type = "14"
  3883. }
  3884. //if order_status == 0 {
  3885. // order_status = 1
  3886. //}
  3887. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3888. utils.ErrorLog("pre_time")
  3889. }
  3890. preTime, _ := items["pre_time"].(string)
  3891. timeLayout := "2006-01-02"
  3892. loc, _ := time.LoadLocation("Local")
  3893. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3894. //result := strings.Split(preTime, " ")
  3895. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3896. if err != nil {
  3897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3898. return
  3899. }
  3900. pTime := theTime2.Unix()
  3901. ctime := time.Now().Unix()
  3902. if tempPrescription.ID == 0 {
  3903. prescription := &models.HisPrescription{
  3904. ID: 0,
  3905. PatientId: patient_id,
  3906. UserOrgId: adminInfo.CurrentOrgId,
  3907. RecordDate: recordDateTime,
  3908. Ctime: ctime,
  3909. Mtime: ctime,
  3910. Type: types,
  3911. Modifier: adminInfo.AdminUser.Id,
  3912. Creator: adminInfo.AdminUser.Id,
  3913. Status: 1,
  3914. Doctor: role.UserName,
  3915. HisPatientId: his_patient_id,
  3916. OrderStatus: 1,
  3917. BatchNumber: "",
  3918. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3919. PreTime: pTime,
  3920. PType: p_type,
  3921. MedType: med_type,
  3922. }
  3923. tempPrescription = prescription
  3924. service.SaveHisPrescription(tempPrescription)
  3925. redis := service.RedisClient()
  3926. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3927. redis.Set(key, "", time.Second)
  3928. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3929. redis.Set(keyOne, "", time.Second)
  3930. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3931. redis.Set(keySeven, "", time.Second)
  3932. defer redis.Close()
  3933. } else {
  3934. tempPrescription.ID = id
  3935. tempPrescription.Type = types
  3936. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3937. tempPrescription.Mtime = time.Now().Unix()
  3938. tempPrescription.Doctor = role.UserName
  3939. //tempPrescription.OrderStatus = order_status
  3940. tempPrescription.PreTime = pTime
  3941. tempPrescription.MedType = med_type
  3942. service.SaveHisPrescription(tempPrescription)
  3943. redis := service.RedisClient()
  3944. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3945. redis.Set(key, "", time.Second)
  3946. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3947. redis.Set(keyOne, "", time.Second)
  3948. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3949. redis.Set(keySeven, "", time.Second)
  3950. defer redis.Close()
  3951. }
  3952. //service.SaveHisPrescription(prescription)
  3953. //更改患者挂号状态
  3954. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3955. fmt.Println("更改失败", err2)
  3956. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3957. advices := items["advices"].([]interface{})
  3958. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3959. groupNo := int64(0)
  3960. if len(advices) > 0 {
  3961. for _, advice := range advices {
  3962. var s models.HisDoctorAdviceInfo
  3963. s.PrescriptionId = tempPrescription.ID
  3964. s.AdviceType = 2
  3965. s.AdviceDoctor = doctor_id
  3966. s.StopState = 2
  3967. s.ExecutionState = 2
  3968. s.AdviceDate = theTime3.Unix()
  3969. s.Status = 1
  3970. s.UserOrgId = adminInfo.CurrentOrgId
  3971. s.RecordDate = theTime3.Unix()
  3972. s.StartTime = tempPrescription.PreTime
  3973. s.Groupno = groupNo
  3974. s.PatientId = patient_id
  3975. s.HisPatientId = his_patient_id
  3976. s.StartTime = pTime
  3977. s.IsSettle = 2
  3978. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3979. if errcode > 0 {
  3980. c.ServeFailJSONWithSGJErrorCode(errcode)
  3981. return
  3982. }
  3983. s.StartTime = pTime
  3984. var total_count int64 //处方总库存
  3985. //查询改药品信息
  3986. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3987. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3988. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3989. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3990. total_count += prescribingNumberSeven * medical.MinNumber
  3991. }
  3992. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3993. total_count += prescribingNumberSeven
  3994. }
  3995. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3996. total_count += prescribingNumberSeven
  3997. }
  3998. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3999. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4000. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4001. if s.Price != lastWarehouse.RetailPrice {
  4002. s.Price = lastWarehouse.RetailPrice
  4003. }
  4004. if s.Price == 0 {
  4005. if lastWarehouse.ID == 0 {
  4006. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4007. s.Price = lastWarehouseTwo.RetailPrice
  4008. }
  4009. }
  4010. }
  4011. if adminInfo.CurrentOrgId != 10206 {
  4012. if s.ID == 0 {
  4013. //查询改药品是否已经停用
  4014. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4015. if base.ID > 0 {
  4016. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4017. return
  4018. }
  4019. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4020. if drugMedical.SumCount == 0 {
  4021. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4022. return
  4023. }
  4024. }
  4025. }
  4026. //赤峰
  4027. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4028. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4029. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4030. if info.RetailPrice > 0 {
  4031. if s.DeliveryWay == "口服" {
  4032. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4033. s.Price = drug.RetailPrice
  4034. }
  4035. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4036. s.Price = info.RetailPrice
  4037. }
  4038. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4039. s.Price = info.RetailPrice
  4040. }
  4041. }
  4042. }
  4043. }
  4044. service.CreateHisDoctorAdvice(&s)
  4045. //记录日志
  4046. byterequest, _ := json.Marshal(s)
  4047. adviceLog := models.XtDoctorAdviceLog{
  4048. UserOrgId: s.UserOrgId,
  4049. PatientId: s.PatientId,
  4050. AdminUserId: adminInfo.AdminUser.Id,
  4051. Module: 1,
  4052. ErrLog: string(byterequest),
  4053. Status: 1,
  4054. Ctime: time.Now().Unix(),
  4055. Mtime: 0,
  4056. Source: "电脑端新建his医嘱",
  4057. RecordDate: s.AdviceDate,
  4058. }
  4059. service.CreateDoctorAdviceLog(adviceLog)
  4060. //存储切片中
  4061. adviceList = append(adviceList, s)
  4062. redis := service.RedisClient()
  4063. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4064. redis.Set(key, "", time.Second)
  4065. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4066. redis.Set(keyOne, "", time.Second)
  4067. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4068. redis.Set(keySeven, "", time.Second)
  4069. var randNum int
  4070. randNum = rand.Intn(10000) + 1000
  4071. timestamp := time.Now().Unix()
  4072. tempTime := time.Unix(timestamp, 0)
  4073. timeFormat := tempTime.Format("20060102150405")
  4074. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4075. service.CreateHisDoctorAdvice(&s)
  4076. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4077. redis.Set(keySix, "", time.Second)
  4078. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4079. redis.Set(keyFive, "", time.Second)
  4080. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4081. redis.Set(keyEight, "", time.Second)
  4082. defer redis.Close()
  4083. }
  4084. }
  4085. }
  4086. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4087. projects := items["project"].([]interface{})
  4088. if len(projects) > 0 {
  4089. for _, project := range projects {
  4090. var p models.HisPrescriptionProject
  4091. p.PrescriptionId = tempPrescription.ID
  4092. p.PatientId = patient_id
  4093. p.RecordDate = theTime3.Unix()
  4094. p.Doctor = doctor_id
  4095. p.UserOrgId = adminInfo.CurrentOrgId
  4096. p.HisPatientId = his_patient_id
  4097. p.Status = 1
  4098. p.StartTime = pTime
  4099. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4100. if errcode > 0 {
  4101. c.ServeFailJSONWithSGJErrorCode(errcode)
  4102. return
  4103. }
  4104. if p.ID == 0 {
  4105. p.IsOut = 2
  4106. }
  4107. if p.ID > 0 {
  4108. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4109. p.IsOut = projectDetail.IsOut
  4110. }
  4111. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4112. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4113. if p.Type == 3 {
  4114. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4115. if p.Price != lastWarehouse.PackingPrice {
  4116. p.Price = lastWarehouse.PackingPrice
  4117. }
  4118. if p.Price == 0 {
  4119. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4120. p.Price = lastWarehouseTwo.PackingPrice
  4121. }
  4122. if p.Unit == "" {
  4123. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4124. p.Unit = goodInfoOne.PackingUnit
  4125. }
  4126. }
  4127. }
  4128. if adminInfo.CurrentOrgId != 10206 {
  4129. if p.Type == 3 {
  4130. if p.ID == 0 {
  4131. //查询该耗材是否停用
  4132. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4133. //表示该耗材已经停用,不能保存
  4134. if goodInfoSeven.ID == 0 {
  4135. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4136. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4137. return
  4138. }
  4139. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4140. if goodInfoOne.SumCount == 0 {
  4141. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4142. return
  4143. }
  4144. }
  4145. }
  4146. }
  4147. service.CreateHisProjectTwo(&p)
  4148. //记录日志
  4149. byterequest, _ := json.Marshal(p)
  4150. adviceLog := models.XtDoctorAdviceLog{
  4151. UserOrgId: p.UserOrgId,
  4152. PatientId: p.PatientId,
  4153. AdminUserId: adminInfo.AdminUser.Id,
  4154. Module: 1,
  4155. ErrLog: string(byterequest),
  4156. Status: 1,
  4157. Ctime: time.Now().Unix(),
  4158. Mtime: 0,
  4159. Source: "电脑端新建his项目",
  4160. RecordDate: p.RecordDate,
  4161. }
  4162. service.CreateDoctorAdviceLog(adviceLog)
  4163. projectList = append(projectList, p)
  4164. var randNum int
  4165. randNum = rand.Intn(10000) + 1000
  4166. timestamp := time.Now().Unix()
  4167. tempTime := time.Unix(timestamp, 0)
  4168. timeFormat := tempTime.Format("20060102150405")
  4169. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4170. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4171. //新增或者编辑项目,修改对应的标签数据
  4172. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4173. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4174. var label models.HisLabelPrintInfo
  4175. project, _ := service.GetProjectDetail(p.ProjectId)
  4176. if project.CostClassify == 3 { //类别为检验检查
  4177. if p.TeamId > 0 { //检验检查组套
  4178. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4179. if tempLabel.ID == 0 {
  4180. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4181. label.Number = tempPrescription.PrescriptionNumber
  4182. label.ProjectId = project.ID
  4183. label.Status = 1
  4184. label.IsPrint = 2
  4185. label.DoctorId = info.DoctorId
  4186. label.UserOrgId = p.UserOrgId
  4187. label.PatientId = patient_id
  4188. label.RecordDate = recordDateTime
  4189. label.Ctime = time.Now().Unix()
  4190. label.Mtime = time.Now().Unix()
  4191. label.ItemId = p.TeamId
  4192. label.FeedetlSn = p.FeedetlSn
  4193. label.PProjectId = p.ID
  4194. label.ProjectName = team.ProjectTeam
  4195. label.PatientName = patient.Name
  4196. service.CreateHisLabelRecord(&label)
  4197. }
  4198. } else { //单条检验检查项目
  4199. label.Number = tempPrescription.PrescriptionNumber
  4200. label.ProjectId = project.ID
  4201. label.Status = 1
  4202. label.DoctorId = info.DoctorId
  4203. label.UserOrgId = p.UserOrgId
  4204. label.PatientId = patient_id
  4205. label.RecordDate = recordDateTime
  4206. label.IsPrint = 2
  4207. label.Ctime = time.Now().Unix()
  4208. label.Mtime = time.Now().Unix()
  4209. label.FeedetlSn = p.FeedetlSn
  4210. label.PProjectId = p.ID
  4211. label.ItemId = p.TeamId
  4212. label.ProjectName = project.ProjectName
  4213. label.PatientName = patient.Name
  4214. service.CreateHisLabelRecord(&label)
  4215. }
  4216. }
  4217. }
  4218. }
  4219. service.SaveHisProjectTwo(&p)
  4220. }
  4221. }
  4222. }
  4223. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4224. // addition := items["addition"].([]interface{})
  4225. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4226. // ctime := time.Now().Unix()
  4227. // mtime := ctime
  4228. // if len(addition) > 0 {
  4229. // for _, item := range addition {
  4230. // var s models.HisAdditionalCharge
  4231. // s.PrescriptionId = tempPrescription.ID
  4232. // s.Status = 1
  4233. // s.UserOrgId = adminInfo.CurrentOrgId
  4234. // s.RecordDate = recordDateTime
  4235. // s.CreatedTime = ctime
  4236. // s.UpdatedTime = mtime
  4237. // s.PatientId = patient_id
  4238. // s.HisPatientId = his_patient_id
  4239. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4240. // if errcode > 0 {
  4241. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4242. // return
  4243. // }
  4244. // service.CreateAdditionalCharge(&s)
  4245. // var randNum int
  4246. // randNum = rand.Intn(10000) + 1000
  4247. // timestamp := time.Now().Unix()
  4248. // tempTime := time.Unix(timestamp, 0)
  4249. // timeFormat := tempTime.Format("20060102150405")
  4250. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4251. // service.CreateAdditionalCharge(&s)
  4252. //
  4253. // }
  4254. // }
  4255. //}
  4256. }
  4257. }
  4258. //查询今日该患者开的药品处方
  4259. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4260. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4261. //药品出库
  4262. if drugOutConfig.IsOpen == 1 {
  4263. for _, item := range hisdoctorlist {
  4264. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4265. // 查询该药品最后一次出库记录
  4266. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4267. if len(druginfo) > 0 {
  4268. //回退库存
  4269. for _, it := range druginfo {
  4270. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4271. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4272. }
  4273. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4274. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4275. }
  4276. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4277. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4278. }
  4279. }
  4280. }
  4281. //删除记录
  4282. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4283. //查询最后一次数据
  4284. if drugOutConfig.IsOpen == 1 {
  4285. //出库
  4286. if drug.IsUse == 2 {
  4287. creater := adminInfo.AdminUser.Id
  4288. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4289. }
  4290. //更新字典里面的库存
  4291. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4292. var sum_count int64
  4293. for _, its := range stockInfo {
  4294. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4295. if its.MaxUnit == baseDrug.MaxUnit {
  4296. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4297. }
  4298. sum_count += its.StockMaxNumber + its.StockMinNumber
  4299. }
  4300. //更新基础库存
  4301. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4302. //剩余库存
  4303. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4304. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4305. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4306. }
  4307. }
  4308. }
  4309. //耗材保存处方出库
  4310. if goodOutConfig.IsOpen == 1 {
  4311. //查询今日耗材出库数量
  4312. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4313. for _, item := range hisgoodlist {
  4314. //查询历史出库数据
  4315. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4316. var out_count_five int64
  4317. for _, item := range flowGood {
  4318. out_count_five += item.Count
  4319. }
  4320. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4321. if out_count_five != parseIntCount {
  4322. //查询耗材最后一次出库记录
  4323. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4324. //查询默认出库仓库库存
  4325. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4326. if len(wareOut) > 0 {
  4327. for _, it := range wareOut {
  4328. //回退库存
  4329. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4330. //删除出库记录
  4331. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4332. }
  4333. }
  4334. timeStr := time.Now().Format("2006-01-02")
  4335. timeArr := strings.Split(timeStr, "-")
  4336. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4337. total = total + 1
  4338. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4339. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4340. number = number + total
  4341. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4342. operation_time := time.Now().Unix()
  4343. creater := c.GetAdminUserInfo().AdminUser.Id
  4344. recordDateStr := time.Now().Format("2006-01-02")
  4345. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4346. nowtime := recordDate.Unix()
  4347. warehouseOut := models.WarehouseOut{
  4348. WarehouseOutOrderNumber: warehousing_out_order,
  4349. OperationTime: operation_time,
  4350. OrgId: adminInfo.CurrentOrgId,
  4351. Creater: creater,
  4352. Ctime: time.Now().Unix(),
  4353. Status: 1,
  4354. WarehouseOutTime: nowtime,
  4355. Type: 1,
  4356. StorehouseId: storeConfig.StorehouseOutInfo,
  4357. IsCheck: 1,
  4358. IsSys: 1,
  4359. }
  4360. //查询是否生成出库单
  4361. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4362. if out.ID == 0 {
  4363. service.AddSigleWarehouseOut(&warehouseOut)
  4364. }
  4365. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4366. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4367. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4368. dialyPrepareOne := models.DialysisBeforePrepare{
  4369. GoodTypeId: goodObj.GoodTypeId,
  4370. GoodId: item.ProjectId,
  4371. PatientId: item.PatientId,
  4372. RecordDate: item.RecordDate,
  4373. UserOrgId: adminInfo.CurrentOrgId,
  4374. Count: parseIntCount,
  4375. Ctime: time.Now().Unix(),
  4376. Creater: creater,
  4377. Status: 1,
  4378. StorehouseId: houseConfig.StorehouseOutInfo,
  4379. ProjectId: item.ID,
  4380. }
  4381. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4382. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4383. //查询历史出库数据
  4384. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4385. var out_count int64
  4386. for _, item := range flowGood {
  4387. out_count += item.Count
  4388. }
  4389. //如果历史数和当前数据不想等才进行退库出库
  4390. if out_count != parseIntCount {
  4391. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4392. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4393. detail := models.AutomaticReduceDetail{
  4394. WarehouseOutId: 0,
  4395. WarehouseOutOrderNumber: "",
  4396. PatientId: item.PatientId,
  4397. Ctime: time.Now().Unix(),
  4398. Mtime: 0,
  4399. Status: 1,
  4400. RecordTime: item.RecordDate,
  4401. OrgId: item.UserOrgId,
  4402. GoodId: item.ProjectId,
  4403. GoodTypeId: 0,
  4404. Count: parseIntCount,
  4405. Type: 0,
  4406. ProjectId: item.ID,
  4407. StorehouseId: 0,
  4408. }
  4409. service.CreateAutoDetail(detail)
  4410. //查询剩余库存
  4411. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4412. var sum_count int64
  4413. for _, item := range goodList {
  4414. sum_count += item.StockCount
  4415. }
  4416. //更新剩余库存
  4417. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4418. //耗材
  4419. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4420. }
  4421. }
  4422. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4423. //查询历史出库数据
  4424. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4425. var out_count int64
  4426. for _, item := range flowGood {
  4427. out_count += item.Count
  4428. }
  4429. //如果历史数和当前数据不想等才进行退库出库
  4430. if out_count != parseIntCount {
  4431. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4432. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4433. detail := models.AutomaticReduceDetail{
  4434. WarehouseOutId: 0,
  4435. WarehouseOutOrderNumber: "",
  4436. PatientId: item.PatientId,
  4437. Ctime: time.Now().Unix(),
  4438. Mtime: 0,
  4439. Status: 1,
  4440. RecordTime: item.RecordDate,
  4441. OrgId: item.UserOrgId,
  4442. GoodId: item.ProjectId,
  4443. GoodTypeId: 0,
  4444. Count: parseIntCount,
  4445. Type: 0,
  4446. ProjectId: item.ID,
  4447. StorehouseId: 0,
  4448. }
  4449. service.CreateAutoDetail(detail)
  4450. //查询剩余库存
  4451. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4452. var sum_count int64
  4453. for _, item := range goodList {
  4454. sum_count += item.StockCount
  4455. }
  4456. //更新剩余库存
  4457. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4458. //耗材
  4459. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4460. }
  4461. }
  4462. }
  4463. }
  4464. }
  4465. ////同步到自备药
  4466. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4467. if selfPrescriptionOpen.IsOpen == 1 {
  4468. timeStr := time.Now().Format("2006-01-02")
  4469. timeArr := strings.Split(timeStr, "-")
  4470. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4471. total = total + 1
  4472. operation_time := time.Now().Unix()
  4473. creater := adminInfo.AdminUser.Id
  4474. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4475. warehousing := models.XtSelfDrugWarehouse{
  4476. WarehousingOrder: warehousing_order,
  4477. OperationTime: operation_time,
  4478. OrgId: adminInfo.CurrentOrgId,
  4479. Creater: creater,
  4480. Ctime: time.Now().Unix(),
  4481. Status: 1,
  4482. WarehousingTime: recordDateTime,
  4483. Type: 0,
  4484. StorehouseId: 0,
  4485. IsCheck: 1,
  4486. PatientId: patient_id,
  4487. IsSys: 1,
  4488. }
  4489. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4490. if selfDrugWarehouse.ID == 0 {
  4491. service.AddSelfDrugWarehouse(&warehousing, tx)
  4492. }
  4493. if selfDrugWarehouse.ID > 0 {
  4494. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4495. }
  4496. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4497. fmt.Println(info)
  4498. for _, item := range hisdoctorlist {
  4499. //查询该病人的该药品是否已经入库
  4500. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4501. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4502. var in_count int64
  4503. if len(selfdruginfo) > 0 {
  4504. for _, item := range selfdruginfo {
  4505. var in_count_one int64
  4506. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4507. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4508. }
  4509. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4510. in_count_one = item.WarehousingCount
  4511. }
  4512. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4513. in_count_one = item.WarehousingCount
  4514. }
  4515. in_count += in_count_one
  4516. }
  4517. }
  4518. if selfBasedrug.IsSelfDrug == 1 {
  4519. var total_count int64
  4520. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4521. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4522. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4523. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4524. }
  4525. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4526. total_count += prescribingNumberSeven
  4527. }
  4528. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4529. total_count += prescribingNumberSeven
  4530. }
  4531. //入库
  4532. if total_count > in_count {
  4533. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4534. WarehousingOrder: warehousing_order,
  4535. WarehousingId: info.ID,
  4536. DrugId: item.DrugId,
  4537. Number: "",
  4538. ProductDate: 0,
  4539. ExpiryDate: 0,
  4540. WarehousingCount: total_count - in_count,
  4541. WarehouseingUnit: selfBasedrug.MinUnit,
  4542. Price: 0,
  4543. TotalPrice: 0,
  4544. Status: 1,
  4545. Ctime: time.Now().Unix(),
  4546. Remark: "",
  4547. OrgId: adminInfo.CurrentOrgId,
  4548. Type: 0,
  4549. Manufacturer: selfBasedrug.Manufacturer,
  4550. Dealer: selfBasedrug.Dealer,
  4551. StockMaxNumber: total_count - in_count,
  4552. RetailTotalPrice: 0,
  4553. BatchNumber: "",
  4554. MaxUnit: selfBasedrug.MinUnit,
  4555. MinUnit: selfBasedrug.MinUnit,
  4556. RetailPrice: 0,
  4557. StorehouseId: 0,
  4558. IsCheck: 1,
  4559. StockMinNumber: 0,
  4560. PatientId: patient_id,
  4561. IsSys: 1,
  4562. RecordDate: item.RecordDate,
  4563. AdviceId: item.ID,
  4564. }
  4565. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4566. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4567. Creator := adminInfo.AdminUser.Id
  4568. //查询默认仓库剩余多少库存
  4569. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4570. var sum_count int64
  4571. for _, it := range list {
  4572. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4573. if it.MaxUnit == baseDrug.MaxUnit {
  4574. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4575. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4576. }
  4577. sum_count += it.StockMaxNumber + it.StockMinNumber
  4578. }
  4579. flow := &models.XtSelfDrugFlow{
  4580. WarehousingId: info.ID,
  4581. DrugId: item.DrugId,
  4582. Number: "",
  4583. BatchNumber: "",
  4584. Count: total_count - in_count,
  4585. UserOrgId: adminInfo.CurrentOrgId,
  4586. PatientId: item.PatientId,
  4587. SystemTime: time.Now().Unix(),
  4588. ConsumableType: 1,
  4589. IsSys: 1,
  4590. WarehousingOrder: warehousing_order,
  4591. WarehouseOutId: 0,
  4592. WarehouseOutOrderNumber: "",
  4593. IsEdit: 0,
  4594. CancelStockId: 0,
  4595. CancelOrderNumber: "",
  4596. Manufacturer: selfBasedrug.Manufacturer,
  4597. Dealer: selfBasedrug.Dealer,
  4598. Creator: Creator,
  4599. UpdateCreator: Creator,
  4600. Status: 1,
  4601. Ctime: item.AdviceDate,
  4602. Mtime: 0,
  4603. Price: item.Price,
  4604. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4605. WarehouseOutDetailId: 0,
  4606. CancelOutDetailId: 0,
  4607. ExpireDate: 0,
  4608. ProductDate: 0,
  4609. MaxUnit: selfBasedrug.MinUnit,
  4610. MinUnit: selfBasedrug.MinUnit,
  4611. StorehouseId: 0,
  4612. OverCount: sum_count,
  4613. OperateTime: time.Now().Unix(),
  4614. AdviceId: item.ID,
  4615. }
  4616. service.CreateSelfDrugFlow(flow, tx)
  4617. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4618. var total_count int64 // 入库总数量
  4619. var over_count int64 //剩余库存
  4620. for _, it := range drugInfolist {
  4621. if it.MaxUnit == selfBasedrug.MaxUnit {
  4622. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4623. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4624. }
  4625. }
  4626. for _, it := range drugInfolist {
  4627. total_count += it.WarehousingCount
  4628. over_count += it.StockMaxNumber + it.StockMinNumber
  4629. }
  4630. //查询该仓库是否有默认数据
  4631. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4632. if selfDrugStock.ID == 0 {
  4633. drugStock := models.XtSelfDrugStockCount{
  4634. UserOrgId: item.UserOrgId,
  4635. PatientId: item.PatientId,
  4636. SumInCount: total_count,
  4637. SumOutCount: 0,
  4638. SumCancelCount: 0,
  4639. DrugId: item.DrugId,
  4640. Ctime: time.Now().Unix(),
  4641. Mtime: 0,
  4642. Status: 1,
  4643. FlushCount: over_count,
  4644. SumActOutCount: 0,
  4645. }
  4646. service.CreateSelfDrugStockSum(drugStock, tx)
  4647. }
  4648. if selfDrugStock.ID > 0 {
  4649. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4650. }
  4651. }
  4652. //查询这个单据的出库数量
  4653. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4654. var his_out_count int64
  4655. for _, item := range drugFlowList {
  4656. his_out_count += item.Count
  4657. }
  4658. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4659. if (total_count + his_out_count) <= in_count {
  4660. // 出库
  4661. if total_count < in_count {
  4662. var cha_count int64
  4663. cha_count = in_count - total_count
  4664. var stock_number int64 = 0
  4665. //查询库存是否充足
  4666. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4667. // 将该批次的剩余库存数量转换为拆零数量
  4668. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4669. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4670. }
  4671. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4672. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4673. }
  4674. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4675. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4676. }
  4677. if stock_number >= cha_count {
  4678. var maxNumber int64 = 0
  4679. var minNumber int64 = 0
  4680. maxNumber = cha_count / selfBasedrug.MinNumber
  4681. minNumber = cha_count % selfBasedrug.MinNumber
  4682. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4683. minNumber = maxNumber
  4684. }
  4685. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4686. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4688. return
  4689. }
  4690. }
  4691. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4692. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4693. }
  4694. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4695. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4696. }
  4697. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4698. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4699. }
  4700. if warehouse.StockMaxNumber < 0 {
  4701. warehouse.StockMaxNumber = 0
  4702. }
  4703. if warehouse.StockMinNumber < 0 {
  4704. warehouse.StockMinNumber = 0
  4705. }
  4706. warehouse.Mtime = time.Now().Unix()
  4707. if warehouse.StockMinNumber < minNumber {
  4708. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4709. if warehouse.MaxUnit != warehouse.MinUnit {
  4710. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4711. }
  4712. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4713. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4714. }
  4715. } else {
  4716. if minNumber > 0 {
  4717. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4718. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4719. }
  4720. }
  4721. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4722. if warehouse.StockMinNumber > 0 {
  4723. if warehouse.StockMinNumber-cha_count >= 0 {
  4724. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4725. }
  4726. }
  4727. }
  4728. }
  4729. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4730. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4731. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4732. }
  4733. }
  4734. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4735. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4737. return
  4738. }
  4739. }
  4740. if warehouse.StockMinNumber <= 0 {
  4741. warehouse.StockMinNumber = 0
  4742. }
  4743. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4744. //查询该药品剩余库存
  4745. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4746. var over_count int64
  4747. for _, its := range infolist {
  4748. if its.MaxUnit == selfBasedrug.MaxUnit {
  4749. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4750. }
  4751. over_count += its.StockMaxNumber + its.StockMinNumber
  4752. }
  4753. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4754. drugflow := models.XtSelfDrugFlow{
  4755. WarehouseOutId: 0,
  4756. WarehouseOutOrderNumber: warehousing_order,
  4757. WarehousingOrder: warehousing_order,
  4758. DrugId: item.DrugId,
  4759. Number: warehouse.Number,
  4760. ProductDate: warehouse.ProductDate,
  4761. ExpireDate: warehouse.ExpiryDate,
  4762. Count: cha_count,
  4763. Price: warehouse.RetailPrice,
  4764. Status: 1,
  4765. Ctime: item.AdviceDate,
  4766. Mtime: time.Now().Unix(),
  4767. UserOrgId: item.UserOrgId,
  4768. Manufacturer: warehouse.Manufacturer,
  4769. Dealer: warehouse.Dealer,
  4770. BatchNumber: warehouse.BatchNumber,
  4771. MaxUnit: selfBasedrug.MinUnit,
  4772. ConsumableType: 20,
  4773. IsEdit: 1,
  4774. Creator: 0,
  4775. IsSys: 3,
  4776. WarehouseOutDetailId: drugWareInfo.ID,
  4777. AdviceId: item.ID,
  4778. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4779. StorehouseId: 0,
  4780. AdminUserId: creater,
  4781. LastPrice: warehouse.Price,
  4782. StockCount: "",
  4783. WarehousingDetailId: 0,
  4784. OverCount: over_count,
  4785. RetailPrice: item.Price, //手动出库出库价格
  4786. WarehousingId: warehouse.ID,
  4787. SystemTime: item.AdviceDate,
  4788. PatientId: item.PatientId,
  4789. Remark: "保存处方入库数据差",
  4790. OperateTime: time.Now().Unix(),
  4791. }
  4792. if warehouse.RetailPrice == 0 {
  4793. drugflow.Price = item.Price
  4794. }
  4795. service.CreateSelfDrugFlowOne(drugflow, tx)
  4796. var out_count int64
  4797. out_count = in_count - total_count
  4798. //
  4799. //fmt.Println("in_count------------------", in_count)
  4800. //fmt.Println("total_count------------------", total_count)
  4801. //添加出库数量
  4802. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4803. //查询剩余库存
  4804. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4805. var sum_count int64
  4806. for _, its := range stockInfo {
  4807. if its.MaxUnit == selfBasedrug.MaxUnit {
  4808. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4809. }
  4810. sum_count += its.StockMaxNumber + its.StockMinNumber
  4811. }
  4812. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4813. } else {
  4814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4815. return
  4816. }
  4817. }
  4818. }
  4819. }
  4820. }
  4821. }
  4822. }
  4823. tx.Commit()
  4824. if err == nil {
  4825. c.ServeSuccessJSON(map[string]interface{}{
  4826. "msg": "保存成功",
  4827. })
  4828. return
  4829. } else {
  4830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4831. return
  4832. }
  4833. }
  4834. }
  4835. //func (c *HisApiController) EditHisPrescription() {
  4836. // record_date := c.GetString("record_date")
  4837. // patient_id, _ := c.GetInt64("patient_id")
  4838. // reg_type, _ := c.GetInt64("reg_type")
  4839. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4840. // diagnose := c.GetString("diagnose")
  4841. // sick_type, _ := c.GetInt64("sick_type")
  4842. // sick_history := c.GetString("sick_history")
  4843. // doctor_id, _ := c.GetInt64("doctor", 0)
  4844. // department, _ := c.GetInt64("department", 0)
  4845. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4846. // p_type, _ := c.GetInt64("p_type")
  4847. //
  4848. // dataBody := make(map[string]interface{}, 0)
  4849. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4850. // if err != nil {
  4851. // utils.ErrorLog(err.Error())
  4852. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4853. // return
  4854. // }
  4855. //
  4856. // timeLayout := "2006-01-02"
  4857. // loc, _ := time.LoadLocation("Local")
  4858. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4859. // if err != nil {
  4860. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4861. // return
  4862. // }
  4863. // adminInfo := c.GetAdminUserInfo()
  4864. // recordDateTime := theTime.Unix()
  4865. //
  4866. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4867. //
  4868. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4869. // var hpInfo models.HisPrescriptionInfo
  4870. // if info.ID == 0 {
  4871. // var randNum int
  4872. // randNum = rand.Intn(10000) + 1000
  4873. // timestamp := time.Now().Unix()
  4874. // tempTime := time.Unix(timestamp, 0)
  4875. // timeFormat := tempTime.Format("20060102150405")
  4876. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4877. //
  4878. // hpInfo = models.HisPrescriptionInfo{
  4879. // UserOrgId: adminInfo.CurrentOrgId,
  4880. // RecordDate: theTime.Unix(),
  4881. // PatientId: patient_id,
  4882. // Status: 1,
  4883. // Ctime: time.Now().Unix(),
  4884. // Mtime: time.Now().Unix(),
  4885. // Creator: adminInfo.AdminUser.Id,
  4886. // Modifier: adminInfo.AdminUser.Id,
  4887. // Diagnosis: diagnose,
  4888. // SickHistory: sick_history,
  4889. // Departments: department,
  4890. // RegisterType: reg_type,
  4891. // PrescriptionNumber: p_number,
  4892. // PrescriptionStatus: 1,
  4893. // Doctor: role.UserName,
  4894. // DoctorId: doctor_id,
  4895. // SickType: sick_type,
  4896. // PType: p_type,
  4897. // }
  4898. // service.SavePatientPrescriptionInfo(hpInfo)
  4899. //
  4900. // } else {
  4901. // hpInfo = models.HisPrescriptionInfo{
  4902. // ID: info.ID,
  4903. // UserOrgId: adminInfo.CurrentOrgId,
  4904. // RecordDate: info.RecordDate,
  4905. // PatientId: info.PatientId,
  4906. // Status: 1,
  4907. // Ctime: info.Ctime,
  4908. // Mtime: time.Now().Unix(),
  4909. // Creator: info.Creator,
  4910. // Modifier: adminInfo.AdminUser.Id,
  4911. // Diagnosis: diagnose,
  4912. // SickHistory: sick_history,
  4913. // Departments: department,
  4914. // RegisterType: reg_type,
  4915. // PrescriptionNumber: info.PrescriptionNumber,
  4916. // Doctor: role.UserName,
  4917. // PrescriptionStatus: info.PrescriptionStatus,
  4918. // DoctorId: doctor_id,
  4919. // SickType: sick_type,
  4920. // PType: info.PType,
  4921. // }
  4922. // service.SavePatientPrescriptionInfo(hpInfo)
  4923. // }
  4924. //
  4925. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4926. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4927. //
  4928. // if len(prescriptions) > 0 {
  4929. // for _, item := range prescriptions {
  4930. // items := item.(map[string]interface{})
  4931. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4932. // utils.ErrorLog("id")
  4933. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4934. // return
  4935. // }
  4936. // id := int64(items["id"].(float64))
  4937. //
  4938. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4939. // utils.ErrorLog("type")
  4940. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4941. // return
  4942. // }
  4943. // types := int64(items["type"].(float64))
  4944. //
  4945. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4946. // utils.ErrorLog("med_type")
  4947. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4948. // return
  4949. // }
  4950. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4951. //
  4952. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4953. //
  4954. // ctime := time.Now().Unix()
  4955. //
  4956. // prescription := &models.HisPrescription{
  4957. // ID: id,
  4958. // PatientId: patient_id,
  4959. // UserOrgId: adminInfo.CurrentOrgId,
  4960. // RecordDate: recordDateTime,
  4961. // Ctime: ctime,
  4962. // Mtime: ctime,
  4963. // Type: types,
  4964. // Modifier: adminInfo.AdminUser.Id,
  4965. // Creator: adminInfo.AdminUser.Id,
  4966. // Status: 1,
  4967. // Doctor: role.UserName,
  4968. // HisPatientId: his_patient_id,
  4969. // OrderStatus: 1,
  4970. // BatchNumber: "",
  4971. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4972. // PType: hpInfo.PType,
  4973. // MedType: med_type,
  4974. // }
  4975. //
  4976. // if historyPrescription.ID > 0 {
  4977. // prescription.PreTime = historyPrescription.PreTime
  4978. //
  4979. // }
  4980. //
  4981. // service.SaveHisPrescription(prescription)
  4982. //
  4983. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4984. // advices := items["advices"].([]interface{})
  4985. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4986. // groupNo := int64(0)
  4987. // ctime := time.Now().Unix()
  4988. // mtime := ctime
  4989. // if len(advices) > 0 {
  4990. // for _, advice := range advices {
  4991. // var s models.HisDoctorAdviceInfo
  4992. // s.PrescriptionId = prescription.ID
  4993. // s.AdviceType = 2
  4994. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4995. // s.StopState = 2
  4996. // s.ExecutionState = 2
  4997. // s.AdviceDate = recordDateTime
  4998. // s.Status = 1
  4999. // s.UserOrgId = adminInfo.CurrentOrgId
  5000. // s.RecordDate = recordDateTime
  5001. // s.StartTime = prescription.PreTime
  5002. // s.Groupno = groupNo
  5003. // s.CreatedTime = ctime
  5004. // s.UpdatedTime = mtime
  5005. // s.PatientId = patient_id
  5006. // s.HisPatientId = his_patient_id
  5007. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5008. // if errcode > 0 {
  5009. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5010. // return
  5011. // }
  5012. //
  5013. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5014. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5015. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5016. // if s.Price == 0 {
  5017. // s.Price = lastWarehouse.RetailPrice
  5018. // }
  5019. // }
  5020. //
  5021. // service.CreateHisDoctorAdvice(&s)
  5022. // //记录日志
  5023. // byterequest, _ := json.Marshal(s)
  5024. // adviceLog := models.XtDoctorAdviceLog{
  5025. // UserOrgId: s.UserOrgId,
  5026. // PatientId: s.PatientId,
  5027. // AdminUserId: adminInfo.AdminUser.Id,
  5028. // Module: 1,
  5029. // ErrLog: string(byterequest),
  5030. // Status: 1,
  5031. // Ctime: time.Now().Unix(),
  5032. // Mtime: 0,
  5033. // Source: "电脑端his医嘱修改",
  5034. // RecordDate: s.AdviceDate,
  5035. // }
  5036. // service.CreateDoctorAdviceLog(adviceLog)
  5037. // redis := service.RedisClient()
  5038. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5039. // redis.Set(key, "", time.Second)
  5040. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5041. // fmt.Println("keyOne", keyOne)
  5042. // redis.Set(keyOne, "", time.Second)
  5043. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5044. // redis.Set(keySeven, "", time.Second)
  5045. // redis.Close()
  5046. //
  5047. // }
  5048. // }
  5049. // }
  5050. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5051. // projects := items["project"].([]interface{})
  5052. // if len(projects) > 0 {
  5053. // for _, project := range projects {
  5054. // var p models.HisPrescriptionProject
  5055. // p.PrescriptionId = prescription.ID
  5056. // p.Ctime = time.Now().Unix()
  5057. // p.Mtime = time.Now().Unix()
  5058. // p.PatientId = patient_id
  5059. // p.RecordDate = recordDateTime
  5060. // p.UserOrgId = adminInfo.CurrentOrgId
  5061. // p.HisPatientId = his_patient_id
  5062. // p.Status = 1
  5063. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5064. // if errcode > 0 {
  5065. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5066. // return
  5067. // }
  5068. // service.CreateHisProjectTwo(&p)
  5069. //
  5070. // //记录日志
  5071. // byterequest, _ := json.Marshal(p)
  5072. // adviceLog := models.XtDoctorAdviceLog{
  5073. // UserOrgId: p.UserOrgId,
  5074. // PatientId: p.PatientId,
  5075. // AdminUserId: adminInfo.AdminUser.Id,
  5076. // Module: 1,
  5077. // ErrLog: string(byterequest),
  5078. // Status: 1,
  5079. // Ctime: time.Now().Unix(),
  5080. // Mtime: 0,
  5081. // Source: "电脑端his项目修改",
  5082. // RecordDate: p.RecordDate,
  5083. // }
  5084. // service.CreateDoctorAdviceLog(adviceLog)
  5085. // }
  5086. // }
  5087. // }
  5088. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5089. // addition := items["addition"].([]interface{})
  5090. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5091. // ctime := time.Now().Unix()
  5092. // mtime := ctime
  5093. // if len(addition) > 0 {
  5094. // for _, item := range addition {
  5095. // var s models.HisAdditionalCharge
  5096. // s.PrescriptionId = prescription.ID
  5097. // s.Status = 1
  5098. // s.UserOrgId = adminInfo.CurrentOrgId
  5099. // s.RecordDate = recordDateTime
  5100. // s.CreatedTime = ctime
  5101. // s.UpdatedTime = mtime
  5102. // s.PatientId = patient_id
  5103. // s.HisPatientId = his_patient_id
  5104. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5105. // if errcode > 0 {
  5106. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5107. // return
  5108. // }
  5109. // service.CreateAdditionalCharge(&s)
  5110. // }
  5111. // }
  5112. // }
  5113. //
  5114. // }
  5115. // }
  5116. // }
  5117. // if err == nil {
  5118. // c.ServeSuccessJSON(map[string]interface{}{
  5119. // "msg": "保存成功",
  5120. // })
  5121. // return
  5122. //
  5123. // } else {
  5124. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5125. // return
  5126. // }
  5127. //}
  5128. func (c *HisApiController) DeletePrescription() {
  5129. prescription_id, _ := c.GetInt64("id")
  5130. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5131. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5132. ////同步到自备药
  5133. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5134. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5135. if selfPrescriptionOpen.IsOpen == 1 {
  5136. // 在函数结束时处理事务回滚
  5137. db := service.XTWriteDB()
  5138. tx := db.Begin()
  5139. defer func() {
  5140. if r := recover(); r != nil {
  5141. tx.Rollback()
  5142. } else {
  5143. tx.Commit()
  5144. }
  5145. }()
  5146. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5147. for _, item := range advicesList {
  5148. timeStr := time.Now().Format("2006-01-02")
  5149. timeArr := strings.Split(timeStr, "-")
  5150. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5151. total = total + 1
  5152. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5153. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5154. number = number + total
  5155. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5156. operation_time := time.Now().Unix()
  5157. creater := c.GetAdminUserInfo().AdminUser.Id
  5158. //创建一个出库单
  5159. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5160. WarehouseOutOrderNumber: warehousing_out_order,
  5161. OperationTime: operation_time,
  5162. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5163. Creater: creater,
  5164. Ctime: time.Now().Unix(),
  5165. Status: 1,
  5166. WarehouseOutTime: item.AdviceDate,
  5167. Type: 0,
  5168. PatientId: item.PatientId,
  5169. IsCheck: 1,
  5170. }
  5171. //查询今日是否有出库数据
  5172. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5173. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5174. if lastWarehouseOut.ID == 0 {
  5175. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5176. }
  5177. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5178. var total_count int64
  5179. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5180. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5181. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5182. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5183. }
  5184. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5185. total_count += prescribingNumberSeven
  5186. }
  5187. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5188. total_count += prescribingNumberSeven
  5189. }
  5190. //出库
  5191. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5192. WarehouseOutOrderNumber: warehousing_out_order,
  5193. WarehouseOutId: lastWarehouseOut.ID,
  5194. DrugId: item.DrugId,
  5195. Count: total_count,
  5196. Price: 0,
  5197. TotalPrice: 0,
  5198. Status: 1,
  5199. Ctime: item.AdviceDate,
  5200. Mtime: item.AdviceDate,
  5201. Remark: "",
  5202. OrgId: item.UserOrgId,
  5203. Type: 0,
  5204. Manufacturer: selfBasedrug.Manufacturer,
  5205. Dealer: selfBasedrug.Dealer,
  5206. RetailPrice: 0,
  5207. RetailTotalPrice: 0,
  5208. CountUnit: selfBasedrug.MinUnit,
  5209. ExpiryDate: 0,
  5210. ProductDate: 0,
  5211. Number: "",
  5212. BatchNumber: "",
  5213. IsSys: 1,
  5214. WarehouseInfoId: 0,
  5215. AdminUserId: 0,
  5216. StockCount: "",
  5217. IsCheck: 1,
  5218. SysRecordTime: item.AdviceDate,
  5219. PatientId: item.PatientId,
  5220. ClassType: "",
  5221. AdviceId: item.ID,
  5222. }
  5223. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5224. }
  5225. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5226. for _, it := range warehousingOutInfo {
  5227. //查询今日是否有出库数据
  5228. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5229. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5230. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5231. //出库逻辑
  5232. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5233. //查询剩余库存
  5234. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5235. var sum_count int64
  5236. for _, its := range stockInfo {
  5237. if its.MaxUnit == medical.MaxUnit {
  5238. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5239. }
  5240. sum_count += its.StockMaxNumber + its.StockMinNumber
  5241. }
  5242. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5243. }
  5244. }
  5245. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5246. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5247. //耗材保存处方出库
  5248. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5249. //已收费和已发药限制逻辑
  5250. isCharge := false
  5251. isMedicine := false
  5252. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5253. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5254. if new_prescription.IsMedicine == 1 {
  5255. isMedicine = true
  5256. }
  5257. for _, item := range new_prescriptions {
  5258. if item.OrderStatus == 4 {
  5259. isCharge = true
  5260. }
  5261. }
  5262. if p_err != nil {
  5263. if new_prescription.ID > 0 {
  5264. if new_prescription.OrderStatus == 2 {
  5265. isCharge = true
  5266. }
  5267. }
  5268. }
  5269. for _, item := range advices {
  5270. if item.IsMedicine == 1 {
  5271. isMedicine = true
  5272. }
  5273. }
  5274. if isCharge {
  5275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5276. return
  5277. }
  5278. if isMedicine {
  5279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5280. return
  5281. }
  5282. //已收费和已发药限制逻辑
  5283. if len(projects) > 0 {
  5284. for _, item := range projects {
  5285. service.DeletePrintInfo(item.ID) //删除打印信息
  5286. if goodOutConfig.IsOpen != 1 {
  5287. if stockConfig.IsOpen == 1 {
  5288. if item.Type == 3 && item.IsOut == 1 {
  5289. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5290. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5291. good.Total = good.Total + f_count
  5292. service.UpdateGoodInfo(&good)
  5293. operation_time := time.Now().Unix()
  5294. creater := c.GetAdminUserInfo().AdminUser.Id
  5295. //创建退库单
  5296. timeStr := time.Now().Format("2006-01-02")
  5297. timeArr := strings.Split(timeStr, "-")
  5298. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5299. total = total + 1
  5300. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5301. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5302. cancelStock := models.CancelStock{
  5303. OrderNumber: orderNumber,
  5304. OperaTime: operation_time,
  5305. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5306. Creater: creater,
  5307. Ctime: time.Now().Unix(),
  5308. Status: 1,
  5309. ReturnTime: item.RecordDate,
  5310. Type: 1,
  5311. StorehouseId: houseConfig.StorehouseOutInfo,
  5312. IsCheck: 1,
  5313. }
  5314. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5315. if msgerrkonde == gorm.ErrRecordNotFound {
  5316. service.AddSigleCancelStock(&cancelStock)
  5317. }
  5318. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5319. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5320. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5321. //查询该耗材是否出库
  5322. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5323. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5324. deaerler, _ := service.GetDealerById(info.Dealer)
  5325. var total_count int64
  5326. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5327. total_count += count
  5328. if info.ID > 0 {
  5329. if info.Count >= total_count {
  5330. //回退库存
  5331. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5332. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5333. var flush_count int64
  5334. for _, it := range goodList {
  5335. flush_count += it.StockCount
  5336. }
  5337. cancelStockInfo := models.CancelStockInfo{
  5338. GoodId: item.ProjectId,
  5339. CancelStockId: cancel.ID,
  5340. GoodTypeId: good.GoodTypeId,
  5341. Count: prescribingNumber,
  5342. Price: info.Price,
  5343. Total: 0,
  5344. ProductDate: info.ProductDate,
  5345. ExpiryDate: info.ExpiryDate,
  5346. Ctime: time.Now().Unix(),
  5347. Status: 1,
  5348. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5349. OrderNumber: cancel.OrderNumber,
  5350. Type: 0,
  5351. Dealer: deaerler.DealerName,
  5352. Manufacturer: manufacturer.ManufacturerName,
  5353. Number: info.Number,
  5354. RegisterAccount: "",
  5355. Remark: "",
  5356. WarehouseInfoId: info.WarehouseInfotId,
  5357. PatientId: info.PatientId,
  5358. RecordDate: info.SysRecordTime,
  5359. StorehouseId: houseConfig.StorehouseOutInfo,
  5360. IsCheck: 1,
  5361. }
  5362. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5363. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5364. flow := models.VmStockFlow{
  5365. WarehousingId: info.WarehouseInfotId,
  5366. GoodId: item.ProjectId,
  5367. Number: info.Number,
  5368. LicenseNumber: info.LicenseNumber,
  5369. Count: prescribingNumber,
  5370. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5371. PatientId: item.PatientId,
  5372. SystemTime: info.SysRecordTime,
  5373. ConsumableType: 7,
  5374. IsSys: 0,
  5375. WarehousingOrder: "",
  5376. WarehouseOutId: info.WarehouseOutId,
  5377. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5378. IsEdit: 0,
  5379. CancelStockId: cancel.ID,
  5380. CancelOrderNumber: cancel.OrderNumber,
  5381. Manufacturer: manufacturer.ID,
  5382. Dealer: 0,
  5383. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5384. UpdateCreator: 0,
  5385. Status: 1,
  5386. Ctime: time.Now().Unix(),
  5387. Mtime: 0,
  5388. Price: info.Price,
  5389. WarehousingDetailId: info.WarehouseInfotId,
  5390. WarehouseOutDetailId: info.ID,
  5391. CancelOutDetailId: cancelInfo.ID,
  5392. ProductDate: info.ProductDate,
  5393. ExpireDate: info.ExpiryDate,
  5394. StorehouseId: houseConfig.StorehouseOutInfo,
  5395. OverCount: flush_count,
  5396. OperateTime: time.Now().Unix(),
  5397. }
  5398. service.CreateStockFlowOne(flow)
  5399. //退库数量增加
  5400. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5401. //出库数量减少
  5402. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5403. }
  5404. if info.Count < total_count {
  5405. //回退库存
  5406. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5407. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5408. var flush_count int64
  5409. for _, it := range goodList {
  5410. flush_count += it.StockCount
  5411. }
  5412. cancelStockInfo := models.CancelStockInfo{
  5413. GoodId: item.ProjectId,
  5414. CancelStockId: cancel.ID,
  5415. GoodTypeId: good.GoodTypeId,
  5416. Count: info.Count,
  5417. Price: info.Price,
  5418. Total: 0,
  5419. ProductDate: info.ProductDate,
  5420. ExpiryDate: info.ExpiryDate,
  5421. Ctime: time.Now().Unix(),
  5422. Status: 1,
  5423. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5424. OrderNumber: cancel.OrderNumber,
  5425. Type: 0,
  5426. Dealer: deaerler.DealerName,
  5427. Manufacturer: manufacturer.ManufacturerName,
  5428. Number: info.Number,
  5429. RegisterAccount: "",
  5430. Remark: "",
  5431. WarehouseInfoId: info.WarehouseInfotId,
  5432. PatientId: info.PatientId,
  5433. RecordDate: info.SysRecordTime,
  5434. StorehouseId: houseConfig.StorehouseOutInfo,
  5435. IsCheck: 1,
  5436. }
  5437. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5438. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5439. flow := models.VmStockFlow{
  5440. WarehousingId: info.WarehouseInfotId,
  5441. GoodId: item.ProjectId,
  5442. Number: info.Number,
  5443. LicenseNumber: info.LicenseNumber,
  5444. Count: info.Count,
  5445. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5446. PatientId: item.PatientId,
  5447. SystemTime: info.SysRecordTime,
  5448. ConsumableType: 7,
  5449. IsSys: 0,
  5450. WarehousingOrder: "",
  5451. WarehouseOutId: info.WarehouseOutId,
  5452. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5453. IsEdit: 0,
  5454. CancelStockId: cancel.ID,
  5455. CancelOrderNumber: cancel.OrderNumber,
  5456. Manufacturer: manufacturer.ID,
  5457. Dealer: 0,
  5458. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5459. UpdateCreator: 0,
  5460. Status: 1,
  5461. Ctime: time.Now().Unix(),
  5462. Mtime: 0,
  5463. Price: info.Price,
  5464. WarehousingDetailId: info.WarehouseInfotId,
  5465. WarehouseOutDetailId: info.ID,
  5466. CancelOutDetailId: cancelInfo.ID,
  5467. ProductDate: info.ProductDate,
  5468. ExpireDate: info.ExpiryDate,
  5469. StorehouseId: houseConfig.StorehouseOutInfo,
  5470. OverCount: flush_count,
  5471. OperateTime: time.Now().Unix(),
  5472. }
  5473. service.CreateStockFlowOne(flow)
  5474. //退库数量增加
  5475. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5476. //出库数量减少
  5477. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5478. }
  5479. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5480. var flush_count int64
  5481. for _, it := range goodList {
  5482. flush_count += it.StockCount
  5483. }
  5484. //查询已出库数量
  5485. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5486. if prescribingNumber < dialysisInfo.Count {
  5487. //改变数量
  5488. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5489. }
  5490. if prescribingNumber >= dialysisInfo.Count {
  5491. //删除出库表
  5492. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5493. }
  5494. //更新库存
  5495. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5496. //更新基础库库存
  5497. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5498. }
  5499. }
  5500. }
  5501. }
  5502. //保存耗材出库
  5503. if goodOutConfig.IsOpen == 1 {
  5504. if item.Type == 3 {
  5505. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5506. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5507. good.Total = good.Total + f_count
  5508. service.UpdateGoodInfo(&good)
  5509. operation_time := time.Now().Unix()
  5510. creater := c.GetAdminUserInfo().AdminUser.Id
  5511. //创建退库单
  5512. timeStr := time.Now().Format("2006-01-02")
  5513. timeArr := strings.Split(timeStr, "-")
  5514. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5515. total = total + 1
  5516. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5517. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5518. cancelStock := models.CancelStock{
  5519. OrderNumber: orderNumber,
  5520. OperaTime: operation_time,
  5521. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5522. Creater: creater,
  5523. Ctime: time.Now().Unix(),
  5524. Status: 1,
  5525. ReturnTime: item.RecordDate,
  5526. Type: 1,
  5527. StorehouseId: houseConfig.StorehouseOutInfo,
  5528. IsCheck: 1,
  5529. }
  5530. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5531. if msgerrkonde == gorm.ErrRecordNotFound {
  5532. service.AddSigleCancelStock(&cancelStock)
  5533. }
  5534. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5535. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5536. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5537. //查询该耗材是否出库
  5538. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5539. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5540. deaerler, _ := service.GetDealerById(info.Dealer)
  5541. var total_count int64
  5542. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5543. total_count += count
  5544. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5545. var flush_count int64
  5546. for _, it := range goodList {
  5547. flush_count += it.StockCount
  5548. }
  5549. fmt.Println("历史出库数据", info.Count)
  5550. fmt.Println("出库数量", total_count)
  5551. if info.ID > 0 {
  5552. cancelStockInfo := models.CancelStockInfo{
  5553. GoodId: item.ProjectId,
  5554. CancelStockId: cancel.ID,
  5555. GoodTypeId: good.GoodTypeId,
  5556. Count: prescribingNumber,
  5557. Price: info.Price,
  5558. Total: 0,
  5559. ProductDate: info.ProductDate,
  5560. ExpiryDate: info.ExpiryDate,
  5561. Ctime: time.Now().Unix(),
  5562. Status: 1,
  5563. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5564. OrderNumber: cancel.OrderNumber,
  5565. Type: 0,
  5566. Dealer: deaerler.DealerName,
  5567. Manufacturer: manufacturer.ManufacturerName,
  5568. Number: info.Number,
  5569. RegisterAccount: "",
  5570. Remark: "",
  5571. WarehouseInfoId: info.WarehouseInfotId,
  5572. PatientId: info.PatientId,
  5573. RecordDate: info.SysRecordTime,
  5574. StorehouseId: houseConfig.StorehouseOutInfo,
  5575. IsCheck: 1,
  5576. }
  5577. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5578. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5579. //查询出库数量
  5580. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5581. //出库数据 大于 退库数量
  5582. if len(list) > 0 {
  5583. for _, it := range list {
  5584. //回退库存
  5585. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5586. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5587. var flush_count_one int64
  5588. for _, it := range goodList {
  5589. flush_count_one += it.StockCount
  5590. }
  5591. //查询该批次是否有退库数据
  5592. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5593. creater := c.GetAdminUserInfo().AdminUser.Id
  5594. flow := models.VmStockFlow{
  5595. WarehousingId: it.WarehouseInfotId,
  5596. GoodId: it.GoodId,
  5597. Number: it.Number,
  5598. LicenseNumber: it.LicenseNumber,
  5599. Count: it.Count,
  5600. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5601. PatientId: it.PatientId,
  5602. SystemTime: it.SysRecordTime,
  5603. ConsumableType: 7,
  5604. IsSys: 0,
  5605. WarehousingOrder: "",
  5606. WarehouseOutId: it.WarehouseOutId,
  5607. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5608. IsEdit: 0,
  5609. CancelStockId: cancel.ID,
  5610. CancelOrderNumber: cancel.OrderNumber,
  5611. Manufacturer: manufacturer.ID,
  5612. Dealer: 0,
  5613. Creator: creater,
  5614. UpdateCreator: 0,
  5615. Status: 1,
  5616. Ctime: time.Now().Unix(),
  5617. Mtime: 0,
  5618. Price: it.Price,
  5619. WarehousingDetailId: it.WarehouseInfotId,
  5620. WarehouseOutDetailId: it.ID,
  5621. CancelOutDetailId: cancelInfo.ID,
  5622. ProductDate: it.ProductDate,
  5623. ExpireDate: it.ExpiryDate,
  5624. StorehouseId: houseConfig.StorehouseOutInfo,
  5625. OverCount: flush_count_one,
  5626. }
  5627. service.CreateStockFlowOne(flow)
  5628. //if flow.ID > 0 {
  5629. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5630. //}
  5631. }
  5632. }
  5633. //flow := models.VmStockFlow{
  5634. // WarehousingId: info.WarehouseInfotId,
  5635. // GoodId: item.ProjectId,
  5636. // Number: info.Number,
  5637. // LicenseNumber: info.LicenseNumber,
  5638. // Count: prescribingNumber,
  5639. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5640. // PatientId: item.PatientId,
  5641. // SystemTime: info.SysRecordTime,
  5642. // ConsumableType: 7,
  5643. // IsSys: 0,
  5644. // WarehousingOrder: "",
  5645. // WarehouseOutId: info.WarehouseOutId,
  5646. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5647. // IsEdit: 0,
  5648. // CancelStockId: cancel.ID,
  5649. // CancelOrderNumber: cancel.OrderNumber,
  5650. // Manufacturer: manufacturer.ID,
  5651. // Dealer: 0,
  5652. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5653. // UpdateCreator: 0,
  5654. // Status: 1,
  5655. // Ctime: time.Now().Unix(),
  5656. // Mtime: 0,
  5657. // Price: info.Price,
  5658. // WarehousingDetailId: info.WarehouseInfotId,
  5659. // WarehouseOutDetailId: info.ID,
  5660. // CancelOutDetailId: cancelInfo.ID,
  5661. // ProductDate: info.ProductDate,
  5662. // ExpireDate: info.ExpiryDate,
  5663. // StorehouseId: houseConfig.StorehouseOutInfo,
  5664. // OverCount: flush_count,
  5665. //}
  5666. //service.CreateStockFlowOne(flow)
  5667. //退库数量增加
  5668. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5669. //出库数量减少
  5670. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5671. //查询已出库数量
  5672. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5673. if prescribingNumber < dialysisInfo.Count {
  5674. //改变数量
  5675. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5676. }
  5677. if prescribingNumber >= dialysisInfo.Count {
  5678. //删除出库表
  5679. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5680. }
  5681. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5682. var flush_count_one int64
  5683. for _, it := range goodList {
  5684. flush_count_one += it.StockCount
  5685. }
  5686. //更新库存
  5687. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5688. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5689. //更新基础库库存
  5690. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5691. }
  5692. }
  5693. }
  5694. }
  5695. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5696. fmt.Println(err)
  5697. }
  5698. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5699. fmt.Println(err)
  5700. if len(advices) > 0 {
  5701. for _, item := range advices {
  5702. redis := service.RedisClient()
  5703. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5704. redis.Set(keyFive, "", time.Second)
  5705. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5706. redis.Set(keyOne, "", time.Second)
  5707. redis.Close()
  5708. }
  5709. }
  5710. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5711. if len(advices) > 0 {
  5712. for _, item := range advices {
  5713. creater := c.GetAdminUserInfo().AdminUser.Id
  5714. service.DrugAutoAddCancelInfo(item, creater)
  5715. }
  5716. }
  5717. } else {
  5718. if drugOutConfig.IsOpen == 1 {
  5719. if len(advices) > 0 {
  5720. for _, item := range advices {
  5721. creater := c.GetAdminUserInfo().AdminUser.Id
  5722. service.DrugAutoAddCancelInfo(item, creater)
  5723. }
  5724. }
  5725. } else {
  5726. if len(advices) > 0 {
  5727. for _, item := range advices {
  5728. creater := c.GetAdminUserInfo().AdminUser.Id
  5729. service.DrugAutoAddCancelInfo(item, creater)
  5730. }
  5731. }
  5732. }
  5733. }
  5734. c.ServeSuccessJSON(map[string]interface{}{
  5735. "msg": "删除成功",
  5736. })
  5737. return
  5738. }
  5739. func (c *HisApiController) DeleteDoctorAdvice() {
  5740. id, _ := c.GetInt64("id")
  5741. advice, _ := service.GetHisDoctorAdvicesById(id)
  5742. ////同步到自备药
  5743. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5744. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5745. if selfPrescriptionOpen.IsOpen == 1 {
  5746. db := service.XTWriteDB()
  5747. tx := db.Begin()
  5748. defer func() {
  5749. if r := recover(); r != nil {
  5750. tx.Rollback()
  5751. } else {
  5752. tx.Commit()
  5753. }
  5754. }()
  5755. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5756. var total_count int64
  5757. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5758. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5759. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5760. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5761. }
  5762. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5763. total_count += prescribingNumberSeven
  5764. }
  5765. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5766. total_count += prescribingNumberSeven
  5767. }
  5768. timeStr := time.Now().Format("2006-01-02")
  5769. timeArr := strings.Split(timeStr, "-")
  5770. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5771. total = total + 1
  5772. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5773. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5774. number = number + total
  5775. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5776. operation_time := time.Now().Unix()
  5777. creater := c.GetAdminUserInfo().AdminUser.Id
  5778. //创建一个出库单
  5779. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5780. WarehouseOutOrderNumber: warehousing_out_order,
  5781. OperationTime: operation_time,
  5782. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5783. Creater: creater,
  5784. Ctime: time.Now().Unix(),
  5785. Status: 1,
  5786. WarehouseOutTime: advice.AdviceDate,
  5787. Type: 0,
  5788. PatientId: advice.PatientId,
  5789. IsCheck: 1,
  5790. }
  5791. //查询今日是否有出库数据
  5792. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5793. if lastWarehouseOut.ID == 0 {
  5794. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5795. }
  5796. //出库
  5797. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5798. WarehouseOutId: lastWarehouseOut.ID,
  5799. WarehouseOutOrderNumber: warehousing_out_order,
  5800. DrugId: advice.DrugId,
  5801. Count: total_count,
  5802. Price: 0,
  5803. TotalPrice: 0,
  5804. Status: 1,
  5805. Ctime: advice.AdviceDate,
  5806. Mtime: advice.AdviceDate,
  5807. Remark: "",
  5808. OrgId: advice.UserOrgId,
  5809. Type: 0,
  5810. Manufacturer: selfBasedrug.Manufacturer,
  5811. Dealer: selfBasedrug.Dealer,
  5812. RetailPrice: 0,
  5813. RetailTotalPrice: 0,
  5814. CountUnit: advice.PrescribingNumberUnit,
  5815. ExpiryDate: 0,
  5816. ProductDate: 0,
  5817. Number: "",
  5818. BatchNumber: "",
  5819. IsSys: 0,
  5820. WarehouseInfoId: 0,
  5821. AdminUserId: 0,
  5822. StockCount: "",
  5823. IsCheck: 1,
  5824. SysRecordTime: advice.AdviceDate,
  5825. PatientId: advice.PatientId,
  5826. AdviceId: advice.ID,
  5827. ClassType: "",
  5828. }
  5829. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5830. for _, it := range warehousingOutInfo {
  5831. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5832. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5833. //出库逻辑
  5834. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5835. //查询剩余库存
  5836. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5837. var sum_count int64
  5838. for _, its := range stockInfo {
  5839. if its.MaxUnit == medical.MaxUnit {
  5840. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5841. }
  5842. sum_count += its.StockMaxNumber + its.StockMinNumber
  5843. }
  5844. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5845. }
  5846. }
  5847. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5848. //已收费和已发药的限制逻辑
  5849. isCharge := false
  5850. isMedicine := false
  5851. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5852. //获取今天该患者所有处方,判断是否发药或者收费
  5853. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5854. //for _, item := range new_prescriptions {
  5855. if new_prescription.IsMedicine == 1 {
  5856. isMedicine = true
  5857. }
  5858. //}
  5859. for _, item := range new_prescriptions {
  5860. if item.OrderStatus == 4 {
  5861. isCharge = true
  5862. }
  5863. }
  5864. if isMedicine {
  5865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5866. return
  5867. }
  5868. if isCharge {
  5869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5870. return
  5871. }
  5872. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5873. for _, item := range advices {
  5874. if item.IsMedicine == 1 {
  5875. isMedicine = true
  5876. }
  5877. }
  5878. if isMedicine {
  5879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5880. return
  5881. }
  5882. if new_prescription.ID > 0 {
  5883. if new_prescription.OrderStatus == 2 {
  5884. isCharge = true
  5885. }
  5886. }
  5887. if isCharge {
  5888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5889. return
  5890. }
  5891. //已收费和已发药的限制逻辑
  5892. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5893. redis := service.RedisClient()
  5894. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5895. redis.Set(keyFive, "", time.Second)
  5896. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5897. redis.Set(keyOne, "", time.Second)
  5898. defer redis.Close()
  5899. if err == nil {
  5900. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5901. //查询是否在处方中出库
  5902. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5903. if openConfig.IsOpen != 1 {
  5904. //判断该医嘱是否执行了
  5905. if advice.ExecutionState == 1 {
  5906. creater := c.GetAdminUserInfo().AdminUser.Id
  5907. service.DrugAutoAddCancelInfo(&advice, creater)
  5908. }
  5909. }
  5910. //开启保存处方扣减功能
  5911. if openConfig.IsOpen == 1 {
  5912. creater := c.GetAdminUserInfo().AdminUser.Id
  5913. service.DrugAutoAddCancelInfo(&advice, creater)
  5914. }
  5915. } else {
  5916. if drugOutConfig.IsOpen == 1 {
  5917. //查询是否在处方中出库
  5918. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5919. if openConfig.IsOpen != 1 {
  5920. //判断该医嘱是否执行了
  5921. if advice.ExecutionState == 1 {
  5922. creater := c.GetAdminUserInfo().AdminUser.Id
  5923. service.DrugAutoAddCancelInfo(&advice, creater)
  5924. }
  5925. }
  5926. //开启保存处方扣减功能
  5927. if openConfig.IsOpen == 1 {
  5928. creater := c.GetAdminUserInfo().AdminUser.Id
  5929. service.DrugAutoAddCancelInfo(&advice, creater)
  5930. }
  5931. } else {
  5932. //判断该医嘱是否执行了
  5933. if advice.ExecutionState == 1 {
  5934. creater := c.GetAdminUserInfo().AdminUser.Id
  5935. service.DrugAutoAddCancelInfo(&advice, creater)
  5936. }
  5937. }
  5938. }
  5939. c.ServeSuccessJSON(map[string]interface{}{
  5940. "msg": "删除成功",
  5941. })
  5942. return
  5943. } else {
  5944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5945. return
  5946. }
  5947. }
  5948. func (c *HisApiController) DeleteProject() {
  5949. id, _ := c.GetInt64("id")
  5950. adminInfo := c.GetAdminUserInfo()
  5951. project, _ := service.GetHisProjectByID(id)
  5952. // var consumable models.DialysisBeforePrepare
  5953. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5954. //耗材保存处方出库
  5955. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5956. isCharge := false
  5957. isMedicine := false
  5958. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5959. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5960. for _, item := range new_prescriptions {
  5961. if item.IsMedicine == 1 {
  5962. isMedicine = true
  5963. }
  5964. }
  5965. for _, item := range new_prescriptions {
  5966. if item.OrderStatus == 4 {
  5967. isCharge = true
  5968. }
  5969. }
  5970. if isMedicine {
  5971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5972. return
  5973. }
  5974. if isCharge {
  5975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5976. return
  5977. }
  5978. if new_prescription.ID > 0 {
  5979. if new_prescription.OrderStatus == 2 {
  5980. isCharge = true
  5981. }
  5982. }
  5983. if isCharge {
  5984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5985. return
  5986. }
  5987. service.DeletePrintInfo(id)
  5988. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5989. label.Status = 0
  5990. service.CreateHisLabelRecordTwo(&label)
  5991. fmt.Println(goodOutConfig.IsOpen)
  5992. if goodOutConfig.IsOpen != 1 {
  5993. if stockConfig.IsOpen == 1 {
  5994. if project.Type == 2 {
  5995. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5996. fmt.Println(err)
  5997. }
  5998. if project.Type == 3 && project.IsOut == 1 {
  5999. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6000. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6001. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6002. operation_time := time.Now().Unix()
  6003. creater := adminInfo.AdminUser.Id
  6004. //创建退库单
  6005. timeStr := time.Now().Format("2006-01-02")
  6006. timeArr := strings.Split(timeStr, "-")
  6007. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6008. total = total + 1
  6009. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6010. cancelStock := models.CancelStock{
  6011. OrderNumber: orderNumber,
  6012. OperaTime: operation_time,
  6013. OrgId: adminInfo.CurrentOrgId,
  6014. Creater: creater,
  6015. Ctime: time.Now().Unix(),
  6016. Status: 1,
  6017. ReturnTime: project.RecordDate,
  6018. Type: 1,
  6019. StorehouseId: houseConfig.StorehouseOutInfo,
  6020. IsCheck: 1,
  6021. }
  6022. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6023. if msgerrkonde == gorm.ErrRecordNotFound {
  6024. service.AddSigleCancelStock(&cancelStock)
  6025. }
  6026. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6027. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6028. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6029. //查询是否有出库
  6030. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6031. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6032. deaerler, _ := service.GetDealerById(info.Dealer)
  6033. if info.ID > 0 {
  6034. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6035. if info.Count >= prescribingNumber {
  6036. cancelStockInfo := models.CancelStockInfo{
  6037. GoodId: project.ProjectId,
  6038. CancelStockId: cancel.ID,
  6039. GoodTypeId: good.GoodTypeId,
  6040. Count: prescribingNumber,
  6041. Price: info.Price,
  6042. Total: 0,
  6043. ProductDate: info.ProductDate,
  6044. ExpiryDate: info.ExpiryDate,
  6045. Ctime: time.Now().Unix(),
  6046. Status: 1,
  6047. OrgId: adminInfo.CurrentOrgId,
  6048. OrderNumber: cancel.OrderNumber,
  6049. Type: 0,
  6050. Dealer: deaerler.DealerName,
  6051. Manufacturer: manufacturer.ManufacturerName,
  6052. Number: info.Number,
  6053. RegisterAccount: "",
  6054. Remark: "",
  6055. WarehouseInfoId: info.WarehouseInfotId,
  6056. PatientId: info.PatientId,
  6057. RecordDate: info.SysRecordTime,
  6058. StorehouseId: houseConfig.StorehouseOutInfo,
  6059. IsCheck: 1,
  6060. }
  6061. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6062. //回退库存
  6063. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6064. //退库数量增加
  6065. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6066. //出库数量减少
  6067. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6068. }
  6069. if info.Count < prescribingNumber {
  6070. cancelStockInfo := models.CancelStockInfo{
  6071. GoodId: project.ProjectId,
  6072. CancelStockId: cancel.ID,
  6073. GoodTypeId: good.GoodTypeId,
  6074. Count: info.Count,
  6075. Price: info.Price,
  6076. Total: 0,
  6077. ProductDate: info.ProductDate,
  6078. ExpiryDate: info.ExpiryDate,
  6079. Ctime: time.Now().Unix(),
  6080. Status: 1,
  6081. OrgId: adminInfo.CurrentOrgId,
  6082. OrderNumber: cancel.OrderNumber,
  6083. Type: 0,
  6084. Dealer: deaerler.DealerName,
  6085. Manufacturer: manufacturer.ManufacturerName,
  6086. Number: info.Number,
  6087. RegisterAccount: "",
  6088. Remark: "",
  6089. WarehouseInfoId: info.WarehouseInfotId,
  6090. PatientId: info.PatientId,
  6091. RecordDate: info.SysRecordTime,
  6092. StorehouseId: houseConfig.StorehouseOutInfo,
  6093. IsCheck: 1,
  6094. }
  6095. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6096. //回退库存
  6097. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6098. //退库数量增加
  6099. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6100. //出库数量减少
  6101. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6102. }
  6103. //查询剩余库存
  6104. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6105. var over_count int64
  6106. for _, it := range goodList {
  6107. over_count += it.StockCount
  6108. }
  6109. //出库数据 大于 退库数量
  6110. if info.Count >= prescribingNumber {
  6111. flow := models.VmStockFlow{
  6112. WarehousingId: info.WarehouseInfotId,
  6113. GoodId: project.ProjectId,
  6114. Number: info.Number,
  6115. LicenseNumber: info.LicenseNumber,
  6116. Count: prescribingNumber,
  6117. UserOrgId: adminInfo.CurrentOrgId,
  6118. PatientId: project.PatientId,
  6119. SystemTime: info.SysRecordTime,
  6120. ConsumableType: 7,
  6121. IsSys: 0,
  6122. WarehousingOrder: "",
  6123. WarehouseOutId: info.WarehouseOutId,
  6124. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6125. IsEdit: 0,
  6126. CancelStockId: cancel.ID,
  6127. CancelOrderNumber: cancel.OrderNumber,
  6128. Manufacturer: manufacturer.ID,
  6129. Dealer: 0,
  6130. Creator: adminInfo.AdminUser.Id,
  6131. UpdateCreator: 0,
  6132. Status: 1,
  6133. Ctime: time.Now().Unix(),
  6134. Mtime: 0,
  6135. Price: info.Price,
  6136. WarehousingDetailId: info.WarehouseInfotId,
  6137. WarehouseOutDetailId: info.ID,
  6138. CancelOutDetailId: cancelInfo.ID,
  6139. ProductDate: info.ProductDate,
  6140. ExpireDate: info.ExpiryDate,
  6141. StorehouseId: houseConfig.StorehouseOutInfo,
  6142. OverCount: over_count,
  6143. OperateTime: time.Now().Unix(),
  6144. }
  6145. service.CreateStockFlowOne(flow)
  6146. }
  6147. //出库数据小于退库数据
  6148. if info.Count < prescribingNumber {
  6149. flow := models.VmStockFlow{
  6150. WarehousingId: info.WarehouseInfotId,
  6151. GoodId: project.ProjectId,
  6152. Number: info.Number,
  6153. LicenseNumber: info.LicenseNumber,
  6154. Count: info.Count,
  6155. UserOrgId: adminInfo.CurrentOrgId,
  6156. PatientId: project.PatientId,
  6157. SystemTime: info.SysRecordTime,
  6158. ConsumableType: 7,
  6159. IsSys: 0,
  6160. WarehousingOrder: "",
  6161. WarehouseOutId: info.WarehouseOutId,
  6162. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6163. IsEdit: 0,
  6164. CancelStockId: cancel.ID,
  6165. CancelOrderNumber: cancel.OrderNumber,
  6166. Manufacturer: manufacturer.ID,
  6167. Dealer: 0,
  6168. Creator: adminInfo.AdminUser.Id,
  6169. UpdateCreator: 0,
  6170. Status: 1,
  6171. Ctime: time.Now().Unix(),
  6172. Mtime: 0,
  6173. Price: info.Price,
  6174. WarehousingDetailId: info.WarehouseInfotId,
  6175. WarehouseOutDetailId: info.ID,
  6176. CancelOutDetailId: cancelInfo.ID,
  6177. ProductDate: info.ProductDate,
  6178. ExpireDate: info.ExpiryDate,
  6179. StorehouseId: houseConfig.StorehouseOutInfo,
  6180. OverCount: over_count,
  6181. OperateTime: time.Now().Unix(),
  6182. }
  6183. service.CreateStockFlowOne(flow)
  6184. }
  6185. //查询已出库数量
  6186. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6187. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6188. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6189. if prescribingNumber < dialysisInfo.Count {
  6190. //改变数量
  6191. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6192. }
  6193. if prescribingNumber >= dialysisInfo.Count {
  6194. //删除出库表
  6195. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6196. }
  6197. //更新剩余库存
  6198. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6199. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6200. var total_count_one int64
  6201. for _, it := range stockList {
  6202. total_count_one += it.StockCount
  6203. }
  6204. //基础库插入数据
  6205. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6206. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6207. var flush_count int64
  6208. for _, it := range goodListOne {
  6209. flush_count += it.StockCount
  6210. }
  6211. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6212. if errs != nil {
  6213. goodErrcode := models.XtGoodErrcode{
  6214. UserOrgId: project.UserOrgId,
  6215. Errcode: "手动出库更新剩余出库失败",
  6216. GoodId: project.ProjectId,
  6217. Status: 1,
  6218. Ctime: time.Now().Unix(),
  6219. Mtime: 0,
  6220. Count: 0,
  6221. StockCount: 0,
  6222. Creater: creater,
  6223. BatchNumberId: 0,
  6224. WarehouseOutId: 0,
  6225. }
  6226. service.CreateGoodErrcode(goodErrcode)
  6227. }
  6228. }
  6229. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6230. fmt.Println(err)
  6231. } else {
  6232. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6233. fmt.Println(err)
  6234. }
  6235. } else {
  6236. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6237. fmt.Println(err)
  6238. }
  6239. }
  6240. //保存处方出库
  6241. if goodOutConfig.IsOpen == 1 {
  6242. if project.Type == 3 {
  6243. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6244. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6245. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6246. operation_time := time.Now().Unix()
  6247. creater := adminInfo.AdminUser.Id
  6248. //创建退库单
  6249. timeStr := time.Now().Format("2006-01-02")
  6250. timeArr := strings.Split(timeStr, "-")
  6251. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6252. total = total + 1
  6253. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6254. cancelStock := models.CancelStock{
  6255. OrderNumber: orderNumber,
  6256. OperaTime: operation_time,
  6257. OrgId: adminInfo.CurrentOrgId,
  6258. Creater: creater,
  6259. Ctime: time.Now().Unix(),
  6260. Status: 1,
  6261. ReturnTime: project.RecordDate,
  6262. Type: 1,
  6263. StorehouseId: houseConfig.StorehouseOutInfo,
  6264. IsCheck: 1,
  6265. }
  6266. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6267. if msgerrkonde == gorm.ErrRecordNotFound {
  6268. service.AddSigleCancelStock(&cancelStock)
  6269. }
  6270. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6271. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6272. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6273. //获取出库数据
  6274. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6275. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6276. deaerler, _ := service.GetDealerById(info.Dealer)
  6277. if info.ID > 0 {
  6278. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6279. if info.Count >= prescribingNumber {
  6280. cancelStockInfo := models.CancelStockInfo{
  6281. GoodId: project.ProjectId,
  6282. CancelStockId: cancel.ID,
  6283. GoodTypeId: good.GoodTypeId,
  6284. Count: prescribingNumber,
  6285. Price: info.Price,
  6286. Total: 0,
  6287. ProductDate: info.ProductDate,
  6288. ExpiryDate: info.ExpiryDate,
  6289. Ctime: time.Now().Unix(),
  6290. Status: 1,
  6291. OrgId: adminInfo.CurrentOrgId,
  6292. OrderNumber: cancel.OrderNumber,
  6293. Type: 0,
  6294. Dealer: deaerler.DealerName,
  6295. Manufacturer: manufacturer.ManufacturerName,
  6296. Number: info.Number,
  6297. RegisterAccount: "",
  6298. Remark: "",
  6299. WarehouseInfoId: info.WarehouseInfotId,
  6300. PatientId: info.PatientId,
  6301. RecordDate: info.SysRecordTime,
  6302. StorehouseId: houseConfig.StorehouseOutInfo,
  6303. IsCheck: 1,
  6304. }
  6305. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6306. //退库数量增加
  6307. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6308. //出库数量减少
  6309. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6310. }
  6311. if info.Count < prescribingNumber {
  6312. cancelStockInfo := models.CancelStockInfo{
  6313. GoodId: project.ProjectId,
  6314. CancelStockId: cancel.ID,
  6315. GoodTypeId: good.GoodTypeId,
  6316. Count: prescribingNumber,
  6317. Price: info.Price,
  6318. Total: 0,
  6319. ProductDate: info.ProductDate,
  6320. ExpiryDate: info.ExpiryDate,
  6321. Ctime: time.Now().Unix(),
  6322. Status: 1,
  6323. OrgId: adminInfo.CurrentOrgId,
  6324. OrderNumber: cancel.OrderNumber,
  6325. Type: 0,
  6326. Dealer: deaerler.DealerName,
  6327. Manufacturer: manufacturer.ManufacturerName,
  6328. Number: info.Number,
  6329. RegisterAccount: "",
  6330. Remark: "",
  6331. WarehouseInfoId: info.WarehouseInfotId,
  6332. PatientId: info.PatientId,
  6333. RecordDate: info.SysRecordTime,
  6334. StorehouseId: houseConfig.StorehouseOutInfo,
  6335. IsCheck: 1,
  6336. }
  6337. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6338. //回退库存
  6339. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6340. }
  6341. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6342. var over_count int64
  6343. for _, it := range goodList {
  6344. over_count += it.StockCount
  6345. }
  6346. //查询出库数量
  6347. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6348. //出库数据 大于 退库数量
  6349. if len(list) > 0 {
  6350. for _, it := range list {
  6351. //回退库存
  6352. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6353. //退库数量增加
  6354. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6355. //出库数量减少
  6356. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6357. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6358. var over_count_one int64
  6359. for _, it := range goodList {
  6360. over_count_one += it.StockCount
  6361. }
  6362. //查询该批次是否有退库数据
  6363. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6364. flow := models.VmStockFlow{
  6365. WarehousingId: it.WarehouseInfotId,
  6366. GoodId: it.GoodId,
  6367. Number: it.Number,
  6368. LicenseNumber: it.LicenseNumber,
  6369. Count: it.Count,
  6370. UserOrgId: adminInfo.CurrentOrgId,
  6371. PatientId: it.PatientId,
  6372. SystemTime: it.SysRecordTime,
  6373. ConsumableType: 7,
  6374. IsSys: 0,
  6375. WarehousingOrder: "",
  6376. WarehouseOutId: it.WarehouseOutId,
  6377. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6378. IsEdit: 0,
  6379. CancelStockId: cancel.ID,
  6380. CancelOrderNumber: cancel.OrderNumber,
  6381. Manufacturer: manufacturer.ID,
  6382. Dealer: 0,
  6383. Creator: adminInfo.AdminUser.Id,
  6384. UpdateCreator: 0,
  6385. Status: 1,
  6386. Ctime: time.Now().Unix(),
  6387. Mtime: 0,
  6388. Price: it.Price,
  6389. WarehousingDetailId: it.WarehouseInfotId,
  6390. WarehouseOutDetailId: it.ID,
  6391. CancelOutDetailId: cancelInfo.ID,
  6392. ProductDate: it.ProductDate,
  6393. ExpireDate: it.ExpiryDate,
  6394. StorehouseId: houseConfig.StorehouseOutInfo,
  6395. OverCount: over_count_one,
  6396. OperateTime: time.Now().Unix(),
  6397. }
  6398. service.CreateStockFlowOne(flow)
  6399. }
  6400. }
  6401. //查询已出库数量
  6402. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6403. if prescribingNumber < dialysisInfo.Count {
  6404. //改变数量
  6405. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6406. }
  6407. if prescribingNumber >= dialysisInfo.Count {
  6408. //删除出库表
  6409. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6410. }
  6411. //更新剩余库存
  6412. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6413. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6414. var total_count_one int64
  6415. for _, it := range stockList {
  6416. total_count_one += it.StockCount
  6417. }
  6418. //基础库插入数据
  6419. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6420. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6421. var flush_count int64
  6422. for _, it := range goodListOne {
  6423. flush_count += it.StockCount
  6424. }
  6425. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6426. if errs != nil {
  6427. goodErrcode := models.XtGoodErrcode{
  6428. UserOrgId: project.UserOrgId,
  6429. Errcode: "手动出库更新剩余出库失败",
  6430. GoodId: project.ProjectId,
  6431. Status: 1,
  6432. Ctime: time.Now().Unix(),
  6433. Mtime: 0,
  6434. Count: 0,
  6435. StockCount: 0,
  6436. Creater: creater,
  6437. BatchNumberId: 0,
  6438. WarehouseOutId: 0,
  6439. }
  6440. service.CreateGoodErrcode(goodErrcode)
  6441. }
  6442. }
  6443. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6444. fmt.Println(err)
  6445. } else {
  6446. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6447. fmt.Println(err)
  6448. }
  6449. }
  6450. c.ServeSuccessJSON(map[string]interface{}{
  6451. "msg": "删除成功",
  6452. })
  6453. return
  6454. }
  6455. func (c *HisApiController) CreateHisAdditionalCharge() {
  6456. his_patient_id, _ := c.GetInt64("his_patient_id")
  6457. patient_id, _ := c.GetInt64("patient_id")
  6458. record_date := c.GetString("record_date")
  6459. timeLayout := "2006-01-02"
  6460. loc, _ := time.LoadLocation("Local")
  6461. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6462. if err != nil {
  6463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6464. return
  6465. }
  6466. adminInfo := c.GetAdminUserInfo()
  6467. recordDateTime := theTime.Unix()
  6468. dataBody := make(map[string]interface{}, 0)
  6469. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6470. if err != nil {
  6471. utils.ErrorLog(err.Error())
  6472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6473. return
  6474. }
  6475. var additions []*models.HisAdditionalCharge
  6476. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6477. additions, _ := dataBody["addition"].([]interface{})
  6478. if len(additions) > 0 {
  6479. for _, item := range additions {
  6480. items := item.(map[string]interface{})
  6481. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6482. utils.ErrorLog("item_id")
  6483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6484. return
  6485. }
  6486. item_id := int64(items["item_id"].(float64))
  6487. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6488. utils.ErrorLog("item_name")
  6489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6490. return
  6491. }
  6492. item_name := items["item_name"].(string)
  6493. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6494. utils.ErrorLog("price")
  6495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6496. return
  6497. }
  6498. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6499. ctime := time.Now().Unix()
  6500. additional := &models.HisAdditionalCharge{
  6501. PatientId: patient_id,
  6502. HisPatientId: his_patient_id,
  6503. UserOrgId: adminInfo.CurrentOrgId,
  6504. RecordDate: recordDateTime,
  6505. CreatedTime: ctime,
  6506. UpdatedTime: ctime,
  6507. Modifier: adminInfo.AdminUser.Id,
  6508. Creator: adminInfo.AdminUser.Id,
  6509. Price: price,
  6510. ItemName: item_name,
  6511. ItemId: item_id,
  6512. Status: 1,
  6513. }
  6514. additions = append(additions, additional)
  6515. }
  6516. }
  6517. }
  6518. for _, item := range additions {
  6519. service.CreateAddtionalCharge(item)
  6520. }
  6521. c.ServeSuccessJSON(map[string]interface{}{
  6522. "msg": "创建成功",
  6523. })
  6524. }
  6525. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6526. blood_fat := c.GetString("blood_fat")
  6527. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6528. blood_sugar := c.GetString("blood_sugar")
  6529. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6530. chief_conplaint := c.GetString("chief_conplaint")
  6531. dbp := c.GetString("dbp")
  6532. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6533. delivery_way, _ := c.GetInt64("delivery_way")
  6534. diagnostic := c.GetString("diagnostic")
  6535. family_history := c.GetString("family_history")
  6536. height := c.GetString("height")
  6537. history_of_present_illness := c.GetString("history_of_present_illness")
  6538. is_infect, _ := c.GetInt64("is_infect")
  6539. past_history := c.GetString("past_history")
  6540. patient_id, _ := c.GetInt64("patient_id")
  6541. his_patient_id, _ := c.GetInt64("his_patient_id")
  6542. personal_history := c.GetString("personal_history")
  6543. pulse := c.GetString("pulse")
  6544. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6545. sbp := c.GetString("sbp")
  6546. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6547. heightfloat, _ := strconv.ParseFloat(height, 64)
  6548. sicktype := c.GetString("sick_type")
  6549. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6550. symptom := c.GetString("symptom")
  6551. sick_date := c.GetString("sick_date")
  6552. temperatures := c.GetString("temperature")
  6553. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6554. record_date := c.GetString("record_date")
  6555. breathing := c.GetString("breathing")
  6556. doctor_advice := c.GetString("doctor_advice")
  6557. remark := c.GetString("remark")
  6558. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6559. sick, _ := c.GetInt64("sick")
  6560. diagnose, _ := c.GetInt64("diagnose")
  6561. //id, _ := c.GetInt64("id")
  6562. timeLayout := "2006-01-02"
  6563. loc, _ := time.LoadLocation("Local")
  6564. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6565. allergic_history := c.GetString("allergic_history")
  6566. if err != nil {
  6567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6568. return
  6569. }
  6570. recordDateTime := theTime.Unix()
  6571. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6572. if err != nil {
  6573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6574. return
  6575. }
  6576. sickTimes := sickTime.Unix()
  6577. ctime := time.Now().Unix()
  6578. primary_disease := c.GetString("primary_disease")
  6579. confirm_failure_date := c.GetString("confirm_failure_date")
  6580. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6581. drug_allergy_history := c.GetString("drug_allergy_history")
  6582. physical_examination := c.GetString("physical_examination")
  6583. special_inspection := c.GetString("special_inspection")
  6584. lab_apparatus := c.GetString("lab_apparatus")
  6585. caseHistory := models.HisPatientCaseHistory{
  6586. HisPatientId: his_patient_id,
  6587. PatientId: patient_id,
  6588. Temperature: temperature,
  6589. BloodSugar: bloodsugarfloat,
  6590. Pulse: pulsefloat,
  6591. Sbp: sbpfloat,
  6592. Dbp: dbpfloat,
  6593. Height: heightfloat,
  6594. BloodFat: bloodfatfloat,
  6595. SickType: sick_type,
  6596. Symptom: symptom,
  6597. SickDate: sickTimes,
  6598. IsInfect: is_infect,
  6599. HistoryOfPresentIllness: history_of_present_illness,
  6600. PastHistory: past_history,
  6601. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6602. ChiefConplaint: chief_conplaint,
  6603. PersonalHistory: personal_history,
  6604. FamilyHistory: family_history,
  6605. Diagnostic: diagnostic,
  6606. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6607. Status: 1,
  6608. Ctime: ctime,
  6609. Mtime: ctime,
  6610. RecordDate: recordDateTime,
  6611. DeliveryWay: delivery_way,
  6612. Breathing: breathingfloat,
  6613. DoctorAdvice: doctor_advice,
  6614. Remark: remark,
  6615. Sick: sick,
  6616. Diagnose: diagnose,
  6617. AllergicHistory: allergic_history,
  6618. PrimaryDisease: primary_disease,
  6619. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6620. DrugAllergyHistory: drug_allergy_history,
  6621. PhysicalExamination: physical_examination,
  6622. SpecialInspection: special_inspection,
  6623. LabApparatus: lab_apparatus,
  6624. }
  6625. //查询该患者是否有病历
  6626. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6627. if errcodes == gorm.ErrRecordNotFound {
  6628. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6629. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6630. if err != nil {
  6631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6632. return
  6633. }
  6634. c.ServeSuccessJSON(map[string]interface{}{
  6635. "caseHistory": caseHistory,
  6636. "historyInfo": historyInfo,
  6637. })
  6638. return
  6639. } else if errcodes == nil {
  6640. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6641. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6642. if err != nil {
  6643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6644. return
  6645. }
  6646. c.ServeSuccessJSON(map[string]interface{}{
  6647. "caseHistory": caseHistory,
  6648. "historyInfo": historyInfo,
  6649. })
  6650. }
  6651. //查询该患者是否有病历
  6652. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6653. //if errcode == gorm.ErrRecordNotFound {
  6654. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6655. // if err != nil {
  6656. // c.ServeSuccessJSON(map[string]interface{}{
  6657. // "msg": "保存成功",
  6658. // })
  6659. // }
  6660. //} else if errcode == nil {
  6661. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6662. // return
  6663. //}
  6664. }
  6665. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6666. patient_id, _ := c.GetInt64("patient_id", 0)
  6667. adminUser := c.GetAdminUserInfo()
  6668. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6669. c.ServeSuccessJSON(map[string]interface{}{
  6670. "list": caseHistorys,
  6671. })
  6672. }
  6673. func (c *HisApiController) GetHisPatientCaseHistory() {
  6674. record_date, _ := c.GetInt64("record_date", 0)
  6675. patient_id, _ := c.GetInt64("patient_id", 0)
  6676. admin := c.GetAdminUserInfo()
  6677. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6678. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6679. c.ServeSuccessJSON(map[string]interface{}{
  6680. "info": info,
  6681. "case_history": case_history,
  6682. })
  6683. }
  6684. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6685. template_name := c.GetString("template_name")
  6686. template_remark := c.GetString("template_remark")
  6687. doctor := c.GetAdminUserInfo().AdminUser.Id
  6688. diagnostic := c.GetString("diagnostic")
  6689. chief_conplaint := c.GetString("chief_conplain")
  6690. history_of_present_illness := c.GetString("history_of_present_illness")
  6691. past_history := c.GetString("past_history")
  6692. personal_history := c.GetString("personal_history")
  6693. family_history := c.GetString("family_history")
  6694. user_name := c.GetString("user_name")
  6695. doctor_advice := c.GetString("doctor_advice")
  6696. remark := c.GetString("remark")
  6697. //record_date := c.GetString("record_date")
  6698. //fmt.Println("record_date--------",record_date)
  6699. //timeLayout := "2006-01-02"
  6700. //loc, _ := time.LoadLocation("Local")
  6701. //
  6702. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6703. //if err != nil {
  6704. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6705. // return
  6706. //}
  6707. //recordDateTime := theTime.Unix()
  6708. ctime := time.Now().Unix()
  6709. template := models.HisCaseHistoryTemplate{
  6710. HistoryOfPresentIllness: history_of_present_illness,
  6711. PastHistory: past_history,
  6712. ChiefConplaint: chief_conplaint,
  6713. PersonalHistory: personal_history,
  6714. FamilyHistory: family_history,
  6715. Diagnostic: diagnostic,
  6716. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6717. Status: 1,
  6718. Ctime: ctime,
  6719. Mtime: ctime,
  6720. RecordDate: time.Now().Unix(),
  6721. TemplateName: template_name,
  6722. TemplateRemark: template_remark,
  6723. Creator: doctor,
  6724. Modifier: doctor,
  6725. UserName: user_name,
  6726. DoctorAdvice: doctor_advice,
  6727. Remark: remark,
  6728. }
  6729. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6730. if err == nil {
  6731. c.ServeSuccessJSON(map[string]interface{}{
  6732. "msg": "保存成功",
  6733. })
  6734. } else {
  6735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6736. return
  6737. }
  6738. }
  6739. func (c *HisApiController) GetCaseHistoryTemplate() {
  6740. timeLayout := "2006-01-02"
  6741. loc, _ := time.LoadLocation("Local")
  6742. keyword := c.GetString("keyword")
  6743. start_time := c.GetString("start_time")
  6744. end_time := c.GetString("end_time")
  6745. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6746. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6747. admin := c.GetAdminUserInfo()
  6748. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6749. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6750. c.ServeSuccessJSON(map[string]interface{}{
  6751. "template": template,
  6752. //"history": history,
  6753. })
  6754. }
  6755. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6756. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6757. utils.ErrorLog("drug_name")
  6758. return enums.ErrorCodeParamWrong
  6759. }
  6760. adviceName, _ := json["drug_name"].(string)
  6761. if len(adviceName) == 0 {
  6762. utils.ErrorLog("len(advice_name) == 0")
  6763. return enums.ErrorCodeParamWrong
  6764. }
  6765. advice.AdviceName = adviceName
  6766. adviceDesc, _ := json["advice_desc"].(string)
  6767. advice.AdviceDesc = adviceDesc
  6768. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6769. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6770. advice.DrugSpec = drugSpec
  6771. }
  6772. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6773. remark, _ := json["remark"].(string)
  6774. advice.Remark = remark
  6775. }
  6776. if json["id"] == nil {
  6777. advice.DrugId = 0
  6778. } else {
  6779. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6780. drug_id := int64(json["id"].(float64))
  6781. advice.DrugId = drug_id
  6782. }
  6783. }
  6784. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6785. advice_id := int64(json["advice_id"].(float64))
  6786. advice.ID = advice_id
  6787. if advice.ID > 0 {
  6788. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6789. if err == nil {
  6790. if hisAdvice.ID > 0 {
  6791. advice.ExecutionTime = hisAdvice.ExecutionTime
  6792. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6793. advice.ExecutionState = hisAdvice.ExecutionState
  6794. advice.CheckTime = hisAdvice.CheckTime
  6795. advice.Checker = hisAdvice.Checker
  6796. advice.CheckState = hisAdvice.CheckState
  6797. advice.StartTime = hisAdvice.StartTime
  6798. advice.FeedetlSn = hisAdvice.FeedetlSn
  6799. }
  6800. }
  6801. }
  6802. }
  6803. //
  6804. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6805. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6806. // advice.ExecutionTime = execution_time
  6807. //}
  6808. //
  6809. //
  6810. //
  6811. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6812. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6813. // advice.ExecutionStaff = execution_staff
  6814. //}
  6815. //
  6816. //
  6817. //
  6818. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6819. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6820. // advice.ExecutionState = execution_state
  6821. //}
  6822. //
  6823. //
  6824. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6825. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6826. // advice.CheckTime = check_time
  6827. //}
  6828. //
  6829. //
  6830. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6831. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6832. // advice.CheckState = check_state
  6833. //}
  6834. //
  6835. //
  6836. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6837. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6838. // advice.Checker = checker
  6839. //}
  6840. //
  6841. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6842. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6843. // advice.StartTime = start_time
  6844. //}
  6845. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6846. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6847. advice.IsSelfDrug = is_self_drug
  6848. }
  6849. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6850. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6851. drug_way_count, _ := json["drug_way_count"].(string)
  6852. advice.DrugWayCount = drug_way_count
  6853. }
  6854. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6855. drugSpecUnit, _ := json["min_unit"].(string)
  6856. advice.DrugSpecUnit = drugSpecUnit
  6857. }
  6858. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6859. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6860. advice.SingleDose = singleDose
  6861. }
  6862. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6863. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6864. advice.SingleDoseUnit = singleDoseUnit
  6865. }
  6866. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6867. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6868. advice.PrescribingNumber = prescribingNumber
  6869. }
  6870. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6871. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6872. advice.PrescribingNumberUnit = prescribingNumberUnit
  6873. }
  6874. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6875. deliveryWay, _ := json["delivery_way"].(string)
  6876. advice.DeliveryWay = deliveryWay
  6877. }
  6878. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6879. executionFrequency, _ := json["execution_frequency"].(string)
  6880. advice.ExecutionFrequency = executionFrequency
  6881. }
  6882. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6883. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6884. advice.Price = price
  6885. }
  6886. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6887. med_list_codg, _ := json["medical_insurance_number"].(string)
  6888. advice.MedListCodg = med_list_codg
  6889. }
  6890. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6891. day := int64(json["day"].(float64))
  6892. advice.Day = day
  6893. }
  6894. return 0
  6895. }
  6896. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6897. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6898. id := int64(json["id"].(float64))
  6899. project.ID = id
  6900. historyProject, _ := service.GetHisProjectByID(id)
  6901. project.FeedetlSn = historyProject.FeedetlSn
  6902. }
  6903. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6904. project_id := int64(json["project_id"].(float64))
  6905. project.ProjectId = project_id
  6906. }
  6907. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6908. // price := int64(json["price"].(float64))
  6909. // formatInt_price := strconv.FormatInt(price, 10)
  6910. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6911. // project.Price = float_price
  6912. // }
  6913. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6914. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6915. project.Price = price
  6916. }
  6917. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6918. total, _ := json["total"].(string)
  6919. project.Count = total
  6920. }
  6921. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6922. medical_code, _ := json["medical_code"].(string)
  6923. project.MedListCodg = medical_code
  6924. }
  6925. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6926. single_dose, _ := json["single_dose"].(string)
  6927. project.SingleDose = single_dose
  6928. }
  6929. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6930. delivery_way, _ := json["delivery_way"].(string)
  6931. project.DeliveryWay = delivery_way
  6932. }
  6933. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6934. execution_frequency, _ := json["execution_frequency"].(string)
  6935. project.ExecutionFrequency = execution_frequency
  6936. }
  6937. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6938. remark, _ := json["remark"].(string)
  6939. project.Remark = remark
  6940. }
  6941. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6942. day, _ := json["number_days"].(string)
  6943. project.Day = day
  6944. }
  6945. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6946. unit, _ := json["unit"].(string)
  6947. project.Unit = unit
  6948. }
  6949. return 0
  6950. }
  6951. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6952. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6953. id := int64(json["id"].(float64))
  6954. historyAddtions, _ := service.GetHisAdditionByID(id)
  6955. additionalCharge.ID = id
  6956. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6957. }
  6958. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6959. item_id := int64(json["item_id"].(float64))
  6960. additionalCharge.ItemId = item_id
  6961. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6962. if config.ID > 0 {
  6963. if len(config.Code) > 0 {
  6964. additionalCharge.MedListCodg = config.Code
  6965. }
  6966. }
  6967. }
  6968. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6969. // price := int64(json["price"].(float64))
  6970. // formatInt_price := strconv.FormatInt(price, 10)
  6971. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6972. // additionalCharge.Price = float_price
  6973. // }
  6974. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6975. // price := int64(json["price"].(float64))
  6976. // formatInt_price := strconv.FormatInt(price, 10)
  6977. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6978. // additionalCharge.Price = float_price
  6979. //}
  6980. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6981. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6982. additionalCharge.Price = price
  6983. }
  6984. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6985. count, _ := json["count"].(string)
  6986. counts, _ := strconv.ParseInt(count, 10, 64)
  6987. additionalCharge.Count = counts
  6988. }
  6989. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6990. item_name, _ := json["item_name"].(string)
  6991. additionalCharge.ItemName = item_name
  6992. }
  6993. return 0
  6994. }
  6995. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6996. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6997. utils.ErrorLog("drug_name")
  6998. return enums.ErrorCodeParamWrong
  6999. }
  7000. adviceName, _ := json["drug_name"].(string)
  7001. if len(adviceName) == 0 {
  7002. utils.ErrorLog("len(advice_name) == 0")
  7003. return enums.ErrorCodeParamWrong
  7004. }
  7005. advice.AdviceName = adviceName
  7006. adviceDesc, _ := json["advice_desc"].(string)
  7007. advice.AdviceDesc = adviceDesc
  7008. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7009. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7010. advice.DrugSpec = drugSpec
  7011. }
  7012. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7013. remark, _ := json["remark"].(string)
  7014. advice.Remark = remark
  7015. }
  7016. if json["id"] == nil {
  7017. advice.DrugId = 0
  7018. } else {
  7019. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7020. drug_id := int64(json["id"].(float64))
  7021. advice.DrugId = drug_id
  7022. }
  7023. }
  7024. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7025. groupno := int64(json["groupno"].(float64))
  7026. advice.Groupno = groupno
  7027. }
  7028. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7029. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7030. advice.IsSelfDrug = is_self_drug
  7031. }
  7032. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7033. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7034. drug_way_count, _ := json["drug_way_count"].(string)
  7035. advice.DrugWayCount = drug_way_count
  7036. }
  7037. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7038. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7039. advice.HospApprFlag = hosp_appr_flag
  7040. }
  7041. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7042. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7043. advice.PrescribingNumber = prescribingNumber
  7044. }
  7045. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7046. // frequency_type := int64(json["frequency_type"].(float64))
  7047. // advice.FrequencyType = frequency_type
  7048. //}
  7049. //
  7050. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7051. // day_count := int64(json["day_count"].(float64))
  7052. // advice.DayCount = day_count
  7053. //}
  7054. //
  7055. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7056. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7057. // week_day, _ := json["week_day"].(string)
  7058. // advice.WeekDay = week_day
  7059. //}
  7060. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7061. drugSpecUnit, _ := json["min_unit"].(string)
  7062. advice.DrugSpecUnit = drugSpecUnit
  7063. }
  7064. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7065. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7066. advice.SingleDose = singleDose
  7067. }
  7068. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7069. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7070. advice.SingleDoseUnit = singleDoseUnit
  7071. }
  7072. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7073. deliveryWay, _ := json["delivery_way"].(string)
  7074. advice.DeliveryWay = deliveryWay
  7075. }
  7076. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7077. executionFrequency, _ := json["execution_frequency"].(string)
  7078. advice.ExecutionFrequency = executionFrequency
  7079. }
  7080. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7081. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7082. advice.Price = price
  7083. }
  7084. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7085. med_list_codg, _ := json["medical_insurance_number"].(string)
  7086. advice.MedListCodg = med_list_codg
  7087. }
  7088. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7089. day := int64(json["day"].(float64))
  7090. advice.Day = day
  7091. }
  7092. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7093. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7094. advice.PrescribingNumberUnit = prescribingNumberUnit
  7095. }
  7096. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7097. advice_id := int64(json["advice_id"].(float64))
  7098. advice.ID = advice_id
  7099. if advice.ID > 0 {
  7100. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7101. if err == nil {
  7102. if hisAdvice.ID > 0 {
  7103. advice.ExecutionTime = hisAdvice.ExecutionTime
  7104. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7105. advice.ExecutionState = hisAdvice.ExecutionState
  7106. advice.CheckTime = hisAdvice.CheckTime
  7107. advice.Checker = hisAdvice.Checker
  7108. advice.CheckState = hisAdvice.CheckState
  7109. advice.StartTime = hisAdvice.StartTime
  7110. advice.HospApprFlag = hisAdvice.HospApprFlag
  7111. advice.IsMedicine = hisAdvice.IsMedicine
  7112. if hisAdvice.UserOrgId == 10028 {
  7113. 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 {
  7114. advice.ExecutionTime = 0
  7115. advice.ExecutionStaff = 0
  7116. advice.ExecutionState = 2
  7117. advice.CheckTime = 0
  7118. advice.Checker = 0
  7119. advice.CheckState = 2
  7120. }
  7121. } else {
  7122. 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 {
  7123. advice.ExecutionTime = 0
  7124. advice.ExecutionStaff = 0
  7125. advice.ExecutionState = 2
  7126. advice.CheckTime = 0
  7127. advice.Checker = 0
  7128. advice.CheckState = 2
  7129. advice.UpdatedTime = time.Now().Unix()
  7130. }
  7131. }
  7132. //advice.Groupno = hisAdvice.Groupno
  7133. }
  7134. }
  7135. }
  7136. }
  7137. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7138. //
  7139. //if drugStockConfig.IsOpen == 1 {
  7140. //
  7141. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7142. // if advice.ID == 0 { //医嘱不存在
  7143. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7144. // drug.Total = drug.Total - advice.PrescribingNumber
  7145. // service.UpdateBaseDrugLib(&drug)
  7146. //
  7147. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7148. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7149. // drug.Total = drug.Total - num
  7150. // service.UpdateBaseDrugLib(&drug)
  7151. // }
  7152. //
  7153. // } else if advice.ID > 0 { //医嘱存在
  7154. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7155. // var num float64
  7156. //
  7157. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7158. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7159. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7160. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7161. // drug.Total = drug.Total + num
  7162. // service.UpdateBaseDrugLib(&drug)
  7163. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7164. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7165. // drug.Total = drug.Total - num
  7166. // service.UpdateBaseDrugLib(&drug)
  7167. // }
  7168. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7169. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7170. // if num2 > advice.PrescribingNumber {
  7171. // num = num2 - advice.PrescribingNumber
  7172. // drug.Total = drug.Total + num
  7173. // service.UpdateBaseDrugLib(&drug)
  7174. // } else if num2 < advice.PrescribingNumber {
  7175. // num = advice.PrescribingNumber - num2
  7176. // drug.Total = drug.Total - num
  7177. // service.UpdateBaseDrugLib(&drug)
  7178. // }
  7179. //
  7180. // }
  7181. //
  7182. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7183. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7184. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7185. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7186. // if num1 > num2 {
  7187. // num = num1 - num2
  7188. // drug.Total = drug.Total + num
  7189. // service.UpdateBaseDrugLib(&drug)
  7190. // } else if num1 < num2 {
  7191. // num = num2 - num1
  7192. // drug.Total = drug.Total - num
  7193. // service.UpdateBaseDrugLib(&drug)
  7194. // }
  7195. //
  7196. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7197. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7198. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7199. // if hisAdvice.PrescribingNumber > num2 {
  7200. // num = hisAdvice.PrescribingNumber - num2
  7201. // drug.Total = drug.Total + num
  7202. // service.UpdateBaseDrugLib(&drug)
  7203. // } else if num2 < advice.PrescribingNumber {
  7204. // num = num2 - hisAdvice.PrescribingNumber
  7205. // drug.Total = drug.Total - num
  7206. // service.UpdateBaseDrugLib(&drug)
  7207. // }
  7208. //
  7209. // }
  7210. // }
  7211. // }
  7212. //}
  7213. //
  7214. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7215. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7216. // advice.ExecutionTime = execution_time
  7217. //}
  7218. //
  7219. //
  7220. //
  7221. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7222. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7223. // advice.ExecutionStaff = execution_staff
  7224. //}
  7225. //
  7226. //
  7227. //
  7228. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7229. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7230. // advice.ExecutionState = execution_state
  7231. //}
  7232. //
  7233. //
  7234. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7235. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7236. // advice.CheckTime = check_time
  7237. //}
  7238. //
  7239. //
  7240. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7241. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7242. // advice.CheckState = check_state
  7243. //}
  7244. //
  7245. //
  7246. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7247. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7248. // advice.Checker = checker
  7249. //}
  7250. //
  7251. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7252. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7253. // advice.StartTime = start_time
  7254. //}
  7255. return 0
  7256. }
  7257. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7258. project.ExecutionStaff = 0
  7259. project.ExecutionState = 2
  7260. project.ExecutionTime = 0
  7261. project.Checker = 0
  7262. project.CheckState = 2
  7263. project.CheckTime = 0
  7264. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7265. id := int64(json["id"].(float64))
  7266. project.ID = id
  7267. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7268. project.ExecutionStaff = temp_project.ExecutionStaff
  7269. project.ExecutionState = temp_project.ExecutionState
  7270. project.ExecutionTime = temp_project.ExecutionTime
  7271. project.Checker = temp_project.Checker
  7272. project.CheckState = temp_project.CheckState
  7273. project.CheckTime = temp_project.CheckTime
  7274. project.TeamId = temp_project.TeamId
  7275. }
  7276. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7277. types := int64(json["type"].(float64))
  7278. project.Type = types
  7279. }
  7280. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7281. project_id := int64(json["project_id"].(float64))
  7282. project.ProjectId = project_id
  7283. }
  7284. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7285. team_id := int64(json["team_id"].(float64))
  7286. project.TeamId = team_id
  7287. }
  7288. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7289. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7290. project.Price = price
  7291. }
  7292. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7293. total, _ := json["total"].(string)
  7294. //totals, _ := strconv.ParseInt(total, 10, 64)
  7295. project.Count = total
  7296. }
  7297. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7298. medical_code, _ := json["medical_code"].(string)
  7299. project.MedListCodg = medical_code
  7300. }
  7301. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7302. single_dose, _ := json["single_dose"].(string)
  7303. project.SingleDose = single_dose
  7304. }
  7305. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7306. delivery_way, _ := json["delivery_way"].(string)
  7307. project.DeliveryWay = delivery_way
  7308. }
  7309. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7310. execution_frequency, _ := json["execution_frequency"].(string)
  7311. project.ExecutionFrequency = execution_frequency
  7312. }
  7313. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7314. remark, _ := json["remark"].(string)
  7315. project.Remark = remark
  7316. }
  7317. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7318. day, _ := json["number_days"].(string)
  7319. project.Day = day
  7320. }
  7321. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7322. unit, _ := json["unit"].(string)
  7323. project.Unit = unit
  7324. }
  7325. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7326. // frequency_type := int64(json["frequency_type"].(float64))
  7327. // project.FrequencyType = frequency_type
  7328. //}
  7329. //
  7330. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7331. // day_count := int64(json["day_count"].(float64))
  7332. // project.DayCount = day_count
  7333. //}
  7334. //
  7335. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7336. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7337. // week_day, _ := json["week_day"].(string)
  7338. // project.WeekDay = week_day
  7339. //}
  7340. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7341. //
  7342. //if project.ID == 0 {
  7343. // if stockConfig.IsOpen == 1 {
  7344. // if project.Type == 3 {
  7345. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7346. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7347. // good.Total = good.Total - f_count
  7348. // service.UpdateGoodInfo(&good)
  7349. // }
  7350. // }
  7351. //
  7352. //} else {
  7353. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7354. //
  7355. // if stockConfig.IsOpen == 1 {
  7356. // if project.Type == 3 {
  7357. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7358. // if project.Count < temp_project.Count {
  7359. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7360. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7361. //
  7362. // other_count := f_count_two - f_count_one
  7363. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7364. // good.Total = good.Total + other_count_two
  7365. // service.UpdateGoodInfo(&good)
  7366. // } else if project.Count > temp_project.Count {
  7367. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7368. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7369. //
  7370. // other_count := f_count_one - f_count_two
  7371. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7372. // good.Total = good.Total - other_count_two
  7373. // service.UpdateGoodInfo(&good)
  7374. // }
  7375. //
  7376. // }
  7377. // }
  7378. //
  7379. //}
  7380. return 0
  7381. }
  7382. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7383. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7384. utils.ErrorLog("drug_name")
  7385. return enums.ErrorCodeParamWrong
  7386. }
  7387. adviceName, _ := json["drug_name"].(string)
  7388. if len(adviceName) == 0 {
  7389. utils.ErrorLog("len(advice_name) == 0")
  7390. return enums.ErrorCodeParamWrong
  7391. }
  7392. advice.AdviceName = adviceName
  7393. adviceDesc, _ := json["advice_desc"].(string)
  7394. advice.AdviceDesc = adviceDesc
  7395. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7396. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7397. advice.DrugSpec = drugSpec
  7398. }
  7399. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7400. remark, _ := json["remark"].(string)
  7401. advice.Remark = remark
  7402. }
  7403. if json["id"] == nil {
  7404. advice.DrugId = 0
  7405. } else {
  7406. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7407. drug_id := int64(json["id"].(float64))
  7408. advice.DrugId = drug_id
  7409. }
  7410. }
  7411. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7412. groupno := int64(json["groupno"].(float64))
  7413. advice.Groupno = groupno
  7414. }
  7415. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7416. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7417. advice.IsSelfDrug = is_self_drug
  7418. }
  7419. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7420. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7421. drug_way_count, _ := json["drug_way_count"].(string)
  7422. advice.DrugWayCount = drug_way_count
  7423. }
  7424. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7425. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7426. advice.HospApprFlag = hosp_appr_flag
  7427. }
  7428. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7429. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7430. advice.PrescribingNumber = prescribingNumber
  7431. }
  7432. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7433. // frequency_type := int64(json["frequency_type"].(float64))
  7434. // advice.FrequencyType = frequency_type
  7435. //}
  7436. //
  7437. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7438. // day_count := int64(json["day_count"].(float64))
  7439. // advice.DayCount = day_count
  7440. //}
  7441. //
  7442. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7443. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7444. // week_day, _ := json["week_day"].(string)
  7445. // advice.WeekDay = week_day
  7446. //}
  7447. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7448. drugSpecUnit, _ := json["min_unit"].(string)
  7449. advice.DrugSpecUnit = drugSpecUnit
  7450. }
  7451. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7452. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7453. advice.SingleDose = singleDose
  7454. }
  7455. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7456. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7457. advice.SingleDoseUnit = singleDoseUnit
  7458. }
  7459. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7460. deliveryWay, _ := json["delivery_way"].(string)
  7461. advice.DeliveryWay = deliveryWay
  7462. }
  7463. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7464. executionFrequency, _ := json["execution_frequency"].(string)
  7465. advice.ExecutionFrequency = executionFrequency
  7466. }
  7467. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7468. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7469. advice.Price = price
  7470. }
  7471. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7472. med_list_codg, _ := json["medical_insurance_number"].(string)
  7473. advice.MedListCodg = med_list_codg
  7474. }
  7475. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7476. day := int64(json["day"].(float64))
  7477. advice.Day = day
  7478. }
  7479. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7480. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7481. advice.PrescribingNumberUnit = prescribingNumberUnit
  7482. }
  7483. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7484. advice_id := int64(json["advice_id"].(float64))
  7485. advice.ID = advice_id
  7486. if advice.ID > 0 {
  7487. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7488. if err == nil {
  7489. if hisAdvice.ID > 0 {
  7490. advice.ExecutionTime = hisAdvice.ExecutionTime
  7491. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7492. advice.ExecutionState = hisAdvice.ExecutionState
  7493. advice.CheckTime = hisAdvice.CheckTime
  7494. advice.Checker = hisAdvice.Checker
  7495. advice.DrugCode = hisAdvice.DrugCode
  7496. advice.CheckState = hisAdvice.CheckState
  7497. advice.StartTime = hisAdvice.StartTime
  7498. advice.HospApprFlag = hisAdvice.HospApprFlag
  7499. advice.IsMedicine = hisAdvice.IsMedicine
  7500. if hisAdvice.UserOrgId == 10028 {
  7501. 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 {
  7502. advice.ExecutionTime = 0
  7503. advice.ExecutionStaff = 0
  7504. advice.ExecutionState = 2
  7505. advice.CheckTime = 0
  7506. advice.Checker = 0
  7507. advice.CheckState = 2
  7508. }
  7509. } else {
  7510. 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 {
  7511. advice.ExecutionTime = 0
  7512. advice.ExecutionStaff = 0
  7513. advice.ExecutionState = 2
  7514. advice.CheckTime = 0
  7515. advice.Checker = 0
  7516. advice.CheckState = 2
  7517. //advice.UpdatedTime = time.Now().Unix()
  7518. advice.CreatedTime = hisAdvice.CreatedTime
  7519. advice.UpdatedTime = time.Now().Unix()
  7520. } else {
  7521. advice.CreatedTime = hisAdvice.CreatedTime
  7522. advice.UpdatedTime = hisAdvice.UpdatedTime
  7523. }
  7524. }
  7525. //advice.Groupno = hisAdvice.Groupno
  7526. } else {
  7527. advice.IsMedicine = 0
  7528. ctime := time.Now().Unix()
  7529. advice.CreatedTime = ctime
  7530. advice.UpdatedTime = ctime
  7531. }
  7532. }
  7533. } else {
  7534. advice.IsMedicine = 0
  7535. ctime := time.Now().Unix()
  7536. advice.CreatedTime = ctime
  7537. advice.UpdatedTime = ctime
  7538. }
  7539. }
  7540. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7541. //
  7542. //if drugStockConfig.IsOpen == 1 {
  7543. //
  7544. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7545. // if advice.ID == 0 { //医嘱不存在
  7546. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7547. // drug.Total = drug.Total - advice.PrescribingNumber
  7548. // service.UpdateBaseDrugLib(&drug)
  7549. //
  7550. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7551. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7552. // drug.Total = drug.Total - num
  7553. // service.UpdateBaseDrugLib(&drug)
  7554. // }
  7555. //
  7556. // } else if advice.ID > 0 { //医嘱存在
  7557. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7558. // var num float64
  7559. //
  7560. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7561. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7562. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7563. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7564. // drug.Total = drug.Total + num
  7565. // service.UpdateBaseDrugLib(&drug)
  7566. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7567. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7568. // drug.Total = drug.Total - num
  7569. // service.UpdateBaseDrugLib(&drug)
  7570. // }
  7571. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7572. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7573. // if num2 > advice.PrescribingNumber {
  7574. // num = num2 - advice.PrescribingNumber
  7575. // drug.Total = drug.Total + num
  7576. // service.UpdateBaseDrugLib(&drug)
  7577. // } else if num2 < advice.PrescribingNumber {
  7578. // num = advice.PrescribingNumber - num2
  7579. // drug.Total = drug.Total - num
  7580. // service.UpdateBaseDrugLib(&drug)
  7581. // }
  7582. //
  7583. // }
  7584. //
  7585. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7586. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7587. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7588. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7589. // if num1 > num2 {
  7590. // num = num1 - num2
  7591. // drug.Total = drug.Total + num
  7592. // service.UpdateBaseDrugLib(&drug)
  7593. // } else if num1 < num2 {
  7594. // num = num2 - num1
  7595. // drug.Total = drug.Total - num
  7596. // service.UpdateBaseDrugLib(&drug)
  7597. // }
  7598. //
  7599. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7600. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7601. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7602. // if hisAdvice.PrescribingNumber > num2 {
  7603. // num = hisAdvice.PrescribingNumber - num2
  7604. // drug.Total = drug.Total + num
  7605. // service.UpdateBaseDrugLib(&drug)
  7606. // } else if num2 < advice.PrescribingNumber {
  7607. // num = num2 - hisAdvice.PrescribingNumber
  7608. // drug.Total = drug.Total - num
  7609. // service.UpdateBaseDrugLib(&drug)
  7610. // }
  7611. //
  7612. // }
  7613. // }
  7614. // }
  7615. //}
  7616. //
  7617. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7618. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7619. // advice.ExecutionTime = execution_time
  7620. //}
  7621. //
  7622. //
  7623. //
  7624. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7625. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7626. // advice.ExecutionStaff = execution_staff
  7627. //}
  7628. //
  7629. //
  7630. //
  7631. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7632. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7633. // advice.ExecutionState = execution_state
  7634. //}
  7635. //
  7636. //
  7637. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7638. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7639. // advice.CheckTime = check_time
  7640. //}
  7641. //
  7642. //
  7643. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7644. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7645. // advice.CheckState = check_state
  7646. //}
  7647. //
  7648. //
  7649. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7650. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7651. // advice.Checker = checker
  7652. //}
  7653. //
  7654. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7655. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7656. // advice.StartTime = start_time
  7657. //}
  7658. return 0
  7659. }
  7660. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7661. project.ExecutionStaff = 0
  7662. project.ExecutionState = 2
  7663. project.ExecutionTime = 0
  7664. project.Checker = 0
  7665. project.CheckState = 2
  7666. project.CheckTime = 0
  7667. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7668. id := int64(json["id"].(float64))
  7669. project.ID = id
  7670. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7671. project.ExecutionStaff = temp_project.ExecutionStaff
  7672. project.ExecutionState = temp_project.ExecutionState
  7673. project.ExecutionTime = temp_project.ExecutionTime
  7674. project.Checker = temp_project.Checker
  7675. project.CheckState = temp_project.CheckState
  7676. project.CheckTime = temp_project.CheckTime
  7677. project.TeamId = temp_project.TeamId
  7678. }
  7679. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7680. types := int64(json["type"].(float64))
  7681. project.Type = types
  7682. }
  7683. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7684. project_id := int64(json["project_id"].(float64))
  7685. project.ProjectId = project_id
  7686. }
  7687. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7688. team_id := int64(json["team_id"].(float64))
  7689. project.TeamId = team_id
  7690. }
  7691. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7692. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7693. project.Price = price
  7694. }
  7695. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7696. total, _ := json["total"].(string)
  7697. //totals, _ := strconv.ParseInt(total, 10, 64)
  7698. project.Count = total
  7699. }
  7700. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7701. medical_code, _ := json["medical_code"].(string)
  7702. project.MedListCodg = medical_code
  7703. }
  7704. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7705. single_dose, _ := json["single_dose"].(string)
  7706. project.SingleDose = single_dose
  7707. }
  7708. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7709. delivery_way, _ := json["delivery_way"].(string)
  7710. project.DeliveryWay = delivery_way
  7711. }
  7712. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7713. execution_frequency, _ := json["execution_frequency"].(string)
  7714. project.ExecutionFrequency = execution_frequency
  7715. }
  7716. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7717. remark, _ := json["remark"].(string)
  7718. project.Remark = remark
  7719. }
  7720. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7721. day, _ := json["number_days"].(string)
  7722. project.Day = day
  7723. }
  7724. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7725. unit, _ := json["unit"].(string)
  7726. project.Unit = unit
  7727. }
  7728. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7729. // frequency_type := int64(json["frequency_type"].(float64))
  7730. // project.FrequencyType = frequency_type
  7731. //}
  7732. //
  7733. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7734. // day_count := int64(json["day_count"].(float64))
  7735. // project.DayCount = day_count
  7736. //}
  7737. //
  7738. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7739. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7740. // week_day, _ := json["week_day"].(string)
  7741. // project.WeekDay = week_day
  7742. //}
  7743. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7744. //
  7745. //if project.ID == 0 {
  7746. // if stockConfig.IsOpen == 1 {
  7747. // if project.Type == 3 {
  7748. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7749. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7750. // good.Total = good.Total - f_count
  7751. // service.UpdateGoodInfo(&good)
  7752. // }
  7753. // }
  7754. //
  7755. //} else {
  7756. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7757. //
  7758. // if stockConfig.IsOpen == 1 {
  7759. // if project.Type == 3 {
  7760. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7761. // if project.Count < temp_project.Count {
  7762. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7763. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7764. //
  7765. // other_count := f_count_two - f_count_one
  7766. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7767. // good.Total = good.Total + other_count_two
  7768. // service.UpdateGoodInfo(&good)
  7769. // } else if project.Count > temp_project.Count {
  7770. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7771. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7772. //
  7773. // other_count := f_count_one - f_count_two
  7774. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7775. // good.Total = good.Total - other_count_two
  7776. // service.UpdateGoodInfo(&good)
  7777. // }
  7778. //
  7779. // }
  7780. // }
  7781. //
  7782. //}
  7783. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7784. id := int64(json["id"].(float64))
  7785. if id > 0 {
  7786. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7787. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7788. fmt.Println("666666")
  7789. project.Mtime = time.Now().Unix()
  7790. project.Ctime = temp_project.Ctime
  7791. } else {
  7792. project.Mtime = temp_project.Mtime
  7793. project.Ctime = temp_project.Ctime
  7794. }
  7795. } else {
  7796. ctime := time.Now().Unix()
  7797. project.Mtime = ctime
  7798. project.Ctime = ctime
  7799. }
  7800. }
  7801. return 0
  7802. }
  7803. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7804. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7805. id := int64(json["id"].(float64))
  7806. additionalCharge.ID = id
  7807. }
  7808. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7809. item_id := int64(json["item_id"].(float64))
  7810. additionalCharge.ItemId = item_id
  7811. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7812. if config.ID > 0 {
  7813. if len(config.Code) > 0 {
  7814. additionalCharge.MedListCodg = config.Code
  7815. }
  7816. }
  7817. }
  7818. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7819. // price := int64(json["price"].(float64))
  7820. // formatInt_price := strconv.FormatInt(price, 10)
  7821. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7822. // additionalCharge.Price = float_price
  7823. // }
  7824. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7825. // price := int64(json["price"].(float64))
  7826. // formatInt_price := strconv.FormatInt(price, 10)
  7827. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7828. // additionalCharge.Price = float_price
  7829. //}
  7830. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7831. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7832. additionalCharge.Price = price
  7833. }
  7834. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7835. count, _ := json["count"].(string)
  7836. counts, _ := strconv.ParseInt(count, 10, 64)
  7837. additionalCharge.Count = counts
  7838. }
  7839. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7840. item_name, _ := json["item_name"].(string)
  7841. additionalCharge.ItemName = item_name
  7842. }
  7843. return 0
  7844. }
  7845. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7846. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7847. utils.ErrorLog("drug_name")
  7848. return enums.ErrorCodeParamWrong
  7849. }
  7850. adviceName, _ := json["drug_name"].(string)
  7851. if len(adviceName) == 0 {
  7852. utils.ErrorLog("len(advice_name) == 0")
  7853. return enums.ErrorCodeParamWrong
  7854. }
  7855. advice.AdviceName = adviceName
  7856. adviceDesc, _ := json["advice_desc"].(string)
  7857. advice.AdviceDesc = adviceDesc
  7858. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7859. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7860. advice.DrugSpec = drugSpec
  7861. }
  7862. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7863. remark, _ := json["remark"].(string)
  7864. advice.Remark = remark
  7865. }
  7866. if json["id"] == nil {
  7867. advice.DrugId = 0
  7868. } else {
  7869. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7870. drug_id := int64(json["id"].(float64))
  7871. advice.DrugId = drug_id
  7872. }
  7873. }
  7874. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7875. groupno := int64(json["groupno"].(float64))
  7876. advice.Groupno = groupno
  7877. }
  7878. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7879. drugSpecUnit, _ := json["min_unit"].(string)
  7880. advice.DrugSpecUnit = drugSpecUnit
  7881. }
  7882. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7883. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7884. advice.SingleDose = singleDose
  7885. }
  7886. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7887. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7888. advice.SingleDoseUnit = singleDoseUnit
  7889. }
  7890. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7891. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7892. advice.PrescribingNumber = prescribingNumber
  7893. }
  7894. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7895. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7896. advice.PrescribingNumberUnit = prescribingNumberUnit
  7897. }
  7898. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7899. deliveryWay, _ := json["delivery_way"].(string)
  7900. advice.DeliveryWay = deliveryWay
  7901. }
  7902. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7903. executionFrequency, _ := json["execution_frequency"].(string)
  7904. advice.ExecutionFrequency = executionFrequency
  7905. }
  7906. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7907. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7908. advice.Price = price
  7909. }
  7910. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7911. med_list_codg, _ := json["medical_insurance_number"].(string)
  7912. advice.MedListCodg = med_list_codg
  7913. }
  7914. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7915. day := int64(json["day"].(float64))
  7916. advice.Day = day
  7917. }
  7918. advice.FrequencyType = 1
  7919. return 0
  7920. }
  7921. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7922. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7923. types := int64(json["type"].(float64))
  7924. project.Type = types
  7925. }
  7926. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7927. project_id := int64(json["project_id"].(float64))
  7928. project.ProjectId = project_id
  7929. }
  7930. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7931. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7932. project.Price = price
  7933. }
  7934. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7935. total, _ := json["total"].(string)
  7936. //totals, _ := strconv.ParseInt(total, 10, 64)
  7937. project.Count = total
  7938. }
  7939. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7940. medical_code, _ := json["medical_code"].(string)
  7941. project.MedListCodg = medical_code
  7942. }
  7943. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7944. single_dose, _ := json["single_dose"].(string)
  7945. project.SingleDose = single_dose
  7946. }
  7947. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7948. delivery_way, _ := json["delivery_way"].(string)
  7949. project.DeliveryWay = delivery_way
  7950. }
  7951. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7952. execution_frequency, _ := json["execution_frequency"].(string)
  7953. project.ExecutionFrequency = execution_frequency
  7954. }
  7955. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7956. remark, _ := json["remark"].(string)
  7957. project.Remark = remark
  7958. }
  7959. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7960. day, _ := json["number_days"].(string)
  7961. project.Day = day
  7962. }
  7963. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7964. unit, _ := json["unit"].(string)
  7965. project.Unit = unit
  7966. }
  7967. project.FrequencyType = 1
  7968. return 0
  7969. }
  7970. func (c *HisApiController) GetHisOrderListTwo() {
  7971. start_time := c.GetString("start_time")
  7972. end_time := c.GetString("end_time")
  7973. timeLayout := "2006-01-02"
  7974. loc, _ := time.LoadLocation("Local")
  7975. var startTime int64
  7976. if len(start_time) > 0 {
  7977. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7978. if err != nil {
  7979. //fmt.Println(err)
  7980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7981. return
  7982. }
  7983. startTime = theTime.Unix()
  7984. }
  7985. var endTime int64
  7986. if len(end_time) > 0 {
  7987. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7988. if err != nil {
  7989. utils.ErrorLog(err.Error())
  7990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7991. return
  7992. }
  7993. endTime = theTime.Unix()
  7994. }
  7995. adminUser := c.GetAdminUserInfo()
  7996. org_id := adminUser.CurrentOrgId
  7997. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7998. if err == nil {
  7999. c.ServeSuccessJSON(map[string]interface{}{
  8000. "order2": order,
  8001. })
  8002. } else {
  8003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8004. return
  8005. }
  8006. }
  8007. func (c *HisApiController) GetHisOrderList() {
  8008. page, _ := c.GetInt64("page", -1)
  8009. limit, _ := c.GetInt64("limit", -1)
  8010. start_time := c.GetString("start_time")
  8011. end_time := c.GetString("end_time")
  8012. types, _ := c.GetInt64("type", 0)
  8013. keywords := c.GetString("keywords")
  8014. p_type, _ := c.GetInt64("p_type", 0)
  8015. sort_type, _ := c.GetInt64("sort_type", 0)
  8016. charge_type, _ := c.GetInt64("charge_type", 0)
  8017. sch_type, _ := c.GetInt64("sch_type", 0)
  8018. zone_type, _ := c.GetInt64("zone_type", 0)
  8019. med_type, _ := c.GetInt64("med_type", 0)
  8020. timeLayout := "2006-01-02"
  8021. loc, _ := time.LoadLocation("Local")
  8022. var startTime int64
  8023. if len(start_time) > 0 {
  8024. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8025. if err != nil {
  8026. //fmt.Println(err)
  8027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8028. return
  8029. }
  8030. startTime = theTime.Unix()
  8031. }
  8032. var endTime int64
  8033. if len(end_time) > 0 {
  8034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8035. if err != nil {
  8036. utils.ErrorLog(err.Error())
  8037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8038. return
  8039. }
  8040. endTime = theTime.Unix()
  8041. }
  8042. adminUser := c.GetAdminUserInfo()
  8043. org_id := adminUser.CurrentOrgId
  8044. 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)
  8045. for _, item := range order {
  8046. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8047. item.DoctorName = info.Doctor
  8048. item.DepartmentName = info.XtHisDepartment.Name
  8049. }
  8050. if err == nil {
  8051. c.ServeSuccessJSON(map[string]interface{}{
  8052. "order": order,
  8053. "total": total,
  8054. })
  8055. } else {
  8056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8057. return
  8058. }
  8059. }
  8060. func (c *HisApiController) GetHisOrder() {
  8061. patient_id, _ := c.GetInt64("patient_id", 0)
  8062. number := c.GetString("number")
  8063. adminInfo := c.GetAdminUserInfo()
  8064. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8065. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8066. if err == nil {
  8067. c.ServeSuccessJSON(map[string]interface{}{
  8068. "order": order,
  8069. "prescription": prescriptions,
  8070. })
  8071. } else {
  8072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8073. return
  8074. }
  8075. }
  8076. func (c *HisApiController) GetHisPrescriptionList() {
  8077. record_date := c.GetString("record_date")
  8078. keywords := c.GetString("keywords")
  8079. page, _ := c.GetInt64("page")
  8080. limit, _ := c.GetInt64("limit")
  8081. sch_type, _ := c.GetInt64("sch_type")
  8082. timeLayout := "2006-01-02"
  8083. loc, _ := time.LoadLocation("Local")
  8084. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8085. if err != nil {
  8086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8087. return
  8088. }
  8089. recordDateTime := theTime.Unix()
  8090. adminInfo := c.GetAdminUserInfo()
  8091. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8092. //adminInfo := c.GetAdminUserInfo()
  8093. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8094. //fmt.Println(prescriptionOrder)
  8095. if err == nil {
  8096. c.ServeSuccessJSON(map[string]interface{}{
  8097. "order": prescriptionOrder,
  8098. "total": total,
  8099. })
  8100. } else {
  8101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8102. return
  8103. }
  8104. }
  8105. func (c *HisApiController) GetHisPrescriptionInfo() {
  8106. id, _ := c.GetInt64("id")
  8107. adminInfo := c.GetAdminUserInfo()
  8108. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8109. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8110. if err == nil {
  8111. c.ServeSuccessJSON(map[string]interface{}{
  8112. "order": prescriptionOrder,
  8113. "prescription": prescription,
  8114. })
  8115. } else {
  8116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8117. return
  8118. }
  8119. }
  8120. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8121. adminUser := c.GetAdminUserInfo()
  8122. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8123. c.ServeSuccessJSON(map[string]interface{}{
  8124. "config": config,
  8125. })
  8126. }
  8127. type ResultTwo struct {
  8128. ErrMsg interface{} `json:"err_msg"`
  8129. InfRefmsgid string `json:"inf_refmsgid"`
  8130. Infcode int64 `json:"infcode"`
  8131. Output struct {
  8132. Baseinfo struct {
  8133. Age float64 `json:"age"`
  8134. Brdy string `json:"brdy"`
  8135. Certno string `json:"certno"`
  8136. Gend string `json:"gend"`
  8137. Naty string `json:"naty"`
  8138. PsnCertType string `json:"psn_cert_type"`
  8139. PsnName string `json:"psn_name"`
  8140. PsnNo string `json:"psn_no"`
  8141. } `json:"baseinfo"`
  8142. Idetinfo []interface{} `json:"idetinfo"`
  8143. Iinfo []struct {
  8144. Balc float64 `json:"balc"`
  8145. CvlservFlag string `json:"cvlserv_flag"`
  8146. EmpName string `json:"emp_name"`
  8147. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8148. Insutype string `json:"insutype"`
  8149. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8150. PausInsuDate interface{} `json:"paus_insu_date"`
  8151. PsnInsuDate string `json:"psn_insu_date"`
  8152. PsnInsuStas string `json:"psn_insu_stas"`
  8153. PsnType string `json:"psn_type"`
  8154. } `json:"insuinfo"`
  8155. } `json:"output"`
  8156. RefmsgTime string `json:"refmsg_time"`
  8157. RespondTime string `json:"respond_time"`
  8158. Signtype interface{} `json:"signtype"`
  8159. WarnInfo interface{} `json:"warn_info"`
  8160. }
  8161. type ResultThree struct {
  8162. Cainfo interface{} `json:"cainfo"`
  8163. ErrMsg interface{} `json:"err_msg"`
  8164. InfRefmsgid string `json:"inf_refmsgid"`
  8165. Infcode int64 `json:"infcode"`
  8166. Output struct {
  8167. Data struct {
  8168. IptOtpNo string `json:"ipt_otp_no"`
  8169. MdtrtID string `json:"mdtrt_id"`
  8170. PsnNo string `json:"psn_no"`
  8171. } `json:"data"`
  8172. } `json:"output"`
  8173. RefmsgTime string `json:"refmsg_time"`
  8174. RespondTime string `json:"respond_time"`
  8175. Signtype interface{} `json:"signtype"`
  8176. WarnMsg interface{} `json:"warn_msg"`
  8177. }
  8178. type ResultFour struct {
  8179. Cainfo string `json:"cainfo"`
  8180. ErrMsg string `json:"err_msg"`
  8181. InfRefmsgid string `json:"inf_refmsgid"`
  8182. Infcode int64 `json:"infcode"`
  8183. Output struct {
  8184. Result []struct {
  8185. BasMednFlag string `json:"bas_medn_flag"`
  8186. ChldMedcFlag string `json:"chld_medc_flag"`
  8187. ChrgitmLv string `json:"chrgitm_lv"`
  8188. Cnt float64 `json:"cnt"`
  8189. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8190. DrtReimFlag string `json:"drt_reim_flag"`
  8191. FeedetlSn string `json:"feedetl_sn"`
  8192. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8193. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8194. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8195. ListSpItemFlag string `json:"list_sp_item_flag"`
  8196. LmtUsedFlag string `json:"lmt_used_flag"`
  8197. MedChrgitmType string `json:"med_chrgitm_type"`
  8198. Memo string `json:"memo"`
  8199. OverlmtAmt float64 `json:"overlmt_amt"`
  8200. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8201. Pric float64 `json:"pric"`
  8202. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8203. SelfpayProp float64 `json:"selfpay_prop"`
  8204. } `json:"result"`
  8205. } `json:"output"`
  8206. RefmsgTime string `json:"refmsg_time"`
  8207. RespondTime string `json:"respond_time"`
  8208. Signtype string `json:"signtype"`
  8209. WarnMsg string `json:"warn_msg"`
  8210. }
  8211. type ResultFive struct {
  8212. Insutype string `json:"insutype"`
  8213. }
  8214. type ResultSix struct {
  8215. Cainfo interface{} `json:"cainfo"`
  8216. ErrMsg interface{} `json:"err_msg"`
  8217. InfRefmsgid string `json:"inf_refmsgid"`
  8218. Infcode int64 `json:"infcode"`
  8219. Output struct {
  8220. } `json:"output"`
  8221. RefmsgTime string `json:"refmsg_time"`
  8222. RespondTime string `json:"respond_time"`
  8223. Signtype interface{} `json:"signtype"`
  8224. WarnMsg interface{} `json:"warn_msg"`
  8225. }
  8226. type ResultSeven struct {
  8227. Cainfo string `json:"cainfo"`
  8228. ErrMsg string `json:"err_msg"`
  8229. InfRefmsgid string `json:"inf_refmsgid"`
  8230. Infcode int64 `json:"infcode"`
  8231. Output struct {
  8232. Setldetail []interface{} `json:"setldetail"`
  8233. Setlinfo struct {
  8234. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8235. AcctPay float64 `json:"acct_pay"`
  8236. ActPayDedc float64 `json:"act_pay_dedc"`
  8237. Age float64 `json:"age"`
  8238. Balc float64 `json:"balc"`
  8239. Brdy string `json:"brdy"`
  8240. Certno string `json:"certno"`
  8241. ClrOptins string `json:"clr_optins"`
  8242. ClrType string `json:"clr_type"`
  8243. ClrWay string `json:"clr_way"`
  8244. CvlservFlag string `json:"cvlserv_flag"`
  8245. CvlservPay float64 `json:"cvlserv_pay"`
  8246. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8247. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8248. Gend string `json:"gend"`
  8249. HifesPay float64 `json:"hifes_pay"`
  8250. HifmiPay float64 `json:"hifmi_pay"`
  8251. HifobPay float64 `json:"hifob_pay"`
  8252. HifpPay float64 `json:"hifp_pay"`
  8253. HospPartAmt float64 `json:"hosp_part_amt"`
  8254. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8255. Insutype string `json:"insutype"`
  8256. MafPay float64 `json:"maf_pay"`
  8257. MdtrtCertType string `json:"mdtrt_cert_type"`
  8258. MdtrtID string `json:"mdtrt_id"`
  8259. MedType string `json:"med_type"`
  8260. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8261. MedinsSetlID string `json:"medins_setl_id"`
  8262. Naty string `json:"naty"`
  8263. OthPay float64 `json:"oth_pay"`
  8264. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8265. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8266. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8267. PsnCashPay float64 `json:"psn_cash_pay"`
  8268. PsnCertType string `json:"psn_cert_type"`
  8269. PsnName string `json:"psn_name"`
  8270. PsnNo string `json:"psn_no"`
  8271. PsnPartAmt float64 `json:"psn_part_amt"`
  8272. PsnType string `json:"psn_type"`
  8273. SetlID string `json:"setl_id"`
  8274. SetlTime string `json:"setl_time"`
  8275. } `json:"setlinfo"`
  8276. } `json:"output"`
  8277. RefmsgTime string `json:"refmsg_time"`
  8278. RespondTime string `json:"respond_time"`
  8279. Signtype interface{} `json:"signtype"`
  8280. WarnMsg interface{} `json:"warn_msg"`
  8281. }
  8282. type ResultEight struct {
  8283. Cainfo string `json:"cainfo"`
  8284. ErrMsg string `json:"err_msg"`
  8285. InfRefmsgid string `json:"inf_refmsgid"`
  8286. Infcode int64 `json:"infcode"`
  8287. Output struct {
  8288. Stmtinfo struct {
  8289. SetlOptins string `json:"setl_optins"`
  8290. StmtRslt string `json:"stmt_rslt"`
  8291. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8292. } `json:"stmtinfo"`
  8293. } `json:"output"`
  8294. RefmsgTime string `json:"refmsg_time"`
  8295. RespondTime string `json:"respond_time"`
  8296. Signtype interface{} `json:"signtype"`
  8297. WarnMsg interface{} `json:"warn_msg"`
  8298. }
  8299. type ResultNine struct {
  8300. Cainfo string `json:"cainfo"`
  8301. ErrMsg string `json:"err_msg"`
  8302. InfRefmsgid string `json:"inf_refmsgid"`
  8303. Infcode int64 `json:"infcode"`
  8304. Output struct {
  8305. FileQuryNo string `json:"file_qury_no"`
  8306. } `json:"output"`
  8307. RefmsgTime string `json:"refmsg_time"`
  8308. RespondTime string `json:"respond_time"`
  8309. Signtype interface{} `json:"signtype"`
  8310. WarnMsg interface{} `json:"warn_msg"`
  8311. }
  8312. type ResultTen struct {
  8313. Cainfo string `json:"cainfo"`
  8314. ErrMsg string `json:"err_msg"`
  8315. InfRefmsgid string `json:"inf_refmsgid"`
  8316. Infcode int64 `json:"infcode"`
  8317. Output struct {
  8318. DldEndtime string `json:"dld_endtime"`
  8319. FileQuryNo string `json:"file_qury_no"`
  8320. Filename string `json:"filename"`
  8321. } `json:"output"`
  8322. RefmsgTime string `json:"refmsg_time"`
  8323. RespondTime string `json:"respond_time"`
  8324. Signtype interface{} `json:"signtype"`
  8325. WarnMsg interface{} `json:"warn_msg"`
  8326. }
  8327. type ResultEleven struct {
  8328. Cainfo string `json:"cainfo"`
  8329. ErrMsg string `json:"err_msg"`
  8330. InfRefmsgid string `json:"inf_refmsgid"`
  8331. Infcode int64 `json:"infcode"`
  8332. Output struct {
  8333. Setlinfo struct {
  8334. FixmedinsName string `json:"fixmedins_name"`
  8335. FixmedinsCode string `json:"fixmedins_code"`
  8336. PsnNo string `json:"psn_no"`
  8337. PsnName string `json:"psn_name"`
  8338. HifobPay float64 `json:"hifob_pay"`
  8339. Gend string `json:"gend"`
  8340. Brdy string `json:"brdy"`
  8341. PsnCertType string `json:"psn_cert_type"`
  8342. PsnType string `json:"psn_type"`
  8343. EmpName string `json:"emp_name"`
  8344. Certno string `json:"certno"`
  8345. Insutype string `json:"insutype"`
  8346. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8347. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8348. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8349. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8350. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8351. ActPayDedc float64 `json:"act_pay_dedc"`
  8352. HifpPay float64 `json:"hifp_pay"`
  8353. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8354. CvlservPay float64 `json:"cvlserv_pay"`
  8355. HifesPay float64 `json:"hifes_pay"`
  8356. HifmiPay float64 `json:"hifmi_pay"`
  8357. MafPay float64 `json:"maf_pay"`
  8358. OthPay float64 `json:"oth_pay"`
  8359. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8360. PsnPay float64 `json:"psn_pay"`
  8361. AcctPay float64 `json:"acct_pay"`
  8362. CashPayamt float64 `json:"cash_payamt"`
  8363. Balc float64 `json:"balc"`
  8364. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8365. MedinsSetlId string `json:"medins_setl_id"`
  8366. RefdSetlFlag string `json:"refd_setl_flag"`
  8367. SetlTime string `json:"setl_time"`
  8368. MedType string `json:"med_type"`
  8369. } `json:"setlinfo"`
  8370. } `json:"output"`
  8371. RefmsgTime string `json:"refmsg_time"`
  8372. RespondTime string `json:"respond_time"`
  8373. Signtype interface{} `json:"signtype"`
  8374. WarnMsg interface{} `json:"warn_msg"`
  8375. }
  8376. type Custom struct {
  8377. DetItemFeeSumamt string
  8378. Cut string
  8379. FeedetlSn string
  8380. Price string
  8381. MedListCodg string
  8382. Type int64
  8383. AdviceId int64
  8384. ProjectId int64
  8385. ItemId int64
  8386. CostType int64
  8387. }
  8388. // 获取个人信息----挂号-----上传就诊信息
  8389. func (c *HisApiController) GetRegisterInfo() {
  8390. id, _ := c.GetInt64("id")
  8391. record_time := c.GetString("record_time")
  8392. settlementValue, _ := c.GetInt64("settlement_value")
  8393. medical_insurance_card := c.GetString("medical_insurance_card")
  8394. name := c.GetString("name")
  8395. id_card_type, _ := c.GetInt64("id_card_type")
  8396. certificates, _ := c.GetInt64("certificates")
  8397. medical_care, _ := c.GetInt64("medical_care")
  8398. birthday := c.GetString("birthday")
  8399. age, _ := c.GetInt64("age")
  8400. id_card := c.GetString("id_card")
  8401. register_type, _ := c.GetInt64("register")
  8402. doctor, _ := c.GetInt64("doctor")
  8403. department, _ := c.GetInt64("department")
  8404. gender, _ := c.GetInt64("sex")
  8405. phone := c.GetString("phone")
  8406. registration_fee, _ := c.GetFloat("registration_fee")
  8407. medical_expenses, _ := c.GetFloat("medical_expenses")
  8408. social_type, _ := c.GetInt64("social_type")
  8409. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8410. diagnosis_ids := c.GetString("diagnosis")
  8411. sick_type, _ := c.GetInt64("sick_type")
  8412. reg_type := c.GetString("p_type")
  8413. timeLayout := "2006-01-02"
  8414. loc, _ := time.LoadLocation("Local")
  8415. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8416. birthUnix := birthdays.Unix()
  8417. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8418. if err != nil {
  8419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8420. return
  8421. }
  8422. recordDateTime := theTime.Unix()
  8423. adminInfo := c.GetAdminUserInfo()
  8424. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8425. if tempPatient.ID == 0 {
  8426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8427. return
  8428. }
  8429. var patient service.Patients
  8430. if id == 0 {
  8431. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8432. } else {
  8433. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8434. }
  8435. if patient.ID == 0 {
  8436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8437. return
  8438. }
  8439. if len(patient.IdCardNo) == 0 {
  8440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8441. return
  8442. }
  8443. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8444. if len(his) >= 1 {
  8445. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8446. if len(his) >= 1 && order.ID == 0 {
  8447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8448. return
  8449. }
  8450. }
  8451. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8452. fmt.Println(timeStr)
  8453. timeArr := strings.Split(timeStr, " ")
  8454. fmt.Println(timeArr)
  8455. timeArrTwo := strings.Split(timeArr[0], "-")
  8456. timeArrThree := strings.Split(timeArr[1], ":")
  8457. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8458. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8459. if len(lists) == 0 {
  8460. var hisPatient models.XtHisPatient
  8461. hisPatient = models.XtHisPatient{
  8462. Name: name,
  8463. Age: age,
  8464. Gender: gender,
  8465. Birthday: birthUnix,
  8466. Phone: phone,
  8467. MedicalTreatmentType: medical_care,
  8468. IdType: certificates,
  8469. IdCardNo: id_card,
  8470. BalanceAccountsType: settlementValue,
  8471. SocialType: social_type,
  8472. MedicalInsuranceNumber: medical_insurance_card,
  8473. RegisterType: register_type,
  8474. RegisterCost: registration_fee,
  8475. TreatmentCost: medical_expenses,
  8476. AdminUserId: adminInfo.AdminUser.Id,
  8477. UserOrgId: adminInfo.CurrentOrgId,
  8478. Status: 1,
  8479. RecordDate: recordDateTime,
  8480. IsReturn: 1,
  8481. PatientId: patient.ID,
  8482. Ctime: time.Now().Unix(),
  8483. Mtime: time.Now().Unix(),
  8484. Number: str,
  8485. IdCardType: id_card_type,
  8486. Departments: department,
  8487. Doctor: doctor,
  8488. PType: reg_type,
  8489. Diagnosis: diagnosis_ids,
  8490. SickType: sick_type,
  8491. }
  8492. service.CreateHisPatient(&hisPatient)
  8493. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8494. c.ServeSuccessJSON(map[string]interface{}{
  8495. "his_info": hisPatient,
  8496. })
  8497. } else {
  8498. //chrgBchno := rand.Intn(1000000) + 10000
  8499. var hisPatient models.XtHisPatient
  8500. hisPatient = models.XtHisPatient{
  8501. Name: name,
  8502. Age: age,
  8503. Gender: gender,
  8504. Birthday: birthUnix,
  8505. Phone: phone,
  8506. MedicalTreatmentType: medical_care,
  8507. IdType: certificates,
  8508. IdCardNo: id_card,
  8509. BalanceAccountsType: settlementValue,
  8510. SocialType: social_type,
  8511. MedicalInsuranceNumber: medical_insurance_card,
  8512. RegisterType: register_type,
  8513. RegisterCost: registration_fee,
  8514. TreatmentCost: medical_expenses,
  8515. AdminUserId: adminInfo.AdminUser.Id,
  8516. UserOrgId: adminInfo.CurrentOrgId,
  8517. Status: 1,
  8518. RecordDate: recordDateTime,
  8519. IsReturn: 1,
  8520. PatientId: patient.ID,
  8521. Ctime: time.Now().Unix(),
  8522. Mtime: time.Now().Unix(),
  8523. Number: str,
  8524. IdCardType: id_card_type,
  8525. Departments: department,
  8526. Doctor: doctor,
  8527. PType: reg_type,
  8528. Diagnosis: diagnosis_ids,
  8529. SickType: sick_type,
  8530. }
  8531. service.CreateHisPatient(&hisPatient)
  8532. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8533. c.ServeSuccessJSON(map[string]interface{}{
  8534. "his_info": hisPatient,
  8535. })
  8536. }
  8537. }
  8538. // 上传明细----结算
  8539. func (c *HisApiController) GetUploadInfo() {
  8540. id, _ := c.GetInt64("id")
  8541. record_time := c.GetString("record_time")
  8542. his_patient_id, _ := c.GetInt64("his_patient_id")
  8543. oth_desc := c.GetString("oth_desc")
  8544. pay_way, _ := c.GetInt64("pay_way")
  8545. pay_ways := c.GetString("pay_ways")
  8546. pay_price, _ := c.GetFloat("pay_price")
  8547. pay_card_no := c.GetString("pay_card_no")
  8548. discount_price, _ := c.GetFloat("discount_price")
  8549. preferential_price, _ := c.GetFloat("preferential_price")
  8550. reality_price, _ := c.GetFloat("reality_price")
  8551. found_price, _ := c.GetFloat("found_price")
  8552. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8553. private_price, _ := c.GetFloat("private_price")
  8554. timeLayout := "2006-01-02"
  8555. loc, _ := time.LoadLocation("Local")
  8556. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8557. fapiao_code := c.GetString("fapiao_code")
  8558. fapiao_number := c.GetString("fapiao_number")
  8559. diagnosis_id := c.GetString("diagnosis")
  8560. sick_type, _ := c.GetInt64("sick_type")
  8561. reg_type, _ := c.GetInt64("p_type")
  8562. order_id, _ := c.GetInt64("order_id")
  8563. cash_pay := c.GetString("cash_pay")
  8564. wechat_pay := c.GetString("wechat_pay")
  8565. ali_pay := c.GetString("ali_pay")
  8566. jifen_pay := c.GetString("jifen_pay")
  8567. band_card_pay := c.GetString("band_card_pay")
  8568. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8569. tmp_decimal := c.GetString("tmp_decimal")
  8570. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8571. var decimal float64 //本次使用的押金
  8572. var errmsg error
  8573. tx := service.XTWriteDB().Begin() //开了事务
  8574. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8575. defer func() {
  8576. if errmsg != nil {
  8577. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8578. tx.Rollback()
  8579. } else {
  8580. tx.Commit()
  8581. }
  8582. }()
  8583. fmt.Println("dec_way", dec_way)
  8584. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8585. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8586. return
  8587. }
  8588. if len(tmp_decimal) > 0 {
  8589. if tmp_decimal[0] == 45 {
  8590. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8591. return
  8592. }
  8593. }
  8594. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8595. fmt.Println(errs)
  8596. decimal = tt
  8597. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8598. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8599. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8600. if err != nil {
  8601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8602. return
  8603. }
  8604. recordDateTime := theTime.Unix()
  8605. adminUser := c.GetAdminUserInfo()
  8606. var prescriptions []*models.HisPrescription
  8607. var prescriptionsOne []*models.HisPrescription
  8608. var start_time int64
  8609. var end_time int64
  8610. ids_str := c.GetString("ids")
  8611. ids_arr := strings.Split(ids_str, ",")
  8612. if tempOrder.ID == 0 {
  8613. if settle_accounts_type == 1 { //日结
  8614. fmt.Println(reg_type)
  8615. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8616. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8617. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8618. } else {
  8619. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8620. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8621. }
  8622. } else { //月结
  8623. start_time_str := c.GetString("start_time")
  8624. end_time_str := c.GetString("end_time")
  8625. timeLayout := "2006-01-02"
  8626. loc, _ := time.LoadLocation("Local")
  8627. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8628. if err != nil {
  8629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8630. return
  8631. }
  8632. recordStartTime := theStartTime.Unix()
  8633. start_time = recordStartTime
  8634. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8635. if err != nil {
  8636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8637. return
  8638. }
  8639. recordEndTime := theEndTime.Unix()
  8640. end_time = recordEndTime
  8641. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8642. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8643. }
  8644. var goods []*models.DialysisBeforePrepareGoods
  8645. var newGoods []*models.NewDialysisBeforePrepareGoods
  8646. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8647. var infos []*models.HisDoctorAdviceInfo
  8648. var infoList []*models.HisDoctorAdviceInfo
  8649. var hisAdvice []*models.HisDoctorAdviceInfo
  8650. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8651. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8652. //判断库存不足
  8653. //结算出库开关
  8654. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8655. if settConfig.IsOpen == 1 {
  8656. //判断库存的地方
  8657. for _, info := range prescriptions {
  8658. if info.Type == 1 {
  8659. infos = append(infos, info.HisDoctorAdviceInfo...)
  8660. }
  8661. if info.Type == 2 {
  8662. for _, sumItem := range info.HisPrescriptionProject {
  8663. if sumItem.Type == 3 {
  8664. var good models.DialysisBeforePrepareGoods
  8665. var newGood models.NewDialysisBeforePrepareGoods
  8666. good.GoodId = sumItem.GoodInfo.ID
  8667. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8668. count, _ := strconv.Atoi(sumItem.Count)
  8669. good.Count = int64(count)
  8670. good.StorehouseId = houseConfig.StorehouseOutInfo
  8671. good.ProjectId = sumItem.ID
  8672. goods = append(goods, &good)
  8673. newGood.GoodId = sumItem.GoodInfo.ID
  8674. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8675. count2, _ := strconv.Atoi(sumItem.Count)
  8676. newGood.Count = int64(count2)
  8677. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8678. newGood.ProjectId = sumItem.ID
  8679. newGoods = append(newGoods, &newGood)
  8680. }
  8681. }
  8682. }
  8683. }
  8684. for _, info := range prescriptionsOne {
  8685. if info.Type == 1 {
  8686. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8687. }
  8688. if info.Type == 2 {
  8689. for _, sumItem := range info.HisPrescriptionProject {
  8690. if sumItem.Type == 3 {
  8691. var newGood models.NewDialysisBeforePrepareGoods
  8692. newGood.GoodId = sumItem.GoodInfo.ID
  8693. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8694. count2, _ := strconv.Atoi(sumItem.Count)
  8695. newGood.Count = int64(count2)
  8696. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8697. newGood.ProjectId = sumItem.ID
  8698. newGoodOne = append(newGoodOne, &newGood)
  8699. }
  8700. }
  8701. }
  8702. }
  8703. //判断
  8704. for _, itemOne := range infos {
  8705. for _, itemTwo := range hisAdvice {
  8706. if itemOne.DrugId == itemTwo.DrugId {
  8707. itemTwo.Child = append(itemTwo.Child, itemOne)
  8708. }
  8709. }
  8710. }
  8711. for _, itemTwo := range hisAdvice {
  8712. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8713. var sum_out_count int64
  8714. for _, itemThree := range itemTwo.Child {
  8715. var prescribing_number int64
  8716. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8717. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8718. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8719. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8720. }
  8721. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8722. prescribing_number = parseIntPrescribingNumber
  8723. }
  8724. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8725. prescribing_number = parseIntPrescribingNumber
  8726. }
  8727. sum_out_count += prescribing_number
  8728. }
  8729. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8730. if sum_out_count > drugStockOut.FlushCount {
  8731. c.ServeSuccessJSON(map[string]interface{}{
  8732. "msg": "2",
  8733. "drug": medical,
  8734. })
  8735. return
  8736. }
  8737. }
  8738. for _, itemOne := range newGoods {
  8739. for _, item := range newGoodOne {
  8740. if itemOne.GoodId == item.GoodId {
  8741. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8742. }
  8743. }
  8744. }
  8745. for _, item := range newGoodOne {
  8746. var sum_out_count_one int64
  8747. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8748. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8749. sum_out_count_one += itemOne.Count
  8750. }
  8751. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8752. fmt.Println("sum_out_count_one", sum_out_count_one)
  8753. fmt.Println("list.FlushCount", list.FlushCount)
  8754. if sum_out_count_one > list.FlushCount {
  8755. c.ServeSuccessJSON(map[string]interface{}{
  8756. "msg": "3",
  8757. "good": good,
  8758. })
  8759. return
  8760. }
  8761. }
  8762. }
  8763. timestamp := time.Now().Unix()
  8764. tempTime := time.Unix(timestamp, 0)
  8765. timeFormat := tempTime.Format("20060102150405")
  8766. chrgBchno := rand.Intn(100000) + 10000
  8767. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8768. strconv.FormatInt(his.PatientId, 10)
  8769. var ids []int64
  8770. for _, item := range prescriptions {
  8771. ids = append(ids, item.ID)
  8772. }
  8773. var total float64
  8774. for _, item := range prescriptions {
  8775. fmt.Println(item)
  8776. if item.Type == 1 { //药品
  8777. for _, subItem := range item.HisDoctorAdviceInfo {
  8778. total = total + (subItem.Price * subItem.PrescribingNumber)
  8779. }
  8780. }
  8781. if item.Type == 2 { //项目
  8782. for _, subItem := range item.HisPrescriptionProject {
  8783. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8784. total = total + (subItem.Price * cnt)
  8785. }
  8786. }
  8787. for _, subItem := range item.HisAdditionalCharge {
  8788. total = total + (subItem.Price * float64(subItem.Count))
  8789. }
  8790. }
  8791. if reg_type == 1111 || reg_type == 1112 {
  8792. reg_type = 11
  8793. }
  8794. tm := time.Unix(time.Now().Unix(), 0)
  8795. allTotal := fmt.Sprintf("%.4f", total)
  8796. totals, _ := strconv.ParseFloat(allTotal, 64)
  8797. order := &models.HisOrder{
  8798. UserOrgId: adminUser.CurrentOrgId,
  8799. HisPatientId: his.ID,
  8800. PatientId: id,
  8801. SettleAccountsDate: recordDateTime,
  8802. Ctime: time.Now().Unix(),
  8803. Mtime: time.Now().Unix(),
  8804. Status: 1,
  8805. OrderStatus: 2,
  8806. MdtrtId: his.Number,
  8807. Number: chrg_bchno,
  8808. MedfeeSumamt: totals,
  8809. PayWay: pay_way,
  8810. PayWays: pay_ways,
  8811. PayPrice: pay_price,
  8812. MedType: strconv.Itoa(int(reg_type)),
  8813. PayCardNo: pay_card_no,
  8814. DiscountPrice: discount_price,
  8815. PreferentialPrice: preferential_price,
  8816. RealityPrice: reality_price,
  8817. FoundPrice: found_price,
  8818. MedicalInsurancePrice: medical_insurance_price,
  8819. PrivatePrice: private_price,
  8820. SettleEndTime: end_time,
  8821. SettleStartTime: start_time,
  8822. PsnPartAmt: totals,
  8823. PsnCashPay: totals,
  8824. SettleType: settle_accounts_type,
  8825. FaPiaoCode: fapiao_code,
  8826. FaPiaoNumber: fapiao_number,
  8827. Diagnosis: diagnosis_id,
  8828. PType: 2,
  8829. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8830. Decimal: decimal,
  8831. OthDesc: oth_desc,
  8832. CashPay: cash_pay,
  8833. WechatPay: wechat_pay,
  8834. AliPay: ali_pay,
  8835. JifenPay: jifen_pay,
  8836. BandCardPay: band_card_pay,
  8837. Creator: adminUser.AdminUser.Id,
  8838. }
  8839. err = service.CreateOrderTX(order, tx)
  8840. if err != nil {
  8841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8842. return
  8843. }
  8844. var customs []*Custom
  8845. for _, item := range prescriptions {
  8846. if item.Type == 1 { //药品a
  8847. for _, subItem := range item.HisDoctorAdviceInfo {
  8848. cus := &Custom{
  8849. AdviceId: subItem.ID,
  8850. ProjectId: 0,
  8851. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8852. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8853. FeedetlSn: subItem.FeedetlSn,
  8854. Price: fmt.Sprintf("%.4f", subItem.Price),
  8855. MedListCodg: subItem.MedListCodg,
  8856. Type: 1,
  8857. CostType: 9,
  8858. }
  8859. customs = append(customs, cus)
  8860. }
  8861. }
  8862. if item.Type == 2 { //项目
  8863. for _, subItem := range item.HisPrescriptionProject {
  8864. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8865. cus := &Custom{
  8866. AdviceId: 0,
  8867. ProjectId: subItem.ID,
  8868. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8869. Cut: fmt.Sprintf("%.4f", cnt),
  8870. FeedetlSn: subItem.FeedetlSn,
  8871. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8872. MedListCodg: subItem.MedListCodg,
  8873. Type: 2,
  8874. CostType: subItem.HisProject.CostClassify,
  8875. }
  8876. customs = append(customs, cus)
  8877. }
  8878. }
  8879. for _, item := range item.HisAdditionalCharge {
  8880. cus := &Custom{
  8881. ItemId: item.ID,
  8882. AdviceId: 0,
  8883. ProjectId: 0,
  8884. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8885. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8886. FeedetlSn: item.FeedetlSn,
  8887. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8888. MedListCodg: item.XtHisAddtionConfig.Code,
  8889. Type: 3,
  8890. CostType: 5,
  8891. }
  8892. customs = append(customs, cus)
  8893. }
  8894. }
  8895. for _, item := range customs {
  8896. var advice_id int64 = 0
  8897. var project_id int64 = 0
  8898. var item_id int64 = 0
  8899. var types int64 = 0
  8900. var med_chrgitm_type string
  8901. if item.Type == 1 {
  8902. advice_id = item.AdviceId
  8903. project_id = 0
  8904. item_id = 0
  8905. med_chrgitm_type = "09"
  8906. } else if item.Type == 2 {
  8907. med_chrgitm_type = "05"
  8908. if item.CostType == 3 {
  8909. med_chrgitm_type = "04"
  8910. }
  8911. if item.CostType == 8 {
  8912. med_chrgitm_type = "03"
  8913. }
  8914. advice_id = 0
  8915. item_id = 0
  8916. project_id = item.ProjectId
  8917. } else if item.Type == 3 {
  8918. advice_id = 0
  8919. item_id = item.ItemId
  8920. project_id = 0
  8921. med_chrgitm_type = "08"
  8922. }
  8923. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8924. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8925. pric, _ := strconv.ParseFloat(item.Price, 32)
  8926. info := &models.HisOrderInfo{
  8927. OrderNumber: order.Number,
  8928. UploadDate: time.Now().Unix(),
  8929. AdviceId: advice_id,
  8930. DetItemFeeSumamt: detItemFeeSumamt,
  8931. MedChrgitmType: med_chrgitm_type,
  8932. Cnt: cut,
  8933. Pric: pric,
  8934. PatientId: id,
  8935. Status: 1,
  8936. Mtime: time.Now().Unix(),
  8937. Ctime: time.Now().Unix(),
  8938. UserOrgId: adminUser.CurrentOrgId,
  8939. HisPatientId: his.ID,
  8940. OrderId: order.ID,
  8941. ProjectId: project_id,
  8942. Type: types,
  8943. ItemId: item_id,
  8944. }
  8945. service.CreateOrderInfoTX(info, tx)
  8946. }
  8947. his.Diagnosis = diagnosis_id
  8948. his.SickType = sick_type
  8949. his.RegisterType = reg_type
  8950. his.MedicalTreatmentType = reg_type
  8951. service.UpdataHisPateintTX(&his, tx)
  8952. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8953. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8954. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8955. //判断是否使用了押金
  8956. if dec_way == "true" {
  8957. tmpstring := strconv.FormatInt(order.ID, 10)
  8958. //扣押金
  8959. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8960. order.Decimal = decimal
  8961. service.UpDateOrderTwo(order, tx)
  8962. if errmsg != nil {
  8963. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8964. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8965. return
  8966. }
  8967. }
  8968. if err == nil {
  8969. for _, info := range prescriptions {
  8970. if info.Type == 1 {
  8971. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8972. }
  8973. if info.Type == 2 {
  8974. for _, sumItem := range info.HisPrescriptionProject {
  8975. if sumItem.Type == 3 {
  8976. var good models.DialysisBeforePrepareGoods
  8977. var newGood models.NewDialysisBeforePrepareGoods
  8978. var oldGood models.OldDialysisBeforePrepareGoods
  8979. good.GoodId = sumItem.GoodInfo.ID
  8980. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8981. count, _ := strconv.Atoi(sumItem.Count)
  8982. good.Count = int64(count)
  8983. good.StorehouseId = houseConfig.StorehouseOutInfo
  8984. good.ProjectId = sumItem.ID
  8985. good.PatientId = sumItem.PatientId
  8986. goods = append(goods, &good)
  8987. newGood.GoodId = sumItem.GoodInfo.ID
  8988. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8989. count2, _ := strconv.Atoi(sumItem.Count)
  8990. newGood.Count = int64(count2)
  8991. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8992. newGood.ProjectId = sumItem.ID
  8993. newGood.PatientId = sumItem.HisPatientId
  8994. newGoods = append(newGoods, &newGood)
  8995. oldGood.GoodId = sumItem.GoodInfo.ID
  8996. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8997. count3, _ := strconv.Atoi(sumItem.Count)
  8998. oldGood.Count = int64(count3)
  8999. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9000. oldGood.ProjectId = sumItem.ID
  9001. oldGood.RecordDate = sumItem.RecordDate
  9002. oldGood.PatientId = sumItem.HisPatientId
  9003. oldGoods = append(oldGoods, &oldGood)
  9004. }
  9005. }
  9006. }
  9007. }
  9008. if settConfig.IsOpen == 1 {
  9009. for _, item := range infoList {
  9010. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9011. if medical.IsUse == 2 {
  9012. //药品出库
  9013. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9014. //查询默认仓库
  9015. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9016. //查询默认仓库剩余多少库存
  9017. var sum_count int64
  9018. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9019. for _, its := range stockInfo {
  9020. if its.MaxUnit == medical.MaxUnit {
  9021. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9022. }
  9023. sum_count += its.StockMaxNumber + its.StockMinNumber
  9024. }
  9025. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9026. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9027. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9028. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9029. }
  9030. }
  9031. orgId := c.GetAdminUserInfo().CurrentOrgId
  9032. if len(oldGoods) > 0 {
  9033. timeStr := time.Now().Format("2006-01-02")
  9034. timeArr := strings.Split(timeStr, "-")
  9035. total, _ := service.FindAllWarehouseOut(orgId)
  9036. total = total + 1
  9037. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9038. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9039. number = number + total
  9040. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9041. operation_time := time.Now().Unix()
  9042. creater := c.GetAdminUserInfo().AdminUser.Id
  9043. //查询默认出库仓库库存
  9044. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9045. recordDateStr := time.Now().Format("2006-01-02")
  9046. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9047. nowtime := recordDate.Unix()
  9048. warehouseOut := models.WarehouseOut{
  9049. WarehouseOutOrderNumber: warehousing_out_order,
  9050. OperationTime: operation_time,
  9051. OrgId: orgId,
  9052. Creater: creater,
  9053. Ctime: time.Now().Unix(),
  9054. Status: 1,
  9055. WarehouseOutTime: nowtime,
  9056. Type: 1,
  9057. StorehouseId: storeConfig.StorehouseOutInfo,
  9058. IsCheck: 1,
  9059. OrderId: order.ID,
  9060. IsSys: 5,
  9061. }
  9062. //查询是否生成出库单
  9063. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9064. if out.ID == 0 {
  9065. service.AddSigleWarehouseOut(&warehouseOut)
  9066. }
  9067. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9068. for _, item := range oldGoods {
  9069. dialyPrepareOne := models.DialysisBeforePrepare{
  9070. GoodTypeId: item.GoodTypeId,
  9071. GoodId: item.GoodId,
  9072. PatientId: his.PatientId,
  9073. RecordDate: item.RecordDate,
  9074. UserOrgId: adminUser.CurrentOrgId,
  9075. Count: item.Count,
  9076. Ctime: time.Now().Unix(),
  9077. Creater: adminUser.AdminUser.Id,
  9078. CommdityCode: item.CommdityCode,
  9079. Status: 1,
  9080. StorehouseId: houseConfig.StorehouseOutInfo,
  9081. }
  9082. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9083. //非零用
  9084. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9085. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9086. //查询剩余库存
  9087. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9088. var sum_count int64
  9089. for _, item := range goodList {
  9090. sum_count += item.StockCount
  9091. }
  9092. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9093. //耗材
  9094. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9095. }
  9096. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9097. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9098. //查询剩余库存
  9099. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9100. var sum_count int64
  9101. for _, item := range goodList {
  9102. sum_count += item.StockCount
  9103. }
  9104. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9105. //耗材
  9106. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9107. }
  9108. }
  9109. }
  9110. }
  9111. c.ServeSuccessJSON(map[string]interface{}{
  9112. "msg": "结算成功",
  9113. })
  9114. }
  9115. }
  9116. }
  9117. // 退款
  9118. func (c *HisApiController) Refund() {
  9119. order_id, _ := c.GetInt64("order_id")
  9120. order, _ := service.GetHisOrderByID(order_id)
  9121. adminUser := c.GetAdminUserInfo()
  9122. orgid := c.GetAdminUserInfo().CurrentOrgId
  9123. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9124. if err != nil {
  9125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9126. return
  9127. }
  9128. tmp := strconv.FormatInt(order.ID, 10)
  9129. //当押金不为零时产生退费记录
  9130. if order.Decimal != 0 {
  9131. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9132. if err != nil {
  9133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9134. return
  9135. }
  9136. }
  9137. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9138. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9139. var goods []*models.DialysisBeforePrepareGoods
  9140. var newGoods []*models.NewDialysisBeforePrepareGoods
  9141. var infos []*models.HisDoctorAdviceInfo
  9142. for _, info := range orders {
  9143. if info.AdviceId > 0 && info.ProjectId == 0 {
  9144. infos = append(infos, &info.HisDoctorAdviceInfo)
  9145. }
  9146. if info.ProjectId > 0 && info.AdviceId == 0 {
  9147. if info.HisPrescriptionProject.Type == 3 {
  9148. var good models.DialysisBeforePrepareGoods
  9149. var newGood models.NewDialysisBeforePrepareGoods
  9150. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9151. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9152. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9153. good.Count = int64(count)
  9154. good.StorehouseId = houseConfig.StorehouseOutInfo
  9155. good.ProjectId = info.HisPrescriptionProject.ID
  9156. good.PatientId = info.PatientId
  9157. good.OrderId = order_id
  9158. goods = append(goods, &good)
  9159. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9160. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9161. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9162. newGood.Count = int64(count2)
  9163. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9164. newGood.ProjectId = info.HisPrescriptionProject.ID
  9165. newGood.RecordDate = order.SettleAccountsDate
  9166. newGood.UserOrgId = order.UserOrgId
  9167. newGood.PatientId = info.PatientId
  9168. newGood.OrderId = order_id
  9169. newGoods = append(newGoods, &newGood)
  9170. }
  9171. }
  9172. }
  9173. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9174. if settConfig.IsOpen == 1 {
  9175. for _, item := range infos {
  9176. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9177. }
  9178. for _, item := range newGoods {
  9179. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9180. }
  9181. }
  9182. c.ServeSuccessJSON(map[string]interface{}{
  9183. "msg": "退费成功",
  9184. })
  9185. }
  9186. func (c *HisApiController) RefundNumber() {
  9187. his_patient_id, _ := c.GetInt64("id")
  9188. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9189. info.Status = 0
  9190. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9191. if count > 0 {
  9192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9193. return
  9194. }
  9195. err := service.SaveHisPatient(info)
  9196. if err == nil {
  9197. c.ServeSuccessJSON(map[string]interface{}{
  9198. "msg": "退号成功",
  9199. })
  9200. } else {
  9201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9202. return
  9203. }
  9204. }
  9205. func (this *HisApiController) AdditionalCharge() {
  9206. dataBody := make(map[string]interface{}, 0)
  9207. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9208. fmt.Println(err)
  9209. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9210. patient_id := int64(dataBody["patient_id"].(float64))
  9211. medicineData, _ := dataBody["medicineData"].([]interface{})
  9212. adminUserInfo := this.GetAdminUserInfo()
  9213. orgId := adminUserInfo.CurrentOrgId
  9214. admin_user_id := adminUserInfo.AdminUser.Id
  9215. timeStr := time.Now().Format("2006-01-02")
  9216. timeLayout := "2006-01-02 15:04:05"
  9217. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9218. timenow := timeStringToTime.Unix()
  9219. var additionalCharges []*models.HisAdditionalCharge
  9220. for _, item := range medicineData {
  9221. var randNum int
  9222. randNum = rand.Intn(10000) + 1000
  9223. timestamp := time.Now().Unix()
  9224. tempTime := time.Unix(timestamp, 0)
  9225. timeFormat := tempTime.Format("20060102150405")
  9226. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9227. items := item.(map[string]interface{})
  9228. money := items["price"].(string)
  9229. item_id_str := items["item_id"].(string)
  9230. name := items["name"].(string)
  9231. id_str := items["id"].(string)
  9232. moneys, _ := strconv.ParseInt(money, 10, 64)
  9233. monStr := strconv.FormatInt(moneys, 10)
  9234. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9235. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9236. id, _ := strconv.ParseInt(id_str, 10, 64)
  9237. additionalCharge := &models.HisAdditionalCharge{
  9238. ID: id,
  9239. HisPatientId: his_patient_id,
  9240. UserOrgId: orgId,
  9241. PatientId: patient_id,
  9242. RecordDate: timenow,
  9243. Price: monneyStr,
  9244. Status: 1,
  9245. ItemName: name,
  9246. ItemId: item_id,
  9247. AdminUserId: admin_user_id,
  9248. CreatedTime: time.Now().Unix(),
  9249. OrderStatus: 0,
  9250. PrescriptionNumber: "",
  9251. BatchNumber: "",
  9252. FeedetlSn: p_number,
  9253. }
  9254. service.CreateAdditionalCharge(additionalCharge)
  9255. additionalCharges = append(additionalCharges, additionalCharge)
  9256. }
  9257. this.ServeSuccessJSON(map[string]interface{}{
  9258. "msg": "添加成功",
  9259. "additional_charges": additionalCharges,
  9260. })
  9261. }
  9262. func (this *HisApiController) DeleteAddition() {
  9263. id, _ := this.GetInt64("id")
  9264. //TODO 需要判断是否已经结算
  9265. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9266. if err == nil {
  9267. this.ServeSuccessJSON(map[string]interface{}{
  9268. "msg": "删除成功",
  9269. })
  9270. return
  9271. } else {
  9272. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9273. return
  9274. }
  9275. }
  9276. func (this *HisApiController) GetAdminUsers() {
  9277. adminUser := this.GetAdminUserInfo()
  9278. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9279. this.ServeSuccessJSON(map[string]interface{}{
  9280. "doctors": doctors,
  9281. })
  9282. }
  9283. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9284. change_type, _ := this.GetInt64("type", 0)
  9285. record_date := this.GetString("record_time")
  9286. patient_id, _ := this.GetInt64("patient_id", 0)
  9287. p_type, _ := this.GetInt64("p_type", 0)
  9288. timeLayout := "2006-01-02"
  9289. loc, _ := time.LoadLocation("Local")
  9290. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9291. record_time := theAdviceRecordTime.Unix()
  9292. adminUserInfo := this.GetAdminUserInfo()
  9293. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9294. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9295. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9296. if config.ID > 0 && config.IsOpen == 1 {
  9297. for _, subitems := range prescriptions {
  9298. for _, item := range subitems.VMHisPrescription {
  9299. for _, subItem := range item.HisDoctorAdviceInfo {
  9300. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9301. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9302. if info.RetailPrice > 0 {
  9303. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9304. subItem.Drug.RetailPrice = drug.RetailPrice
  9305. }
  9306. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9307. subItem.Drug.MinPrice = info.RetailPrice
  9308. subItem.Drug.RetailPrice = info.RetailPrice
  9309. }
  9310. }
  9311. }
  9312. }
  9313. }
  9314. }
  9315. if config.ID > 0 && config.IsOpen == 1 {
  9316. for _, subitems := range prescriptions {
  9317. for _, item := range subitems.VMHisPrescription {
  9318. for _, subItem := range item.HisPrescriptionProject {
  9319. if subItem.Type == 3 {
  9320. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9321. if info.Price > 0 {
  9322. subItem.GoodInfo.PackingPrice = info.Price
  9323. }
  9324. }
  9325. }
  9326. }
  9327. }
  9328. }
  9329. }
  9330. if err == nil {
  9331. if len(prescriptions) == 0 {
  9332. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9333. return
  9334. } else {
  9335. this.ServeSuccessJSON(map[string]interface{}{
  9336. "prescriptions": prescriptions,
  9337. })
  9338. return
  9339. }
  9340. } else {
  9341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9342. return
  9343. }
  9344. }
  9345. func (this *HisApiController) GetCallHisPrescription() {
  9346. patient_id, _ := this.GetInt64("patient_id", 0)
  9347. timeLayout := "2006-01-02"
  9348. loc, _ := time.LoadLocation("Local")
  9349. start_time := this.GetString("start_time")
  9350. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9351. end_time := this.GetString("end_time")
  9352. p_type, _ := this.GetInt64("p_type")
  9353. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9354. adminUserInfo := this.GetAdminUserInfo()
  9355. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9356. //if
  9357. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9358. //
  9359. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9360. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  9361. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9362. if config.ID > 0 && config.IsOpen == 1 {
  9363. for _, subitems := range prescriptions {
  9364. for _, item := range subitems.VMHisPrescription {
  9365. for _, subItem := range item.HisDoctorAdviceInfo {
  9366. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9367. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9368. if info.RetailPrice > 0 {
  9369. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9370. subItem.Drug.RetailPrice = drug.RetailPrice
  9371. }
  9372. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9373. subItem.Drug.MinPrice = info.RetailPrice
  9374. subItem.Drug.RetailPrice = info.RetailPrice
  9375. }
  9376. }
  9377. }
  9378. }
  9379. }
  9380. }
  9381. if config.ID > 0 && config.IsOpen == 1 {
  9382. for _, subitems := range prescriptions {
  9383. for _, item := range subitems.VMHisPrescription {
  9384. for _, subItem := range item.HisPrescriptionProject {
  9385. if subItem.Type == 3 {
  9386. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9387. if info.Price > 0 {
  9388. subItem.GoodInfo.PackingPrice = info.Price
  9389. }
  9390. }
  9391. }
  9392. }
  9393. }
  9394. }
  9395. }
  9396. if err == nil {
  9397. this.ServeSuccessJSON(map[string]interface{}{
  9398. "prescriptions": prescriptions,
  9399. })
  9400. return
  9401. } else {
  9402. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9403. return
  9404. }
  9405. }
  9406. func (this *HisApiController) GetHisDayPrescription() {
  9407. timeLayout := "2006-01-02"
  9408. loc, _ := time.LoadLocation("Local")
  9409. start_time := this.GetString("start_time")
  9410. patient_id, _ := this.GetInt64("patient_id", 0)
  9411. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9412. end_time := this.GetString("end_time")
  9413. p_type, _ := this.GetInt64("p_type")
  9414. order_status, _ := this.GetInt64("type")
  9415. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9416. adminUserInfo := this.GetAdminUserInfo()
  9417. var dayHisPrescription []*models.HisPrescription
  9418. var err error
  9419. if order_status == 1 || order_status == 0 {
  9420. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9421. } else if order_status == 2 {
  9422. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9423. }
  9424. var settle_total float64
  9425. for _, item := range dayHisPrescription {
  9426. if len(item.HisPrescriptionProject) > 0 {
  9427. for _, subItem := range item.HisPrescriptionProject {
  9428. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9429. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9430. settle_total = settle_total + total
  9431. }
  9432. }
  9433. if len(item.HisDoctorAdviceInfo) > 0 {
  9434. for _, subItem := range item.HisDoctorAdviceInfo {
  9435. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9436. settle_total = settle_total + total
  9437. }
  9438. }
  9439. }
  9440. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9441. if err == nil {
  9442. this.ServeSuccessJSON(map[string]interface{}{
  9443. "day_prescription": dayHisPrescription,
  9444. "settle_total": settle_total,
  9445. })
  9446. return
  9447. } else {
  9448. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9449. return
  9450. }
  9451. }
  9452. func (c *HisApiController) GetHisChargePatientList() {
  9453. record_date := c.GetString("record_date")
  9454. order_status, _ := c.GetInt64("type")
  9455. sch_type, _ := c.GetInt64("sch_type")
  9456. timeLayout := "2006-01-02"
  9457. loc, _ := time.LoadLocation("Local")
  9458. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9459. if err != nil {
  9460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9461. return
  9462. }
  9463. recordDateTime := theTime.Unix()
  9464. adminInfo := c.GetAdminUserInfo()
  9465. var tempPatients []*service.NewTempPatients
  9466. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9467. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9468. if order_status != 2 {
  9469. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9470. } else {
  9471. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9472. }
  9473. } else {
  9474. if order_status != 2 {
  9475. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9476. } else {
  9477. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9478. }
  9479. }
  9480. var patients []*service.NewTempPatients
  9481. var patients_two []*service.NewTempPatients
  9482. for _, item := range tempPatients {
  9483. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9484. //过滤掉没挂号的和没开处方的
  9485. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9486. patients = append(patients, item)
  9487. }
  9488. //过滤掉没挂号的
  9489. if len(item.HisPatient) > 0 {
  9490. patients_two = append(patients_two, item)
  9491. }
  9492. } else {
  9493. if len(item.HisPrescription) > 0 {
  9494. patients = append(patients, item)
  9495. }
  9496. }
  9497. }
  9498. c.ServeSuccessJSON(map[string]interface{}{
  9499. "list": patients,
  9500. "list_two": patients_two,
  9501. })
  9502. }
  9503. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9504. record_date := c.GetString("record_date")
  9505. timeLayout := "2006-01-02"
  9506. loc, _ := time.LoadLocation("Local")
  9507. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9508. if err != nil {
  9509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9510. return
  9511. }
  9512. recordDateTime := theTime.Unix()
  9513. adminUser := c.GetAdminUserInfo()
  9514. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9515. var patients []*service.Patients
  9516. for _, item := range tempPatients {
  9517. if item.HisPatient.ID == 0 {
  9518. patients = append(patients, item)
  9519. }
  9520. }
  9521. c.ServeSuccessJSON(map[string]interface{}{
  9522. "list": patients,
  9523. //"list_two": patients_two,
  9524. })
  9525. }
  9526. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9527. newArr = make([]*service.Patients, 0)
  9528. for i := 0; i < len(patient); i++ {
  9529. repeat := false
  9530. for j := i + 1; j < len(patient); j++ {
  9531. if patient[i].ID == patient[j].ID {
  9532. repeat = true
  9533. break
  9534. }
  9535. }
  9536. if !repeat {
  9537. newArr = append(newArr, patient[i])
  9538. }
  9539. }
  9540. return
  9541. }
  9542. func (c *HisApiController) GetHisChargePatientInfo() {
  9543. patient_id, _ := c.GetInt64("patient_id")
  9544. his_patient_id, _ := c.GetInt64("his_patient_id")
  9545. record_date := c.GetString("record_date")
  9546. //start_time := c.GetString("start_time")
  9547. //end_time := c.GetString("end_time")
  9548. order_status, _ := c.GetInt64("type", 0)
  9549. p_type, _ := c.GetInt64("p_type", 0)
  9550. order_id, _ := c.GetInt64("order_id", 0)
  9551. timeLayout := "2006-01-02"
  9552. loc, _ := time.LoadLocation("Local")
  9553. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9554. if err != nil {
  9555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9556. return
  9557. }
  9558. recordDateTime := theTime.Unix()
  9559. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9560. //if err != nil {
  9561. //
  9562. //}
  9563. //startRecordDateTime := startTime.Unix()
  9564. //
  9565. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9566. //if err != nil {
  9567. //
  9568. //}
  9569. //endRecordDateTime := endTime.Unix()
  9570. admin := c.GetAdminUserInfo()
  9571. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9572. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9573. var prescriptions []*models.HisPrescription
  9574. //var unChargeMonthPrescriptions []*models.HisPrescription
  9575. order, _ := service.GetHisOrderByID(order_id)
  9576. if order_status == 1 || order_status == 0 {
  9577. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9578. } else if order_status == 2 {
  9579. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9580. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9581. }
  9582. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9583. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9584. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9585. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9586. //获取所有科室信息
  9587. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9588. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9589. c.ServeSuccessJSON(map[string]interface{}{
  9590. "his_info": his_patient_info,
  9591. "xt_info": xt_patient_info,
  9592. "prescription": prescriptions,
  9593. "case_history": case_history,
  9594. "info": patientPrescriptionInfo,
  9595. "last_info": lastPatientPrescriptionInfo,
  9596. "order": order,
  9597. "doctors": doctors,
  9598. "department": department,
  9599. "sch": sch,
  9600. })
  9601. return
  9602. }
  9603. func (c *HisApiController) GetAllOrderDetail() {
  9604. order_id, _ := c.GetInt64("id", 0)
  9605. order, _ := service.GetHisOrderByID(order_id)
  9606. if order.ID == 0 {
  9607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9608. return
  9609. }
  9610. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9611. org_id := c.GetAdminUserInfo().CurrentOrgId
  9612. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9613. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9614. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9615. c.ServeSuccessJSON(map[string]interface{}{
  9616. "order": order,
  9617. "order_info": order_info,
  9618. "patient": patient,
  9619. "admin_info": adminInfo,
  9620. "hospital_record": record,
  9621. })
  9622. return
  9623. }
  9624. func (c *HisApiController) GetAllOrderDetailCollect() {
  9625. order_id, _ := c.GetInt64("id", 0)
  9626. order, _ := service.GetHisOrderByID(order_id)
  9627. if order.ID == 0 {
  9628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9629. return
  9630. }
  9631. org_id := c.GetAdminUserInfo().CurrentOrgId
  9632. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9633. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9634. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9635. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9636. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9637. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9638. var bedCostTotal float64 = 0 //床位总费
  9639. //var bedCostSelfTotal float64 = 0 //床位自费
  9640. var operationCostTotal float64 = 0 //手术费
  9641. //var operationCostSelfTotal float64 = 0 //手术费
  9642. var otherCostTotal float64 = 0 //其他费用
  9643. //var otherCostSelfTotal float64 = 0 //其他费用
  9644. var materialCostTotal float64 = 0 //材料费
  9645. //var materialCostSelfTotal float64 = 0 //材料费
  9646. var westernMedicineCostTotal float64 = 0 //西药费
  9647. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9648. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9649. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9650. var checkCostTotal float64 = 0 //检查费
  9651. //var checkCostSelfTotal float64 = 0 //检查费
  9652. var laboratoryCostTotal float64 = 0 //化验费
  9653. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9654. var treatCostTotal float64 = 0 //治疗费用
  9655. //var treatCostSelfTotal float64 = 0 //治疗费用
  9656. var zhenChaCostTotal float64 = 0 //其他费用
  9657. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9658. decimal.DivisionPrecision = 2
  9659. var BalanceAccountsType int64
  9660. if his.ID > 0 {
  9661. BalanceAccountsType = his.BalanceAccountsType
  9662. } else {
  9663. BalanceAccountsType = record.BalanceAccountsType
  9664. }
  9665. if BalanceAccountsType != 2 {
  9666. for _, item := range order_info {
  9667. if org_id == 10215 {
  9668. if item.MedChrgitmType == "01" { //床位费
  9669. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9670. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9671. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9672. }
  9673. if item.MedChrgitmType == "02" { //诊察费
  9674. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9675. //zhenChaCostSelfTotal = zhenChaCostTotal
  9676. }
  9677. if item.MedChrgitmType == "03" { //检查费
  9678. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9679. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9680. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9681. }
  9682. //if item.MedChrgitmType == "02" { //检查费
  9683. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9684. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9685. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9686. //}
  9687. if item.MedChrgitmType == "04" { //化验费
  9688. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9689. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9690. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9691. }
  9692. if item.MedChrgitmType == "05" { //治疗费
  9693. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9694. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9695. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9696. }
  9697. if item.MedChrgitmType == "06" { //手术费
  9698. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9699. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9700. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9701. }
  9702. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9703. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9704. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9705. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9706. }
  9707. if item.MedChrgitmType == "09" { //西药费
  9708. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9709. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9710. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9711. }
  9712. if item.MedChrgitmType == "11" { //中成费
  9713. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9714. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9715. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9716. }
  9717. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9718. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9719. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9720. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9721. }
  9722. } else if org_id == 10188 || org_id == 10217 {
  9723. if item.MedChrgitmType == "01" { //床位费
  9724. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9725. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9726. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9727. }
  9728. if item.MedChrgitmType == "02" { //诊察费
  9729. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9730. //zhenChaCostSelfTotal = zhenChaCostTotal
  9731. }
  9732. if item.MedChrgitmType == "03" { //检查费
  9733. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9734. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9735. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9736. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9737. }
  9738. //if item.MedChrgitmType == "02" { //检查费
  9739. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9740. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9741. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9742. //}
  9743. if item.MedChrgitmType == "04" { //化验费
  9744. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9745. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9746. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9747. }
  9748. if item.MedChrgitmType == "05" { //治疗费
  9749. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9750. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9751. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9752. }
  9753. if item.MedChrgitmType == "06" { //手术费
  9754. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9755. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9756. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9757. }
  9758. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9759. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9760. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9761. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9762. }
  9763. if item.MedChrgitmType == "09" { //西药费
  9764. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9765. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9766. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9767. }
  9768. if item.MedChrgitmType == "11" { //中成费
  9769. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9770. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9771. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9772. }
  9773. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9774. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9775. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9776. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9777. }
  9778. } else {
  9779. if item.MedChrgitmType == "01" { //床位费
  9780. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9781. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9782. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9783. }
  9784. //if item.MedChrgitmType == "02" { //诊察费
  9785. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9786. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9787. //}
  9788. if item.MedChrgitmType == "03" { //检查费
  9789. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9790. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9791. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9792. }
  9793. //if item.MedChrgitmType == "02" { //检查费
  9794. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9795. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9796. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9797. //}
  9798. if item.MedChrgitmType == "04" { //化验费
  9799. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9800. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9801. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9802. }
  9803. if item.MedChrgitmType == "05" { //治疗费
  9804. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9805. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9806. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9807. }
  9808. if item.MedChrgitmType == "06" { //手术费
  9809. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9810. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9811. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9812. }
  9813. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9814. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9815. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9816. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9817. }
  9818. if item.MedChrgitmType == "09" { //西药费
  9819. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9820. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9821. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9822. }
  9823. if item.MedChrgitmType == "11" { //中成费
  9824. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9825. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9826. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9827. }
  9828. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9829. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9830. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9831. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9832. }
  9833. }
  9834. }
  9835. c.ServeSuccessJSON(map[string]interface{}{
  9836. "order": order,
  9837. "order_info": order_info,
  9838. "patient": patient,
  9839. "admin_info": adminInfo,
  9840. "his_hospital": record,
  9841. "bedCostTotal": bedCostTotal,
  9842. "operationCostTotal": operationCostTotal,
  9843. "otherCostTotal": otherCostTotal,
  9844. "materialCostTotal": materialCostTotal,
  9845. "westernMedicineCostTotal": westernMedicineCostTotal,
  9846. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9847. "checkCostTotal": checkCostTotal,
  9848. "zhenChaCostTotal": zhenChaCostTotal,
  9849. "laboratoryCostTotal": laboratoryCostTotal,
  9850. "treatCostTotal": treatCostTotal,
  9851. })
  9852. } else {
  9853. for _, item := range order_info {
  9854. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9855. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9856. item.MedChrgitmType = "09"
  9857. }
  9858. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9859. if item.HisPrescriptionProject.Type == 2 {
  9860. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9861. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9862. case 0:
  9863. item.MedChrgitmType = "0"
  9864. break
  9865. case 1:
  9866. item.MedChrgitmType = "14"
  9867. break
  9868. case 2:
  9869. item.MedChrgitmType = "05"
  9870. break
  9871. case 3:
  9872. item.MedChrgitmType = "03"
  9873. break
  9874. case 4:
  9875. item.MedChrgitmType = "03"
  9876. break
  9877. case 5:
  9878. item.MedChrgitmType = "08"
  9879. break
  9880. case 6:
  9881. item.MedChrgitmType = "14"
  9882. break
  9883. case 7:
  9884. item.MedChrgitmType = "14"
  9885. break
  9886. case 8:
  9887. item.MedChrgitmType = "03"
  9888. break
  9889. case 9:
  9890. item.MedChrgitmType = "14"
  9891. break
  9892. case 10:
  9893. item.MedChrgitmType = "14"
  9894. break
  9895. case 11:
  9896. item.MedChrgitmType = "06"
  9897. break
  9898. case 12:
  9899. item.MedChrgitmType = "12"
  9900. break
  9901. case 13:
  9902. item.MedChrgitmType = "01"
  9903. break
  9904. case 14:
  9905. item.MedChrgitmType = "04"
  9906. break
  9907. case 15:
  9908. item.MedChrgitmType = "14"
  9909. break
  9910. }
  9911. } else {
  9912. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9913. case 1:
  9914. item.MedChrgitmType = "14"
  9915. break
  9916. case 2:
  9917. item.MedChrgitmType = "05"
  9918. break
  9919. case 3:
  9920. item.MedChrgitmType = "04"
  9921. break
  9922. case 4:
  9923. item.MedChrgitmType = "14"
  9924. break
  9925. case 5:
  9926. item.MedChrgitmType = "08"
  9927. break
  9928. case 6:
  9929. item.MedChrgitmType = "14"
  9930. break
  9931. case 7:
  9932. item.MedChrgitmType = "14"
  9933. break
  9934. case 8:
  9935. item.MedChrgitmType = "03"
  9936. break
  9937. case 9:
  9938. item.MedChrgitmType = "14"
  9939. break
  9940. }
  9941. }
  9942. } else if item.HisPrescriptionProject.Type == 3 {
  9943. item.MedChrgitmType = "08"
  9944. }
  9945. }
  9946. }
  9947. for _, item := range order_info {
  9948. if org_id == 10215 {
  9949. if item.MedChrgitmType == "01" { //床位费
  9950. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9951. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9952. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9953. }
  9954. if item.MedChrgitmType == "02" { //诊察费
  9955. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9956. //zhenChaCostSelfTotal = zhenChaCostTotal
  9957. }
  9958. if item.MedChrgitmType == "03" { //检查费
  9959. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9960. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9961. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9962. }
  9963. //if item.MedChrgitmType == "02" { //检查费
  9964. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9965. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9966. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9967. //}
  9968. if item.MedChrgitmType == "04" { //化验费
  9969. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9970. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9971. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9972. }
  9973. if item.MedChrgitmType == "05" { //治疗费
  9974. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9975. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9976. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9977. }
  9978. if item.MedChrgitmType == "06" { //手术费
  9979. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9980. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9981. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9982. }
  9983. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9984. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9985. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9986. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9987. }
  9988. if item.MedChrgitmType == "09" { //西药费
  9989. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9990. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9991. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9992. }
  9993. if item.MedChrgitmType == "11" { //中成费
  9994. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9995. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9996. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9997. }
  9998. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9999. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10000. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10001. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10002. }
  10003. } else {
  10004. if item.MedChrgitmType == "01" { //床位费
  10005. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10006. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10007. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10008. }
  10009. //if item.MedChrgitmType == "02" { //诊察费
  10010. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10011. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10012. //}
  10013. if item.MedChrgitmType == "03" { //检查费
  10014. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10015. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10016. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10017. }
  10018. //if item.MedChrgitmType == "02" { //检查费
  10019. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10020. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10021. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10022. //}
  10023. if item.MedChrgitmType == "04" { //化验费
  10024. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10025. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10026. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10027. }
  10028. if item.MedChrgitmType == "05" { //治疗费
  10029. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10030. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10031. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10032. }
  10033. if item.MedChrgitmType == "06" { //手术费
  10034. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10035. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10036. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10037. }
  10038. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10039. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10040. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10041. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10042. }
  10043. if item.MedChrgitmType == "09" { //西药费
  10044. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10045. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10046. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10047. }
  10048. if item.MedChrgitmType == "11" { //中成费
  10049. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10050. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10051. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10052. }
  10053. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10054. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10055. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10056. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10057. }
  10058. }
  10059. }
  10060. c.ServeSuccessJSON(map[string]interface{}{
  10061. "order": order,
  10062. "order_info": order_info,
  10063. "patient": patient,
  10064. "admin_info": adminInfo,
  10065. "his_hospital": record,
  10066. "bedCostTotal": bedCostTotal,
  10067. "operationCostTotal": operationCostTotal,
  10068. "otherCostTotal": otherCostTotal,
  10069. "materialCostTotal": materialCostTotal,
  10070. "westernMedicineCostTotal": westernMedicineCostTotal,
  10071. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10072. "checkCostTotal": checkCostTotal,
  10073. "zhenChaCostTotal": zhenChaCostTotal,
  10074. "laboratoryCostTotal": laboratoryCostTotal,
  10075. "treatCostTotal": treatCostTotal,
  10076. })
  10077. }
  10078. }
  10079. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10080. page, _ := c.GetInt64("page")
  10081. limit, _ := c.GetInt64("limit")
  10082. keywords := c.GetString("keywords")
  10083. start_time := c.GetString("start_time")
  10084. end_time := c.GetString("end_time")
  10085. //clr_type := c.GetString("clr_type")
  10086. insutype := c.GetString("insutype")
  10087. timeLayout := "2006-01-02"
  10088. loc, _ := time.LoadLocation("Local")
  10089. var theStartTIme int64
  10090. if len(start_time) > 0 {
  10091. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10092. theStartTIme = theTime.Unix()
  10093. }
  10094. var theEndtTIme int64
  10095. if len(end_time) > 0 {
  10096. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10097. theEndtTIme = theTime.Unix()
  10098. }
  10099. if page <= 0 {
  10100. page = 1
  10101. }
  10102. if limit <= 0 {
  10103. limit = 10
  10104. }
  10105. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10106. c.ServeSuccessJSON(map[string]interface{}{
  10107. "total": total,
  10108. "list": list,
  10109. })
  10110. return
  10111. }
  10112. func (c *HisApiController) GetPutOnRecordList() {
  10113. page, _ := c.GetInt64("page")
  10114. limit, _ := c.GetInt64("limit")
  10115. keywords := c.GetString("keywords")
  10116. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10117. if page <= 0 {
  10118. page = 1
  10119. }
  10120. if limit <= 0 {
  10121. limit = 10
  10122. }
  10123. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10124. c.ServeSuccessJSON(map[string]interface{}{
  10125. "total": total,
  10126. "list": list,
  10127. })
  10128. return
  10129. }
  10130. func (c *HisApiController) GetCompareData() {
  10131. start_time := c.GetString("start_time")
  10132. end_time := c.GetString("end_time")
  10133. insutype := c.GetString("insutype")
  10134. clr_type := c.GetString("clr_type")
  10135. timeLayout := "2006-01-02"
  10136. loc, _ := time.LoadLocation("Local")
  10137. var theStartTIme int64
  10138. if len(start_time) > 0 {
  10139. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10140. if err != nil {
  10141. theStartTIme = 0
  10142. }
  10143. theStartTIme = theTime.Unix()
  10144. }
  10145. var theEndtTIme int64
  10146. if len(end_time) > 0 {
  10147. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10148. if err != nil {
  10149. theEndtTIme = 0
  10150. }
  10151. theEndtTIme = theTime.Unix()
  10152. }
  10153. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10154. fmt.Println(err)
  10155. if err == nil {
  10156. c.ServeSuccessJSON(map[string]interface{}{
  10157. "list": formData,
  10158. })
  10159. } else {
  10160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10161. return
  10162. }
  10163. }
  10164. func (c *HisApiController) GetFaPiaoData() {
  10165. order_id, _ := c.GetInt64("order_id")
  10166. patient_id, _ := c.GetInt64("patient_id")
  10167. //number := c.GetString("number")
  10168. adminUser := c.GetAdminUserInfo()
  10169. order, _ := service.GetHisOrderByID(order_id)
  10170. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10171. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10172. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10173. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10174. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10175. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10176. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10177. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10178. var bedCostTotal float64 = 0 //床位总费
  10179. var bedCostSelfTotal float64 = 0 //床位自费
  10180. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10181. var operationCostTotal float64 = 0 //手术费
  10182. var operationCostSelfTotal float64 = 0 //手术费
  10183. var operationCostPartSelfTotal float64 = 0 //手术费
  10184. var otherCostTotal float64 = 0 //其他费用
  10185. var otherCostSelfTotal float64 = 0 //其他费用
  10186. var otherCostPartSelfTotal float64 = 0 //其他费用
  10187. var materialCostTotal float64 = 0 //材料费
  10188. var materialCostSelfTotal float64 = 0 //材料费
  10189. var materialCostPartSelfTotal float64 = 0 //材料费
  10190. var westernMedicineCostTotal float64 = 0 //西药费
  10191. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10192. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10193. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10194. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10195. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10196. var checkCostTotal float64 = 0 //检查费
  10197. var checkCostSelfTotal float64 = 0 //检查费
  10198. var checkCostPartSelfTotal float64 = 0 //检查费
  10199. var hiliCostTotal float64 = 0 //护理费
  10200. var hiliCostSelfTotal float64 = 0 //护理费
  10201. var hiliCostPartSelfTotal float64 = 0 //护理费
  10202. var laboratoryCostTotal float64 = 0 //化验费
  10203. var laboratoryCostSelfTotal float64 = 0 //化验费
  10204. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10205. var treatCostTotal float64 = 0 //治疗费用
  10206. var treatCostSelfTotal float64 = 0 //治疗费用
  10207. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10208. var zhenChaCostTotal float64 = 0 //其他费用
  10209. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10210. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10211. decimal.DivisionPrecision = 2
  10212. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10213. var balanceAccountsType int64
  10214. if his.ID > 0 {
  10215. balanceAccountsType = his.BalanceAccountsType
  10216. } else {
  10217. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10218. }
  10219. if balanceAccountsType == 2 {
  10220. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10221. for _, item := range orderInfos_two {
  10222. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10223. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10224. item.MedChrgitmType = "09"
  10225. }
  10226. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10227. if item.HisPrescriptionProject.Type == 2 {
  10228. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10229. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10230. case 0:
  10231. item.MedChrgitmType = "0"
  10232. break
  10233. case 1:
  10234. item.MedChrgitmType = "14"
  10235. break
  10236. case 2:
  10237. item.MedChrgitmType = "05"
  10238. break
  10239. case 3:
  10240. item.MedChrgitmType = "03"
  10241. break
  10242. case 4:
  10243. item.MedChrgitmType = "03"
  10244. break
  10245. case 5:
  10246. item.MedChrgitmType = "08"
  10247. break
  10248. case 6:
  10249. item.MedChrgitmType = "14"
  10250. break
  10251. case 7:
  10252. item.MedChrgitmType = "14"
  10253. break
  10254. case 8:
  10255. item.MedChrgitmType = "03"
  10256. break
  10257. case 9:
  10258. item.MedChrgitmType = "14"
  10259. break
  10260. case 10:
  10261. item.MedChrgitmType = "14"
  10262. break
  10263. case 11:
  10264. item.MedChrgitmType = "06"
  10265. break
  10266. case 12:
  10267. item.MedChrgitmType = "12"
  10268. break
  10269. case 13:
  10270. item.MedChrgitmType = "01"
  10271. break
  10272. case 14:
  10273. item.MedChrgitmType = "04"
  10274. break
  10275. case 15:
  10276. item.MedChrgitmType = "02"
  10277. break
  10278. }
  10279. } else {
  10280. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10281. case 1:
  10282. item.MedChrgitmType = "14"
  10283. break
  10284. case 2:
  10285. item.MedChrgitmType = "05"
  10286. break
  10287. case 3:
  10288. item.MedChrgitmType = "04"
  10289. break
  10290. case 4:
  10291. item.MedChrgitmType = "03"
  10292. break
  10293. case 5:
  10294. item.MedChrgitmType = "08"
  10295. break
  10296. case 6:
  10297. item.MedChrgitmType = "14"
  10298. break
  10299. case 7:
  10300. item.MedChrgitmType = "14"
  10301. break
  10302. case 8:
  10303. item.MedChrgitmType = "03"
  10304. break
  10305. case 9:
  10306. item.MedChrgitmType = "14"
  10307. break
  10308. }
  10309. }
  10310. } else if item.HisPrescriptionProject.Type == 3 {
  10311. item.MedChrgitmType = "08"
  10312. }
  10313. }
  10314. }
  10315. for _, item := range orderInfos_two {
  10316. fmt.Println(item.MedChrgitmType)
  10317. if item.MedChrgitmType == "07" { //床位费
  10318. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10319. hiliCostSelfTotal = hiliCostTotal
  10320. }
  10321. if item.MedChrgitmType == "01" { //床位费
  10322. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10323. bedCostSelfTotal = bedCostTotal
  10324. }
  10325. if item.MedChrgitmType == "02" { //诊察费
  10326. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10327. zhenChaCostSelfTotal = zhenChaCostTotal
  10328. }
  10329. if item.MedChrgitmType == "03" { //检查费
  10330. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10331. checkCostSelfTotal = checkCostTotal
  10332. }
  10333. if item.MedChrgitmType == "04" { //化验费
  10334. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10335. laboratoryCostSelfTotal = laboratoryCostTotal
  10336. }
  10337. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10338. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10339. treatCostSelfTotal = treatCostTotal
  10340. }
  10341. if item.MedChrgitmType == "06" { //手术费
  10342. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10343. operationCostSelfTotal = treatCostTotal
  10344. }
  10345. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10346. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10347. materialCostSelfTotal = materialCostTotal
  10348. }
  10349. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10350. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10351. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10352. }
  10353. if item.MedChrgitmType == "11" { //中成费
  10354. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10355. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10356. }
  10357. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10358. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10359. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10360. otherCostSelfTotal = otherCostTotal
  10361. }
  10362. } else {
  10363. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10364. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10365. otherCostSelfTotal = otherCostTotal
  10366. }
  10367. }
  10368. }
  10369. } else {
  10370. for _, item := range orderInfos {
  10371. if item.MedChrgitmType == "01" { //床位费
  10372. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10373. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10374. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10375. }
  10376. if item.MedChrgitmType == "02" { //诊察费
  10377. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10378. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10379. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10380. }
  10381. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10382. if item.MedChrgitmType == "03" { //检查费
  10383. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10384. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10385. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10386. }
  10387. } else {
  10388. if item.MedChrgitmType == "03" { //检查费
  10389. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10390. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10391. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10392. }
  10393. }
  10394. if item.MedChrgitmType == "04" { //化验费
  10395. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10396. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10397. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10398. }
  10399. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10400. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10401. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10402. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10403. }
  10404. if item.MedChrgitmType == "06" { //手术费
  10405. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10406. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10407. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10408. }
  10409. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10410. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10411. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10412. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10413. }
  10414. if item.MedChrgitmType == "07" { //护理
  10415. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10416. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10417. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10418. }
  10419. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10420. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10421. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10422. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10423. }
  10424. if item.MedChrgitmType == "11" { //中成费
  10425. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10426. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10427. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10428. }
  10429. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10430. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10431. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10432. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10433. }
  10434. }
  10435. }
  10436. timeLayout := "2006-01-02"
  10437. loc, _ := time.LoadLocation("Local")
  10438. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10439. if err != nil {
  10440. }
  10441. startRecordDateTime := startTime.Unix()
  10442. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10443. if err != nil {
  10444. }
  10445. endRecordDateTime := endTime.Unix()
  10446. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10447. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10448. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10449. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10450. c.ServeSuccessJSON(map[string]interface{}{
  10451. "charge_admin_name": charge_admin.UserName,
  10452. "order_number": order.Number, //业务流水号
  10453. "id_card_no": his.IdCardNo, //社会保障号
  10454. "patient": patient,
  10455. "department_name": department.Name, //科室
  10456. "number": his.Number, //门诊号
  10457. "date": order.SettleAccountsDate, //结算日期
  10458. "name": order.PsnName, //姓名
  10459. "gender": patient.Gender, //性别
  10460. "psn_cash_money": order.PsnCashPay, //个人支付
  10461. "pay_way": "门诊", //结算方式
  10462. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10463. "admin_user_name": admin.UserName, //收款员
  10464. "order": order,
  10465. "order_info": orderInfos_two,
  10466. "his": his,
  10467. "bedCostTotal": bedCostTotal,
  10468. "bedCostSelfTotal": bedCostSelfTotal,
  10469. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10470. "operationCostTotal": operationCostTotal,
  10471. "operationCostSelfTotal": operationCostSelfTotal,
  10472. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10473. "otherCostTotal": otherCostTotal,
  10474. "otherCostSelfTotal": otherCostSelfTotal,
  10475. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10476. "materialCostTotal": materialCostTotal,
  10477. "materialCostSelfTotal": materialCostSelfTotal,
  10478. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10479. "westernMedicineCostTotal": westernMedicineCostTotal,
  10480. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10481. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10482. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10483. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10484. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10485. "checkCostTotal": checkCostTotal,
  10486. "checkCostSelfTotal": checkCostSelfTotal,
  10487. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10488. "laboratoryCostTotal": laboratoryCostTotal,
  10489. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10490. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10491. "treatCostTotal": treatCostTotal,
  10492. "treatCostSelfTotal": treatCostSelfTotal,
  10493. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10494. "zhenChaCostTotal": zhenChaCostTotal,
  10495. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10496. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10497. "his_hospital_record": his_hospital_record,
  10498. "pre_pay_money": pre_pay_money,
  10499. "refund_sum": sum,
  10500. "doctor_info": doctor_info,
  10501. "hiliCostTotal": hiliCostTotal,
  10502. "hiliCostSelfTotal": hiliCostSelfTotal,
  10503. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10504. })
  10505. }
  10506. //func (c *HisApiController) GetFaPiaoDatas() {
  10507. // order_ids := c.GetString("order_ids")
  10508. // patient_id, _ := c.GetInt64("patient_id")
  10509. // adminUser := c.GetAdminUserInfo()
  10510. //
  10511. // orders := strings.Split(order_ids, ",")
  10512. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10513. //
  10514. // for _, item := range orders {
  10515. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10516. // order, _ := service.GetHisOrderByID(order_id)
  10517. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10518. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10519. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10520. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10521. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10522. //
  10523. // }
  10524. //
  10525. // var bedCostTotal float64 = 0 //床位总费
  10526. // var bedCostSelfTotal float64 = 0 //床位自费
  10527. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10528. //
  10529. // var operationCostTotal float64 = 0 //手术费
  10530. // var operationCostSelfTotal float64 = 0 //手术费
  10531. // var operationCostPartSelfTotal float64 = 0 //手术费
  10532. //
  10533. // var otherCostTotal float64 = 0 //其他费用
  10534. // var otherCostSelfTotal float64 = 0 //其他费用
  10535. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10536. //
  10537. // var materialCostTotal float64 = 0 //材料费
  10538. // var materialCostSelfTotal float64 = 0 //材料费
  10539. // var materialCostPartSelfTotal float64 = 0 //材料费
  10540. //
  10541. // var westernMedicineCostTotal float64 = 0 //西药费
  10542. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10543. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10544. //
  10545. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10546. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10547. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10548. //
  10549. // var checkCostTotal float64 = 0 //检查费
  10550. // var checkCostSelfTotal float64 = 0 //检查费
  10551. // var checkCostPartSelfTotal float64 = 0 //检查费
  10552. //
  10553. // var laboratoryCostTotal float64 = 0 //化验费
  10554. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10555. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10556. //
  10557. // var treatCostTotal float64 = 0 //治疗费用
  10558. // var treatCostSelfTotal float64 = 0 //治疗费用
  10559. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10560. //
  10561. // var zhenChaCostTotal float64 = 0 //其他费用
  10562. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10563. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10564. //
  10565. // decimal.DivisionPrecision = 2
  10566. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10567. //
  10568. // var balanceAccountsType int64
  10569. // if his.ID > 0 {
  10570. // balanceAccountsType = his.BalanceAccountsType
  10571. // } else {
  10572. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10573. // }
  10574. // if balanceAccountsType == 2 {
  10575. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10576. // for _, item := range orderInfos_two {
  10577. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10578. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10579. // item.MedChrgitmType = "09"
  10580. // }
  10581. //
  10582. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10583. // if item.HisPrescriptionProject.Type == 2 {
  10584. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10585. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10586. // case 0:
  10587. // item.MedChrgitmType = "0"
  10588. // break
  10589. // case 1:
  10590. // item.MedChrgitmType = "14"
  10591. // break
  10592. // case 2:
  10593. // item.MedChrgitmType = "05"
  10594. //
  10595. // break
  10596. // case 3:
  10597. // item.MedChrgitmType = "03"
  10598. //
  10599. // break
  10600. // case 4:
  10601. // item.MedChrgitmType = "03"
  10602. //
  10603. // break
  10604. // case 5:
  10605. // item.MedChrgitmType = "08"
  10606. //
  10607. // break
  10608. // case 6:
  10609. // item.MedChrgitmType = "14"
  10610. //
  10611. // break
  10612. // case 7:
  10613. // item.MedChrgitmType = "14"
  10614. //
  10615. // break
  10616. // case 8:
  10617. // item.MedChrgitmType = "03"
  10618. // break
  10619. // case 9:
  10620. // item.MedChrgitmType = "14"
  10621. // break
  10622. // case 10:
  10623. // item.MedChrgitmType = "14"
  10624. // break
  10625. // case 11:
  10626. // item.MedChrgitmType = "06"
  10627. // break
  10628. // case 12:
  10629. // item.MedChrgitmType = "12"
  10630. // break
  10631. // case 13:
  10632. // item.MedChrgitmType = "01"
  10633. // break
  10634. // case 14:
  10635. // item.MedChrgitmType = "04"
  10636. // break
  10637. // case 15:
  10638. // item.MedChrgitmType = "02"
  10639. // break
  10640. //
  10641. // }
  10642. //
  10643. // } else {
  10644. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10645. //
  10646. // case 1:
  10647. // item.MedChrgitmType = "14"
  10648. // break
  10649. // case 2:
  10650. // item.MedChrgitmType = "05"
  10651. //
  10652. // break
  10653. // case 3:
  10654. // item.MedChrgitmType = "03"
  10655. //
  10656. // break
  10657. // case 4:
  10658. // item.MedChrgitmType = "03"
  10659. //
  10660. // break
  10661. // case 5:
  10662. // item.MedChrgitmType = "08"
  10663. //
  10664. // break
  10665. // case 6:
  10666. // item.MedChrgitmType = "14"
  10667. //
  10668. // break
  10669. // case 7:
  10670. // item.MedChrgitmType = "14"
  10671. //
  10672. // break
  10673. // case 8:
  10674. // item.MedChrgitmType = "03"
  10675. // break
  10676. // case 9:
  10677. // item.MedChrgitmType = "14"
  10678. // break
  10679. //
  10680. // }
  10681. //
  10682. // }
  10683. //
  10684. // } else if item.HisPrescriptionProject.Type == 3 {
  10685. // item.MedChrgitmType = "08"
  10686. // }
  10687. // }
  10688. // }
  10689. //
  10690. // for _, item := range orderInfos_two {
  10691. // fmt.Println(item.MedChrgitmType)
  10692. // if item.MedChrgitmType == "01" { //床位费
  10693. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10694. // bedCostSelfTotal = bedCostTotal
  10695. // }
  10696. //
  10697. // if item.MedChrgitmType == "02" { //诊察费
  10698. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10699. // zhenChaCostSelfTotal = zhenChaCostTotal
  10700. // }
  10701. //
  10702. // if item.MedChrgitmType == "03" { //检查费
  10703. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10704. // checkCostSelfTotal = checkCostTotal
  10705. // }
  10706. //
  10707. // if item.MedChrgitmType == "04" { //化验费
  10708. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10709. // laboratoryCostSelfTotal = laboratoryCostTotal
  10710. // }
  10711. //
  10712. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10713. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10714. // treatCostSelfTotal = treatCostTotal
  10715. // }
  10716. //
  10717. // if item.MedChrgitmType == "06" { //手术费
  10718. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10719. // operationCostSelfTotal = treatCostTotal
  10720. // }
  10721. //
  10722. // if item.MedChrgitmType == "08" { //材料费
  10723. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10724. // materialCostSelfTotal = materialCostTotal
  10725. // }
  10726. //
  10727. // if item.MedChrgitmType == "09" { //西药费
  10728. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10729. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10730. // }
  10731. //
  10732. // if item.MedChrgitmType == "11" { //中成费
  10733. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10734. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10735. // }
  10736. //
  10737. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10738. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10739. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10740. // otherCostSelfTotal = otherCostTotal
  10741. // }
  10742. // } else {
  10743. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10744. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10745. // otherCostSelfTotal = otherCostTotal
  10746. // }
  10747. //
  10748. // }
  10749. //
  10750. // }
  10751. //
  10752. // } else {
  10753. // for _, item := range orderInfos {
  10754. // if item.MedChrgitmType == "01" { //床位费
  10755. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10756. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10757. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10758. // }
  10759. //
  10760. // if item.MedChrgitmType == "02" { //诊察费
  10761. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10762. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10763. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10764. // }
  10765. //
  10766. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10767. // if item.MedChrgitmType == "03" { //检查费
  10768. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10769. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10770. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10771. //
  10772. // }
  10773. // } else {
  10774. // if item.MedChrgitmType == "03" { //检查费
  10775. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10776. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10777. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10778. // }
  10779. //
  10780. // }
  10781. //
  10782. // if item.MedChrgitmType == "04" { //化验费
  10783. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10784. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10785. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10786. //
  10787. // }
  10788. //
  10789. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10790. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10791. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10792. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10793. //
  10794. // }
  10795. //
  10796. // if item.MedChrgitmType == "06" { //手术费
  10797. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10798. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10799. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10800. // }
  10801. //
  10802. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10803. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10804. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10805. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10806. // }
  10807. //
  10808. // if item.MedChrgitmType == "09" { //西药费
  10809. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10810. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10811. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10812. // }
  10813. //
  10814. // if item.MedChrgitmType == "11" { //中成费
  10815. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10816. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10817. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10818. // }
  10819. //
  10820. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10821. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10822. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10823. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10824. // }
  10825. //
  10826. // }
  10827. // }
  10828. // timeLayout := "2006-01-02"
  10829. // loc, _ := time.LoadLocation("Local")
  10830. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10831. // if err != nil {
  10832. // }
  10833. // startRecordDateTime := startTime.Unix()
  10834. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10835. // if err != nil {
  10836. // }
  10837. // endRecordDateTime := endTime.Unix()
  10838. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10839. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10840. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10841. //
  10842. // c.ServeSuccessJSON(map[string]interface{}{
  10843. // "order_number": order.Number, //业务流水号
  10844. // "id_card_no": his.IdCardNo, //社会保障号
  10845. // "department_name": department.Name, //科室
  10846. // "number": his.Number, //门诊号
  10847. // "date": order.SettleAccountsDate, //结算日期
  10848. // "name": order.PsnName, //姓名
  10849. // "gender": patient.Gender, //性别
  10850. // "psn_cash_money": order.PsnCashPay, //个人支付
  10851. // "pay_way": "门诊", //结算方式
  10852. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10853. // "admin_user_name": admin.UserName, //收款员
  10854. // "order": order,
  10855. // "order_info": orderInfos_two,
  10856. // "his": his,
  10857. // "bedCostTotal": bedCostTotal,
  10858. // "bedCostSelfTotal": bedCostSelfTotal,
  10859. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10860. // "operationCostTotal": operationCostTotal,
  10861. // "operationCostSelfTotal": operationCostSelfTotal,
  10862. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10863. // "otherCostTotal": otherCostTotal,
  10864. // "otherCostSelfTotal": otherCostSelfTotal,
  10865. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10866. // "materialCostTotal": materialCostTotal,
  10867. // "materialCostSelfTotal": materialCostSelfTotal,
  10868. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10869. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10870. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10871. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10872. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10873. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10874. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10875. // "checkCostTotal": checkCostTotal,
  10876. // "checkCostSelfTotal": checkCostSelfTotal,
  10877. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10878. // "laboratoryCostTotal": laboratoryCostTotal,
  10879. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10880. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10881. // "treatCostTotal": treatCostTotal,
  10882. // "treatCostSelfTotal": treatCostSelfTotal,
  10883. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10884. // "zhenChaCostTotal": zhenChaCostTotal,
  10885. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10886. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10887. // "his_hospital_record": his_hospital_record,
  10888. // "pre_pay_money": pre_pay_money,
  10889. // "refund_sum": sum,
  10890. // })
  10891. //
  10892. //}
  10893. func (this *HisApiController) GetIncomeStatisticsData() {
  10894. start_time := this.GetString("start_time")
  10895. end_time := this.GetString("end_time")
  10896. key_words := this.GetString("key_words")
  10897. limit, _ := this.GetInt64("limit")
  10898. page, _ := this.GetInt64("page")
  10899. if page <= 0 {
  10900. page = 1
  10901. }
  10902. if limit <= 0 {
  10903. limit = 10
  10904. }
  10905. statistics_type, _ := this.GetInt64("statistics_type")
  10906. admin := this.GetAdminUserInfo()
  10907. timeLayout := "2006-01-02"
  10908. loc, _ := time.LoadLocation("Local")
  10909. var theStartTIme int64
  10910. if len(start_time) > 0 {
  10911. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10912. if err != nil {
  10913. theStartTIme = 0
  10914. }
  10915. theStartTIme = theTime.Unix()
  10916. }
  10917. var theEndtTIme int64
  10918. if len(end_time) > 0 {
  10919. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10920. if err != nil {
  10921. theEndtTIme = 0
  10922. }
  10923. theEndtTIme = theTime.Unix()
  10924. }
  10925. if statistics_type == 1 {
  10926. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10927. this.ServeSuccessJSON(map[string]interface{}{
  10928. "list": list,
  10929. "total": total,
  10930. })
  10931. } else {
  10932. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10933. this.ServeSuccessJSON(map[string]interface{}{
  10934. "list": list,
  10935. "total": total,
  10936. })
  10937. }
  10938. }
  10939. func (c *HisApiController) PostProjectInformation() {
  10940. adminUser := c.GetAdminUserInfo()
  10941. orgId := adminUser.CurrentOrgId
  10942. dataBody := make(map[string]interface{}, 0)
  10943. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10944. if err != nil {
  10945. utils.ErrorLog(err.Error())
  10946. return
  10947. }
  10948. utils.ErrorLog("%v", dataBody)
  10949. var projectList []*models.HisProject
  10950. var total_goods []interface{}
  10951. tempProjects := dataBody["projects"].([]interface{})
  10952. total_goods = tempProjects
  10953. for index, projectMap := range tempProjects {
  10954. projectM := projectMap.(map[string]interface{})
  10955. var project models.HisProject
  10956. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10957. utils.ErrorLog("project_name")
  10958. return
  10959. }
  10960. project_name, _ := projectM["project_name"].(string)
  10961. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10962. err_log := models.ExportErrLog{
  10963. LogType: 6,
  10964. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10965. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10966. Status: 1,
  10967. CreateTime: time.Now().Unix(),
  10968. UpdateTime: time.Now().Unix(),
  10969. ExportTime: time.Now().Unix(),
  10970. }
  10971. service.CreateExportErrLog(&err_log)
  10972. continue
  10973. }
  10974. project.ProjectName = project_name
  10975. prices := projectM["price"].(string)
  10976. price, _ := strconv.ParseFloat(prices, 64)
  10977. if price <= 0 { //名字为空则生成一条导入错误日志
  10978. err_log := models.ExportErrLog{
  10979. LogType: 6,
  10980. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10981. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10982. Status: 1,
  10983. CreateTime: time.Now().Unix(),
  10984. UpdateTime: time.Now().Unix(),
  10985. ExportTime: time.Now().Unix(),
  10986. }
  10987. service.CreateExportErrLog(&err_log)
  10988. continue
  10989. }
  10990. project.Price = price
  10991. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10992. utils.ErrorLog("unit_id")
  10993. return
  10994. }
  10995. unit := projectM["unit"].(string)
  10996. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10997. err_log := models.ExportErrLog{
  10998. LogType: 6,
  10999. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11000. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11001. Status: 1,
  11002. CreateTime: time.Now().Unix(),
  11003. UpdateTime: time.Now().Unix(),
  11004. ExportTime: time.Now().Unix(),
  11005. }
  11006. service.CreateExportErrLog(&err_log)
  11007. continue
  11008. }
  11009. project.Unit = unit
  11010. cost_classify := projectM["cost_classify"].(string)
  11011. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11012. err_log := models.ExportErrLog{
  11013. LogType: 6,
  11014. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11015. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11016. Status: 1,
  11017. CreateTime: time.Now().Unix(),
  11018. UpdateTime: time.Now().Unix(),
  11019. ExportTime: time.Now().Unix(),
  11020. }
  11021. service.CreateExportErrLog(&err_log)
  11022. continue
  11023. }
  11024. var costClassify = "费用类别"
  11025. var cost_classify_id int64
  11026. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11027. if len(cost_classify) != 0 {
  11028. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11029. if errcode == gorm.ErrRecordNotFound {
  11030. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11031. dataconfig := models.DictDataconfig{
  11032. ParentId: costClassifyConfig.ID,
  11033. Module: "system",
  11034. OrgId: orgId,
  11035. Name: cost_classify,
  11036. FieldName: "",
  11037. Value: costConfig.Value + 1,
  11038. CreatedTime: "",
  11039. UpdatedTime: "",
  11040. CreateUserId: adminUser.AdminUser.Id,
  11041. Status: 1,
  11042. Remark: "",
  11043. DeleteIdSystem: 0,
  11044. Title: "",
  11045. Content: "",
  11046. Order: 0,
  11047. Code: "",
  11048. }
  11049. service.CreatedDicConfig(&dataconfig)
  11050. }
  11051. }
  11052. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11053. for _, it := range costClassList {
  11054. if cost_classify == it.Name {
  11055. cost_classify_id = int64(it.Value)
  11056. }
  11057. }
  11058. project.CostClassify = cost_classify_id
  11059. executive_section := projectM["executive_section"].(string)
  11060. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11061. err_log := models.ExportErrLog{
  11062. LogType: 6,
  11063. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11064. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11065. Status: 1,
  11066. CreateTime: time.Now().Unix(),
  11067. UpdateTime: time.Now().Unix(),
  11068. ExportTime: time.Now().Unix(),
  11069. }
  11070. service.CreateExportErrLog(&err_log)
  11071. continue
  11072. }
  11073. if len(executive_section) != 0 {
  11074. //查找科室是否有内容
  11075. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11076. if errcodedepart == gorm.ErrRecordNotFound {
  11077. department := models.XtHisDepartment{
  11078. Name: executive_section,
  11079. Status: 1,
  11080. UserOrgId: adminUser.CurrentOrgId,
  11081. CreatedTime: time.Now().Unix(),
  11082. }
  11083. service.CreateDePartment(&department)
  11084. }
  11085. }
  11086. var executive_section_id int64
  11087. departMentList, _ := service.GetAllDepartMent(orgId)
  11088. for _, it := range departMentList {
  11089. if executive_section == it.Name {
  11090. executive_section_id = it.ID
  11091. }
  11092. }
  11093. project.ExecutiveSection = executive_section_id
  11094. medical_coverage := projectM["medical_coverage"].(string)
  11095. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11096. err_log := models.ExportErrLog{
  11097. LogType: 6,
  11098. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11099. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11100. Status: 1,
  11101. CreateTime: time.Now().Unix(),
  11102. UpdateTime: time.Now().Unix(),
  11103. ExportTime: time.Now().Unix(),
  11104. }
  11105. service.CreateExportErrLog(&err_log)
  11106. continue
  11107. }
  11108. var medicalCoverage = "医保等级"
  11109. var medical_coverage_id int64
  11110. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11111. if len(medical_coverage) != 0 {
  11112. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11113. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11114. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11115. dataconfig := models.DictDataconfig{
  11116. ParentId: medicalCoverageConfig.ID,
  11117. Module: "system",
  11118. OrgId: orgId,
  11119. Name: medical_coverage,
  11120. FieldName: "",
  11121. Value: medicalCoverageConfig.Value + 1,
  11122. CreatedTime: "",
  11123. UpdatedTime: "",
  11124. CreateUserId: adminUser.AdminUser.Id,
  11125. Status: 1,
  11126. Remark: "",
  11127. DeleteIdSystem: 0,
  11128. Title: "",
  11129. Content: "",
  11130. Order: 0,
  11131. Code: "",
  11132. }
  11133. service.CreatedDicConfig(&dataconfig)
  11134. }
  11135. }
  11136. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11137. for _, it := range medicalCoverageList {
  11138. if medical_coverage == it.Name {
  11139. medical_coverage_id = int64(it.Value)
  11140. }
  11141. }
  11142. project.MedicalCoverage = medical_coverage_id
  11143. pinyin := projectM["pinyin"].(string)
  11144. project.Pinyin = pinyin
  11145. wubi := projectM["wubi"].(string)
  11146. project.Wubi = wubi
  11147. statistical_classification := projectM["statistical_classification"].(string)
  11148. var statisticalClassification = "统计分类"
  11149. var statistical_classification_id int64
  11150. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11151. if len(statistical_classification) != 0 {
  11152. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11153. if classificationerrcodes == gorm.ErrRecordNotFound {
  11154. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11155. dataconfig := models.DictDataconfig{
  11156. ParentId: classiFication.ID,
  11157. Module: "system",
  11158. OrgId: orgId,
  11159. Name: statistical_classification,
  11160. FieldName: "",
  11161. Value: classiFicationConfig.Value + 1,
  11162. CreatedTime: "",
  11163. UpdatedTime: "",
  11164. CreateUserId: adminUser.AdminUser.Id,
  11165. Status: 1,
  11166. Remark: "",
  11167. DeleteIdSystem: 0,
  11168. Title: "",
  11169. Content: "",
  11170. Order: 0,
  11171. Code: "",
  11172. }
  11173. service.CreatedDicConfig(&dataconfig)
  11174. }
  11175. }
  11176. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11177. for _, it := range classiFicationList {
  11178. if statistical_classification == it.Name {
  11179. statistical_classification_id = int64(it.Value)
  11180. }
  11181. }
  11182. project.StatisticalClassification = statistical_classification_id
  11183. disease_directory := int64(projectM["disease_directory"].(float64))
  11184. project.DiseaseDirectory = disease_directory
  11185. is_record := int64(projectM["is_record"].(float64))
  11186. project.IsRecord = is_record
  11187. medical_code := projectM["medical_code"].(string)
  11188. project.MedicalCode = medical_code
  11189. tube_color := projectM["tube_color"].(string)
  11190. var tubeColor = "试管颜色"
  11191. var tube_color_id int64
  11192. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11193. if len(tube_color) != 0 {
  11194. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11195. if errcodetube == gorm.ErrRecordNotFound {
  11196. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11197. dataconfig := models.DictDataconfig{
  11198. ParentId: tubeColorConfig.ID,
  11199. Module: "system",
  11200. OrgId: orgId,
  11201. Name: tube_color,
  11202. FieldName: "",
  11203. Value: tubeConfig.Value + 1,
  11204. CreatedTime: "",
  11205. UpdatedTime: "",
  11206. CreateUserId: adminUser.AdminUser.Id,
  11207. Status: 1,
  11208. Remark: "",
  11209. DeleteIdSystem: 0,
  11210. Title: "",
  11211. Content: "",
  11212. Order: 0,
  11213. Code: "",
  11214. }
  11215. service.CreatedDicConfig(&dataconfig)
  11216. }
  11217. }
  11218. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11219. for _, it := range tubeColorList {
  11220. if tube_color == it.Name {
  11221. tube_color_id = int64(it.Value)
  11222. }
  11223. }
  11224. project.TubeColor = tube_color_id
  11225. single_dose := projectM["single_dose"].(string)
  11226. project.SingleDose = single_dose
  11227. execution_frequency := projectM["execution_frequency"].(string)
  11228. project.ExecutionFrequency = execution_frequency
  11229. delivery_way := projectM["delivery_way"].(string)
  11230. project.DeliveryWay = delivery_way
  11231. number_days := projectM["number_days"].(string)
  11232. project.NumberDays = number_days
  11233. total := projectM["total"].(string)
  11234. project.Total = total
  11235. medical_status := int64(projectM["medical_status"].(float64))
  11236. project.MedicalStatus = medical_status
  11237. category := int64(projectM["category"].(float64))
  11238. project.Category = category
  11239. specail_project := int64(projectM["specail_project"].(float64))
  11240. project.SpecailProject = specail_project
  11241. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11242. project.SocialSecurityDirectoryCode = social_security_directory_code
  11243. remark := projectM["remark"].(string)
  11244. project.Remark = remark
  11245. record_date := projectM["record_date"].(string)
  11246. timeLayout := "2006-01-02"
  11247. loc, _ := time.LoadLocation("Local")
  11248. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11249. project.RecordDate = theTime.Unix()
  11250. projectList = append(projectList, &project)
  11251. }
  11252. export_time := time.Now().Unix()
  11253. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11254. if len(projectList) > 0 {
  11255. for _, item := range projectList {
  11256. hans := item.ProjectName // 要转换的汉字字符串
  11257. // 创建一个拼音转换器
  11258. p := pinyin.NewArgs()
  11259. // 将汉字转为拼音
  11260. pinyinSlice := pinyin.Pinyin(hans, p)
  11261. // 输出拼音
  11262. fmt.Println("Pinyin:", pinyinSlice)
  11263. // 获取首字母
  11264. firstLetter := ""
  11265. for _, py := range pinyinSlice {
  11266. if len(py) > 0 {
  11267. firstLetter += string(py[0][0])
  11268. }
  11269. }
  11270. item.FirstLetter = firstLetter
  11271. project := models.HisProject{
  11272. ProjectName: item.ProjectName,
  11273. Price: item.Price,
  11274. Unit: item.Unit,
  11275. CostClassify: item.CostClassify,
  11276. ExecutiveSection: item.ExecutiveSection,
  11277. MedicalCoverage: item.MedicalCoverage,
  11278. UserOrgId: orgId,
  11279. Status: 1,
  11280. CreatedTime: time.Now().Unix(),
  11281. Pinyin: item.Pinyin,
  11282. Wubi: item.Wubi,
  11283. StatisticalClassification: item.StatisticalClassification,
  11284. DiseaseDirectory: item.DiseaseDirectory,
  11285. IsRecord: item.IsRecord,
  11286. MedicalCode: item.MedicalCode,
  11287. TubeColor: item.TubeColor,
  11288. SingleDose: item.SingleDose,
  11289. DeliveryWay: item.DeliveryWay,
  11290. NumberDays: item.NumberDays,
  11291. Total: item.Total,
  11292. Category: item.Category,
  11293. MedicalStatus: item.MedicalStatus,
  11294. SpecailProject: item.SpecailProject,
  11295. RecordDate: item.RecordDate,
  11296. Remark: item.Remark,
  11297. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11298. ExecutionFrequency: item.ExecutionFrequency,
  11299. FirstLetter: item.FirstLetter,
  11300. }
  11301. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11302. if errcodeproject == gorm.ErrRecordNotFound {
  11303. service.CreateProjectInfomation(&project)
  11304. } else if errcodeproject == nil {
  11305. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11306. }
  11307. log := models.ExportLog{
  11308. LogType: 6,
  11309. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11310. TotalNum: int64(len(total_goods)),
  11311. FailNum: int64(len(errLogs)),
  11312. SuccessNum: int64(len(projectList)),
  11313. CreateTime: time.Now().Unix(),
  11314. UpdateTime: time.Now().Unix(),
  11315. ExportTime: export_time,
  11316. Status: 1,
  11317. }
  11318. service.CreateExportLog(&log)
  11319. c.ServeSuccessJSON(map[string]interface{}{
  11320. "msg": "导入成功",
  11321. "total_num": len(total_goods),
  11322. "success_num": len(projectList),
  11323. "fail_num": int64(len(errLogs)),
  11324. })
  11325. }
  11326. } else {
  11327. log := models.ExportLog{
  11328. LogType: 6,
  11329. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11330. TotalNum: int64(len(total_goods)),
  11331. FailNum: int64(len(errLogs)),
  11332. SuccessNum: int64(len(projectList)),
  11333. CreateTime: time.Now().Unix(),
  11334. UpdateTime: time.Now().Unix(),
  11335. ExportTime: export_time,
  11336. Status: 1,
  11337. }
  11338. service.CreateExportLog(&log)
  11339. c.ServeSuccessJSON(map[string]interface{}{
  11340. "msg": "导入成功",
  11341. "total_num": len(total_goods),
  11342. "success_num": len(projectList),
  11343. "fail_num": int64(len(errLogs)),
  11344. })
  11345. }
  11346. }
  11347. //func (this *HisApiController) EditProjectInformation(){
  11348. //
  11349. // id, _ := this.GetInt64("id")
  11350. // project_team := this.GetString("project_team")
  11351. // price := this.GetString("price")
  11352. // price_float, _ := strconv.ParseFloat(price, 64)
  11353. // pinyin := this.GetString("pinyin")
  11354. // wubi := this.GetString("wubi")
  11355. // tube_color, _ := this.GetInt64("tube_color")
  11356. // team_type, _ := this.GetInt64("team_type")
  11357. // remark := this.GetString("remark")
  11358. // ids := this.GetString("ids")
  11359. // item_id := this.GetString("item_id")
  11360. // projectTeam := models.XtHisProjectTeam{
  11361. // ProjectTeam: project_team,
  11362. // Price: price_float,
  11363. // Pinyin: pinyin,
  11364. // Wubi: wubi,
  11365. // TubeColor: tube_color,
  11366. // TeamType: team_type,
  11367. // Remark: remark,
  11368. // ProjectId: ids,
  11369. // ItemId: item_id,
  11370. // }
  11371. //
  11372. //
  11373. // dataBody := make(map[string]interface{}, 0)
  11374. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11375. // if err != nil {
  11376. // utils.ErrorLog(err.Error())
  11377. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11378. // return
  11379. // }
  11380. //
  11381. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11382. //
  11383. //
  11384. // if err != nil {
  11385. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11386. // return
  11387. // }
  11388. //
  11389. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11390. // infos, _ := dataBody["info"].([]interface{})
  11391. // if len(infos) > 0 {
  11392. // var ids []string
  11393. //
  11394. // for _, item := range infos {
  11395. // items := item.(map[string]interface{})
  11396. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11397. // utils.ErrorLog("id")
  11398. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11399. // return
  11400. // }
  11401. // id := int64(items["id"].(float64))
  11402. //
  11403. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11404. // utils.ErrorLog("type")
  11405. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11406. // return
  11407. // }
  11408. // types := int64(items["type"].(float64))
  11409. //
  11410. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11411. // utils.ErrorLog("number")
  11412. // }
  11413. //
  11414. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11415. //
  11416. // projectList := models.XtHisProjectList{
  11417. // Number: number,
  11418. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11419. // ProjectId: id,
  11420. // Status: 1,
  11421. // CreatedTime: time.Now().Unix(),
  11422. // UpdatedTime: time.Now().Unix(),
  11423. // TeamId: projectTeam.ID,
  11424. // Type: types,
  11425. // }
  11426. // list := projectList
  11427. //
  11428. // service.CreateProjectList(&list)
  11429. //
  11430. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11431. //
  11432. // }
  11433. // ids_str := strings.Join(ids, ",")
  11434. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11435. // service.SaveProjectTeam(&projectTeam)
  11436. // this.ServeSuccessJSON(map[string]interface{}{
  11437. // "projectTeam": projectTeam,
  11438. // })
  11439. // }
  11440. // }
  11441. //}
  11442. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11443. name := c.GetString("name")
  11444. mode_id, _ := c.GetInt64("mode", 0)
  11445. types, _ := c.GetInt64("type", 0)
  11446. patient_id, _ := c.GetInt64("patient_id", 0)
  11447. types = 1
  11448. adminInfo := c.GetAdminUserInfo()
  11449. template := &models.HisPrescriptionTemplate{
  11450. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11451. PatientId: patient_id,
  11452. Type: types,
  11453. Status: 1,
  11454. Ctime: time.Now().Unix(),
  11455. Mtime: time.Now().Unix(),
  11456. Name: name,
  11457. Mode: mode_id,
  11458. }
  11459. dataBody := make(map[string]interface{}, 0)
  11460. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11461. if err != nil {
  11462. utils.ErrorLog(err.Error())
  11463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11464. return
  11465. }
  11466. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11467. //如果已经存在记录则删除处方
  11468. if template_one.ID > 0 {
  11469. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11470. var ids []int64
  11471. var org_id int64
  11472. for _, item := range ps {
  11473. org_id = c.GetAdminUserInfo().CurrentOrgId
  11474. ids = append(ids, item.ID)
  11475. }
  11476. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11477. if err2 == nil {
  11478. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11479. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11480. if len(prescriptions) > 0 {
  11481. for _, item := range prescriptions {
  11482. items := item.(map[string]interface{})
  11483. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11484. utils.ErrorLog("type")
  11485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11486. return
  11487. }
  11488. types := int64(items["type"].(float64))
  11489. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11490. utils.ErrorLog("med_type")
  11491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11492. return
  11493. }
  11494. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11495. ctime := time.Now().Unix()
  11496. prescription := &models.HisPrescriptionInfoTemplate{
  11497. PatientId: patient_id,
  11498. UserOrgId: adminInfo.CurrentOrgId,
  11499. Ctime: ctime,
  11500. Mtime: ctime,
  11501. Type: types,
  11502. Modifier: adminInfo.AdminUser.Id,
  11503. Creator: adminInfo.AdminUser.Id,
  11504. Status: 1,
  11505. PTemplateId: template_one.ID,
  11506. MedType: med_type,
  11507. }
  11508. service.CreateHisPrescriptionInfoTemplate(prescription)
  11509. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11510. advices := items["advices"].([]interface{})
  11511. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11512. ctime := time.Now().Unix()
  11513. mtime := ctime
  11514. if len(advices) > 0 {
  11515. for _, advice := range advices {
  11516. var s models.HisPrescriptionAdviceTemplate
  11517. s.PrescriptionId = prescription.ID
  11518. s.AdviceType = 2
  11519. s.StopState = 2
  11520. s.ExecutionState = 2
  11521. s.Status = 1
  11522. s.UserOrgId = adminInfo.CurrentOrgId
  11523. s.CreatedTime = ctime
  11524. s.UpdatedTime = mtime
  11525. s.PatientId = patient_id
  11526. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11527. if errcode > 0 {
  11528. c.ServeFailJSONWithSGJErrorCode(errcode)
  11529. return
  11530. }
  11531. service.CreateHisPrescriptionAdviceTemplate(&s)
  11532. }
  11533. }
  11534. }
  11535. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11536. projects := items["project"].([]interface{})
  11537. if len(projects) > 0 {
  11538. for _, project := range projects {
  11539. var p models.HisPrescriptionProjectTemplate
  11540. p.PrescriptionId = prescription.ID
  11541. p.Ctime = time.Now().Unix()
  11542. p.Mtime = time.Now().Unix()
  11543. p.PatientId = patient_id
  11544. p.UserOrgId = adminInfo.CurrentOrgId
  11545. p.Status = 1
  11546. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11547. if errcode > 0 {
  11548. c.ServeFailJSONWithSGJErrorCode(errcode)
  11549. return
  11550. }
  11551. service.CreateHisPrescriptionProjectTemplate(&p)
  11552. }
  11553. }
  11554. }
  11555. }
  11556. c.ServeSuccessJSON(map[string]interface{}{
  11557. "msg": "创建成功",
  11558. })
  11559. }
  11560. }
  11561. } else {
  11562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11563. return
  11564. }
  11565. } else {
  11566. err3 := service.CreateHisPrescriptionTemplate(template)
  11567. if err3 == nil {
  11568. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11569. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11570. if len(prescriptions) > 0 {
  11571. for _, item := range prescriptions {
  11572. items := item.(map[string]interface{})
  11573. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11574. utils.ErrorLog("type")
  11575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11576. return
  11577. }
  11578. types := int64(items["type"].(float64))
  11579. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11580. utils.ErrorLog("med_type")
  11581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11582. return
  11583. }
  11584. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11585. ctime := time.Now().Unix()
  11586. prescription := &models.HisPrescriptionInfoTemplate{
  11587. PatientId: patient_id,
  11588. UserOrgId: adminInfo.CurrentOrgId,
  11589. Ctime: ctime,
  11590. Mtime: ctime,
  11591. Type: types,
  11592. Modifier: adminInfo.AdminUser.Id,
  11593. Creator: adminInfo.AdminUser.Id,
  11594. Status: 1,
  11595. PTemplateId: template.ID,
  11596. MedType: med_type,
  11597. }
  11598. service.CreateHisPrescriptionInfoTemplate(prescription)
  11599. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11600. advices := items["advices"].([]interface{})
  11601. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11602. ctime := time.Now().Unix()
  11603. mtime := ctime
  11604. if len(advices) > 0 {
  11605. for _, advice := range advices {
  11606. var s models.HisPrescriptionAdviceTemplate
  11607. s.PrescriptionId = prescription.ID
  11608. s.AdviceType = 2
  11609. s.StopState = 2
  11610. s.ExecutionState = 2
  11611. s.Status = 1
  11612. s.UserOrgId = adminInfo.CurrentOrgId
  11613. s.CreatedTime = ctime
  11614. s.UpdatedTime = mtime
  11615. s.PatientId = patient_id
  11616. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11617. if errcode > 0 {
  11618. c.ServeFailJSONWithSGJErrorCode(errcode)
  11619. return
  11620. }
  11621. service.CreateHisPrescriptionAdviceTemplate(&s)
  11622. }
  11623. }
  11624. }
  11625. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11626. projects := items["project"].([]interface{})
  11627. if len(projects) > 0 {
  11628. for _, project := range projects {
  11629. var p models.HisPrescriptionProjectTemplate
  11630. p.PrescriptionId = prescription.ID
  11631. p.Ctime = time.Now().Unix()
  11632. p.Mtime = time.Now().Unix()
  11633. p.PatientId = patient_id
  11634. p.UserOrgId = adminInfo.CurrentOrgId
  11635. p.Status = 1
  11636. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11637. if errcode > 0 {
  11638. c.ServeFailJSONWithSGJErrorCode(errcode)
  11639. return
  11640. }
  11641. service.CreateHisPrescriptionProjectTemplate(&p)
  11642. }
  11643. }
  11644. }
  11645. }
  11646. c.ServeSuccessJSON(map[string]interface{}{
  11647. "msg": "创建成功",
  11648. })
  11649. }
  11650. }
  11651. } else {
  11652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11653. return
  11654. }
  11655. }
  11656. }
  11657. func (c *HisApiController) PreSettle() {
  11658. id, _ := c.GetInt64("id")
  11659. record_time := c.GetString("record_time")
  11660. his_patient_id, _ := c.GetInt64("his_patient_id")
  11661. timeLayout := "2006-01-02"
  11662. loc, _ := time.LoadLocation("Local")
  11663. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11664. diagnosis_id := c.GetString("diagnosis")
  11665. sick_type, _ := c.GetInt64("sick_type")
  11666. reg_type, _ := c.GetInt64("p_type")
  11667. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11668. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11669. if err != nil {
  11670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11671. return
  11672. }
  11673. recordDateTime := theTime.Unix()
  11674. adminUser := c.GetAdminUserInfo()
  11675. var prescriptions []*models.HisPrescription
  11676. var start_time int64
  11677. var end_time int64
  11678. ids_str := c.GetString("ids")
  11679. ids_arr := strings.Split(ids_str, ",")
  11680. fmt.Println(reg_type)
  11681. if settle_accounts_type == 1 { //日结
  11682. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11683. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11684. } else {
  11685. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11686. }
  11687. fmt.Println(prescriptions)
  11688. } else { //月结
  11689. start_time_str := c.GetString("start_time")
  11690. end_time_str := c.GetString("end_time")
  11691. timeLayout := "2006-01-02"
  11692. loc, _ := time.LoadLocation("Local")
  11693. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11694. if err != nil {
  11695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11696. return
  11697. }
  11698. recordStartTime := theStartTime.Unix()
  11699. start_time = recordStartTime
  11700. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11701. if err != nil {
  11702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11703. return
  11704. }
  11705. recordEndTime := theEndTime.Unix()
  11706. end_time = recordEndTime
  11707. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11708. }
  11709. if reg_type == 1111 || reg_type == 1112 {
  11710. reg_type = 11
  11711. }
  11712. timestamp := time.Now().Unix()
  11713. tempTime := time.Unix(timestamp, 0)
  11714. timeFormat := tempTime.Format("20060102150405")
  11715. chrgBchno := rand.Intn(100000) + 10000
  11716. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11717. strconv.FormatInt(his.PatientId, 10)
  11718. var ids []int64
  11719. for _, item := range prescriptions {
  11720. ids = append(ids, item.ID)
  11721. }
  11722. fmt.Println(ids)
  11723. var total float64
  11724. for _, item := range prescriptions {
  11725. fmt.Println(item)
  11726. if item.Type == 1 { //药品
  11727. for _, subItem := range item.HisDoctorAdviceInfo {
  11728. total = total + (subItem.Price * subItem.PrescribingNumber)
  11729. }
  11730. }
  11731. if item.Type == 2 { //项目
  11732. for _, subItem := range item.HisPrescriptionProject {
  11733. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11734. total = total + (subItem.Price * cnt)
  11735. }
  11736. }
  11737. for _, subItem := range item.HisAdditionalCharge {
  11738. total = total + (subItem.Price * float64(subItem.Count))
  11739. }
  11740. }
  11741. allTotal := fmt.Sprintf("%.2f", total)
  11742. totals, _ := strconv.ParseFloat(allTotal, 64)
  11743. order := &models.HisOrder{
  11744. UserOrgId: adminUser.CurrentOrgId,
  11745. HisPatientId: his.ID,
  11746. PatientId: id,
  11747. SettleAccountsDate: recordDateTime,
  11748. Ctime: time.Now().Unix(),
  11749. Mtime: time.Now().Unix(),
  11750. Status: 1,
  11751. OrderStatus: 1,
  11752. MdtrtId: his.Number,
  11753. Number: chrg_bchno,
  11754. MedfeeSumamt: totals,
  11755. SettleEndTime: end_time,
  11756. SettleStartTime: start_time,
  11757. SettleType: settle_accounts_type,
  11758. PsnPartAmt: totals,
  11759. PsnCashPay: totals,
  11760. PType: 2,
  11761. IsPre: 1,
  11762. MedType: strconv.Itoa(int(reg_type)),
  11763. Diagnosis: diagnosis_id,
  11764. }
  11765. err = service.CreateOrder(order)
  11766. if err != nil {
  11767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11768. return
  11769. }
  11770. var customs []*Custom
  11771. for _, item := range prescriptions {
  11772. fmt.Println(item.Type)
  11773. if item.Type == 1 { //药品
  11774. for _, subItem := range item.HisDoctorAdviceInfo {
  11775. cus := &Custom{
  11776. AdviceId: subItem.ID,
  11777. ProjectId: 0,
  11778. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11779. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11780. FeedetlSn: subItem.FeedetlSn,
  11781. Price: fmt.Sprintf("%.2f", subItem.Price),
  11782. MedListCodg: subItem.MedListCodg,
  11783. Type: 1,
  11784. }
  11785. customs = append(customs, cus)
  11786. }
  11787. }
  11788. if item.Type == 2 { //项目
  11789. for _, subItem := range item.HisPrescriptionProject {
  11790. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11791. cus := &Custom{
  11792. AdviceId: 0,
  11793. ProjectId: subItem.ID,
  11794. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11795. Cut: fmt.Sprintf("%.2f", cnt),
  11796. FeedetlSn: subItem.FeedetlSn,
  11797. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11798. MedListCodg: subItem.MedListCodg,
  11799. Type: 2,
  11800. }
  11801. customs = append(customs, cus)
  11802. }
  11803. }
  11804. for _, item := range item.HisAdditionalCharge {
  11805. cus := &Custom{
  11806. ItemId: item.ID,
  11807. AdviceId: 0,
  11808. ProjectId: 0,
  11809. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11810. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11811. FeedetlSn: item.FeedetlSn,
  11812. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11813. MedListCodg: item.XtHisAddtionConfig.Code,
  11814. Type: 3,
  11815. }
  11816. customs = append(customs, cus)
  11817. }
  11818. }
  11819. fmt.Println(customs)
  11820. for _, item := range customs {
  11821. var advice_id int64 = 0
  11822. var project_id int64 = 0
  11823. var item_id int64 = 0
  11824. var types int64 = 0
  11825. if item.Type == 1 {
  11826. advice_id = item.AdviceId
  11827. project_id = 0
  11828. item_id = 0
  11829. } else if item.Type == 2 {
  11830. advice_id = 0
  11831. item_id = 0
  11832. project_id = item.ProjectId
  11833. } else if item.Type == 3 {
  11834. advice_id = 0
  11835. item_id = item.ItemId
  11836. project_id = 0
  11837. }
  11838. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11839. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11840. pric, _ := strconv.ParseFloat(item.Price, 32)
  11841. info := &models.HisOrderInfo{
  11842. OrderNumber: order.Number,
  11843. UploadDate: time.Now().Unix(),
  11844. AdviceId: advice_id,
  11845. DetItemFeeSumamt: detItemFeeSumamt,
  11846. Cnt: cut,
  11847. Pric: pric,
  11848. PatientId: id,
  11849. Status: 1,
  11850. Mtime: time.Now().Unix(),
  11851. Ctime: time.Now().Unix(),
  11852. UserOrgId: adminUser.CurrentOrgId,
  11853. HisPatientId: his.ID,
  11854. OrderId: order.ID,
  11855. ProjectId: project_id,
  11856. Type: types,
  11857. ItemId: item_id,
  11858. }
  11859. service.CreateOrderInfo(info)
  11860. }
  11861. his.SickType = sick_type
  11862. service.UpdataHisPateint(&his)
  11863. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11864. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11865. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11866. if err == nil {
  11867. c.ServeSuccessJSON(map[string]interface{}{
  11868. "msg": "结算成功",
  11869. })
  11870. }
  11871. }
  11872. type CustomOrderInfo struct {
  11873. Name string
  11874. Spec string
  11875. Unit string
  11876. Count float64
  11877. Price float64
  11878. Total float64
  11879. }
  11880. func (c *HisApiController) GetPrivateExpensesInfo() {
  11881. order_id, _ := c.GetInt64("id", 0)
  11882. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11883. order, _ := service.GetHisOrderByID(order_id)
  11884. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11885. if order.ID == 0 {
  11886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11887. return
  11888. }
  11889. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11890. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11891. org_id := c.GetAdminUserInfo().CurrentOrgId
  11892. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11893. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11894. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11895. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11896. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11897. //var orderInfos_four []*models.HisOrderInfoTwo
  11898. //for _, item := range orderInfos_three {
  11899. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11900. // item.HisPrescriptionProject.IsCheckTeam = 1
  11901. // orderInfos_four = append(orderInfos_four, item)
  11902. //
  11903. // }
  11904. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11905. // item.HisPrescriptionProject.IsCheckTeam = 2
  11906. // orderInfos_two = append(orderInfos_two, item)
  11907. // }
  11908. //}
  11909. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11910. //var cus_slice []CustomOrderInfo
  11911. //for _, item := range new_order_info {
  11912. // var cus CustomOrderInfo
  11913. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11914. // cus.Unit = ""
  11915. // cus.Spec = ""
  11916. // var total float64
  11917. // for _, subItem := range orderInfos_four {
  11918. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11919. // total = total + subItem.DetItemFeeSumamt
  11920. // fmt.Println(subItem.DetItemFeeSumamt)
  11921. // }
  11922. // }
  11923. // cus.Count = 1
  11924. // cus.Total = total
  11925. // cus_slice = append(cus_slice, cus)
  11926. //}
  11927. orderInfos = append(orderInfos, orderInfos_two...)
  11928. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11929. //orderInfos = append(orderInfos, orderInfos_three...)
  11930. //}/**/
  11931. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11932. c.ServeSuccessJSON(map[string]interface{}{
  11933. "order": order,
  11934. "order_info": orderInfos,
  11935. "patient": patient,
  11936. "admin_info": adminInfo,
  11937. "his": his,
  11938. "current_admin": role,
  11939. "org_config": miConfig,
  11940. //"new_order_info": cus_slice,
  11941. })
  11942. }
  11943. func (this *HisApiController) ChangeMedType() {
  11944. med_type := this.GetString("med_type")
  11945. old_med_type := this.GetString("old_med_type")
  11946. ids := this.GetString("ids")
  11947. settle_type, _ := this.GetInt64("settle_type")
  11948. start_time := this.GetString("start_time")
  11949. end_time := this.GetString("end_time")
  11950. ids_arr := strings.Split(ids, ",")
  11951. if settle_type == 1 { //日结
  11952. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11953. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11954. prescription.MedType = med_type
  11955. err := service.SaveHisPrescriptionTwo(&prescription)
  11956. if err == nil {
  11957. this.ServeSuccessJSON(map[string]interface{}{
  11958. "msg": "修改成功",
  11959. })
  11960. } else {
  11961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11962. return
  11963. }
  11964. } else if settle_type == 2 {
  11965. timeLayout := "2006-01-02"
  11966. loc, _ := time.LoadLocation("Local")
  11967. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11968. if err != nil {
  11969. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11970. return
  11971. }
  11972. recordStartTime := theStartTime.Unix()
  11973. start_time_timestamp := recordStartTime
  11974. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11975. if err != nil {
  11976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11977. return
  11978. }
  11979. recordEndTime := theEndTime.Unix()
  11980. end_time_timestamp := recordEndTime
  11981. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11982. if updateErr == nil {
  11983. this.ServeSuccessJSON(map[string]interface{}{
  11984. "msg": "修改成功",
  11985. })
  11986. } else {
  11987. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11988. return
  11989. }
  11990. }
  11991. }
  11992. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11993. patient_id, _ := c.GetInt64("patient_id")
  11994. his_patient_id, _ := c.GetInt64("his_patient_id")
  11995. record_date := c.GetString("record_date")
  11996. start_time := c.GetString("start_time")
  11997. end_time := c.GetString("end_time")
  11998. order_status, _ := c.GetInt64("type", 0)
  11999. p_type, _ := c.GetInt64("p_type", 0)
  12000. order_id, _ := c.GetInt64("order_id", 0)
  12001. timeLayout := "2006-01-02"
  12002. loc, _ := time.LoadLocation("Local")
  12003. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12004. if err != nil {
  12005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12006. return
  12007. }
  12008. recordDateTime := theTime.Unix()
  12009. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12010. if err != nil {
  12011. }
  12012. startRecordDateTime := startTime.Unix()
  12013. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12014. if err != nil {
  12015. }
  12016. endRecordDateTime := endTime.Unix()
  12017. admin := c.GetAdminUserInfo()
  12018. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12019. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12020. order, _ := service.GetHisOrderByID(order_id)
  12021. var monthPrescriptions []*models.HisPrescription
  12022. if order_status == 1 || order_status == 0 {
  12023. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12024. } else if order_status == 2 {
  12025. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12026. }
  12027. var settle_total float64
  12028. for _, item := range monthPrescriptions {
  12029. if len(item.HisPrescriptionProject) > 0 {
  12030. for _, subItem := range item.HisPrescriptionProject {
  12031. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12032. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12033. settle_total = settle_total + total
  12034. }
  12035. }
  12036. if len(item.HisDoctorAdviceInfo) > 0 {
  12037. for _, subItem := range item.HisDoctorAdviceInfo {
  12038. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12039. settle_total = settle_total + total
  12040. }
  12041. }
  12042. }
  12043. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12044. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12045. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12046. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12047. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12048. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12049. //获取所有科室信息
  12050. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12051. var dia string
  12052. for _, item := range month_p_info {
  12053. if len(dia) == 0 {
  12054. dia = item.Diagnosis
  12055. } else {
  12056. dia = dia + "," + item.Diagnosis
  12057. }
  12058. }
  12059. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12060. dia_arr = removeEmptyStrings(dia_arr)
  12061. c.ServeSuccessJSON(map[string]interface{}{
  12062. "his_info": his_patient_info,
  12063. "xt_info": xt_patient_info,
  12064. "case_history": case_history,
  12065. "info": patientPrescriptionInfo,
  12066. "last_info": lastPatientPrescriptionInfo,
  12067. "month_prescriptions": monthPrescriptions,
  12068. "order": order,
  12069. "doctors": doctors,
  12070. "department": department,
  12071. "settle_total": settle_total,
  12072. "dia_arr": dia_arr,
  12073. })
  12074. return
  12075. }
  12076. func removeEmptyStrings(input []string) []string {
  12077. var output []string
  12078. for _, s := range input {
  12079. if s != "" {
  12080. output = append(output, s)
  12081. }
  12082. }
  12083. return output
  12084. }
  12085. func removeDuplicates(input []string) []string {
  12086. seen := make(map[string]bool)
  12087. output := []string{}
  12088. for _, s := range input {
  12089. if _, exists := seen[s]; !exists {
  12090. seen[s] = true
  12091. output = append(output, s)
  12092. }
  12093. }
  12094. return output
  12095. }
  12096. func (c *HisApiController) GetHisMonthPatientInfo() {
  12097. patient_id, _ := c.GetInt64("patient_id")
  12098. his_patient_id, _ := c.GetInt64("his_patient_id")
  12099. record_date := c.GetString("record_date")
  12100. number := c.GetString("number")
  12101. start_time := c.GetString("start_time")
  12102. end_time := c.GetString("end_time")
  12103. p_type, _ := c.GetInt64("p_type")
  12104. timeLayout := "2006-01-02"
  12105. loc, _ := time.LoadLocation("Local")
  12106. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12107. if err != nil {
  12108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12109. return
  12110. }
  12111. recordDateTime := theTime.Unix()
  12112. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12113. if err != nil {
  12114. }
  12115. startRecordDateTime := startTime.Unix()
  12116. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12117. if err != nil {
  12118. }
  12119. endRecordDateTime := endTime.Unix()
  12120. admin := c.GetAdminUserInfo()
  12121. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12122. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12123. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12124. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12125. var settle_total float64
  12126. for _, item := range monthPrescriptions {
  12127. if len(item.HisPrescriptionProject) > 0 {
  12128. for _, subItem := range item.HisPrescriptionProject {
  12129. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12130. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12131. settle_total = settle_total + total
  12132. }
  12133. }
  12134. if len(item.HisDoctorAdviceInfo) > 0 {
  12135. for _, subItem := range item.HisDoctorAdviceInfo {
  12136. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12137. settle_total = settle_total + total
  12138. }
  12139. }
  12140. }
  12141. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12142. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12143. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12144. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12145. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12146. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12147. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12148. //获取所有科室信息
  12149. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12150. c.ServeSuccessJSON(map[string]interface{}{
  12151. "his_info": his_patient_info,
  12152. "xt_info": xt_patient_info,
  12153. "case_history": case_history,
  12154. "info": patientPrescriptionInfo,
  12155. "month_prescriptions": monthPrescriptions,
  12156. "order": order,
  12157. "doctors": doctors,
  12158. "department": department,
  12159. "count": count,
  12160. "drugStockConfig": drugStockConfig,
  12161. "last_info": lastPatientPrescriptionInfo,
  12162. "settle_total": settle_total,
  12163. })
  12164. return
  12165. }
  12166. func (c *HisApiController) GetAllOrder() {
  12167. org_id := c.GetAdminUserInfo().CurrentOrgId
  12168. orders, _ := service.GetNewHisOrderList(org_id)
  12169. c.ServeSuccessJSON(map[string]interface{}{
  12170. "order": orders,
  12171. })
  12172. return
  12173. }
  12174. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12175. newArr = make([]*models.HisOrderInfoTwo, 0)
  12176. for i := 0; i < len(arr); i++ {
  12177. repeat := false
  12178. for j := i + 1; j < len(arr); j++ {
  12179. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12180. repeat = true
  12181. break
  12182. }
  12183. }
  12184. if !repeat {
  12185. newArr = append(newArr, arr[i])
  12186. }
  12187. }
  12188. return
  12189. }
  12190. // 修改处方退库操作 参数传修改之前的处方数据
  12191. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12192. if advice.ExecutionState == 1 {
  12193. //查询该病人该药品是否有库存记录
  12194. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12195. if errcode == gorm.ErrRecordNotFound {
  12196. } else {
  12197. //退库
  12198. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12199. if advice.PrescribingNumberUnit == drug.MinUnit {
  12200. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12201. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12202. //退库
  12203. warehouseInfo := models.DrugWarehouseInfo{
  12204. StockMinNumber: prescribingNumber,
  12205. }
  12206. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12207. operation_time := time.Now().Unix()
  12208. creater := advice.AdviceDoctor
  12209. ctime := time.Now().Unix()
  12210. timeStr := time.Now().Format("2006-01-02")
  12211. timeArr := strings.Split(timeStr, "-")
  12212. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12213. total = total + 1
  12214. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12215. cancelStock := models.DrugCancelStock{
  12216. OrderNumber: orderNumber,
  12217. OperaTime: operation_time,
  12218. OrgId: advice.UserOrgId,
  12219. Creater: creater,
  12220. Ctime: ctime,
  12221. Status: 1,
  12222. ReturnTime: advice.AdviceDate,
  12223. Dealer: info.Dealer,
  12224. Manufacturer: info.Manufacturer,
  12225. Type: 1,
  12226. }
  12227. service.AddSigleDrugCancelStock(&cancelStock)
  12228. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12229. dealer, _ := service.GetDealerById(info.Dealer)
  12230. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12231. cancelStockInfo := models.DrugCancelStockInfo{
  12232. OrderNumber: cancelInfo.OrderNumber,
  12233. CancelStockId: cancelInfo.ID,
  12234. DrugId: info.DrugId,
  12235. Count: info.Count,
  12236. Status: 1,
  12237. Ctime: ctime,
  12238. OrgId: advice.UserOrgId,
  12239. Type: 1,
  12240. Manufacturer: manufactureName.ManufacturerName,
  12241. Dealer: dealer.DealerName,
  12242. Total: 0,
  12243. RetailPrice: info.RetailPrice,
  12244. RetailTotalPrice: info.RetailTotalPrice,
  12245. Price: info.Price,
  12246. RegisterAccount: "",
  12247. Remark: info.Remark,
  12248. BatchNumber: info.BatchNumber,
  12249. MaxUnit: info.CountUnit,
  12250. ProductDate: info.ProductDate,
  12251. ExpiryDate: info.ExpiryDate,
  12252. BatchNumberId: info.WarehouseInfoId,
  12253. }
  12254. flow := models.DrugFlow{
  12255. WarehousingId: 0,
  12256. DrugId: info.DrugId,
  12257. Number: "",
  12258. BatchNumber: info.BatchNumber,
  12259. Count: info.Count,
  12260. UserOrgId: advice.UserOrgId,
  12261. PatientId: 0,
  12262. SystemTime: ctime,
  12263. ConsumableType: 4,
  12264. IsSys: 0,
  12265. WarehousingOrder: "",
  12266. WarehouseOutId: 0,
  12267. WarehouseOutOrderNumber: "",
  12268. IsEdit: 0,
  12269. CancelStockId: cancelStock.ID,
  12270. CancelOrderNumber: cancelStock.OrderNumber,
  12271. Manufacturer: info.Manufacturer,
  12272. Dealer: info.Dealer,
  12273. Creator: advice.UserOrgId,
  12274. UpdateCreator: 0,
  12275. Status: 1,
  12276. Ctime: time.Now().Unix(),
  12277. Mtime: 0,
  12278. Price: info.Price,
  12279. WarehousingDetailId: 0,
  12280. WarehouseOutDetailId: 0,
  12281. CancelOutDetailId: 0,
  12282. ExpireDate: info.ExpiryDate,
  12283. ProductDate: info.ProductDate,
  12284. MaxUnit: info.CountUnit,
  12285. MinUnit: "",
  12286. }
  12287. service.CreatedCancelStock(cancelStockInfo)
  12288. service.CreateDrugFlowOne(flow)
  12289. } else {
  12290. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12291. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12292. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12293. warehouseInfo := models.DrugWarehouseInfo{
  12294. StockMinNumber: prescribingNumber,
  12295. }
  12296. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12297. }
  12298. operation_time := time.Now().Unix()
  12299. creater := advice.AdviceDoctor
  12300. ctime := time.Now().Unix()
  12301. timeStr := time.Now().Format("2006-01-02")
  12302. timeArr := strings.Split(timeStr, "-")
  12303. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12304. total = total + 1
  12305. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12306. cancelStock := models.DrugCancelStock{
  12307. OrderNumber: orderNumber,
  12308. OperaTime: operation_time,
  12309. OrgId: advice.UserOrgId,
  12310. Creater: creater,
  12311. Ctime: ctime,
  12312. Status: 1,
  12313. ReturnTime: advice.AdviceDate,
  12314. Dealer: info.Dealer,
  12315. Manufacturer: info.Manufacturer,
  12316. Type: 1,
  12317. }
  12318. service.AddSigleDrugCancelStock(&cancelStock)
  12319. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12320. dealer, _ := service.GetDealerById(info.Dealer)
  12321. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12322. cancelStockInfo := models.DrugCancelStockInfo{
  12323. OrderNumber: cancelInfo.OrderNumber,
  12324. CancelStockId: cancelInfo.ID,
  12325. DrugId: info.DrugId,
  12326. Count: info.Count,
  12327. Status: 1,
  12328. Ctime: ctime,
  12329. OrgId: advice.UserOrgId,
  12330. Type: 1,
  12331. Manufacturer: manufactureName.ManufacturerName,
  12332. Dealer: dealer.DealerName,
  12333. Total: 0,
  12334. RetailPrice: info.RetailPrice,
  12335. RetailTotalPrice: info.RetailTotalPrice,
  12336. Price: info.Price,
  12337. RegisterAccount: "",
  12338. Remark: info.Remark,
  12339. BatchNumber: info.BatchNumber,
  12340. MaxUnit: info.CountUnit,
  12341. ProductDate: info.ProductDate,
  12342. ExpiryDate: info.ExpiryDate,
  12343. BatchNumberId: info.WarehouseInfoId,
  12344. }
  12345. flow := models.DrugFlow{
  12346. WarehousingId: 0,
  12347. DrugId: info.DrugId,
  12348. Number: "",
  12349. BatchNumber: info.BatchNumber,
  12350. Count: info.Count,
  12351. UserOrgId: advice.UserOrgId,
  12352. PatientId: 0,
  12353. SystemTime: ctime,
  12354. ConsumableType: 4,
  12355. IsSys: 0,
  12356. WarehousingOrder: "",
  12357. WarehouseOutId: 0,
  12358. WarehouseOutOrderNumber: "",
  12359. IsEdit: 0,
  12360. CancelStockId: cancelStock.ID,
  12361. CancelOrderNumber: cancelStock.OrderNumber,
  12362. Manufacturer: info.Manufacturer,
  12363. Dealer: info.Dealer,
  12364. Creator: advice.AdviceDoctor,
  12365. UpdateCreator: 0,
  12366. Status: 1,
  12367. Ctime: time.Now().Unix(),
  12368. Mtime: 0,
  12369. Price: info.Price,
  12370. WarehousingDetailId: 0,
  12371. WarehouseOutDetailId: 0,
  12372. CancelOutDetailId: 0,
  12373. ExpireDate: info.ExpiryDate,
  12374. ProductDate: info.ProductDate,
  12375. MaxUnit: info.CountUnit,
  12376. MinUnit: "",
  12377. }
  12378. service.CreatedCancelStock(cancelStockInfo)
  12379. service.CreateDrugFlowOne(flow)
  12380. }
  12381. }
  12382. }
  12383. return err
  12384. }
  12385. func (this *HisApiController) DeleteNCDS() {
  12386. id, _ := this.GetInt64("id", 0)
  12387. if id > 0 {
  12388. service.DeletePsnNCDSRecordById(id)
  12389. this.ServeSuccessJSON(map[string]interface{}{
  12390. "msg": "删除成功",
  12391. })
  12392. } else {
  12393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12394. return
  12395. }
  12396. }
  12397. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12398. id, _ := c.GetInt64("id")
  12399. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12400. c.ServeSuccessJSON(map[string]interface{}{
  12401. "advice": advice,
  12402. })
  12403. return
  12404. }
  12405. func (c *HisApiController) GetHisMonthChargePatientList() {
  12406. record_date := c.GetString("record_date")
  12407. start_time := c.GetString("start_time")
  12408. end_time := c.GetString("end_time")
  12409. timeLayout := "2006-01-02"
  12410. loc, _ := time.LoadLocation("Local")
  12411. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12412. if err != nil {
  12413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12414. return
  12415. }
  12416. if err != nil {
  12417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12418. return
  12419. }
  12420. recordDateTime := theTime.Unix()
  12421. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12422. if err != nil {
  12423. }
  12424. startRecordDateTime := startTime.Unix()
  12425. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12426. if err != nil {
  12427. }
  12428. endRecordDateTime := endTime.Unix()
  12429. adminInfo := c.GetAdminUserInfo()
  12430. var tempMonthChargePatients []*service.MonthChargePatients
  12431. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12432. for _, item := range tempPatients {
  12433. //过滤没有处方的
  12434. if len(item.HisPrescription) == 0 {
  12435. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12436. }
  12437. }
  12438. c.ServeSuccessJSON(map[string]interface{}{
  12439. "list": tempMonthChargePatients,
  12440. })
  12441. }
  12442. // PrescriptionDifference 医嘱数量差值结构体
  12443. type PrescriptionDrugDifference struct {
  12444. DrugID int64 //基础库药品id
  12445. ID int64 //医嘱id
  12446. Difference float64 //差值
  12447. Unit string //单位
  12448. }
  12449. type PrescriptionGoodDifference struct {
  12450. GoodID int64 //基础库项目耗材id
  12451. ID int64 //医嘱id
  12452. Difference int64 //差值
  12453. Unit string //单位
  12454. Type int64 //类型
  12455. }
  12456. type EditCustomData struct {
  12457. adviceList []*models.HisDoctorAdviceInfo
  12458. projectList []*models.HisPrescriptionProject
  12459. }
  12460. type SrcCustomData struct {
  12461. adviceList []*models.HisDoctorAdviceInfo
  12462. projectList []*models.HisPrescriptionProject
  12463. }
  12464. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12465. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12466. differences := make([]*PrescriptionDrugDifference, 0)
  12467. // 创建一个 map 来存储第一个切片中的药品信息
  12468. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12469. for _, advice := range firstPrescription {
  12470. firstMap[advice.DrugId] = advice
  12471. }
  12472. // 遍历第二个切片中的药品信息,并比较数量差值
  12473. for _, advice := range secondPrescription {
  12474. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12475. diff := &PrescriptionDrugDifference{
  12476. DrugID: advice.DrugId,
  12477. ID: firstAdvice.ID,
  12478. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12479. Unit: firstAdvice.PrescribingNumberUnit,
  12480. }
  12481. differences = append(differences, diff)
  12482. }
  12483. }
  12484. return differences
  12485. }
  12486. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12487. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12488. differences := make([]*PrescriptionGoodDifference, 0)
  12489. // 创建一个 map 来存储第一个切片中的耗材信息
  12490. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12491. for _, good := range firstPrescription {
  12492. firstMap[good.ProjectId] = good
  12493. }
  12494. // 遍历第二个切片中的耗材信息,并比较数量差值
  12495. for _, good := range secondPrescription {
  12496. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12497. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12498. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12499. diff := &PrescriptionGoodDifference{
  12500. GoodID: good.ProjectId,
  12501. ID: firstGood.ID,
  12502. Difference: count - firstCount,
  12503. Unit: firstGood.Unit,
  12504. Type: firstGood.Type,
  12505. }
  12506. differences = append(differences, diff)
  12507. }
  12508. }
  12509. return differences
  12510. }
  12511. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12512. var adviceList []*models.HisDoctorAdviceInfo
  12513. var projectList []*models.HisPrescriptionProject
  12514. var advice_ids []int64
  12515. var project_ids []int64
  12516. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12517. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12518. //var tempPrescription *models.HisPrescriptionProjectscription
  12519. if len(prescriptions) > 0 {
  12520. for _, item := range prescriptions {
  12521. items := item.(map[string]interface{})
  12522. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12523. advices := items["advices"].([]interface{})
  12524. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12525. groupNo := int64(0)
  12526. ctime := time.Now().Unix()
  12527. mtime := ctime
  12528. if len(advices) > 0 {
  12529. for _, advice := range advices {
  12530. var s models.HisDoctorAdviceInfo
  12531. s.AdviceType = 2
  12532. s.StopState = 2
  12533. s.ExecutionState = 2
  12534. s.Status = 1
  12535. s.Groupno = groupNo
  12536. s.CreatedTime = ctime
  12537. s.UpdatedTime = mtime
  12538. s.IsSettle = 2
  12539. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12540. //存储切片中
  12541. if s.ID > 0 {
  12542. advice_ids = append(advice_ids, s.ID)
  12543. adviceList = append(adviceList, &s)
  12544. }
  12545. }
  12546. }
  12547. }
  12548. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12549. projects := items["project"].([]interface{})
  12550. if len(projects) > 0 {
  12551. for _, project := range projects {
  12552. var p models.HisPrescriptionProject
  12553. p.Ctime = time.Now().Unix()
  12554. p.Mtime = time.Now().Unix()
  12555. p.Status = 1
  12556. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12557. if p.ID > 0 {
  12558. project_ids = append(project_ids, p.ID)
  12559. projectList = append(projectList, &p)
  12560. }
  12561. }
  12562. }
  12563. }
  12564. }
  12565. }
  12566. }
  12567. editCustomData.projectList = projectList
  12568. editCustomData.adviceList = adviceList
  12569. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12570. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12571. srcCustomData.adviceList = list
  12572. srcCustomData.projectList = list2
  12573. return
  12574. }
  12575. func (c *HisApiController) GetAllGoodInforList() {
  12576. orgId := c.GetAdminUserInfo().CurrentOrgId
  12577. goodList, _ := service.GetAllGoodList(orgId)
  12578. c.ServeSuccessJSON(map[string]interface{}{
  12579. "goodList": goodList,
  12580. })
  12581. return
  12582. }
  12583. func (this *HisApiController) SaveGoodList() {
  12584. project_name := this.GetString("project_name")
  12585. sort, _ := this.GetInt64("sort")
  12586. orgId := this.GetAdminUserInfo().CurrentOrgId
  12587. dataBody := make(map[string]interface{}, 0)
  12588. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12589. if err != nil {
  12590. utils.ErrorLog(err.Error())
  12591. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12592. return
  12593. }
  12594. goodTeam := models.XtGoodTeam{
  12595. ProjectName: project_name,
  12596. Sort: sort,
  12597. UserOrgId: orgId,
  12598. Status: 1,
  12599. Ctime: time.Now().Unix(),
  12600. Mtime: time.Now().Unix(),
  12601. }
  12602. service.CreateGoodTeam(goodTeam)
  12603. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  12604. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12605. infos, _ := dataBody["info"].([]interface{})
  12606. if len(infos) > 0 {
  12607. for _, item := range infos {
  12608. items := item.(map[string]interface{})
  12609. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  12610. utils.ErrorLog("good_id")
  12611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12612. return
  12613. }
  12614. good_id := int64(items["good_id"].(float64))
  12615. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  12616. utils.ErrorLog("number")
  12617. }
  12618. number := int64(items["number"].(float64))
  12619. xtGoodTeamList := models.XtGoodTeamList{
  12620. GoodId: good_id,
  12621. Count: number,
  12622. TeamId: lastGoodTeam.ID,
  12623. UserOrgId: orgId,
  12624. Status: 1,
  12625. Ctime: time.Now().Unix(),
  12626. Mtime: time.Now().Unix(),
  12627. }
  12628. service.CreateGoodList(xtGoodTeamList)
  12629. }
  12630. this.ServeSuccessJSON(map[string]interface{}{
  12631. "lastGoodTeam": lastGoodTeam,
  12632. })
  12633. }
  12634. }
  12635. return
  12636. }
  12637. func (this *HisApiController) GetGoodList() {
  12638. orgId := this.GetAdminUserInfo().CurrentOrgId
  12639. limit, _ := this.GetInt64("limit")
  12640. page, _ := this.GetInt64("page")
  12641. keyword := this.GetString("keyword")
  12642. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  12643. this.ServeSuccessJSON(map[string]interface{}{
  12644. "list": list,
  12645. "total": total,
  12646. })
  12647. }
  12648. func (this *HisApiController) GetGoodNameDetail() {
  12649. id, _ := this.GetInt64("id")
  12650. orgId := this.GetAdminUserInfo().CurrentOrgId
  12651. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  12652. goodList, _ := service.GetAllGoodList(orgId)
  12653. this.ServeSuccessJSON(map[string]interface{}{
  12654. "goodNameDetail": goodNameDetail,
  12655. "goodList": goodList,
  12656. })
  12657. }
  12658. func (this *HisApiController) UpdateGoodList() {
  12659. project_name := this.GetString("project_name")
  12660. sort, _ := this.GetInt64("sort")
  12661. id, _ := this.GetInt64("id")
  12662. orgId := this.GetAdminUserInfo().CurrentOrgId
  12663. dataBody := make(map[string]interface{}, 0)
  12664. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12665. if err != nil {
  12666. utils.ErrorLog(err.Error())
  12667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12668. return
  12669. }
  12670. goodTeam := models.XtGoodTeam{
  12671. ProjectName: project_name,
  12672. Sort: sort,
  12673. UserOrgId: orgId,
  12674. Status: 1,
  12675. Ctime: time.Now().Unix(),
  12676. Mtime: time.Now().Unix(),
  12677. ID: id,
  12678. }
  12679. service.SaveGoodTeam(goodTeam)
  12680. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  12681. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12682. infos, _ := dataBody["info"].([]interface{})
  12683. if len(infos) > 0 {
  12684. for _, item := range infos {
  12685. items := item.(map[string]interface{})
  12686. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  12687. utils.ErrorLog("good_id")
  12688. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12689. return
  12690. }
  12691. good_id := int64(items["good_id"].(float64))
  12692. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12693. utils.ErrorLog("id")
  12694. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12695. return
  12696. }
  12697. id := int64(items["id"].(float64))
  12698. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  12699. utils.ErrorLog("number")
  12700. }
  12701. number := int64(items["number"].(float64))
  12702. xtGoodTeamList := models.XtGoodTeamList{
  12703. ID: id,
  12704. GoodId: good_id,
  12705. Count: number,
  12706. TeamId: lastGoodTeam.ID,
  12707. UserOrgId: orgId,
  12708. Status: 1,
  12709. Ctime: time.Now().Unix(),
  12710. Mtime: time.Now().Unix(),
  12711. }
  12712. service.SaveGoodList(xtGoodTeamList)
  12713. }
  12714. this.ServeSuccessJSON(map[string]interface{}{
  12715. "lastGoodTeam": lastGoodTeam,
  12716. })
  12717. }
  12718. }
  12719. return
  12720. }
  12721. func (this *HisApiController) DeleteGoodTeam() {
  12722. id, _ := this.GetInt64("id")
  12723. team, _ := service.DeleteGoodTeam(id)
  12724. this.ServeSuccessJSON(map[string]interface{}{
  12725. "team": team,
  12726. })
  12727. }
  12728. func (this *HisApiController) DeleteGood() {
  12729. id, _ := this.GetInt64("id")
  12730. good, _ := service.DeleteGood(id)
  12731. this.ServeSuccessJSON(map[string]interface{}{
  12732. "good": good,
  12733. })
  12734. }