his_api_controller.go 597KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "card_desc":
  229. order.CardDesc = desc
  230. break
  231. case "band_card_pay":
  232. order.BandCardPay = desc
  233. break
  234. case "ali_pay":
  235. order.AliPay = desc
  236. break
  237. case "wechat_pay":
  238. order.WechatPay = desc
  239. break
  240. case "fa_piao_number":
  241. order.FaPiaoNumber = desc
  242. break
  243. case "fa_piao_code":
  244. order.FaPiaoCode = desc
  245. break
  246. }
  247. err := service.SaveHisOrder(&order)
  248. if err == nil {
  249. c.ServeSuccessJSON(map[string]interface{}{
  250. "msg": "修改成功",
  251. })
  252. return
  253. } else {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  255. return
  256. }
  257. }
  258. func (c *HisApiController) GetMonthHisPatient() {
  259. record_date := c.GetString("record_date")
  260. //order_status, _ := c.GetInt64("type")
  261. timeLayout := "2006-01-02"
  262. loc, _ := time.LoadLocation("Local")
  263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  264. if err != nil {
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. recordDateTime := theTime.Unix()
  269. adminInfo := c.GetAdminUserInfo()
  270. var tempPatients []service.NewTempPatients
  271. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  272. // 获取当前时间
  273. now := time.Now()
  274. // 获取本月的第一天
  275. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  276. // 获取下个月的第一天
  277. nextMonth := firstDay.AddDate(0, 1, 0)
  278. // 获取本月的最后一天
  279. lastDay := nextMonth.Add(-time.Nanosecond)
  280. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  281. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  282. var patients []service.NewTempPatients
  283. var patients_two []service.NewTempPatients
  284. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. patients_two = append(patients_two, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. //}
  294. }
  295. } else {
  296. for _, item := range tempPatients {
  297. //过滤掉没挂号的和没开处方的
  298. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  299. patients = append(patients, item)
  300. }
  301. ////过滤掉没挂号的
  302. //if len(item.HisPatient) > 0 {
  303. // patients_two = append(patients_two, item)
  304. //}
  305. }
  306. }
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "list": patients,
  309. "list_two": patients_two,
  310. "chargePatients": chargePatients,
  311. })
  312. }
  313. func (c *HisApiController) GetBatchSettleAccounts() {
  314. order_ids := c.GetString("order_ids")
  315. admin_user_id, _ := c.GetInt64("admin_user_id")
  316. adminUser := c.GetAdminUserInfo()
  317. orders := strings.Split(order_ids, ",")
  318. var newOrders []models.Orders
  319. for _, item := range orders {
  320. order, _ := service.GetHisOrderByIDTenOne(item)
  321. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  322. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  323. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  324. orderInfos = append(orderInfos, orderInfos_two...)
  325. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  326. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  327. var diagnosis_ids []string
  328. if his.ID > 0 {
  329. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  330. } else {
  331. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  332. }
  333. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  334. var dia_config []*models.HisXtDiagnoseConfig
  335. var name string
  336. for _, item := range diagnosis_ids {
  337. id, _ := strconv.ParseInt(item, 10, 64)
  338. diagnosisConfig, _ := service.FindDiagnoseById(id)
  339. dia_config = append(dia_config, diagnosisConfig)
  340. if len(name) == 0 {
  341. name = diagnosisConfig.ClassName
  342. } else {
  343. name = name + "," + diagnosisConfig.ClassName
  344. }
  345. }
  346. var bedCostTotal float64 = 0 //床位总费
  347. var bedCostSelfTotal float64 = 0 //床位自费
  348. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  349. var bedSelfTotal float64 = 0 //床位部分项目自费
  350. var bedInscpTotal float64 = 0 //床位部分项目自费
  351. var operationCostTotal float64 = 0 //手术费
  352. var operationCostSelfTotal float64 = 0 //手术费
  353. var operationCostPartSelfTotal float64 = 0 //手术费
  354. var operationSelfTotal float64 = 0 //床位部分项目自费
  355. var operationInscpTotal float64 = 0 //床位部分项目自费
  356. var otherCostTotal float64 = 0 //其他费用
  357. var otherCostSelfTotal float64 = 0 //其他费用
  358. var otherCostPartSelfTotal float64 = 0 //其他费用
  359. var otherSelfTotal float64 = 0 //床位部分项目自费
  360. var otherInscpTotal float64 = 0 //床位部分项目自费
  361. var materialCostTotal float64 = 0 //材料费
  362. var materialCostSelfTotal float64 = 0 //材料费
  363. var materialCostPartSelfTotal float64 = 0 //材料费
  364. var materialSelfTotal float64 = 0 //床位部分项目自费
  365. var materialInscpTotal float64 = 0 //床位部分项目自费
  366. var westernMedicineCostTotal float64 = 0 //西药费
  367. var westernMedicineCostSelfTotal float64 = 0 //西药费
  368. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  369. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  370. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  371. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  372. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  373. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  374. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  375. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  376. var checkCostTotal float64 = 0 //检查费
  377. var checkCostSelfTotal float64 = 0 //检查费
  378. var checkCostPartSelfTotal float64 = 0 //检查费
  379. var checkSelfTotal float64 = 0 //床位部分项目自费
  380. var checkInscpTotal float64 = 0 //床位部分项目自费
  381. var laboratoryCostTotal float64 = 0 //化验费
  382. var laboratoryCostSelfTotal float64 = 0 //化验费
  383. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  384. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  385. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  386. var treatCostTotal float64 = 0 //治疗费用
  387. var treatCostSelfTotal float64 = 0 //治疗费用
  388. var treatCostPartSelfTotal float64 = 0 //治疗费用
  389. var treatSelfTotal float64 = 0 //床位部分项目自费
  390. var treatInscpTotal float64 = 0 //床位部分项目自费
  391. decimal.DivisionPrecision = 2
  392. for _, item := range orderInfos {
  393. if item.MedChrgitmType == "01" { //床位费
  394. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  395. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  396. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  397. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  398. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  399. }
  400. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  401. if item.MedChrgitmType == "03" { //检查费
  402. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  403. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  404. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  405. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  406. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  407. }
  408. } else {
  409. if item.MedChrgitmType == "03" { //检查费
  410. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  411. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  412. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  413. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  414. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  415. }
  416. }
  417. if item.MedChrgitmType == "04" { //化验费
  418. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  419. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  420. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  421. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  422. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  423. }
  424. if item.MedChrgitmType == "05" { //治疗费
  425. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  426. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  427. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  428. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  429. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  430. }
  431. if item.MedChrgitmType == "06" { //手术费
  432. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  433. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  434. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  435. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  436. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  437. }
  438. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  439. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  440. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  441. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  442. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  443. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  444. }
  445. if item.MedChrgitmType == "09" { //西药费
  446. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  447. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  448. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  449. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  450. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  451. }
  452. if item.MedChrgitmType == "11" { //中成费
  453. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  454. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  455. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  456. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  457. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  458. }
  459. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  461. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  462. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  463. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  464. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  465. }
  466. }
  467. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  468. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  470. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  471. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  472. var doctor_name string
  473. if roles.ID == 0 {
  474. doctor_name = "管理员"
  475. } else {
  476. doctor_name = roles.UserName
  477. }
  478. yiliao_leibie := ""
  479. switch order.MedType {
  480. case "11":
  481. yiliao_leibie = "普通门诊"
  482. break
  483. case "12":
  484. yiliao_leibie = "门诊挂号"
  485. break
  486. case "13":
  487. yiliao_leibie = "急诊"
  488. break
  489. case "14":
  490. yiliao_leibie = "门诊特殊病"
  491. break
  492. case "15":
  493. yiliao_leibie = "门诊统筹"
  494. break
  495. case "16":
  496. yiliao_leibie = "门诊慢性病"
  497. break
  498. case "21":
  499. yiliao_leibie = "普通住院"
  500. break
  501. }
  502. var newOrder models.Orders
  503. newOrder.Diagnosis = name
  504. newOrder.OrderInfos = orderInfos
  505. newOrder.Number = order.MdtrtId
  506. newOrder.Date = order.SettleAccountsDate
  507. newOrder.ChargeAdmin = charge_admin
  508. newOrder.PrintorAdmin = printor_admin
  509. newOrder.Order = order
  510. newOrder.BedCostTotal = bedCostTotal
  511. newOrder.BedCostSelfTotal = bedCostSelfTotal
  512. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  513. newOrder.BedSelfTotal = bedSelfTotal
  514. newOrder.BedInscpTotal = bedInscpTotal
  515. newOrder.OperationCostTotal = operationCostTotal
  516. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  517. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  518. newOrder.OperationSelfTotal = operationSelfTotal
  519. newOrder.OperationInscpTotal = operationInscpTotal
  520. newOrder.OtherCostTotal = otherCostTotal
  521. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  522. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  523. newOrder.OtherSelfTotal = otherSelfTotal
  524. newOrder.OtherInscpTotal = otherInscpTotal
  525. newOrder.MaterialCostTotal = materialCostTotal
  526. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  527. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  528. newOrder.MaterialSelfTotal = materialSelfTotal
  529. newOrder.MaterialInscpTotal = materialInscpTotal
  530. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  531. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  532. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  533. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  534. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  535. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  536. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  537. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  538. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  539. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  540. newOrder.CheckCostTotal = checkCostTotal
  541. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  542. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  543. newOrder.CheckSelfTotal = checkSelfTotal
  544. newOrder.CheckInscpTotal = checkInscpTotal
  545. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  546. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  547. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  548. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  549. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  550. newOrder.TreatCostTotal = treatCostTotal
  551. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  552. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  553. newOrder.TreatSelfTotal = treatSelfTotal
  554. newOrder.TreatInscpTotal = treatInscpTotal
  555. newOrder.DoctorInfo = doctor_info
  556. newOrder.DoctorName = doctor_name
  557. newOrder.HealthCardNo = order.PsnNo
  558. newOrder.YiliaoLeibie = yiliao_leibie
  559. newOrder.Patient = patient
  560. newOrder.OrgName = miConfig.OrgName
  561. newOrder.OrgCode = miConfig.Code
  562. newOrder.OrderNumber = order.Number
  563. newOrder.HisPatient = his
  564. newOrder.DiaConfig = dia_config
  565. newOrders = append(newOrders, newOrder)
  566. }
  567. c.ServeSuccessJSON(map[string]interface{}{
  568. "orders": newOrders,
  569. })
  570. }
  571. func (c *HisApiController) GetTestOrder() {
  572. order_id, _ := c.GetInt64("order_id")
  573. admin_user_id, _ := c.GetInt64("admin_user_id")
  574. adminUser := c.GetAdminUserInfo()
  575. order, _ := service.GetHisOrderByID(order_id)
  576. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  577. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  578. orderInfos = append(orderInfos, orderInfos_two...)
  579. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  580. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  581. var dia_config []*models.HisXtDiagnoseConfig
  582. var name string
  583. var bedCostTotal float64 = 0 //床位总费
  584. var bedCostSelfTotal float64 = 0 //床位自费
  585. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  586. var bedSelfTotal float64 = 0 //床位部分项目自费
  587. var bedInscpTotal float64 = 0 //床位部分项目自费
  588. var operationCostTotal float64 = 0 //手术费
  589. var operationCostSelfTotal float64 = 0 //手术费
  590. var operationCostPartSelfTotal float64 = 0 //手术费
  591. var operationSelfTotal float64 = 0 //床位部分项目自费
  592. var operationInscpTotal float64 = 0 //床位部分项目自费
  593. var otherCostTotal float64 = 0 //其他费用
  594. var otherCostSelfTotal float64 = 0 //其他费用
  595. var otherCostPartSelfTotal float64 = 0 //其他费用
  596. var otherSelfTotal float64 = 0 //床位部分项目自费
  597. var otherInscpTotal float64 = 0 //床位部分项目自费
  598. var materialCostTotal float64 = 0 //材料费
  599. var materialCostSelfTotal float64 = 0 //材料费
  600. var materialCostPartSelfTotal float64 = 0 //材料费
  601. var materialSelfTotal float64 = 0 //床位部分项目自费
  602. var materialInscpTotal float64 = 0 //床位部分项目自费
  603. var westernMedicineCostTotal float64 = 0 //西药费
  604. var westernMedicineCostSelfTotal float64 = 0 //西药费
  605. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  606. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  607. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  608. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  609. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  610. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  611. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  612. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  613. var checkCostTotal float64 = 0 //检查费
  614. var checkCostSelfTotal float64 = 0 //检查费
  615. var checkCostPartSelfTotal float64 = 0 //检查费
  616. var checkSelfTotal float64 = 0 //床位部分项目自费
  617. var checkInscpTotal float64 = 0 //床位部分项目自费
  618. var laboratoryCostTotal float64 = 0 //化验费
  619. var laboratoryCostSelfTotal float64 = 0 //化验费
  620. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  621. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  622. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  623. var treatCostTotal float64 = 0 //治疗费用
  624. var treatCostSelfTotal float64 = 0 //治疗费用
  625. var treatCostPartSelfTotal float64 = 0 //治疗费用
  626. var treatSelfTotal float64 = 0 //床位部分项目自费
  627. var treatInscpTotal float64 = 0 //床位部分项目自费
  628. decimal.DivisionPrecision = 2
  629. for _, item := range orderInfos {
  630. if item.MedChrgitmType == "01" { //床位费
  631. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  632. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  633. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  634. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  635. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  636. }
  637. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  638. if item.MedChrgitmType == "03" { //检查费
  639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  640. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  641. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  642. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  643. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  644. }
  645. } else {
  646. if item.MedChrgitmType == "03" { //检查费
  647. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  648. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  649. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  650. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  651. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  652. }
  653. }
  654. if item.MedChrgitmType == "04" { //化验费
  655. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  656. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  657. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  658. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  659. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  660. }
  661. if item.MedChrgitmType == "05" { //治疗费
  662. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  663. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  664. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  665. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  666. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  667. }
  668. if item.MedChrgitmType == "06" { //手术费
  669. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  670. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  671. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  672. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  673. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  674. }
  675. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  676. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  677. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  678. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  679. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  680. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  681. }
  682. if item.MedChrgitmType == "09" { //西药费
  683. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  684. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  685. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  686. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  687. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  688. }
  689. if item.MedChrgitmType == "11" { //中成费
  690. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  691. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  692. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  693. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  694. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  695. }
  696. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  698. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  699. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  700. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  701. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  702. }
  703. }
  704. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  705. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  707. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  708. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  709. var doctor_name string
  710. if roles.ID == 0 {
  711. doctor_name = "管理员"
  712. } else {
  713. doctor_name = roles.UserName
  714. }
  715. yiliao_leibie := ""
  716. switch order.MedType {
  717. case "11":
  718. yiliao_leibie = "普通门诊"
  719. break
  720. case "12":
  721. yiliao_leibie = "门诊挂号"
  722. break
  723. case "13":
  724. yiliao_leibie = "急诊"
  725. break
  726. case "14":
  727. yiliao_leibie = "门诊特殊病"
  728. break
  729. case "15":
  730. yiliao_leibie = "门诊统筹"
  731. break
  732. case "16":
  733. yiliao_leibie = "门诊慢性病"
  734. break
  735. case "21":
  736. yiliao_leibie = "普通住院"
  737. break
  738. }
  739. c.ServeSuccessJSON(map[string]interface{}{
  740. "diagnosis": name,
  741. "order_infos": orderInfos,
  742. "number": order.MdtrtId,
  743. "date": order.SettleAccountsDate,
  744. "charge_admin": charge_admin,
  745. "printor_admin": printor_admin,
  746. "info": order,
  747. "order": order,
  748. "bedCostTotal": bedCostTotal,
  749. "bedCostSelfTotal": bedCostSelfTotal,
  750. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  751. "bedSelfTotal": bedSelfTotal,
  752. "bedInscpTotal": bedInscpTotal,
  753. "operationCostTotal": operationCostTotal,
  754. "operationCostSelfTotal": operationCostSelfTotal,
  755. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  756. "operationSelfTotal": operationSelfTotal,
  757. "operationInscpTotal": operationInscpTotal,
  758. "otherCostTotal": otherCostTotal,
  759. "otherCostSelfTotal": otherCostSelfTotal,
  760. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  761. "otherSelfTotal": otherSelfTotal,
  762. "otherInscpTotal": otherInscpTotal,
  763. "materialCostTotal": materialCostTotal,
  764. "materialCostSelfTotal": materialCostSelfTotal,
  765. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  766. "materialSelfTotal": materialSelfTotal,
  767. "materialInscpTotal": materialInscpTotal,
  768. "westernMedicineCostTotal": westernMedicineCostTotal,
  769. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  770. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  771. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  772. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  773. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  774. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  775. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  776. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  777. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  778. "checkCostTotal": checkCostTotal,
  779. "checkCostSelfTotal": checkCostSelfTotal,
  780. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  781. "checkSelfTotal": checkSelfTotal,
  782. "checkInscpTotal": checkInscpTotal,
  783. "laboratoryCostTotal": laboratoryCostTotal,
  784. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  785. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  786. "laboratorySelfTotal": laboratorySelfTotal,
  787. "laboratoryInscpTotal": laboratoryInscpTotal,
  788. "treatCostTotal": treatCostTotal,
  789. "treatCostSelfTotal": treatCostSelfTotal,
  790. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  791. "treatSelfTotal": treatSelfTotal,
  792. "treatInscpTotal": treatInscpTotal,
  793. "doctor_info": doctor_info,
  794. "doctor_name": doctor_name,
  795. "health_card_no": order.PsnNo,
  796. "yiliao_leibie": yiliao_leibie,
  797. "patient": patient,
  798. "org_name": miConfig.OrgName,
  799. "org_code": miConfig.Code,
  800. "order_number": order.Number,
  801. "his_hospital": his_hospital,
  802. "dia_config": dia_config,
  803. })
  804. }
  805. type CustomFundPay struct {
  806. FundPayType string `json:"fund_pay_type"`
  807. FundPayamt float64 `json:"fund_payamt"`
  808. InscpScpAmt float64 `json:"inscp_scp_amt"`
  809. }
  810. func (c *PublicApiController) GetBaiLinExportData() {
  811. data := service.GetBaiLinOrderData()
  812. fmt.Println(len(data))
  813. var new_data []*models.NewCustomHisOrder
  814. for _, item := range data {
  815. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  816. new_data = append(new_data, item)
  817. }
  818. }
  819. fmt.Println(len(new_data))
  820. c.ServeSuccessJSON(map[string]interface{}{
  821. "list": new_data,
  822. })
  823. }
  824. func (c *HisApiController) GetHisUnChargePatientList() {
  825. record_date := c.GetString("record_date")
  826. sch_type, _ := c.GetInt64("sch_type")
  827. timeLayout := "2006-01-02"
  828. loc, _ := time.LoadLocation("Local")
  829. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  830. if err != nil {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. recordDateTime := theTime.Unix()
  835. adminInfo := c.GetAdminUserInfo()
  836. var tempPatients []*service.NewTempPatients
  837. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  838. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  839. var patients []*service.NewTempPatients
  840. var patients_two []*service.NewTempPatients
  841. for _, item := range tempPatients {
  842. //过滤掉没挂号的和没开处方的
  843. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  844. patients = append(patients, item)
  845. }
  846. //过滤掉没挂号的
  847. if len(item.HisPatient) > 0 {
  848. patients_two = append(patients_two, item)
  849. }
  850. }
  851. c.ServeSuccessJSON(map[string]interface{}{
  852. "list": patients,
  853. "list_two": patients_two,
  854. })
  855. }
  856. func (c *HisApiController) GetPrivateExpensesOrder() {
  857. //id, _ := c.GetInt64("id")
  858. //record_time := c.GetString("record_time")
  859. order_id, _ := c.GetInt64("order_id")
  860. admin_user_id, _ := c.GetInt64("admin_user_id")
  861. //timeLayout := "2006-01-02"
  862. //loc, _ := time.LoadLocation("Local")
  863. //
  864. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  865. //if err != nil {
  866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. // return
  868. //}
  869. //recordDateTime := theTime.Unix()
  870. adminUser := c.GetAdminUserInfo()
  871. order, _ := service.GetHisOrderByID(order_id)
  872. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  873. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  874. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  875. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  876. //var config []*models.HisXtDiagnoseConfig
  877. var name string
  878. if order.PType == 1 {
  879. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  880. for _, item := range diagnosis_ids {
  881. id, _ := strconv.ParseInt(item, 10, 64)
  882. diagnosisConfig, _ := service.FindDiagnoseById(id)
  883. if len(name) == 0 {
  884. name = diagnosisConfig.ClassName
  885. } else {
  886. name = name + "," + diagnosisConfig.ClassName
  887. }
  888. }
  889. } else {
  890. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  891. for _, item := range diagnosis_ids {
  892. id, _ := strconv.ParseInt(item, 10, 64)
  893. diagnosisConfig, _ := service.FindDiagnoseById(id)
  894. if len(name) == 0 {
  895. name = diagnosisConfig.ClassName
  896. } else {
  897. name = name + "," + diagnosisConfig.ClassName
  898. }
  899. }
  900. }
  901. var bedCostTotal float64 = 0 //床位总费
  902. var bedCostSelfTotal float64 = 0 //床位自费
  903. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  904. var bedSelfTotal float64 = 0 //床位部分项目自费
  905. var bedInscpTotal float64 = 0 //床位部分项目自费
  906. var operationCostTotal float64 = 0 //手术费
  907. var operationCostSelfTotal float64 = 0 //手术费
  908. var operationCostPartSelfTotal float64 = 0 //手术费
  909. var operationSelfTotal float64 = 0 //床位部分项目自费
  910. var operationInscpTotal float64 = 0 //床位部分项目自费
  911. var otherCostTotal float64 = 0 //其他费用
  912. //var otherCostSelfTotal float64 = 0 //其他费用
  913. var otherCostPartSelfTotal float64 = 0 //其他费用
  914. //var otherSelfTotal float64 = 0 //床位部分项目自费
  915. //var otherInscpTotal float64 = 0 //床位部分项目自费
  916. var materialCostTotal float64 = 0 //材料费
  917. var materialCostSelfTotal float64 = 0 //材料费
  918. var materialCostPartSelfTotal float64 = 0 //材料费
  919. var materialSelfTotal float64 = 0 //床位部分项目自费
  920. var materialInscpTotal float64 = 0 //床位部分项目自费
  921. var westernMedicineCostTotal float64 = 0 //西药费
  922. var westernMedicineCostSelfTotal float64 = 0 //西药费
  923. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  924. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  925. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  926. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  927. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  928. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  929. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  930. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  931. var checkCostTotal float64 = 0 //检查费
  932. var checkCostSelfTotal float64 = 0 //检查费
  933. var checkCostPartSelfTotal float64 = 0 //检查费
  934. var checkSelfTotal float64 = 0 //床位部分项目自费
  935. var checkInscpTotal float64 = 0 //床位部分项目自费
  936. var laboratoryCostTotal float64 = 0 //化验费
  937. var laboratoryCostSelfTotal float64 = 0 //化验费
  938. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  939. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  940. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  941. var treatCostTotal float64 = 0 //治疗费用
  942. var treatCostSelfTotal float64 = 0 //治疗费用
  943. var treatCostPartSelfTotal float64 = 0 //治疗费用
  944. var treatSelfTotal float64 = 0 //床位部分项目自费
  945. var treatInscpTotal float64 = 0 //床位部分项目自费
  946. var zhenChaCostTotal float64 = 0 //其他费用
  947. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  948. decimal.DivisionPrecision = 2
  949. for _, item := range orderInfos {
  950. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  951. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  952. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  953. item.MedChrgitmType = "09"
  954. }
  955. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  956. if item.HisPrescriptionProject.Type == 2 {
  957. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  958. fmt.Println("CostClassify")
  959. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  960. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  961. case 0:
  962. item.MedChrgitmType = "0"
  963. break
  964. case 1:
  965. item.MedChrgitmType = "14"
  966. break
  967. case 2:
  968. item.MedChrgitmType = "05"
  969. break
  970. case 3:
  971. item.MedChrgitmType = "03"
  972. break
  973. case 4:
  974. item.MedChrgitmType = "03"
  975. break
  976. case 5:
  977. item.MedChrgitmType = "08"
  978. break
  979. case 6:
  980. item.MedChrgitmType = "14"
  981. break
  982. case 7:
  983. item.MedChrgitmType = "14"
  984. break
  985. case 8:
  986. item.MedChrgitmType = "03"
  987. break
  988. case 9:
  989. item.MedChrgitmType = "14"
  990. break
  991. case 10:
  992. item.MedChrgitmType = "14"
  993. break
  994. case 11:
  995. item.MedChrgitmType = "06"
  996. break
  997. case 12:
  998. item.MedChrgitmType = "12"
  999. break
  1000. case 13:
  1001. item.MedChrgitmType = "01"
  1002. break
  1003. case 14:
  1004. item.MedChrgitmType = "04"
  1005. break
  1006. case 15:
  1007. item.MedChrgitmType = "14"
  1008. break
  1009. }
  1010. } else {
  1011. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1012. case 1:
  1013. item.MedChrgitmType = "14"
  1014. break
  1015. case 2:
  1016. item.MedChrgitmType = "05"
  1017. break
  1018. case 3:
  1019. item.MedChrgitmType = "04"
  1020. break
  1021. case 4:
  1022. item.MedChrgitmType = "14"
  1023. break
  1024. case 5:
  1025. item.MedChrgitmType = "08"
  1026. break
  1027. case 6:
  1028. item.MedChrgitmType = "14"
  1029. break
  1030. case 7:
  1031. item.MedChrgitmType = "14"
  1032. break
  1033. case 8:
  1034. item.MedChrgitmType = "03"
  1035. break
  1036. case 9:
  1037. item.MedChrgitmType = "14"
  1038. break
  1039. default:
  1040. item.MedChrgitmType = "14"
  1041. break
  1042. }
  1043. }
  1044. } else if item.HisPrescriptionProject.Type == 3 {
  1045. item.MedChrgitmType = "08"
  1046. }
  1047. }
  1048. }
  1049. }
  1050. if order.IsMedicineInsurance != 1 {
  1051. order.PsnCashPay = order.MedfeeSumamt
  1052. }
  1053. for _, item := range orderInfos {
  1054. if item.MedChrgitmType == "01" { //床位费
  1055. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1059. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "02" { //诊察费
  1062. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //zhenChaCostSelfTotal = zhenChaCostTotal
  1064. }
  1065. if item.MedChrgitmType == "03" { //检查费
  1066. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1070. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1071. }
  1072. if item.MedChrgitmType == "02" { //检查费
  1073. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1074. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1075. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1076. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1077. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1078. }
  1079. if item.MedChrgitmType == "04" { //化验费
  1080. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1081. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1082. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1083. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1084. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1085. }
  1086. if item.MedChrgitmType == "05" { //治疗费
  1087. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1088. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1089. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1090. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1091. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1092. }
  1093. if item.MedChrgitmType == "06" { //手术费
  1094. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1095. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1096. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1097. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1098. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1099. }
  1100. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1101. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1102. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1103. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1104. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1105. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1106. }
  1107. if item.MedChrgitmType == "09" { //西药费
  1108. fmt.Println("FulamtOwnpayAmt")
  1109. fmt.Println(item.FulamtOwnpayAmt)
  1110. fmt.Println("FulamtOwnpayAmt")
  1111. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1112. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1113. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1114. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1115. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1116. }
  1117. if item.MedChrgitmType == "11" { //中成费
  1118. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1119. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1120. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1121. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1122. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1123. }
  1124. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1125. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1126. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1127. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1128. }
  1129. }
  1130. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1131. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1132. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1133. var dia_config []*models.HisXtDiagnoseConfig
  1134. var diagnosis_ids []string
  1135. if his.ID > 0 {
  1136. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1137. } else {
  1138. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1139. }
  1140. for _, item := range diagnosis_ids {
  1141. id, _ := strconv.ParseInt(item, 10, 64)
  1142. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1143. dia_config = append(dia_config, diagnosisConfig)
  1144. }
  1145. var rf []CustomFundPay
  1146. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1147. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "patient": patient,
  1150. "order_infos": orderInfos,
  1151. "diagnosis": name,
  1152. "bedCostTotal": bedCostTotal,
  1153. "bedCostSelfTotal": bedCostSelfTotal,
  1154. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1155. "bedSelfTotal": bedSelfTotal,
  1156. "bedInscpTotal": bedInscpTotal,
  1157. "operationCostTotal": operationCostTotal,
  1158. "operationCostSelfTotal": operationCostSelfTotal,
  1159. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1160. "operationInscpTotal": operationInscpTotal,
  1161. "operationSelfTotal": operationSelfTotal,
  1162. "otherCostTotal": otherCostTotal,
  1163. //"otherCostSelfTotal": otherCostSelfTotal,
  1164. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1165. "materialCostTotal": materialCostTotal,
  1166. "materialCostSelfTotal": materialCostSelfTotal,
  1167. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1168. "materialSelfTotal": materialSelfTotal,
  1169. "materialInscpTotal": materialInscpTotal,
  1170. "westernMedicineCostTotal": westernMedicineCostTotal,
  1171. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1172. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1173. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1174. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1175. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1176. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1177. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1178. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1179. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1180. "checkCostTotal": checkCostTotal,
  1181. "checkCostSelfTotal": checkCostSelfTotal,
  1182. "checkSelfTotal": checkSelfTotal,
  1183. "checkInscpTotal": checkInscpTotal,
  1184. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1185. "zhenChaCostTotal": zhenChaCostTotal,
  1186. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1187. "laboratoryCostTotal": laboratoryCostTotal,
  1188. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1189. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1190. "laboratorySelfTotal": laboratorySelfTotal,
  1191. "laboratoryInscpTotal": laboratoryInscpTotal,
  1192. "treatCostTotal": treatCostTotal,
  1193. "treatCostSelfTotal": treatCostSelfTotal,
  1194. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1195. "treatSelfTotal": treatSelfTotal,
  1196. "treatInscpTotal": treatInscpTotal,
  1197. "charge_admin": charge_admin,
  1198. "printor_admin": printor_admin,
  1199. "org_name": org.OrgName,
  1200. "org_code": miConfig.Code,
  1201. "name": patient.Name,
  1202. "number": order.MdtrtId,
  1203. "date": order.SettleAccountsDate,
  1204. "info": order,
  1205. "new_order": order,
  1206. "his_hospital": his_hospital,
  1207. "his": his,
  1208. "funds": rf,
  1209. "dia_config": dia_config,
  1210. })
  1211. }
  1212. func (c *HisApiController) RefudDetail() {
  1213. order_id, _ := c.GetInt64("order_id")
  1214. order, _ := service.GetHisOrderByID(order_id)
  1215. adminUser := c.GetAdminUserInfo()
  1216. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1217. c.ServeSuccessJSON(map[string]interface{}{
  1218. "msg": "撤销成功",
  1219. })
  1220. }
  1221. func (c *HisApiController) Sscard() {
  1222. //r := CardInit()
  1223. //if r == 0 {
  1224. // GetBaseInfo()
  1225. //}
  1226. //c.ServeSuccessJSON(map[string]interface{}{
  1227. // "list": "11",
  1228. //})
  1229. }
  1230. func GetBaseInfo() error {
  1231. //handle := syscall.MustLoadDLL("SSCard.dll")
  1232. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1233. //
  1234. //str := make([]byte, 256)
  1235. //str1 := make([]byte, 256)
  1236. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1237. //if ferr != nil {
  1238. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1239. // return ferr
  1240. //}
  1241. //
  1242. //fmt.Println(string(str))
  1243. //
  1244. //fmt.Println(r)
  1245. return nil
  1246. }
  1247. func CardInit() int {
  1248. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1249. //add := DllTestDef.MustFindProc("Init")
  1250. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1251. //if err != nil {
  1252. // fmt.Println("SSCard的运算结果为:", ret)
  1253. //}
  1254. //result := int(ret)
  1255. return 0
  1256. }
  1257. func IntPtr(n int) uintptr {
  1258. return uintptr(n)
  1259. }
  1260. func StrPtr(s string) uintptr {
  1261. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1262. }
  1263. func (c *HisApiController) GetHisPatientList() {
  1264. record_date := c.GetString("record_date")
  1265. sch_type, _ := c.GetInt64("sch_type")
  1266. patient_type, _ := c.GetInt64("patient_type")
  1267. fmt.Println("patient_type")
  1268. fmt.Println(patient_type)
  1269. timeLayout := "2006-01-02"
  1270. loc, _ := time.LoadLocation("Local")
  1271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1272. if err != nil {
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1274. return
  1275. }
  1276. recordDateTime := theTime.Unix()
  1277. adminInfo := c.GetAdminUserInfo()
  1278. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1279. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1280. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1281. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1282. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1283. fmt.Println(patients_three)
  1284. //获取当前用户的信息
  1285. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1286. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1287. //获取所有科室信息
  1288. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1289. //var aa []service.PatientThree
  1290. noElementsSlice := make([]service.PatientThree, 0)
  1291. c.ServeSuccessJSON(map[string]interface{}{
  1292. "list": patients_three,
  1293. "list_two": patients_four,
  1294. "list_three": noElementsSlice,
  1295. "info": adminUserInfo,
  1296. "doctors": doctors,
  1297. "department": department,
  1298. })
  1299. } else {
  1300. //获取当前用户的信息
  1301. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1302. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1303. //获取所有科室信息
  1304. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1305. //var aa []service.PatientThree
  1306. noElementsSlice := make([]service.PatientThree, 0)
  1307. c.ServeSuccessJSON(map[string]interface{}{
  1308. "list": patients,
  1309. "list_two": patients_two,
  1310. "list_three": noElementsSlice,
  1311. "info": adminUserInfo,
  1312. "doctors": doctors,
  1313. "department": department,
  1314. })
  1315. }
  1316. }
  1317. type CustomTemplate struct {
  1318. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1319. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1320. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1321. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1322. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1323. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1324. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1325. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1326. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1327. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1328. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1329. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1330. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1331. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1332. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1333. }
  1334. func (c *HisApiController) GetHisPatientInfo() {
  1335. patient_id, _ := c.GetInt64("patient_id")
  1336. his_patient_id, _ := c.GetInt64("his_patient_id")
  1337. record_date := c.GetString("record_date")
  1338. number := c.GetString("number")
  1339. //start_time := c.GetString("start_time")
  1340. //end_time := c.GetString("end_time")
  1341. p_type, _ := c.GetInt64("p_type")
  1342. timeLayout := "2006-01-02"
  1343. loc, _ := time.LoadLocation("Local")
  1344. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1345. if err != nil {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1347. return
  1348. }
  1349. recordDateTime := theTime.Unix()
  1350. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1351. //if err != nil {
  1352. //
  1353. //}
  1354. //startRecordDateTime := startTime.Unix()
  1355. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1356. //if err != nil {
  1357. //
  1358. //}
  1359. //endRecordDateTime := endTime.Unix()
  1360. admin := c.GetAdminUserInfo()
  1361. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1362. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1363. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1364. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1365. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1366. var prescriptions []*models.HisPrescription
  1367. var last_prescriptions []*models.HisPrescription
  1368. var sch_prescriptions []CustomTemplate
  1369. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1370. if p_type == 1 { //住院
  1371. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1372. for _, item := range prescriptions {
  1373. for _, subItem := range item.HisDoctorAdviceInfo {
  1374. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1375. if info.RetailPrice > 0 {
  1376. subItem.Drug.MinPrice = info.RetailPrice
  1377. }
  1378. }
  1379. }
  1380. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1381. } else { //门诊
  1382. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1383. for _, item := range prescriptions {
  1384. for _, subItem := range item.HisDoctorAdviceInfo {
  1385. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1386. if info.RetailPrice > 0 {
  1387. subItem.Drug.MinPrice = info.RetailPrice
  1388. }
  1389. }
  1390. }
  1391. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1392. }
  1393. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1394. if sch.ID > 0 {
  1395. var week string
  1396. t := time.Now()
  1397. switch t.Weekday().String() {
  1398. case "Monday":
  1399. week = "周一"
  1400. break
  1401. case "Tuesday":
  1402. week = "周二"
  1403. break
  1404. case "Wednesday":
  1405. week = "周三"
  1406. break
  1407. case "Thursday":
  1408. week = "周四"
  1409. break
  1410. case "Friday":
  1411. week = "周五"
  1412. break
  1413. case "Saturday":
  1414. week = "周六"
  1415. break
  1416. case "Sunday":
  1417. week = "周日"
  1418. break
  1419. }
  1420. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1421. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1422. //根据推送频率组装新的数组
  1423. for _, item := range temp_sch_prescriptions {
  1424. var cus CustomTemplate
  1425. cus.ID = item.ID
  1426. cus.UserOrgId = item.UserOrgId
  1427. cus.PatientId = item.PatientId
  1428. cus.MedType = item.MedType
  1429. cus.RecordDate = item.RecordDate
  1430. cus.Type = item.Type
  1431. cus.PType = item.PType
  1432. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1433. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1434. if subItem.FrequencyType == 1 { //每次必推
  1435. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1436. }
  1437. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1438. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1439. }
  1440. if subItem.FrequencyType == 2 { //按照天数频率
  1441. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1442. now := p.Unix()
  1443. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1444. dayStr2 := "-" + dayStr
  1445. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1446. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1447. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1448. if len(advices) == 0 {
  1449. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1450. }
  1451. }
  1452. }
  1453. }
  1454. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1455. if subItem.Type == 2 {
  1456. if subItem.XtHisProject.MedicalStatus != 1 {
  1457. if subItem.FrequencyType == 1 {
  1458. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1459. }
  1460. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1461. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1462. }
  1463. if subItem.FrequencyType == 2 {
  1464. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1465. now := p.Unix()
  1466. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1467. dayStr2 := "-" + dayStr
  1468. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1469. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1470. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1471. if len(projects) == 0 {
  1472. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1473. }
  1474. }
  1475. }
  1476. } else if subItem.Type == 3 {
  1477. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1478. if subItem.FrequencyType == 1 {
  1479. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1480. }
  1481. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1482. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1483. }
  1484. if subItem.FrequencyType == 2 {
  1485. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1486. now := p.Unix()
  1487. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1488. dayStr2 := "-" + dayStr
  1489. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1490. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1491. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1492. if len(projects) == 0 {
  1493. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1494. }
  1495. }
  1496. }
  1497. }
  1498. }
  1499. sch_prescriptions = append(sch_prescriptions, cus)
  1500. }
  1501. for _, item := range sch_prescriptions {
  1502. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1503. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1504. }
  1505. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1506. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1507. }
  1508. }
  1509. }
  1510. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1511. if config.ID > 0 && config.IsOpen == 1 {
  1512. for _, item := range sch_prescriptions {
  1513. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1514. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1515. if info.RetailPrice > 0 {
  1516. subItem.Drug.MinPrice = info.RetailPrice
  1517. if admin.CurrentOrgId != 10598 {
  1518. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1519. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1520. }
  1521. }
  1522. }
  1523. }
  1524. }
  1525. if config.ID > 0 && config.IsOpen == 1 {
  1526. for _, item := range sch_prescriptions {
  1527. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1528. if subItem.Type == 3 {
  1529. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1530. if info.Price > 0 {
  1531. subItem.GoodInfo.PackingPrice = info.Price
  1532. if admin.CurrentOrgId != 10598 {
  1533. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1534. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1535. }
  1536. }
  1537. }
  1538. }
  1539. }
  1540. }
  1541. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1542. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1543. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1544. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1545. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1546. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1547. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1548. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1551. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1552. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1553. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1554. fmt.Println(prescriptions)
  1555. fmt.Println(sch_prescriptions)
  1556. fmt.Println(last_prescriptions)
  1557. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1558. if len(sch_prescriptions) > 0 {
  1559. var index = 0
  1560. for subindex, item := range sch_prescriptions {
  1561. if item.Type == 2 {
  1562. index = subindex
  1563. }
  1564. }
  1565. fmt.Println(index)
  1566. fmt.Println(len(sch_prescriptions))
  1567. if index >= 0 && index < len(sch_prescriptions) {
  1568. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1569. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1570. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1571. if one.ID > 0 {
  1572. var hpt models.HisPrescriptionProjectTemplate
  1573. hpt.Type = 3
  1574. hpt.ID = 0
  1575. hpt.PatientId = sch_prescriptions[index].PatientId
  1576. hpt.Status = 1
  1577. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1578. hpt.Mtime = time.Now().Unix()
  1579. hpt.Ctime = time.Now().Unix()
  1580. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1581. hpt.Count = "1"
  1582. hpt.Price = one.RetailPrice
  1583. hpt.ProjectId = one.ID
  1584. hpt.FeedetlSn = ""
  1585. hpt.PrescriptionId = sch_prescriptions[index].ID
  1586. hpt.Unit = one.PackingUnit
  1587. hpt.Day = "1"
  1588. hpt.SingleDose = "1"
  1589. hpt.GoodInfo = one
  1590. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1591. }
  1592. if two.ID > 0 {
  1593. var hpt models.HisPrescriptionProjectTemplate
  1594. hpt.Type = 3
  1595. hpt.ID = 0
  1596. hpt.PatientId = sch_prescriptions[index].PatientId
  1597. hpt.Status = 1
  1598. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1599. hpt.Mtime = time.Now().Unix()
  1600. hpt.Ctime = time.Now().Unix()
  1601. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1602. hpt.Count = "1"
  1603. hpt.Price = two.RetailPrice
  1604. hpt.ProjectId = two.ID
  1605. hpt.FeedetlSn = ""
  1606. hpt.PrescriptionId = sch_prescriptions[index].ID
  1607. hpt.Unit = two.PackingUnit
  1608. hpt.Day = "1"
  1609. hpt.SingleDose = "1"
  1610. hpt.GoodInfo = two
  1611. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1612. }
  1613. //if three.ID > 0 {
  1614. // var hpt models.HisPrescriptionProjectTemplate
  1615. // hpt.Type = 3
  1616. // hpt.ID = 0
  1617. // hpt.PatientId = sch_prescriptions[index].PatientId
  1618. // hpt.Status = 1
  1619. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1620. // hpt.Mtime = time.Now().Unix()
  1621. // hpt.Ctime = time.Now().Unix()
  1622. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1623. // hpt.Count = "1"
  1624. // hpt.Price = three.RetailPrice
  1625. // hpt.ProjectId = three.ID
  1626. // hpt.FeedetlSn = ""
  1627. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1628. // hpt.Unit = three.PackingUnit
  1629. // hpt.Day = "1"
  1630. // hpt.SingleDose = "1"
  1631. // hpt.GoodInfo = three
  1632. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1633. //}
  1634. fmt.Println(sch_prescriptions)
  1635. }
  1636. } else {
  1637. if len(last_prescriptions) > 0 {
  1638. var index = 0
  1639. for subindex, item := range last_prescriptions {
  1640. if item.Type == 2 {
  1641. index = subindex
  1642. }
  1643. }
  1644. if index >= 0 && index < len(last_prescriptions) {
  1645. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1646. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1647. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1648. if one.ID > 0 {
  1649. var hpt models.HisPrescriptionProject
  1650. hpt.Type = 3
  1651. hpt.ID = 0
  1652. hpt.PatientId = last_prescriptions[index].PatientId
  1653. hpt.Status = 1
  1654. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1655. hpt.Mtime = time.Now().Unix()
  1656. hpt.Ctime = time.Now().Unix()
  1657. hpt.RecordDate = last_prescriptions[index].RecordDate
  1658. hpt.Count = "1"
  1659. hpt.Price = one.RetailPrice
  1660. hpt.ProjectId = one.ID
  1661. hpt.FeedetlSn = ""
  1662. hpt.PrescriptionId = last_prescriptions[index].ID
  1663. hpt.Unit = one.PackingUnit
  1664. hpt.Day = "1"
  1665. hpt.SingleDose = "1"
  1666. hpt.GoodInfo = one
  1667. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1668. }
  1669. if two.ID > 0 {
  1670. var hpt models.HisPrescriptionProject
  1671. hpt.Type = 3
  1672. hpt.ID = 0
  1673. hpt.PatientId = last_prescriptions[index].PatientId
  1674. hpt.Status = 1
  1675. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1676. hpt.Mtime = time.Now().Unix()
  1677. hpt.Ctime = time.Now().Unix()
  1678. hpt.RecordDate = last_prescriptions[index].RecordDate
  1679. hpt.Count = "1"
  1680. hpt.Price = two.RetailPrice
  1681. hpt.ProjectId = two.ID
  1682. hpt.FeedetlSn = ""
  1683. hpt.PrescriptionId = last_prescriptions[index].ID
  1684. hpt.Unit = two.PackingUnit
  1685. hpt.Day = "1"
  1686. hpt.SingleDose = "1"
  1687. hpt.GoodInfo = two
  1688. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1689. }
  1690. //if three.ID > 0 {
  1691. // var hpt models.HisPrescriptionProject
  1692. // hpt.Type = 3
  1693. // hpt.ID = 0
  1694. // hpt.PatientId = last_prescriptions[index].PatientId
  1695. // hpt.Status = 1
  1696. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1697. // hpt.Mtime = time.Now().Unix()
  1698. // hpt.Ctime = time.Now().Unix()
  1699. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1700. // hpt.Count = "1"
  1701. // hpt.Price = three.RetailPrice
  1702. // hpt.ProjectId = three.ID
  1703. // hpt.FeedetlSn = ""
  1704. // hpt.PrescriptionId = last_prescriptions[index].ID
  1705. // hpt.Unit = three.PackingUnit
  1706. // hpt.Day = "1"
  1707. // hpt.SingleDose = "1"
  1708. // hpt.GoodInfo = three
  1709. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1710. //}
  1711. }
  1712. }
  1713. }
  1714. }
  1715. c.ServeSuccessJSON(map[string]interface{}{
  1716. "his_info": his_patient_info,
  1717. "xt_info": xt_patient_info,
  1718. "prescription": prescriptions,
  1719. "case_history": case_history,
  1720. "info": patientPrescriptionInfo,
  1721. //"month_prescriptions": monthPrescriptions,
  1722. "order": order,
  1723. "doctors": doctors,
  1724. "department": department,
  1725. "sch_prescriptions": sch_prescriptions,
  1726. "last_prescriptions": last_prescriptions,
  1727. "schedule": sch,
  1728. "count": count,
  1729. "drugStockConfig": drugStockConfig,
  1730. "last_info": lastPatientPrescriptionInfo,
  1731. "befor": beforThrity,
  1732. "LastCaseHistory": LastCaseHistory,
  1733. "prescriptionInfo": prescriptionInfo,
  1734. })
  1735. return
  1736. }
  1737. func (c *HisApiController) GetHisPrescriptionConfig() {
  1738. adminInfo := c.GetAdminUserInfo()
  1739. //获取医嘱模版
  1740. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1741. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1742. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1743. //获取所有基础药
  1744. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1745. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1746. if config.ID > 0 && config.IsOpen == 1 {
  1747. for _, item := range drugs {
  1748. var index = 0
  1749. for _, subItem := range item.OtherDrugWarehouseInfo {
  1750. if index == 0 {
  1751. index = index + 1
  1752. if subItem.RetailPrice > 0 {
  1753. item.MinPrice = subItem.RetailPrice
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1760. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1761. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1762. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1763. //获取所有科室信息
  1764. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1765. //获取诊断信息
  1766. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1767. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1768. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1769. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1770. //获取是否开启保存耗材出库的开关
  1771. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1772. c.ServeSuccessJSON(map[string]interface{}{
  1773. "drugs": drugs,
  1774. "advices_template": advices,
  1775. "drugways": drugways,
  1776. "efs": efs,
  1777. "doctors": doctors,
  1778. "department": department,
  1779. "sick": sick,
  1780. "additions": additions,
  1781. "diagnose": diagnose,
  1782. "manufacturers": manufacturers,
  1783. "goodOutOpen": goodOutOpen,
  1784. "patientDiagnose": patientDiagnose,
  1785. })
  1786. }
  1787. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1788. //获取所有基础药
  1789. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1790. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1791. if config.ID > 0 && config.IsOpen == 1 {
  1792. for _, item := range drugs {
  1793. var index = 0
  1794. for _, subItem := range item.OtherDrugWarehouseInfo {
  1795. if index == 0 {
  1796. index = index + 1
  1797. if subItem.RetailPrice > 0 {
  1798. item.MinPrice = subItem.RetailPrice
  1799. }
  1800. }
  1801. }
  1802. }
  1803. }
  1804. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1805. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1806. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1807. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1808. //获取所有科室信息
  1809. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1810. //获取诊断信息
  1811. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1812. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1813. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1814. //获取是否开启保存耗材出库的开关
  1815. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1816. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1817. c.ServeSuccessJSON(map[string]interface{}{
  1818. "drugs": drugs,
  1819. "advices_template": advices,
  1820. "drugways": drugways,
  1821. "efs": efs,
  1822. "doctors": doctors,
  1823. "department": department,
  1824. "sick": sick,
  1825. "additions": additions,
  1826. "diagnose": diagnose,
  1827. "manufacturers": manufacturers,
  1828. "goodOutOpen": goodOutOpen,
  1829. "patientDiagnose": patientDiagnose,
  1830. })
  1831. }
  1832. }
  1833. func (c *HisApiController) CreateHisPrescription() {
  1834. record_date := c.GetString("record_date")
  1835. patient_id, _ := c.GetInt64("patient_id")
  1836. reg_type, _ := c.GetInt64("reg_type")
  1837. diagnose := c.GetString("diagnose")
  1838. sick_type, _ := c.GetInt64("sick_type")
  1839. sick_history := c.GetString("sick_history")
  1840. doctor_id, _ := c.GetInt64("doctor", 0)
  1841. department, _ := c.GetInt64("department", 0)
  1842. his_patient_id, _ := c.GetInt64("his_patient_id")
  1843. p_type, _ := c.GetInt64("p_type")
  1844. patient_diagnose := c.GetString("patient_diagnose")
  1845. dataBody := make(map[string]interface{}, 0)
  1846. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1847. if err != nil {
  1848. utils.ErrorLog(err.Error())
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1850. return
  1851. }
  1852. //edit, src := GetCompareData(dataBody)
  1853. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1854. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1855. //fmt.Println(drugResult)
  1856. //fmt.Println(goodResult)
  1857. timeLayout := "2006-01-02"
  1858. loc, _ := time.LoadLocation("Local")
  1859. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1860. if err != nil {
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. adminInfo := c.GetAdminUserInfo()
  1865. recordDateTime := theTime.Unix()
  1866. //查询默认出库仓库库存
  1867. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1868. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1869. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1870. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1871. if len(lists) == 1 {
  1872. his_patient_id = lists[0].ID
  1873. }
  1874. }
  1875. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1876. //自动出库的开关开启
  1877. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1878. //自动出库
  1879. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1880. //耗材保存处方出库
  1881. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1882. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1883. //已发药和已收费限制逻辑
  1884. isMidicine := false
  1885. isCharge := false
  1886. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1887. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1888. if len(prescriptions) > 0 {
  1889. for _, item := range prescriptions {
  1890. items := item.(map[string]interface{})
  1891. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1892. utils.ErrorLog("id")
  1893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1894. return
  1895. }
  1896. id := int64(items["id"].(float64))
  1897. if id > 0 {
  1898. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1899. if err != nil {
  1900. if new_prescription.OrderStatus == 4 {
  1901. isCharge = true
  1902. }
  1903. }
  1904. }
  1905. }
  1906. }
  1907. }
  1908. if isMidicine == true {
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1910. return
  1911. }
  1912. if isCharge == true {
  1913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1914. return
  1915. }
  1916. // 开始主事务
  1917. db := service.XTWriteDB()
  1918. tx := db.Begin()
  1919. // 在函数结束时处理事务回滚
  1920. defer func() {
  1921. if r := recover(); r != nil {
  1922. tx.Rollback()
  1923. }
  1924. }()
  1925. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1926. //药品发药出库
  1927. if pharmacyConfig.IsOpen == 1 {
  1928. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1929. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1930. if len(prescriptions) > 0 {
  1931. for _, item := range prescriptions {
  1932. items := item.(map[string]interface{})
  1933. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1934. advices := items["advices"].([]interface{})
  1935. if len(advices) > 0 {
  1936. for _, advice := range advices {
  1937. var drug_id int64
  1938. var prescribing_number float64
  1939. var prescribingNumberUnit string
  1940. var adviceId int64
  1941. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1942. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1943. }
  1944. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1945. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1946. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1947. }
  1948. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1949. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1950. }
  1951. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1952. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1953. }
  1954. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1955. if drug.ID == 0 {
  1956. tx.Rollback()
  1957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1958. return
  1959. }
  1960. //查询药品的所有库存
  1961. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1962. var total_count int64
  1963. for _, it := range list {
  1964. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1965. }
  1966. totals := strconv.FormatInt(total_count, 10)
  1967. //查询该药品是否存在开药记录
  1968. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1969. //新增处方盘点库存是否充足
  1970. if advicelist.ID == 0 {
  1971. all_count, _ := strconv.ParseFloat(totals, 64)
  1972. if prescribingNumberUnit == drug.MinUnit {
  1973. if drug.IsUse != 1 {
  1974. if drug.IsProject == 0 || drug.IsProject == 2 {
  1975. if all_count == 0 {
  1976. tx.Rollback()
  1977. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1978. return
  1979. }
  1980. if prescribing_number > all_count {
  1981. tx.Rollback()
  1982. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1983. return
  1984. }
  1985. }
  1986. }
  1987. }
  1988. if prescribingNumberUnit == drug.MaxUnit {
  1989. num := prescribing_number * float64(drug.MinNumber)
  1990. if drug.IsUse != 1 {
  1991. if drug.IsProject == 0 || drug.IsProject == 2 {
  1992. if all_count == 0 {
  1993. tx.Rollback()
  1994. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1995. return
  1996. }
  1997. if num > all_count {
  1998. tx.Rollback()
  1999. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2000. return
  2001. }
  2002. }
  2003. }
  2004. }
  2005. }
  2006. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2007. //不使用保存处方出库
  2008. if drugOutConfig.IsOpen != 1 {
  2009. //修改处方
  2010. for _, advice := range advices {
  2011. var drug_id int64
  2012. var prescribing_number float64
  2013. var prescribingNumberUnit string
  2014. var prescribingNumber string
  2015. var adviceId int64
  2016. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2017. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2018. }
  2019. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2020. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2021. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2022. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2023. }
  2024. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2025. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2026. }
  2027. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2028. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2029. }
  2030. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2031. if drug.ID == 0 {
  2032. tx.Rollback()
  2033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2034. return
  2035. }
  2036. //查询药品的所有库存
  2037. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2038. var total_count int64
  2039. for _, it := range list {
  2040. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2041. }
  2042. totals := strconv.FormatInt(total_count, 10)
  2043. //查询该药品是否存在开药记录
  2044. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2045. //新增处方
  2046. if advicelist.ID == 0 {
  2047. all_count, _ := strconv.ParseFloat(totals, 64)
  2048. if prescribingNumberUnit == drug.MinUnit {
  2049. if drug.IsUse != 1 {
  2050. if drug.IsProject == 0 || drug.IsProject == 2 {
  2051. if all_count == 0 {
  2052. tx.Rollback()
  2053. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2054. return
  2055. }
  2056. if prescribing_number > all_count {
  2057. tx.Rollback()
  2058. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2059. return
  2060. }
  2061. }
  2062. }
  2063. } else {
  2064. if prescribingNumberUnit == drug.MaxUnit {
  2065. num := prescribing_number * float64(drug.MinNumber)
  2066. if drug.IsUse != 1 {
  2067. if drug.IsProject == 0 || drug.IsProject == 2 {
  2068. if all_count == 0 {
  2069. tx.Rollback()
  2070. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2071. return
  2072. }
  2073. if num > all_count {
  2074. tx.Rollback()
  2075. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2076. return
  2077. }
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. //修改处方
  2084. if advicelist.ID > 0 {
  2085. var device_number int64
  2086. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2087. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2088. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2089. device_number = prescribingNumberInt * drug.MinNumber
  2090. }
  2091. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2092. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2093. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2094. device_number = prescribingNumberInt
  2095. }
  2096. var number_count int64
  2097. if prescribingNumberUnit == drug.MaxUnit {
  2098. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2099. number_count = prescribingNumberInt * drug.MinNumber
  2100. }
  2101. if prescribingNumberUnit == drug.MinUnit {
  2102. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2103. number_count = prescribingNumberInt
  2104. }
  2105. //如果修改的数量大于之前修改的数量
  2106. if (number_count - device_number) > 0 {
  2107. //如果修改的差数量 大于库存数量
  2108. if drug.IsUse != 1 {
  2109. if (number_count - device_number) > total_count {
  2110. tx.Rollback()
  2111. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2112. return
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. }
  2119. }
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125. }
  2126. //已发药和已收费限制逻辑
  2127. //执行出库的逻辑
  2128. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2129. //校验库存总量
  2130. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2131. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2132. if len(prescriptions) > 0 {
  2133. for _, item := range prescriptions {
  2134. items := item.(map[string]interface{})
  2135. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2136. advices := items["advices"].([]interface{})
  2137. if len(advices) > 0 {
  2138. for _, advice := range advices {
  2139. var drug_id int64
  2140. var prescribing_number float64
  2141. var prescribingNumberUnit string
  2142. var adviceId int64
  2143. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2144. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2145. }
  2146. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2147. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2148. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2149. }
  2150. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2151. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2152. }
  2153. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2154. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2155. }
  2156. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2157. if drug.ID == 0 {
  2158. tx.Rollback()
  2159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2160. return
  2161. }
  2162. //查询药品的所有库存
  2163. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2164. var total_count int64
  2165. for _, it := range list {
  2166. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2167. }
  2168. totals := strconv.FormatInt(total_count, 10)
  2169. //查询该药品是否存在开药记录
  2170. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2171. //查询最新批次库存
  2172. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2173. var batch_number_count int64
  2174. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2175. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2176. //新增处方
  2177. if advicelist.ID == 0 {
  2178. all_count, _ := strconv.ParseFloat(totals, 64)
  2179. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2180. if prescribingNumberUnit == drug.MinUnit {
  2181. if drug.IsUse != 1 {
  2182. if drug.IsProject == 0 || drug.IsProject == 2 {
  2183. if all_count == 0 {
  2184. tx.Rollback()
  2185. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2186. return
  2187. }
  2188. if prescribing_number > all_count {
  2189. tx.Rollback()
  2190. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2191. return
  2192. }
  2193. }
  2194. if adminInfo.CurrentOrgId == 10215 {
  2195. if prescribing_number > batch_number_all_count {
  2196. tx.Rollback()
  2197. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2198. return
  2199. }
  2200. }
  2201. }
  2202. }
  2203. if prescribingNumberUnit == drug.MaxUnit {
  2204. num := prescribing_number * float64(drug.MinNumber)
  2205. if drug.IsUse != 1 {
  2206. if drug.IsProject == 0 || drug.IsProject == 2 {
  2207. if all_count == 0 {
  2208. tx.Rollback()
  2209. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2210. return
  2211. }
  2212. if num > all_count {
  2213. tx.Rollback()
  2214. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2215. return
  2216. }
  2217. }
  2218. if adminInfo.CurrentOrgId == 10215 {
  2219. if num > batch_number_all_count {
  2220. tx.Rollback()
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2222. return
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. //不是保存处方出库
  2229. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2230. if drugOutConfig.IsOpen != 1 {
  2231. //修改处方
  2232. for _, advice := range advices {
  2233. var drug_id int64
  2234. var prescribing_number float64
  2235. var prescribingNumberUnit string
  2236. var prescribingNumber string
  2237. var adviceId int64
  2238. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2239. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2240. }
  2241. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2242. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2243. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2244. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2245. }
  2246. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2247. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2248. }
  2249. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2250. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2251. }
  2252. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2253. if drug.ID == 0 {
  2254. tx.Rollback()
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2256. return
  2257. }
  2258. //查询药品的所有库存
  2259. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2260. var total_count int64
  2261. for _, it := range list {
  2262. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2263. }
  2264. totals := strconv.FormatInt(total_count, 10)
  2265. //查询该药品是否存在开药记录
  2266. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2267. //新增处方
  2268. if advicelist.ID == 0 {
  2269. //查询最新批次库存
  2270. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2271. var batch_number_count int64
  2272. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2273. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2274. all_count, _ := strconv.ParseFloat(totals, 64)
  2275. if all_count == 0 {
  2276. tx.Rollback()
  2277. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2278. return
  2279. }
  2280. if prescribingNumberUnit == drug.MinUnit {
  2281. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2282. if drug.IsUse != 1 {
  2283. if drug.IsProject == 0 || drug.IsProject == 2 {
  2284. if all_count == 0 {
  2285. tx.Rollback()
  2286. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2287. return
  2288. }
  2289. if prescribing_number > all_count {
  2290. tx.Rollback()
  2291. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2292. return
  2293. }
  2294. }
  2295. if adminInfo.CurrentOrgId == 10215 {
  2296. if prescribing_number > batch_number_all_count {
  2297. tx.Rollback()
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2299. return
  2300. }
  2301. }
  2302. }
  2303. } else {
  2304. if prescribingNumberUnit == drug.MaxUnit {
  2305. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2306. num := prescribing_number * float64(drug.MinNumber)
  2307. if drug.IsUse != 1 {
  2308. if drug.IsProject == 0 || drug.IsProject == 2 {
  2309. if all_count == 0 {
  2310. tx.Rollback()
  2311. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2312. return
  2313. }
  2314. if num > all_count {
  2315. tx.Rollback()
  2316. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2317. return
  2318. }
  2319. }
  2320. if adminInfo.CurrentOrgId == 10215 {
  2321. if prescribing_number > batch_number_all_count {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2324. return
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. //修改处方
  2332. if advicelist.ID > 0 {
  2333. //查询最新批次库存
  2334. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2335. var batch_number_count int64
  2336. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2337. var device_number int64
  2338. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2339. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2340. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2341. device_number = prescribingNumberInt * drug.MinNumber
  2342. }
  2343. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2344. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2345. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2346. device_number = prescribingNumberInt
  2347. //回退库存
  2348. }
  2349. var number_count int64
  2350. if prescribingNumberUnit == drug.MaxUnit {
  2351. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2352. number_count = prescribingNumberInt * drug.MinNumber
  2353. //回退库存
  2354. }
  2355. if prescribingNumberUnit == drug.MinUnit {
  2356. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2357. number_count = prescribingNumberInt
  2358. //回退库存
  2359. }
  2360. //如果修改的数量大于之前修改的数量
  2361. if (number_count - device_number) > 0 {
  2362. //如果修改的差数量 大于库存数量
  2363. if drug.IsUse != 1 {
  2364. if drug.IsProject == 0 || drug.IsProject == 2 {
  2365. if total_count == 0 {
  2366. tx.Rollback()
  2367. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2368. return
  2369. }
  2370. if (number_count - device_number) > total_count {
  2371. tx.Rollback()
  2372. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2373. return
  2374. }
  2375. if (number_count - device_number) > batch_number_count {
  2376. tx.Rollback()
  2377. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2378. return
  2379. }
  2380. }
  2381. if adminInfo.CurrentOrgId == 10215 {
  2382. // 查询该药品最后一次出库记录
  2383. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2384. var out_count int64
  2385. var in_count int64
  2386. var stock_max_number int64
  2387. var stock_min_number int64
  2388. for _, it := range outInfo {
  2389. if it.CountUnit == drug.MaxUnit {
  2390. it.Count = it.Count * drug.MinNumber
  2391. }
  2392. out_count += it.Count
  2393. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2394. stock_max_number = warehouseInfoList.StockMaxNumber
  2395. stock_min_number = warehouseInfoList.StockMinNumber
  2396. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2397. }
  2398. if out_count > 0 {
  2399. if (number_count - device_number) > in_count {
  2400. tx.Rollback()
  2401. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2402. return
  2403. }
  2404. }
  2405. // 未出库
  2406. if out_count == 0 {
  2407. var sum_in_count int64
  2408. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2409. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2410. //如果修改的数量大于有库存的第一个批次
  2411. if number_count > sum_in_count {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2414. return
  2415. }
  2416. }
  2417. }
  2418. }
  2419. }
  2420. //药品发药
  2421. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2422. //不使用药品发药的功能
  2423. //if pharmacyConfig.IsOpen != 1 {
  2424. // if device_number != number_count {
  2425. //
  2426. // //查询该药品的出库记录
  2427. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2428. // if len(outListExport) > 0 {
  2429. // //
  2430. // for _, item := range outListExport {
  2431. // //回退库存
  2432. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2433. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2434. // }
  2435. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2436. // var stock_max_number int64
  2437. // var stock_min_number int64
  2438. //
  2439. // if number_count >= drug.MinNumber {
  2440. //
  2441. // stock_max_number = device_number / drug.MinNumber
  2442. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2443. //
  2444. // stock_min_number = device_number % drug.MinNumber
  2445. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2446. //
  2447. // } else {
  2448. //
  2449. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2450. //
  2451. // }
  2452. // }
  2453. //
  2454. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2455. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2456. // }
  2457. // }
  2458. // }
  2459. //
  2460. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2461. // var sum_count int64
  2462. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2463. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2464. // for _, its := range stockInfo {
  2465. // if its.MaxUnit == drug.MaxUnit {
  2466. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2467. // }
  2468. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2469. // }
  2470. // //更新字典里面的库存
  2471. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2472. //
  2473. // //剩余库存
  2474. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2475. //
  2476. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2477. // //减少出库数量
  2478. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2479. //
  2480. // }
  2481. //}
  2482. }
  2483. }
  2484. }
  2485. //保存处方开药
  2486. if drugOutConfig.IsOpen == 1 {
  2487. //修改处方
  2488. for _, advice := range advices {
  2489. var drug_id int64
  2490. var prescribing_number float64
  2491. var prescribingNumberUnit string
  2492. var prescribingNumber string
  2493. var adviceId int64
  2494. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2495. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2496. }
  2497. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2498. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2499. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2500. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2501. }
  2502. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2503. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2504. }
  2505. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2506. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2507. }
  2508. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2509. if drug.ID == 0 {
  2510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2511. return
  2512. }
  2513. //查询药品的所有库存
  2514. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2515. var total_count int64
  2516. for _, it := range list {
  2517. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2518. }
  2519. totals := strconv.FormatInt(total_count, 10)
  2520. //查询该药品是否存在开药记录
  2521. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2522. //新增处方
  2523. if advicelist.ID == 0 {
  2524. //查询最新批次库存
  2525. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2526. var batch_number_count int64
  2527. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2528. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2529. all_count, _ := strconv.ParseFloat(totals, 64)
  2530. if prescribingNumberUnit == drug.MinUnit {
  2531. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2532. if drug.IsUse != 1 {
  2533. if drug.IsProject == 0 || drug.IsProject == 2 {
  2534. if all_count == 0 {
  2535. tx.Rollback()
  2536. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2537. return
  2538. }
  2539. if prescribing_number > all_count {
  2540. tx.Rollback()
  2541. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2542. return
  2543. }
  2544. }
  2545. if adminInfo.CurrentOrgId == 10215 {
  2546. if prescribing_number > batch_number_all_count {
  2547. tx.Rollback()
  2548. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2549. return
  2550. }
  2551. }
  2552. }
  2553. } else {
  2554. if prescribingNumberUnit == drug.MaxUnit {
  2555. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2556. num := prescribing_number * float64(drug.MinNumber)
  2557. if drug.IsUse != 1 {
  2558. if drug.IsProject == 0 || drug.IsProject == 2 {
  2559. if all_count == 0 {
  2560. tx.Rollback()
  2561. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2562. return
  2563. }
  2564. if num > all_count {
  2565. tx.Rollback()
  2566. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2567. return
  2568. }
  2569. }
  2570. if adminInfo.CurrentOrgId == 10215 {
  2571. if prescribing_number > batch_number_all_count {
  2572. tx.Rollback()
  2573. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2574. return
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. //修改处方
  2582. if advicelist.ID > 0 {
  2583. //查询最新批次库存
  2584. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2585. var batch_number_count int64
  2586. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2587. var device_number int64
  2588. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2589. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2590. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2591. device_number = prescribingNumberInt * drug.MinNumber
  2592. }
  2593. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2594. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2595. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2596. device_number = prescribingNumberInt
  2597. }
  2598. var number_count int64
  2599. if prescribingNumberUnit == drug.MaxUnit {
  2600. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2601. number_count = prescribingNumberInt * drug.MinNumber
  2602. }
  2603. if prescribingNumberUnit == drug.MinUnit {
  2604. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2605. number_count = prescribingNumberInt
  2606. }
  2607. //如果修改的数量大于之前修改的数量
  2608. if (number_count - device_number) > 0 {
  2609. //如果修改的差数量 大于库存数量
  2610. if drug.IsUse != 1 {
  2611. if drug.IsProject == 0 || drug.IsProject == 2 {
  2612. if total_count == 0 {
  2613. tx.Rollback()
  2614. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2615. return
  2616. }
  2617. if (number_count - device_number) > total_count {
  2618. tx.Rollback()
  2619. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2620. return
  2621. }
  2622. }
  2623. if adminInfo.CurrentOrgId == 10215 {
  2624. if (number_count - device_number) > batch_number_count {
  2625. tx.Rollback()
  2626. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2627. return
  2628. }
  2629. }
  2630. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2631. //查询历史出库数据总批次
  2632. // 查询该药品最后一次出库记录
  2633. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2634. var out_count int64
  2635. var in_count int64
  2636. var stock_max_number int64
  2637. var stock_min_number int64
  2638. for _, it := range outInfo {
  2639. if it.CountUnit == drug.MaxUnit {
  2640. it.Count = it.Count * drug.MinNumber
  2641. }
  2642. out_count += it.Count
  2643. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2644. stock_max_number = warehouseInfoList.StockMaxNumber
  2645. stock_min_number = warehouseInfoList.StockMinNumber
  2646. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2647. }
  2648. if out_count > 0 {
  2649. if (number_count - device_number) > in_count {
  2650. tx.Rollback()
  2651. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2652. return
  2653. }
  2654. }
  2655. // 未出库
  2656. if out_count == 0 {
  2657. var sum_in_count int64
  2658. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2659. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2660. if sum_in_count == 0 {
  2661. tx.Rollback()
  2662. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2663. return
  2664. }
  2665. //如果修改的数量大于有库存的第一个批次
  2666. if number_count > sum_in_count {
  2667. tx.Rollback()
  2668. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2669. return
  2670. }
  2671. }
  2672. }
  2673. }
  2674. }
  2675. }
  2676. }
  2677. }
  2678. }
  2679. }
  2680. }
  2681. }
  2682. }
  2683. }
  2684. }
  2685. //校验耗材库存
  2686. if goodOutConfig.IsOpen == 1 {
  2687. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2688. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2689. if len(prescriptions) > 0 {
  2690. for _, item := range prescriptions {
  2691. items := item.(map[string]interface{})
  2692. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2693. projects := items["project"].([]interface{})
  2694. if len(projects) > 0 {
  2695. for _, project := range projects {
  2696. var project_id int64
  2697. var project_type int64
  2698. var totals float64
  2699. var project_name string
  2700. var parsetotal int64
  2701. var id int64
  2702. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2703. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2704. }
  2705. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2706. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2707. }
  2708. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2709. total, _ := project.(map[string]interface{})["total"].(string)
  2710. totals, _ = strconv.ParseFloat(total, 64)
  2711. }
  2712. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2713. project_name = project.(map[string]interface{})["project_name"].(string)
  2714. }
  2715. if project_type == 3 {
  2716. //查找该耗材的出库记录
  2717. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2718. if len(goodWarehouseInfo) == 0 {
  2719. //查询耗材库存
  2720. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2721. var stock_count int64
  2722. for _, it := range list {
  2723. stock_count += it.StockCount
  2724. }
  2725. stock_counts := strconv.FormatInt(stock_count, 10)
  2726. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2727. if stock_total_count == 0 {
  2728. tx.Rollback()
  2729. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2730. return
  2731. }
  2732. if totals > stock_total_count {
  2733. tx.Rollback()
  2734. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2735. return
  2736. }
  2737. }
  2738. if len(goodWarehouseInfo) > 0 {
  2739. //查询该患者耗材的历史数据
  2740. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2741. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2742. //数量发生改变
  2743. if parsetotal != count {
  2744. //如果现在的数量大于历史数量,就要看库存是否足够
  2745. if parsetotal > count {
  2746. //查询耗材所有库存
  2747. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2748. var stock_count int64
  2749. for _, it := range list {
  2750. stock_count += it.StockCount
  2751. }
  2752. //库存不足
  2753. if stock_count == 0 {
  2754. tx.Rollback()
  2755. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2756. return
  2757. }
  2758. if (parsetotal - count) > stock_count {
  2759. tx.Rollback()
  2760. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2761. return
  2762. }
  2763. }
  2764. }
  2765. }
  2766. }
  2767. }
  2768. }
  2769. }
  2770. }
  2771. }
  2772. }
  2773. }
  2774. //不使用耗材保存处方出库
  2775. if goodOutConfig.IsOpen != 1 {
  2776. if stockConfig.IsOpen == 1 {
  2777. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2778. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2779. if len(prescriptions) > 0 {
  2780. for _, item := range prescriptions {
  2781. items := item.(map[string]interface{})
  2782. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2783. projects := items["project"].([]interface{})
  2784. if len(projects) > 0 {
  2785. for _, project := range projects {
  2786. var project_id int64
  2787. var project_type int64
  2788. var totals float64
  2789. var project_name string
  2790. var parsetotal int64
  2791. var id int64
  2792. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2793. id = int64(project.(map[string]interface{})["id"].(float64))
  2794. }
  2795. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2796. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2797. }
  2798. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2799. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2800. }
  2801. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2802. total, _ := project.(map[string]interface{})["total"].(string)
  2803. totals, _ = strconv.ParseFloat(total, 64)
  2804. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2805. }
  2806. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2807. project_name = project.(map[string]interface{})["project_name"].(string)
  2808. }
  2809. if project_type == 3 {
  2810. //查找该耗材的出库记录
  2811. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2812. //没有出库记录
  2813. if len(goodWarehouseInfo) == 0 {
  2814. //查询耗材库存
  2815. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2816. var stock_count int64
  2817. for _, it := range list {
  2818. stock_count += it.StockCount
  2819. }
  2820. stock_counts := strconv.FormatInt(stock_count, 10)
  2821. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2822. if stock_total_count == 0 {
  2823. tx.Rollback()
  2824. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2825. return
  2826. }
  2827. if totals > stock_total_count {
  2828. tx.Rollback()
  2829. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2830. return
  2831. }
  2832. //查找今日该患者已经出库的所有耗材
  2833. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2834. for _, item := range goodList {
  2835. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2836. var flush_count int64
  2837. for _, it := range goodListSix {
  2838. flush_count += it.StockCount
  2839. }
  2840. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2841. creater := adminInfo.AdminUser.Id
  2842. if errs != nil {
  2843. goodErrcode := models.XtGoodErrcode{
  2844. UserOrgId: item.OrgId,
  2845. Errcode: "手动出库更新剩余出库失败",
  2846. GoodId: item.GoodId,
  2847. Status: 1,
  2848. Ctime: time.Now().Unix(),
  2849. Mtime: 0,
  2850. Count: 0,
  2851. StockCount: 0,
  2852. Creater: creater,
  2853. BatchNumberId: 0,
  2854. WarehouseOutId: 0,
  2855. }
  2856. service.CreateGoodErrcode(goodErrcode)
  2857. }
  2858. }
  2859. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2860. }
  2861. //有出库记录
  2862. if len(goodWarehouseInfo) > 0 {
  2863. //查询该患者耗材的历史数据
  2864. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2865. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2866. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2867. //数量发生改变
  2868. if parsetotal != count {
  2869. //查找今日该患者已经出库的所有耗材
  2870. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2871. for _, item := range goodList {
  2872. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2873. var flush_count int64
  2874. for _, it := range goodListSix {
  2875. flush_count += it.StockCount
  2876. }
  2877. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2878. //减少出库数量
  2879. creater := adminInfo.AdminUser.Id
  2880. if errs != nil {
  2881. goodErrcode := models.XtGoodErrcode{
  2882. UserOrgId: item.OrgId,
  2883. Errcode: "手动出库更新剩余出库失败",
  2884. GoodId: item.GoodId,
  2885. Status: 1,
  2886. Ctime: time.Now().Unix(),
  2887. Mtime: 0,
  2888. Count: 0,
  2889. StockCount: 0,
  2890. Creater: creater,
  2891. BatchNumberId: 0,
  2892. WarehouseOutId: 0,
  2893. }
  2894. service.CreateGoodErrcode(goodErrcode)
  2895. }
  2896. //查询默认仓库
  2897. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2898. var total_count int64
  2899. for _, it := range stockList {
  2900. total_count += it.StockCount
  2901. }
  2902. //基础库插入数据
  2903. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2904. }
  2905. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2906. }
  2907. }
  2908. }
  2909. }
  2910. }
  2911. }
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2918. var hpInfo models.HisPrescriptionInfo
  2919. if info.ID == 0 {
  2920. var randNum int
  2921. randNum = rand.Intn(10000) + 1000
  2922. timestamp := time.Now().Unix()
  2923. tempTime := time.Unix(timestamp, 0)
  2924. timeFormat := tempTime.Format("20060102150405")
  2925. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2926. hpInfo = models.HisPrescriptionInfo{
  2927. HisPatientId: his_patient_id,
  2928. UserOrgId: adminInfo.CurrentOrgId,
  2929. RecordDate: theTime.Unix(),
  2930. PatientId: patient_id,
  2931. Status: 1,
  2932. Ctime: time.Now().Unix(),
  2933. Mtime: time.Now().Unix(),
  2934. Creator: adminInfo.AdminUser.Id,
  2935. Modifier: adminInfo.AdminUser.Id,
  2936. Diagnosis: diagnose,
  2937. SickHistory: sick_history,
  2938. Departments: department,
  2939. RegisterType: reg_type,
  2940. PrescriptionNumber: p_number,
  2941. PrescriptionStatus: 1,
  2942. Doctor: role.UserName,
  2943. DoctorId: doctor_id,
  2944. SickType: sick_type,
  2945. PType: p_type,
  2946. PatientDiagnosis: patient_diagnose,
  2947. }
  2948. service.SavePatientPrescriptionInfo(hpInfo)
  2949. //创建步骤表
  2950. finish := models.XtDialysisFinish{
  2951. IsFinish: 1,
  2952. UserOrgId: adminInfo.CurrentOrgId,
  2953. Status: 1,
  2954. Ctime: time.Now().Unix(),
  2955. Mtime: 0,
  2956. Module: 4,
  2957. RecordDate: theTime.Unix(),
  2958. Sourse: 1,
  2959. PatientId: patient_id,
  2960. }
  2961. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2962. if dialysisFinish.ID == 0 {
  2963. service.CreateDialysisFinish(finish)
  2964. }
  2965. redis := service.RedisClient()
  2966. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2967. redis.Set(key, "", time.Second)
  2968. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2969. redis.Set(keyOne, "", time.Second)
  2970. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2971. redis.Set(keySeven, "", time.Second)
  2972. defer redis.Close()
  2973. } else {
  2974. hpInfo = models.HisPrescriptionInfo{
  2975. ID: info.ID,
  2976. UserOrgId: adminInfo.CurrentOrgId,
  2977. RecordDate: info.RecordDate,
  2978. PatientId: info.PatientId,
  2979. Status: 1,
  2980. Ctime: info.Ctime,
  2981. Mtime: time.Now().Unix(),
  2982. Creator: info.Creator,
  2983. Modifier: adminInfo.AdminUser.Id,
  2984. Diagnosis: diagnose,
  2985. SickHistory: sick_history,
  2986. Departments: department,
  2987. RegisterType: reg_type,
  2988. PrescriptionNumber: info.PrescriptionNumber,
  2989. Doctor: role.UserName,
  2990. PrescriptionStatus: info.PrescriptionStatus,
  2991. DoctorId: doctor_id,
  2992. SickType: sick_type,
  2993. PType: info.PType,
  2994. HisPatientId: info.HisPatientId,
  2995. PatientDiagnosis: patient_diagnose,
  2996. }
  2997. service.SavePatientPrescriptionInfo(hpInfo)
  2998. //创建步骤表
  2999. finish := models.XtDialysisFinish{
  3000. IsFinish: 1,
  3001. UserOrgId: adminInfo.CurrentOrgId,
  3002. Status: 1,
  3003. Ctime: time.Now().Unix(),
  3004. Mtime: 0,
  3005. Module: 4,
  3006. RecordDate: info.RecordDate,
  3007. Sourse: 1,
  3008. PatientId: info.PatientId,
  3009. }
  3010. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3011. if dialysisFinish.ID == 0 {
  3012. service.CreateDialysisFinish(finish)
  3013. }
  3014. redis := service.RedisClient()
  3015. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3016. redis.Set(key, "", time.Second)
  3017. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3018. redis.Set(keyOne, "", time.Second)
  3019. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3020. redis.Set(keySeven, "", time.Second)
  3021. defer redis.Close()
  3022. }
  3023. //定义切片
  3024. var adviceList []models.HisDoctorAdviceInfo
  3025. var projectList []models.HisPrescriptionProject
  3026. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10635 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 || adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10726 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10571 || adminInfo.CurrentOrgId == 10724 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10653 || adminInfo.CurrentOrgId == 10567 {
  3027. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3028. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3029. var tempPrescription *models.HisPrescription
  3030. if len(prescriptions) > 0 {
  3031. for _, item := range prescriptions {
  3032. // 开始外部循环的事务
  3033. tx := db.Begin()
  3034. // 在函数结束时处理事务回滚
  3035. defer func() {
  3036. if r := recover(); r != nil {
  3037. tx.Rollback()
  3038. }
  3039. }()
  3040. items := item.(map[string]interface{})
  3041. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3042. utils.ErrorLog("id")
  3043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3044. return
  3045. }
  3046. id := int64(items["id"].(float64))
  3047. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3048. tempPrescription = &new_prescription
  3049. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3050. utils.ErrorLog("type")
  3051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3052. return
  3053. }
  3054. types := int64(items["type"].(float64))
  3055. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3056. utils.ErrorLog("med_type")
  3057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3058. return
  3059. }
  3060. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3061. if med_type == "0" {
  3062. med_type = "14"
  3063. }
  3064. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3065. // utils.ErrorLog("diagnoses")
  3066. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3067. // return
  3068. //}
  3069. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3070. diagnoses, _ := items["diagnoses"].(string)
  3071. //if order_status == 0 {
  3072. // order_status = 1
  3073. //}
  3074. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3075. utils.ErrorLog("pre_time")
  3076. }
  3077. preTime, _ := items["pre_time"].(string)
  3078. fmt.Println("preTime", preTime)
  3079. timeLayout := "2006-01-02"
  3080. loc, _ := time.LoadLocation("Local")
  3081. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3082. //result := strings.Split(preTime, " ")
  3083. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3084. if err != nil {
  3085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3086. return
  3087. }
  3088. pTime := theTime2.Unix()
  3089. ctime := time.Now().Unix()
  3090. if tempPrescription.ID == 0 {
  3091. prescription := &models.HisPrescription{
  3092. ID: 0,
  3093. PatientId: patient_id,
  3094. UserOrgId: adminInfo.CurrentOrgId,
  3095. RecordDate: recordDateTime,
  3096. Ctime: ctime,
  3097. Mtime: ctime,
  3098. Type: types,
  3099. Modifier: adminInfo.AdminUser.Id,
  3100. Creator: adminInfo.AdminUser.Id,
  3101. Status: 1,
  3102. Doctor: role.UserName,
  3103. HisPatientId: his_patient_id,
  3104. OrderStatus: 1,
  3105. BatchNumber: "",
  3106. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3107. PreTime: pTime,
  3108. PType: p_type,
  3109. MedType: med_type,
  3110. Diagnose: diagnoses,
  3111. }
  3112. tempPrescription = prescription
  3113. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3114. redis := service.RedisClient()
  3115. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3116. redis.Set(key, "", time.Second)
  3117. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3118. redis.Set(keyOne, "", time.Second)
  3119. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3120. redis.Set(keySeven, "", time.Second)
  3121. defer redis.Close()
  3122. } else {
  3123. tempPrescription.ID = id
  3124. tempPrescription.Type = types
  3125. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3126. tempPrescription.Mtime = time.Now().Unix()
  3127. tempPrescription.Doctor = role.UserName
  3128. //tempPrescription.OrderStatus = order_status
  3129. tempPrescription.PreTime = pTime
  3130. tempPrescription.MedType = med_type
  3131. tempPrescription.Diagnose = diagnoses
  3132. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3133. redis := service.RedisClient()
  3134. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3135. redis.Set(key, "", time.Second)
  3136. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3137. redis.Set(keyOne, "", time.Second)
  3138. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3139. redis.Set(keySeven, "", time.Second)
  3140. defer redis.Close()
  3141. }
  3142. //service.SaveHisPrescription(prescription)
  3143. //更改患者挂号状态
  3144. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3145. fmt.Println("更改失败", err2)
  3146. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3147. advices := items["advices"].([]interface{})
  3148. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3149. groupNo := int64(0)
  3150. if len(advices) > 0 {
  3151. for _, advice := range advices {
  3152. tx := db.Begin()
  3153. // 在函数结束时处理事务回滚
  3154. defer func() {
  3155. if r := recover(); r != nil {
  3156. tx.Rollback()
  3157. }
  3158. }()
  3159. var s models.HisDoctorAdviceInfo
  3160. s.PrescriptionId = tempPrescription.ID
  3161. s.AdviceType = 2
  3162. s.AdviceDoctor = doctor_id
  3163. s.StopState = 2
  3164. s.ExecutionState = 2
  3165. s.AdviceDate = theTime3.Unix()
  3166. s.Status = 1
  3167. s.UserOrgId = adminInfo.CurrentOrgId
  3168. s.RecordDate = theTime3.Unix()
  3169. s.StartTime = tempPrescription.PreTime
  3170. s.Groupno = groupNo
  3171. s.PatientId = patient_id
  3172. s.HisPatientId = his_patient_id
  3173. s.StartTime = pTime
  3174. s.IsSettle = 2
  3175. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3176. if errcode > 0 {
  3177. c.ServeFailJSONWithSGJErrorCode(errcode)
  3178. return
  3179. }
  3180. s.StartTime = pTime
  3181. var total_count int64 //处方总库存
  3182. //查询改药品信息
  3183. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3184. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3185. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3186. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3187. total_count += prescribingNumberSeven * medical.MinNumber
  3188. }
  3189. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3190. total_count += prescribingNumberSeven
  3191. }
  3192. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3193. total_count += prescribingNumberSeven
  3194. }
  3195. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3196. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3197. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3198. if s.Price != lastWarehouse.RetailPrice {
  3199. s.Price = lastWarehouse.RetailPrice
  3200. }
  3201. if s.Price == 0 {
  3202. if lastWarehouse.ID == 0 {
  3203. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3204. s.Price = lastWarehouseTwo.RetailPrice
  3205. }
  3206. }
  3207. }
  3208. //查询保存处方出库开关是否打开
  3209. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3210. if s.PatientId != 30038 {
  3211. if drugOutConfig.IsOpen == 1 {
  3212. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3213. // 查询该药品最后一次出库记录
  3214. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3215. var is_user_total int64
  3216. var no_user_total int64
  3217. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3218. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3219. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3220. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3221. }
  3222. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3223. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3224. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3225. no_user_total += prescribingNumberSevenTy
  3226. }
  3227. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3228. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3229. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3230. no_user_total += prescribingNumberSevenTy
  3231. }
  3232. if len(druginfo) > 0 {
  3233. for _, it := range druginfo {
  3234. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3235. it.Count = it.Count * drug.MinNumber
  3236. is_user_total += it.Count
  3237. }
  3238. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3239. is_user_total += it.Count
  3240. }
  3241. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3242. is_user_total += it.Count
  3243. }
  3244. }
  3245. }
  3246. //fmt.Println("药品名称----------------------", drug.DrugName)
  3247. //fmt.Println("药品名称----------------------", drug.IsUse)
  3248. //fmt.Println("is_user_total-------------------------", is_user_total)
  3249. //fmt.Println("no_user_total-------------------------", no_user_total)
  3250. //fmt.Println("drug.IsUse---------------", drug.IsUse)
  3251. //fmt.Println("00000000000000000000", s.UserOrgId)
  3252. if is_user_total != no_user_total {
  3253. //出库
  3254. //针对御享天源
  3255. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  3256. creater := adminInfo.AdminUser.Id
  3257. newadviceInfo := &models.HisDoctorAdviceInfo{
  3258. ID: s.ID,
  3259. UserOrgId: s.UserOrgId,
  3260. PatientId: s.PatientId,
  3261. HisPatientId: s.HisPatientId,
  3262. AdviceType: s.AdviceType,
  3263. AdviceDate: s.AdviceDate,
  3264. StartTime: s.StartTime,
  3265. AdviceName: s.AdviceName,
  3266. AdviceDesc: s.AdviceDesc,
  3267. ReminderDate: s.ReminderDate,
  3268. SingleDose: s.SingleDose,
  3269. SingleDoseUnit: s.SingleDoseUnit,
  3270. PrescribingNumber: s.PrescribingNumber,
  3271. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3272. DeliveryWay: s.DeliveryWay,
  3273. ExecutionFrequency: s.ExecutionFrequency,
  3274. AdviceDoctor: s.AdviceDoctor,
  3275. Status: s.Status,
  3276. CreatedTime: s.CreatedTime,
  3277. UpdatedTime: s.UpdatedTime,
  3278. AdviceAffirm: s.AdviceAffirm,
  3279. Remark: s.Remark,
  3280. StopTime: s.StopTime,
  3281. StopReason: s.StopReason,
  3282. StopDoctor: s.StopDoctor,
  3283. StopState: s.StopState,
  3284. ParentId: s.ParentId,
  3285. ExecutionTime: s.ExecutionTime,
  3286. ExecutionStaff: s.ExecutionStaff,
  3287. ExecutionState: s.ExecutionState,
  3288. Checker: s.Checker,
  3289. RecordDate: s.RecordDate,
  3290. DialysisOrderId: s.DialysisOrderId,
  3291. CheckTime: s.CheckTime,
  3292. CheckState: s.CheckState,
  3293. DrugSpec: s.DrugSpec,
  3294. DrugSpecUnit: s.DrugSpecUnit,
  3295. Groupno: s.Groupno,
  3296. RemindType: s.RemindType,
  3297. FrequencyType: s.FrequencyType,
  3298. DayCount: s.DayCount,
  3299. WeekDay: s.WeekDay,
  3300. TemplateId: s.TemplateId,
  3301. Modifier: s.Modifier,
  3302. DrugId: s.DrugId,
  3303. Price: s.Price,
  3304. PrescriptionId: s.PrescriptionId,
  3305. MedListCodg: s.MedListCodg,
  3306. FeedetlSn: s.FeedetlSn,
  3307. Day: s.DayCount,
  3308. ChildDoctorAdvice: nil,
  3309. Drug: models.Drug{},
  3310. Diagnosis: s.Diagnosis,
  3311. Way: s.Way,
  3312. HospApprFlag: s.HospApprFlag,
  3313. LmtUsedFlag: s.LmtUsedFlag,
  3314. HisOrderInfo: models.HisOrderInfo{},
  3315. IsMedicine: s.IsMedicine,
  3316. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3317. Child: nil,
  3318. IsSettle: s.IsSettle,
  3319. IsMobile: s.IsMobile,
  3320. IsSelfDrug: s.IsSelfDrug,
  3321. DrugWayCount: s.DrugWayCount,
  3322. }
  3323. var history_count int64
  3324. var local_count int64
  3325. //查找已经开过的医嘱信息
  3326. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3327. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3328. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3329. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3330. local_count += prescribingNumberSevenTy * drug.MinNumber
  3331. }
  3332. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3333. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3334. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3335. local_count += prescribingNumberSevenTy
  3336. }
  3337. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3338. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3339. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3340. local_count += prescribingNumberSevenTy
  3341. }
  3342. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3343. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3344. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3345. history_count += prescribingNumberSevenTy * drug.MinNumber
  3346. }
  3347. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3348. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3349. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3350. history_count += prescribingNumberSevenTy
  3351. }
  3352. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3353. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3354. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3355. history_count += prescribingNumberSevenTy
  3356. }
  3357. fmt.Println("local_count---------------", local_count)
  3358. fmt.Println("history_count---------------", history_count)
  3359. //如果当前出库数量大于历史出库数量则需要出库
  3360. if local_count > history_count {
  3361. //按最小单位出库
  3362. var cha_count = local_count - history_count
  3363. newadviceInfo.PrescribingNumber = float64(cha_count)
  3364. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3365. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3366. }
  3367. //如果当前出库数量小于历史出库数量则需要退库
  3368. if local_count < history_count {
  3369. var cha_count = history_count - local_count
  3370. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3371. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3372. }
  3373. if local_count == history_count {
  3374. if is_user_total == 0 {
  3375. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3376. }
  3377. }
  3378. }
  3379. if drug.IsUse == 2 {
  3380. creater := adminInfo.AdminUser.Id
  3381. newadviceInfo := &models.HisDoctorAdviceInfo{
  3382. ID: s.ID,
  3383. UserOrgId: s.UserOrgId,
  3384. PatientId: s.PatientId,
  3385. HisPatientId: s.HisPatientId,
  3386. AdviceType: s.AdviceType,
  3387. AdviceDate: s.AdviceDate,
  3388. StartTime: s.StartTime,
  3389. AdviceName: s.AdviceName,
  3390. AdviceDesc: s.AdviceDesc,
  3391. ReminderDate: s.ReminderDate,
  3392. SingleDose: s.SingleDose,
  3393. SingleDoseUnit: s.SingleDoseUnit,
  3394. PrescribingNumber: s.PrescribingNumber,
  3395. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3396. DeliveryWay: s.DeliveryWay,
  3397. ExecutionFrequency: s.ExecutionFrequency,
  3398. AdviceDoctor: s.AdviceDoctor,
  3399. Status: s.Status,
  3400. CreatedTime: s.CreatedTime,
  3401. UpdatedTime: s.UpdatedTime,
  3402. AdviceAffirm: s.AdviceAffirm,
  3403. Remark: s.Remark,
  3404. StopTime: s.StopTime,
  3405. StopReason: s.StopReason,
  3406. StopDoctor: s.StopDoctor,
  3407. StopState: s.StopState,
  3408. ParentId: s.ParentId,
  3409. ExecutionTime: s.ExecutionTime,
  3410. ExecutionStaff: s.ExecutionStaff,
  3411. ExecutionState: s.ExecutionState,
  3412. Checker: s.Checker,
  3413. RecordDate: s.RecordDate,
  3414. DialysisOrderId: s.DialysisOrderId,
  3415. CheckTime: s.CheckTime,
  3416. CheckState: s.CheckState,
  3417. DrugSpec: s.DrugSpec,
  3418. DrugSpecUnit: s.DrugSpecUnit,
  3419. Groupno: s.Groupno,
  3420. RemindType: s.RemindType,
  3421. FrequencyType: s.FrequencyType,
  3422. DayCount: s.DayCount,
  3423. WeekDay: s.WeekDay,
  3424. TemplateId: s.TemplateId,
  3425. Modifier: s.Modifier,
  3426. DrugId: s.DrugId,
  3427. Price: s.Price,
  3428. PrescriptionId: s.PrescriptionId,
  3429. MedListCodg: s.MedListCodg,
  3430. FeedetlSn: s.FeedetlSn,
  3431. Day: s.DayCount,
  3432. ChildDoctorAdvice: nil,
  3433. Drug: models.Drug{},
  3434. Diagnosis: s.Diagnosis,
  3435. Way: s.Way,
  3436. HospApprFlag: s.HospApprFlag,
  3437. LmtUsedFlag: s.LmtUsedFlag,
  3438. HisOrderInfo: models.HisOrderInfo{},
  3439. IsMedicine: s.IsMedicine,
  3440. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3441. Child: nil,
  3442. IsSettle: s.IsSettle,
  3443. IsMobile: s.IsMobile,
  3444. IsSelfDrug: s.IsSelfDrug,
  3445. DrugWayCount: s.DrugWayCount,
  3446. }
  3447. var history_count int64
  3448. var local_count int64
  3449. //查找已经开过的医嘱信息
  3450. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3451. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3452. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3453. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3454. local_count += prescribingNumberSevenTy * drug.MinNumber
  3455. }
  3456. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3457. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3458. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3459. local_count += prescribingNumberSevenTy
  3460. }
  3461. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3462. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3463. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3464. local_count += prescribingNumberSevenTy
  3465. }
  3466. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3467. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3468. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3469. history_count += prescribingNumberSevenTy * drug.MinNumber
  3470. }
  3471. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3472. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3473. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3474. history_count += prescribingNumberSevenTy
  3475. }
  3476. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3477. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3478. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3479. history_count += prescribingNumberSevenTy
  3480. }
  3481. fmt.Println("local_count---------------", local_count)
  3482. fmt.Println("history_count---------------", history_count)
  3483. //如果当前出库数量大于历史出库数量则需要出库
  3484. if local_count > history_count {
  3485. //按最小单位出库
  3486. var cha_count = local_count - history_count
  3487. newadviceInfo.PrescribingNumber = float64(cha_count)
  3488. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3489. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3490. }
  3491. //如果当前出库数量小于历史出库数量则需要退库
  3492. if local_count < history_count {
  3493. var cha_count = history_count - local_count
  3494. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3495. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3496. }
  3497. if local_count == history_count {
  3498. if is_user_total == 0 {
  3499. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3500. }
  3501. }
  3502. }
  3503. //更新字典里面的库存
  3504. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3505. var sum_count int64
  3506. for _, its := range stockInfo {
  3507. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3508. if its.MaxUnit == baseDrug.MaxUnit {
  3509. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3510. }
  3511. sum_count += its.StockMaxNumber + its.StockMinNumber
  3512. }
  3513. //更新基础库存
  3514. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3515. //剩余库存
  3516. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3517. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3518. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3519. //创建医嘱
  3520. service.CreateHisDoctorAdviceOne(&s, tx)
  3521. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3522. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3523. if len(outInfoTwo) > 0 {
  3524. for _, item := range outInfoTwo {
  3525. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3526. }
  3527. }
  3528. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3529. if len(drugAutoDetail) > 0 {
  3530. for _, item := range drugAutoDetail {
  3531. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3532. }
  3533. }
  3534. }
  3535. }
  3536. }
  3537. //记录日志
  3538. byterequest, _ := json.Marshal(s)
  3539. adviceLog := models.XtDoctorAdviceLog{
  3540. UserOrgId: s.UserOrgId,
  3541. PatientId: s.PatientId,
  3542. AdminUserId: adminInfo.AdminUser.Id,
  3543. Module: 1,
  3544. ErrLog: string(byterequest),
  3545. Status: 1,
  3546. Ctime: time.Now().Unix(),
  3547. Mtime: 0,
  3548. Source: "电脑端新建his医嘱",
  3549. RecordDate: s.AdviceDate,
  3550. }
  3551. service.CreateDoctorAdviceLog(adviceLog)
  3552. //存储切片中
  3553. adviceList = append(adviceList, s)
  3554. redis := service.RedisClient()
  3555. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3556. redis.Set(key, "", time.Second)
  3557. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3558. redis.Set(keyOne, "", time.Second)
  3559. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3560. redis.Set(keySeven, "", time.Second)
  3561. var randNum int
  3562. randNum = rand.Intn(10000) + 1000
  3563. timestamp := time.Now().Unix()
  3564. tempTime := time.Unix(timestamp, 0)
  3565. timeFormat := tempTime.Format("20060102150405")
  3566. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3567. if s.UserOrgId != 10206 {
  3568. if s.ID == 0 {
  3569. //查询改药品是否已经停用
  3570. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3571. if base.ID > 0 {
  3572. tx.Rollback()
  3573. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3574. return
  3575. }
  3576. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3577. if drugMedical.SumCount == 0 {
  3578. tx.Rollback()
  3579. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3580. return
  3581. }
  3582. }
  3583. if s.ID > 0 {
  3584. //查询改药品是否已经停用
  3585. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3586. if base.ID > 0 {
  3587. tx.Rollback()
  3588. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3589. return
  3590. }
  3591. }
  3592. }
  3593. //赤峰
  3594. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3595. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3596. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3597. if info.RetailPrice > 0 {
  3598. if s.DeliveryWay == "口服" {
  3599. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3600. s.Price = drug.RetailPrice
  3601. }
  3602. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3603. s.Price = info.RetailPrice
  3604. }
  3605. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3606. s.Price = info.RetailPrice
  3607. }
  3608. }
  3609. }
  3610. }
  3611. service.CreateHisDoctorAdviceOne(&s, tx)
  3612. tx.Commit()
  3613. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3614. redis.Set(keySix, "", time.Second)
  3615. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3616. redis.Set(keyFive, "", time.Second)
  3617. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3618. redis.Set(keyEight, "", time.Second)
  3619. defer redis.Close()
  3620. }
  3621. }
  3622. }
  3623. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3624. projects := items["project"].([]interface{})
  3625. if len(projects) > 0 {
  3626. for _, project := range projects {
  3627. tx := db.Begin()
  3628. // 在函数结束时处理事务回滚
  3629. defer func() {
  3630. if r := recover(); r != nil {
  3631. tx.Rollback()
  3632. }
  3633. }()
  3634. var p models.HisPrescriptionProject
  3635. p.PrescriptionId = tempPrescription.ID
  3636. p.PatientId = patient_id
  3637. p.RecordDate = theTime3.Unix()
  3638. p.Doctor = doctor_id
  3639. p.UserOrgId = adminInfo.CurrentOrgId
  3640. p.HisPatientId = his_patient_id
  3641. p.Status = 1
  3642. p.StartTime = pTime
  3643. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3644. if errcode > 0 {
  3645. tx.Rollback()
  3646. c.ServeFailJSONWithSGJErrorCode(errcode)
  3647. return
  3648. }
  3649. if p.ID == 0 {
  3650. p.IsOut = 2
  3651. }
  3652. if p.ID > 0 {
  3653. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3654. p.IsOut = projectDetail.IsOut
  3655. }
  3656. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3657. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3658. if p.Type == 3 {
  3659. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3660. if p.Price != lastWarehouse.PackingPrice {
  3661. p.Price = lastWarehouse.PackingPrice
  3662. }
  3663. if p.Price == 0 {
  3664. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3665. p.Price = lastWarehouseTwo.PackingPrice
  3666. }
  3667. if p.Unit == "" {
  3668. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3669. p.Unit = goodInfoOne.PackingUnit
  3670. }
  3671. }
  3672. }
  3673. if adminInfo.CurrentOrgId != 10206 {
  3674. if p.Type == 3 {
  3675. if p.ID == 0 {
  3676. //查询该耗材是否停用
  3677. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3678. //表示该耗材已经停用,不能保存
  3679. if goodInfoSeven.ID == 0 {
  3680. tx.Rollback()
  3681. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3682. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3683. return
  3684. }
  3685. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3686. if goodInfoOne.SumCount == 0 {
  3687. tx.Rollback()
  3688. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3689. return
  3690. }
  3691. }
  3692. if p.ID > 0 {
  3693. //查询该耗材是否停用
  3694. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3695. //表示该耗材已经停用,不能保存
  3696. if goodInfoSeven.ID == 0 {
  3697. tx.Rollback()
  3698. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3699. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3700. return
  3701. }
  3702. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3703. if goodInfoOne.SumCount == 0 {
  3704. tx.Rollback()
  3705. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3706. return
  3707. }
  3708. }
  3709. }
  3710. }
  3711. //查询保存耗材出库开关是否打开
  3712. if p.PatientId != 30038 {
  3713. //用机构ID区分
  3714. if adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10164 {
  3715. if goodOutConfig.IsOpen == 1 {
  3716. //耗材出库
  3717. if p.Type == 3 {
  3718. //对比当前数据和历史出库数据
  3719. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3720. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3721. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3722. //如果当前处方数量大于历史数据,则需要出库
  3723. if nowCount > historyCount {
  3724. var cha_count int64
  3725. cha_count = nowCount - historyCount
  3726. timeStr := time.Now().Format("2006-01-02")
  3727. timeArr := strings.Split(timeStr, "-")
  3728. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3729. total = total + 1
  3730. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3731. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3732. number = number + total
  3733. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3734. operation_time := time.Now().Unix()
  3735. creater := c.GetAdminUserInfo().AdminUser.Id
  3736. recordDateStr := time.Now().Format("2006-01-02")
  3737. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3738. nowtime := recordDate.Unix()
  3739. warehouseOut := models.WarehouseOut{
  3740. WarehouseOutOrderNumber: warehousing_out_order,
  3741. OperationTime: operation_time,
  3742. OrgId: adminInfo.CurrentOrgId,
  3743. Creater: creater,
  3744. Ctime: time.Now().Unix(),
  3745. Status: 1,
  3746. WarehouseOutTime: nowtime,
  3747. Type: 1,
  3748. StorehouseId: storeConfig.StorehouseOutInfo,
  3749. IsCheck: 1,
  3750. IsSys: 1,
  3751. }
  3752. //查询是否生成出库单
  3753. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3754. if out.ID == 0 {
  3755. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3756. }
  3757. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3758. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3759. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3760. dialyPrepareOne := models.DialysisBeforePrepare{
  3761. GoodTypeId: goodObj.GoodTypeId,
  3762. GoodId: p.ProjectId,
  3763. PatientId: p.PatientId,
  3764. RecordDate: p.RecordDate,
  3765. UserOrgId: adminInfo.CurrentOrgId,
  3766. Count: cha_count,
  3767. Ctime: time.Now().Unix(),
  3768. Creater: creater,
  3769. Status: 1,
  3770. StorehouseId: houseConfig.StorehouseOutInfo,
  3771. ProjectId: p.ID,
  3772. }
  3773. //出库
  3774. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3775. }
  3776. //如果当前处方数量小于历史数据,怎需要退库
  3777. if nowCount < historyCount {
  3778. var cha_count int64
  3779. cha_count = historyCount - nowCount
  3780. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3781. creater := c.GetAdminUserInfo().AdminUser.Id
  3782. newPrescriptionProject := &models.HisPrescriptionProject{
  3783. ID: p.ID,
  3784. ProjectId: p.ProjectId,
  3785. Price: p.Price,
  3786. UserOrgId: p.UserOrgId,
  3787. Status: 1,
  3788. Ctime: time.Now().Unix(),
  3789. Mtime: time.Now().Unix(),
  3790. PatientId: p.PatientId,
  3791. HisPatientId: p.HisPatientId,
  3792. RecordDate: p.RecordDate,
  3793. PrescriptionId: p.PrescriptionId,
  3794. Count: p.Count,
  3795. FeedetlSn: p.FeedetlSn,
  3796. MedListCodg: p.MedListCodg,
  3797. SingleDose: p.SingleDose,
  3798. DeliveryWay: p.DeliveryWay,
  3799. ExecutionFrequency: p.ExecutionFrequency,
  3800. Day: p.Day,
  3801. HisProject: models.HisProject{},
  3802. GoodInfo: models.GoodInfo{},
  3803. Remark: p.Remark,
  3804. Unit: p.Unit,
  3805. Type: p.Type,
  3806. Doctor: p.Doctor,
  3807. ExecutionTime: p.ExecutionTime,
  3808. ExecutionStaff: p.ExecutionStaff,
  3809. ExecutionState: p.ExecutionState,
  3810. CheckTime: p.CheckTime,
  3811. CheckState: p.CheckState,
  3812. Checker: p.Checker,
  3813. StartTime: p.StartTime,
  3814. TeamId: p.TeamId,
  3815. XtHisProjectTeam: models.XtHisProjectTeam{},
  3816. FrequencyType: p.FrequencyType,
  3817. DayCount: p.DayCount,
  3818. WeekDay: p.WeekDay,
  3819. IsCheckTeam: p.IsCheckTeam,
  3820. HisOrderInfo: models.HisOrderInfo{},
  3821. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3822. IsOut: p.IsOut,
  3823. YbSyncStatus: p.YbSyncStatus,
  3824. }
  3825. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3826. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3827. }
  3828. if nowCount == historyCount {
  3829. if historyCount == 0 {
  3830. recordDateStr := time.Now().Format("2006-01-02")
  3831. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3832. nowtime := recordDate.Unix()
  3833. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3834. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3835. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3836. creater := c.GetAdminUserInfo().AdminUser.Id
  3837. dialyPrepareOne := models.DialysisBeforePrepare{
  3838. GoodTypeId: goodObj.GoodTypeId,
  3839. GoodId: p.ProjectId,
  3840. PatientId: p.PatientId,
  3841. RecordDate: p.RecordDate,
  3842. UserOrgId: adminInfo.CurrentOrgId,
  3843. Count: nowCount,
  3844. Ctime: time.Now().Unix(),
  3845. Creater: creater,
  3846. Status: 1,
  3847. StorehouseId: houseConfig.StorehouseOutInfo,
  3848. ProjectId: p.ID,
  3849. }
  3850. //出库
  3851. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3852. }
  3853. }
  3854. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3855. //查询历史出库数据
  3856. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3857. var out_count_five int64
  3858. for _, item := range flowGood {
  3859. out_count_five += item.Count
  3860. }
  3861. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3862. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3863. if out_count_five != parseIntCount {
  3864. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3865. detail := models.AutomaticReduceDetail{
  3866. WarehouseOutId: 0,
  3867. WarehouseOutOrderNumber: "",
  3868. PatientId: p.PatientId,
  3869. Ctime: time.Now().Unix(),
  3870. Mtime: 0,
  3871. Status: 1,
  3872. RecordTime: p.RecordDate,
  3873. OrgId: p.UserOrgId,
  3874. GoodId: p.ProjectId,
  3875. GoodTypeId: 0,
  3876. Count: parseIntCount,
  3877. Type: 0,
  3878. ProjectId: lastHisProject.ID,
  3879. StorehouseId: 0,
  3880. }
  3881. service.CreateNewAutoDetail(detail, tx)
  3882. }
  3883. // //查询耗材最后一次出库记录
  3884. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3885. // //查询默认出库仓库库存
  3886. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3887. // if len(wareOut) > 0 {
  3888. //
  3889. // for _, it := range wareOut {
  3890. // //回退库存
  3891. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3892. //
  3893. // //删除出库记录
  3894. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3895. //
  3896. // }
  3897. // }
  3898. //
  3899. // timeStr := time.Now().Format("2006-01-02")
  3900. // timeArr := strings.Split(timeStr, "-")
  3901. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3902. //
  3903. // total = total + 1
  3904. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3905. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3906. // number = number + total
  3907. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3908. //
  3909. // operation_time := time.Now().Unix()
  3910. // creater := c.GetAdminUserInfo().AdminUser.Id
  3911. //
  3912. // recordDateStr := time.Now().Format("2006-01-02")
  3913. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3914. // nowtime := recordDate.Unix()
  3915. // warehouseOut := models.WarehouseOut{
  3916. // WarehouseOutOrderNumber: warehousing_out_order,
  3917. // OperationTime: operation_time,
  3918. // OrgId: adminInfo.CurrentOrgId,
  3919. // Creater: creater,
  3920. // Ctime: time.Now().Unix(),
  3921. // Status: 1,
  3922. // WarehouseOutTime: nowtime,
  3923. // Type: 1,
  3924. // StorehouseId: storeConfig.StorehouseOutInfo,
  3925. // IsCheck: 1,
  3926. // IsSys: 1,
  3927. // }
  3928. // //查询是否生成出库单
  3929. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3930. // if out.ID == 0 {
  3931. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3932. // }
  3933. //
  3934. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3935. //
  3936. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3937. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3938. //
  3939. // dialyPrepareOne := models.DialysisBeforePrepare{
  3940. // GoodTypeId: goodObj.GoodTypeId,
  3941. // GoodId: p.ProjectId,
  3942. // PatientId: p.PatientId,
  3943. // RecordDate: p.RecordDate,
  3944. // UserOrgId: adminInfo.CurrentOrgId,
  3945. // Count: parseIntCount,
  3946. // Ctime: time.Now().Unix(),
  3947. // Creater: creater,
  3948. // Status: 1,
  3949. // StorehouseId: houseConfig.StorehouseOutInfo,
  3950. // ProjectId: lastHisProject.ID,
  3951. // }
  3952. // //判断是否是零用耗材(非零用)
  3953. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3954. //
  3955. // //查询历史出库数据
  3956. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3957. // var out_count int64
  3958. // for _, item := range flowGood {
  3959. // out_count += item.Count
  3960. // }
  3961. // //如果历史数和当前数据不想等才进行退库出库
  3962. // if out_count != parseIntCount {
  3963. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3964. //
  3965. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3966. // detail := models.AutomaticReduceDetail{
  3967. // WarehouseOutId: 0,
  3968. // WarehouseOutOrderNumber: "",
  3969. // PatientId: p.PatientId,
  3970. // Ctime: time.Now().Unix(),
  3971. // Mtime: 0,
  3972. // Status: 1,
  3973. // RecordTime: p.RecordDate,
  3974. // OrgId: p.UserOrgId,
  3975. // GoodId: p.ProjectId,
  3976. // GoodTypeId: 0,
  3977. // Count: parseIntCount,
  3978. // Type: 0,
  3979. // ProjectId: lastHisProject.ID,
  3980. // StorehouseId: 0,
  3981. // }
  3982. //
  3983. // service.CreateNewAutoDetail(detail, tx)
  3984. //
  3985. // //查询剩余库存
  3986. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3987. // var sum_count int64
  3988. // for _, item := range goodList {
  3989. // sum_count += item.StockCount
  3990. // }
  3991. //
  3992. // //更新剩余库存
  3993. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3994. //
  3995. // //耗材
  3996. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3997. //
  3998. // }
  3999. // //判断是否是零用耗材(零用但是是出库耗材)
  4000. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4001. //
  4002. // //查询历史出库数据
  4003. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4004. // var out_count int64
  4005. // for _, item := range flowGood {
  4006. // out_count += item.Count
  4007. // }
  4008. // //如果历史数和当前数据不想等才进行退库出库
  4009. // if out_count != parseIntCount {
  4010. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4011. //
  4012. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4013. // detail := models.AutomaticReduceDetail{
  4014. // WarehouseOutId: 0,
  4015. // WarehouseOutOrderNumber: "",
  4016. // PatientId: p.PatientId,
  4017. // Ctime: time.Now().Unix(),
  4018. // Mtime: 0,
  4019. // Status: 1,
  4020. // RecordTime: p.RecordDate,
  4021. // OrgId: p.UserOrgId,
  4022. // GoodId: p.ProjectId,
  4023. // GoodTypeId: 0,
  4024. // Count: parseIntCount,
  4025. // Type: 0,
  4026. // ProjectId: p.ID,
  4027. // StorehouseId: 0,
  4028. // }
  4029. //
  4030. // service.CreateNewAutoDetail(detail, tx)
  4031. //
  4032. // //查询剩余库存
  4033. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4034. // var sum_count int64
  4035. // for _, item := range goodList {
  4036. // sum_count += item.StockCount
  4037. // }
  4038. //
  4039. // //更新剩余库存
  4040. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4041. //
  4042. // //耗材
  4043. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4044. // }
  4045. //
  4046. // }
  4047. //
  4048. // }
  4049. //
  4050. //}
  4051. //记录日志
  4052. byterequest, _ := json.Marshal(p)
  4053. adviceLog := models.XtDoctorAdviceLog{
  4054. UserOrgId: p.UserOrgId,
  4055. PatientId: p.PatientId,
  4056. AdminUserId: adminInfo.AdminUser.Id,
  4057. Module: 1,
  4058. ErrLog: string(byterequest),
  4059. Status: 1,
  4060. Ctime: time.Now().Unix(),
  4061. Mtime: 0,
  4062. Source: "电脑端新建his项目",
  4063. RecordDate: p.RecordDate,
  4064. }
  4065. service.CreateDoctorAdviceLog(adviceLog)
  4066. projectList = append(projectList, p)
  4067. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4068. //新增或者编辑项目,修改对应的标签数据
  4069. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4070. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4071. var label models.HisLabelPrintInfo
  4072. project, _ := service.GetProjectDetail(p.ProjectId)
  4073. if project.CostClassify == 3 { //类别为检验检查
  4074. if p.TeamId > 0 { //检验检查组套
  4075. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4076. if tempLabel.ID == 0 {
  4077. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4078. label.Number = tempPrescription.PrescriptionNumber
  4079. label.ProjectId = project.ID
  4080. label.Status = 1
  4081. label.IsPrint = 2
  4082. label.DoctorId = info.DoctorId
  4083. label.UserOrgId = p.UserOrgId
  4084. label.PatientId = patient_id
  4085. label.RecordDate = recordDateTime
  4086. label.Ctime = time.Now().Unix()
  4087. label.Mtime = time.Now().Unix()
  4088. label.ItemId = p.TeamId
  4089. label.FeedetlSn = p.FeedetlSn
  4090. label.PProjectId = p.ID
  4091. label.ProjectName = team.ProjectTeam
  4092. label.PatientName = patient.Name
  4093. service.CreateNewHisLabelRecord(&label, tx)
  4094. }
  4095. } else { //单条检验检查项目
  4096. label.Number = tempPrescription.PrescriptionNumber
  4097. label.ProjectId = project.ID
  4098. label.Status = 1
  4099. label.DoctorId = info.DoctorId
  4100. label.UserOrgId = p.UserOrgId
  4101. label.PatientId = patient_id
  4102. label.RecordDate = recordDateTime
  4103. label.IsPrint = 2
  4104. label.Ctime = time.Now().Unix()
  4105. label.Mtime = time.Now().Unix()
  4106. label.FeedetlSn = p.FeedetlSn
  4107. label.PProjectId = p.ID
  4108. label.ItemId = p.TeamId
  4109. label.ProjectName = project.ProjectName
  4110. label.PatientName = patient.Name
  4111. service.CreateNewHisLabelRecord(&label, tx)
  4112. }
  4113. }
  4114. }
  4115. }
  4116. }
  4117. }
  4118. }
  4119. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4120. //耗材出库
  4121. if p.Type == 3 {
  4122. //对比当前数据和历史出库数据
  4123. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4124. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4125. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4126. //如果当前处方数量大于历史数据,则需要出库
  4127. if nowCount > historyCount {
  4128. var cha_count int64
  4129. cha_count = nowCount - historyCount
  4130. timeStr := time.Now().Format("2006-01-02")
  4131. timeArr := strings.Split(timeStr, "-")
  4132. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4133. total = total + 1
  4134. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4135. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4136. number = number + total
  4137. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4138. operation_time := time.Now().Unix()
  4139. creater := c.GetAdminUserInfo().AdminUser.Id
  4140. recordDateStr := time.Now().Format("2006-01-02")
  4141. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4142. nowtime := recordDate.Unix()
  4143. warehouseOut := models.WarehouseOut{
  4144. WarehouseOutOrderNumber: warehousing_out_order,
  4145. OperationTime: operation_time,
  4146. OrgId: adminInfo.CurrentOrgId,
  4147. Creater: creater,
  4148. Ctime: time.Now().Unix(),
  4149. Status: 1,
  4150. WarehouseOutTime: nowtime,
  4151. Type: 1,
  4152. StorehouseId: storeConfig.StorehouseOutInfo,
  4153. IsCheck: 1,
  4154. IsSys: 1,
  4155. }
  4156. //查询是否生成出库单
  4157. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4158. if out.ID == 0 {
  4159. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4160. }
  4161. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4162. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4163. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4164. dialyPrepareOne := models.DialysisBeforePrepare{
  4165. GoodTypeId: goodObj.GoodTypeId,
  4166. GoodId: p.ProjectId,
  4167. PatientId: p.PatientId,
  4168. RecordDate: p.RecordDate,
  4169. UserOrgId: adminInfo.CurrentOrgId,
  4170. Count: cha_count,
  4171. Ctime: time.Now().Unix(),
  4172. Creater: creater,
  4173. Status: 1,
  4174. StorehouseId: houseConfig.StorehouseOutInfo,
  4175. ProjectId: p.ID,
  4176. }
  4177. //出库
  4178. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4179. }
  4180. //如果当前处方数量小于历史数据,怎需要退库
  4181. if nowCount < historyCount {
  4182. var cha_count int64
  4183. cha_count = historyCount - nowCount
  4184. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4185. creater := c.GetAdminUserInfo().AdminUser.Id
  4186. newPrescriptionProject := &models.HisPrescriptionProject{
  4187. ID: p.ID,
  4188. ProjectId: p.ProjectId,
  4189. Price: p.Price,
  4190. UserOrgId: p.UserOrgId,
  4191. Status: 1,
  4192. Ctime: time.Now().Unix(),
  4193. Mtime: time.Now().Unix(),
  4194. PatientId: p.PatientId,
  4195. HisPatientId: p.HisPatientId,
  4196. RecordDate: p.RecordDate,
  4197. PrescriptionId: p.PrescriptionId,
  4198. Count: p.Count,
  4199. FeedetlSn: p.FeedetlSn,
  4200. MedListCodg: p.MedListCodg,
  4201. SingleDose: p.SingleDose,
  4202. DeliveryWay: p.DeliveryWay,
  4203. ExecutionFrequency: p.ExecutionFrequency,
  4204. Day: p.Day,
  4205. HisProject: models.HisProject{},
  4206. GoodInfo: models.GoodInfo{},
  4207. Remark: p.Remark,
  4208. Unit: p.Unit,
  4209. Type: p.Type,
  4210. Doctor: p.Doctor,
  4211. ExecutionTime: p.ExecutionTime,
  4212. ExecutionStaff: p.ExecutionStaff,
  4213. ExecutionState: p.ExecutionState,
  4214. CheckTime: p.CheckTime,
  4215. CheckState: p.CheckState,
  4216. Checker: p.Checker,
  4217. StartTime: p.StartTime,
  4218. TeamId: p.TeamId,
  4219. XtHisProjectTeam: models.XtHisProjectTeam{},
  4220. FrequencyType: p.FrequencyType,
  4221. DayCount: p.DayCount,
  4222. WeekDay: p.WeekDay,
  4223. IsCheckTeam: p.IsCheckTeam,
  4224. HisOrderInfo: models.HisOrderInfo{},
  4225. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4226. IsOut: p.IsOut,
  4227. YbSyncStatus: p.YbSyncStatus,
  4228. }
  4229. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4230. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4231. }
  4232. if nowCount == historyCount {
  4233. if historyCount == 0 {
  4234. recordDateStr := time.Now().Format("2006-01-02")
  4235. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4236. nowtime := recordDate.Unix()
  4237. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4238. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4239. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4240. creater := c.GetAdminUserInfo().AdminUser.Id
  4241. dialyPrepareOne := models.DialysisBeforePrepare{
  4242. GoodTypeId: goodObj.GoodTypeId,
  4243. GoodId: p.ProjectId,
  4244. PatientId: p.PatientId,
  4245. RecordDate: p.RecordDate,
  4246. UserOrgId: adminInfo.CurrentOrgId,
  4247. Count: nowCount,
  4248. Ctime: time.Now().Unix(),
  4249. Creater: creater,
  4250. Status: 1,
  4251. StorehouseId: houseConfig.StorehouseOutInfo,
  4252. ProjectId: p.ID,
  4253. }
  4254. //出库
  4255. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4256. }
  4257. }
  4258. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4259. //查询历史出库数据
  4260. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4261. var out_count_five int64
  4262. for _, item := range flowGood {
  4263. out_count_five += item.Count
  4264. }
  4265. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4266. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4267. if out_count_five != parseIntCount {
  4268. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4269. detail := models.AutomaticReduceDetail{
  4270. WarehouseOutId: 0,
  4271. WarehouseOutOrderNumber: "",
  4272. PatientId: p.PatientId,
  4273. Ctime: time.Now().Unix(),
  4274. Mtime: 0,
  4275. Status: 1,
  4276. RecordTime: p.RecordDate,
  4277. OrgId: p.UserOrgId,
  4278. GoodId: p.ProjectId,
  4279. GoodTypeId: 0,
  4280. Count: parseIntCount,
  4281. Type: 0,
  4282. ProjectId: lastHisProject.ID,
  4283. StorehouseId: 0,
  4284. }
  4285. service.CreateNewAutoDetail(detail, tx)
  4286. }
  4287. // //查询耗材最后一次出库记录
  4288. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4289. // //查询默认出库仓库库存
  4290. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4291. // if len(wareOut) > 0 {
  4292. //
  4293. // for _, it := range wareOut {
  4294. // //回退库存
  4295. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4296. //
  4297. // //删除出库记录
  4298. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4299. //
  4300. // }
  4301. // }
  4302. //
  4303. // timeStr := time.Now().Format("2006-01-02")
  4304. // timeArr := strings.Split(timeStr, "-")
  4305. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4306. //
  4307. // total = total + 1
  4308. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4309. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4310. // number = number + total
  4311. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4312. //
  4313. // operation_time := time.Now().Unix()
  4314. // creater := c.GetAdminUserInfo().AdminUser.Id
  4315. //
  4316. // recordDateStr := time.Now().Format("2006-01-02")
  4317. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4318. // nowtime := recordDate.Unix()
  4319. // warehouseOut := models.WarehouseOut{
  4320. // WarehouseOutOrderNumber: warehousing_out_order,
  4321. // OperationTime: operation_time,
  4322. // OrgId: adminInfo.CurrentOrgId,
  4323. // Creater: creater,
  4324. // Ctime: time.Now().Unix(),
  4325. // Status: 1,
  4326. // WarehouseOutTime: nowtime,
  4327. // Type: 1,
  4328. // StorehouseId: storeConfig.StorehouseOutInfo,
  4329. // IsCheck: 1,
  4330. // IsSys: 1,
  4331. // }
  4332. // //查询是否生成出库单
  4333. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4334. // if out.ID == 0 {
  4335. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4336. // }
  4337. //
  4338. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4339. //
  4340. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4341. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4342. //
  4343. // dialyPrepareOne := models.DialysisBeforePrepare{
  4344. // GoodTypeId: goodObj.GoodTypeId,
  4345. // GoodId: p.ProjectId,
  4346. // PatientId: p.PatientId,
  4347. // RecordDate: p.RecordDate,
  4348. // UserOrgId: adminInfo.CurrentOrgId,
  4349. // Count: parseIntCount,
  4350. // Ctime: time.Now().Unix(),
  4351. // Creater: creater,
  4352. // Status: 1,
  4353. // StorehouseId: houseConfig.StorehouseOutInfo,
  4354. // ProjectId: lastHisProject.ID,
  4355. // }
  4356. // //判断是否是零用耗材(非零用)
  4357. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4358. //
  4359. // //查询历史出库数据
  4360. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4361. // var out_count int64
  4362. // for _, item := range flowGood {
  4363. // out_count += item.Count
  4364. // }
  4365. // //如果历史数和当前数据不想等才进行退库出库
  4366. // if out_count != parseIntCount {
  4367. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4368. //
  4369. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4370. // detail := models.AutomaticReduceDetail{
  4371. // WarehouseOutId: 0,
  4372. // WarehouseOutOrderNumber: "",
  4373. // PatientId: p.PatientId,
  4374. // Ctime: time.Now().Unix(),
  4375. // Mtime: 0,
  4376. // Status: 1,
  4377. // RecordTime: p.RecordDate,
  4378. // OrgId: p.UserOrgId,
  4379. // GoodId: p.ProjectId,
  4380. // GoodTypeId: 0,
  4381. // Count: parseIntCount,
  4382. // Type: 0,
  4383. // ProjectId: lastHisProject.ID,
  4384. // StorehouseId: 0,
  4385. // }
  4386. //
  4387. // service.CreateNewAutoDetail(detail, tx)
  4388. //
  4389. // //查询剩余库存
  4390. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4391. // var sum_count int64
  4392. // for _, item := range goodList {
  4393. // sum_count += item.StockCount
  4394. // }
  4395. //
  4396. // //更新剩余库存
  4397. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4398. //
  4399. // //耗材
  4400. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4401. //
  4402. // }
  4403. // //判断是否是零用耗材(零用但是是出库耗材)
  4404. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4405. //
  4406. // //查询历史出库数据
  4407. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4408. // var out_count int64
  4409. // for _, item := range flowGood {
  4410. // out_count += item.Count
  4411. // }
  4412. // //如果历史数和当前数据不想等才进行退库出库
  4413. // if out_count != parseIntCount {
  4414. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4415. //
  4416. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4417. // detail := models.AutomaticReduceDetail{
  4418. // WarehouseOutId: 0,
  4419. // WarehouseOutOrderNumber: "",
  4420. // PatientId: p.PatientId,
  4421. // Ctime: time.Now().Unix(),
  4422. // Mtime: 0,
  4423. // Status: 1,
  4424. // RecordTime: p.RecordDate,
  4425. // OrgId: p.UserOrgId,
  4426. // GoodId: p.ProjectId,
  4427. // GoodTypeId: 0,
  4428. // Count: parseIntCount,
  4429. // Type: 0,
  4430. // ProjectId: p.ID,
  4431. // StorehouseId: 0,
  4432. // }
  4433. //
  4434. // service.CreateNewAutoDetail(detail, tx)
  4435. //
  4436. // //查询剩余库存
  4437. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4438. // var sum_count int64
  4439. // for _, item := range goodList {
  4440. // sum_count += item.StockCount
  4441. // }
  4442. //
  4443. // //更新剩余库存
  4444. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4445. //
  4446. // //耗材
  4447. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4448. // }
  4449. //
  4450. // }
  4451. //
  4452. // }
  4453. //
  4454. //}
  4455. //记录日志
  4456. byterequest, _ := json.Marshal(p)
  4457. adviceLog := models.XtDoctorAdviceLog{
  4458. UserOrgId: p.UserOrgId,
  4459. PatientId: p.PatientId,
  4460. AdminUserId: adminInfo.AdminUser.Id,
  4461. Module: 1,
  4462. ErrLog: string(byterequest),
  4463. Status: 1,
  4464. Ctime: time.Now().Unix(),
  4465. Mtime: 0,
  4466. Source: "电脑端新建his项目",
  4467. RecordDate: p.RecordDate,
  4468. }
  4469. service.CreateDoctorAdviceLog(adviceLog)
  4470. projectList = append(projectList, p)
  4471. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4472. //新增或者编辑项目,修改对应的标签数据
  4473. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4474. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4475. var label models.HisLabelPrintInfo
  4476. project, _ := service.GetProjectDetail(p.ProjectId)
  4477. if project.CostClassify == 3 { //类别为检验检查
  4478. if p.TeamId > 0 { //检验检查组套
  4479. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4480. if tempLabel.ID == 0 {
  4481. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4482. label.Number = tempPrescription.PrescriptionNumber
  4483. label.ProjectId = project.ID
  4484. label.Status = 1
  4485. label.IsPrint = 2
  4486. label.DoctorId = info.DoctorId
  4487. label.UserOrgId = p.UserOrgId
  4488. label.PatientId = patient_id
  4489. label.RecordDate = recordDateTime
  4490. label.Ctime = time.Now().Unix()
  4491. label.Mtime = time.Now().Unix()
  4492. label.ItemId = p.TeamId
  4493. label.FeedetlSn = p.FeedetlSn
  4494. label.PProjectId = p.ID
  4495. label.ProjectName = team.ProjectTeam
  4496. label.PatientName = patient.Name
  4497. service.CreateNewHisLabelRecord(&label, tx)
  4498. }
  4499. } else { //单条检验检查项目
  4500. label.Number = tempPrescription.PrescriptionNumber
  4501. label.ProjectId = project.ID
  4502. label.Status = 1
  4503. label.DoctorId = info.DoctorId
  4504. label.UserOrgId = p.UserOrgId
  4505. label.PatientId = patient_id
  4506. label.RecordDate = recordDateTime
  4507. label.IsPrint = 2
  4508. label.Ctime = time.Now().Unix()
  4509. label.Mtime = time.Now().Unix()
  4510. label.FeedetlSn = p.FeedetlSn
  4511. label.PProjectId = p.ID
  4512. label.ItemId = p.TeamId
  4513. label.ProjectName = project.ProjectName
  4514. label.PatientName = patient.Name
  4515. service.CreateNewHisLabelRecord(&label, tx)
  4516. }
  4517. }
  4518. }
  4519. }
  4520. }
  4521. }
  4522. }
  4523. //插入检验数据
  4524. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4525. //新增或者编辑项目,修改对应的标签数据
  4526. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4527. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4528. var label models.HisLabelPrintInfo
  4529. project, _ := service.GetProjectDetail(p.ProjectId)
  4530. if project.CostClassify == 3 { //类别为检验检查
  4531. if p.TeamId > 0 { //检验检查组套
  4532. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4533. if tempLabel.ID == 0 {
  4534. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4535. label.Number = tempPrescription.PrescriptionNumber
  4536. label.ProjectId = project.ID
  4537. label.Status = 1
  4538. label.IsPrint = 2
  4539. label.DoctorId = info.DoctorId
  4540. label.UserOrgId = p.UserOrgId
  4541. label.PatientId = patient_id
  4542. label.RecordDate = recordDateTime
  4543. label.Ctime = time.Now().Unix()
  4544. label.Mtime = time.Now().Unix()
  4545. label.ItemId = p.TeamId
  4546. label.FeedetlSn = p.FeedetlSn
  4547. label.PProjectId = p.ID
  4548. label.ProjectName = team.ProjectTeam
  4549. label.PatientName = patient.Name
  4550. service.CreateHisLabelRecord(&label)
  4551. }
  4552. } else { //单条检验检查项目
  4553. label.Number = tempPrescription.PrescriptionNumber
  4554. label.ProjectId = project.ID
  4555. label.Status = 1
  4556. label.DoctorId = info.DoctorId
  4557. label.UserOrgId = p.UserOrgId
  4558. label.PatientId = patient_id
  4559. label.RecordDate = recordDateTime
  4560. label.IsPrint = 2
  4561. label.Ctime = time.Now().Unix()
  4562. label.Mtime = time.Now().Unix()
  4563. label.FeedetlSn = p.FeedetlSn
  4564. label.PProjectId = p.ID
  4565. label.ItemId = p.TeamId
  4566. label.ProjectName = project.ProjectName
  4567. label.PatientName = patient.Name
  4568. service.CreateHisLabelRecord(&label)
  4569. }
  4570. }
  4571. }
  4572. }
  4573. service.CreateNewHisProjectTwo(&p, tx)
  4574. var randNum int
  4575. randNum = rand.Intn(10000) + 1000
  4576. timestamp := time.Now().Unix()
  4577. tempTime := time.Unix(timestamp, 0)
  4578. timeFormat := tempTime.Format("20060102150405")
  4579. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4580. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4581. if goodBase.ID > 0 {
  4582. tx.Rollback()
  4583. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4584. return
  4585. }
  4586. service.CreateNewHisProjectTwo(&p, tx)
  4587. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4588. //查询剩余库存
  4589. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4590. var sum_count int64
  4591. for _, item := range goodList {
  4592. sum_count += item.StockCount
  4593. }
  4594. //更新剩余库存
  4595. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4596. //耗材
  4597. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4598. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4599. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4600. if len(outInfoTwo) > 0 {
  4601. for _, item := range outInfoTwo {
  4602. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4603. }
  4604. }
  4605. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4606. if len(drugAutoDetail) > 0 {
  4607. for _, item := range drugAutoDetail {
  4608. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4609. }
  4610. }
  4611. tx.Commit()
  4612. }
  4613. }
  4614. }
  4615. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4616. // addition := items["addition"].([]interface{})
  4617. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4618. // ctime := time.Now().Unix()
  4619. // mtime := ctime
  4620. // if len(addition) > 0 {
  4621. // for _, item := range addition {
  4622. // var s models.HisAdditionalCharge
  4623. // s.PrescriptionId = tempPrescription.ID
  4624. // s.Status = 1
  4625. // s.UserOrgId = adminInfo.CurrentOrgId
  4626. // s.RecordDate = recordDateTime
  4627. // s.CreatedTime = ctime
  4628. // s.UpdatedTime = mtime
  4629. // s.PatientId = patient_id
  4630. // s.HisPatientId = his_patient_id
  4631. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4632. // if errcode > 0 {
  4633. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4634. // return
  4635. // }
  4636. // service.CreateAdditionalCharge(&s)
  4637. // var randNum int
  4638. // randNum = rand.Intn(10000) + 1000
  4639. // timestamp := time.Now().Unix()
  4640. // tempTime := time.Unix(timestamp, 0)
  4641. // timeFormat := tempTime.Format("20060102150405")
  4642. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4643. // service.CreateAdditionalCharge(&s)
  4644. //
  4645. // }
  4646. // }
  4647. //}
  4648. }
  4649. }
  4650. }
  4651. tx.Commit()
  4652. if err == nil {
  4653. c.ServeSuccessJSON(map[string]interface{}{
  4654. "msg": "保存成功",
  4655. })
  4656. return
  4657. } else {
  4658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4659. return
  4660. }
  4661. } else {
  4662. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4663. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4664. var tempPrescription *models.HisPrescription
  4665. if len(prescriptions) > 0 {
  4666. for _, item := range prescriptions {
  4667. items := item.(map[string]interface{})
  4668. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4669. utils.ErrorLog("id")
  4670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4671. return
  4672. }
  4673. id := int64(items["id"].(float64))
  4674. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4675. tempPrescription = &new_prescription
  4676. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4677. utils.ErrorLog("type")
  4678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4679. return
  4680. }
  4681. types := int64(items["type"].(float64))
  4682. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4683. utils.ErrorLog("med_type")
  4684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4685. return
  4686. }
  4687. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4688. if med_type == "0" {
  4689. med_type = "14"
  4690. }
  4691. //if order_status == 0 {
  4692. // order_status = 1
  4693. //}
  4694. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4695. // utils.ErrorLog("diagnoses")
  4696. //}
  4697. diagnoses, _ := items["diagnoses"].(string)
  4698. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4699. utils.ErrorLog("pre_time")
  4700. }
  4701. preTime, _ := items["pre_time"].(string)
  4702. timeLayout := "2006-01-02"
  4703. loc, _ := time.LoadLocation("Local")
  4704. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4705. //result := strings.Split(preTime, " ")
  4706. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4707. if err != nil {
  4708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4709. return
  4710. }
  4711. pTime := theTime2.Unix()
  4712. ctime := time.Now().Unix()
  4713. if tempPrescription.ID == 0 {
  4714. prescription := &models.HisPrescription{
  4715. ID: 0,
  4716. PatientId: patient_id,
  4717. UserOrgId: adminInfo.CurrentOrgId,
  4718. RecordDate: recordDateTime,
  4719. Ctime: ctime,
  4720. Mtime: ctime,
  4721. Type: types,
  4722. Modifier: adminInfo.AdminUser.Id,
  4723. Creator: adminInfo.AdminUser.Id,
  4724. Status: 1,
  4725. Doctor: role.UserName,
  4726. HisPatientId: his_patient_id,
  4727. OrderStatus: 1,
  4728. BatchNumber: "",
  4729. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4730. PreTime: pTime,
  4731. PType: p_type,
  4732. MedType: med_type,
  4733. Diagnose: diagnoses,
  4734. }
  4735. tempPrescription = prescription
  4736. service.SaveHisPrescription(tempPrescription)
  4737. redis := service.RedisClient()
  4738. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4739. redis.Set(key, "", time.Second)
  4740. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4741. redis.Set(keyOne, "", time.Second)
  4742. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4743. redis.Set(keySeven, "", time.Second)
  4744. defer redis.Close()
  4745. } else {
  4746. tempPrescription.ID = id
  4747. tempPrescription.Type = types
  4748. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4749. tempPrescription.Mtime = time.Now().Unix()
  4750. tempPrescription.Doctor = role.UserName
  4751. //tempPrescription.OrderStatus = order_status
  4752. tempPrescription.PreTime = pTime
  4753. tempPrescription.MedType = med_type
  4754. tempPrescription.Diagnose = diagnoses
  4755. service.SaveHisPrescription(tempPrescription)
  4756. redis := service.RedisClient()
  4757. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4758. redis.Set(key, "", time.Second)
  4759. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4760. redis.Set(keyOne, "", time.Second)
  4761. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4762. redis.Set(keySeven, "", time.Second)
  4763. defer redis.Close()
  4764. }
  4765. //service.SaveHisPrescription(prescription)
  4766. //更改患者挂号状态
  4767. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4768. fmt.Println("更改失败", err2)
  4769. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4770. advices := items["advices"].([]interface{})
  4771. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4772. groupNo := int64(0)
  4773. if len(advices) > 0 {
  4774. for _, advice := range advices {
  4775. var s models.HisDoctorAdviceInfo
  4776. s.PrescriptionId = tempPrescription.ID
  4777. s.AdviceType = 2
  4778. s.AdviceDoctor = doctor_id
  4779. s.StopState = 2
  4780. s.ExecutionState = 2
  4781. s.AdviceDate = theTime3.Unix()
  4782. s.Status = 1
  4783. s.UserOrgId = adminInfo.CurrentOrgId
  4784. s.RecordDate = theTime3.Unix()
  4785. s.StartTime = tempPrescription.PreTime
  4786. s.Groupno = groupNo
  4787. s.PatientId = patient_id
  4788. s.HisPatientId = his_patient_id
  4789. s.StartTime = pTime
  4790. s.IsSettle = 2
  4791. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4792. if errcode > 0 {
  4793. c.ServeFailJSONWithSGJErrorCode(errcode)
  4794. return
  4795. }
  4796. s.StartTime = pTime
  4797. var total_count int64 //处方总库存
  4798. //查询改药品信息
  4799. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4800. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4801. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4802. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4803. total_count += prescribingNumberSeven * medical.MinNumber
  4804. }
  4805. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4806. total_count += prescribingNumberSeven
  4807. }
  4808. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4809. total_count += prescribingNumberSeven
  4810. }
  4811. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4812. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4813. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4814. if s.Price != lastWarehouse.RetailPrice {
  4815. s.Price = lastWarehouse.RetailPrice
  4816. }
  4817. if s.Price == 0 {
  4818. if lastWarehouse.ID == 0 {
  4819. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4820. s.Price = lastWarehouseTwo.RetailPrice
  4821. }
  4822. }
  4823. }
  4824. if adminInfo.CurrentOrgId != 10206 {
  4825. if s.ID == 0 {
  4826. //查询改药品是否已经停用
  4827. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4828. if base.ID > 0 {
  4829. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4830. return
  4831. }
  4832. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4833. if drugMedical.SumCount == 0 {
  4834. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4835. return
  4836. }
  4837. }
  4838. }
  4839. //赤峰
  4840. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4841. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4842. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4843. if info.RetailPrice > 0 {
  4844. if s.DeliveryWay == "口服" {
  4845. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4846. s.Price = drug.RetailPrice
  4847. }
  4848. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4849. s.Price = info.RetailPrice
  4850. }
  4851. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4852. s.Price = info.RetailPrice
  4853. }
  4854. }
  4855. }
  4856. }
  4857. service.CreateHisDoctorAdvice(&s)
  4858. //记录日志
  4859. byterequest, _ := json.Marshal(s)
  4860. adviceLog := models.XtDoctorAdviceLog{
  4861. UserOrgId: s.UserOrgId,
  4862. PatientId: s.PatientId,
  4863. AdminUserId: adminInfo.AdminUser.Id,
  4864. Module: 1,
  4865. ErrLog: string(byterequest),
  4866. Status: 1,
  4867. Ctime: time.Now().Unix(),
  4868. Mtime: 0,
  4869. Source: "电脑端新建his医嘱",
  4870. RecordDate: s.AdviceDate,
  4871. }
  4872. service.CreateDoctorAdviceLog(adviceLog)
  4873. //存储切片中
  4874. adviceList = append(adviceList, s)
  4875. redis := service.RedisClient()
  4876. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4877. redis.Set(key, "", time.Second)
  4878. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4879. redis.Set(keyOne, "", time.Second)
  4880. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4881. redis.Set(keySeven, "", time.Second)
  4882. var randNum int
  4883. randNum = rand.Intn(10000) + 1000
  4884. timestamp := time.Now().Unix()
  4885. tempTime := time.Unix(timestamp, 0)
  4886. timeFormat := tempTime.Format("20060102150405")
  4887. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4888. service.CreateHisDoctorAdvice(&s)
  4889. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4890. redis.Set(keySix, "", time.Second)
  4891. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4892. redis.Set(keyFive, "", time.Second)
  4893. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4894. redis.Set(keyEight, "", time.Second)
  4895. defer redis.Close()
  4896. }
  4897. }
  4898. }
  4899. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4900. projects := items["project"].([]interface{})
  4901. if len(projects) > 0 {
  4902. for _, project := range projects {
  4903. var p models.HisPrescriptionProject
  4904. p.PrescriptionId = tempPrescription.ID
  4905. p.PatientId = patient_id
  4906. p.RecordDate = theTime3.Unix()
  4907. p.Doctor = doctor_id
  4908. p.UserOrgId = adminInfo.CurrentOrgId
  4909. p.HisPatientId = his_patient_id
  4910. p.Status = 1
  4911. p.StartTime = pTime
  4912. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4913. if errcode > 0 {
  4914. c.ServeFailJSONWithSGJErrorCode(errcode)
  4915. return
  4916. }
  4917. if p.ID == 0 {
  4918. p.IsOut = 2
  4919. }
  4920. if p.ID > 0 {
  4921. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4922. p.IsOut = projectDetail.IsOut
  4923. }
  4924. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4925. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4926. if p.Type == 3 {
  4927. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4928. if p.Price != lastWarehouse.PackingPrice {
  4929. p.Price = lastWarehouse.PackingPrice
  4930. }
  4931. if p.Price == 0 {
  4932. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4933. p.Price = lastWarehouseTwo.PackingPrice
  4934. }
  4935. if p.Unit == "" {
  4936. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4937. p.Unit = goodInfoOne.PackingUnit
  4938. }
  4939. }
  4940. }
  4941. if adminInfo.CurrentOrgId != 10206 {
  4942. if p.Type == 3 {
  4943. if p.ID == 0 {
  4944. //查询该耗材是否停用
  4945. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4946. //表示该耗材已经停用,不能保存
  4947. if goodInfoSeven.ID == 0 {
  4948. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4949. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4950. return
  4951. }
  4952. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4953. if goodInfoOne.SumCount == 0 {
  4954. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4955. return
  4956. }
  4957. }
  4958. }
  4959. }
  4960. service.CreateHisProjectTwo(&p)
  4961. //记录日志
  4962. byterequest, _ := json.Marshal(p)
  4963. adviceLog := models.XtDoctorAdviceLog{
  4964. UserOrgId: p.UserOrgId,
  4965. PatientId: p.PatientId,
  4966. AdminUserId: adminInfo.AdminUser.Id,
  4967. Module: 1,
  4968. ErrLog: string(byterequest),
  4969. Status: 1,
  4970. Ctime: time.Now().Unix(),
  4971. Mtime: 0,
  4972. Source: "电脑端新建his项目",
  4973. RecordDate: p.RecordDate,
  4974. }
  4975. service.CreateDoctorAdviceLog(adviceLog)
  4976. projectList = append(projectList, p)
  4977. var randNum int
  4978. randNum = rand.Intn(10000) + 1000
  4979. timestamp := time.Now().Unix()
  4980. tempTime := time.Unix(timestamp, 0)
  4981. timeFormat := tempTime.Format("20060102150405")
  4982. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4983. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4984. //新增或者编辑项目,修改对应的标签数据
  4985. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4986. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4987. var label models.HisLabelPrintInfo
  4988. project, _ := service.GetProjectDetail(p.ProjectId)
  4989. if project.CostClassify == 3 { //类别为检验检查
  4990. if p.TeamId > 0 { //检验检查组套
  4991. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4992. if tempLabel.ID == 0 {
  4993. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4994. label.Number = tempPrescription.PrescriptionNumber
  4995. label.ProjectId = project.ID
  4996. label.Status = 1
  4997. label.IsPrint = 2
  4998. label.DoctorId = info.DoctorId
  4999. label.UserOrgId = p.UserOrgId
  5000. label.PatientId = patient_id
  5001. label.RecordDate = recordDateTime
  5002. label.Ctime = time.Now().Unix()
  5003. label.Mtime = time.Now().Unix()
  5004. label.ItemId = p.TeamId
  5005. label.FeedetlSn = p.FeedetlSn
  5006. label.PProjectId = p.ID
  5007. label.ProjectName = team.ProjectTeam
  5008. label.PatientName = patient.Name
  5009. service.CreateHisLabelRecord(&label)
  5010. }
  5011. } else { //单条检验检查项目
  5012. label.Number = tempPrescription.PrescriptionNumber
  5013. label.ProjectId = project.ID
  5014. label.Status = 1
  5015. label.DoctorId = info.DoctorId
  5016. label.UserOrgId = p.UserOrgId
  5017. label.PatientId = patient_id
  5018. label.RecordDate = recordDateTime
  5019. label.IsPrint = 2
  5020. label.Ctime = time.Now().Unix()
  5021. label.Mtime = time.Now().Unix()
  5022. label.FeedetlSn = p.FeedetlSn
  5023. label.PProjectId = p.ID
  5024. label.ItemId = p.TeamId
  5025. label.ProjectName = project.ProjectName
  5026. label.PatientName = patient.Name
  5027. service.CreateHisLabelRecord(&label)
  5028. }
  5029. }
  5030. }
  5031. }
  5032. service.SaveHisProjectTwo(&p)
  5033. }
  5034. }
  5035. }
  5036. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5037. // addition := items["addition"].([]interface{})
  5038. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5039. // ctime := time.Now().Unix()
  5040. // mtime := ctime
  5041. // if len(addition) > 0 {
  5042. // for _, item := range addition {
  5043. // var s models.HisAdditionalCharge
  5044. // s.PrescriptionId = tempPrescription.ID
  5045. // s.Status = 1
  5046. // s.UserOrgId = adminInfo.CurrentOrgId
  5047. // s.RecordDate = recordDateTime
  5048. // s.CreatedTime = ctime
  5049. // s.UpdatedTime = mtime
  5050. // s.PatientId = patient_id
  5051. // s.HisPatientId = his_patient_id
  5052. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5053. // if errcode > 0 {
  5054. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5055. // return
  5056. // }
  5057. // service.CreateAdditionalCharge(&s)
  5058. // var randNum int
  5059. // randNum = rand.Intn(10000) + 1000
  5060. // timestamp := time.Now().Unix()
  5061. // tempTime := time.Unix(timestamp, 0)
  5062. // timeFormat := tempTime.Format("20060102150405")
  5063. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5064. // service.CreateAdditionalCharge(&s)
  5065. //
  5066. // }
  5067. // }
  5068. //}
  5069. }
  5070. }
  5071. //查询今日该患者开的药品处方
  5072. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5073. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5074. //药品出库
  5075. if drugOutConfig.IsOpen == 1 {
  5076. for _, item := range hisdoctorlist {
  5077. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5078. // 查询该药品最后一次出库记录
  5079. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5080. if len(druginfo) > 0 {
  5081. //回退库存
  5082. for _, it := range druginfo {
  5083. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5084. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5085. }
  5086. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5087. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5088. }
  5089. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5090. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5091. }
  5092. }
  5093. }
  5094. //删除记录
  5095. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5096. //查询最后一次数据
  5097. if drugOutConfig.IsOpen == 1 {
  5098. //出库
  5099. if drug.IsUse == 2 {
  5100. creater := adminInfo.AdminUser.Id
  5101. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5102. }
  5103. //更新字典里面的库存
  5104. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5105. var sum_count int64
  5106. for _, its := range stockInfo {
  5107. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5108. if its.MaxUnit == baseDrug.MaxUnit {
  5109. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5110. }
  5111. sum_count += its.StockMaxNumber + its.StockMinNumber
  5112. }
  5113. //更新基础库存
  5114. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5115. //剩余库存
  5116. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5117. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5118. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5119. }
  5120. }
  5121. }
  5122. //耗材保存处方出库
  5123. if goodOutConfig.IsOpen == 1 {
  5124. //查询今日耗材出库数量
  5125. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5126. for _, item := range hisgoodlist {
  5127. //查询历史出库数据
  5128. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5129. var out_count_five int64
  5130. for _, item := range flowGood {
  5131. out_count_five += item.Count
  5132. }
  5133. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5134. if out_count_five != parseIntCount {
  5135. //查询耗材最后一次出库记录
  5136. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5137. //查询默认出库仓库库存
  5138. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5139. if len(wareOut) > 0 {
  5140. for _, it := range wareOut {
  5141. //回退库存
  5142. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5143. //删除出库记录
  5144. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5145. }
  5146. }
  5147. timeStr := time.Now().Format("2006-01-02")
  5148. timeArr := strings.Split(timeStr, "-")
  5149. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5150. total = total + 1
  5151. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5152. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5153. number = number + total
  5154. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5155. operation_time := time.Now().Unix()
  5156. creater := c.GetAdminUserInfo().AdminUser.Id
  5157. recordDateStr := time.Now().Format("2006-01-02")
  5158. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5159. nowtime := recordDate.Unix()
  5160. warehouseOut := models.WarehouseOut{
  5161. WarehouseOutOrderNumber: warehousing_out_order,
  5162. OperationTime: operation_time,
  5163. OrgId: adminInfo.CurrentOrgId,
  5164. Creater: creater,
  5165. Ctime: time.Now().Unix(),
  5166. Status: 1,
  5167. WarehouseOutTime: nowtime,
  5168. Type: 1,
  5169. StorehouseId: storeConfig.StorehouseOutInfo,
  5170. IsCheck: 1,
  5171. IsSys: 1,
  5172. }
  5173. //查询是否生成出库单
  5174. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5175. if out.ID == 0 {
  5176. service.AddSigleWarehouseOutOne(&warehouseOut)
  5177. }
  5178. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5179. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5180. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5181. dialyPrepareOne := models.DialysisBeforePrepare{
  5182. GoodTypeId: goodObj.GoodTypeId,
  5183. GoodId: item.ProjectId,
  5184. PatientId: item.PatientId,
  5185. RecordDate: item.RecordDate,
  5186. UserOrgId: adminInfo.CurrentOrgId,
  5187. Count: parseIntCount,
  5188. Ctime: time.Now().Unix(),
  5189. Creater: creater,
  5190. Status: 1,
  5191. StorehouseId: houseConfig.StorehouseOutInfo,
  5192. ProjectId: item.ID,
  5193. }
  5194. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5195. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5196. //查询历史出库数据
  5197. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5198. var out_count int64
  5199. for _, item := range flowGood {
  5200. out_count += item.Count
  5201. }
  5202. //如果历史数和当前数据不想等才进行退库出库
  5203. if out_count != parseIntCount {
  5204. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5205. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5206. detail := models.AutomaticReduceDetail{
  5207. WarehouseOutId: 0,
  5208. WarehouseOutOrderNumber: "",
  5209. PatientId: item.PatientId,
  5210. Ctime: time.Now().Unix(),
  5211. Mtime: 0,
  5212. Status: 1,
  5213. RecordTime: item.RecordDate,
  5214. OrgId: item.UserOrgId,
  5215. GoodId: item.ProjectId,
  5216. GoodTypeId: 0,
  5217. Count: parseIntCount,
  5218. Type: 0,
  5219. ProjectId: item.ID,
  5220. StorehouseId: 0,
  5221. }
  5222. service.CreateAutoDetail(detail)
  5223. //查询剩余库存
  5224. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5225. var sum_count int64
  5226. for _, item := range goodList {
  5227. sum_count += item.StockCount
  5228. }
  5229. //更新剩余库存
  5230. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5231. //耗材
  5232. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5233. }
  5234. }
  5235. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5236. //查询历史出库数据
  5237. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5238. var out_count int64
  5239. for _, item := range flowGood {
  5240. out_count += item.Count
  5241. }
  5242. //如果历史数和当前数据不想等才进行退库出库
  5243. if out_count != parseIntCount {
  5244. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5245. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5246. detail := models.AutomaticReduceDetail{
  5247. WarehouseOutId: 0,
  5248. WarehouseOutOrderNumber: "",
  5249. PatientId: item.PatientId,
  5250. Ctime: time.Now().Unix(),
  5251. Mtime: 0,
  5252. Status: 1,
  5253. RecordTime: item.RecordDate,
  5254. OrgId: item.UserOrgId,
  5255. GoodId: item.ProjectId,
  5256. GoodTypeId: 0,
  5257. Count: parseIntCount,
  5258. Type: 0,
  5259. ProjectId: item.ID,
  5260. StorehouseId: 0,
  5261. }
  5262. service.CreateAutoDetail(detail)
  5263. //查询剩余库存
  5264. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5265. var sum_count int64
  5266. for _, item := range goodList {
  5267. sum_count += item.StockCount
  5268. }
  5269. //更新剩余库存
  5270. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5271. //耗材
  5272. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5273. }
  5274. }
  5275. }
  5276. }
  5277. }
  5278. ////同步到自备药
  5279. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5280. if selfPrescriptionOpen.IsOpen == 1 {
  5281. timeStr := time.Now().Format("2006-01-02")
  5282. timeArr := strings.Split(timeStr, "-")
  5283. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5284. total = total + 1
  5285. operation_time := time.Now().Unix()
  5286. creater := adminInfo.AdminUser.Id
  5287. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5288. warehousing := models.XtSelfDrugWarehouse{
  5289. WarehousingOrder: warehousing_order,
  5290. OperationTime: operation_time,
  5291. OrgId: adminInfo.CurrentOrgId,
  5292. Creater: creater,
  5293. Ctime: time.Now().Unix(),
  5294. Status: 1,
  5295. WarehousingTime: recordDateTime,
  5296. Type: 0,
  5297. StorehouseId: 0,
  5298. IsCheck: 1,
  5299. PatientId: patient_id,
  5300. IsSys: 1,
  5301. }
  5302. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5303. if selfDrugWarehouse.ID == 0 {
  5304. service.AddSelfDrugWarehouse(&warehousing, tx)
  5305. }
  5306. if selfDrugWarehouse.ID > 0 {
  5307. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5308. }
  5309. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5310. fmt.Println(info)
  5311. for _, item := range hisdoctorlist {
  5312. //查询该病人的该药品是否已经入库
  5313. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5314. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5315. var in_count int64
  5316. if len(selfdruginfo) > 0 {
  5317. for _, item := range selfdruginfo {
  5318. var in_count_one int64
  5319. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5320. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5321. }
  5322. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5323. in_count_one = item.WarehousingCount
  5324. }
  5325. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5326. in_count_one = item.WarehousingCount
  5327. }
  5328. in_count += in_count_one
  5329. }
  5330. }
  5331. if selfBasedrug.IsSelfDrug == 1 {
  5332. var total_count int64
  5333. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5334. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5335. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5336. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5337. }
  5338. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5339. total_count += prescribingNumberSeven
  5340. }
  5341. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5342. total_count += prescribingNumberSeven
  5343. }
  5344. //入库
  5345. if total_count > in_count {
  5346. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5347. WarehousingOrder: warehousing_order,
  5348. WarehousingId: info.ID,
  5349. DrugId: item.DrugId,
  5350. Number: "",
  5351. ProductDate: 0,
  5352. ExpiryDate: 0,
  5353. WarehousingCount: total_count - in_count,
  5354. WarehouseingUnit: selfBasedrug.MinUnit,
  5355. Price: 0,
  5356. TotalPrice: 0,
  5357. Status: 1,
  5358. Ctime: time.Now().Unix(),
  5359. Remark: "",
  5360. OrgId: adminInfo.CurrentOrgId,
  5361. Type: 0,
  5362. Manufacturer: selfBasedrug.Manufacturer,
  5363. Dealer: selfBasedrug.Dealer,
  5364. StockMaxNumber: total_count - in_count,
  5365. RetailTotalPrice: 0,
  5366. BatchNumber: "",
  5367. MaxUnit: selfBasedrug.MinUnit,
  5368. MinUnit: selfBasedrug.MinUnit,
  5369. RetailPrice: 0,
  5370. StorehouseId: 0,
  5371. IsCheck: 1,
  5372. StockMinNumber: 0,
  5373. PatientId: patient_id,
  5374. IsSys: 1,
  5375. RecordDate: item.RecordDate,
  5376. AdviceId: item.ID,
  5377. }
  5378. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5379. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5380. Creator := adminInfo.AdminUser.Id
  5381. //查询默认仓库剩余多少库存
  5382. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5383. var sum_count int64
  5384. for _, it := range list {
  5385. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5386. if it.MaxUnit == baseDrug.MaxUnit {
  5387. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5388. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5389. }
  5390. sum_count += it.StockMaxNumber + it.StockMinNumber
  5391. }
  5392. flow := &models.XtSelfDrugFlow{
  5393. WarehousingId: info.ID,
  5394. DrugId: item.DrugId,
  5395. Number: "",
  5396. BatchNumber: "",
  5397. Count: total_count - in_count,
  5398. UserOrgId: adminInfo.CurrentOrgId,
  5399. PatientId: item.PatientId,
  5400. SystemTime: time.Now().Unix(),
  5401. ConsumableType: 1,
  5402. IsSys: 1,
  5403. WarehousingOrder: warehousing_order,
  5404. WarehouseOutId: 0,
  5405. WarehouseOutOrderNumber: "",
  5406. IsEdit: 0,
  5407. CancelStockId: 0,
  5408. CancelOrderNumber: "",
  5409. Manufacturer: selfBasedrug.Manufacturer,
  5410. Dealer: selfBasedrug.Dealer,
  5411. Creator: Creator,
  5412. UpdateCreator: Creator,
  5413. Status: 1,
  5414. Ctime: item.AdviceDate,
  5415. Mtime: 0,
  5416. Price: item.Price,
  5417. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5418. WarehouseOutDetailId: 0,
  5419. CancelOutDetailId: 0,
  5420. ExpireDate: 0,
  5421. ProductDate: 0,
  5422. MaxUnit: selfBasedrug.MinUnit,
  5423. MinUnit: selfBasedrug.MinUnit,
  5424. StorehouseId: 0,
  5425. OverCount: sum_count,
  5426. OperateTime: time.Now().Unix(),
  5427. AdviceId: item.ID,
  5428. }
  5429. service.CreateSelfDrugFlow(flow, tx)
  5430. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5431. var total_count int64 // 入库总数量
  5432. var over_count int64 //剩余库存
  5433. for _, it := range drugInfolist {
  5434. if it.MaxUnit == selfBasedrug.MaxUnit {
  5435. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5436. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5437. }
  5438. }
  5439. for _, it := range drugInfolist {
  5440. total_count += it.WarehousingCount
  5441. over_count += it.StockMaxNumber + it.StockMinNumber
  5442. }
  5443. //查询该仓库是否有默认数据
  5444. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5445. if selfDrugStock.ID == 0 {
  5446. drugStock := models.XtSelfDrugStockCount{
  5447. UserOrgId: item.UserOrgId,
  5448. PatientId: item.PatientId,
  5449. SumInCount: total_count,
  5450. SumOutCount: 0,
  5451. SumCancelCount: 0,
  5452. DrugId: item.DrugId,
  5453. Ctime: time.Now().Unix(),
  5454. Mtime: 0,
  5455. Status: 1,
  5456. FlushCount: over_count,
  5457. SumActOutCount: 0,
  5458. }
  5459. service.CreateSelfDrugStockSum(drugStock, tx)
  5460. }
  5461. if selfDrugStock.ID > 0 {
  5462. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5463. }
  5464. }
  5465. //查询这个单据的出库数量
  5466. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5467. var his_out_count int64
  5468. for _, item := range drugFlowList {
  5469. his_out_count += item.Count
  5470. }
  5471. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5472. if (total_count + his_out_count) <= in_count {
  5473. // 出库
  5474. if total_count < in_count {
  5475. var cha_count int64
  5476. cha_count = in_count - total_count
  5477. var stock_number int64 = 0
  5478. //查询库存是否充足
  5479. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5480. // 将该批次的剩余库存数量转换为拆零数量
  5481. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5482. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5483. }
  5484. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5485. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5486. }
  5487. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5488. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5489. }
  5490. if stock_number >= cha_count {
  5491. var maxNumber int64 = 0
  5492. var minNumber int64 = 0
  5493. maxNumber = cha_count / selfBasedrug.MinNumber
  5494. minNumber = cha_count % selfBasedrug.MinNumber
  5495. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5496. minNumber = maxNumber
  5497. }
  5498. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5499. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5501. return
  5502. }
  5503. }
  5504. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5505. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5506. }
  5507. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5508. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5509. }
  5510. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5511. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5512. }
  5513. if warehouse.StockMaxNumber < 0 {
  5514. warehouse.StockMaxNumber = 0
  5515. }
  5516. if warehouse.StockMinNumber < 0 {
  5517. warehouse.StockMinNumber = 0
  5518. }
  5519. warehouse.Mtime = time.Now().Unix()
  5520. if warehouse.StockMinNumber < minNumber {
  5521. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5522. if warehouse.MaxUnit != warehouse.MinUnit {
  5523. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5524. }
  5525. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5526. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5527. }
  5528. } else {
  5529. if minNumber > 0 {
  5530. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5531. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5532. }
  5533. }
  5534. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5535. if warehouse.StockMinNumber > 0 {
  5536. if warehouse.StockMinNumber-cha_count >= 0 {
  5537. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5538. }
  5539. }
  5540. }
  5541. }
  5542. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5543. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5544. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5545. }
  5546. }
  5547. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5548. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5550. return
  5551. }
  5552. }
  5553. if warehouse.StockMinNumber <= 0 {
  5554. warehouse.StockMinNumber = 0
  5555. }
  5556. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5557. //查询该药品剩余库存
  5558. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5559. var over_count int64
  5560. for _, its := range infolist {
  5561. if its.MaxUnit == selfBasedrug.MaxUnit {
  5562. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5563. }
  5564. over_count += its.StockMaxNumber + its.StockMinNumber
  5565. }
  5566. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5567. drugflow := models.XtSelfDrugFlow{
  5568. WarehouseOutId: 0,
  5569. WarehouseOutOrderNumber: warehousing_order,
  5570. WarehousingOrder: warehousing_order,
  5571. DrugId: item.DrugId,
  5572. Number: warehouse.Number,
  5573. ProductDate: warehouse.ProductDate,
  5574. ExpireDate: warehouse.ExpiryDate,
  5575. Count: cha_count,
  5576. Price: warehouse.RetailPrice,
  5577. Status: 1,
  5578. Ctime: item.AdviceDate,
  5579. Mtime: time.Now().Unix(),
  5580. UserOrgId: item.UserOrgId,
  5581. Manufacturer: warehouse.Manufacturer,
  5582. Dealer: warehouse.Dealer,
  5583. BatchNumber: warehouse.BatchNumber,
  5584. MaxUnit: selfBasedrug.MinUnit,
  5585. ConsumableType: 20,
  5586. IsEdit: 1,
  5587. Creator: 0,
  5588. IsSys: 3,
  5589. WarehouseOutDetailId: drugWareInfo.ID,
  5590. AdviceId: item.ID,
  5591. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5592. StorehouseId: 0,
  5593. AdminUserId: creater,
  5594. LastPrice: warehouse.Price,
  5595. StockCount: "",
  5596. WarehousingDetailId: 0,
  5597. OverCount: over_count,
  5598. RetailPrice: item.Price, //手动出库出库价格
  5599. WarehousingId: warehouse.ID,
  5600. SystemTime: item.AdviceDate,
  5601. PatientId: item.PatientId,
  5602. Remark: "保存处方入库数据差",
  5603. OperateTime: time.Now().Unix(),
  5604. }
  5605. if warehouse.RetailPrice == 0 {
  5606. drugflow.Price = item.Price
  5607. }
  5608. service.CreateSelfDrugFlowOne(drugflow, tx)
  5609. var out_count int64
  5610. out_count = in_count - total_count
  5611. //
  5612. //fmt.Println("in_count------------------", in_count)
  5613. //fmt.Println("total_count------------------", total_count)
  5614. //添加出库数量
  5615. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5616. //查询剩余库存
  5617. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5618. var sum_count int64
  5619. for _, its := range stockInfo {
  5620. if its.MaxUnit == selfBasedrug.MaxUnit {
  5621. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5622. }
  5623. sum_count += its.StockMaxNumber + its.StockMinNumber
  5624. }
  5625. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5626. } else {
  5627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5628. return
  5629. }
  5630. }
  5631. }
  5632. }
  5633. }
  5634. }
  5635. }
  5636. tx.Commit()
  5637. if err == nil {
  5638. c.ServeSuccessJSON(map[string]interface{}{
  5639. "msg": "保存成功",
  5640. })
  5641. return
  5642. } else {
  5643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5644. return
  5645. }
  5646. }
  5647. }
  5648. //func (c *HisApiController) EditHisPrescription() {
  5649. // record_date := c.GetString("record_date")
  5650. // patient_id, _ := c.GetInt64("patient_id")
  5651. // reg_type, _ := c.GetInt64("reg_type")
  5652. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5653. // diagnose := c.GetString("diagnose")
  5654. // sick_type, _ := c.GetInt64("sick_type")
  5655. // sick_history := c.GetString("sick_history")
  5656. // doctor_id, _ := c.GetInt64("doctor", 0)
  5657. // department, _ := c.GetInt64("department", 0)
  5658. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5659. // p_type, _ := c.GetInt64("p_type")
  5660. //
  5661. // dataBody := make(map[string]interface{}, 0)
  5662. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5663. // if err != nil {
  5664. // utils.ErrorLog(err.Error())
  5665. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5666. // return
  5667. // }
  5668. //
  5669. // timeLayout := "2006-01-02"
  5670. // loc, _ := time.LoadLocation("Local")
  5671. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5672. // if err != nil {
  5673. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5674. // return
  5675. // }
  5676. // adminInfo := c.GetAdminUserInfo()
  5677. // recordDateTime := theTime.Unix()
  5678. //
  5679. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5680. //
  5681. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5682. // var hpInfo models.HisPrescriptionInfo
  5683. // if info.ID == 0 {
  5684. // var randNum int
  5685. // randNum = rand.Intn(10000) + 1000
  5686. // timestamp := time.Now().Unix()
  5687. // tempTime := time.Unix(timestamp, 0)
  5688. // timeFormat := tempTime.Format("20060102150405")
  5689. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5690. //
  5691. // hpInfo = models.HisPrescriptionInfo{
  5692. // UserOrgId: adminInfo.CurrentOrgId,
  5693. // RecordDate: theTime.Unix(),
  5694. // PatientId: patient_id,
  5695. // Status: 1,
  5696. // Ctime: time.Now().Unix(),
  5697. // Mtime: time.Now().Unix(),
  5698. // Creator: adminInfo.AdminUser.Id,
  5699. // Modifier: adminInfo.AdminUser.Id,
  5700. // Diagnosis: diagnose,
  5701. // SickHistory: sick_history,
  5702. // Departments: department,
  5703. // RegisterType: reg_type,
  5704. // PrescriptionNumber: p_number,
  5705. // PrescriptionStatus: 1,
  5706. // Doctor: role.UserName,
  5707. // DoctorId: doctor_id,
  5708. // SickType: sick_type,
  5709. // PType: p_type,
  5710. // }
  5711. // service.SavePatientPrescriptionInfo(hpInfo)
  5712. //
  5713. // } else {
  5714. // hpInfo = models.HisPrescriptionInfo{
  5715. // ID: info.ID,
  5716. // UserOrgId: adminInfo.CurrentOrgId,
  5717. // RecordDate: info.RecordDate,
  5718. // PatientId: info.PatientId,
  5719. // Status: 1,
  5720. // Ctime: info.Ctime,
  5721. // Mtime: time.Now().Unix(),
  5722. // Creator: info.Creator,
  5723. // Modifier: adminInfo.AdminUser.Id,
  5724. // Diagnosis: diagnose,
  5725. // SickHistory: sick_history,
  5726. // Departments: department,
  5727. // RegisterType: reg_type,
  5728. // PrescriptionNumber: info.PrescriptionNumber,
  5729. // Doctor: role.UserName,
  5730. // PrescriptionStatus: info.PrescriptionStatus,
  5731. // DoctorId: doctor_id,
  5732. // SickType: sick_type,
  5733. // PType: info.PType,
  5734. // }
  5735. // service.SavePatientPrescriptionInfo(hpInfo)
  5736. // }
  5737. //
  5738. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5739. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5740. //
  5741. // if len(prescriptions) > 0 {
  5742. // for _, item := range prescriptions {
  5743. // items := item.(map[string]interface{})
  5744. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5745. // utils.ErrorLog("id")
  5746. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5747. // return
  5748. // }
  5749. // id := int64(items["id"].(float64))
  5750. //
  5751. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5752. // utils.ErrorLog("type")
  5753. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5754. // return
  5755. // }
  5756. // types := int64(items["type"].(float64))
  5757. //
  5758. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5759. // utils.ErrorLog("med_type")
  5760. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5761. // return
  5762. // }
  5763. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5764. //
  5765. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5766. //
  5767. // ctime := time.Now().Unix()
  5768. //
  5769. // prescription := &models.HisPrescription{
  5770. // ID: id,
  5771. // PatientId: patient_id,
  5772. // UserOrgId: adminInfo.CurrentOrgId,
  5773. // RecordDate: recordDateTime,
  5774. // Ctime: ctime,
  5775. // Mtime: ctime,
  5776. // Type: types,
  5777. // Modifier: adminInfo.AdminUser.Id,
  5778. // Creator: adminInfo.AdminUser.Id,
  5779. // Status: 1,
  5780. // Doctor: role.UserName,
  5781. // HisPatientId: his_patient_id,
  5782. // OrderStatus: 1,
  5783. // BatchNumber: "",
  5784. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5785. // PType: hpInfo.PType,
  5786. // MedType: med_type,
  5787. // }
  5788. //
  5789. // if historyPrescription.ID > 0 {
  5790. // prescription.PreTime = historyPrescription.PreTime
  5791. //
  5792. // }
  5793. //
  5794. // service.SaveHisPrescription(prescription)
  5795. //
  5796. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5797. // advices := items["advices"].([]interface{})
  5798. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5799. // groupNo := int64(0)
  5800. // ctime := time.Now().Unix()
  5801. // mtime := ctime
  5802. // if len(advices) > 0 {
  5803. // for _, advice := range advices {
  5804. // var s models.HisDoctorAdviceInfo
  5805. // s.PrescriptionId = prescription.ID
  5806. // s.AdviceType = 2
  5807. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5808. // s.StopState = 2
  5809. // s.ExecutionState = 2
  5810. // s.AdviceDate = recordDateTime
  5811. // s.Status = 1
  5812. // s.UserOrgId = adminInfo.CurrentOrgId
  5813. // s.RecordDate = recordDateTime
  5814. // s.StartTime = prescription.PreTime
  5815. // s.Groupno = groupNo
  5816. // s.CreatedTime = ctime
  5817. // s.UpdatedTime = mtime
  5818. // s.PatientId = patient_id
  5819. // s.HisPatientId = his_patient_id
  5820. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5821. // if errcode > 0 {
  5822. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5823. // return
  5824. // }
  5825. //
  5826. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5827. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5828. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5829. // if s.Price == 0 {
  5830. // s.Price = lastWarehouse.RetailPrice
  5831. // }
  5832. // }
  5833. //
  5834. // service.CreateHisDoctorAdvice(&s)
  5835. // //记录日志
  5836. // byterequest, _ := json.Marshal(s)
  5837. // adviceLog := models.XtDoctorAdviceLog{
  5838. // UserOrgId: s.UserOrgId,
  5839. // PatientId: s.PatientId,
  5840. // AdminUserId: adminInfo.AdminUser.Id,
  5841. // Module: 1,
  5842. // ErrLog: string(byterequest),
  5843. // Status: 1,
  5844. // Ctime: time.Now().Unix(),
  5845. // Mtime: 0,
  5846. // Source: "电脑端his医嘱修改",
  5847. // RecordDate: s.AdviceDate,
  5848. // }
  5849. // service.CreateDoctorAdviceLog(adviceLog)
  5850. // redis := service.RedisClient()
  5851. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5852. // redis.Set(key, "", time.Second)
  5853. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5854. // fmt.Println("keyOne", keyOne)
  5855. // redis.Set(keyOne, "", time.Second)
  5856. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5857. // redis.Set(keySeven, "", time.Second)
  5858. // redis.Close()
  5859. //
  5860. // }
  5861. // }
  5862. // }
  5863. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5864. // projects := items["project"].([]interface{})
  5865. // if len(projects) > 0 {
  5866. // for _, project := range projects {
  5867. // var p models.HisPrescriptionProject
  5868. // p.PrescriptionId = prescription.ID
  5869. // p.Ctime = time.Now().Unix()
  5870. // p.Mtime = time.Now().Unix()
  5871. // p.PatientId = patient_id
  5872. // p.RecordDate = recordDateTime
  5873. // p.UserOrgId = adminInfo.CurrentOrgId
  5874. // p.HisPatientId = his_patient_id
  5875. // p.Status = 1
  5876. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5877. // if errcode > 0 {
  5878. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5879. // return
  5880. // }
  5881. // service.CreateHisProjectTwo(&p)
  5882. //
  5883. // //记录日志
  5884. // byterequest, _ := json.Marshal(p)
  5885. // adviceLog := models.XtDoctorAdviceLog{
  5886. // UserOrgId: p.UserOrgId,
  5887. // PatientId: p.PatientId,
  5888. // AdminUserId: adminInfo.AdminUser.Id,
  5889. // Module: 1,
  5890. // ErrLog: string(byterequest),
  5891. // Status: 1,
  5892. // Ctime: time.Now().Unix(),
  5893. // Mtime: 0,
  5894. // Source: "电脑端his项目修改",
  5895. // RecordDate: p.RecordDate,
  5896. // }
  5897. // service.CreateDoctorAdviceLog(adviceLog)
  5898. // }
  5899. // }
  5900. // }
  5901. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5902. // addition := items["addition"].([]interface{})
  5903. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5904. // ctime := time.Now().Unix()
  5905. // mtime := ctime
  5906. // if len(addition) > 0 {
  5907. // for _, item := range addition {
  5908. // var s models.HisAdditionalCharge
  5909. // s.PrescriptionId = prescription.ID
  5910. // s.Status = 1
  5911. // s.UserOrgId = adminInfo.CurrentOrgId
  5912. // s.RecordDate = recordDateTime
  5913. // s.CreatedTime = ctime
  5914. // s.UpdatedTime = mtime
  5915. // s.PatientId = patient_id
  5916. // s.HisPatientId = his_patient_id
  5917. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5918. // if errcode > 0 {
  5919. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5920. // return
  5921. // }
  5922. // service.CreateAdditionalCharge(&s)
  5923. // }
  5924. // }
  5925. // }
  5926. //
  5927. // }
  5928. // }
  5929. // }
  5930. // if err == nil {
  5931. // c.ServeSuccessJSON(map[string]interface{}{
  5932. // "msg": "保存成功",
  5933. // })
  5934. // return
  5935. //
  5936. // } else {
  5937. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5938. // return
  5939. // }
  5940. //}
  5941. func (c *HisApiController) DeletePrescription() {
  5942. prescription_id, _ := c.GetInt64("id")
  5943. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5944. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5945. ////同步到自备药
  5946. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5947. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5948. if selfPrescriptionOpen.IsOpen == 1 {
  5949. // 在函数结束时处理事务回滚
  5950. db := service.XTWriteDB()
  5951. tx := db.Begin()
  5952. defer func() {
  5953. if r := recover(); r != nil {
  5954. tx.Rollback()
  5955. } else {
  5956. tx.Commit()
  5957. }
  5958. }()
  5959. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5960. for _, item := range advicesList {
  5961. timeStr := time.Now().Format("2006-01-02")
  5962. timeArr := strings.Split(timeStr, "-")
  5963. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5964. total = total + 1
  5965. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5966. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5967. number = number + total
  5968. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5969. operation_time := time.Now().Unix()
  5970. creater := c.GetAdminUserInfo().AdminUser.Id
  5971. //创建一个出库单
  5972. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5973. WarehouseOutOrderNumber: warehousing_out_order,
  5974. OperationTime: operation_time,
  5975. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5976. Creater: creater,
  5977. Ctime: time.Now().Unix(),
  5978. Status: 1,
  5979. WarehouseOutTime: item.AdviceDate,
  5980. Type: 0,
  5981. PatientId: item.PatientId,
  5982. IsCheck: 1,
  5983. }
  5984. //查询今日是否有出库数据
  5985. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5986. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5987. if lastWarehouseOut.ID == 0 {
  5988. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5989. }
  5990. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5991. var total_count int64
  5992. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5993. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5994. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5995. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5996. }
  5997. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5998. total_count += prescribingNumberSeven
  5999. }
  6000. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6001. total_count += prescribingNumberSeven
  6002. }
  6003. //出库
  6004. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6005. WarehouseOutOrderNumber: warehousing_out_order,
  6006. WarehouseOutId: lastWarehouseOut.ID,
  6007. DrugId: item.DrugId,
  6008. Count: total_count,
  6009. Price: 0,
  6010. TotalPrice: 0,
  6011. Status: 1,
  6012. Ctime: item.AdviceDate,
  6013. Mtime: item.AdviceDate,
  6014. Remark: "",
  6015. OrgId: item.UserOrgId,
  6016. Type: 0,
  6017. Manufacturer: selfBasedrug.Manufacturer,
  6018. Dealer: selfBasedrug.Dealer,
  6019. RetailPrice: 0,
  6020. RetailTotalPrice: 0,
  6021. CountUnit: selfBasedrug.MinUnit,
  6022. ExpiryDate: 0,
  6023. ProductDate: 0,
  6024. Number: "",
  6025. BatchNumber: "",
  6026. IsSys: 1,
  6027. WarehouseInfoId: 0,
  6028. AdminUserId: 0,
  6029. StockCount: "",
  6030. IsCheck: 1,
  6031. SysRecordTime: item.AdviceDate,
  6032. PatientId: item.PatientId,
  6033. ClassType: "",
  6034. AdviceId: item.ID,
  6035. }
  6036. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6037. }
  6038. fmt.Println("长度-------------------------------", warehousingOutInfo)
  6039. for _, it := range warehousingOutInfo {
  6040. //查询今日是否有出库数据
  6041. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6042. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6043. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6044. //出库逻辑
  6045. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6046. //查询剩余库存
  6047. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6048. var sum_count int64
  6049. for _, its := range stockInfo {
  6050. if its.MaxUnit == medical.MaxUnit {
  6051. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6052. }
  6053. sum_count += its.StockMaxNumber + its.StockMinNumber
  6054. }
  6055. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6056. }
  6057. }
  6058. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6059. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6060. //耗材保存处方出库
  6061. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6062. //已收费和已发药限制逻辑
  6063. isCharge := false
  6064. isMedicine := false
  6065. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6066. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6067. if new_prescription.IsMedicine == 1 {
  6068. isMedicine = true
  6069. }
  6070. for _, item := range new_prescriptions {
  6071. if item.OrderStatus == 4 {
  6072. isCharge = true
  6073. }
  6074. }
  6075. if p_err != nil {
  6076. if new_prescription.ID > 0 {
  6077. if new_prescription.OrderStatus == 2 {
  6078. isCharge = true
  6079. }
  6080. }
  6081. }
  6082. for _, item := range advices {
  6083. if item.IsMedicine == 1 {
  6084. isMedicine = true
  6085. }
  6086. }
  6087. if isCharge {
  6088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6089. return
  6090. }
  6091. if isMedicine {
  6092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6093. return
  6094. }
  6095. //已收费和已发药限制逻辑
  6096. if len(projects) > 0 {
  6097. for _, item := range projects {
  6098. service.DeletePrintInfo(item.ID) //删除打印信息
  6099. if goodOutConfig.IsOpen != 1 {
  6100. if stockConfig.IsOpen == 1 {
  6101. if item.Type == 3 && item.IsOut == 1 {
  6102. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6103. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6104. good.Total = good.Total + f_count
  6105. service.UpdateGoodInfo(&good)
  6106. operation_time := time.Now().Unix()
  6107. creater := c.GetAdminUserInfo().AdminUser.Id
  6108. //创建退库单
  6109. timeStr := time.Now().Format("2006-01-02")
  6110. timeArr := strings.Split(timeStr, "-")
  6111. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6112. total = total + 1
  6113. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6114. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6115. cancelStock := models.CancelStock{
  6116. OrderNumber: orderNumber,
  6117. OperaTime: operation_time,
  6118. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6119. Creater: creater,
  6120. Ctime: time.Now().Unix(),
  6121. Status: 1,
  6122. ReturnTime: item.RecordDate,
  6123. Type: 1,
  6124. StorehouseId: houseConfig.StorehouseOutInfo,
  6125. IsCheck: 1,
  6126. }
  6127. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6128. if msgerrkonde == gorm.ErrRecordNotFound {
  6129. service.AddSigleCancelStock(&cancelStock)
  6130. }
  6131. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6132. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6133. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6134. //查询该耗材是否出库
  6135. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6136. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6137. deaerler, _ := service.GetDealerById(info.Dealer)
  6138. var total_count int64
  6139. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6140. total_count += count
  6141. if info.ID > 0 {
  6142. if info.Count >= total_count {
  6143. //回退库存
  6144. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6145. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6146. var flush_count int64
  6147. for _, it := range goodList {
  6148. flush_count += it.StockCount
  6149. }
  6150. cancelStockInfo := models.CancelStockInfo{
  6151. GoodId: item.ProjectId,
  6152. CancelStockId: cancel.ID,
  6153. GoodTypeId: good.GoodTypeId,
  6154. Count: prescribingNumber,
  6155. Price: info.Price,
  6156. Total: 0,
  6157. ProductDate: info.ProductDate,
  6158. ExpiryDate: info.ExpiryDate,
  6159. Ctime: time.Now().Unix(),
  6160. Status: 1,
  6161. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6162. OrderNumber: cancel.OrderNumber,
  6163. Type: 0,
  6164. Dealer: deaerler.DealerName,
  6165. Manufacturer: manufacturer.ManufacturerName,
  6166. Number: info.Number,
  6167. RegisterAccount: "",
  6168. Remark: "",
  6169. WarehouseInfoId: info.WarehouseInfotId,
  6170. PatientId: info.PatientId,
  6171. RecordDate: info.SysRecordTime,
  6172. StorehouseId: houseConfig.StorehouseOutInfo,
  6173. IsCheck: 1,
  6174. }
  6175. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6176. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6177. flow := models.VmStockFlow{
  6178. WarehousingId: info.WarehouseInfotId,
  6179. GoodId: item.ProjectId,
  6180. Number: info.Number,
  6181. LicenseNumber: info.LicenseNumber,
  6182. Count: prescribingNumber,
  6183. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6184. PatientId: item.PatientId,
  6185. SystemTime: info.SysRecordTime,
  6186. ConsumableType: 7,
  6187. IsSys: 0,
  6188. WarehousingOrder: "",
  6189. WarehouseOutId: info.WarehouseOutId,
  6190. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6191. IsEdit: 0,
  6192. CancelStockId: cancel.ID,
  6193. CancelOrderNumber: cancel.OrderNumber,
  6194. Manufacturer: manufacturer.ID,
  6195. Dealer: 0,
  6196. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6197. UpdateCreator: 0,
  6198. Status: 1,
  6199. Ctime: time.Now().Unix(),
  6200. Mtime: 0,
  6201. Price: info.Price,
  6202. WarehousingDetailId: info.WarehouseInfotId,
  6203. WarehouseOutDetailId: info.ID,
  6204. CancelOutDetailId: cancelInfo.ID,
  6205. ProductDate: info.ProductDate,
  6206. ExpireDate: info.ExpiryDate,
  6207. StorehouseId: houseConfig.StorehouseOutInfo,
  6208. OverCount: flush_count,
  6209. OperateTime: time.Now().Unix(),
  6210. }
  6211. service.CreateStockFlowOne(flow)
  6212. //退库数量增加
  6213. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6214. //出库数量减少
  6215. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6216. }
  6217. if info.Count < total_count {
  6218. //回退库存
  6219. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6220. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6221. var flush_count int64
  6222. for _, it := range goodList {
  6223. flush_count += it.StockCount
  6224. }
  6225. cancelStockInfo := models.CancelStockInfo{
  6226. GoodId: item.ProjectId,
  6227. CancelStockId: cancel.ID,
  6228. GoodTypeId: good.GoodTypeId,
  6229. Count: info.Count,
  6230. Price: info.Price,
  6231. Total: 0,
  6232. ProductDate: info.ProductDate,
  6233. ExpiryDate: info.ExpiryDate,
  6234. Ctime: time.Now().Unix(),
  6235. Status: 1,
  6236. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6237. OrderNumber: cancel.OrderNumber,
  6238. Type: 0,
  6239. Dealer: deaerler.DealerName,
  6240. Manufacturer: manufacturer.ManufacturerName,
  6241. Number: info.Number,
  6242. RegisterAccount: "",
  6243. Remark: "",
  6244. WarehouseInfoId: info.WarehouseInfotId,
  6245. PatientId: info.PatientId,
  6246. RecordDate: info.SysRecordTime,
  6247. StorehouseId: houseConfig.StorehouseOutInfo,
  6248. IsCheck: 1,
  6249. }
  6250. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6251. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6252. flow := models.VmStockFlow{
  6253. WarehousingId: info.WarehouseInfotId,
  6254. GoodId: item.ProjectId,
  6255. Number: info.Number,
  6256. LicenseNumber: info.LicenseNumber,
  6257. Count: info.Count,
  6258. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6259. PatientId: item.PatientId,
  6260. SystemTime: info.SysRecordTime,
  6261. ConsumableType: 7,
  6262. IsSys: 0,
  6263. WarehousingOrder: "",
  6264. WarehouseOutId: info.WarehouseOutId,
  6265. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6266. IsEdit: 0,
  6267. CancelStockId: cancel.ID,
  6268. CancelOrderNumber: cancel.OrderNumber,
  6269. Manufacturer: manufacturer.ID,
  6270. Dealer: 0,
  6271. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6272. UpdateCreator: 0,
  6273. Status: 1,
  6274. Ctime: time.Now().Unix(),
  6275. Mtime: 0,
  6276. Price: info.Price,
  6277. WarehousingDetailId: info.WarehouseInfotId,
  6278. WarehouseOutDetailId: info.ID,
  6279. CancelOutDetailId: cancelInfo.ID,
  6280. ProductDate: info.ProductDate,
  6281. ExpireDate: info.ExpiryDate,
  6282. StorehouseId: houseConfig.StorehouseOutInfo,
  6283. OverCount: flush_count,
  6284. OperateTime: time.Now().Unix(),
  6285. }
  6286. service.CreateStockFlowOne(flow)
  6287. //退库数量增加
  6288. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6289. //出库数量减少
  6290. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6291. }
  6292. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6293. var flush_count int64
  6294. for _, it := range goodList {
  6295. flush_count += it.StockCount
  6296. }
  6297. //查询已出库数量
  6298. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6299. if prescribingNumber < dialysisInfo.Count {
  6300. //改变数量
  6301. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6302. }
  6303. if prescribingNumber >= dialysisInfo.Count {
  6304. //删除出库表
  6305. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6306. }
  6307. //更新库存
  6308. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6309. //更新基础库库存
  6310. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6311. }
  6312. }
  6313. }
  6314. }
  6315. //保存耗材出库
  6316. if goodOutConfig.IsOpen == 1 {
  6317. if item.Type == 3 {
  6318. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6319. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6320. good.Total = good.Total + f_count
  6321. service.UpdateGoodInfo(&good)
  6322. operation_time := time.Now().Unix()
  6323. creater := c.GetAdminUserInfo().AdminUser.Id
  6324. //创建退库单
  6325. timeStr := time.Now().Format("2006-01-02")
  6326. timeArr := strings.Split(timeStr, "-")
  6327. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6328. total = total + 1
  6329. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6330. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6331. cancelStock := models.CancelStock{
  6332. OrderNumber: orderNumber,
  6333. OperaTime: operation_time,
  6334. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6335. Creater: creater,
  6336. Ctime: time.Now().Unix(),
  6337. Status: 1,
  6338. ReturnTime: item.RecordDate,
  6339. Type: 1,
  6340. StorehouseId: houseConfig.StorehouseOutInfo,
  6341. IsCheck: 1,
  6342. }
  6343. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6344. if msgerrkonde == gorm.ErrRecordNotFound {
  6345. service.AddSigleCancelStock(&cancelStock)
  6346. }
  6347. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6348. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6349. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6350. //查询该耗材是否出库
  6351. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6352. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6353. deaerler, _ := service.GetDealerById(info.Dealer)
  6354. var total_count int64
  6355. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6356. total_count += count
  6357. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6358. var flush_count int64
  6359. for _, it := range goodList {
  6360. flush_count += it.StockCount
  6361. }
  6362. fmt.Println("历史出库数据", info.Count)
  6363. fmt.Println("出库数量", total_count)
  6364. if info.ID > 0 {
  6365. cancelStockInfo := models.CancelStockInfo{
  6366. GoodId: item.ProjectId,
  6367. CancelStockId: cancel.ID,
  6368. GoodTypeId: good.GoodTypeId,
  6369. Count: prescribingNumber,
  6370. Price: info.Price,
  6371. Total: 0,
  6372. ProductDate: info.ProductDate,
  6373. ExpiryDate: info.ExpiryDate,
  6374. Ctime: time.Now().Unix(),
  6375. Status: 1,
  6376. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6377. OrderNumber: cancel.OrderNumber,
  6378. Type: 0,
  6379. Dealer: deaerler.DealerName,
  6380. Manufacturer: manufacturer.ManufacturerName,
  6381. Number: info.Number,
  6382. RegisterAccount: "",
  6383. Remark: "",
  6384. WarehouseInfoId: info.WarehouseInfotId,
  6385. PatientId: info.PatientId,
  6386. RecordDate: info.SysRecordTime,
  6387. StorehouseId: houseConfig.StorehouseOutInfo,
  6388. IsCheck: 1,
  6389. }
  6390. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6391. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6392. //查询出库数量
  6393. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6394. //出库数据 大于 退库数量
  6395. if len(list) > 0 {
  6396. for _, it := range list {
  6397. //回退库存
  6398. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6399. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6400. var flush_count_one int64
  6401. for _, it := range goodList {
  6402. flush_count_one += it.StockCount
  6403. }
  6404. //查询该批次是否有退库数据
  6405. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6406. creater := c.GetAdminUserInfo().AdminUser.Id
  6407. flow := models.VmStockFlow{
  6408. WarehousingId: it.WarehouseInfotId,
  6409. GoodId: it.GoodId,
  6410. Number: it.Number,
  6411. LicenseNumber: it.LicenseNumber,
  6412. Count: it.Count,
  6413. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6414. PatientId: it.PatientId,
  6415. SystemTime: it.SysRecordTime,
  6416. ConsumableType: 7,
  6417. IsSys: 0,
  6418. WarehousingOrder: "",
  6419. WarehouseOutId: it.WarehouseOutId,
  6420. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6421. IsEdit: 0,
  6422. CancelStockId: cancel.ID,
  6423. CancelOrderNumber: cancel.OrderNumber,
  6424. Manufacturer: manufacturer.ID,
  6425. Dealer: 0,
  6426. Creator: creater,
  6427. UpdateCreator: 0,
  6428. Status: 1,
  6429. Ctime: time.Now().Unix(),
  6430. Mtime: 0,
  6431. Price: it.Price,
  6432. WarehousingDetailId: it.WarehouseInfotId,
  6433. WarehouseOutDetailId: it.ID,
  6434. CancelOutDetailId: cancelInfo.ID,
  6435. ProductDate: it.ProductDate,
  6436. ExpireDate: it.ExpiryDate,
  6437. StorehouseId: houseConfig.StorehouseOutInfo,
  6438. OverCount: flush_count_one,
  6439. OperateTime: time.Now().Unix(),
  6440. }
  6441. service.CreateStockFlowOne(flow)
  6442. //if flow.ID > 0 {
  6443. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6444. //}
  6445. }
  6446. }
  6447. //flow := models.VmStockFlow{
  6448. // WarehousingId: info.WarehouseInfotId,
  6449. // GoodId: item.ProjectId,
  6450. // Number: info.Number,
  6451. // LicenseNumber: info.LicenseNumber,
  6452. // Count: prescribingNumber,
  6453. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6454. // PatientId: item.PatientId,
  6455. // SystemTime: info.SysRecordTime,
  6456. // ConsumableType: 7,
  6457. // IsSys: 0,
  6458. // WarehousingOrder: "",
  6459. // WarehouseOutId: info.WarehouseOutId,
  6460. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6461. // IsEdit: 0,
  6462. // CancelStockId: cancel.ID,
  6463. // CancelOrderNumber: cancel.OrderNumber,
  6464. // Manufacturer: manufacturer.ID,
  6465. // Dealer: 0,
  6466. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6467. // UpdateCreator: 0,
  6468. // Status: 1,
  6469. // Ctime: time.Now().Unix(),
  6470. // Mtime: 0,
  6471. // Price: info.Price,
  6472. // WarehousingDetailId: info.WarehouseInfotId,
  6473. // WarehouseOutDetailId: info.ID,
  6474. // CancelOutDetailId: cancelInfo.ID,
  6475. // ProductDate: info.ProductDate,
  6476. // ExpireDate: info.ExpiryDate,
  6477. // StorehouseId: houseConfig.StorehouseOutInfo,
  6478. // OverCount: flush_count,
  6479. //}
  6480. //service.CreateStockFlowOne(flow)
  6481. //退库数量增加
  6482. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6483. //出库数量减少
  6484. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6485. //查询已出库数量
  6486. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6487. if prescribingNumber < dialysisInfo.Count {
  6488. //改变数量
  6489. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6490. }
  6491. if prescribingNumber >= dialysisInfo.Count {
  6492. //删除出库表
  6493. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6494. }
  6495. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6496. var flush_count_one int64
  6497. for _, it := range goodList {
  6498. flush_count_one += it.StockCount
  6499. }
  6500. //更新库存
  6501. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6502. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6503. //更新基础库库存
  6504. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6505. }
  6506. }
  6507. }
  6508. }
  6509. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6510. fmt.Println(err)
  6511. }
  6512. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6513. fmt.Println(err)
  6514. if len(advices) > 0 {
  6515. for _, item := range advices {
  6516. redis := service.RedisClient()
  6517. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6518. redis.Set(keyFive, "", time.Second)
  6519. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6520. redis.Set(keyOne, "", time.Second)
  6521. redis.Close()
  6522. }
  6523. }
  6524. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6525. if len(advices) > 0 {
  6526. for _, item := range advices {
  6527. creater := c.GetAdminUserInfo().AdminUser.Id
  6528. service.DrugAutoAddCancelInfo(item, creater)
  6529. }
  6530. }
  6531. } else {
  6532. if drugOutConfig.IsOpen == 1 {
  6533. if len(advices) > 0 {
  6534. for _, item := range advices {
  6535. creater := c.GetAdminUserInfo().AdminUser.Id
  6536. service.DrugAutoAddCancelInfo(item, creater)
  6537. }
  6538. }
  6539. } else {
  6540. if len(advices) > 0 {
  6541. for _, item := range advices {
  6542. creater := c.GetAdminUserInfo().AdminUser.Id
  6543. service.DrugAutoAddCancelInfo(item, creater)
  6544. }
  6545. }
  6546. }
  6547. }
  6548. c.ServeSuccessJSON(map[string]interface{}{
  6549. "msg": "删除成功",
  6550. })
  6551. return
  6552. }
  6553. func (c *HisApiController) DeleteDoctorAdvice() {
  6554. id, _ := c.GetInt64("id")
  6555. advice, _ := service.GetHisDoctorAdvicesById(id)
  6556. ////同步到自备药
  6557. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6558. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6559. if selfPrescriptionOpen.IsOpen == 1 {
  6560. db := service.XTWriteDB()
  6561. tx := db.Begin()
  6562. defer func() {
  6563. if r := recover(); r != nil {
  6564. tx.Rollback()
  6565. } else {
  6566. tx.Commit()
  6567. }
  6568. }()
  6569. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6570. var total_count int64
  6571. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6572. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6573. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6574. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6575. }
  6576. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6577. total_count += prescribingNumberSeven
  6578. }
  6579. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6580. total_count += prescribingNumberSeven
  6581. }
  6582. timeStr := time.Now().Format("2006-01-02")
  6583. timeArr := strings.Split(timeStr, "-")
  6584. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6585. total = total + 1
  6586. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6587. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6588. number = number + total
  6589. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6590. operation_time := time.Now().Unix()
  6591. creater := c.GetAdminUserInfo().AdminUser.Id
  6592. //创建一个出库单
  6593. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6594. WarehouseOutOrderNumber: warehousing_out_order,
  6595. OperationTime: operation_time,
  6596. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6597. Creater: creater,
  6598. Ctime: time.Now().Unix(),
  6599. Status: 1,
  6600. WarehouseOutTime: advice.AdviceDate,
  6601. Type: 0,
  6602. PatientId: advice.PatientId,
  6603. IsCheck: 1,
  6604. }
  6605. //查询今日是否有出库数据
  6606. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6607. if lastWarehouseOut.ID == 0 {
  6608. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6609. }
  6610. //出库
  6611. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6612. WarehouseOutId: lastWarehouseOut.ID,
  6613. WarehouseOutOrderNumber: warehousing_out_order,
  6614. DrugId: advice.DrugId,
  6615. Count: total_count,
  6616. Price: 0,
  6617. TotalPrice: 0,
  6618. Status: 1,
  6619. Ctime: advice.AdviceDate,
  6620. Mtime: advice.AdviceDate,
  6621. Remark: "",
  6622. OrgId: advice.UserOrgId,
  6623. Type: 0,
  6624. Manufacturer: selfBasedrug.Manufacturer,
  6625. Dealer: selfBasedrug.Dealer,
  6626. RetailPrice: 0,
  6627. RetailTotalPrice: 0,
  6628. CountUnit: advice.PrescribingNumberUnit,
  6629. ExpiryDate: 0,
  6630. ProductDate: 0,
  6631. Number: "",
  6632. BatchNumber: "",
  6633. IsSys: 0,
  6634. WarehouseInfoId: 0,
  6635. AdminUserId: 0,
  6636. StockCount: "",
  6637. IsCheck: 1,
  6638. SysRecordTime: advice.AdviceDate,
  6639. PatientId: advice.PatientId,
  6640. AdviceId: advice.ID,
  6641. ClassType: "",
  6642. }
  6643. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6644. for _, it := range warehousingOutInfo {
  6645. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6646. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6647. //出库逻辑
  6648. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6649. //查询剩余库存
  6650. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6651. var sum_count int64
  6652. for _, its := range stockInfo {
  6653. if its.MaxUnit == medical.MaxUnit {
  6654. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6655. }
  6656. sum_count += its.StockMaxNumber + its.StockMinNumber
  6657. }
  6658. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6659. }
  6660. }
  6661. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6662. //已收费和已发药的限制逻辑
  6663. isCharge := false
  6664. isMedicine := false
  6665. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6666. //获取今天该患者所有处方,判断是否发药或者收费
  6667. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6668. //for _, item := range new_prescriptions {
  6669. if new_prescription.IsMedicine == 1 {
  6670. isMedicine = true
  6671. }
  6672. //}
  6673. for _, item := range new_prescriptions {
  6674. if item.OrderStatus == 4 {
  6675. isCharge = true
  6676. }
  6677. }
  6678. if isMedicine {
  6679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6680. return
  6681. }
  6682. if isCharge {
  6683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6684. return
  6685. }
  6686. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6687. for _, item := range advices {
  6688. if item.IsMedicine == 1 {
  6689. isMedicine = true
  6690. }
  6691. }
  6692. if isMedicine {
  6693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6694. return
  6695. }
  6696. if new_prescription.ID > 0 {
  6697. if new_prescription.OrderStatus == 2 {
  6698. isCharge = true
  6699. }
  6700. }
  6701. if isCharge {
  6702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6703. return
  6704. }
  6705. //已收费和已发药的限制逻辑
  6706. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6707. redis := service.RedisClient()
  6708. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6709. redis.Set(keyFive, "", time.Second)
  6710. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6711. redis.Set(keyOne, "", time.Second)
  6712. defer redis.Close()
  6713. if err == nil {
  6714. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6715. //查询是否在处方中出库
  6716. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6717. if openConfig.IsOpen != 1 {
  6718. //判断该医嘱是否执行了
  6719. if advice.ExecutionState == 1 {
  6720. creater := c.GetAdminUserInfo().AdminUser.Id
  6721. service.DrugAutoAddCancelInfo(&advice, creater)
  6722. }
  6723. }
  6724. //开启保存处方扣减功能
  6725. if openConfig.IsOpen == 1 {
  6726. creater := c.GetAdminUserInfo().AdminUser.Id
  6727. service.DrugAutoAddCancelInfo(&advice, creater)
  6728. }
  6729. } else {
  6730. if drugOutConfig.IsOpen == 1 {
  6731. //查询是否在处方中出库
  6732. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6733. if openConfig.IsOpen != 1 {
  6734. //判断该医嘱是否执行了
  6735. if advice.ExecutionState == 1 {
  6736. creater := c.GetAdminUserInfo().AdminUser.Id
  6737. service.DrugAutoAddCancelInfo(&advice, creater)
  6738. }
  6739. }
  6740. //开启保存处方扣减功能
  6741. if openConfig.IsOpen == 1 {
  6742. creater := c.GetAdminUserInfo().AdminUser.Id
  6743. service.DrugAutoAddCancelInfo(&advice, creater)
  6744. }
  6745. } else {
  6746. //判断该医嘱是否执行了
  6747. if advice.ExecutionState == 1 {
  6748. creater := c.GetAdminUserInfo().AdminUser.Id
  6749. service.DrugAutoAddCancelInfo(&advice, creater)
  6750. }
  6751. }
  6752. }
  6753. c.ServeSuccessJSON(map[string]interface{}{
  6754. "msg": "删除成功",
  6755. })
  6756. return
  6757. } else {
  6758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6759. return
  6760. }
  6761. }
  6762. func (c *HisApiController) DeleteProject() {
  6763. id, _ := c.GetInt64("id")
  6764. adminInfo := c.GetAdminUserInfo()
  6765. project, _ := service.GetHisProjectByID(id)
  6766. // var consumable models.DialysisBeforePrepare
  6767. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6768. //耗材保存处方出库
  6769. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6770. isCharge := false
  6771. isMedicine := false
  6772. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6773. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6774. for _, item := range new_prescriptions {
  6775. if item.IsMedicine == 1 {
  6776. isMedicine = true
  6777. }
  6778. }
  6779. for _, item := range new_prescriptions {
  6780. if item.OrderStatus == 4 {
  6781. isCharge = true
  6782. }
  6783. }
  6784. if isMedicine {
  6785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6786. return
  6787. }
  6788. if isCharge {
  6789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6790. return
  6791. }
  6792. if new_prescription.ID > 0 {
  6793. if new_prescription.OrderStatus == 2 {
  6794. isCharge = true
  6795. }
  6796. }
  6797. if isCharge {
  6798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6799. return
  6800. }
  6801. service.DeletePrintInfo(id)
  6802. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6803. label.Status = 0
  6804. service.CreateHisLabelRecordTwo(&label)
  6805. fmt.Println(goodOutConfig.IsOpen)
  6806. if goodOutConfig.IsOpen != 1 {
  6807. if stockConfig.IsOpen == 1 {
  6808. if project.Type == 2 {
  6809. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6810. fmt.Println(err)
  6811. }
  6812. if project.Type == 3 && project.IsOut == 1 {
  6813. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6814. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6815. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6816. operation_time := time.Now().Unix()
  6817. creater := adminInfo.AdminUser.Id
  6818. //创建退库单
  6819. timeStr := time.Now().Format("2006-01-02")
  6820. timeArr := strings.Split(timeStr, "-")
  6821. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6822. total = total + 1
  6823. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6824. cancelStock := models.CancelStock{
  6825. OrderNumber: orderNumber,
  6826. OperaTime: operation_time,
  6827. OrgId: adminInfo.CurrentOrgId,
  6828. Creater: creater,
  6829. Ctime: time.Now().Unix(),
  6830. Status: 1,
  6831. ReturnTime: project.RecordDate,
  6832. Type: 1,
  6833. StorehouseId: houseConfig.StorehouseOutInfo,
  6834. IsCheck: 1,
  6835. }
  6836. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6837. if msgerrkonde == gorm.ErrRecordNotFound {
  6838. service.AddSigleCancelStock(&cancelStock)
  6839. }
  6840. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6841. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6842. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6843. //查询是否有出库
  6844. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6845. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6846. deaerler, _ := service.GetDealerById(info.Dealer)
  6847. if info.ID > 0 {
  6848. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6849. if info.Count >= prescribingNumber {
  6850. cancelStockInfo := models.CancelStockInfo{
  6851. GoodId: project.ProjectId,
  6852. CancelStockId: cancel.ID,
  6853. GoodTypeId: good.GoodTypeId,
  6854. Count: prescribingNumber,
  6855. Price: info.Price,
  6856. Total: 0,
  6857. ProductDate: info.ProductDate,
  6858. ExpiryDate: info.ExpiryDate,
  6859. Ctime: time.Now().Unix(),
  6860. Status: 1,
  6861. OrgId: adminInfo.CurrentOrgId,
  6862. OrderNumber: cancel.OrderNumber,
  6863. Type: 0,
  6864. Dealer: deaerler.DealerName,
  6865. Manufacturer: manufacturer.ManufacturerName,
  6866. Number: info.Number,
  6867. RegisterAccount: "",
  6868. Remark: "",
  6869. WarehouseInfoId: info.WarehouseInfotId,
  6870. PatientId: info.PatientId,
  6871. RecordDate: info.SysRecordTime,
  6872. StorehouseId: houseConfig.StorehouseOutInfo,
  6873. IsCheck: 1,
  6874. }
  6875. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6876. //回退库存
  6877. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6878. //退库数量增加
  6879. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6880. //出库数量减少
  6881. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6882. }
  6883. if info.Count < prescribingNumber {
  6884. cancelStockInfo := models.CancelStockInfo{
  6885. GoodId: project.ProjectId,
  6886. CancelStockId: cancel.ID,
  6887. GoodTypeId: good.GoodTypeId,
  6888. Count: info.Count,
  6889. Price: info.Price,
  6890. Total: 0,
  6891. ProductDate: info.ProductDate,
  6892. ExpiryDate: info.ExpiryDate,
  6893. Ctime: time.Now().Unix(),
  6894. Status: 1,
  6895. OrgId: adminInfo.CurrentOrgId,
  6896. OrderNumber: cancel.OrderNumber,
  6897. Type: 0,
  6898. Dealer: deaerler.DealerName,
  6899. Manufacturer: manufacturer.ManufacturerName,
  6900. Number: info.Number,
  6901. RegisterAccount: "",
  6902. Remark: "",
  6903. WarehouseInfoId: info.WarehouseInfotId,
  6904. PatientId: info.PatientId,
  6905. RecordDate: info.SysRecordTime,
  6906. StorehouseId: houseConfig.StorehouseOutInfo,
  6907. IsCheck: 1,
  6908. }
  6909. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6910. //回退库存
  6911. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6912. //退库数量增加
  6913. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6914. //出库数量减少
  6915. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6916. }
  6917. //查询剩余库存
  6918. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6919. var over_count int64
  6920. for _, it := range goodList {
  6921. over_count += it.StockCount
  6922. }
  6923. //出库数据 大于 退库数量
  6924. if info.Count >= prescribingNumber {
  6925. flow := models.VmStockFlow{
  6926. WarehousingId: info.WarehouseInfotId,
  6927. GoodId: project.ProjectId,
  6928. Number: info.Number,
  6929. LicenseNumber: info.LicenseNumber,
  6930. Count: prescribingNumber,
  6931. UserOrgId: adminInfo.CurrentOrgId,
  6932. PatientId: project.PatientId,
  6933. SystemTime: info.SysRecordTime,
  6934. ConsumableType: 7,
  6935. IsSys: 0,
  6936. WarehousingOrder: "",
  6937. WarehouseOutId: info.WarehouseOutId,
  6938. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6939. IsEdit: 0,
  6940. CancelStockId: cancel.ID,
  6941. CancelOrderNumber: cancel.OrderNumber,
  6942. Manufacturer: manufacturer.ID,
  6943. Dealer: 0,
  6944. Creator: adminInfo.AdminUser.Id,
  6945. UpdateCreator: 0,
  6946. Status: 1,
  6947. Ctime: time.Now().Unix(),
  6948. Mtime: 0,
  6949. Price: info.Price,
  6950. WarehousingDetailId: info.WarehouseInfotId,
  6951. WarehouseOutDetailId: info.ID,
  6952. CancelOutDetailId: cancelInfo.ID,
  6953. ProductDate: info.ProductDate,
  6954. ExpireDate: info.ExpiryDate,
  6955. StorehouseId: houseConfig.StorehouseOutInfo,
  6956. OverCount: over_count,
  6957. OperateTime: time.Now().Unix(),
  6958. }
  6959. service.CreateStockFlowOne(flow)
  6960. }
  6961. //出库数据小于退库数据
  6962. if info.Count < prescribingNumber {
  6963. flow := models.VmStockFlow{
  6964. WarehousingId: info.WarehouseInfotId,
  6965. GoodId: project.ProjectId,
  6966. Number: info.Number,
  6967. LicenseNumber: info.LicenseNumber,
  6968. Count: info.Count,
  6969. UserOrgId: adminInfo.CurrentOrgId,
  6970. PatientId: project.PatientId,
  6971. SystemTime: info.SysRecordTime,
  6972. ConsumableType: 7,
  6973. IsSys: 0,
  6974. WarehousingOrder: "",
  6975. WarehouseOutId: info.WarehouseOutId,
  6976. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6977. IsEdit: 0,
  6978. CancelStockId: cancel.ID,
  6979. CancelOrderNumber: cancel.OrderNumber,
  6980. Manufacturer: manufacturer.ID,
  6981. Dealer: 0,
  6982. Creator: adminInfo.AdminUser.Id,
  6983. UpdateCreator: 0,
  6984. Status: 1,
  6985. Ctime: time.Now().Unix(),
  6986. Mtime: 0,
  6987. Price: info.Price,
  6988. WarehousingDetailId: info.WarehouseInfotId,
  6989. WarehouseOutDetailId: info.ID,
  6990. CancelOutDetailId: cancelInfo.ID,
  6991. ProductDate: info.ProductDate,
  6992. ExpireDate: info.ExpiryDate,
  6993. StorehouseId: houseConfig.StorehouseOutInfo,
  6994. OverCount: over_count,
  6995. OperateTime: time.Now().Unix(),
  6996. }
  6997. service.CreateStockFlowOne(flow)
  6998. }
  6999. //查询已出库数量
  7000. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7001. if prescribingNumber < dialysisInfo.Count {
  7002. //改变数量
  7003. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7004. }
  7005. if prescribingNumber >= dialysisInfo.Count {
  7006. //删除出库表
  7007. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7008. }
  7009. //更新剩余库存
  7010. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7011. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7012. var total_count_one int64
  7013. for _, it := range stockList {
  7014. total_count_one += it.StockCount
  7015. }
  7016. //基础库插入数据
  7017. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7018. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7019. var flush_count int64
  7020. for _, it := range goodListOne {
  7021. flush_count += it.StockCount
  7022. }
  7023. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7024. if errs != nil {
  7025. goodErrcode := models.XtGoodErrcode{
  7026. UserOrgId: project.UserOrgId,
  7027. Errcode: "手动出库更新剩余出库失败",
  7028. GoodId: project.ProjectId,
  7029. Status: 1,
  7030. Ctime: time.Now().Unix(),
  7031. Mtime: 0,
  7032. Count: 0,
  7033. StockCount: 0,
  7034. Creater: creater,
  7035. BatchNumberId: 0,
  7036. WarehouseOutId: 0,
  7037. }
  7038. service.CreateGoodErrcode(goodErrcode)
  7039. }
  7040. }
  7041. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7042. fmt.Println(err)
  7043. } else {
  7044. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7045. fmt.Println(err)
  7046. }
  7047. } else {
  7048. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7049. fmt.Println(err)
  7050. }
  7051. }
  7052. //保存处方出库
  7053. if goodOutConfig.IsOpen == 1 {
  7054. if project.Type == 3 {
  7055. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7056. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7057. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7058. operation_time := time.Now().Unix()
  7059. creater := adminInfo.AdminUser.Id
  7060. //创建退库单
  7061. timeStr := time.Now().Format("2006-01-02")
  7062. timeArr := strings.Split(timeStr, "-")
  7063. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7064. total = total + 1
  7065. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7066. cancelStock := models.CancelStock{
  7067. OrderNumber: orderNumber,
  7068. OperaTime: operation_time,
  7069. OrgId: adminInfo.CurrentOrgId,
  7070. Creater: creater,
  7071. Ctime: time.Now().Unix(),
  7072. Status: 1,
  7073. ReturnTime: project.RecordDate,
  7074. Type: 1,
  7075. StorehouseId: houseConfig.StorehouseOutInfo,
  7076. IsCheck: 1,
  7077. }
  7078. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7079. if msgerrkonde == gorm.ErrRecordNotFound {
  7080. service.AddSigleCancelStock(&cancelStock)
  7081. }
  7082. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7083. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7084. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7085. //获取出库数据
  7086. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7087. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7088. deaerler, _ := service.GetDealerById(info.Dealer)
  7089. if info.ID > 0 {
  7090. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7091. if info.Count >= prescribingNumber {
  7092. cancelStockInfo := models.CancelStockInfo{
  7093. GoodId: project.ProjectId,
  7094. CancelStockId: cancel.ID,
  7095. GoodTypeId: good.GoodTypeId,
  7096. Count: prescribingNumber,
  7097. Price: info.Price,
  7098. Total: 0,
  7099. ProductDate: info.ProductDate,
  7100. ExpiryDate: info.ExpiryDate,
  7101. Ctime: time.Now().Unix(),
  7102. Status: 1,
  7103. OrgId: adminInfo.CurrentOrgId,
  7104. OrderNumber: cancel.OrderNumber,
  7105. Type: 0,
  7106. Dealer: deaerler.DealerName,
  7107. Manufacturer: manufacturer.ManufacturerName,
  7108. Number: info.Number,
  7109. RegisterAccount: "",
  7110. Remark: "",
  7111. WarehouseInfoId: info.WarehouseInfotId,
  7112. PatientId: info.PatientId,
  7113. RecordDate: info.SysRecordTime,
  7114. StorehouseId: houseConfig.StorehouseOutInfo,
  7115. IsCheck: 1,
  7116. }
  7117. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7118. //退库数量增加
  7119. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7120. //出库数量减少
  7121. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7122. }
  7123. if info.Count < prescribingNumber {
  7124. cancelStockInfo := models.CancelStockInfo{
  7125. GoodId: project.ProjectId,
  7126. CancelStockId: cancel.ID,
  7127. GoodTypeId: good.GoodTypeId,
  7128. Count: prescribingNumber,
  7129. Price: info.Price,
  7130. Total: 0,
  7131. ProductDate: info.ProductDate,
  7132. ExpiryDate: info.ExpiryDate,
  7133. Ctime: time.Now().Unix(),
  7134. Status: 1,
  7135. OrgId: adminInfo.CurrentOrgId,
  7136. OrderNumber: cancel.OrderNumber,
  7137. Type: 0,
  7138. Dealer: deaerler.DealerName,
  7139. Manufacturer: manufacturer.ManufacturerName,
  7140. Number: info.Number,
  7141. RegisterAccount: "",
  7142. Remark: "",
  7143. WarehouseInfoId: info.WarehouseInfotId,
  7144. PatientId: info.PatientId,
  7145. RecordDate: info.SysRecordTime,
  7146. StorehouseId: houseConfig.StorehouseOutInfo,
  7147. IsCheck: 1,
  7148. }
  7149. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7150. //回退库存
  7151. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7152. }
  7153. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7154. var over_count int64
  7155. for _, it := range goodList {
  7156. over_count += it.StockCount
  7157. }
  7158. //查询出库数量
  7159. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7160. //出库数据 大于 退库数量
  7161. if len(list) > 0 {
  7162. for _, it := range list {
  7163. //回退库存
  7164. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7165. //退库数量增加
  7166. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7167. //出库数量减少
  7168. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7169. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7170. var over_count_one int64
  7171. for _, it := range goodList {
  7172. over_count_one += it.StockCount
  7173. }
  7174. //查询该批次是否有退库数据
  7175. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7176. flow := models.VmStockFlow{
  7177. WarehousingId: it.WarehouseInfotId,
  7178. GoodId: it.GoodId,
  7179. Number: it.Number,
  7180. LicenseNumber: it.LicenseNumber,
  7181. Count: it.Count,
  7182. UserOrgId: adminInfo.CurrentOrgId,
  7183. PatientId: it.PatientId,
  7184. SystemTime: it.SysRecordTime,
  7185. ConsumableType: 7,
  7186. IsSys: 0,
  7187. WarehousingOrder: "",
  7188. WarehouseOutId: it.WarehouseOutId,
  7189. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7190. IsEdit: 0,
  7191. CancelStockId: cancel.ID,
  7192. CancelOrderNumber: cancel.OrderNumber,
  7193. Manufacturer: manufacturer.ID,
  7194. Dealer: 0,
  7195. Creator: adminInfo.AdminUser.Id,
  7196. UpdateCreator: 0,
  7197. Status: 1,
  7198. Ctime: time.Now().Unix(),
  7199. Mtime: 0,
  7200. Price: it.Price,
  7201. WarehousingDetailId: it.WarehouseInfotId,
  7202. WarehouseOutDetailId: it.ID,
  7203. CancelOutDetailId: cancelInfo.ID,
  7204. ProductDate: it.ProductDate,
  7205. ExpireDate: it.ExpiryDate,
  7206. StorehouseId: houseConfig.StorehouseOutInfo,
  7207. OverCount: over_count_one,
  7208. OperateTime: time.Now().Unix(),
  7209. }
  7210. service.CreateStockFlowOne(flow)
  7211. }
  7212. }
  7213. //查询已出库数量
  7214. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7215. if prescribingNumber < dialysisInfo.Count {
  7216. //改变数量
  7217. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7218. }
  7219. if prescribingNumber >= dialysisInfo.Count {
  7220. //删除出库表
  7221. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7222. }
  7223. //更新剩余库存
  7224. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7225. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7226. var total_count_one int64
  7227. for _, it := range stockList {
  7228. total_count_one += it.StockCount
  7229. }
  7230. //基础库插入数据
  7231. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7232. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7233. var flush_count int64
  7234. for _, it := range goodListOne {
  7235. flush_count += it.StockCount
  7236. }
  7237. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7238. if errs != nil {
  7239. goodErrcode := models.XtGoodErrcode{
  7240. UserOrgId: project.UserOrgId,
  7241. Errcode: "手动出库更新剩余出库失败",
  7242. GoodId: project.ProjectId,
  7243. Status: 1,
  7244. Ctime: time.Now().Unix(),
  7245. Mtime: 0,
  7246. Count: 0,
  7247. StockCount: 0,
  7248. Creater: creater,
  7249. BatchNumberId: 0,
  7250. WarehouseOutId: 0,
  7251. }
  7252. service.CreateGoodErrcode(goodErrcode)
  7253. }
  7254. }
  7255. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7256. fmt.Println(err)
  7257. } else {
  7258. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7259. fmt.Println(err)
  7260. }
  7261. }
  7262. c.ServeSuccessJSON(map[string]interface{}{
  7263. "msg": "删除成功",
  7264. })
  7265. return
  7266. }
  7267. func (c *HisApiController) CreateHisAdditionalCharge() {
  7268. his_patient_id, _ := c.GetInt64("his_patient_id")
  7269. patient_id, _ := c.GetInt64("patient_id")
  7270. record_date := c.GetString("record_date")
  7271. timeLayout := "2006-01-02"
  7272. loc, _ := time.LoadLocation("Local")
  7273. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7274. if err != nil {
  7275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7276. return
  7277. }
  7278. adminInfo := c.GetAdminUserInfo()
  7279. recordDateTime := theTime.Unix()
  7280. dataBody := make(map[string]interface{}, 0)
  7281. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7282. if err != nil {
  7283. utils.ErrorLog(err.Error())
  7284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7285. return
  7286. }
  7287. var additions []*models.HisAdditionalCharge
  7288. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7289. additions, _ := dataBody["addition"].([]interface{})
  7290. if len(additions) > 0 {
  7291. for _, item := range additions {
  7292. items := item.(map[string]interface{})
  7293. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7294. utils.ErrorLog("item_id")
  7295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7296. return
  7297. }
  7298. item_id := int64(items["item_id"].(float64))
  7299. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7300. utils.ErrorLog("item_name")
  7301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7302. return
  7303. }
  7304. item_name := items["item_name"].(string)
  7305. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7306. utils.ErrorLog("price")
  7307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7308. return
  7309. }
  7310. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7311. ctime := time.Now().Unix()
  7312. additional := &models.HisAdditionalCharge{
  7313. PatientId: patient_id,
  7314. HisPatientId: his_patient_id,
  7315. UserOrgId: adminInfo.CurrentOrgId,
  7316. RecordDate: recordDateTime,
  7317. CreatedTime: ctime,
  7318. UpdatedTime: ctime,
  7319. Modifier: adminInfo.AdminUser.Id,
  7320. Creator: adminInfo.AdminUser.Id,
  7321. Price: price,
  7322. ItemName: item_name,
  7323. ItemId: item_id,
  7324. Status: 1,
  7325. }
  7326. additions = append(additions, additional)
  7327. }
  7328. }
  7329. }
  7330. for _, item := range additions {
  7331. service.CreateAddtionalCharge(item)
  7332. }
  7333. c.ServeSuccessJSON(map[string]interface{}{
  7334. "msg": "创建成功",
  7335. })
  7336. }
  7337. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7338. blood_fat := c.GetString("blood_fat")
  7339. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7340. blood_sugar := c.GetString("blood_sugar")
  7341. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7342. chief_conplaint := c.GetString("chief_conplaint")
  7343. dbp := c.GetString("dbp")
  7344. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7345. delivery_way, _ := c.GetInt64("delivery_way")
  7346. diagnostic := c.GetString("diagnostic")
  7347. family_history := c.GetString("family_history")
  7348. height := c.GetString("height")
  7349. history_of_present_illness := c.GetString("history_of_present_illness")
  7350. is_infect, _ := c.GetInt64("is_infect")
  7351. past_history := c.GetString("past_history")
  7352. patient_id, _ := c.GetInt64("patient_id")
  7353. his_patient_id, _ := c.GetInt64("his_patient_id")
  7354. personal_history := c.GetString("personal_history")
  7355. pulse := c.GetString("pulse")
  7356. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7357. sbp := c.GetString("sbp")
  7358. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7359. heightfloat, _ := strconv.ParseFloat(height, 64)
  7360. sicktype := c.GetString("sick_type")
  7361. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7362. symptom := c.GetString("symptom")
  7363. sick_date := c.GetString("sick_date")
  7364. temperatures := c.GetString("temperature")
  7365. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7366. record_date := c.GetString("record_date")
  7367. breathing := c.GetString("breathing")
  7368. doctor_advice := c.GetString("doctor_advice")
  7369. remark := c.GetString("remark")
  7370. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7371. sick, _ := c.GetInt64("sick")
  7372. diagnose, _ := c.GetInt64("diagnose")
  7373. //id, _ := c.GetInt64("id")
  7374. timeLayout := "2006-01-02"
  7375. loc, _ := time.LoadLocation("Local")
  7376. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7377. allergic_history := c.GetString("allergic_history")
  7378. if err != nil {
  7379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7380. return
  7381. }
  7382. recordDateTime := theTime.Unix()
  7383. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7384. if err != nil {
  7385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7386. return
  7387. }
  7388. sickTimes := sickTime.Unix()
  7389. ctime := time.Now().Unix()
  7390. primary_disease := c.GetString("primary_disease")
  7391. confirm_failure_date := c.GetString("confirm_failure_date")
  7392. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7393. drug_allergy_history := c.GetString("drug_allergy_history")
  7394. physical_examination := c.GetString("physical_examination")
  7395. special_inspection := c.GetString("special_inspection")
  7396. lab_apparatus := c.GetString("lab_apparatus")
  7397. caseHistory := models.HisPatientCaseHistory{
  7398. HisPatientId: his_patient_id,
  7399. PatientId: patient_id,
  7400. Temperature: temperature,
  7401. BloodSugar: bloodsugarfloat,
  7402. Pulse: pulsefloat,
  7403. Sbp: sbpfloat,
  7404. Dbp: dbpfloat,
  7405. Height: heightfloat,
  7406. BloodFat: bloodfatfloat,
  7407. SickType: sick_type,
  7408. Symptom: symptom,
  7409. SickDate: sickTimes,
  7410. IsInfect: is_infect,
  7411. HistoryOfPresentIllness: history_of_present_illness,
  7412. PastHistory: past_history,
  7413. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7414. ChiefConplaint: chief_conplaint,
  7415. PersonalHistory: personal_history,
  7416. FamilyHistory: family_history,
  7417. Diagnostic: diagnostic,
  7418. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7419. Status: 1,
  7420. Ctime: ctime,
  7421. Mtime: ctime,
  7422. RecordDate: recordDateTime,
  7423. DeliveryWay: delivery_way,
  7424. Breathing: breathingfloat,
  7425. DoctorAdvice: doctor_advice,
  7426. Remark: remark,
  7427. Sick: sick,
  7428. Diagnose: diagnose,
  7429. AllergicHistory: allergic_history,
  7430. PrimaryDisease: primary_disease,
  7431. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7432. DrugAllergyHistory: drug_allergy_history,
  7433. PhysicalExamination: physical_examination,
  7434. SpecialInspection: special_inspection,
  7435. LabApparatus: lab_apparatus,
  7436. }
  7437. //查询该患者是否有病历
  7438. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7439. if errcodes == gorm.ErrRecordNotFound {
  7440. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7441. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7442. if err != nil {
  7443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7444. return
  7445. }
  7446. c.ServeSuccessJSON(map[string]interface{}{
  7447. "caseHistory": caseHistory,
  7448. "historyInfo": historyInfo,
  7449. })
  7450. return
  7451. } else if errcodes == nil {
  7452. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7453. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7454. if err != nil {
  7455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7456. return
  7457. }
  7458. c.ServeSuccessJSON(map[string]interface{}{
  7459. "caseHistory": caseHistory,
  7460. "historyInfo": historyInfo,
  7461. })
  7462. }
  7463. //查询该患者是否有病历
  7464. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7465. //if errcode == gorm.ErrRecordNotFound {
  7466. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7467. // if err != nil {
  7468. // c.ServeSuccessJSON(map[string]interface{}{
  7469. // "msg": "保存成功",
  7470. // })
  7471. // }
  7472. //} else if errcode == nil {
  7473. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7474. // return
  7475. //}
  7476. }
  7477. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7478. patient_id, _ := c.GetInt64("patient_id", 0)
  7479. adminUser := c.GetAdminUserInfo()
  7480. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7481. c.ServeSuccessJSON(map[string]interface{}{
  7482. "list": caseHistorys,
  7483. })
  7484. }
  7485. func (c *HisApiController) GetHisPatientCaseHistory() {
  7486. record_date, _ := c.GetInt64("record_date", 0)
  7487. patient_id, _ := c.GetInt64("patient_id", 0)
  7488. admin := c.GetAdminUserInfo()
  7489. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7490. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7491. c.ServeSuccessJSON(map[string]interface{}{
  7492. "info": info,
  7493. "case_history": case_history,
  7494. })
  7495. }
  7496. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7497. template_name := c.GetString("template_name")
  7498. template_remark := c.GetString("template_remark")
  7499. doctor := c.GetAdminUserInfo().AdminUser.Id
  7500. diagnostic := c.GetString("diagnostic")
  7501. chief_conplaint := c.GetString("chief_conplain")
  7502. history_of_present_illness := c.GetString("history_of_present_illness")
  7503. past_history := c.GetString("past_history")
  7504. personal_history := c.GetString("personal_history")
  7505. family_history := c.GetString("family_history")
  7506. user_name := c.GetString("user_name")
  7507. doctor_advice := c.GetString("doctor_advice")
  7508. remark := c.GetString("remark")
  7509. //record_date := c.GetString("record_date")
  7510. //fmt.Println("record_date--------",record_date)
  7511. //timeLayout := "2006-01-02"
  7512. //loc, _ := time.LoadLocation("Local")
  7513. //
  7514. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7515. //if err != nil {
  7516. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7517. // return
  7518. //}
  7519. //recordDateTime := theTime.Unix()
  7520. ctime := time.Now().Unix()
  7521. template := models.HisCaseHistoryTemplate{
  7522. HistoryOfPresentIllness: history_of_present_illness,
  7523. PastHistory: past_history,
  7524. ChiefConplaint: chief_conplaint,
  7525. PersonalHistory: personal_history,
  7526. FamilyHistory: family_history,
  7527. Diagnostic: diagnostic,
  7528. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7529. Status: 1,
  7530. Ctime: ctime,
  7531. Mtime: ctime,
  7532. RecordDate: time.Now().Unix(),
  7533. TemplateName: template_name,
  7534. TemplateRemark: template_remark,
  7535. Creator: doctor,
  7536. Modifier: doctor,
  7537. UserName: user_name,
  7538. DoctorAdvice: doctor_advice,
  7539. Remark: remark,
  7540. }
  7541. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7542. if err == nil {
  7543. c.ServeSuccessJSON(map[string]interface{}{
  7544. "msg": "保存成功",
  7545. })
  7546. } else {
  7547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7548. return
  7549. }
  7550. }
  7551. func (c *HisApiController) GetCaseHistoryTemplate() {
  7552. timeLayout := "2006-01-02"
  7553. loc, _ := time.LoadLocation("Local")
  7554. keyword := c.GetString("keyword")
  7555. start_time := c.GetString("start_time")
  7556. end_time := c.GetString("end_time")
  7557. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7558. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7559. admin := c.GetAdminUserInfo()
  7560. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7561. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7562. c.ServeSuccessJSON(map[string]interface{}{
  7563. "template": template,
  7564. //"history": history,
  7565. })
  7566. }
  7567. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7568. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7569. utils.ErrorLog("drug_name")
  7570. return enums.ErrorCodeParamWrong
  7571. }
  7572. adviceName, _ := json["drug_name"].(string)
  7573. if len(adviceName) == 0 {
  7574. utils.ErrorLog("len(advice_name) == 0")
  7575. return enums.ErrorCodeParamWrong
  7576. }
  7577. advice.AdviceName = adviceName
  7578. adviceDesc, _ := json["advice_desc"].(string)
  7579. advice.AdviceDesc = adviceDesc
  7580. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7581. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7582. advice.DrugSpec = drugSpec
  7583. }
  7584. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7585. remark, _ := json["remark"].(string)
  7586. advice.Remark = remark
  7587. }
  7588. if json["id"] == nil {
  7589. advice.DrugId = 0
  7590. } else {
  7591. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7592. drug_id := int64(json["id"].(float64))
  7593. advice.DrugId = drug_id
  7594. }
  7595. }
  7596. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7597. advice_id := int64(json["advice_id"].(float64))
  7598. advice.ID = advice_id
  7599. if advice.ID > 0 {
  7600. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7601. if err == nil {
  7602. if hisAdvice.ID > 0 {
  7603. advice.ExecutionTime = hisAdvice.ExecutionTime
  7604. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7605. advice.ExecutionState = hisAdvice.ExecutionState
  7606. advice.CheckTime = hisAdvice.CheckTime
  7607. advice.Checker = hisAdvice.Checker
  7608. advice.CheckState = hisAdvice.CheckState
  7609. advice.StartTime = hisAdvice.StartTime
  7610. advice.FeedetlSn = hisAdvice.FeedetlSn
  7611. }
  7612. }
  7613. }
  7614. }
  7615. //
  7616. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7617. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7618. // advice.ExecutionTime = execution_time
  7619. //}
  7620. //
  7621. //
  7622. //
  7623. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7624. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7625. // advice.ExecutionStaff = execution_staff
  7626. //}
  7627. //
  7628. //
  7629. //
  7630. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7631. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7632. // advice.ExecutionState = execution_state
  7633. //}
  7634. //
  7635. //
  7636. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7637. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7638. // advice.CheckTime = check_time
  7639. //}
  7640. //
  7641. //
  7642. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7643. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7644. // advice.CheckState = check_state
  7645. //}
  7646. //
  7647. //
  7648. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7649. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7650. // advice.Checker = checker
  7651. //}
  7652. //
  7653. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7654. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7655. // advice.StartTime = start_time
  7656. //}
  7657. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7658. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7659. advice.IsSelfDrug = is_self_drug
  7660. }
  7661. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7662. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7663. drug_way_count, _ := json["drug_way_count"].(string)
  7664. advice.DrugWayCount = drug_way_count
  7665. }
  7666. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7667. drugSpecUnit, _ := json["min_unit"].(string)
  7668. advice.DrugSpecUnit = drugSpecUnit
  7669. }
  7670. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7671. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7672. advice.SingleDose = singleDose
  7673. }
  7674. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7675. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7676. advice.SingleDoseUnit = singleDoseUnit
  7677. }
  7678. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7679. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7680. advice.PrescribingNumber = prescribingNumber
  7681. }
  7682. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7683. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7684. advice.PrescribingNumberUnit = prescribingNumberUnit
  7685. }
  7686. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7687. deliveryWay, _ := json["delivery_way"].(string)
  7688. advice.DeliveryWay = deliveryWay
  7689. }
  7690. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7691. executionFrequency, _ := json["execution_frequency"].(string)
  7692. advice.ExecutionFrequency = executionFrequency
  7693. }
  7694. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7695. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7696. advice.Price = price
  7697. }
  7698. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7699. med_list_codg, _ := json["medical_insurance_number"].(string)
  7700. advice.MedListCodg = med_list_codg
  7701. }
  7702. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7703. day := int64(json["day"].(float64))
  7704. advice.Day = day
  7705. }
  7706. return 0
  7707. }
  7708. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7709. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7710. id := int64(json["id"].(float64))
  7711. project.ID = id
  7712. historyProject, _ := service.GetHisProjectByID(id)
  7713. project.FeedetlSn = historyProject.FeedetlSn
  7714. }
  7715. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7716. project_id := int64(json["project_id"].(float64))
  7717. project.ProjectId = project_id
  7718. }
  7719. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7720. // price := int64(json["price"].(float64))
  7721. // formatInt_price := strconv.FormatInt(price, 10)
  7722. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7723. // project.Price = float_price
  7724. // }
  7725. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7726. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7727. project.Price = price
  7728. }
  7729. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7730. total, _ := json["total"].(string)
  7731. project.Count = total
  7732. }
  7733. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7734. medical_code, _ := json["medical_code"].(string)
  7735. project.MedListCodg = medical_code
  7736. }
  7737. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7738. single_dose, _ := json["single_dose"].(string)
  7739. project.SingleDose = single_dose
  7740. }
  7741. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7742. delivery_way, _ := json["delivery_way"].(string)
  7743. project.DeliveryWay = delivery_way
  7744. }
  7745. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7746. execution_frequency, _ := json["execution_frequency"].(string)
  7747. project.ExecutionFrequency = execution_frequency
  7748. }
  7749. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7750. remark, _ := json["remark"].(string)
  7751. project.Remark = remark
  7752. }
  7753. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7754. day, _ := json["number_days"].(string)
  7755. project.Day = day
  7756. }
  7757. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7758. unit, _ := json["unit"].(string)
  7759. project.Unit = unit
  7760. }
  7761. return 0
  7762. }
  7763. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7764. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7765. id := int64(json["id"].(float64))
  7766. historyAddtions, _ := service.GetHisAdditionByID(id)
  7767. additionalCharge.ID = id
  7768. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7769. }
  7770. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7771. item_id := int64(json["item_id"].(float64))
  7772. additionalCharge.ItemId = item_id
  7773. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7774. if config.ID > 0 {
  7775. if len(config.Code) > 0 {
  7776. additionalCharge.MedListCodg = config.Code
  7777. }
  7778. }
  7779. }
  7780. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7781. // price := int64(json["price"].(float64))
  7782. // formatInt_price := strconv.FormatInt(price, 10)
  7783. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7784. // additionalCharge.Price = float_price
  7785. // }
  7786. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7787. // price := int64(json["price"].(float64))
  7788. // formatInt_price := strconv.FormatInt(price, 10)
  7789. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7790. // additionalCharge.Price = float_price
  7791. //}
  7792. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7793. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7794. additionalCharge.Price = price
  7795. }
  7796. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7797. count, _ := json["count"].(string)
  7798. counts, _ := strconv.ParseInt(count, 10, 64)
  7799. additionalCharge.Count = counts
  7800. }
  7801. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7802. item_name, _ := json["item_name"].(string)
  7803. additionalCharge.ItemName = item_name
  7804. }
  7805. return 0
  7806. }
  7807. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7808. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7809. utils.ErrorLog("drug_name")
  7810. return enums.ErrorCodeParamWrong
  7811. }
  7812. adviceName, _ := json["drug_name"].(string)
  7813. if len(adviceName) == 0 {
  7814. utils.ErrorLog("len(advice_name) == 0")
  7815. return enums.ErrorCodeParamWrong
  7816. }
  7817. advice.AdviceName = adviceName
  7818. adviceDesc, _ := json["advice_desc"].(string)
  7819. advice.AdviceDesc = adviceDesc
  7820. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7821. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7822. advice.DrugSpec = drugSpec
  7823. }
  7824. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7825. remark, _ := json["remark"].(string)
  7826. advice.Remark = remark
  7827. }
  7828. if json["id"] == nil {
  7829. advice.DrugId = 0
  7830. } else {
  7831. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7832. drug_id := int64(json["id"].(float64))
  7833. advice.DrugId = drug_id
  7834. }
  7835. }
  7836. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7837. groupno := int64(json["groupno"].(float64))
  7838. advice.Groupno = groupno
  7839. }
  7840. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7841. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7842. advice.IsSelfDrug = is_self_drug
  7843. }
  7844. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7845. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7846. drug_way_count, _ := json["drug_way_count"].(string)
  7847. advice.DrugWayCount = drug_way_count
  7848. }
  7849. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7850. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7851. advice.HospApprFlag = hosp_appr_flag
  7852. }
  7853. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7854. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7855. advice.PrescribingNumber = prescribingNumber
  7856. }
  7857. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7858. // frequency_type := int64(json["frequency_type"].(float64))
  7859. // advice.FrequencyType = frequency_type
  7860. //}
  7861. //
  7862. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7863. // day_count := int64(json["day_count"].(float64))
  7864. // advice.DayCount = day_count
  7865. //}
  7866. //
  7867. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7868. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7869. // week_day, _ := json["week_day"].(string)
  7870. // advice.WeekDay = week_day
  7871. //}
  7872. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7873. drugSpecUnit, _ := json["min_unit"].(string)
  7874. advice.DrugSpecUnit = drugSpecUnit
  7875. }
  7876. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7877. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7878. advice.SingleDose = singleDose
  7879. }
  7880. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7881. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7882. advice.SingleDoseUnit = singleDoseUnit
  7883. }
  7884. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7885. deliveryWay, _ := json["delivery_way"].(string)
  7886. advice.DeliveryWay = deliveryWay
  7887. }
  7888. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7889. executionFrequency, _ := json["execution_frequency"].(string)
  7890. advice.ExecutionFrequency = executionFrequency
  7891. }
  7892. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7893. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7894. advice.Price = price
  7895. }
  7896. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7897. med_list_codg, _ := json["medical_insurance_number"].(string)
  7898. advice.MedListCodg = med_list_codg
  7899. }
  7900. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7901. day := int64(json["day"].(float64))
  7902. advice.Day = day
  7903. }
  7904. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7905. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7906. advice.PrescribingNumberUnit = prescribingNumberUnit
  7907. }
  7908. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7909. advice_id := int64(json["advice_id"].(float64))
  7910. advice.ID = advice_id
  7911. if advice.ID > 0 {
  7912. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7913. if err == nil {
  7914. if hisAdvice.ID > 0 {
  7915. advice.ExecutionTime = hisAdvice.ExecutionTime
  7916. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7917. advice.ExecutionState = hisAdvice.ExecutionState
  7918. advice.CheckTime = hisAdvice.CheckTime
  7919. advice.Checker = hisAdvice.Checker
  7920. advice.CheckState = hisAdvice.CheckState
  7921. advice.StartTime = hisAdvice.StartTime
  7922. advice.HospApprFlag = hisAdvice.HospApprFlag
  7923. advice.IsMedicine = hisAdvice.IsMedicine
  7924. if hisAdvice.UserOrgId == 10028 {
  7925. 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 {
  7926. advice.ExecutionTime = 0
  7927. advice.ExecutionStaff = 0
  7928. advice.ExecutionState = 2
  7929. advice.CheckTime = 0
  7930. advice.Checker = 0
  7931. advice.CheckState = 2
  7932. }
  7933. } else {
  7934. 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 {
  7935. advice.ExecutionTime = 0
  7936. advice.ExecutionStaff = 0
  7937. advice.ExecutionState = 2
  7938. advice.CheckTime = 0
  7939. advice.Checker = 0
  7940. advice.CheckState = 2
  7941. advice.UpdatedTime = time.Now().Unix()
  7942. }
  7943. }
  7944. //advice.Groupno = hisAdvice.Groupno
  7945. }
  7946. }
  7947. }
  7948. }
  7949. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7950. //
  7951. //if drugStockConfig.IsOpen == 1 {
  7952. //
  7953. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7954. // if advice.ID == 0 { //医嘱不存在
  7955. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7956. // drug.Total = drug.Total - advice.PrescribingNumber
  7957. // service.UpdateBaseDrugLib(&drug)
  7958. //
  7959. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7960. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7961. // drug.Total = drug.Total - num
  7962. // service.UpdateBaseDrugLib(&drug)
  7963. // }
  7964. //
  7965. // } else if advice.ID > 0 { //医嘱存在
  7966. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7967. // var num float64
  7968. //
  7969. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7970. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7971. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7972. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7973. // drug.Total = drug.Total + num
  7974. // service.UpdateBaseDrugLib(&drug)
  7975. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7976. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7977. // drug.Total = drug.Total - num
  7978. // service.UpdateBaseDrugLib(&drug)
  7979. // }
  7980. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7981. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7982. // if num2 > advice.PrescribingNumber {
  7983. // num = num2 - advice.PrescribingNumber
  7984. // drug.Total = drug.Total + num
  7985. // service.UpdateBaseDrugLib(&drug)
  7986. // } else if num2 < advice.PrescribingNumber {
  7987. // num = advice.PrescribingNumber - num2
  7988. // drug.Total = drug.Total - num
  7989. // service.UpdateBaseDrugLib(&drug)
  7990. // }
  7991. //
  7992. // }
  7993. //
  7994. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7995. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7996. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7997. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7998. // if num1 > num2 {
  7999. // num = num1 - num2
  8000. // drug.Total = drug.Total + num
  8001. // service.UpdateBaseDrugLib(&drug)
  8002. // } else if num1 < num2 {
  8003. // num = num2 - num1
  8004. // drug.Total = drug.Total - num
  8005. // service.UpdateBaseDrugLib(&drug)
  8006. // }
  8007. //
  8008. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8009. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8010. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8011. // if hisAdvice.PrescribingNumber > num2 {
  8012. // num = hisAdvice.PrescribingNumber - num2
  8013. // drug.Total = drug.Total + num
  8014. // service.UpdateBaseDrugLib(&drug)
  8015. // } else if num2 < advice.PrescribingNumber {
  8016. // num = num2 - hisAdvice.PrescribingNumber
  8017. // drug.Total = drug.Total - num
  8018. // service.UpdateBaseDrugLib(&drug)
  8019. // }
  8020. //
  8021. // }
  8022. // }
  8023. // }
  8024. //}
  8025. //
  8026. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8027. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8028. // advice.ExecutionTime = execution_time
  8029. //}
  8030. //
  8031. //
  8032. //
  8033. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8034. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8035. // advice.ExecutionStaff = execution_staff
  8036. //}
  8037. //
  8038. //
  8039. //
  8040. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8041. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8042. // advice.ExecutionState = execution_state
  8043. //}
  8044. //
  8045. //
  8046. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8047. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8048. // advice.CheckTime = check_time
  8049. //}
  8050. //
  8051. //
  8052. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8053. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8054. // advice.CheckState = check_state
  8055. //}
  8056. //
  8057. //
  8058. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8059. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8060. // advice.Checker = checker
  8061. //}
  8062. //
  8063. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8064. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8065. // advice.StartTime = start_time
  8066. //}
  8067. return 0
  8068. }
  8069. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8070. project.ExecutionStaff = 0
  8071. project.ExecutionState = 2
  8072. project.ExecutionTime = 0
  8073. project.Checker = 0
  8074. project.CheckState = 2
  8075. project.CheckTime = 0
  8076. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8077. id := int64(json["id"].(float64))
  8078. project.ID = id
  8079. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8080. project.ExecutionStaff = temp_project.ExecutionStaff
  8081. project.ExecutionState = temp_project.ExecutionState
  8082. project.ExecutionTime = temp_project.ExecutionTime
  8083. project.Checker = temp_project.Checker
  8084. project.CheckState = temp_project.CheckState
  8085. project.CheckTime = temp_project.CheckTime
  8086. project.TeamId = temp_project.TeamId
  8087. }
  8088. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8089. types := int64(json["type"].(float64))
  8090. project.Type = types
  8091. }
  8092. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8093. project_id := int64(json["project_id"].(float64))
  8094. project.ProjectId = project_id
  8095. }
  8096. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8097. team_id := int64(json["team_id"].(float64))
  8098. project.TeamId = team_id
  8099. }
  8100. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8101. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8102. project.Price = price
  8103. }
  8104. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8105. total, _ := json["total"].(string)
  8106. //totals, _ := strconv.ParseInt(total, 10, 64)
  8107. project.Count = total
  8108. }
  8109. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8110. medical_code, _ := json["medical_code"].(string)
  8111. project.MedListCodg = medical_code
  8112. }
  8113. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8114. single_dose, _ := json["single_dose"].(string)
  8115. project.SingleDose = single_dose
  8116. }
  8117. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8118. delivery_way, _ := json["delivery_way"].(string)
  8119. project.DeliveryWay = delivery_way
  8120. }
  8121. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8122. execution_frequency, _ := json["execution_frequency"].(string)
  8123. project.ExecutionFrequency = execution_frequency
  8124. }
  8125. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8126. remark, _ := json["remark"].(string)
  8127. project.Remark = remark
  8128. }
  8129. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8130. day, _ := json["number_days"].(string)
  8131. project.Day = day
  8132. }
  8133. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8134. unit, _ := json["unit"].(string)
  8135. project.Unit = unit
  8136. }
  8137. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8138. // frequency_type := int64(json["frequency_type"].(float64))
  8139. // project.FrequencyType = frequency_type
  8140. //}
  8141. //
  8142. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8143. // day_count := int64(json["day_count"].(float64))
  8144. // project.DayCount = day_count
  8145. //}
  8146. //
  8147. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8148. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8149. // week_day, _ := json["week_day"].(string)
  8150. // project.WeekDay = week_day
  8151. //}
  8152. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8153. //
  8154. //if project.ID == 0 {
  8155. // if stockConfig.IsOpen == 1 {
  8156. // if project.Type == 3 {
  8157. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8158. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8159. // good.Total = good.Total - f_count
  8160. // service.UpdateGoodInfo(&good)
  8161. // }
  8162. // }
  8163. //
  8164. //} else {
  8165. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8166. //
  8167. // if stockConfig.IsOpen == 1 {
  8168. // if project.Type == 3 {
  8169. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8170. // if project.Count < temp_project.Count {
  8171. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8172. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8173. //
  8174. // other_count := f_count_two - f_count_one
  8175. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8176. // good.Total = good.Total + other_count_two
  8177. // service.UpdateGoodInfo(&good)
  8178. // } else if project.Count > temp_project.Count {
  8179. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8180. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8181. //
  8182. // other_count := f_count_one - f_count_two
  8183. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8184. // good.Total = good.Total - other_count_two
  8185. // service.UpdateGoodInfo(&good)
  8186. // }
  8187. //
  8188. // }
  8189. // }
  8190. //
  8191. //}
  8192. return 0
  8193. }
  8194. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8195. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8196. utils.ErrorLog("drug_name")
  8197. return enums.ErrorCodeParamWrong
  8198. }
  8199. adviceName, _ := json["drug_name"].(string)
  8200. if len(adviceName) == 0 {
  8201. utils.ErrorLog("len(advice_name) == 0")
  8202. return enums.ErrorCodeParamWrong
  8203. }
  8204. advice.AdviceName = adviceName
  8205. adviceDesc, _ := json["advice_desc"].(string)
  8206. advice.AdviceDesc = adviceDesc
  8207. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8208. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8209. advice.DrugSpec = drugSpec
  8210. }
  8211. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8212. remark, _ := json["remark"].(string)
  8213. advice.Remark = remark
  8214. }
  8215. if json["id"] == nil {
  8216. advice.DrugId = 0
  8217. } else {
  8218. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8219. drug_id := int64(json["id"].(float64))
  8220. advice.DrugId = drug_id
  8221. }
  8222. }
  8223. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8224. groupno := int64(json["groupno"].(float64))
  8225. advice.Groupno = groupno
  8226. }
  8227. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8228. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8229. advice.IsSelfDrug = is_self_drug
  8230. }
  8231. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8232. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8233. drug_way_count, _ := json["drug_way_count"].(string)
  8234. advice.DrugWayCount = drug_way_count
  8235. }
  8236. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8237. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8238. advice.HospApprFlag = hosp_appr_flag
  8239. }
  8240. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8241. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8242. advice.PrescribingNumber = prescribingNumber
  8243. }
  8244. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8245. // frequency_type := int64(json["frequency_type"].(float64))
  8246. // advice.FrequencyType = frequency_type
  8247. //}
  8248. //
  8249. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8250. // day_count := int64(json["day_count"].(float64))
  8251. // advice.DayCount = day_count
  8252. //}
  8253. //
  8254. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8255. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8256. // week_day, _ := json["week_day"].(string)
  8257. // advice.WeekDay = week_day
  8258. //}
  8259. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8260. drugSpecUnit, _ := json["min_unit"].(string)
  8261. advice.DrugSpecUnit = drugSpecUnit
  8262. }
  8263. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8264. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8265. advice.SingleDose = singleDose
  8266. }
  8267. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8268. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8269. advice.SingleDoseUnit = singleDoseUnit
  8270. }
  8271. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8272. deliveryWay, _ := json["delivery_way"].(string)
  8273. advice.DeliveryWay = deliveryWay
  8274. }
  8275. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8276. executionFrequency, _ := json["execution_frequency"].(string)
  8277. advice.ExecutionFrequency = executionFrequency
  8278. }
  8279. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8280. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8281. advice.Price = price
  8282. }
  8283. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8284. med_list_codg, _ := json["medical_insurance_number"].(string)
  8285. advice.MedListCodg = med_list_codg
  8286. }
  8287. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8288. day := int64(json["day"].(float64))
  8289. advice.Day = day
  8290. }
  8291. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8292. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8293. advice.PrescribingNumberUnit = prescribingNumberUnit
  8294. }
  8295. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8296. advice_id := int64(json["advice_id"].(float64))
  8297. advice.ID = advice_id
  8298. if advice.ID > 0 {
  8299. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8300. if err == nil {
  8301. if hisAdvice.ID > 0 {
  8302. advice.ExecutionTime = hisAdvice.ExecutionTime
  8303. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8304. advice.ExecutionState = hisAdvice.ExecutionState
  8305. advice.CheckTime = hisAdvice.CheckTime
  8306. advice.Checker = hisAdvice.Checker
  8307. advice.DrugCode = hisAdvice.DrugCode
  8308. advice.CheckState = hisAdvice.CheckState
  8309. advice.StartTime = hisAdvice.StartTime
  8310. advice.HospApprFlag = hisAdvice.HospApprFlag
  8311. advice.IsMedicine = hisAdvice.IsMedicine
  8312. if hisAdvice.UserOrgId == 10028 {
  8313. 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 {
  8314. advice.ExecutionTime = 0
  8315. advice.ExecutionStaff = 0
  8316. advice.ExecutionState = 2
  8317. advice.CheckTime = 0
  8318. advice.Checker = 0
  8319. advice.CheckState = 2
  8320. }
  8321. } else {
  8322. 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 {
  8323. advice.ExecutionTime = 0
  8324. advice.ExecutionStaff = 0
  8325. advice.ExecutionState = 2
  8326. advice.CheckTime = 0
  8327. advice.Checker = 0
  8328. advice.CheckState = 2
  8329. //advice.UpdatedTime = time.Now().Unix()
  8330. advice.CreatedTime = hisAdvice.CreatedTime
  8331. advice.UpdatedTime = time.Now().Unix()
  8332. } else {
  8333. advice.CreatedTime = hisAdvice.CreatedTime
  8334. advice.UpdatedTime = hisAdvice.UpdatedTime
  8335. }
  8336. }
  8337. //advice.Groupno = hisAdvice.Groupno
  8338. } else {
  8339. advice.IsMedicine = 0
  8340. ctime := time.Now().Unix()
  8341. advice.CreatedTime = ctime
  8342. advice.UpdatedTime = ctime
  8343. }
  8344. }
  8345. } else {
  8346. advice.IsMedicine = 0
  8347. ctime := time.Now().Unix()
  8348. advice.CreatedTime = ctime
  8349. advice.UpdatedTime = ctime
  8350. }
  8351. }
  8352. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8353. //
  8354. //if drugStockConfig.IsOpen == 1 {
  8355. //
  8356. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8357. // if advice.ID == 0 { //医嘱不存在
  8358. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8359. // drug.Total = drug.Total - advice.PrescribingNumber
  8360. // service.UpdateBaseDrugLib(&drug)
  8361. //
  8362. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8363. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8364. // drug.Total = drug.Total - num
  8365. // service.UpdateBaseDrugLib(&drug)
  8366. // }
  8367. //
  8368. // } else if advice.ID > 0 { //医嘱存在
  8369. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8370. // var num float64
  8371. //
  8372. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8373. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8374. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8375. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8376. // drug.Total = drug.Total + num
  8377. // service.UpdateBaseDrugLib(&drug)
  8378. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8379. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8380. // drug.Total = drug.Total - num
  8381. // service.UpdateBaseDrugLib(&drug)
  8382. // }
  8383. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8384. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8385. // if num2 > advice.PrescribingNumber {
  8386. // num = num2 - advice.PrescribingNumber
  8387. // drug.Total = drug.Total + num
  8388. // service.UpdateBaseDrugLib(&drug)
  8389. // } else if num2 < advice.PrescribingNumber {
  8390. // num = advice.PrescribingNumber - num2
  8391. // drug.Total = drug.Total - num
  8392. // service.UpdateBaseDrugLib(&drug)
  8393. // }
  8394. //
  8395. // }
  8396. //
  8397. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8398. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8399. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8400. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8401. // if num1 > num2 {
  8402. // num = num1 - num2
  8403. // drug.Total = drug.Total + num
  8404. // service.UpdateBaseDrugLib(&drug)
  8405. // } else if num1 < num2 {
  8406. // num = num2 - num1
  8407. // drug.Total = drug.Total - num
  8408. // service.UpdateBaseDrugLib(&drug)
  8409. // }
  8410. //
  8411. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8412. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8413. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8414. // if hisAdvice.PrescribingNumber > num2 {
  8415. // num = hisAdvice.PrescribingNumber - num2
  8416. // drug.Total = drug.Total + num
  8417. // service.UpdateBaseDrugLib(&drug)
  8418. // } else if num2 < advice.PrescribingNumber {
  8419. // num = num2 - hisAdvice.PrescribingNumber
  8420. // drug.Total = drug.Total - num
  8421. // service.UpdateBaseDrugLib(&drug)
  8422. // }
  8423. //
  8424. // }
  8425. // }
  8426. // }
  8427. //}
  8428. //
  8429. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8430. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8431. // advice.ExecutionTime = execution_time
  8432. //}
  8433. //
  8434. //
  8435. //
  8436. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8437. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8438. // advice.ExecutionStaff = execution_staff
  8439. //}
  8440. //
  8441. //
  8442. //
  8443. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8444. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8445. // advice.ExecutionState = execution_state
  8446. //}
  8447. //
  8448. //
  8449. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8450. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8451. // advice.CheckTime = check_time
  8452. //}
  8453. //
  8454. //
  8455. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8456. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8457. // advice.CheckState = check_state
  8458. //}
  8459. //
  8460. //
  8461. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8462. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8463. // advice.Checker = checker
  8464. //}
  8465. //
  8466. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8467. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8468. // advice.StartTime = start_time
  8469. //}
  8470. return 0
  8471. }
  8472. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8473. project.ExecutionStaff = 0
  8474. project.ExecutionState = 2
  8475. project.ExecutionTime = 0
  8476. project.Checker = 0
  8477. project.CheckState = 2
  8478. project.CheckTime = 0
  8479. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8480. id := int64(json["id"].(float64))
  8481. project.ID = id
  8482. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8483. project.ExecutionStaff = temp_project.ExecutionStaff
  8484. project.ExecutionState = temp_project.ExecutionState
  8485. project.ExecutionTime = temp_project.ExecutionTime
  8486. project.Checker = temp_project.Checker
  8487. project.CheckState = temp_project.CheckState
  8488. project.CheckTime = temp_project.CheckTime
  8489. project.TeamId = temp_project.TeamId
  8490. }
  8491. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8492. types := int64(json["type"].(float64))
  8493. project.Type = types
  8494. }
  8495. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8496. project_id := int64(json["project_id"].(float64))
  8497. project.ProjectId = project_id
  8498. }
  8499. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8500. team_id := int64(json["team_id"].(float64))
  8501. project.TeamId = team_id
  8502. }
  8503. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8504. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8505. project.Price = price
  8506. }
  8507. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8508. total, _ := json["total"].(string)
  8509. //totals, _ := strconv.ParseInt(total, 10, 64)
  8510. project.Count = total
  8511. }
  8512. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8513. medical_code, _ := json["medical_code"].(string)
  8514. project.MedListCodg = medical_code
  8515. }
  8516. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8517. single_dose, _ := json["single_dose"].(string)
  8518. project.SingleDose = single_dose
  8519. }
  8520. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8521. delivery_way, _ := json["delivery_way"].(string)
  8522. project.DeliveryWay = delivery_way
  8523. }
  8524. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8525. execution_frequency, _ := json["execution_frequency"].(string)
  8526. project.ExecutionFrequency = execution_frequency
  8527. }
  8528. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8529. remark, _ := json["remark"].(string)
  8530. project.Remark = remark
  8531. }
  8532. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8533. day, _ := json["number_days"].(string)
  8534. project.Day = day
  8535. }
  8536. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8537. unit, _ := json["unit"].(string)
  8538. project.Unit = unit
  8539. }
  8540. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8541. // frequency_type := int64(json["frequency_type"].(float64))
  8542. // project.FrequencyType = frequency_type
  8543. //}
  8544. //
  8545. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8546. // day_count := int64(json["day_count"].(float64))
  8547. // project.DayCount = day_count
  8548. //}
  8549. //
  8550. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8551. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8552. // week_day, _ := json["week_day"].(string)
  8553. // project.WeekDay = week_day
  8554. //}
  8555. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8556. //
  8557. //if project.ID == 0 {
  8558. // if stockConfig.IsOpen == 1 {
  8559. // if project.Type == 3 {
  8560. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8561. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8562. // good.Total = good.Total - f_count
  8563. // service.UpdateGoodInfo(&good)
  8564. // }
  8565. // }
  8566. //
  8567. //} else {
  8568. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8569. //
  8570. // if stockConfig.IsOpen == 1 {
  8571. // if project.Type == 3 {
  8572. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8573. // if project.Count < temp_project.Count {
  8574. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8575. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8576. //
  8577. // other_count := f_count_two - f_count_one
  8578. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8579. // good.Total = good.Total + other_count_two
  8580. // service.UpdateGoodInfo(&good)
  8581. // } else if project.Count > temp_project.Count {
  8582. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8583. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8584. //
  8585. // other_count := f_count_one - f_count_two
  8586. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8587. // good.Total = good.Total - other_count_two
  8588. // service.UpdateGoodInfo(&good)
  8589. // }
  8590. //
  8591. // }
  8592. // }
  8593. //
  8594. //}
  8595. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8596. id := int64(json["id"].(float64))
  8597. if id > 0 {
  8598. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8599. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8600. fmt.Println("666666")
  8601. project.Mtime = time.Now().Unix()
  8602. project.Ctime = temp_project.Ctime
  8603. } else {
  8604. project.Mtime = temp_project.Mtime
  8605. project.Ctime = temp_project.Ctime
  8606. }
  8607. } else {
  8608. ctime := time.Now().Unix()
  8609. project.Mtime = ctime
  8610. project.Ctime = ctime
  8611. }
  8612. }
  8613. return 0
  8614. }
  8615. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8616. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8617. id := int64(json["id"].(float64))
  8618. additionalCharge.ID = id
  8619. }
  8620. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8621. item_id := int64(json["item_id"].(float64))
  8622. additionalCharge.ItemId = item_id
  8623. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8624. if config.ID > 0 {
  8625. if len(config.Code) > 0 {
  8626. additionalCharge.MedListCodg = config.Code
  8627. }
  8628. }
  8629. }
  8630. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8631. // price := int64(json["price"].(float64))
  8632. // formatInt_price := strconv.FormatInt(price, 10)
  8633. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8634. // additionalCharge.Price = float_price
  8635. // }
  8636. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8637. // price := int64(json["price"].(float64))
  8638. // formatInt_price := strconv.FormatInt(price, 10)
  8639. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8640. // additionalCharge.Price = float_price
  8641. //}
  8642. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8643. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8644. additionalCharge.Price = price
  8645. }
  8646. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8647. count, _ := json["count"].(string)
  8648. counts, _ := strconv.ParseInt(count, 10, 64)
  8649. additionalCharge.Count = counts
  8650. }
  8651. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8652. item_name, _ := json["item_name"].(string)
  8653. additionalCharge.ItemName = item_name
  8654. }
  8655. return 0
  8656. }
  8657. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8658. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8659. utils.ErrorLog("drug_name")
  8660. return enums.ErrorCodeParamWrong
  8661. }
  8662. adviceName, _ := json["drug_name"].(string)
  8663. if len(adviceName) == 0 {
  8664. utils.ErrorLog("len(advice_name) == 0")
  8665. return enums.ErrorCodeParamWrong
  8666. }
  8667. advice.AdviceName = adviceName
  8668. adviceDesc, _ := json["advice_desc"].(string)
  8669. advice.AdviceDesc = adviceDesc
  8670. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8671. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8672. advice.DrugSpec = drugSpec
  8673. }
  8674. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8675. remark, _ := json["remark"].(string)
  8676. advice.Remark = remark
  8677. }
  8678. if json["id"] == nil {
  8679. advice.DrugId = 0
  8680. } else {
  8681. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8682. drug_id := int64(json["id"].(float64))
  8683. advice.DrugId = drug_id
  8684. }
  8685. }
  8686. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8687. groupno := int64(json["groupno"].(float64))
  8688. advice.Groupno = groupno
  8689. }
  8690. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8691. drugSpecUnit, _ := json["min_unit"].(string)
  8692. advice.DrugSpecUnit = drugSpecUnit
  8693. }
  8694. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8695. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8696. advice.SingleDose = singleDose
  8697. }
  8698. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8699. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8700. advice.SingleDoseUnit = singleDoseUnit
  8701. }
  8702. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8703. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8704. advice.PrescribingNumber = prescribingNumber
  8705. }
  8706. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8707. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8708. advice.PrescribingNumberUnit = prescribingNumberUnit
  8709. }
  8710. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8711. deliveryWay, _ := json["delivery_way"].(string)
  8712. advice.DeliveryWay = deliveryWay
  8713. }
  8714. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8715. executionFrequency, _ := json["execution_frequency"].(string)
  8716. advice.ExecutionFrequency = executionFrequency
  8717. }
  8718. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8719. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8720. advice.Price = price
  8721. }
  8722. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8723. med_list_codg, _ := json["medical_insurance_number"].(string)
  8724. advice.MedListCodg = med_list_codg
  8725. }
  8726. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8727. day := int64(json["day"].(float64))
  8728. advice.Day = day
  8729. }
  8730. advice.FrequencyType = 1
  8731. return 0
  8732. }
  8733. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8734. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8735. types := int64(json["type"].(float64))
  8736. project.Type = types
  8737. }
  8738. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8739. project_id := int64(json["project_id"].(float64))
  8740. project.ProjectId = project_id
  8741. }
  8742. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8743. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8744. project.Price = price
  8745. }
  8746. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8747. total, _ := json["total"].(string)
  8748. //totals, _ := strconv.ParseInt(total, 10, 64)
  8749. project.Count = total
  8750. }
  8751. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8752. medical_code, _ := json["medical_code"].(string)
  8753. project.MedListCodg = medical_code
  8754. }
  8755. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8756. single_dose, _ := json["single_dose"].(string)
  8757. project.SingleDose = single_dose
  8758. }
  8759. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8760. delivery_way, _ := json["delivery_way"].(string)
  8761. project.DeliveryWay = delivery_way
  8762. }
  8763. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8764. execution_frequency, _ := json["execution_frequency"].(string)
  8765. project.ExecutionFrequency = execution_frequency
  8766. }
  8767. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8768. remark, _ := json["remark"].(string)
  8769. project.Remark = remark
  8770. }
  8771. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8772. day, _ := json["number_days"].(string)
  8773. project.Day = day
  8774. }
  8775. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8776. unit, _ := json["unit"].(string)
  8777. project.Unit = unit
  8778. }
  8779. project.FrequencyType = 1
  8780. return 0
  8781. }
  8782. func (c *HisApiController) GetHisOrderListTwo() {
  8783. start_time := c.GetString("start_time")
  8784. end_time := c.GetString("end_time")
  8785. timeLayout := "2006-01-02"
  8786. loc, _ := time.LoadLocation("Local")
  8787. var startTime int64
  8788. if len(start_time) > 0 {
  8789. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8790. if err != nil {
  8791. //fmt.Println(err)
  8792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8793. return
  8794. }
  8795. startTime = theTime.Unix()
  8796. }
  8797. var endTime int64
  8798. if len(end_time) > 0 {
  8799. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8800. if err != nil {
  8801. utils.ErrorLog(err.Error())
  8802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8803. return
  8804. }
  8805. endTime = theTime.Unix()
  8806. }
  8807. adminUser := c.GetAdminUserInfo()
  8808. org_id := adminUser.CurrentOrgId
  8809. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8810. if err == nil {
  8811. c.ServeSuccessJSON(map[string]interface{}{
  8812. "order2": order,
  8813. })
  8814. } else {
  8815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8816. return
  8817. }
  8818. }
  8819. func (c *HisApiController) GetHisOrderList() {
  8820. page, _ := c.GetInt64("page", -1)
  8821. limit, _ := c.GetInt64("limit", -1)
  8822. start_time := c.GetString("start_time")
  8823. end_time := c.GetString("end_time")
  8824. types, _ := c.GetInt64("type", 0)
  8825. keywords := c.GetString("keywords")
  8826. p_type, _ := c.GetInt64("p_type", 0)
  8827. sort_type, _ := c.GetInt64("sort_type", 0)
  8828. charge_type, _ := c.GetInt64("charge_type", 0)
  8829. sch_type, _ := c.GetInt64("sch_type", 0)
  8830. zone_type, _ := c.GetInt64("zone_type", 0)
  8831. med_type, _ := c.GetInt64("med_type", 0)
  8832. timeLayout := "2006-01-02"
  8833. loc, _ := time.LoadLocation("Local")
  8834. var startTime int64
  8835. if len(start_time) > 0 {
  8836. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8837. if err != nil {
  8838. //fmt.Println(err)
  8839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8840. return
  8841. }
  8842. startTime = theTime.Unix()
  8843. }
  8844. var endTime int64
  8845. if len(end_time) > 0 {
  8846. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8847. if err != nil {
  8848. utils.ErrorLog(err.Error())
  8849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8850. return
  8851. }
  8852. endTime = theTime.Unix()
  8853. }
  8854. adminUser := c.GetAdminUserInfo()
  8855. org_id := adminUser.CurrentOrgId
  8856. 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)
  8857. for _, item := range order {
  8858. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8859. item.DoctorName = info.Doctor
  8860. item.DepartmentName = info.XtHisDepartment.Name
  8861. }
  8862. if err == nil {
  8863. c.ServeSuccessJSON(map[string]interface{}{
  8864. "order": order,
  8865. "total": total,
  8866. })
  8867. } else {
  8868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8869. return
  8870. }
  8871. }
  8872. func (c *HisApiController) GetHisOrder() {
  8873. patient_id, _ := c.GetInt64("patient_id", 0)
  8874. number := c.GetString("number")
  8875. adminInfo := c.GetAdminUserInfo()
  8876. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8877. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8878. if err == nil {
  8879. c.ServeSuccessJSON(map[string]interface{}{
  8880. "order": order,
  8881. "prescription": prescriptions,
  8882. })
  8883. } else {
  8884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8885. return
  8886. }
  8887. }
  8888. func (c *HisApiController) GetHisPrescriptionList() {
  8889. record_date := c.GetString("record_date")
  8890. keywords := c.GetString("keywords")
  8891. page, _ := c.GetInt64("page")
  8892. limit, _ := c.GetInt64("limit")
  8893. sch_type, _ := c.GetInt64("sch_type")
  8894. timeLayout := "2006-01-02"
  8895. loc, _ := time.LoadLocation("Local")
  8896. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8897. if err != nil {
  8898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8899. return
  8900. }
  8901. recordDateTime := theTime.Unix()
  8902. adminInfo := c.GetAdminUserInfo()
  8903. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8904. //adminInfo := c.GetAdminUserInfo()
  8905. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8906. //fmt.Println(prescriptionOrder)
  8907. if err == nil {
  8908. c.ServeSuccessJSON(map[string]interface{}{
  8909. "order": prescriptionOrder,
  8910. "total": total,
  8911. })
  8912. } else {
  8913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8914. return
  8915. }
  8916. }
  8917. func (c *HisApiController) GetHisPrescriptionInfo() {
  8918. id, _ := c.GetInt64("id")
  8919. adminInfo := c.GetAdminUserInfo()
  8920. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8921. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8922. if err == nil {
  8923. c.ServeSuccessJSON(map[string]interface{}{
  8924. "order": prescriptionOrder,
  8925. "prescription": prescription,
  8926. })
  8927. } else {
  8928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8929. return
  8930. }
  8931. }
  8932. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8933. adminUser := c.GetAdminUserInfo()
  8934. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8935. c.ServeSuccessJSON(map[string]interface{}{
  8936. "config": config,
  8937. })
  8938. }
  8939. type ResultTwo struct {
  8940. ErrMsg interface{} `json:"err_msg"`
  8941. InfRefmsgid string `json:"inf_refmsgid"`
  8942. Infcode int64 `json:"infcode"`
  8943. Output struct {
  8944. Baseinfo struct {
  8945. Age float64 `json:"age"`
  8946. Brdy string `json:"brdy"`
  8947. Certno string `json:"certno"`
  8948. Gend string `json:"gend"`
  8949. Naty string `json:"naty"`
  8950. PsnCertType string `json:"psn_cert_type"`
  8951. PsnName string `json:"psn_name"`
  8952. PsnNo string `json:"psn_no"`
  8953. } `json:"baseinfo"`
  8954. Idetinfo []interface{} `json:"idetinfo"`
  8955. Iinfo []struct {
  8956. Balc float64 `json:"balc"`
  8957. CvlservFlag string `json:"cvlserv_flag"`
  8958. EmpName string `json:"emp_name"`
  8959. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8960. Insutype string `json:"insutype"`
  8961. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8962. PausInsuDate interface{} `json:"paus_insu_date"`
  8963. PsnInsuDate string `json:"psn_insu_date"`
  8964. PsnInsuStas string `json:"psn_insu_stas"`
  8965. PsnType string `json:"psn_type"`
  8966. } `json:"insuinfo"`
  8967. } `json:"output"`
  8968. RefmsgTime string `json:"refmsg_time"`
  8969. RespondTime string `json:"respond_time"`
  8970. Signtype interface{} `json:"signtype"`
  8971. WarnInfo interface{} `json:"warn_info"`
  8972. }
  8973. type ResultThree struct {
  8974. Cainfo interface{} `json:"cainfo"`
  8975. ErrMsg interface{} `json:"err_msg"`
  8976. InfRefmsgid string `json:"inf_refmsgid"`
  8977. Infcode int64 `json:"infcode"`
  8978. Output struct {
  8979. Data struct {
  8980. IptOtpNo string `json:"ipt_otp_no"`
  8981. MdtrtID string `json:"mdtrt_id"`
  8982. PsnNo string `json:"psn_no"`
  8983. } `json:"data"`
  8984. } `json:"output"`
  8985. RefmsgTime string `json:"refmsg_time"`
  8986. RespondTime string `json:"respond_time"`
  8987. Signtype interface{} `json:"signtype"`
  8988. WarnMsg interface{} `json:"warn_msg"`
  8989. }
  8990. type ResultFour struct {
  8991. Cainfo string `json:"cainfo"`
  8992. ErrMsg string `json:"err_msg"`
  8993. InfRefmsgid string `json:"inf_refmsgid"`
  8994. Infcode int64 `json:"infcode"`
  8995. Output struct {
  8996. Result []struct {
  8997. BasMednFlag string `json:"bas_medn_flag"`
  8998. ChldMedcFlag string `json:"chld_medc_flag"`
  8999. ChrgitmLv string `json:"chrgitm_lv"`
  9000. Cnt float64 `json:"cnt"`
  9001. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9002. DrtReimFlag string `json:"drt_reim_flag"`
  9003. FeedetlSn string `json:"feedetl_sn"`
  9004. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9005. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9006. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9007. ListSpItemFlag string `json:"list_sp_item_flag"`
  9008. LmtUsedFlag string `json:"lmt_used_flag"`
  9009. MedChrgitmType string `json:"med_chrgitm_type"`
  9010. Memo string `json:"memo"`
  9011. OverlmtAmt float64 `json:"overlmt_amt"`
  9012. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9013. Pric float64 `json:"pric"`
  9014. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9015. SelfpayProp float64 `json:"selfpay_prop"`
  9016. } `json:"result"`
  9017. } `json:"output"`
  9018. RefmsgTime string `json:"refmsg_time"`
  9019. RespondTime string `json:"respond_time"`
  9020. Signtype string `json:"signtype"`
  9021. WarnMsg string `json:"warn_msg"`
  9022. }
  9023. type ResultFive struct {
  9024. Insutype string `json:"insutype"`
  9025. }
  9026. type ResultSix struct {
  9027. Cainfo interface{} `json:"cainfo"`
  9028. ErrMsg interface{} `json:"err_msg"`
  9029. InfRefmsgid string `json:"inf_refmsgid"`
  9030. Infcode int64 `json:"infcode"`
  9031. Output struct {
  9032. } `json:"output"`
  9033. RefmsgTime string `json:"refmsg_time"`
  9034. RespondTime string `json:"respond_time"`
  9035. Signtype interface{} `json:"signtype"`
  9036. WarnMsg interface{} `json:"warn_msg"`
  9037. }
  9038. type ResultSeven struct {
  9039. Cainfo string `json:"cainfo"`
  9040. ErrMsg string `json:"err_msg"`
  9041. InfRefmsgid string `json:"inf_refmsgid"`
  9042. Infcode int64 `json:"infcode"`
  9043. Output struct {
  9044. Setldetail []interface{} `json:"setldetail"`
  9045. Setlinfo struct {
  9046. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9047. AcctPay float64 `json:"acct_pay"`
  9048. ActPayDedc float64 `json:"act_pay_dedc"`
  9049. Age float64 `json:"age"`
  9050. Balc float64 `json:"balc"`
  9051. Brdy string `json:"brdy"`
  9052. Certno string `json:"certno"`
  9053. ClrOptins string `json:"clr_optins"`
  9054. ClrType string `json:"clr_type"`
  9055. ClrWay string `json:"clr_way"`
  9056. CvlservFlag string `json:"cvlserv_flag"`
  9057. CvlservPay float64 `json:"cvlserv_pay"`
  9058. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9059. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9060. Gend string `json:"gend"`
  9061. HifesPay float64 `json:"hifes_pay"`
  9062. HifmiPay float64 `json:"hifmi_pay"`
  9063. HifobPay float64 `json:"hifob_pay"`
  9064. HifpPay float64 `json:"hifp_pay"`
  9065. HospPartAmt float64 `json:"hosp_part_amt"`
  9066. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9067. Insutype string `json:"insutype"`
  9068. MafPay float64 `json:"maf_pay"`
  9069. MdtrtCertType string `json:"mdtrt_cert_type"`
  9070. MdtrtID string `json:"mdtrt_id"`
  9071. MedType string `json:"med_type"`
  9072. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9073. MedinsSetlID string `json:"medins_setl_id"`
  9074. Naty string `json:"naty"`
  9075. OthPay float64 `json:"oth_pay"`
  9076. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9077. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9078. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9079. PsnCashPay float64 `json:"psn_cash_pay"`
  9080. PsnCertType string `json:"psn_cert_type"`
  9081. PsnName string `json:"psn_name"`
  9082. PsnNo string `json:"psn_no"`
  9083. PsnPartAmt float64 `json:"psn_part_amt"`
  9084. PsnType string `json:"psn_type"`
  9085. SetlID string `json:"setl_id"`
  9086. SetlTime string `json:"setl_time"`
  9087. } `json:"setlinfo"`
  9088. } `json:"output"`
  9089. RefmsgTime string `json:"refmsg_time"`
  9090. RespondTime string `json:"respond_time"`
  9091. Signtype interface{} `json:"signtype"`
  9092. WarnMsg interface{} `json:"warn_msg"`
  9093. }
  9094. type ResultEight struct {
  9095. Cainfo string `json:"cainfo"`
  9096. ErrMsg string `json:"err_msg"`
  9097. InfRefmsgid string `json:"inf_refmsgid"`
  9098. Infcode int64 `json:"infcode"`
  9099. Output struct {
  9100. Stmtinfo struct {
  9101. SetlOptins string `json:"setl_optins"`
  9102. StmtRslt string `json:"stmt_rslt"`
  9103. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9104. } `json:"stmtinfo"`
  9105. } `json:"output"`
  9106. RefmsgTime string `json:"refmsg_time"`
  9107. RespondTime string `json:"respond_time"`
  9108. Signtype interface{} `json:"signtype"`
  9109. WarnMsg interface{} `json:"warn_msg"`
  9110. }
  9111. type ResultNine struct {
  9112. Cainfo string `json:"cainfo"`
  9113. ErrMsg string `json:"err_msg"`
  9114. InfRefmsgid string `json:"inf_refmsgid"`
  9115. Infcode int64 `json:"infcode"`
  9116. Output struct {
  9117. FileQuryNo string `json:"file_qury_no"`
  9118. } `json:"output"`
  9119. RefmsgTime string `json:"refmsg_time"`
  9120. RespondTime string `json:"respond_time"`
  9121. Signtype interface{} `json:"signtype"`
  9122. WarnMsg interface{} `json:"warn_msg"`
  9123. }
  9124. type ResultTen struct {
  9125. Cainfo string `json:"cainfo"`
  9126. ErrMsg string `json:"err_msg"`
  9127. InfRefmsgid string `json:"inf_refmsgid"`
  9128. Infcode int64 `json:"infcode"`
  9129. Output struct {
  9130. DldEndtime string `json:"dld_endtime"`
  9131. FileQuryNo string `json:"file_qury_no"`
  9132. Filename string `json:"filename"`
  9133. } `json:"output"`
  9134. RefmsgTime string `json:"refmsg_time"`
  9135. RespondTime string `json:"respond_time"`
  9136. Signtype interface{} `json:"signtype"`
  9137. WarnMsg interface{} `json:"warn_msg"`
  9138. }
  9139. type ResultEleven struct {
  9140. Cainfo string `json:"cainfo"`
  9141. ErrMsg string `json:"err_msg"`
  9142. InfRefmsgid string `json:"inf_refmsgid"`
  9143. Infcode int64 `json:"infcode"`
  9144. Output struct {
  9145. Setlinfo struct {
  9146. FixmedinsName string `json:"fixmedins_name"`
  9147. FixmedinsCode string `json:"fixmedins_code"`
  9148. PsnNo string `json:"psn_no"`
  9149. PsnName string `json:"psn_name"`
  9150. HifobPay float64 `json:"hifob_pay"`
  9151. Gend string `json:"gend"`
  9152. Brdy string `json:"brdy"`
  9153. PsnCertType string `json:"psn_cert_type"`
  9154. PsnType string `json:"psn_type"`
  9155. EmpName string `json:"emp_name"`
  9156. Certno string `json:"certno"`
  9157. Insutype string `json:"insutype"`
  9158. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9159. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9160. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9161. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9162. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9163. ActPayDedc float64 `json:"act_pay_dedc"`
  9164. HifpPay float64 `json:"hifp_pay"`
  9165. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9166. CvlservPay float64 `json:"cvlserv_pay"`
  9167. HifesPay float64 `json:"hifes_pay"`
  9168. HifmiPay float64 `json:"hifmi_pay"`
  9169. MafPay float64 `json:"maf_pay"`
  9170. OthPay float64 `json:"oth_pay"`
  9171. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9172. PsnPay float64 `json:"psn_pay"`
  9173. AcctPay float64 `json:"acct_pay"`
  9174. CashPayamt float64 `json:"cash_payamt"`
  9175. Balc float64 `json:"balc"`
  9176. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9177. MedinsSetlId string `json:"medins_setl_id"`
  9178. RefdSetlFlag string `json:"refd_setl_flag"`
  9179. SetlTime string `json:"setl_time"`
  9180. MedType string `json:"med_type"`
  9181. } `json:"setlinfo"`
  9182. } `json:"output"`
  9183. RefmsgTime string `json:"refmsg_time"`
  9184. RespondTime string `json:"respond_time"`
  9185. Signtype interface{} `json:"signtype"`
  9186. WarnMsg interface{} `json:"warn_msg"`
  9187. }
  9188. type Custom struct {
  9189. DetItemFeeSumamt string
  9190. Cut string
  9191. FeedetlSn string
  9192. Price string
  9193. MedListCodg string
  9194. Type int64
  9195. AdviceId int64
  9196. ProjectId int64
  9197. ItemId int64
  9198. CostType int64
  9199. }
  9200. // 获取个人信息----挂号-----上传就诊信息
  9201. func (c *HisApiController) GetRegisterInfo() {
  9202. id, _ := c.GetInt64("id")
  9203. record_time := c.GetString("record_time")
  9204. settlementValue, _ := c.GetInt64("settlement_value")
  9205. medical_insurance_card := c.GetString("medical_insurance_card")
  9206. name := c.GetString("name")
  9207. id_card_type, _ := c.GetInt64("id_card_type")
  9208. certificates, _ := c.GetInt64("certificates")
  9209. medical_care, _ := c.GetInt64("medical_care")
  9210. birthday := c.GetString("birthday")
  9211. age, _ := c.GetInt64("age")
  9212. id_card := c.GetString("id_card")
  9213. register_type, _ := c.GetInt64("register")
  9214. doctor, _ := c.GetInt64("doctor")
  9215. department, _ := c.GetInt64("department")
  9216. gender, _ := c.GetInt64("sex")
  9217. phone := c.GetString("phone")
  9218. registration_fee, _ := c.GetFloat("registration_fee")
  9219. medical_expenses, _ := c.GetFloat("medical_expenses")
  9220. social_type, _ := c.GetInt64("social_type")
  9221. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9222. diagnosis_ids := c.GetString("diagnosis")
  9223. sick_type, _ := c.GetInt64("sick_type")
  9224. reg_type := c.GetString("p_type")
  9225. timeLayout := "2006-01-02"
  9226. loc, _ := time.LoadLocation("Local")
  9227. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9228. birthUnix := birthdays.Unix()
  9229. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9230. if err != nil {
  9231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9232. return
  9233. }
  9234. recordDateTime := theTime.Unix()
  9235. adminInfo := c.GetAdminUserInfo()
  9236. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9237. if tempPatient.ID == 0 {
  9238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9239. return
  9240. }
  9241. var patient service.Patients
  9242. if id == 0 {
  9243. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9244. } else {
  9245. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9246. }
  9247. if patient.ID == 0 {
  9248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9249. return
  9250. }
  9251. if len(patient.IdCardNo) == 0 {
  9252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9253. return
  9254. }
  9255. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9256. if len(his) >= 1 {
  9257. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9258. if len(his) >= 1 && order.ID == 0 {
  9259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9260. return
  9261. }
  9262. }
  9263. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9264. fmt.Println(timeStr)
  9265. timeArr := strings.Split(timeStr, " ")
  9266. fmt.Println(timeArr)
  9267. timeArrTwo := strings.Split(timeArr[0], "-")
  9268. timeArrThree := strings.Split(timeArr[1], ":")
  9269. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9270. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9271. if len(lists) == 0 {
  9272. var hisPatient models.XtHisPatient
  9273. hisPatient = models.XtHisPatient{
  9274. Name: name,
  9275. Age: age,
  9276. Gender: gender,
  9277. Birthday: birthUnix,
  9278. Phone: phone,
  9279. MedicalTreatmentType: medical_care,
  9280. IdType: certificates,
  9281. IdCardNo: id_card,
  9282. BalanceAccountsType: settlementValue,
  9283. SocialType: social_type,
  9284. MedicalInsuranceNumber: medical_insurance_card,
  9285. RegisterType: register_type,
  9286. RegisterCost: registration_fee,
  9287. TreatmentCost: medical_expenses,
  9288. AdminUserId: adminInfo.AdminUser.Id,
  9289. UserOrgId: adminInfo.CurrentOrgId,
  9290. Status: 1,
  9291. RecordDate: recordDateTime,
  9292. IsReturn: 1,
  9293. PatientId: patient.ID,
  9294. Ctime: time.Now().Unix(),
  9295. Mtime: time.Now().Unix(),
  9296. Number: str,
  9297. IdCardType: id_card_type,
  9298. Departments: department,
  9299. Doctor: doctor,
  9300. PType: reg_type,
  9301. Diagnosis: diagnosis_ids,
  9302. SickType: sick_type,
  9303. }
  9304. service.CreateHisPatient(&hisPatient)
  9305. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9306. c.ServeSuccessJSON(map[string]interface{}{
  9307. "his_info": hisPatient,
  9308. })
  9309. } else {
  9310. //chrgBchno := rand.Intn(1000000) + 10000
  9311. var hisPatient models.XtHisPatient
  9312. hisPatient = models.XtHisPatient{
  9313. Name: name,
  9314. Age: age,
  9315. Gender: gender,
  9316. Birthday: birthUnix,
  9317. Phone: phone,
  9318. MedicalTreatmentType: medical_care,
  9319. IdType: certificates,
  9320. IdCardNo: id_card,
  9321. BalanceAccountsType: settlementValue,
  9322. SocialType: social_type,
  9323. MedicalInsuranceNumber: medical_insurance_card,
  9324. RegisterType: register_type,
  9325. RegisterCost: registration_fee,
  9326. TreatmentCost: medical_expenses,
  9327. AdminUserId: adminInfo.AdminUser.Id,
  9328. UserOrgId: adminInfo.CurrentOrgId,
  9329. Status: 1,
  9330. RecordDate: recordDateTime,
  9331. IsReturn: 1,
  9332. PatientId: patient.ID,
  9333. Ctime: time.Now().Unix(),
  9334. Mtime: time.Now().Unix(),
  9335. Number: str,
  9336. IdCardType: id_card_type,
  9337. Departments: department,
  9338. Doctor: doctor,
  9339. PType: reg_type,
  9340. Diagnosis: diagnosis_ids,
  9341. SickType: sick_type,
  9342. }
  9343. service.CreateHisPatient(&hisPatient)
  9344. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9345. c.ServeSuccessJSON(map[string]interface{}{
  9346. "his_info": hisPatient,
  9347. })
  9348. }
  9349. }
  9350. // 上传明细----结算
  9351. func (c *HisApiController) GetUploadInfo() {
  9352. id, _ := c.GetInt64("id")
  9353. record_time := c.GetString("record_time")
  9354. his_patient_id, _ := c.GetInt64("his_patient_id")
  9355. oth_desc := c.GetString("oth_desc")
  9356. pay_way, _ := c.GetInt64("pay_way")
  9357. pay_ways := c.GetString("pay_ways")
  9358. pay_price, _ := c.GetFloat("pay_price")
  9359. pay_card_no := c.GetString("pay_card_no")
  9360. discount_price, _ := c.GetFloat("discount_price")
  9361. preferential_price, _ := c.GetFloat("preferential_price")
  9362. reality_price, _ := c.GetFloat("reality_price")
  9363. found_price, _ := c.GetFloat("found_price")
  9364. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9365. private_price, _ := c.GetFloat("private_price")
  9366. timeLayout := "2006-01-02"
  9367. loc, _ := time.LoadLocation("Local")
  9368. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9369. fapiao_code := c.GetString("fapiao_code")
  9370. fapiao_number := c.GetString("fapiao_number")
  9371. diagnosis_id := c.GetString("diagnosis")
  9372. sick_type, _ := c.GetInt64("sick_type")
  9373. reg_type, _ := c.GetInt64("p_type")
  9374. order_id, _ := c.GetInt64("order_id")
  9375. cash_pay := c.GetString("cash_pay")
  9376. wechat_pay := c.GetString("wechat_pay")
  9377. ali_pay := c.GetString("ali_pay")
  9378. jifen_pay := c.GetString("jifen_pay")
  9379. card_desc := c.GetString("card_desc")
  9380. band_card_pay := c.GetString("band_card_pay")
  9381. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9382. tmp_decimal := c.GetString("tmp_decimal")
  9383. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9384. var decimal float64 //本次使用的押金
  9385. var errmsg error
  9386. tx := service.XTWriteDB().Begin() //开了事务
  9387. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9388. defer func() {
  9389. if errmsg != nil {
  9390. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9391. tx.Rollback()
  9392. } else {
  9393. tx.Commit()
  9394. }
  9395. }()
  9396. fmt.Println("dec_way", dec_way)
  9397. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9398. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9399. return
  9400. }
  9401. if len(tmp_decimal) > 0 {
  9402. if tmp_decimal[0] == 45 {
  9403. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9404. return
  9405. }
  9406. }
  9407. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9408. fmt.Println(errs)
  9409. decimal = tt
  9410. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9411. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9412. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9413. if err != nil {
  9414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9415. return
  9416. }
  9417. recordDateTime := theTime.Unix()
  9418. adminUser := c.GetAdminUserInfo()
  9419. var prescriptions []*models.HisPrescription
  9420. var prescriptionsOne []*models.HisPrescription
  9421. var start_time int64
  9422. var end_time int64
  9423. ids_str := c.GetString("ids")
  9424. ids_arr := strings.Split(ids_str, ",")
  9425. if tempOrder.ID == 0 {
  9426. if settle_accounts_type == 1 { //日结
  9427. fmt.Println(reg_type)
  9428. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9429. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9430. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9431. } else {
  9432. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9433. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9434. }
  9435. } else { //月结
  9436. start_time_str := c.GetString("start_time")
  9437. end_time_str := c.GetString("end_time")
  9438. timeLayout := "2006-01-02"
  9439. loc, _ := time.LoadLocation("Local")
  9440. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9441. if err != nil {
  9442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9443. return
  9444. }
  9445. recordStartTime := theStartTime.Unix()
  9446. start_time = recordStartTime
  9447. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9448. if err != nil {
  9449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9450. return
  9451. }
  9452. recordEndTime := theEndTime.Unix()
  9453. end_time = recordEndTime
  9454. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9455. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9456. }
  9457. var goods []*models.DialysisBeforePrepareGoods
  9458. var newGoods []*models.NewDialysisBeforePrepareGoods
  9459. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9460. var infos []*models.HisDoctorAdviceInfo
  9461. var infoList []*models.HisDoctorAdviceInfo
  9462. var hisAdvice []*models.HisDoctorAdviceInfo
  9463. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9464. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9465. //判断库存不足
  9466. //结算出库开关
  9467. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9468. if settConfig.IsOpen == 1 {
  9469. //判断库存的地方
  9470. for _, info := range prescriptions {
  9471. if info.Type == 1 {
  9472. infos = append(infos, info.HisDoctorAdviceInfo...)
  9473. }
  9474. if info.Type == 2 {
  9475. for _, sumItem := range info.HisPrescriptionProject {
  9476. if sumItem.Type == 3 {
  9477. var good models.DialysisBeforePrepareGoods
  9478. var newGood models.NewDialysisBeforePrepareGoods
  9479. good.GoodId = sumItem.GoodInfo.ID
  9480. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9481. count, _ := strconv.Atoi(sumItem.Count)
  9482. good.Count = int64(count)
  9483. good.StorehouseId = houseConfig.StorehouseOutInfo
  9484. good.ProjectId = sumItem.ID
  9485. goods = append(goods, &good)
  9486. newGood.GoodId = sumItem.GoodInfo.ID
  9487. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9488. count2, _ := strconv.Atoi(sumItem.Count)
  9489. newGood.Count = int64(count2)
  9490. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9491. newGood.ProjectId = sumItem.ID
  9492. newGoods = append(newGoods, &newGood)
  9493. }
  9494. }
  9495. }
  9496. }
  9497. for _, info := range prescriptionsOne {
  9498. if info.Type == 1 {
  9499. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9500. }
  9501. if info.Type == 2 {
  9502. for _, sumItem := range info.HisPrescriptionProject {
  9503. if sumItem.Type == 3 {
  9504. var newGood models.NewDialysisBeforePrepareGoods
  9505. newGood.GoodId = sumItem.GoodInfo.ID
  9506. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9507. count2, _ := strconv.Atoi(sumItem.Count)
  9508. newGood.Count = int64(count2)
  9509. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9510. newGood.ProjectId = sumItem.ID
  9511. newGoodOne = append(newGoodOne, &newGood)
  9512. }
  9513. }
  9514. }
  9515. }
  9516. //判断
  9517. for _, itemOne := range infos {
  9518. for _, itemTwo := range hisAdvice {
  9519. if itemOne.DrugId == itemTwo.DrugId {
  9520. itemTwo.Child = append(itemTwo.Child, itemOne)
  9521. }
  9522. }
  9523. }
  9524. for _, itemTwo := range hisAdvice {
  9525. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9526. var sum_out_count int64
  9527. for _, itemThree := range itemTwo.Child {
  9528. var prescribing_number int64
  9529. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9530. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9531. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9532. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9533. }
  9534. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9535. prescribing_number = parseIntPrescribingNumber
  9536. }
  9537. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9538. prescribing_number = parseIntPrescribingNumber
  9539. }
  9540. sum_out_count += prescribing_number
  9541. }
  9542. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9543. if sum_out_count > drugStockOut.FlushCount {
  9544. c.ServeSuccessJSON(map[string]interface{}{
  9545. "msg": "2",
  9546. "drug": medical,
  9547. })
  9548. return
  9549. }
  9550. }
  9551. for _, itemOne := range newGoods {
  9552. for _, item := range newGoodOne {
  9553. if itemOne.GoodId == item.GoodId {
  9554. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9555. }
  9556. }
  9557. }
  9558. for _, item := range newGoodOne {
  9559. var sum_out_count_one int64
  9560. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9561. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9562. sum_out_count_one += itemOne.Count
  9563. }
  9564. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9565. fmt.Println("sum_out_count_one", sum_out_count_one)
  9566. fmt.Println("list.FlushCount", list.FlushCount)
  9567. if sum_out_count_one > list.FlushCount {
  9568. c.ServeSuccessJSON(map[string]interface{}{
  9569. "msg": "3",
  9570. "good": good,
  9571. })
  9572. return
  9573. }
  9574. }
  9575. }
  9576. timestamp := time.Now().Unix()
  9577. tempTime := time.Unix(timestamp, 0)
  9578. timeFormat := tempTime.Format("20060102150405")
  9579. chrgBchno := rand.Intn(100000) + 10000
  9580. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9581. strconv.FormatInt(his.PatientId, 10)
  9582. var ids []int64
  9583. for _, item := range prescriptions {
  9584. ids = append(ids, item.ID)
  9585. }
  9586. var total float64
  9587. for _, item := range prescriptions {
  9588. fmt.Println(item)
  9589. if item.Type == 1 { //药品
  9590. for _, subItem := range item.HisDoctorAdviceInfo {
  9591. total = total + (subItem.Price * subItem.PrescribingNumber)
  9592. }
  9593. }
  9594. if item.Type == 2 { //项目
  9595. for _, subItem := range item.HisPrescriptionProject {
  9596. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9597. total = total + (subItem.Price * cnt)
  9598. }
  9599. }
  9600. for _, subItem := range item.HisAdditionalCharge {
  9601. total = total + (subItem.Price * float64(subItem.Count))
  9602. }
  9603. }
  9604. if reg_type == 1111 || reg_type == 1112 {
  9605. reg_type = 11
  9606. }
  9607. tm := time.Unix(time.Now().Unix(), 0)
  9608. allTotal := fmt.Sprintf("%.4f", total)
  9609. totals, _ := strconv.ParseFloat(allTotal, 64)
  9610. order := &models.HisOrder{
  9611. UserOrgId: adminUser.CurrentOrgId,
  9612. HisPatientId: his.ID,
  9613. PatientId: id,
  9614. SettleAccountsDate: recordDateTime,
  9615. Ctime: time.Now().Unix(),
  9616. Mtime: time.Now().Unix(),
  9617. Status: 1,
  9618. OrderStatus: 2,
  9619. MdtrtId: his.Number,
  9620. Number: chrg_bchno,
  9621. MedfeeSumamt: totals,
  9622. PayWay: pay_way,
  9623. PayWays: pay_ways,
  9624. PayPrice: pay_price,
  9625. MedType: strconv.Itoa(int(reg_type)),
  9626. PayCardNo: pay_card_no,
  9627. DiscountPrice: discount_price,
  9628. PreferentialPrice: preferential_price,
  9629. RealityPrice: reality_price,
  9630. FoundPrice: found_price,
  9631. MedicalInsurancePrice: medical_insurance_price,
  9632. PrivatePrice: private_price,
  9633. SettleEndTime: end_time,
  9634. SettleStartTime: start_time,
  9635. PsnPartAmt: totals,
  9636. PsnCashPay: totals,
  9637. SettleType: settle_accounts_type,
  9638. FaPiaoCode: fapiao_code,
  9639. FaPiaoNumber: fapiao_number,
  9640. Diagnosis: diagnosis_id,
  9641. PType: 2,
  9642. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9643. Decimal: decimal,
  9644. OthDesc: oth_desc,
  9645. CashPay: cash_pay,
  9646. WechatPay: wechat_pay,
  9647. AliPay: ali_pay,
  9648. JifenPay: jifen_pay,
  9649. BandCardPay: band_card_pay,
  9650. Creator: adminUser.AdminUser.Id,
  9651. CardDesc: card_desc,
  9652. }
  9653. err = service.CreateOrderTX(order, tx)
  9654. if err != nil {
  9655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9656. return
  9657. }
  9658. var customs []*Custom
  9659. for _, item := range prescriptions {
  9660. if item.Type == 1 { //药品a
  9661. for _, subItem := range item.HisDoctorAdviceInfo {
  9662. if subItem.Drug.IsUser != 1 {
  9663. cus := &Custom{
  9664. AdviceId: subItem.ID,
  9665. ProjectId: 0,
  9666. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9667. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9668. FeedetlSn: subItem.FeedetlSn,
  9669. Price: fmt.Sprintf("%.4f", subItem.Price),
  9670. MedListCodg: subItem.MedListCodg,
  9671. Type: 1,
  9672. CostType: 9,
  9673. }
  9674. customs = append(customs, cus)
  9675. }
  9676. }
  9677. }
  9678. if item.Type == 2 { //项目
  9679. for _, subItem := range item.HisPrescriptionProject {
  9680. if subItem.Type == 2 {
  9681. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9682. cus := &Custom{
  9683. AdviceId: 0,
  9684. ProjectId: subItem.ID,
  9685. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9686. Cut: fmt.Sprintf("%.4f", cnt),
  9687. FeedetlSn: subItem.FeedetlSn,
  9688. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9689. MedListCodg: subItem.MedListCodg,
  9690. Type: 2,
  9691. CostType: subItem.HisProject.CostClassify,
  9692. }
  9693. customs = append(customs, cus)
  9694. } else {
  9695. if subItem.GoodInfo.IsUser != 1 {
  9696. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9697. cus := &Custom{
  9698. AdviceId: 0,
  9699. ProjectId: subItem.ID,
  9700. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9701. Cut: fmt.Sprintf("%.4f", cnt),
  9702. FeedetlSn: subItem.FeedetlSn,
  9703. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9704. MedListCodg: subItem.MedListCodg,
  9705. Type: 2,
  9706. CostType: subItem.HisProject.CostClassify,
  9707. }
  9708. customs = append(customs, cus)
  9709. }
  9710. }
  9711. }
  9712. }
  9713. for _, item := range item.HisAdditionalCharge {
  9714. cus := &Custom{
  9715. ItemId: item.ID,
  9716. AdviceId: 0,
  9717. ProjectId: 0,
  9718. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9719. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9720. FeedetlSn: item.FeedetlSn,
  9721. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9722. MedListCodg: item.XtHisAddtionConfig.Code,
  9723. Type: 3,
  9724. CostType: 5,
  9725. }
  9726. customs = append(customs, cus)
  9727. }
  9728. }
  9729. for _, item := range customs {
  9730. var advice_id int64 = 0
  9731. var project_id int64 = 0
  9732. var item_id int64 = 0
  9733. var types int64 = 0
  9734. var med_chrgitm_type string
  9735. if item.Type == 1 {
  9736. advice_id = item.AdviceId
  9737. project_id = 0
  9738. item_id = 0
  9739. med_chrgitm_type = "09"
  9740. } else if item.Type == 2 {
  9741. med_chrgitm_type = "05"
  9742. if item.CostType == 3 {
  9743. med_chrgitm_type = "04"
  9744. }
  9745. if item.CostType == 8 {
  9746. med_chrgitm_type = "03"
  9747. }
  9748. advice_id = 0
  9749. item_id = 0
  9750. project_id = item.ProjectId
  9751. } else if item.Type == 3 {
  9752. advice_id = 0
  9753. item_id = item.ItemId
  9754. project_id = 0
  9755. med_chrgitm_type = "08"
  9756. }
  9757. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9758. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9759. pric, _ := strconv.ParseFloat(item.Price, 32)
  9760. info := &models.HisOrderInfo{
  9761. OrderNumber: order.Number,
  9762. UploadDate: time.Now().Unix(),
  9763. AdviceId: advice_id,
  9764. DetItemFeeSumamt: detItemFeeSumamt,
  9765. MedChrgitmType: med_chrgitm_type,
  9766. Cnt: cut,
  9767. Pric: pric,
  9768. PatientId: id,
  9769. Status: 1,
  9770. Mtime: time.Now().Unix(),
  9771. Ctime: time.Now().Unix(),
  9772. UserOrgId: adminUser.CurrentOrgId,
  9773. HisPatientId: his.ID,
  9774. OrderId: order.ID,
  9775. ProjectId: project_id,
  9776. Type: types,
  9777. ItemId: item_id,
  9778. }
  9779. service.CreateOrderInfoTX(info, tx)
  9780. }
  9781. his.Diagnosis = diagnosis_id
  9782. his.SickType = sick_type
  9783. his.RegisterType = reg_type
  9784. his.MedicalTreatmentType = reg_type
  9785. service.UpdataHisPateintTX(&his, tx)
  9786. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9787. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9788. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9789. //判断是否使用了押金
  9790. if dec_way == "true" {
  9791. tmpstring := strconv.FormatInt(order.ID, 10)
  9792. //扣押金
  9793. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9794. order.Decimal = decimal
  9795. service.UpDateOrderTwo(order, tx)
  9796. if errmsg != nil {
  9797. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9798. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9799. return
  9800. }
  9801. }
  9802. if err == nil {
  9803. for _, info := range prescriptions {
  9804. if info.Type == 1 {
  9805. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9806. }
  9807. if info.Type == 2 {
  9808. for _, sumItem := range info.HisPrescriptionProject {
  9809. if sumItem.Type == 3 {
  9810. var good models.DialysisBeforePrepareGoods
  9811. var newGood models.NewDialysisBeforePrepareGoods
  9812. var oldGood models.OldDialysisBeforePrepareGoods
  9813. good.GoodId = sumItem.GoodInfo.ID
  9814. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9815. count, _ := strconv.Atoi(sumItem.Count)
  9816. good.Count = int64(count)
  9817. good.StorehouseId = houseConfig.StorehouseOutInfo
  9818. good.ProjectId = sumItem.ID
  9819. good.PatientId = sumItem.PatientId
  9820. goods = append(goods, &good)
  9821. newGood.GoodId = sumItem.GoodInfo.ID
  9822. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9823. count2, _ := strconv.Atoi(sumItem.Count)
  9824. newGood.Count = int64(count2)
  9825. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9826. newGood.ProjectId = sumItem.ID
  9827. newGood.PatientId = sumItem.HisPatientId
  9828. newGoods = append(newGoods, &newGood)
  9829. oldGood.GoodId = sumItem.GoodInfo.ID
  9830. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9831. count3, _ := strconv.Atoi(sumItem.Count)
  9832. oldGood.Count = int64(count3)
  9833. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9834. oldGood.ProjectId = sumItem.ID
  9835. oldGood.RecordDate = sumItem.RecordDate
  9836. oldGood.PatientId = sumItem.HisPatientId
  9837. oldGoods = append(oldGoods, &oldGood)
  9838. }
  9839. }
  9840. }
  9841. }
  9842. if settConfig.IsOpen == 1 {
  9843. for _, item := range infoList {
  9844. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9845. if medical.IsUse == 2 {
  9846. //药品出库
  9847. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9848. //查询默认仓库
  9849. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9850. //查询默认仓库剩余多少库存
  9851. var sum_count int64
  9852. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9853. for _, its := range stockInfo {
  9854. if its.MaxUnit == medical.MaxUnit {
  9855. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9856. }
  9857. sum_count += its.StockMaxNumber + its.StockMinNumber
  9858. }
  9859. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9860. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9861. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9862. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9863. }
  9864. }
  9865. orgId := c.GetAdminUserInfo().CurrentOrgId
  9866. if len(oldGoods) > 0 {
  9867. timeStr := time.Now().Format("2006-01-02")
  9868. timeArr := strings.Split(timeStr, "-")
  9869. total, _ := service.FindAllWarehouseOut(orgId)
  9870. total = total + 1
  9871. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9872. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9873. number = number + total
  9874. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9875. operation_time := time.Now().Unix()
  9876. creater := c.GetAdminUserInfo().AdminUser.Id
  9877. //查询默认出库仓库库存
  9878. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9879. recordDateStr := time.Now().Format("2006-01-02")
  9880. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9881. nowtime := recordDate.Unix()
  9882. warehouseOut := models.WarehouseOut{
  9883. WarehouseOutOrderNumber: warehousing_out_order,
  9884. OperationTime: operation_time,
  9885. OrgId: orgId,
  9886. Creater: creater,
  9887. Ctime: time.Now().Unix(),
  9888. Status: 1,
  9889. WarehouseOutTime: nowtime,
  9890. Type: 1,
  9891. StorehouseId: storeConfig.StorehouseOutInfo,
  9892. IsCheck: 1,
  9893. OrderId: order.ID,
  9894. IsSys: 5,
  9895. }
  9896. //查询是否生成出库单
  9897. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9898. if out.ID == 0 {
  9899. service.AddSigleWarehouseOutOne(&warehouseOut)
  9900. }
  9901. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9902. for _, item := range oldGoods {
  9903. dialyPrepareOne := models.DialysisBeforePrepare{
  9904. GoodTypeId: item.GoodTypeId,
  9905. GoodId: item.GoodId,
  9906. PatientId: his.PatientId,
  9907. RecordDate: item.RecordDate,
  9908. UserOrgId: adminUser.CurrentOrgId,
  9909. Count: item.Count,
  9910. Ctime: time.Now().Unix(),
  9911. Creater: adminUser.AdminUser.Id,
  9912. CommdityCode: item.CommdityCode,
  9913. Status: 1,
  9914. StorehouseId: houseConfig.StorehouseOutInfo,
  9915. }
  9916. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9917. //非零用
  9918. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9919. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9920. //查询剩余库存
  9921. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9922. var sum_count int64
  9923. for _, item := range goodList {
  9924. sum_count += item.StockCount
  9925. }
  9926. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9927. //耗材
  9928. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9929. }
  9930. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9931. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9932. //查询剩余库存
  9933. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9934. var sum_count int64
  9935. for _, item := range goodList {
  9936. sum_count += item.StockCount
  9937. }
  9938. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9939. //耗材
  9940. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9941. }
  9942. }
  9943. }
  9944. }
  9945. c.ServeSuccessJSON(map[string]interface{}{
  9946. "msg": "结算成功",
  9947. })
  9948. }
  9949. }
  9950. }
  9951. // 退款
  9952. func (c *HisApiController) Refund() {
  9953. order_id, _ := c.GetInt64("order_id")
  9954. order, _ := service.GetHisOrderByID(order_id)
  9955. adminUser := c.GetAdminUserInfo()
  9956. orgid := c.GetAdminUserInfo().CurrentOrgId
  9957. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9958. if err != nil {
  9959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9960. return
  9961. }
  9962. tmp := strconv.FormatInt(order.ID, 10)
  9963. //当押金不为零时产生退费记录
  9964. if order.Decimal != 0 {
  9965. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9966. if err != nil {
  9967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9968. return
  9969. }
  9970. }
  9971. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  9972. if fapiao.ID > 0 {
  9973. c.ServeSuccessJSON(map[string]interface{}{
  9974. "failed_code": -10,
  9975. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  9976. })
  9977. return
  9978. }
  9979. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9980. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9981. var goods []*models.DialysisBeforePrepareGoods
  9982. var newGoods []*models.NewDialysisBeforePrepareGoods
  9983. var infos []*models.HisDoctorAdviceInfo
  9984. for _, info := range orders {
  9985. if info.AdviceId > 0 && info.ProjectId == 0 {
  9986. infos = append(infos, &info.HisDoctorAdviceInfo)
  9987. }
  9988. if info.ProjectId > 0 && info.AdviceId == 0 {
  9989. if info.HisPrescriptionProject.Type == 3 {
  9990. var good models.DialysisBeforePrepareGoods
  9991. var newGood models.NewDialysisBeforePrepareGoods
  9992. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9993. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9994. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9995. good.Count = int64(count)
  9996. good.StorehouseId = houseConfig.StorehouseOutInfo
  9997. good.ProjectId = info.HisPrescriptionProject.ID
  9998. good.PatientId = info.PatientId
  9999. good.OrderId = order_id
  10000. goods = append(goods, &good)
  10001. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10002. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10003. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10004. newGood.Count = int64(count2)
  10005. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10006. newGood.ProjectId = info.HisPrescriptionProject.ID
  10007. newGood.RecordDate = order.SettleAccountsDate
  10008. newGood.UserOrgId = order.UserOrgId
  10009. newGood.PatientId = info.PatientId
  10010. newGood.OrderId = order_id
  10011. newGoods = append(newGoods, &newGood)
  10012. }
  10013. }
  10014. }
  10015. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10016. if settConfig.IsOpen == 1 {
  10017. for _, item := range infos {
  10018. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10019. }
  10020. for _, item := range newGoods {
  10021. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10022. }
  10023. }
  10024. c.ServeSuccessJSON(map[string]interface{}{
  10025. "msg": "退费成功",
  10026. })
  10027. }
  10028. func (c *HisApiController) RefundNumber() {
  10029. his_patient_id, _ := c.GetInt64("id")
  10030. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10031. info.Status = 0
  10032. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10033. if count > 0 {
  10034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10035. return
  10036. }
  10037. err := service.SaveHisPatient(info)
  10038. if err == nil {
  10039. c.ServeSuccessJSON(map[string]interface{}{
  10040. "msg": "退号成功",
  10041. })
  10042. } else {
  10043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10044. return
  10045. }
  10046. }
  10047. func (this *HisApiController) AdditionalCharge() {
  10048. dataBody := make(map[string]interface{}, 0)
  10049. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10050. fmt.Println(err)
  10051. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10052. patient_id := int64(dataBody["patient_id"].(float64))
  10053. medicineData, _ := dataBody["medicineData"].([]interface{})
  10054. adminUserInfo := this.GetAdminUserInfo()
  10055. orgId := adminUserInfo.CurrentOrgId
  10056. admin_user_id := adminUserInfo.AdminUser.Id
  10057. timeStr := time.Now().Format("2006-01-02")
  10058. timeLayout := "2006-01-02 15:04:05"
  10059. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10060. timenow := timeStringToTime.Unix()
  10061. var additionalCharges []*models.HisAdditionalCharge
  10062. for _, item := range medicineData {
  10063. var randNum int
  10064. randNum = rand.Intn(10000) + 1000
  10065. timestamp := time.Now().Unix()
  10066. tempTime := time.Unix(timestamp, 0)
  10067. timeFormat := tempTime.Format("20060102150405")
  10068. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10069. items := item.(map[string]interface{})
  10070. money := items["price"].(string)
  10071. item_id_str := items["item_id"].(string)
  10072. name := items["name"].(string)
  10073. id_str := items["id"].(string)
  10074. moneys, _ := strconv.ParseInt(money, 10, 64)
  10075. monStr := strconv.FormatInt(moneys, 10)
  10076. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10077. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10078. id, _ := strconv.ParseInt(id_str, 10, 64)
  10079. additionalCharge := &models.HisAdditionalCharge{
  10080. ID: id,
  10081. HisPatientId: his_patient_id,
  10082. UserOrgId: orgId,
  10083. PatientId: patient_id,
  10084. RecordDate: timenow,
  10085. Price: monneyStr,
  10086. Status: 1,
  10087. ItemName: name,
  10088. ItemId: item_id,
  10089. AdminUserId: admin_user_id,
  10090. CreatedTime: time.Now().Unix(),
  10091. OrderStatus: 0,
  10092. PrescriptionNumber: "",
  10093. BatchNumber: "",
  10094. FeedetlSn: p_number,
  10095. }
  10096. service.CreateAdditionalCharge(additionalCharge)
  10097. additionalCharges = append(additionalCharges, additionalCharge)
  10098. }
  10099. this.ServeSuccessJSON(map[string]interface{}{
  10100. "msg": "添加成功",
  10101. "additional_charges": additionalCharges,
  10102. })
  10103. }
  10104. func (this *HisApiController) DeleteAddition() {
  10105. id, _ := this.GetInt64("id")
  10106. //TODO 需要判断是否已经结算
  10107. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10108. if err == nil {
  10109. this.ServeSuccessJSON(map[string]interface{}{
  10110. "msg": "删除成功",
  10111. })
  10112. return
  10113. } else {
  10114. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10115. return
  10116. }
  10117. }
  10118. func (this *HisApiController) GetAdminUsers() {
  10119. adminUser := this.GetAdminUserInfo()
  10120. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10121. this.ServeSuccessJSON(map[string]interface{}{
  10122. "doctors": doctors,
  10123. })
  10124. }
  10125. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10126. change_type, _ := this.GetInt64("type", 0)
  10127. record_date := this.GetString("record_time")
  10128. patient_id, _ := this.GetInt64("patient_id", 0)
  10129. p_type, _ := this.GetInt64("p_type", 0)
  10130. timeLayout := "2006-01-02"
  10131. loc, _ := time.LoadLocation("Local")
  10132. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10133. record_time := theAdviceRecordTime.Unix()
  10134. adminUserInfo := this.GetAdminUserInfo()
  10135. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10136. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10137. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10138. if config.ID > 0 && config.IsOpen == 1 {
  10139. for _, subitems := range prescriptions {
  10140. for _, item := range subitems.VMHisPrescription {
  10141. for _, subItem := range item.HisDoctorAdviceInfo {
  10142. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10143. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10144. if info.RetailPrice > 0 {
  10145. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10146. subItem.Drug.RetailPrice = drug.RetailPrice
  10147. }
  10148. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10149. subItem.Drug.MinPrice = info.RetailPrice
  10150. subItem.Drug.RetailPrice = info.RetailPrice
  10151. }
  10152. }
  10153. }
  10154. }
  10155. }
  10156. }
  10157. if config.ID > 0 && config.IsOpen == 1 {
  10158. for _, subitems := range prescriptions {
  10159. for _, item := range subitems.VMHisPrescription {
  10160. for _, subItem := range item.HisPrescriptionProject {
  10161. if subItem.Type == 3 {
  10162. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10163. if info.Price > 0 {
  10164. subItem.GoodInfo.PackingPrice = info.Price
  10165. }
  10166. }
  10167. }
  10168. }
  10169. }
  10170. }
  10171. }
  10172. if err == nil {
  10173. if len(prescriptions) == 0 {
  10174. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10175. return
  10176. } else {
  10177. this.ServeSuccessJSON(map[string]interface{}{
  10178. "prescriptions": prescriptions,
  10179. })
  10180. return
  10181. }
  10182. } else {
  10183. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10184. return
  10185. }
  10186. }
  10187. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10188. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10189. for i := 0; i < len(arr); i++ {
  10190. repeat := false
  10191. for j := i + 1; j < len(arr); j++ {
  10192. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10193. repeat = true
  10194. break
  10195. }
  10196. }
  10197. if !repeat {
  10198. newArr = append(newArr, arr[i])
  10199. }
  10200. }
  10201. return
  10202. }
  10203. func (this *HisApiController) GetCallHisPrescription() {
  10204. patient_id, _ := this.GetInt64("patient_id", 0)
  10205. timeLayout := "2006-01-02"
  10206. loc, _ := time.LoadLocation("Local")
  10207. start_time := this.GetString("start_time")
  10208. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10209. end_time := this.GetString("end_time")
  10210. p_type, _ := this.GetInt64("p_type")
  10211. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10212. adminUserInfo := this.GetAdminUserInfo()
  10213. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10214. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10215. //if
  10216. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10217. //
  10218. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10219. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10220. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10221. if config.ID > 0 && config.IsOpen == 1 {
  10222. for _, subitems := range prescriptions {
  10223. for _, item := range subitems.VMHisPrescription {
  10224. for _, subItem := range item.HisDoctorAdviceInfo {
  10225. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10226. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10227. if info.RetailPrice > 0 {
  10228. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10229. subItem.Drug.RetailPrice = drug.RetailPrice
  10230. }
  10231. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10232. subItem.Drug.MinPrice = info.RetailPrice
  10233. subItem.Drug.RetailPrice = info.RetailPrice
  10234. }
  10235. }
  10236. }
  10237. }
  10238. }
  10239. }
  10240. if config.ID > 0 && config.IsOpen == 1 {
  10241. for _, subitems := range prescriptions {
  10242. for _, item := range subitems.VMHisPrescription {
  10243. for _, subItem := range item.HisPrescriptionProject {
  10244. if subItem.Type == 3 {
  10245. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10246. if info.Price > 0 {
  10247. subItem.GoodInfo.PackingPrice = info.Price
  10248. }
  10249. }
  10250. }
  10251. }
  10252. }
  10253. }
  10254. }
  10255. if err == nil {
  10256. this.ServeSuccessJSON(map[string]interface{}{
  10257. "prescriptions": prescriptions,
  10258. })
  10259. return
  10260. } else {
  10261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10262. return
  10263. }
  10264. }
  10265. func (this *HisApiController) GetHisDayPrescription() {
  10266. timeLayout := "2006-01-02"
  10267. loc, _ := time.LoadLocation("Local")
  10268. start_time := this.GetString("start_time")
  10269. patient_id, _ := this.GetInt64("patient_id", 0)
  10270. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10271. end_time := this.GetString("end_time")
  10272. p_type, _ := this.GetInt64("p_type")
  10273. order_status, _ := this.GetInt64("type")
  10274. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10275. adminUserInfo := this.GetAdminUserInfo()
  10276. var dayHisPrescription []*models.HisPrescription
  10277. var err error
  10278. if order_status == 1 || order_status == 0 {
  10279. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10280. } else if order_status == 2 {
  10281. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10282. }
  10283. var settle_total float64
  10284. for _, item := range dayHisPrescription {
  10285. if len(item.HisPrescriptionProject) > 0 {
  10286. for _, subItem := range item.HisPrescriptionProject {
  10287. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10288. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10289. settle_total = settle_total + total
  10290. }
  10291. }
  10292. if len(item.HisDoctorAdviceInfo) > 0 {
  10293. for _, subItem := range item.HisDoctorAdviceInfo {
  10294. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10295. settle_total = settle_total + total
  10296. }
  10297. }
  10298. }
  10299. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10300. if err == nil {
  10301. this.ServeSuccessJSON(map[string]interface{}{
  10302. "day_prescription": dayHisPrescription,
  10303. "settle_total": settle_total,
  10304. })
  10305. return
  10306. } else {
  10307. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10308. return
  10309. }
  10310. }
  10311. func (c *HisApiController) GetHisChargePatientList() {
  10312. record_date := c.GetString("record_date")
  10313. order_status, _ := c.GetInt64("type")
  10314. sch_type, _ := c.GetInt64("sch_type")
  10315. timeLayout := "2006-01-02"
  10316. loc, _ := time.LoadLocation("Local")
  10317. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10318. if err != nil {
  10319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10320. return
  10321. }
  10322. recordDateTime := theTime.Unix()
  10323. adminInfo := c.GetAdminUserInfo()
  10324. var tempPatients []*service.NewTempPatients
  10325. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10326. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10327. if order_status != 2 {
  10328. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10329. } else {
  10330. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10331. }
  10332. } else {
  10333. if order_status != 2 {
  10334. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10335. } else {
  10336. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10337. }
  10338. }
  10339. var patients []*service.NewTempPatients
  10340. var patients_two []*service.NewTempPatients
  10341. for _, item := range tempPatients {
  10342. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10343. //过滤掉没挂号的和没开处方的
  10344. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10345. patients = append(patients, item)
  10346. }
  10347. //过滤掉没挂号的
  10348. if len(item.HisPatient) > 0 {
  10349. patients_two = append(patients_two, item)
  10350. }
  10351. } else {
  10352. if len(item.HisPrescription) > 0 {
  10353. patients = append(patients, item)
  10354. }
  10355. }
  10356. }
  10357. c.ServeSuccessJSON(map[string]interface{}{
  10358. "list": patients,
  10359. "list_two": patients_two,
  10360. })
  10361. }
  10362. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10363. record_date := c.GetString("record_date")
  10364. timeLayout := "2006-01-02"
  10365. loc, _ := time.LoadLocation("Local")
  10366. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10367. if err != nil {
  10368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10369. return
  10370. }
  10371. recordDateTime := theTime.Unix()
  10372. adminUser := c.GetAdminUserInfo()
  10373. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10374. var patients []*service.Patients
  10375. for _, item := range tempPatients {
  10376. if item.HisPatient.ID == 0 {
  10377. patients = append(patients, item)
  10378. }
  10379. }
  10380. c.ServeSuccessJSON(map[string]interface{}{
  10381. "list": patients,
  10382. //"list_two": patients_two,
  10383. })
  10384. }
  10385. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10386. newArr = make([]*service.Patients, 0)
  10387. for i := 0; i < len(patient); i++ {
  10388. repeat := false
  10389. for j := i + 1; j < len(patient); j++ {
  10390. if patient[i].ID == patient[j].ID {
  10391. repeat = true
  10392. break
  10393. }
  10394. }
  10395. if !repeat {
  10396. newArr = append(newArr, patient[i])
  10397. }
  10398. }
  10399. return
  10400. }
  10401. func (c *HisApiController) GetHisChargePatientInfo() {
  10402. patient_id, _ := c.GetInt64("patient_id")
  10403. his_patient_id, _ := c.GetInt64("his_patient_id")
  10404. record_date := c.GetString("record_date")
  10405. //start_time := c.GetString("start_time")
  10406. //end_time := c.GetString("end_time")
  10407. order_status, _ := c.GetInt64("type", 0)
  10408. p_type, _ := c.GetInt64("p_type", 0)
  10409. order_id, _ := c.GetInt64("order_id", 0)
  10410. timeLayout := "2006-01-02"
  10411. loc, _ := time.LoadLocation("Local")
  10412. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10413. if err != nil {
  10414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10415. return
  10416. }
  10417. recordDateTime := theTime.Unix()
  10418. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10419. //if err != nil {
  10420. //
  10421. //}
  10422. //startRecordDateTime := startTime.Unix()
  10423. //
  10424. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10425. //if err != nil {
  10426. //
  10427. //}
  10428. //endRecordDateTime := endTime.Unix()
  10429. admin := c.GetAdminUserInfo()
  10430. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10431. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10432. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10433. var prescriptions []*models.HisPrescription
  10434. //var unChargeMonthPrescriptions []*models.HisPrescription
  10435. order, _ := service.GetHisOrderByID(order_id)
  10436. if order_status == 1 || order_status == 0 {
  10437. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10438. } else if order_status == 2 {
  10439. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10440. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10441. }
  10442. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10443. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10444. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10445. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10446. //获取所有科室信息
  10447. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10448. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10449. c.ServeSuccessJSON(map[string]interface{}{
  10450. "his_info": his_patient_info,
  10451. "last_his_patient_info": last_his_patient_info,
  10452. "xt_info": xt_patient_info,
  10453. "prescription": prescriptions,
  10454. "case_history": case_history,
  10455. "info": patientPrescriptionInfo,
  10456. "last_info": lastPatientPrescriptionInfo,
  10457. "order": order,
  10458. "doctors": doctors,
  10459. "department": department,
  10460. "sch": sch,
  10461. })
  10462. return
  10463. }
  10464. func (c *HisApiController) GetAllOrderDetail() {
  10465. order_id, _ := c.GetInt64("id", 0)
  10466. order, _ := service.GetHisOrderByID(order_id)
  10467. if order.ID == 0 {
  10468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10469. return
  10470. }
  10471. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10472. org_id := c.GetAdminUserInfo().CurrentOrgId
  10473. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10474. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10475. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10476. c.ServeSuccessJSON(map[string]interface{}{
  10477. "order": order,
  10478. "order_info": order_info,
  10479. "patient": patient,
  10480. "admin_info": adminInfo,
  10481. "hospital_record": record,
  10482. })
  10483. return
  10484. }
  10485. func (c *HisApiController) GetAllOrderDetailCollect() {
  10486. order_id, _ := c.GetInt64("id", 0)
  10487. order, _ := service.GetHisOrderByID(order_id)
  10488. if order.ID == 0 {
  10489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10490. return
  10491. }
  10492. org_id := c.GetAdminUserInfo().CurrentOrgId
  10493. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10494. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10495. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10496. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10497. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10498. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10499. var bedCostTotal float64 = 0 //床位总费
  10500. //var bedCostSelfTotal float64 = 0 //床位自费
  10501. var operationCostTotal float64 = 0 //手术费
  10502. //var operationCostSelfTotal float64 = 0 //手术费
  10503. var otherCostTotal float64 = 0 //其他费用
  10504. //var otherCostSelfTotal float64 = 0 //其他费用
  10505. var materialCostTotal float64 = 0 //材料费
  10506. //var materialCostSelfTotal float64 = 0 //材料费
  10507. var westernMedicineCostTotal float64 = 0 //西药费
  10508. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10509. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10510. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10511. var checkCostTotal float64 = 0 //检查费
  10512. //var checkCostSelfTotal float64 = 0 //检查费
  10513. var laboratoryCostTotal float64 = 0 //化验费
  10514. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10515. var treatCostTotal float64 = 0 //治疗费用
  10516. //var treatCostSelfTotal float64 = 0 //治疗费用
  10517. var zhenChaCostTotal float64 = 0 //其他费用
  10518. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10519. decimal.DivisionPrecision = 2
  10520. var BalanceAccountsType int64
  10521. if his.ID > 0 {
  10522. BalanceAccountsType = his.BalanceAccountsType
  10523. } else {
  10524. BalanceAccountsType = record.BalanceAccountsType
  10525. }
  10526. if BalanceAccountsType != 2 {
  10527. for _, item := range order_info {
  10528. if org_id == 10215 {
  10529. if item.MedChrgitmType == "01" { //床位费
  10530. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10531. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10532. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10533. }
  10534. if item.MedChrgitmType == "02" { //诊察费
  10535. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10536. //zhenChaCostSelfTotal = zhenChaCostTotal
  10537. }
  10538. if item.MedChrgitmType == "03" { //检查费
  10539. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10540. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10541. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10542. }
  10543. //if item.MedChrgitmType == "02" { //检查费
  10544. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10545. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10546. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10547. //}
  10548. if item.MedChrgitmType == "04" { //化验费
  10549. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10550. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10551. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10552. }
  10553. if item.MedChrgitmType == "05" { //治疗费
  10554. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10555. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10556. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10557. }
  10558. if item.MedChrgitmType == "06" { //手术费
  10559. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10560. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10561. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10562. }
  10563. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10564. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10565. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10566. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10567. }
  10568. if item.MedChrgitmType == "09" { //西药费
  10569. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10570. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10571. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10572. }
  10573. if item.MedChrgitmType == "11" { //中成费
  10574. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10575. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10576. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10577. }
  10578. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10579. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10580. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10581. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10582. }
  10583. } else if org_id == 10188 || org_id == 10217 {
  10584. if item.MedChrgitmType == "01" { //床位费
  10585. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10586. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10587. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10588. }
  10589. if item.MedChrgitmType == "02" { //诊察费
  10590. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10591. //zhenChaCostSelfTotal = zhenChaCostTotal
  10592. }
  10593. if item.MedChrgitmType == "03" { //检查费
  10594. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10595. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10596. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10597. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10598. }
  10599. //if item.MedChrgitmType == "02" { //检查费
  10600. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10601. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10602. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10603. //}
  10604. if item.MedChrgitmType == "04" { //化验费
  10605. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10606. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10607. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10608. }
  10609. if item.MedChrgitmType == "05" { //治疗费
  10610. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10611. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10612. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10613. }
  10614. if item.MedChrgitmType == "06" { //手术费
  10615. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10616. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10617. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10618. }
  10619. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10620. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10621. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10622. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10623. }
  10624. if item.MedChrgitmType == "09" { //西药费
  10625. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10626. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10627. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10628. }
  10629. if item.MedChrgitmType == "11" { //中成费
  10630. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10631. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10632. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10633. }
  10634. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10635. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10636. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10637. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10638. }
  10639. } else {
  10640. if item.MedChrgitmType == "01" { //床位费
  10641. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10642. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10643. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10644. }
  10645. //if item.MedChrgitmType == "02" { //诊察费
  10646. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10647. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10648. //}
  10649. if item.MedChrgitmType == "03" { //检查费
  10650. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10651. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10652. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10653. }
  10654. //if item.MedChrgitmType == "02" { //检查费
  10655. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10656. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10657. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10658. //}
  10659. if item.MedChrgitmType == "04" { //化验费
  10660. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10661. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10662. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10663. }
  10664. if item.MedChrgitmType == "05" { //治疗费
  10665. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10666. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10667. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10668. }
  10669. if item.MedChrgitmType == "06" { //手术费
  10670. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10671. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10672. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10673. }
  10674. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10675. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10676. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10677. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10678. }
  10679. if item.MedChrgitmType == "09" { //西药费
  10680. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10681. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10682. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10683. }
  10684. if item.MedChrgitmType == "11" { //中成费
  10685. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10686. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10687. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10688. }
  10689. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10690. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10691. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10692. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10693. }
  10694. }
  10695. }
  10696. c.ServeSuccessJSON(map[string]interface{}{
  10697. "order": order,
  10698. "order_info": order_info,
  10699. "patient": patient,
  10700. "admin_info": adminInfo,
  10701. "his_hospital": record,
  10702. "bedCostTotal": bedCostTotal,
  10703. "operationCostTotal": operationCostTotal,
  10704. "otherCostTotal": otherCostTotal,
  10705. "materialCostTotal": materialCostTotal,
  10706. "westernMedicineCostTotal": westernMedicineCostTotal,
  10707. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10708. "checkCostTotal": checkCostTotal,
  10709. "zhenChaCostTotal": zhenChaCostTotal,
  10710. "laboratoryCostTotal": laboratoryCostTotal,
  10711. "treatCostTotal": treatCostTotal,
  10712. })
  10713. } else {
  10714. for _, item := range order_info {
  10715. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10716. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10717. item.MedChrgitmType = "09"
  10718. }
  10719. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10720. if item.HisPrescriptionProject.Type == 2 {
  10721. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10722. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10723. case 0:
  10724. item.MedChrgitmType = "0"
  10725. break
  10726. case 1:
  10727. item.MedChrgitmType = "14"
  10728. break
  10729. case 2:
  10730. item.MedChrgitmType = "05"
  10731. break
  10732. case 3:
  10733. item.MedChrgitmType = "03"
  10734. break
  10735. case 4:
  10736. item.MedChrgitmType = "03"
  10737. break
  10738. case 5:
  10739. item.MedChrgitmType = "08"
  10740. break
  10741. case 6:
  10742. item.MedChrgitmType = "14"
  10743. break
  10744. case 7:
  10745. item.MedChrgitmType = "14"
  10746. break
  10747. case 8:
  10748. item.MedChrgitmType = "03"
  10749. break
  10750. case 9:
  10751. item.MedChrgitmType = "14"
  10752. break
  10753. case 10:
  10754. item.MedChrgitmType = "14"
  10755. break
  10756. case 11:
  10757. item.MedChrgitmType = "06"
  10758. break
  10759. case 12:
  10760. item.MedChrgitmType = "12"
  10761. break
  10762. case 13:
  10763. item.MedChrgitmType = "01"
  10764. break
  10765. case 14:
  10766. item.MedChrgitmType = "04"
  10767. break
  10768. case 15:
  10769. item.MedChrgitmType = "14"
  10770. break
  10771. }
  10772. } else {
  10773. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10774. case 1:
  10775. item.MedChrgitmType = "14"
  10776. break
  10777. case 2:
  10778. item.MedChrgitmType = "05"
  10779. break
  10780. case 3:
  10781. item.MedChrgitmType = "04"
  10782. break
  10783. case 4:
  10784. item.MedChrgitmType = "14"
  10785. break
  10786. case 5:
  10787. item.MedChrgitmType = "08"
  10788. break
  10789. case 6:
  10790. item.MedChrgitmType = "14"
  10791. break
  10792. case 7:
  10793. item.MedChrgitmType = "14"
  10794. break
  10795. case 8:
  10796. item.MedChrgitmType = "03"
  10797. break
  10798. case 9:
  10799. item.MedChrgitmType = "14"
  10800. break
  10801. }
  10802. }
  10803. } else if item.HisPrescriptionProject.Type == 3 {
  10804. item.MedChrgitmType = "08"
  10805. }
  10806. }
  10807. }
  10808. for _, item := range order_info {
  10809. if org_id == 10215 {
  10810. if item.MedChrgitmType == "01" { //床位费
  10811. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10812. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10813. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10814. }
  10815. if item.MedChrgitmType == "02" { //诊察费
  10816. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10817. //zhenChaCostSelfTotal = zhenChaCostTotal
  10818. }
  10819. if item.MedChrgitmType == "03" { //检查费
  10820. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10821. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10822. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10823. }
  10824. //if item.MedChrgitmType == "02" { //检查费
  10825. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10826. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10827. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10828. //}
  10829. if item.MedChrgitmType == "04" { //化验费
  10830. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10831. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10832. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10833. }
  10834. if item.MedChrgitmType == "05" { //治疗费
  10835. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10836. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10837. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10838. }
  10839. if item.MedChrgitmType == "06" { //手术费
  10840. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10841. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10842. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10843. }
  10844. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10845. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10846. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10847. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10848. }
  10849. if item.MedChrgitmType == "09" { //西药费
  10850. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10851. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10852. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10853. }
  10854. if item.MedChrgitmType == "11" { //中成费
  10855. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10856. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10857. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10858. }
  10859. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10860. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10861. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10862. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10863. }
  10864. } else {
  10865. if item.MedChrgitmType == "01" { //床位费
  10866. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10867. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10868. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10869. }
  10870. //if item.MedChrgitmType == "02" { //诊察费
  10871. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10872. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10873. //}
  10874. if item.MedChrgitmType == "03" { //检查费
  10875. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10876. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10877. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10878. }
  10879. //if item.MedChrgitmType == "02" { //检查费
  10880. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10881. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10882. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10883. //}
  10884. if item.MedChrgitmType == "04" { //化验费
  10885. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10886. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10887. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10888. }
  10889. if item.MedChrgitmType == "05" { //治疗费
  10890. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10891. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10892. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10893. }
  10894. if item.MedChrgitmType == "06" { //手术费
  10895. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10896. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10897. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10898. }
  10899. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10900. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10901. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10902. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10903. }
  10904. if item.MedChrgitmType == "09" { //西药费
  10905. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10906. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10907. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10908. }
  10909. if item.MedChrgitmType == "11" { //中成费
  10910. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10911. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10912. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10913. }
  10914. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10915. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10916. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10917. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10918. }
  10919. }
  10920. }
  10921. c.ServeSuccessJSON(map[string]interface{}{
  10922. "order": order,
  10923. "order_info": order_info,
  10924. "patient": patient,
  10925. "admin_info": adminInfo,
  10926. "his_hospital": record,
  10927. "bedCostTotal": bedCostTotal,
  10928. "operationCostTotal": operationCostTotal,
  10929. "otherCostTotal": otherCostTotal,
  10930. "materialCostTotal": materialCostTotal,
  10931. "westernMedicineCostTotal": westernMedicineCostTotal,
  10932. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10933. "checkCostTotal": checkCostTotal,
  10934. "zhenChaCostTotal": zhenChaCostTotal,
  10935. "laboratoryCostTotal": laboratoryCostTotal,
  10936. "treatCostTotal": treatCostTotal,
  10937. })
  10938. }
  10939. }
  10940. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10941. page, _ := c.GetInt64("page")
  10942. limit, _ := c.GetInt64("limit")
  10943. keywords := c.GetString("keywords")
  10944. start_time := c.GetString("start_time")
  10945. end_time := c.GetString("end_time")
  10946. //clr_type := c.GetString("clr_type")
  10947. insutype := c.GetString("insutype")
  10948. timeLayout := "2006-01-02"
  10949. loc, _ := time.LoadLocation("Local")
  10950. var theStartTIme int64
  10951. if len(start_time) > 0 {
  10952. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10953. theStartTIme = theTime.Unix()
  10954. }
  10955. var theEndtTIme int64
  10956. if len(end_time) > 0 {
  10957. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10958. theEndtTIme = theTime.Unix()
  10959. }
  10960. if page <= 0 {
  10961. page = 1
  10962. }
  10963. if limit <= 0 {
  10964. limit = 10
  10965. }
  10966. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10967. c.ServeSuccessJSON(map[string]interface{}{
  10968. "total": total,
  10969. "list": list,
  10970. })
  10971. return
  10972. }
  10973. func (c *HisApiController) GetPutOnRecordList() {
  10974. page, _ := c.GetInt64("page")
  10975. limit, _ := c.GetInt64("limit")
  10976. keywords := c.GetString("keywords")
  10977. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10978. if page <= 0 {
  10979. page = 1
  10980. }
  10981. if limit <= 0 {
  10982. limit = 10
  10983. }
  10984. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10985. c.ServeSuccessJSON(map[string]interface{}{
  10986. "total": total,
  10987. "list": list,
  10988. })
  10989. return
  10990. }
  10991. func (c *HisApiController) GetCompareData() {
  10992. start_time := c.GetString("start_time")
  10993. end_time := c.GetString("end_time")
  10994. insutype := c.GetString("insutype")
  10995. clr_type := c.GetString("clr_type")
  10996. timeLayout := "2006-01-02"
  10997. loc, _ := time.LoadLocation("Local")
  10998. var theStartTIme int64
  10999. if len(start_time) > 0 {
  11000. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11001. if err != nil {
  11002. theStartTIme = 0
  11003. }
  11004. theStartTIme = theTime.Unix()
  11005. }
  11006. var theEndtTIme int64
  11007. if len(end_time) > 0 {
  11008. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11009. if err != nil {
  11010. theEndtTIme = 0
  11011. }
  11012. theEndtTIme = theTime.Unix()
  11013. }
  11014. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11015. fmt.Println(err)
  11016. if err == nil {
  11017. c.ServeSuccessJSON(map[string]interface{}{
  11018. "list": formData,
  11019. })
  11020. } else {
  11021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11022. return
  11023. }
  11024. }
  11025. func (c *HisApiController) GetFaPiaoData() {
  11026. order_id, _ := c.GetInt64("order_id")
  11027. patient_id, _ := c.GetInt64("patient_id")
  11028. //number := c.GetString("number")
  11029. adminUser := c.GetAdminUserInfo()
  11030. order, _ := service.GetHisOrderByID(order_id)
  11031. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11032. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11033. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11034. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11035. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11036. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11037. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11038. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11039. var bedCostTotal float64 = 0 //床位总费
  11040. var bedCostSelfTotal float64 = 0 //床位自费
  11041. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11042. var operationCostTotal float64 = 0 //手术费
  11043. var operationCostSelfTotal float64 = 0 //手术费
  11044. var operationCostPartSelfTotal float64 = 0 //手术费
  11045. var otherCostTotal float64 = 0 //其他费用
  11046. var otherCostSelfTotal float64 = 0 //其他费用
  11047. var otherCostPartSelfTotal float64 = 0 //其他费用
  11048. var materialCostTotal float64 = 0 //材料费
  11049. var materialCostSelfTotal float64 = 0 //材料费
  11050. var materialCostPartSelfTotal float64 = 0 //材料费
  11051. var westernMedicineCostTotal float64 = 0 //西药费
  11052. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11053. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11054. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11055. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11056. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11057. var checkCostTotal float64 = 0 //检查费
  11058. var checkCostSelfTotal float64 = 0 //检查费
  11059. var checkCostPartSelfTotal float64 = 0 //检查费
  11060. var hiliCostTotal float64 = 0 //护理费
  11061. var hiliCostSelfTotal float64 = 0 //护理费
  11062. var hiliCostPartSelfTotal float64 = 0 //护理费
  11063. var laboratoryCostTotal float64 = 0 //化验费
  11064. var laboratoryCostSelfTotal float64 = 0 //化验费
  11065. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11066. var treatCostTotal float64 = 0 //治疗费用
  11067. var treatCostSelfTotal float64 = 0 //治疗费用
  11068. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11069. var zhenChaCostTotal float64 = 0 //其他费用
  11070. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11071. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11072. decimal.DivisionPrecision = 2
  11073. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11074. var balanceAccountsType int64
  11075. if his.ID > 0 {
  11076. balanceAccountsType = his.BalanceAccountsType
  11077. } else {
  11078. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11079. }
  11080. if balanceAccountsType == 2 {
  11081. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11082. for _, item := range orderInfos_two {
  11083. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11084. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11085. item.MedChrgitmType = "09"
  11086. }
  11087. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11088. if item.HisPrescriptionProject.Type == 2 {
  11089. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11090. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11091. case 0:
  11092. item.MedChrgitmType = "0"
  11093. break
  11094. case 1:
  11095. item.MedChrgitmType = "14"
  11096. break
  11097. case 2:
  11098. item.MedChrgitmType = "05"
  11099. break
  11100. case 3:
  11101. item.MedChrgitmType = "03"
  11102. break
  11103. case 4:
  11104. item.MedChrgitmType = "03"
  11105. break
  11106. case 5:
  11107. item.MedChrgitmType = "08"
  11108. break
  11109. case 6:
  11110. item.MedChrgitmType = "14"
  11111. break
  11112. case 7:
  11113. item.MedChrgitmType = "14"
  11114. break
  11115. case 8:
  11116. item.MedChrgitmType = "03"
  11117. break
  11118. case 9:
  11119. item.MedChrgitmType = "14"
  11120. break
  11121. case 10:
  11122. item.MedChrgitmType = "14"
  11123. break
  11124. case 11:
  11125. item.MedChrgitmType = "06"
  11126. break
  11127. case 12:
  11128. item.MedChrgitmType = "12"
  11129. break
  11130. case 13:
  11131. item.MedChrgitmType = "01"
  11132. break
  11133. case 14:
  11134. item.MedChrgitmType = "04"
  11135. break
  11136. case 15:
  11137. item.MedChrgitmType = "02"
  11138. break
  11139. }
  11140. } else {
  11141. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11142. case 1:
  11143. item.MedChrgitmType = "14"
  11144. break
  11145. case 2:
  11146. item.MedChrgitmType = "05"
  11147. break
  11148. case 3:
  11149. item.MedChrgitmType = "04"
  11150. break
  11151. case 4:
  11152. item.MedChrgitmType = "03"
  11153. break
  11154. case 5:
  11155. item.MedChrgitmType = "08"
  11156. break
  11157. case 6:
  11158. item.MedChrgitmType = "14"
  11159. break
  11160. case 7:
  11161. item.MedChrgitmType = "14"
  11162. break
  11163. case 8:
  11164. item.MedChrgitmType = "03"
  11165. break
  11166. case 9:
  11167. item.MedChrgitmType = "14"
  11168. break
  11169. }
  11170. }
  11171. } else if item.HisPrescriptionProject.Type == 3 {
  11172. item.MedChrgitmType = "08"
  11173. }
  11174. }
  11175. }
  11176. for _, item := range orderInfos_two {
  11177. fmt.Println(item.MedChrgitmType)
  11178. if item.MedChrgitmType == "07" { //床位费
  11179. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11180. hiliCostSelfTotal = hiliCostTotal
  11181. }
  11182. if item.MedChrgitmType == "01" { //床位费
  11183. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11184. bedCostSelfTotal = bedCostTotal
  11185. }
  11186. if item.MedChrgitmType == "02" { //诊察费
  11187. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11188. zhenChaCostSelfTotal = zhenChaCostTotal
  11189. }
  11190. if item.MedChrgitmType == "03" { //检查费
  11191. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11192. checkCostSelfTotal = checkCostTotal
  11193. }
  11194. if item.MedChrgitmType == "04" { //化验费
  11195. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11196. laboratoryCostSelfTotal = laboratoryCostTotal
  11197. }
  11198. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11199. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11200. treatCostSelfTotal = treatCostTotal
  11201. }
  11202. if item.MedChrgitmType == "06" { //手术费
  11203. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11204. operationCostSelfTotal = treatCostTotal
  11205. }
  11206. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11207. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11208. materialCostSelfTotal = materialCostTotal
  11209. }
  11210. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11211. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11212. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11213. }
  11214. if item.MedChrgitmType == "11" { //中成费
  11215. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11216. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11217. }
  11218. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11219. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11220. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11221. otherCostSelfTotal = otherCostTotal
  11222. }
  11223. } else {
  11224. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11225. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11226. otherCostSelfTotal = otherCostTotal
  11227. }
  11228. }
  11229. }
  11230. } else {
  11231. for _, item := range orderInfos {
  11232. if item.MedChrgitmType == "01" { //床位费
  11233. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11234. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11235. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11236. }
  11237. if item.MedChrgitmType == "02" { //诊察费
  11238. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11239. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11240. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11241. }
  11242. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11243. if item.MedChrgitmType == "03" { //检查费
  11244. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11245. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11246. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11247. }
  11248. } else {
  11249. if item.MedChrgitmType == "03" { //检查费
  11250. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11251. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11252. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11253. }
  11254. }
  11255. if item.MedChrgitmType == "04" { //化验费
  11256. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11257. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11258. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11259. }
  11260. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11261. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11262. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11263. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11264. }
  11265. if item.MedChrgitmType == "06" { //手术费
  11266. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11267. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11268. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11269. }
  11270. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11271. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11272. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11273. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11274. }
  11275. if item.MedChrgitmType == "07" { //护理
  11276. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11277. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11278. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11279. }
  11280. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11281. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11282. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11283. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11284. }
  11285. if item.MedChrgitmType == "11" { //中成费
  11286. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11287. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11288. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11289. }
  11290. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11291. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11292. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11293. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11294. }
  11295. }
  11296. }
  11297. timeLayout := "2006-01-02"
  11298. loc, _ := time.LoadLocation("Local")
  11299. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11300. if err != nil {
  11301. }
  11302. startRecordDateTime := startTime.Unix()
  11303. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11304. if err != nil {
  11305. }
  11306. endRecordDateTime := endTime.Unix()
  11307. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11308. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11309. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11310. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11311. c.ServeSuccessJSON(map[string]interface{}{
  11312. "charge_admin_name": charge_admin.UserName,
  11313. "order_number": order.Number, //业务流水号
  11314. "id_card_no": his.IdCardNo, //社会保障号
  11315. "patient": patient,
  11316. "department_name": department.Name, //科室
  11317. "number": his.Number, //门诊号
  11318. "date": order.SettleAccountsDate, //结算日期
  11319. "name": order.PsnName, //姓名
  11320. "gender": patient.Gender, //性别
  11321. "psn_cash_money": order.PsnCashPay, //个人支付
  11322. "pay_way": "门诊", //结算方式
  11323. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11324. "admin_user_name": admin.UserName, //收款员
  11325. "order": order,
  11326. "order_info": orderInfos_two,
  11327. "his": his,
  11328. "bedCostTotal": bedCostTotal,
  11329. "bedCostSelfTotal": bedCostSelfTotal,
  11330. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11331. "operationCostTotal": operationCostTotal,
  11332. "operationCostSelfTotal": operationCostSelfTotal,
  11333. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11334. "otherCostTotal": otherCostTotal,
  11335. "otherCostSelfTotal": otherCostSelfTotal,
  11336. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11337. "materialCostTotal": materialCostTotal,
  11338. "materialCostSelfTotal": materialCostSelfTotal,
  11339. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11340. "westernMedicineCostTotal": westernMedicineCostTotal,
  11341. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11342. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11343. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11344. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11345. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11346. "checkCostTotal": checkCostTotal,
  11347. "checkCostSelfTotal": checkCostSelfTotal,
  11348. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11349. "laboratoryCostTotal": laboratoryCostTotal,
  11350. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11351. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11352. "treatCostTotal": treatCostTotal,
  11353. "treatCostSelfTotal": treatCostSelfTotal,
  11354. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11355. "zhenChaCostTotal": zhenChaCostTotal,
  11356. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11357. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11358. "his_hospital_record": his_hospital_record,
  11359. "pre_pay_money": pre_pay_money,
  11360. "refund_sum": sum,
  11361. "doctor_info": doctor_info,
  11362. "hiliCostTotal": hiliCostTotal,
  11363. "hiliCostSelfTotal": hiliCostSelfTotal,
  11364. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11365. })
  11366. }
  11367. //func (c *HisApiController) GetFaPiaoDatas() {
  11368. // order_ids := c.GetString("order_ids")
  11369. // patient_id, _ := c.GetInt64("patient_id")
  11370. // adminUser := c.GetAdminUserInfo()
  11371. //
  11372. // orders := strings.Split(order_ids, ",")
  11373. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11374. //
  11375. // for _, item := range orders {
  11376. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11377. // order, _ := service.GetHisOrderByID(order_id)
  11378. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11379. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11380. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11381. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11382. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11383. //
  11384. // }
  11385. //
  11386. // var bedCostTotal float64 = 0 //床位总费
  11387. // var bedCostSelfTotal float64 = 0 //床位自费
  11388. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11389. //
  11390. // var operationCostTotal float64 = 0 //手术费
  11391. // var operationCostSelfTotal float64 = 0 //手术费
  11392. // var operationCostPartSelfTotal float64 = 0 //手术费
  11393. //
  11394. // var otherCostTotal float64 = 0 //其他费用
  11395. // var otherCostSelfTotal float64 = 0 //其他费用
  11396. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11397. //
  11398. // var materialCostTotal float64 = 0 //材料费
  11399. // var materialCostSelfTotal float64 = 0 //材料费
  11400. // var materialCostPartSelfTotal float64 = 0 //材料费
  11401. //
  11402. // var westernMedicineCostTotal float64 = 0 //西药费
  11403. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11404. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11405. //
  11406. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11407. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11408. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11409. //
  11410. // var checkCostTotal float64 = 0 //检查费
  11411. // var checkCostSelfTotal float64 = 0 //检查费
  11412. // var checkCostPartSelfTotal float64 = 0 //检查费
  11413. //
  11414. // var laboratoryCostTotal float64 = 0 //化验费
  11415. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11416. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11417. //
  11418. // var treatCostTotal float64 = 0 //治疗费用
  11419. // var treatCostSelfTotal float64 = 0 //治疗费用
  11420. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11421. //
  11422. // var zhenChaCostTotal float64 = 0 //其他费用
  11423. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11424. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11425. //
  11426. // decimal.DivisionPrecision = 2
  11427. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11428. //
  11429. // var balanceAccountsType int64
  11430. // if his.ID > 0 {
  11431. // balanceAccountsType = his.BalanceAccountsType
  11432. // } else {
  11433. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11434. // }
  11435. // if balanceAccountsType == 2 {
  11436. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11437. // for _, item := range orderInfos_two {
  11438. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11439. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11440. // item.MedChrgitmType = "09"
  11441. // }
  11442. //
  11443. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11444. // if item.HisPrescriptionProject.Type == 2 {
  11445. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11446. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11447. // case 0:
  11448. // item.MedChrgitmType = "0"
  11449. // break
  11450. // case 1:
  11451. // item.MedChrgitmType = "14"
  11452. // break
  11453. // case 2:
  11454. // item.MedChrgitmType = "05"
  11455. //
  11456. // break
  11457. // case 3:
  11458. // item.MedChrgitmType = "03"
  11459. //
  11460. // break
  11461. // case 4:
  11462. // item.MedChrgitmType = "03"
  11463. //
  11464. // break
  11465. // case 5:
  11466. // item.MedChrgitmType = "08"
  11467. //
  11468. // break
  11469. // case 6:
  11470. // item.MedChrgitmType = "14"
  11471. //
  11472. // break
  11473. // case 7:
  11474. // item.MedChrgitmType = "14"
  11475. //
  11476. // break
  11477. // case 8:
  11478. // item.MedChrgitmType = "03"
  11479. // break
  11480. // case 9:
  11481. // item.MedChrgitmType = "14"
  11482. // break
  11483. // case 10:
  11484. // item.MedChrgitmType = "14"
  11485. // break
  11486. // case 11:
  11487. // item.MedChrgitmType = "06"
  11488. // break
  11489. // case 12:
  11490. // item.MedChrgitmType = "12"
  11491. // break
  11492. // case 13:
  11493. // item.MedChrgitmType = "01"
  11494. // break
  11495. // case 14:
  11496. // item.MedChrgitmType = "04"
  11497. // break
  11498. // case 15:
  11499. // item.MedChrgitmType = "02"
  11500. // break
  11501. //
  11502. // }
  11503. //
  11504. // } else {
  11505. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11506. //
  11507. // case 1:
  11508. // item.MedChrgitmType = "14"
  11509. // break
  11510. // case 2:
  11511. // item.MedChrgitmType = "05"
  11512. //
  11513. // break
  11514. // case 3:
  11515. // item.MedChrgitmType = "03"
  11516. //
  11517. // break
  11518. // case 4:
  11519. // item.MedChrgitmType = "03"
  11520. //
  11521. // break
  11522. // case 5:
  11523. // item.MedChrgitmType = "08"
  11524. //
  11525. // break
  11526. // case 6:
  11527. // item.MedChrgitmType = "14"
  11528. //
  11529. // break
  11530. // case 7:
  11531. // item.MedChrgitmType = "14"
  11532. //
  11533. // break
  11534. // case 8:
  11535. // item.MedChrgitmType = "03"
  11536. // break
  11537. // case 9:
  11538. // item.MedChrgitmType = "14"
  11539. // break
  11540. //
  11541. // }
  11542. //
  11543. // }
  11544. //
  11545. // } else if item.HisPrescriptionProject.Type == 3 {
  11546. // item.MedChrgitmType = "08"
  11547. // }
  11548. // }
  11549. // }
  11550. //
  11551. // for _, item := range orderInfos_two {
  11552. // fmt.Println(item.MedChrgitmType)
  11553. // if item.MedChrgitmType == "01" { //床位费
  11554. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11555. // bedCostSelfTotal = bedCostTotal
  11556. // }
  11557. //
  11558. // if item.MedChrgitmType == "02" { //诊察费
  11559. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11560. // zhenChaCostSelfTotal = zhenChaCostTotal
  11561. // }
  11562. //
  11563. // if item.MedChrgitmType == "03" { //检查费
  11564. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11565. // checkCostSelfTotal = checkCostTotal
  11566. // }
  11567. //
  11568. // if item.MedChrgitmType == "04" { //化验费
  11569. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11570. // laboratoryCostSelfTotal = laboratoryCostTotal
  11571. // }
  11572. //
  11573. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11574. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11575. // treatCostSelfTotal = treatCostTotal
  11576. // }
  11577. //
  11578. // if item.MedChrgitmType == "06" { //手术费
  11579. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11580. // operationCostSelfTotal = treatCostTotal
  11581. // }
  11582. //
  11583. // if item.MedChrgitmType == "08" { //材料费
  11584. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11585. // materialCostSelfTotal = materialCostTotal
  11586. // }
  11587. //
  11588. // if item.MedChrgitmType == "09" { //西药费
  11589. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11590. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11591. // }
  11592. //
  11593. // if item.MedChrgitmType == "11" { //中成费
  11594. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11595. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11596. // }
  11597. //
  11598. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11599. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11600. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11601. // otherCostSelfTotal = otherCostTotal
  11602. // }
  11603. // } else {
  11604. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11605. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11606. // otherCostSelfTotal = otherCostTotal
  11607. // }
  11608. //
  11609. // }
  11610. //
  11611. // }
  11612. //
  11613. // } else {
  11614. // for _, item := range orderInfos {
  11615. // if item.MedChrgitmType == "01" { //床位费
  11616. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11617. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11618. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11619. // }
  11620. //
  11621. // if item.MedChrgitmType == "02" { //诊察费
  11622. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11623. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11624. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11625. // }
  11626. //
  11627. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11628. // if item.MedChrgitmType == "03" { //检查费
  11629. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11630. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11631. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11632. //
  11633. // }
  11634. // } else {
  11635. // if item.MedChrgitmType == "03" { //检查费
  11636. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11637. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11638. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11639. // }
  11640. //
  11641. // }
  11642. //
  11643. // if item.MedChrgitmType == "04" { //化验费
  11644. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11645. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11646. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11647. //
  11648. // }
  11649. //
  11650. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11651. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11652. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11653. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11654. //
  11655. // }
  11656. //
  11657. // if item.MedChrgitmType == "06" { //手术费
  11658. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11659. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11660. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11661. // }
  11662. //
  11663. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11664. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11665. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11666. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11667. // }
  11668. //
  11669. // if item.MedChrgitmType == "09" { //西药费
  11670. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11671. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11672. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11673. // }
  11674. //
  11675. // if item.MedChrgitmType == "11" { //中成费
  11676. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11677. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11678. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11679. // }
  11680. //
  11681. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11682. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11683. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11684. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11685. // }
  11686. //
  11687. // }
  11688. // }
  11689. // timeLayout := "2006-01-02"
  11690. // loc, _ := time.LoadLocation("Local")
  11691. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11692. // if err != nil {
  11693. // }
  11694. // startRecordDateTime := startTime.Unix()
  11695. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11696. // if err != nil {
  11697. // }
  11698. // endRecordDateTime := endTime.Unix()
  11699. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11700. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11701. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11702. //
  11703. // c.ServeSuccessJSON(map[string]interface{}{
  11704. // "order_number": order.Number, //业务流水号
  11705. // "id_card_no": his.IdCardNo, //社会保障号
  11706. // "department_name": department.Name, //科室
  11707. // "number": his.Number, //门诊号
  11708. // "date": order.SettleAccountsDate, //结算日期
  11709. // "name": order.PsnName, //姓名
  11710. // "gender": patient.Gender, //性别
  11711. // "psn_cash_money": order.PsnCashPay, //个人支付
  11712. // "pay_way": "门诊", //结算方式
  11713. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11714. // "admin_user_name": admin.UserName, //收款员
  11715. // "order": order,
  11716. // "order_info": orderInfos_two,
  11717. // "his": his,
  11718. // "bedCostTotal": bedCostTotal,
  11719. // "bedCostSelfTotal": bedCostSelfTotal,
  11720. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11721. // "operationCostTotal": operationCostTotal,
  11722. // "operationCostSelfTotal": operationCostSelfTotal,
  11723. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11724. // "otherCostTotal": otherCostTotal,
  11725. // "otherCostSelfTotal": otherCostSelfTotal,
  11726. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11727. // "materialCostTotal": materialCostTotal,
  11728. // "materialCostSelfTotal": materialCostSelfTotal,
  11729. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11730. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11731. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11732. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11733. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11734. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11735. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11736. // "checkCostTotal": checkCostTotal,
  11737. // "checkCostSelfTotal": checkCostSelfTotal,
  11738. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11739. // "laboratoryCostTotal": laboratoryCostTotal,
  11740. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11741. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11742. // "treatCostTotal": treatCostTotal,
  11743. // "treatCostSelfTotal": treatCostSelfTotal,
  11744. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11745. // "zhenChaCostTotal": zhenChaCostTotal,
  11746. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11747. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11748. // "his_hospital_record": his_hospital_record,
  11749. // "pre_pay_money": pre_pay_money,
  11750. // "refund_sum": sum,
  11751. // })
  11752. //
  11753. //}
  11754. func (this *HisApiController) GetIncomeStatisticsData() {
  11755. start_time := this.GetString("start_time")
  11756. end_time := this.GetString("end_time")
  11757. key_words := this.GetString("key_words")
  11758. limit, _ := this.GetInt64("limit")
  11759. page, _ := this.GetInt64("page")
  11760. if page <= 0 {
  11761. page = 1
  11762. }
  11763. if limit <= 0 {
  11764. limit = 10
  11765. }
  11766. statistics_type, _ := this.GetInt64("statistics_type")
  11767. admin := this.GetAdminUserInfo()
  11768. timeLayout := "2006-01-02"
  11769. loc, _ := time.LoadLocation("Local")
  11770. var theStartTIme int64
  11771. if len(start_time) > 0 {
  11772. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11773. if err != nil {
  11774. theStartTIme = 0
  11775. }
  11776. theStartTIme = theTime.Unix()
  11777. }
  11778. var theEndtTIme int64
  11779. if len(end_time) > 0 {
  11780. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11781. if err != nil {
  11782. theEndtTIme = 0
  11783. }
  11784. theEndtTIme = theTime.Unix()
  11785. }
  11786. if statistics_type == 1 {
  11787. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11788. this.ServeSuccessJSON(map[string]interface{}{
  11789. "list": list,
  11790. "total": total,
  11791. })
  11792. } else {
  11793. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11794. this.ServeSuccessJSON(map[string]interface{}{
  11795. "list": list,
  11796. "total": total,
  11797. })
  11798. }
  11799. }
  11800. func (c *HisApiController) PostProjectInformation() {
  11801. adminUser := c.GetAdminUserInfo()
  11802. orgId := adminUser.CurrentOrgId
  11803. dataBody := make(map[string]interface{}, 0)
  11804. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11805. if err != nil {
  11806. utils.ErrorLog(err.Error())
  11807. return
  11808. }
  11809. utils.ErrorLog("%v", dataBody)
  11810. var projectList []*models.HisProject
  11811. var total_goods []interface{}
  11812. tempProjects := dataBody["projects"].([]interface{})
  11813. total_goods = tempProjects
  11814. for index, projectMap := range tempProjects {
  11815. projectM := projectMap.(map[string]interface{})
  11816. var project models.HisProject
  11817. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11818. utils.ErrorLog("project_name")
  11819. return
  11820. }
  11821. project_name, _ := projectM["project_name"].(string)
  11822. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11823. err_log := models.ExportErrLog{
  11824. LogType: 6,
  11825. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11826. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11827. Status: 1,
  11828. CreateTime: time.Now().Unix(),
  11829. UpdateTime: time.Now().Unix(),
  11830. ExportTime: time.Now().Unix(),
  11831. }
  11832. service.CreateExportErrLog(&err_log)
  11833. continue
  11834. }
  11835. project.ProjectName = project_name
  11836. prices := projectM["price"].(string)
  11837. price, _ := strconv.ParseFloat(prices, 64)
  11838. if price <= 0 { //名字为空则生成一条导入错误日志
  11839. err_log := models.ExportErrLog{
  11840. LogType: 6,
  11841. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11842. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11843. Status: 1,
  11844. CreateTime: time.Now().Unix(),
  11845. UpdateTime: time.Now().Unix(),
  11846. ExportTime: time.Now().Unix(),
  11847. }
  11848. service.CreateExportErrLog(&err_log)
  11849. continue
  11850. }
  11851. project.Price = price
  11852. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11853. utils.ErrorLog("unit_id")
  11854. return
  11855. }
  11856. unit := projectM["unit"].(string)
  11857. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11858. err_log := models.ExportErrLog{
  11859. LogType: 6,
  11860. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11861. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11862. Status: 1,
  11863. CreateTime: time.Now().Unix(),
  11864. UpdateTime: time.Now().Unix(),
  11865. ExportTime: time.Now().Unix(),
  11866. }
  11867. service.CreateExportErrLog(&err_log)
  11868. continue
  11869. }
  11870. project.Unit = unit
  11871. cost_classify := projectM["cost_classify"].(string)
  11872. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11873. err_log := models.ExportErrLog{
  11874. LogType: 6,
  11875. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11876. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11877. Status: 1,
  11878. CreateTime: time.Now().Unix(),
  11879. UpdateTime: time.Now().Unix(),
  11880. ExportTime: time.Now().Unix(),
  11881. }
  11882. service.CreateExportErrLog(&err_log)
  11883. continue
  11884. }
  11885. var costClassify = "费用类别"
  11886. var cost_classify_id int64
  11887. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11888. if len(cost_classify) != 0 {
  11889. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11890. if errcode == gorm.ErrRecordNotFound {
  11891. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11892. dataconfig := models.DictDataconfig{
  11893. ParentId: costClassifyConfig.ID,
  11894. Module: "system",
  11895. OrgId: orgId,
  11896. Name: cost_classify,
  11897. FieldName: "",
  11898. Value: costConfig.Value + 1,
  11899. CreatedTime: "",
  11900. UpdatedTime: "",
  11901. CreateUserId: adminUser.AdminUser.Id,
  11902. Status: 1,
  11903. Remark: "",
  11904. DeleteIdSystem: 0,
  11905. Title: "",
  11906. Content: "",
  11907. Order: 0,
  11908. Code: "",
  11909. }
  11910. service.CreatedDicConfig(&dataconfig)
  11911. }
  11912. }
  11913. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11914. for _, it := range costClassList {
  11915. if cost_classify == it.Name {
  11916. cost_classify_id = int64(it.Value)
  11917. }
  11918. }
  11919. project.CostClassify = cost_classify_id
  11920. executive_section := projectM["executive_section"].(string)
  11921. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11922. err_log := models.ExportErrLog{
  11923. LogType: 6,
  11924. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11925. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11926. Status: 1,
  11927. CreateTime: time.Now().Unix(),
  11928. UpdateTime: time.Now().Unix(),
  11929. ExportTime: time.Now().Unix(),
  11930. }
  11931. service.CreateExportErrLog(&err_log)
  11932. continue
  11933. }
  11934. if len(executive_section) != 0 {
  11935. //查找科室是否有内容
  11936. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11937. if errcodedepart == gorm.ErrRecordNotFound {
  11938. department := models.XtHisDepartment{
  11939. Name: executive_section,
  11940. Status: 1,
  11941. UserOrgId: adminUser.CurrentOrgId,
  11942. CreatedTime: time.Now().Unix(),
  11943. }
  11944. service.CreateDePartment(&department)
  11945. }
  11946. }
  11947. var executive_section_id int64
  11948. departMentList, _ := service.GetAllDepartMent(orgId)
  11949. for _, it := range departMentList {
  11950. if executive_section == it.Name {
  11951. executive_section_id = it.ID
  11952. }
  11953. }
  11954. project.ExecutiveSection = executive_section_id
  11955. medical_coverage := projectM["medical_coverage"].(string)
  11956. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11957. err_log := models.ExportErrLog{
  11958. LogType: 6,
  11959. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11960. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11961. Status: 1,
  11962. CreateTime: time.Now().Unix(),
  11963. UpdateTime: time.Now().Unix(),
  11964. ExportTime: time.Now().Unix(),
  11965. }
  11966. service.CreateExportErrLog(&err_log)
  11967. continue
  11968. }
  11969. var medicalCoverage = "医保等级"
  11970. var medical_coverage_id int64
  11971. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11972. if len(medical_coverage) != 0 {
  11973. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11974. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11975. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11976. dataconfig := models.DictDataconfig{
  11977. ParentId: medicalCoverageConfig.ID,
  11978. Module: "system",
  11979. OrgId: orgId,
  11980. Name: medical_coverage,
  11981. FieldName: "",
  11982. Value: medicalCoverageConfig.Value + 1,
  11983. CreatedTime: "",
  11984. UpdatedTime: "",
  11985. CreateUserId: adminUser.AdminUser.Id,
  11986. Status: 1,
  11987. Remark: "",
  11988. DeleteIdSystem: 0,
  11989. Title: "",
  11990. Content: "",
  11991. Order: 0,
  11992. Code: "",
  11993. }
  11994. service.CreatedDicConfig(&dataconfig)
  11995. }
  11996. }
  11997. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11998. for _, it := range medicalCoverageList {
  11999. if medical_coverage == it.Name {
  12000. medical_coverage_id = int64(it.Value)
  12001. }
  12002. }
  12003. project.MedicalCoverage = medical_coverage_id
  12004. pinyin := projectM["pinyin"].(string)
  12005. project.Pinyin = pinyin
  12006. wubi := projectM["wubi"].(string)
  12007. project.Wubi = wubi
  12008. statistical_classification := projectM["statistical_classification"].(string)
  12009. var statisticalClassification = "统计分类"
  12010. var statistical_classification_id int64
  12011. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12012. if len(statistical_classification) != 0 {
  12013. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12014. if classificationerrcodes == gorm.ErrRecordNotFound {
  12015. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12016. dataconfig := models.DictDataconfig{
  12017. ParentId: classiFication.ID,
  12018. Module: "system",
  12019. OrgId: orgId,
  12020. Name: statistical_classification,
  12021. FieldName: "",
  12022. Value: classiFicationConfig.Value + 1,
  12023. CreatedTime: "",
  12024. UpdatedTime: "",
  12025. CreateUserId: adminUser.AdminUser.Id,
  12026. Status: 1,
  12027. Remark: "",
  12028. DeleteIdSystem: 0,
  12029. Title: "",
  12030. Content: "",
  12031. Order: 0,
  12032. Code: "",
  12033. }
  12034. service.CreatedDicConfig(&dataconfig)
  12035. }
  12036. }
  12037. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12038. for _, it := range classiFicationList {
  12039. if statistical_classification == it.Name {
  12040. statistical_classification_id = int64(it.Value)
  12041. }
  12042. }
  12043. project.StatisticalClassification = statistical_classification_id
  12044. disease_directory := int64(projectM["disease_directory"].(float64))
  12045. project.DiseaseDirectory = disease_directory
  12046. is_record := int64(projectM["is_record"].(float64))
  12047. project.IsRecord = is_record
  12048. medical_code := projectM["medical_code"].(string)
  12049. project.MedicalCode = medical_code
  12050. tube_color := projectM["tube_color"].(string)
  12051. var tubeColor = "试管颜色"
  12052. var tube_color_id int64
  12053. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12054. if len(tube_color) != 0 {
  12055. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12056. if errcodetube == gorm.ErrRecordNotFound {
  12057. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12058. dataconfig := models.DictDataconfig{
  12059. ParentId: tubeColorConfig.ID,
  12060. Module: "system",
  12061. OrgId: orgId,
  12062. Name: tube_color,
  12063. FieldName: "",
  12064. Value: tubeConfig.Value + 1,
  12065. CreatedTime: "",
  12066. UpdatedTime: "",
  12067. CreateUserId: adminUser.AdminUser.Id,
  12068. Status: 1,
  12069. Remark: "",
  12070. DeleteIdSystem: 0,
  12071. Title: "",
  12072. Content: "",
  12073. Order: 0,
  12074. Code: "",
  12075. }
  12076. service.CreatedDicConfig(&dataconfig)
  12077. }
  12078. }
  12079. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12080. for _, it := range tubeColorList {
  12081. if tube_color == it.Name {
  12082. tube_color_id = int64(it.Value)
  12083. }
  12084. }
  12085. project.TubeColor = tube_color_id
  12086. single_dose := projectM["single_dose"].(string)
  12087. project.SingleDose = single_dose
  12088. execution_frequency := projectM["execution_frequency"].(string)
  12089. project.ExecutionFrequency = execution_frequency
  12090. delivery_way := projectM["delivery_way"].(string)
  12091. project.DeliveryWay = delivery_way
  12092. number_days := projectM["number_days"].(string)
  12093. project.NumberDays = number_days
  12094. total := projectM["total"].(string)
  12095. project.Total = total
  12096. medical_status := int64(projectM["medical_status"].(float64))
  12097. project.MedicalStatus = medical_status
  12098. category := int64(projectM["category"].(float64))
  12099. project.Category = category
  12100. specail_project := int64(projectM["specail_project"].(float64))
  12101. project.SpecailProject = specail_project
  12102. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12103. project.SocialSecurityDirectoryCode = social_security_directory_code
  12104. remark := projectM["remark"].(string)
  12105. project.Remark = remark
  12106. record_date := projectM["record_date"].(string)
  12107. timeLayout := "2006-01-02"
  12108. loc, _ := time.LoadLocation("Local")
  12109. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12110. project.RecordDate = theTime.Unix()
  12111. projectList = append(projectList, &project)
  12112. }
  12113. export_time := time.Now().Unix()
  12114. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12115. if len(projectList) > 0 {
  12116. for _, item := range projectList {
  12117. hans := item.ProjectName // 要转换的汉字字符串
  12118. // 创建一个拼音转换器
  12119. p := pinyin.NewArgs()
  12120. // 将汉字转为拼音
  12121. pinyinSlice := pinyin.Pinyin(hans, p)
  12122. // 输出拼音
  12123. fmt.Println("Pinyin:", pinyinSlice)
  12124. // 获取首字母
  12125. firstLetter := ""
  12126. for _, py := range pinyinSlice {
  12127. if len(py) > 0 {
  12128. firstLetter += string(py[0][0])
  12129. }
  12130. }
  12131. item.FirstLetter = firstLetter
  12132. project := models.HisProject{
  12133. ProjectName: item.ProjectName,
  12134. Price: item.Price,
  12135. Unit: item.Unit,
  12136. CostClassify: item.CostClassify,
  12137. ExecutiveSection: item.ExecutiveSection,
  12138. MedicalCoverage: item.MedicalCoverage,
  12139. UserOrgId: orgId,
  12140. Status: 1,
  12141. CreatedTime: time.Now().Unix(),
  12142. Pinyin: item.Pinyin,
  12143. Wubi: item.Wubi,
  12144. StatisticalClassification: item.StatisticalClassification,
  12145. DiseaseDirectory: item.DiseaseDirectory,
  12146. IsRecord: item.IsRecord,
  12147. MedicalCode: item.MedicalCode,
  12148. TubeColor: item.TubeColor,
  12149. SingleDose: item.SingleDose,
  12150. DeliveryWay: item.DeliveryWay,
  12151. NumberDays: item.NumberDays,
  12152. Total: item.Total,
  12153. Category: item.Category,
  12154. MedicalStatus: item.MedicalStatus,
  12155. SpecailProject: item.SpecailProject,
  12156. RecordDate: item.RecordDate,
  12157. Remark: item.Remark,
  12158. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12159. ExecutionFrequency: item.ExecutionFrequency,
  12160. FirstLetter: item.FirstLetter,
  12161. }
  12162. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12163. if errcodeproject == gorm.ErrRecordNotFound {
  12164. service.CreateProjectInfomation(&project)
  12165. } else if errcodeproject == nil {
  12166. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12167. }
  12168. log := models.ExportLog{
  12169. LogType: 6,
  12170. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12171. TotalNum: int64(len(total_goods)),
  12172. FailNum: int64(len(errLogs)),
  12173. SuccessNum: int64(len(projectList)),
  12174. CreateTime: time.Now().Unix(),
  12175. UpdateTime: time.Now().Unix(),
  12176. ExportTime: export_time,
  12177. Status: 1,
  12178. }
  12179. service.CreateExportLog(&log)
  12180. c.ServeSuccessJSON(map[string]interface{}{
  12181. "msg": "导入成功",
  12182. "total_num": len(total_goods),
  12183. "success_num": len(projectList),
  12184. "fail_num": int64(len(errLogs)),
  12185. })
  12186. }
  12187. } else {
  12188. log := models.ExportLog{
  12189. LogType: 6,
  12190. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12191. TotalNum: int64(len(total_goods)),
  12192. FailNum: int64(len(errLogs)),
  12193. SuccessNum: int64(len(projectList)),
  12194. CreateTime: time.Now().Unix(),
  12195. UpdateTime: time.Now().Unix(),
  12196. ExportTime: export_time,
  12197. Status: 1,
  12198. }
  12199. service.CreateExportLog(&log)
  12200. c.ServeSuccessJSON(map[string]interface{}{
  12201. "msg": "导入成功",
  12202. "total_num": len(total_goods),
  12203. "success_num": len(projectList),
  12204. "fail_num": int64(len(errLogs)),
  12205. })
  12206. }
  12207. }
  12208. //func (this *HisApiController) EditProjectInformation(){
  12209. //
  12210. // id, _ := this.GetInt64("id")
  12211. // project_team := this.GetString("project_team")
  12212. // price := this.GetString("price")
  12213. // price_float, _ := strconv.ParseFloat(price, 64)
  12214. // pinyin := this.GetString("pinyin")
  12215. // wubi := this.GetString("wubi")
  12216. // tube_color, _ := this.GetInt64("tube_color")
  12217. // team_type, _ := this.GetInt64("team_type")
  12218. // remark := this.GetString("remark")
  12219. // ids := this.GetString("ids")
  12220. // item_id := this.GetString("item_id")
  12221. // projectTeam := models.XtHisProjectTeam{
  12222. // ProjectTeam: project_team,
  12223. // Price: price_float,
  12224. // Pinyin: pinyin,
  12225. // Wubi: wubi,
  12226. // TubeColor: tube_color,
  12227. // TeamType: team_type,
  12228. // Remark: remark,
  12229. // ProjectId: ids,
  12230. // ItemId: item_id,
  12231. // }
  12232. //
  12233. //
  12234. // dataBody := make(map[string]interface{}, 0)
  12235. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12236. // if err != nil {
  12237. // utils.ErrorLog(err.Error())
  12238. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12239. // return
  12240. // }
  12241. //
  12242. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12243. //
  12244. //
  12245. // if err != nil {
  12246. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12247. // return
  12248. // }
  12249. //
  12250. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12251. // infos, _ := dataBody["info"].([]interface{})
  12252. // if len(infos) > 0 {
  12253. // var ids []string
  12254. //
  12255. // for _, item := range infos {
  12256. // items := item.(map[string]interface{})
  12257. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12258. // utils.ErrorLog("id")
  12259. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12260. // return
  12261. // }
  12262. // id := int64(items["id"].(float64))
  12263. //
  12264. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12265. // utils.ErrorLog("type")
  12266. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12267. // return
  12268. // }
  12269. // types := int64(items["type"].(float64))
  12270. //
  12271. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12272. // utils.ErrorLog("number")
  12273. // }
  12274. //
  12275. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12276. //
  12277. // projectList := models.XtHisProjectList{
  12278. // Number: number,
  12279. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12280. // ProjectId: id,
  12281. // Status: 1,
  12282. // CreatedTime: time.Now().Unix(),
  12283. // UpdatedTime: time.Now().Unix(),
  12284. // TeamId: projectTeam.ID,
  12285. // Type: types,
  12286. // }
  12287. // list := projectList
  12288. //
  12289. // service.CreateProjectList(&list)
  12290. //
  12291. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12292. //
  12293. // }
  12294. // ids_str := strings.Join(ids, ",")
  12295. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12296. // service.SaveProjectTeam(&projectTeam)
  12297. // this.ServeSuccessJSON(map[string]interface{}{
  12298. // "projectTeam": projectTeam,
  12299. // })
  12300. // }
  12301. // }
  12302. //}
  12303. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12304. name := c.GetString("name")
  12305. mode_id, _ := c.GetInt64("mode", 0)
  12306. types, _ := c.GetInt64("type", 0)
  12307. patient_id, _ := c.GetInt64("patient_id", 0)
  12308. types = 1
  12309. adminInfo := c.GetAdminUserInfo()
  12310. template := &models.HisPrescriptionTemplate{
  12311. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12312. PatientId: patient_id,
  12313. Type: types,
  12314. Status: 1,
  12315. Ctime: time.Now().Unix(),
  12316. Mtime: time.Now().Unix(),
  12317. Name: name,
  12318. Mode: mode_id,
  12319. }
  12320. dataBody := make(map[string]interface{}, 0)
  12321. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12322. if err != nil {
  12323. utils.ErrorLog(err.Error())
  12324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12325. return
  12326. }
  12327. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12328. //如果已经存在记录则删除处方
  12329. if template_one.ID > 0 {
  12330. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12331. var ids []int64
  12332. var org_id int64
  12333. for _, item := range ps {
  12334. org_id = c.GetAdminUserInfo().CurrentOrgId
  12335. ids = append(ids, item.ID)
  12336. }
  12337. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12338. if err2 == nil {
  12339. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12340. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12341. if len(prescriptions) > 0 {
  12342. for _, item := range prescriptions {
  12343. items := item.(map[string]interface{})
  12344. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12345. utils.ErrorLog("type")
  12346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12347. return
  12348. }
  12349. types := int64(items["type"].(float64))
  12350. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12351. utils.ErrorLog("med_type")
  12352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12353. return
  12354. }
  12355. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12356. ctime := time.Now().Unix()
  12357. prescription := &models.HisPrescriptionInfoTemplate{
  12358. PatientId: patient_id,
  12359. UserOrgId: adminInfo.CurrentOrgId,
  12360. Ctime: ctime,
  12361. Mtime: ctime,
  12362. Type: types,
  12363. Modifier: adminInfo.AdminUser.Id,
  12364. Creator: adminInfo.AdminUser.Id,
  12365. Status: 1,
  12366. PTemplateId: template_one.ID,
  12367. MedType: med_type,
  12368. }
  12369. service.CreateHisPrescriptionInfoTemplate(prescription)
  12370. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12371. advices := items["advices"].([]interface{})
  12372. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12373. ctime := time.Now().Unix()
  12374. mtime := ctime
  12375. if len(advices) > 0 {
  12376. for _, advice := range advices {
  12377. var s models.HisPrescriptionAdviceTemplate
  12378. s.PrescriptionId = prescription.ID
  12379. s.AdviceType = 2
  12380. s.StopState = 2
  12381. s.ExecutionState = 2
  12382. s.Status = 1
  12383. s.UserOrgId = adminInfo.CurrentOrgId
  12384. s.CreatedTime = ctime
  12385. s.UpdatedTime = mtime
  12386. s.PatientId = patient_id
  12387. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12388. if errcode > 0 {
  12389. c.ServeFailJSONWithSGJErrorCode(errcode)
  12390. return
  12391. }
  12392. service.CreateHisPrescriptionAdviceTemplate(&s)
  12393. }
  12394. }
  12395. }
  12396. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12397. projects := items["project"].([]interface{})
  12398. if len(projects) > 0 {
  12399. for _, project := range projects {
  12400. var p models.HisPrescriptionProjectTemplate
  12401. p.PrescriptionId = prescription.ID
  12402. p.Ctime = time.Now().Unix()
  12403. p.Mtime = time.Now().Unix()
  12404. p.PatientId = patient_id
  12405. p.UserOrgId = adminInfo.CurrentOrgId
  12406. p.Status = 1
  12407. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12408. if errcode > 0 {
  12409. c.ServeFailJSONWithSGJErrorCode(errcode)
  12410. return
  12411. }
  12412. service.CreateHisPrescriptionProjectTemplate(&p)
  12413. }
  12414. }
  12415. }
  12416. }
  12417. c.ServeSuccessJSON(map[string]interface{}{
  12418. "msg": "创建成功",
  12419. })
  12420. }
  12421. }
  12422. } else {
  12423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12424. return
  12425. }
  12426. } else {
  12427. err3 := service.CreateHisPrescriptionTemplate(template)
  12428. if err3 == nil {
  12429. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12430. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12431. if len(prescriptions) > 0 {
  12432. for _, item := range prescriptions {
  12433. items := item.(map[string]interface{})
  12434. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12435. utils.ErrorLog("type")
  12436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12437. return
  12438. }
  12439. types := int64(items["type"].(float64))
  12440. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12441. utils.ErrorLog("med_type")
  12442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12443. return
  12444. }
  12445. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12446. ctime := time.Now().Unix()
  12447. prescription := &models.HisPrescriptionInfoTemplate{
  12448. PatientId: patient_id,
  12449. UserOrgId: adminInfo.CurrentOrgId,
  12450. Ctime: ctime,
  12451. Mtime: ctime,
  12452. Type: types,
  12453. Modifier: adminInfo.AdminUser.Id,
  12454. Creator: adminInfo.AdminUser.Id,
  12455. Status: 1,
  12456. PTemplateId: template.ID,
  12457. MedType: med_type,
  12458. }
  12459. service.CreateHisPrescriptionInfoTemplate(prescription)
  12460. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12461. advices := items["advices"].([]interface{})
  12462. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12463. ctime := time.Now().Unix()
  12464. mtime := ctime
  12465. if len(advices) > 0 {
  12466. for _, advice := range advices {
  12467. var s models.HisPrescriptionAdviceTemplate
  12468. s.PrescriptionId = prescription.ID
  12469. s.AdviceType = 2
  12470. s.StopState = 2
  12471. s.ExecutionState = 2
  12472. s.Status = 1
  12473. s.UserOrgId = adminInfo.CurrentOrgId
  12474. s.CreatedTime = ctime
  12475. s.UpdatedTime = mtime
  12476. s.PatientId = patient_id
  12477. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12478. if errcode > 0 {
  12479. c.ServeFailJSONWithSGJErrorCode(errcode)
  12480. return
  12481. }
  12482. service.CreateHisPrescriptionAdviceTemplate(&s)
  12483. }
  12484. }
  12485. }
  12486. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12487. projects := items["project"].([]interface{})
  12488. if len(projects) > 0 {
  12489. for _, project := range projects {
  12490. var p models.HisPrescriptionProjectTemplate
  12491. p.PrescriptionId = prescription.ID
  12492. p.Ctime = time.Now().Unix()
  12493. p.Mtime = time.Now().Unix()
  12494. p.PatientId = patient_id
  12495. p.UserOrgId = adminInfo.CurrentOrgId
  12496. p.Status = 1
  12497. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12498. if errcode > 0 {
  12499. c.ServeFailJSONWithSGJErrorCode(errcode)
  12500. return
  12501. }
  12502. service.CreateHisPrescriptionProjectTemplate(&p)
  12503. }
  12504. }
  12505. }
  12506. }
  12507. c.ServeSuccessJSON(map[string]interface{}{
  12508. "msg": "创建成功",
  12509. })
  12510. }
  12511. }
  12512. } else {
  12513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12514. return
  12515. }
  12516. }
  12517. }
  12518. func (c *HisApiController) PreSettle() {
  12519. id, _ := c.GetInt64("id")
  12520. record_time := c.GetString("record_time")
  12521. his_patient_id, _ := c.GetInt64("his_patient_id")
  12522. timeLayout := "2006-01-02"
  12523. loc, _ := time.LoadLocation("Local")
  12524. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12525. diagnosis_id := c.GetString("diagnosis")
  12526. sick_type, _ := c.GetInt64("sick_type")
  12527. reg_type, _ := c.GetInt64("p_type")
  12528. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12529. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12530. if err != nil {
  12531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12532. return
  12533. }
  12534. recordDateTime := theTime.Unix()
  12535. adminUser := c.GetAdminUserInfo()
  12536. var prescriptions []*models.HisPrescription
  12537. var start_time int64
  12538. var end_time int64
  12539. ids_str := c.GetString("ids")
  12540. ids_arr := strings.Split(ids_str, ",")
  12541. fmt.Println(reg_type)
  12542. if settle_accounts_type == 1 { //日结
  12543. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12544. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12545. } else {
  12546. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12547. }
  12548. fmt.Println(prescriptions)
  12549. } else { //月结
  12550. start_time_str := c.GetString("start_time")
  12551. end_time_str := c.GetString("end_time")
  12552. timeLayout := "2006-01-02"
  12553. loc, _ := time.LoadLocation("Local")
  12554. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12555. if err != nil {
  12556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12557. return
  12558. }
  12559. recordStartTime := theStartTime.Unix()
  12560. start_time = recordStartTime
  12561. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12562. if err != nil {
  12563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12564. return
  12565. }
  12566. recordEndTime := theEndTime.Unix()
  12567. end_time = recordEndTime
  12568. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12569. }
  12570. if reg_type == 1111 || reg_type == 1112 {
  12571. reg_type = 11
  12572. }
  12573. timestamp := time.Now().Unix()
  12574. tempTime := time.Unix(timestamp, 0)
  12575. timeFormat := tempTime.Format("20060102150405")
  12576. chrgBchno := rand.Intn(100000) + 10000
  12577. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12578. strconv.FormatInt(his.PatientId, 10)
  12579. var ids []int64
  12580. for _, item := range prescriptions {
  12581. ids = append(ids, item.ID)
  12582. }
  12583. fmt.Println(ids)
  12584. var total float64
  12585. for _, item := range prescriptions {
  12586. fmt.Println(item)
  12587. if item.Type == 1 { //药品
  12588. for _, subItem := range item.HisDoctorAdviceInfo {
  12589. total = total + (subItem.Price * subItem.PrescribingNumber)
  12590. }
  12591. }
  12592. if item.Type == 2 { //项目
  12593. for _, subItem := range item.HisPrescriptionProject {
  12594. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12595. total = total + (subItem.Price * cnt)
  12596. }
  12597. }
  12598. for _, subItem := range item.HisAdditionalCharge {
  12599. total = total + (subItem.Price * float64(subItem.Count))
  12600. }
  12601. }
  12602. allTotal := fmt.Sprintf("%.2f", total)
  12603. totals, _ := strconv.ParseFloat(allTotal, 64)
  12604. order := &models.HisOrder{
  12605. UserOrgId: adminUser.CurrentOrgId,
  12606. HisPatientId: his.ID,
  12607. PatientId: id,
  12608. SettleAccountsDate: recordDateTime,
  12609. Ctime: time.Now().Unix(),
  12610. Mtime: time.Now().Unix(),
  12611. Status: 1,
  12612. OrderStatus: 1,
  12613. MdtrtId: his.Number,
  12614. Number: chrg_bchno,
  12615. MedfeeSumamt: totals,
  12616. SettleEndTime: end_time,
  12617. SettleStartTime: start_time,
  12618. SettleType: settle_accounts_type,
  12619. PsnPartAmt: totals,
  12620. PsnCashPay: totals,
  12621. PType: 2,
  12622. IsPre: 1,
  12623. MedType: strconv.Itoa(int(reg_type)),
  12624. Diagnosis: diagnosis_id,
  12625. }
  12626. err = service.CreateOrder(order)
  12627. if err != nil {
  12628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12629. return
  12630. }
  12631. var customs []*Custom
  12632. for _, item := range prescriptions {
  12633. fmt.Println(item.Type)
  12634. if item.Type == 1 { //药品
  12635. for _, subItem := range item.HisDoctorAdviceInfo {
  12636. cus := &Custom{
  12637. AdviceId: subItem.ID,
  12638. ProjectId: 0,
  12639. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12640. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12641. FeedetlSn: subItem.FeedetlSn,
  12642. Price: fmt.Sprintf("%.2f", subItem.Price),
  12643. MedListCodg: subItem.MedListCodg,
  12644. Type: 1,
  12645. }
  12646. customs = append(customs, cus)
  12647. }
  12648. }
  12649. if item.Type == 2 { //项目
  12650. for _, subItem := range item.HisPrescriptionProject {
  12651. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12652. cus := &Custom{
  12653. AdviceId: 0,
  12654. ProjectId: subItem.ID,
  12655. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12656. Cut: fmt.Sprintf("%.2f", cnt),
  12657. FeedetlSn: subItem.FeedetlSn,
  12658. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12659. MedListCodg: subItem.MedListCodg,
  12660. Type: 2,
  12661. }
  12662. customs = append(customs, cus)
  12663. }
  12664. }
  12665. for _, item := range item.HisAdditionalCharge {
  12666. cus := &Custom{
  12667. ItemId: item.ID,
  12668. AdviceId: 0,
  12669. ProjectId: 0,
  12670. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12671. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12672. FeedetlSn: item.FeedetlSn,
  12673. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12674. MedListCodg: item.XtHisAddtionConfig.Code,
  12675. Type: 3,
  12676. }
  12677. customs = append(customs, cus)
  12678. }
  12679. }
  12680. fmt.Println(customs)
  12681. for _, item := range customs {
  12682. var advice_id int64 = 0
  12683. var project_id int64 = 0
  12684. var item_id int64 = 0
  12685. var types int64 = 0
  12686. if item.Type == 1 {
  12687. advice_id = item.AdviceId
  12688. project_id = 0
  12689. item_id = 0
  12690. } else if item.Type == 2 {
  12691. advice_id = 0
  12692. item_id = 0
  12693. project_id = item.ProjectId
  12694. } else if item.Type == 3 {
  12695. advice_id = 0
  12696. item_id = item.ItemId
  12697. project_id = 0
  12698. }
  12699. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12700. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12701. pric, _ := strconv.ParseFloat(item.Price, 32)
  12702. info := &models.HisOrderInfo{
  12703. OrderNumber: order.Number,
  12704. UploadDate: time.Now().Unix(),
  12705. AdviceId: advice_id,
  12706. DetItemFeeSumamt: detItemFeeSumamt,
  12707. Cnt: cut,
  12708. Pric: pric,
  12709. PatientId: id,
  12710. Status: 1,
  12711. Mtime: time.Now().Unix(),
  12712. Ctime: time.Now().Unix(),
  12713. UserOrgId: adminUser.CurrentOrgId,
  12714. HisPatientId: his.ID,
  12715. OrderId: order.ID,
  12716. ProjectId: project_id,
  12717. Type: types,
  12718. ItemId: item_id,
  12719. }
  12720. service.CreateOrderInfo(info)
  12721. }
  12722. his.SickType = sick_type
  12723. service.UpdataHisPateint(&his)
  12724. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12725. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12726. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12727. if err == nil {
  12728. c.ServeSuccessJSON(map[string]interface{}{
  12729. "msg": "结算成功",
  12730. })
  12731. }
  12732. }
  12733. type CustomOrderInfo struct {
  12734. Name string
  12735. Spec string
  12736. Unit string
  12737. Count float64
  12738. Price float64
  12739. Total float64
  12740. }
  12741. func (c *HisApiController) GetPrivateExpensesInfo() {
  12742. order_id, _ := c.GetInt64("id", 0)
  12743. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12744. order, _ := service.GetHisOrderByID(order_id)
  12745. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12746. if order.ID == 0 {
  12747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12748. return
  12749. }
  12750. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12751. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12752. org_id := c.GetAdminUserInfo().CurrentOrgId
  12753. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12754. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12755. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12756. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12757. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12758. //var orderInfos_four []*models.HisOrderInfoTwo
  12759. //for _, item := range orderInfos_three {
  12760. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12761. // item.HisPrescriptionProject.IsCheckTeam = 1
  12762. // orderInfos_four = append(orderInfos_four, item)
  12763. //
  12764. // }
  12765. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12766. // item.HisPrescriptionProject.IsCheckTeam = 2
  12767. // orderInfos_two = append(orderInfos_two, item)
  12768. // }
  12769. //}
  12770. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12771. //var cus_slice []CustomOrderInfo
  12772. //for _, item := range new_order_info {
  12773. // var cus CustomOrderInfo
  12774. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12775. // cus.Unit = ""
  12776. // cus.Spec = ""
  12777. // var total float64
  12778. // for _, subItem := range orderInfos_four {
  12779. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12780. // total = total + subItem.DetItemFeeSumamt
  12781. // fmt.Println(subItem.DetItemFeeSumamt)
  12782. // }
  12783. // }
  12784. // cus.Count = 1
  12785. // cus.Total = total
  12786. // cus_slice = append(cus_slice, cus)
  12787. //}
  12788. orderInfos = append(orderInfos, orderInfos_two...)
  12789. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12790. //orderInfos = append(orderInfos, orderInfos_three...)
  12791. //}/**/
  12792. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12793. c.ServeSuccessJSON(map[string]interface{}{
  12794. "order": order,
  12795. "order_info": orderInfos,
  12796. "patient": patient,
  12797. "admin_info": adminInfo,
  12798. "his": his,
  12799. "current_admin": role,
  12800. "org_config": miConfig,
  12801. //"new_order_info": cus_slice,
  12802. })
  12803. }
  12804. func (this *HisApiController) ChangeMedType() {
  12805. med_type := this.GetString("med_type")
  12806. old_med_type := this.GetString("old_med_type")
  12807. ids := this.GetString("ids")
  12808. settle_type, _ := this.GetInt64("settle_type")
  12809. start_time := this.GetString("start_time")
  12810. end_time := this.GetString("end_time")
  12811. ids_arr := strings.Split(ids, ",")
  12812. if settle_type == 1 { //日结
  12813. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12814. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12815. prescription.MedType = med_type
  12816. err := service.SaveHisPrescriptionTwo(&prescription)
  12817. if err == nil {
  12818. this.ServeSuccessJSON(map[string]interface{}{
  12819. "msg": "修改成功",
  12820. })
  12821. } else {
  12822. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12823. return
  12824. }
  12825. } else if settle_type == 2 {
  12826. timeLayout := "2006-01-02"
  12827. loc, _ := time.LoadLocation("Local")
  12828. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12829. if err != nil {
  12830. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12831. return
  12832. }
  12833. recordStartTime := theStartTime.Unix()
  12834. start_time_timestamp := recordStartTime
  12835. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12836. if err != nil {
  12837. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12838. return
  12839. }
  12840. recordEndTime := theEndTime.Unix()
  12841. end_time_timestamp := recordEndTime
  12842. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12843. if updateErr == nil {
  12844. this.ServeSuccessJSON(map[string]interface{}{
  12845. "msg": "修改成功",
  12846. })
  12847. } else {
  12848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12849. return
  12850. }
  12851. }
  12852. }
  12853. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12854. patient_id, _ := c.GetInt64("patient_id")
  12855. his_patient_id, _ := c.GetInt64("his_patient_id")
  12856. record_date := c.GetString("record_date")
  12857. start_time := c.GetString("start_time")
  12858. end_time := c.GetString("end_time")
  12859. order_status, _ := c.GetInt64("type", 0)
  12860. p_type, _ := c.GetInt64("p_type", 0)
  12861. order_id, _ := c.GetInt64("order_id", 0)
  12862. timeLayout := "2006-01-02"
  12863. loc, _ := time.LoadLocation("Local")
  12864. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12865. if err != nil {
  12866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12867. return
  12868. }
  12869. recordDateTime := theTime.Unix()
  12870. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12871. if err != nil {
  12872. }
  12873. startRecordDateTime := startTime.Unix()
  12874. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12875. if err != nil {
  12876. }
  12877. endRecordDateTime := endTime.Unix()
  12878. admin := c.GetAdminUserInfo()
  12879. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12880. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12881. order, _ := service.GetHisOrderByID(order_id)
  12882. var monthPrescriptions []*models.HisPrescription
  12883. if order_status == 1 || order_status == 0 {
  12884. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12885. } else if order_status == 2 {
  12886. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12887. }
  12888. var settle_total float64
  12889. for _, item := range monthPrescriptions {
  12890. if len(item.HisPrescriptionProject) > 0 {
  12891. for _, subItem := range item.HisPrescriptionProject {
  12892. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12893. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12894. settle_total = settle_total + total
  12895. }
  12896. }
  12897. if len(item.HisDoctorAdviceInfo) > 0 {
  12898. for _, subItem := range item.HisDoctorAdviceInfo {
  12899. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12900. settle_total = settle_total + total
  12901. }
  12902. }
  12903. }
  12904. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12905. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12906. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12907. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12908. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12909. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12910. //获取所有科室信息
  12911. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12912. var dia string
  12913. for _, item := range month_p_info {
  12914. if len(dia) == 0 {
  12915. dia = item.Diagnosis
  12916. } else {
  12917. dia = dia + "," + item.Diagnosis
  12918. }
  12919. }
  12920. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12921. dia_arr = removeEmptyStrings(dia_arr)
  12922. c.ServeSuccessJSON(map[string]interface{}{
  12923. "his_info": his_patient_info,
  12924. "xt_info": xt_patient_info,
  12925. "case_history": case_history,
  12926. "info": patientPrescriptionInfo,
  12927. "last_info": lastPatientPrescriptionInfo,
  12928. "month_prescriptions": monthPrescriptions,
  12929. "order": order,
  12930. "doctors": doctors,
  12931. "department": department,
  12932. "settle_total": settle_total,
  12933. "dia_arr": dia_arr,
  12934. })
  12935. return
  12936. }
  12937. func removeEmptyStrings(input []string) []string {
  12938. var output []string
  12939. for _, s := range input {
  12940. if s != "" {
  12941. output = append(output, s)
  12942. }
  12943. }
  12944. return output
  12945. }
  12946. func removeDuplicates(input []string) []string {
  12947. seen := make(map[string]bool)
  12948. output := []string{}
  12949. for _, s := range input {
  12950. if _, exists := seen[s]; !exists {
  12951. seen[s] = true
  12952. output = append(output, s)
  12953. }
  12954. }
  12955. return output
  12956. }
  12957. func (c *HisApiController) GetHisMonthPatientInfo() {
  12958. patient_id, _ := c.GetInt64("patient_id")
  12959. his_patient_id, _ := c.GetInt64("his_patient_id")
  12960. record_date := c.GetString("record_date")
  12961. number := c.GetString("number")
  12962. start_time := c.GetString("start_time")
  12963. end_time := c.GetString("end_time")
  12964. p_type, _ := c.GetInt64("p_type")
  12965. timeLayout := "2006-01-02"
  12966. loc, _ := time.LoadLocation("Local")
  12967. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12968. if err != nil {
  12969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12970. return
  12971. }
  12972. recordDateTime := theTime.Unix()
  12973. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12974. if err != nil {
  12975. }
  12976. startRecordDateTime := startTime.Unix()
  12977. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12978. if err != nil {
  12979. }
  12980. endRecordDateTime := endTime.Unix()
  12981. admin := c.GetAdminUserInfo()
  12982. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12983. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12984. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12985. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12986. var settle_total float64
  12987. for _, item := range monthPrescriptions {
  12988. if len(item.HisPrescriptionProject) > 0 {
  12989. for _, subItem := range item.HisPrescriptionProject {
  12990. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12991. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12992. settle_total = settle_total + total
  12993. }
  12994. }
  12995. if len(item.HisDoctorAdviceInfo) > 0 {
  12996. for _, subItem := range item.HisDoctorAdviceInfo {
  12997. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12998. settle_total = settle_total + total
  12999. }
  13000. }
  13001. }
  13002. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13003. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13004. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13005. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13006. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13007. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13008. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13009. //获取所有科室信息
  13010. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13011. c.ServeSuccessJSON(map[string]interface{}{
  13012. "his_info": his_patient_info,
  13013. "xt_info": xt_patient_info,
  13014. "case_history": case_history,
  13015. "info": patientPrescriptionInfo,
  13016. "month_prescriptions": monthPrescriptions,
  13017. "order": order,
  13018. "doctors": doctors,
  13019. "department": department,
  13020. "count": count,
  13021. "drugStockConfig": drugStockConfig,
  13022. "last_info": lastPatientPrescriptionInfo,
  13023. "settle_total": settle_total,
  13024. })
  13025. return
  13026. }
  13027. func (c *HisApiController) GetAllOrder() {
  13028. org_id := c.GetAdminUserInfo().CurrentOrgId
  13029. orders, _ := service.GetNewHisOrderList(org_id)
  13030. c.ServeSuccessJSON(map[string]interface{}{
  13031. "order": orders,
  13032. })
  13033. return
  13034. }
  13035. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13036. newArr = make([]*models.HisOrderInfoTwo, 0)
  13037. for i := 0; i < len(arr); i++ {
  13038. repeat := false
  13039. for j := i + 1; j < len(arr); j++ {
  13040. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13041. repeat = true
  13042. break
  13043. }
  13044. }
  13045. if !repeat {
  13046. newArr = append(newArr, arr[i])
  13047. }
  13048. }
  13049. return
  13050. }
  13051. // 修改处方退库操作 参数传修改之前的处方数据
  13052. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13053. if advice.ExecutionState == 1 {
  13054. //查询该病人该药品是否有库存记录
  13055. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13056. if errcode == gorm.ErrRecordNotFound {
  13057. } else {
  13058. //退库
  13059. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13060. if advice.PrescribingNumberUnit == drug.MinUnit {
  13061. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13062. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13063. //退库
  13064. warehouseInfo := models.DrugWarehouseInfo{
  13065. StockMinNumber: prescribingNumber,
  13066. }
  13067. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13068. operation_time := time.Now().Unix()
  13069. creater := advice.AdviceDoctor
  13070. ctime := time.Now().Unix()
  13071. timeStr := time.Now().Format("2006-01-02")
  13072. timeArr := strings.Split(timeStr, "-")
  13073. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13074. total = total + 1
  13075. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13076. cancelStock := models.DrugCancelStock{
  13077. OrderNumber: orderNumber,
  13078. OperaTime: operation_time,
  13079. OrgId: advice.UserOrgId,
  13080. Creater: creater,
  13081. Ctime: ctime,
  13082. Status: 1,
  13083. ReturnTime: advice.AdviceDate,
  13084. Dealer: info.Dealer,
  13085. Manufacturer: info.Manufacturer,
  13086. Type: 1,
  13087. }
  13088. service.AddSigleDrugCancelStock(&cancelStock)
  13089. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13090. dealer, _ := service.GetDealerById(info.Dealer)
  13091. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13092. cancelStockInfo := models.DrugCancelStockInfo{
  13093. OrderNumber: cancelInfo.OrderNumber,
  13094. CancelStockId: cancelInfo.ID,
  13095. DrugId: info.DrugId,
  13096. Count: info.Count,
  13097. Status: 1,
  13098. Ctime: ctime,
  13099. OrgId: advice.UserOrgId,
  13100. Type: 1,
  13101. Manufacturer: manufactureName.ManufacturerName,
  13102. Dealer: dealer.DealerName,
  13103. Total: 0,
  13104. RetailPrice: info.RetailPrice,
  13105. RetailTotalPrice: info.RetailTotalPrice,
  13106. Price: info.Price,
  13107. RegisterAccount: "",
  13108. Remark: info.Remark,
  13109. BatchNumber: info.BatchNumber,
  13110. MaxUnit: info.CountUnit,
  13111. ProductDate: info.ProductDate,
  13112. ExpiryDate: info.ExpiryDate,
  13113. BatchNumberId: info.WarehouseInfoId,
  13114. }
  13115. flow := models.DrugFlow{
  13116. WarehousingId: 0,
  13117. DrugId: info.DrugId,
  13118. Number: "",
  13119. BatchNumber: info.BatchNumber,
  13120. Count: info.Count,
  13121. UserOrgId: advice.UserOrgId,
  13122. PatientId: 0,
  13123. SystemTime: ctime,
  13124. ConsumableType: 4,
  13125. IsSys: 0,
  13126. WarehousingOrder: "",
  13127. WarehouseOutId: 0,
  13128. WarehouseOutOrderNumber: "",
  13129. IsEdit: 0,
  13130. CancelStockId: cancelStock.ID,
  13131. CancelOrderNumber: cancelStock.OrderNumber,
  13132. Manufacturer: info.Manufacturer,
  13133. Dealer: info.Dealer,
  13134. Creator: advice.UserOrgId,
  13135. UpdateCreator: 0,
  13136. Status: 1,
  13137. Ctime: time.Now().Unix(),
  13138. Mtime: 0,
  13139. Price: info.Price,
  13140. WarehousingDetailId: 0,
  13141. WarehouseOutDetailId: 0,
  13142. CancelOutDetailId: 0,
  13143. ExpireDate: info.ExpiryDate,
  13144. ProductDate: info.ProductDate,
  13145. MaxUnit: info.CountUnit,
  13146. MinUnit: "",
  13147. }
  13148. service.CreatedCancelStock(cancelStockInfo)
  13149. service.CreateDrugFlowOne(flow)
  13150. } else {
  13151. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13152. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13153. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13154. warehouseInfo := models.DrugWarehouseInfo{
  13155. StockMinNumber: prescribingNumber,
  13156. }
  13157. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13158. }
  13159. operation_time := time.Now().Unix()
  13160. creater := advice.AdviceDoctor
  13161. ctime := time.Now().Unix()
  13162. timeStr := time.Now().Format("2006-01-02")
  13163. timeArr := strings.Split(timeStr, "-")
  13164. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13165. total = total + 1
  13166. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13167. cancelStock := models.DrugCancelStock{
  13168. OrderNumber: orderNumber,
  13169. OperaTime: operation_time,
  13170. OrgId: advice.UserOrgId,
  13171. Creater: creater,
  13172. Ctime: ctime,
  13173. Status: 1,
  13174. ReturnTime: advice.AdviceDate,
  13175. Dealer: info.Dealer,
  13176. Manufacturer: info.Manufacturer,
  13177. Type: 1,
  13178. }
  13179. service.AddSigleDrugCancelStock(&cancelStock)
  13180. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13181. dealer, _ := service.GetDealerById(info.Dealer)
  13182. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13183. cancelStockInfo := models.DrugCancelStockInfo{
  13184. OrderNumber: cancelInfo.OrderNumber,
  13185. CancelStockId: cancelInfo.ID,
  13186. DrugId: info.DrugId,
  13187. Count: info.Count,
  13188. Status: 1,
  13189. Ctime: ctime,
  13190. OrgId: advice.UserOrgId,
  13191. Type: 1,
  13192. Manufacturer: manufactureName.ManufacturerName,
  13193. Dealer: dealer.DealerName,
  13194. Total: 0,
  13195. RetailPrice: info.RetailPrice,
  13196. RetailTotalPrice: info.RetailTotalPrice,
  13197. Price: info.Price,
  13198. RegisterAccount: "",
  13199. Remark: info.Remark,
  13200. BatchNumber: info.BatchNumber,
  13201. MaxUnit: info.CountUnit,
  13202. ProductDate: info.ProductDate,
  13203. ExpiryDate: info.ExpiryDate,
  13204. BatchNumberId: info.WarehouseInfoId,
  13205. }
  13206. flow := models.DrugFlow{
  13207. WarehousingId: 0,
  13208. DrugId: info.DrugId,
  13209. Number: "",
  13210. BatchNumber: info.BatchNumber,
  13211. Count: info.Count,
  13212. UserOrgId: advice.UserOrgId,
  13213. PatientId: 0,
  13214. SystemTime: ctime,
  13215. ConsumableType: 4,
  13216. IsSys: 0,
  13217. WarehousingOrder: "",
  13218. WarehouseOutId: 0,
  13219. WarehouseOutOrderNumber: "",
  13220. IsEdit: 0,
  13221. CancelStockId: cancelStock.ID,
  13222. CancelOrderNumber: cancelStock.OrderNumber,
  13223. Manufacturer: info.Manufacturer,
  13224. Dealer: info.Dealer,
  13225. Creator: advice.AdviceDoctor,
  13226. UpdateCreator: 0,
  13227. Status: 1,
  13228. Ctime: time.Now().Unix(),
  13229. Mtime: 0,
  13230. Price: info.Price,
  13231. WarehousingDetailId: 0,
  13232. WarehouseOutDetailId: 0,
  13233. CancelOutDetailId: 0,
  13234. ExpireDate: info.ExpiryDate,
  13235. ProductDate: info.ProductDate,
  13236. MaxUnit: info.CountUnit,
  13237. MinUnit: "",
  13238. }
  13239. service.CreatedCancelStock(cancelStockInfo)
  13240. service.CreateDrugFlowOne(flow)
  13241. }
  13242. }
  13243. }
  13244. return err
  13245. }
  13246. func (this *HisApiController) DeleteNCDS() {
  13247. id, _ := this.GetInt64("id", 0)
  13248. if id > 0 {
  13249. service.DeletePsnNCDSRecordById(id)
  13250. this.ServeSuccessJSON(map[string]interface{}{
  13251. "msg": "删除成功",
  13252. })
  13253. } else {
  13254. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13255. return
  13256. }
  13257. }
  13258. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13259. id, _ := c.GetInt64("id")
  13260. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13261. c.ServeSuccessJSON(map[string]interface{}{
  13262. "advice": advice,
  13263. })
  13264. return
  13265. }
  13266. func (c *HisApiController) GetHisMonthChargePatientList() {
  13267. record_date := c.GetString("record_date")
  13268. start_time := c.GetString("start_time")
  13269. end_time := c.GetString("end_time")
  13270. timeLayout := "2006-01-02"
  13271. loc, _ := time.LoadLocation("Local")
  13272. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13273. if err != nil {
  13274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13275. return
  13276. }
  13277. if err != nil {
  13278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13279. return
  13280. }
  13281. recordDateTime := theTime.Unix()
  13282. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13283. if err != nil {
  13284. }
  13285. startRecordDateTime := startTime.Unix()
  13286. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13287. if err != nil {
  13288. }
  13289. endRecordDateTime := endTime.Unix()
  13290. adminInfo := c.GetAdminUserInfo()
  13291. var tempMonthChargePatients []*service.MonthChargePatients
  13292. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13293. for _, item := range tempPatients {
  13294. //过滤没有处方的
  13295. if len(item.HisPrescription) == 0 {
  13296. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13297. }
  13298. }
  13299. c.ServeSuccessJSON(map[string]interface{}{
  13300. "list": tempMonthChargePatients,
  13301. })
  13302. }
  13303. // PrescriptionDifference 医嘱数量差值结构体
  13304. type PrescriptionDrugDifference struct {
  13305. DrugID int64 //基础库药品id
  13306. ID int64 //医嘱id
  13307. Difference float64 //差值
  13308. Unit string //单位
  13309. }
  13310. type PrescriptionGoodDifference struct {
  13311. GoodID int64 //基础库项目耗材id
  13312. ID int64 //医嘱id
  13313. Difference int64 //差值
  13314. Unit string //单位
  13315. Type int64 //类型
  13316. }
  13317. type EditCustomData struct {
  13318. adviceList []*models.HisDoctorAdviceInfo
  13319. projectList []*models.HisPrescriptionProject
  13320. }
  13321. type SrcCustomData struct {
  13322. adviceList []*models.HisDoctorAdviceInfo
  13323. projectList []*models.HisPrescriptionProject
  13324. }
  13325. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13326. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13327. differences := make([]*PrescriptionDrugDifference, 0)
  13328. // 创建一个 map 来存储第一个切片中的药品信息
  13329. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13330. for _, advice := range firstPrescription {
  13331. firstMap[advice.DrugId] = advice
  13332. }
  13333. // 遍历第二个切片中的药品信息,并比较数量差值
  13334. for _, advice := range secondPrescription {
  13335. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13336. diff := &PrescriptionDrugDifference{
  13337. DrugID: advice.DrugId,
  13338. ID: firstAdvice.ID,
  13339. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13340. Unit: firstAdvice.PrescribingNumberUnit,
  13341. }
  13342. differences = append(differences, diff)
  13343. }
  13344. }
  13345. return differences
  13346. }
  13347. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13348. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13349. differences := make([]*PrescriptionGoodDifference, 0)
  13350. // 创建一个 map 来存储第一个切片中的耗材信息
  13351. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13352. for _, good := range firstPrescription {
  13353. firstMap[good.ProjectId] = good
  13354. }
  13355. // 遍历第二个切片中的耗材信息,并比较数量差值
  13356. for _, good := range secondPrescription {
  13357. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13358. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13359. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13360. diff := &PrescriptionGoodDifference{
  13361. GoodID: good.ProjectId,
  13362. ID: firstGood.ID,
  13363. Difference: count - firstCount,
  13364. Unit: firstGood.Unit,
  13365. Type: firstGood.Type,
  13366. }
  13367. differences = append(differences, diff)
  13368. }
  13369. }
  13370. return differences
  13371. }
  13372. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13373. var adviceList []*models.HisDoctorAdviceInfo
  13374. var projectList []*models.HisPrescriptionProject
  13375. var advice_ids []int64
  13376. var project_ids []int64
  13377. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13378. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13379. //var tempPrescription *models.HisPrescriptionProjectscription
  13380. if len(prescriptions) > 0 {
  13381. for _, item := range prescriptions {
  13382. items := item.(map[string]interface{})
  13383. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13384. advices := items["advices"].([]interface{})
  13385. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13386. groupNo := int64(0)
  13387. ctime := time.Now().Unix()
  13388. mtime := ctime
  13389. if len(advices) > 0 {
  13390. for _, advice := range advices {
  13391. var s models.HisDoctorAdviceInfo
  13392. s.AdviceType = 2
  13393. s.StopState = 2
  13394. s.ExecutionState = 2
  13395. s.Status = 1
  13396. s.Groupno = groupNo
  13397. s.CreatedTime = ctime
  13398. s.UpdatedTime = mtime
  13399. s.IsSettle = 2
  13400. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13401. //存储切片中
  13402. if s.ID > 0 {
  13403. advice_ids = append(advice_ids, s.ID)
  13404. adviceList = append(adviceList, &s)
  13405. }
  13406. }
  13407. }
  13408. }
  13409. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13410. projects := items["project"].([]interface{})
  13411. if len(projects) > 0 {
  13412. for _, project := range projects {
  13413. var p models.HisPrescriptionProject
  13414. p.Ctime = time.Now().Unix()
  13415. p.Mtime = time.Now().Unix()
  13416. p.Status = 1
  13417. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13418. if p.ID > 0 {
  13419. project_ids = append(project_ids, p.ID)
  13420. projectList = append(projectList, &p)
  13421. }
  13422. }
  13423. }
  13424. }
  13425. }
  13426. }
  13427. }
  13428. editCustomData.projectList = projectList
  13429. editCustomData.adviceList = adviceList
  13430. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13431. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13432. srcCustomData.adviceList = list
  13433. srcCustomData.projectList = list2
  13434. return
  13435. }
  13436. func (c *HisApiController) GetAllGoodInforList() {
  13437. orgId := c.GetAdminUserInfo().CurrentOrgId
  13438. goodList, _ := service.GetAllGoodList(orgId)
  13439. c.ServeSuccessJSON(map[string]interface{}{
  13440. "goodList": goodList,
  13441. })
  13442. return
  13443. }
  13444. func (this *HisApiController) SaveGoodList() {
  13445. project_name := this.GetString("project_name")
  13446. sort, _ := this.GetInt64("sort")
  13447. orgId := this.GetAdminUserInfo().CurrentOrgId
  13448. dataBody := make(map[string]interface{}, 0)
  13449. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13450. if err != nil {
  13451. utils.ErrorLog(err.Error())
  13452. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13453. return
  13454. }
  13455. goodTeam := models.XtGoodTeam{
  13456. ProjectName: project_name,
  13457. Sort: sort,
  13458. UserOrgId: orgId,
  13459. Status: 1,
  13460. Ctime: time.Now().Unix(),
  13461. Mtime: time.Now().Unix(),
  13462. }
  13463. service.CreateGoodTeam(goodTeam)
  13464. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13465. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13466. infos, _ := dataBody["info"].([]interface{})
  13467. if len(infos) > 0 {
  13468. for _, item := range infos {
  13469. items := item.(map[string]interface{})
  13470. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13471. utils.ErrorLog("good_id")
  13472. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13473. return
  13474. }
  13475. good_id := int64(items["good_id"].(float64))
  13476. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13477. utils.ErrorLog("number")
  13478. }
  13479. number := int64(items["number"].(float64))
  13480. xtGoodTeamList := models.XtGoodTeamList{
  13481. GoodId: good_id,
  13482. Count: number,
  13483. TeamId: lastGoodTeam.ID,
  13484. UserOrgId: orgId,
  13485. Status: 1,
  13486. Ctime: time.Now().Unix(),
  13487. Mtime: time.Now().Unix(),
  13488. }
  13489. service.CreateGoodList(xtGoodTeamList)
  13490. }
  13491. this.ServeSuccessJSON(map[string]interface{}{
  13492. "lastGoodTeam": lastGoodTeam,
  13493. })
  13494. }
  13495. }
  13496. return
  13497. }
  13498. func (this *HisApiController) GetGoodList() {
  13499. orgId := this.GetAdminUserInfo().CurrentOrgId
  13500. limit, _ := this.GetInt64("limit")
  13501. page, _ := this.GetInt64("page")
  13502. keyword := this.GetString("keyword")
  13503. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13504. this.ServeSuccessJSON(map[string]interface{}{
  13505. "list": list,
  13506. "total": total,
  13507. })
  13508. }
  13509. func (this *HisApiController) GetGoodNameDetail() {
  13510. id, _ := this.GetInt64("id")
  13511. orgId := this.GetAdminUserInfo().CurrentOrgId
  13512. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13513. goodList, _ := service.GetAllGoodList(orgId)
  13514. this.ServeSuccessJSON(map[string]interface{}{
  13515. "goodNameDetail": goodNameDetail,
  13516. "goodList": goodList,
  13517. })
  13518. }
  13519. func (this *HisApiController) UpdateGoodList() {
  13520. project_name := this.GetString("project_name")
  13521. sort, _ := this.GetInt64("sort")
  13522. id, _ := this.GetInt64("id")
  13523. orgId := this.GetAdminUserInfo().CurrentOrgId
  13524. dataBody := make(map[string]interface{}, 0)
  13525. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13526. if err != nil {
  13527. utils.ErrorLog(err.Error())
  13528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13529. return
  13530. }
  13531. goodTeam := models.XtGoodTeam{
  13532. ProjectName: project_name,
  13533. Sort: sort,
  13534. UserOrgId: orgId,
  13535. Status: 1,
  13536. Ctime: time.Now().Unix(),
  13537. Mtime: time.Now().Unix(),
  13538. ID: id,
  13539. }
  13540. service.SaveGoodTeam(goodTeam)
  13541. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13542. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13543. infos, _ := dataBody["info"].([]interface{})
  13544. if len(infos) > 0 {
  13545. for _, item := range infos {
  13546. items := item.(map[string]interface{})
  13547. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13548. utils.ErrorLog("good_id")
  13549. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13550. return
  13551. }
  13552. good_id := int64(items["good_id"].(float64))
  13553. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13554. utils.ErrorLog("id")
  13555. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13556. return
  13557. }
  13558. id := int64(items["id"].(float64))
  13559. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13560. utils.ErrorLog("number")
  13561. }
  13562. number := int64(items["number"].(float64))
  13563. xtGoodTeamList := models.XtGoodTeamList{
  13564. ID: id,
  13565. GoodId: good_id,
  13566. Count: number,
  13567. TeamId: lastGoodTeam.ID,
  13568. UserOrgId: orgId,
  13569. Status: 1,
  13570. Ctime: time.Now().Unix(),
  13571. Mtime: time.Now().Unix(),
  13572. }
  13573. service.SaveGoodList(xtGoodTeamList)
  13574. }
  13575. this.ServeSuccessJSON(map[string]interface{}{
  13576. "lastGoodTeam": lastGoodTeam,
  13577. })
  13578. }
  13579. }
  13580. return
  13581. }
  13582. func (this *HisApiController) DeleteGoodTeam() {
  13583. id, _ := this.GetInt64("id")
  13584. team, _ := service.DeleteGoodTeam(id)
  13585. this.ServeSuccessJSON(map[string]interface{}{
  13586. "team": team,
  13587. })
  13588. }
  13589. func (this *HisApiController) DeleteGood() {
  13590. id, _ := this.GetInt64("id")
  13591. good, _ := service.DeleteGood(id)
  13592. this.ServeSuccessJSON(map[string]interface{}{
  13593. "good": good,
  13594. })
  13595. }