his_api_controller.go 544KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981
  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. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. //if number >= 1000 {
  187. // zero = "0000" + strconv.FormatInt(number, 10)
  188. //} else if number >= 10000 {
  189. // zero = "000" + strconv.FormatInt(number, 10)
  190. //} else if number >= 100000 {
  191. // zero = "00" + strconv.FormatInt(number, 10)
  192. //} else if number >= 1000000 {
  193. // zero = "0" + strconv.FormatInt(number, 10)
  194. //} else {
  195. zero = "0" + strconv.FormatInt(number, 10)
  196. //}
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. if order.IsMedicineInsurance != 1 {
  1021. order.PsnCashPay = order.MedfeeSumamt
  1022. }
  1023. for _, item := range orderInfos {
  1024. if item.MedChrgitmType == "01" { //床位费
  1025. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1026. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1027. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1028. }
  1029. if item.MedChrgitmType == "02" { //诊察费
  1030. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1031. //zhenChaCostSelfTotal = zhenChaCostTotal
  1032. }
  1033. if item.MedChrgitmType == "03" { //检查费
  1034. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1035. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1036. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1037. }
  1038. if item.MedChrgitmType == "02" { //检查费
  1039. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1040. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1041. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1042. }
  1043. if item.MedChrgitmType == "04" { //化验费
  1044. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1045. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1046. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1047. }
  1048. if item.MedChrgitmType == "05" { //治疗费
  1049. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1050. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1051. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1052. }
  1053. if item.MedChrgitmType == "06" { //手术费
  1054. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1055. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1056. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1057. }
  1058. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1059. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1060. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1061. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1062. }
  1063. if item.MedChrgitmType == "09" { //西药费
  1064. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1065. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1066. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1067. }
  1068. if item.MedChrgitmType == "11" { //中成费
  1069. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1070. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1071. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1072. }
  1073. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1074. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1075. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1076. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1077. }
  1078. }
  1079. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1080. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1081. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1082. var dia_config []*models.HisXtDiagnoseConfig
  1083. var diagnosis_ids []string
  1084. if his.ID > 0 {
  1085. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1086. } else {
  1087. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1088. }
  1089. for _, item := range diagnosis_ids {
  1090. id, _ := strconv.ParseInt(item, 10, 64)
  1091. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1092. dia_config = append(dia_config, diagnosisConfig)
  1093. }
  1094. var rf []CustomFundPay
  1095. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1096. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1097. c.ServeSuccessJSON(map[string]interface{}{
  1098. "patient": patient,
  1099. "order_infos": orderInfos,
  1100. "diagnosis": name,
  1101. "bedCostTotal": bedCostTotal,
  1102. "bedCostSelfTotal": bedCostTotal,
  1103. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1104. "operationCostTotal": operationCostTotal,
  1105. "operationCostSelfTotal": operationCostTotal,
  1106. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1107. "otherCostTotal": otherCostTotal,
  1108. "otherCostSelfTotal": otherCostTotal,
  1109. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1110. "materialCostTotal": materialCostTotal,
  1111. "materialCostSelfTotal": materialCostTotal,
  1112. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1113. "westernMedicineCostTotal": westernMedicineCostTotal,
  1114. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1116. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1117. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1119. "checkCostTotal": checkCostTotal,
  1120. "checkCostSelfTotal": checkCostTotal,
  1121. "zhenChaCostTotal": zhenChaCostTotal,
  1122. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1123. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1124. "laboratoryCostTotal": laboratoryCostTotal,
  1125. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1126. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1127. "treatCostTotal": treatCostTotal,
  1128. "treatCostSelfTotal": treatCostTotal,
  1129. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1130. "charge_admin": charge_admin,
  1131. "printor_admin": printor_admin,
  1132. "org_name": org.OrgName,
  1133. "org_code": miConfig.Code,
  1134. "name": patient.Name,
  1135. "number": order.MdtrtId,
  1136. "date": order.SettleAccountsDate,
  1137. "info": order,
  1138. "new_order": order,
  1139. "his_hospital": his_hospital,
  1140. "his": his,
  1141. "funds": rf,
  1142. "dia_config": dia_config,
  1143. })
  1144. }
  1145. func (c *HisApiController) RefudDetail() {
  1146. order_id, _ := c.GetInt64("order_id")
  1147. order, _ := service.GetHisOrderByID(order_id)
  1148. adminUser := c.GetAdminUserInfo()
  1149. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1150. c.ServeSuccessJSON(map[string]interface{}{
  1151. "msg": "撤销成功",
  1152. })
  1153. }
  1154. func (c *HisApiController) Sscard() {
  1155. //r := CardInit()
  1156. //if r == 0 {
  1157. // GetBaseInfo()
  1158. //}
  1159. //c.ServeSuccessJSON(map[string]interface{}{
  1160. // "list": "11",
  1161. //})
  1162. }
  1163. func GetBaseInfo() error {
  1164. //handle := syscall.MustLoadDLL("SSCard.dll")
  1165. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1166. //
  1167. //str := make([]byte, 256)
  1168. //str1 := make([]byte, 256)
  1169. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1170. //if ferr != nil {
  1171. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1172. // return ferr
  1173. //}
  1174. //
  1175. //fmt.Println(string(str))
  1176. //
  1177. //fmt.Println(r)
  1178. return nil
  1179. }
  1180. func CardInit() int {
  1181. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1182. //add := DllTestDef.MustFindProc("Init")
  1183. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1184. //if err != nil {
  1185. // fmt.Println("SSCard的运算结果为:", ret)
  1186. //}
  1187. //result := int(ret)
  1188. return 0
  1189. }
  1190. func IntPtr(n int) uintptr {
  1191. return uintptr(n)
  1192. }
  1193. func StrPtr(s string) uintptr {
  1194. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1195. }
  1196. func (c *HisApiController) GetHisPatientList() {
  1197. //types, _ := c.GetInt64("type", 0)
  1198. record_date := c.GetString("record_date")
  1199. sch_type, _ := c.GetInt64("sch_type")
  1200. timeLayout := "2006-01-02"
  1201. loc, _ := time.LoadLocation("Local")
  1202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1203. if err != nil {
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. recordDateTime := theTime.Unix()
  1208. adminInfo := c.GetAdminUserInfo()
  1209. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1210. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1211. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1212. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1213. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1214. //获取当前用户的信息
  1215. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1216. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1217. //获取所有科室信息
  1218. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1219. //var aa []service.PatientThree
  1220. noElementsSlice := make([]service.PatientThree, 0)
  1221. c.ServeSuccessJSON(map[string]interface{}{
  1222. "list": patients,
  1223. "list_two": patients_two,
  1224. "list_three": noElementsSlice,
  1225. "info": adminUserInfo,
  1226. "doctors": doctors,
  1227. "department": department,
  1228. })
  1229. }
  1230. type CustomTemplate struct {
  1231. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1232. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1233. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1234. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1235. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1236. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1237. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1238. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1239. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1240. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1241. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1242. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1243. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1244. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1245. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1246. }
  1247. func (c *HisApiController) GetHisPatientInfo() {
  1248. patient_id, _ := c.GetInt64("patient_id")
  1249. his_patient_id, _ := c.GetInt64("his_patient_id")
  1250. record_date := c.GetString("record_date")
  1251. number := c.GetString("number")
  1252. //start_time := c.GetString("start_time")
  1253. //end_time := c.GetString("end_time")
  1254. p_type, _ := c.GetInt64("p_type")
  1255. timeLayout := "2006-01-02"
  1256. loc, _ := time.LoadLocation("Local")
  1257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1258. if err != nil {
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1260. return
  1261. }
  1262. recordDateTime := theTime.Unix()
  1263. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1264. //if err != nil {
  1265. //
  1266. //}
  1267. //startRecordDateTime := startTime.Unix()
  1268. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1269. //if err != nil {
  1270. //
  1271. //}
  1272. //endRecordDateTime := endTime.Unix()
  1273. admin := c.GetAdminUserInfo()
  1274. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1275. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1276. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1277. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. var prescriptions []*models.HisPrescription
  1279. var last_prescriptions []*models.HisPrescription
  1280. var sch_prescriptions []CustomTemplate
  1281. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1282. if p_type == 1 { //住院
  1283. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1284. for _, item := range prescriptions {
  1285. for _, subItem := range item.HisDoctorAdviceInfo {
  1286. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1287. if info.RetailPrice > 0 {
  1288. subItem.Drug.MinPrice = info.RetailPrice
  1289. }
  1290. }
  1291. }
  1292. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1293. } else { //门诊
  1294. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1295. for _, item := range prescriptions {
  1296. for _, subItem := range item.HisDoctorAdviceInfo {
  1297. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1298. if info.RetailPrice > 0 {
  1299. subItem.Drug.MinPrice = info.RetailPrice
  1300. }
  1301. }
  1302. }
  1303. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1304. }
  1305. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1306. if sch.ID > 0 {
  1307. var week string
  1308. t := time.Now()
  1309. switch t.Weekday().String() {
  1310. case "Monday":
  1311. week = "周一"
  1312. break
  1313. case "Tuesday":
  1314. week = "周二"
  1315. break
  1316. case "Wednesday":
  1317. week = "周三"
  1318. break
  1319. case "Thursday":
  1320. week = "周四"
  1321. break
  1322. case "Friday":
  1323. week = "周五"
  1324. break
  1325. case "Saturday":
  1326. week = "周六"
  1327. break
  1328. case "Sunday":
  1329. week = "周日"
  1330. break
  1331. }
  1332. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1333. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1334. //根据推送频率组装新的数组
  1335. for _, item := range temp_sch_prescriptions {
  1336. var cus CustomTemplate
  1337. cus.ID = item.ID
  1338. cus.UserOrgId = item.UserOrgId
  1339. cus.PatientId = item.PatientId
  1340. cus.MedType = item.MedType
  1341. cus.RecordDate = item.RecordDate
  1342. cus.Type = item.Type
  1343. cus.PType = item.PType
  1344. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1345. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1346. if subItem.FrequencyType == 1 { //每次必推
  1347. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1348. }
  1349. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1350. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1351. }
  1352. if subItem.FrequencyType == 2 { //按照天数频率
  1353. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1354. now := p.Unix()
  1355. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1356. dayStr2 := "-" + dayStr
  1357. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1358. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1359. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1360. if len(advices) == 0 {
  1361. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1362. }
  1363. }
  1364. }
  1365. }
  1366. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1367. if subItem.Type == 2 {
  1368. if subItem.XtHisProject.MedicalStatus != 1 {
  1369. if subItem.FrequencyType == 1 {
  1370. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1371. }
  1372. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1373. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1374. }
  1375. if subItem.FrequencyType == 2 {
  1376. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1377. now := p.Unix()
  1378. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1379. dayStr2 := "-" + dayStr
  1380. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1381. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1382. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1383. if len(projects) == 0 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. }
  1387. }
  1388. } else if subItem.Type == 3 {
  1389. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1390. if subItem.FrequencyType == 1 {
  1391. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1392. }
  1393. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1394. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1395. }
  1396. if subItem.FrequencyType == 2 {
  1397. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1398. now := p.Unix()
  1399. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1400. dayStr2 := "-" + dayStr
  1401. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1402. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1403. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1404. if len(projects) == 0 {
  1405. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1406. }
  1407. }
  1408. }
  1409. }
  1410. }
  1411. sch_prescriptions = append(sch_prescriptions, cus)
  1412. }
  1413. for _, item := range sch_prescriptions {
  1414. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1415. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1416. }
  1417. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1418. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1419. }
  1420. }
  1421. }
  1422. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1423. if config.ID > 0 && config.IsOpen == 1 {
  1424. for _, item := range sch_prescriptions {
  1425. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1426. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1427. if info.RetailPrice > 0 {
  1428. subItem.Drug.MinPrice = info.RetailPrice
  1429. if admin.CurrentOrgId != 10598 {
  1430. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1431. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. if config.ID > 0 && config.IsOpen == 1 {
  1438. for _, item := range sch_prescriptions {
  1439. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1440. if subItem.Type == 3 {
  1441. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1442. if info.Price > 0 {
  1443. subItem.GoodInfo.PackingPrice = info.Price
  1444. if admin.CurrentOrgId != 10598 {
  1445. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1446. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1447. }
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1454. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1455. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1456. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1457. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1458. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1459. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1460. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1461. //获取所有科室信息
  1462. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1463. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1464. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1465. c.ServeSuccessJSON(map[string]interface{}{
  1466. "his_info": his_patient_info,
  1467. "xt_info": xt_patient_info,
  1468. "prescription": prescriptions,
  1469. "case_history": case_history,
  1470. "info": patientPrescriptionInfo,
  1471. //"month_prescriptions": monthPrescriptions,
  1472. "order": order,
  1473. "doctors": doctors,
  1474. "department": department,
  1475. "sch_prescriptions": sch_prescriptions,
  1476. "last_prescriptions": last_prescriptions,
  1477. "schedule": sch,
  1478. "count": count,
  1479. "drugStockConfig": drugStockConfig,
  1480. "last_info": lastPatientPrescriptionInfo,
  1481. "befor": beforThrity,
  1482. "LastCaseHistory": LastCaseHistory,
  1483. })
  1484. return
  1485. }
  1486. func (c *HisApiController) GetHisPrescriptionConfig() {
  1487. adminInfo := c.GetAdminUserInfo()
  1488. //获取医嘱模版
  1489. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1490. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1491. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1492. //获取所有基础药
  1493. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1494. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1495. if config.ID > 0 && config.IsOpen == 1 {
  1496. for _, item := range drugs {
  1497. var index = 0
  1498. for _, subItem := range item.OtherDrugWarehouseInfo {
  1499. if index == 0 {
  1500. index = index + 1
  1501. if subItem.RetailPrice > 0 {
  1502. item.MinPrice = subItem.RetailPrice
  1503. }
  1504. }
  1505. }
  1506. }
  1507. }
  1508. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1509. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1510. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1511. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1512. //获取所有科室信息
  1513. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1514. //获取诊断信息
  1515. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1516. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1517. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1518. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1519. //获取是否开启保存耗材出库的开关
  1520. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1521. c.ServeSuccessJSON(map[string]interface{}{
  1522. "drugs": drugs,
  1523. "advices_template": advices,
  1524. "drugways": drugways,
  1525. "efs": efs,
  1526. "doctors": doctors,
  1527. "department": department,
  1528. "sick": sick,
  1529. "additions": additions,
  1530. "diagnose": diagnose,
  1531. "manufacturers": manufacturers,
  1532. "goodOutOpen": goodOutOpen,
  1533. "patientDiagnose": patientDiagnose,
  1534. })
  1535. }
  1536. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1537. //获取所有基础药
  1538. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1539. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1540. if config.ID > 0 && config.IsOpen == 1 {
  1541. for _, item := range drugs {
  1542. var index = 0
  1543. for _, subItem := range item.OtherDrugWarehouseInfo {
  1544. if index == 0 {
  1545. index = index + 1
  1546. if subItem.RetailPrice > 0 {
  1547. item.MinPrice = subItem.RetailPrice
  1548. }
  1549. }
  1550. }
  1551. }
  1552. }
  1553. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1554. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1555. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1556. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1557. //获取所有科室信息
  1558. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1559. //获取诊断信息
  1560. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1561. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1562. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1563. //获取是否开启保存耗材出库的开关
  1564. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1565. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1566. c.ServeSuccessJSON(map[string]interface{}{
  1567. "drugs": drugs,
  1568. "advices_template": advices,
  1569. "drugways": drugways,
  1570. "efs": efs,
  1571. "doctors": doctors,
  1572. "department": department,
  1573. "sick": sick,
  1574. "additions": additions,
  1575. "diagnose": diagnose,
  1576. "manufacturers": manufacturers,
  1577. "goodOutOpen": goodOutOpen,
  1578. "patientDiagnose": patientDiagnose,
  1579. })
  1580. }
  1581. }
  1582. func (c *HisApiController) CreateHisPrescription() {
  1583. record_date := c.GetString("record_date")
  1584. patient_id, _ := c.GetInt64("patient_id")
  1585. reg_type, _ := c.GetInt64("reg_type")
  1586. diagnose := c.GetString("diagnose")
  1587. sick_type, _ := c.GetInt64("sick_type")
  1588. sick_history := c.GetString("sick_history")
  1589. doctor_id, _ := c.GetInt64("doctor", 0)
  1590. department, _ := c.GetInt64("department", 0)
  1591. his_patient_id, _ := c.GetInt64("his_patient_id")
  1592. p_type, _ := c.GetInt64("p_type")
  1593. patient_diagnose := c.GetString("patient_diagnose")
  1594. dataBody := make(map[string]interface{}, 0)
  1595. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1596. if err != nil {
  1597. utils.ErrorLog(err.Error())
  1598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1599. return
  1600. }
  1601. //edit, src := GetCompareData(dataBody)
  1602. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1603. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1604. //fmt.Println(drugResult)
  1605. //fmt.Println(goodResult)
  1606. timeLayout := "2006-01-02"
  1607. loc, _ := time.LoadLocation("Local")
  1608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1609. if err != nil {
  1610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1611. return
  1612. }
  1613. adminInfo := c.GetAdminUserInfo()
  1614. recordDateTime := theTime.Unix()
  1615. //查询默认出库仓库库存
  1616. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1617. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1618. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1619. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1620. if len(lists) == 1 {
  1621. his_patient_id = lists[0].ID
  1622. }
  1623. }
  1624. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1625. //自动出库的开关开启
  1626. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1627. //自动出库
  1628. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1629. //耗材保存处方出库
  1630. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1631. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1632. //已发药和已收费限制逻辑
  1633. isMidicine := false
  1634. isCharge := false
  1635. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1636. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1637. if len(prescriptions) > 0 {
  1638. for _, item := range prescriptions {
  1639. items := item.(map[string]interface{})
  1640. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1641. utils.ErrorLog("id")
  1642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1643. return
  1644. }
  1645. id := int64(items["id"].(float64))
  1646. if id > 0 {
  1647. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1648. if err != nil {
  1649. if new_prescription.OrderStatus == 4 {
  1650. isCharge = true
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. if isMidicine == true {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1659. return
  1660. }
  1661. if isCharge == true {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1663. return
  1664. }
  1665. // 开始主事务
  1666. db := service.XTWriteDB()
  1667. tx := db.Begin()
  1668. // 在函数结束时处理事务回滚
  1669. defer func() {
  1670. if r := recover(); r != nil {
  1671. tx.Rollback()
  1672. }
  1673. }()
  1674. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1675. //药品发药出库
  1676. if pharmacyConfig.IsOpen == 1 {
  1677. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1678. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1679. if len(prescriptions) > 0 {
  1680. for _, item := range prescriptions {
  1681. items := item.(map[string]interface{})
  1682. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1683. advices := items["advices"].([]interface{})
  1684. if len(advices) > 0 {
  1685. for _, advice := range advices {
  1686. var drug_id int64
  1687. var prescribing_number float64
  1688. var prescribingNumberUnit string
  1689. var adviceId int64
  1690. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1691. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1692. }
  1693. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1694. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1695. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1696. }
  1697. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1698. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1699. }
  1700. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1701. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1702. }
  1703. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1704. if drug.ID == 0 {
  1705. tx.Rollback()
  1706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1707. return
  1708. }
  1709. //查询药品的所有库存
  1710. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1711. var total_count int64
  1712. for _, it := range list {
  1713. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1714. }
  1715. totals := strconv.FormatInt(total_count, 10)
  1716. //查询该药品是否存在开药记录
  1717. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1718. //新增处方盘点库存是否充足
  1719. if advicelist.ID == 0 {
  1720. all_count, _ := strconv.ParseFloat(totals, 64)
  1721. if prescribingNumberUnit == drug.MinUnit {
  1722. if drug.IsUse != 1 {
  1723. if drug.IsProject == 0 || drug.IsProject == 2 {
  1724. if all_count == 0 {
  1725. tx.Rollback()
  1726. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1727. return
  1728. }
  1729. if prescribing_number > all_count {
  1730. tx.Rollback()
  1731. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1732. return
  1733. }
  1734. }
  1735. }
  1736. }
  1737. if prescribingNumberUnit == drug.MaxUnit {
  1738. num := prescribing_number * float64(drug.MinNumber)
  1739. if drug.IsUse != 1 {
  1740. if drug.IsProject == 0 || drug.IsProject == 2 {
  1741. if all_count == 0 {
  1742. tx.Rollback()
  1743. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1744. return
  1745. }
  1746. if num > all_count {
  1747. tx.Rollback()
  1748. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1749. return
  1750. }
  1751. }
  1752. }
  1753. }
  1754. }
  1755. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1756. //不使用保存处方出库
  1757. if drugOutConfig.IsOpen != 1 {
  1758. //修改处方
  1759. for _, advice := range advices {
  1760. var drug_id int64
  1761. var prescribing_number float64
  1762. var prescribingNumberUnit string
  1763. var prescribingNumber string
  1764. var adviceId int64
  1765. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1766. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1767. }
  1768. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1769. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1770. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1771. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1772. }
  1773. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1774. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1775. }
  1776. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1777. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1778. }
  1779. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1780. if drug.ID == 0 {
  1781. tx.Rollback()
  1782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1783. return
  1784. }
  1785. //查询药品的所有库存
  1786. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1787. var total_count int64
  1788. for _, it := range list {
  1789. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1790. }
  1791. totals := strconv.FormatInt(total_count, 10)
  1792. //查询该药品是否存在开药记录
  1793. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1794. //新增处方
  1795. if advicelist.ID == 0 {
  1796. all_count, _ := strconv.ParseFloat(totals, 64)
  1797. if prescribingNumberUnit == drug.MinUnit {
  1798. if drug.IsUse != 1 {
  1799. if drug.IsProject == 0 || drug.IsProject == 2 {
  1800. if all_count == 0 {
  1801. tx.Rollback()
  1802. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1803. return
  1804. }
  1805. if prescribing_number > all_count {
  1806. tx.Rollback()
  1807. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1808. return
  1809. }
  1810. }
  1811. }
  1812. } else {
  1813. if prescribingNumberUnit == drug.MaxUnit {
  1814. num := prescribing_number * float64(drug.MinNumber)
  1815. if drug.IsUse != 1 {
  1816. if drug.IsProject == 0 || drug.IsProject == 2 {
  1817. if all_count == 0 {
  1818. tx.Rollback()
  1819. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1820. return
  1821. }
  1822. if num > all_count {
  1823. tx.Rollback()
  1824. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1825. return
  1826. }
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. //修改处方
  1833. if advicelist.ID > 0 {
  1834. var device_number int64
  1835. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1836. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1837. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1838. device_number = prescribingNumberInt * drug.MinNumber
  1839. }
  1840. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1841. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1842. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1843. device_number = prescribingNumberInt
  1844. }
  1845. var number_count int64
  1846. if prescribingNumberUnit == drug.MaxUnit {
  1847. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1848. number_count = prescribingNumberInt * drug.MinNumber
  1849. }
  1850. if prescribingNumberUnit == drug.MinUnit {
  1851. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1852. number_count = prescribingNumberInt
  1853. }
  1854. //如果修改的数量大于之前修改的数量
  1855. if (number_count - device_number) > 0 {
  1856. //如果修改的差数量 大于库存数量
  1857. if drug.IsUse != 1 {
  1858. if (number_count - device_number) > total_count {
  1859. tx.Rollback()
  1860. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1861. return
  1862. }
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. //已发药和已收费限制逻辑
  1876. //执行出库的逻辑
  1877. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1878. //校验库存总量
  1879. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1880. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1881. if len(prescriptions) > 0 {
  1882. for _, item := range prescriptions {
  1883. items := item.(map[string]interface{})
  1884. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1885. advices := items["advices"].([]interface{})
  1886. if len(advices) > 0 {
  1887. for _, advice := range advices {
  1888. var drug_id int64
  1889. var prescribing_number float64
  1890. var prescribingNumberUnit string
  1891. var adviceId int64
  1892. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1893. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1894. }
  1895. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1896. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1897. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1898. }
  1899. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1900. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1901. }
  1902. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1903. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1904. }
  1905. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1906. if drug.ID == 0 {
  1907. tx.Rollback()
  1908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1909. return
  1910. }
  1911. //查询药品的所有库存
  1912. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1913. var total_count int64
  1914. for _, it := range list {
  1915. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1916. }
  1917. totals := strconv.FormatInt(total_count, 10)
  1918. //查询该药品是否存在开药记录
  1919. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1920. //查询最新批次库存
  1921. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1922. var batch_number_count int64
  1923. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1924. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1925. //新增处方
  1926. if advicelist.ID == 0 {
  1927. all_count, _ := strconv.ParseFloat(totals, 64)
  1928. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1929. if prescribingNumberUnit == drug.MinUnit {
  1930. if drug.IsUse != 1 {
  1931. if drug.IsProject == 0 || drug.IsProject == 2 {
  1932. if all_count == 0 {
  1933. tx.Rollback()
  1934. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1935. return
  1936. }
  1937. if prescribing_number > all_count {
  1938. tx.Rollback()
  1939. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1940. return
  1941. }
  1942. }
  1943. if adminInfo.CurrentOrgId == 10215 {
  1944. if prescribing_number > batch_number_all_count {
  1945. tx.Rollback()
  1946. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1947. return
  1948. }
  1949. }
  1950. }
  1951. }
  1952. if prescribingNumberUnit == drug.MaxUnit {
  1953. num := prescribing_number * float64(drug.MinNumber)
  1954. if drug.IsUse != 1 {
  1955. if drug.IsProject == 0 || drug.IsProject == 2 {
  1956. if all_count == 0 {
  1957. tx.Rollback()
  1958. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1959. return
  1960. }
  1961. if num > all_count {
  1962. tx.Rollback()
  1963. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1964. return
  1965. }
  1966. }
  1967. if adminInfo.CurrentOrgId == 10215 {
  1968. if num > batch_number_all_count {
  1969. tx.Rollback()
  1970. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1971. return
  1972. }
  1973. }
  1974. }
  1975. }
  1976. }
  1977. //不是保存处方出库
  1978. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1979. if drugOutConfig.IsOpen != 1 {
  1980. //修改处方
  1981. for _, advice := range advices {
  1982. var drug_id int64
  1983. var prescribing_number float64
  1984. var prescribingNumberUnit string
  1985. var prescribingNumber string
  1986. var adviceId int64
  1987. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1988. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1989. }
  1990. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1991. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1992. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1993. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1994. }
  1995. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1996. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1997. }
  1998. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1999. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2000. }
  2001. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2002. if drug.ID == 0 {
  2003. tx.Rollback()
  2004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2005. return
  2006. }
  2007. //查询药品的所有库存
  2008. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2009. var total_count int64
  2010. for _, it := range list {
  2011. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2012. }
  2013. totals := strconv.FormatInt(total_count, 10)
  2014. //查询该药品是否存在开药记录
  2015. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2016. //新增处方
  2017. if advicelist.ID == 0 {
  2018. //查询最新批次库存
  2019. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2020. var batch_number_count int64
  2021. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2022. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2023. all_count, _ := strconv.ParseFloat(totals, 64)
  2024. if all_count == 0 {
  2025. tx.Rollback()
  2026. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2027. return
  2028. }
  2029. if prescribingNumberUnit == drug.MinUnit {
  2030. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2031. if drug.IsUse != 1 {
  2032. if drug.IsProject == 0 || drug.IsProject == 2 {
  2033. if all_count == 0 {
  2034. tx.Rollback()
  2035. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2036. return
  2037. }
  2038. if prescribing_number > all_count {
  2039. tx.Rollback()
  2040. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2041. return
  2042. }
  2043. }
  2044. if adminInfo.CurrentOrgId == 10215 {
  2045. if prescribing_number > batch_number_all_count {
  2046. tx.Rollback()
  2047. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2048. return
  2049. }
  2050. }
  2051. }
  2052. } else {
  2053. if prescribingNumberUnit == drug.MaxUnit {
  2054. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2055. num := prescribing_number * float64(drug.MinNumber)
  2056. if drug.IsUse != 1 {
  2057. if drug.IsProject == 0 || drug.IsProject == 2 {
  2058. if all_count == 0 {
  2059. tx.Rollback()
  2060. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2061. return
  2062. }
  2063. if num > all_count {
  2064. tx.Rollback()
  2065. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2066. return
  2067. }
  2068. }
  2069. if adminInfo.CurrentOrgId == 10215 {
  2070. if prescribing_number > batch_number_all_count {
  2071. tx.Rollback()
  2072. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2073. return
  2074. }
  2075. }
  2076. }
  2077. }
  2078. }
  2079. }
  2080. //修改处方
  2081. if advicelist.ID > 0 {
  2082. //查询最新批次库存
  2083. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2084. var batch_number_count int64
  2085. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2086. var device_number int64
  2087. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2088. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2089. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2090. device_number = prescribingNumberInt * drug.MinNumber
  2091. }
  2092. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2093. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2094. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2095. device_number = prescribingNumberInt
  2096. //回退库存
  2097. }
  2098. var number_count int64
  2099. if prescribingNumberUnit == drug.MaxUnit {
  2100. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2101. number_count = prescribingNumberInt * drug.MinNumber
  2102. //回退库存
  2103. }
  2104. if prescribingNumberUnit == drug.MinUnit {
  2105. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2106. number_count = prescribingNumberInt
  2107. //回退库存
  2108. }
  2109. //如果修改的数量大于之前修改的数量
  2110. if (number_count - device_number) > 0 {
  2111. //如果修改的差数量 大于库存数量
  2112. if drug.IsUse != 1 {
  2113. if drug.IsProject == 0 || drug.IsProject == 2 {
  2114. if total_count == 0 {
  2115. tx.Rollback()
  2116. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2117. return
  2118. }
  2119. if (number_count - device_number) > total_count {
  2120. tx.Rollback()
  2121. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2122. return
  2123. }
  2124. if (number_count - device_number) > batch_number_count {
  2125. tx.Rollback()
  2126. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2127. return
  2128. }
  2129. }
  2130. if adminInfo.CurrentOrgId == 10215 {
  2131. // 查询该药品最后一次出库记录
  2132. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2133. var out_count int64
  2134. var in_count int64
  2135. var stock_max_number int64
  2136. var stock_min_number int64
  2137. for _, it := range outInfo {
  2138. if it.CountUnit == drug.MaxUnit {
  2139. it.Count = it.Count * drug.MinNumber
  2140. }
  2141. out_count += it.Count
  2142. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2143. stock_max_number = warehouseInfoList.StockMaxNumber
  2144. stock_min_number = warehouseInfoList.StockMinNumber
  2145. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2146. }
  2147. if out_count > 0 {
  2148. if (number_count - device_number) > in_count {
  2149. tx.Rollback()
  2150. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2151. return
  2152. }
  2153. }
  2154. // 未出库
  2155. if out_count == 0 {
  2156. var sum_in_count int64
  2157. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2158. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2159. //如果修改的数量大于有库存的第一个批次
  2160. if number_count > sum_in_count {
  2161. tx.Rollback()
  2162. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2163. return
  2164. }
  2165. }
  2166. }
  2167. }
  2168. }
  2169. //药品发药
  2170. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2171. //不使用药品发药的功能
  2172. //if pharmacyConfig.IsOpen != 1 {
  2173. // if device_number != number_count {
  2174. //
  2175. // //查询该药品的出库记录
  2176. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2177. // if len(outListExport) > 0 {
  2178. // //
  2179. // for _, item := range outListExport {
  2180. // //回退库存
  2181. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2182. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2183. // }
  2184. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2185. // var stock_max_number int64
  2186. // var stock_min_number int64
  2187. //
  2188. // if number_count >= drug.MinNumber {
  2189. //
  2190. // stock_max_number = device_number / drug.MinNumber
  2191. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2192. //
  2193. // stock_min_number = device_number % drug.MinNumber
  2194. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2195. //
  2196. // } else {
  2197. //
  2198. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2199. //
  2200. // }
  2201. // }
  2202. //
  2203. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2204. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2205. // }
  2206. // }
  2207. // }
  2208. //
  2209. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2210. // var sum_count int64
  2211. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2212. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2213. // for _, its := range stockInfo {
  2214. // if its.MaxUnit == drug.MaxUnit {
  2215. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2216. // }
  2217. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2218. // }
  2219. // //更新字典里面的库存
  2220. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2221. //
  2222. // //剩余库存
  2223. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2224. //
  2225. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2226. // //减少出库数量
  2227. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2228. //
  2229. // }
  2230. //}
  2231. }
  2232. }
  2233. }
  2234. //保存处方开药
  2235. if drugOutConfig.IsOpen == 1 {
  2236. //修改处方
  2237. for _, advice := range advices {
  2238. var drug_id int64
  2239. var prescribing_number float64
  2240. var prescribingNumberUnit string
  2241. var prescribingNumber string
  2242. var adviceId int64
  2243. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2244. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2245. }
  2246. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2247. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2248. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2249. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2250. }
  2251. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2252. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2253. }
  2254. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2255. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2256. }
  2257. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2258. if drug.ID == 0 {
  2259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2260. return
  2261. }
  2262. //查询药品的所有库存
  2263. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2264. var total_count int64
  2265. for _, it := range list {
  2266. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2267. }
  2268. totals := strconv.FormatInt(total_count, 10)
  2269. //查询该药品是否存在开药记录
  2270. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2271. //新增处方
  2272. if advicelist.ID == 0 {
  2273. //查询最新批次库存
  2274. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2275. var batch_number_count int64
  2276. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2277. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2278. all_count, _ := strconv.ParseFloat(totals, 64)
  2279. if prescribingNumberUnit == drug.MinUnit {
  2280. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2281. if drug.IsUse != 1 {
  2282. if drug.IsProject == 0 || drug.IsProject == 2 {
  2283. if all_count == 0 {
  2284. tx.Rollback()
  2285. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2286. return
  2287. }
  2288. if prescribing_number > all_count {
  2289. tx.Rollback()
  2290. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2291. return
  2292. }
  2293. }
  2294. if adminInfo.CurrentOrgId == 10215 {
  2295. if prescribing_number > batch_number_all_count {
  2296. tx.Rollback()
  2297. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2298. return
  2299. }
  2300. }
  2301. }
  2302. } else {
  2303. if prescribingNumberUnit == drug.MaxUnit {
  2304. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2305. num := prescribing_number * float64(drug.MinNumber)
  2306. if drug.IsUse != 1 {
  2307. if drug.IsProject == 0 || drug.IsProject == 2 {
  2308. if all_count == 0 {
  2309. tx.Rollback()
  2310. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2311. return
  2312. }
  2313. if num > all_count {
  2314. tx.Rollback()
  2315. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2316. return
  2317. }
  2318. }
  2319. if adminInfo.CurrentOrgId == 10215 {
  2320. if prescribing_number > batch_number_all_count {
  2321. tx.Rollback()
  2322. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2323. return
  2324. }
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. //修改处方
  2331. if advicelist.ID > 0 {
  2332. //查询最新批次库存
  2333. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2334. var batch_number_count int64
  2335. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2336. var device_number int64
  2337. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2338. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2339. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2340. device_number = prescribingNumberInt * drug.MinNumber
  2341. }
  2342. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2343. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2344. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2345. device_number = prescribingNumberInt
  2346. }
  2347. var number_count int64
  2348. if prescribingNumberUnit == drug.MaxUnit {
  2349. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2350. number_count = prescribingNumberInt * drug.MinNumber
  2351. }
  2352. if prescribingNumberUnit == drug.MinUnit {
  2353. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2354. number_count = prescribingNumberInt
  2355. }
  2356. //如果修改的数量大于之前修改的数量
  2357. if (number_count - device_number) > 0 {
  2358. //如果修改的差数量 大于库存数量
  2359. if drug.IsUse != 1 {
  2360. if drug.IsProject == 0 || drug.IsProject == 2 {
  2361. if total_count == 0 {
  2362. tx.Rollback()
  2363. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2364. return
  2365. }
  2366. if (number_count - device_number) > total_count {
  2367. tx.Rollback()
  2368. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2369. return
  2370. }
  2371. }
  2372. if adminInfo.CurrentOrgId == 10215 {
  2373. if (number_count - device_number) > batch_number_count {
  2374. tx.Rollback()
  2375. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2376. return
  2377. }
  2378. }
  2379. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2380. //查询历史出库数据总批次
  2381. // 查询该药品最后一次出库记录
  2382. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2383. var out_count int64
  2384. var in_count int64
  2385. var stock_max_number int64
  2386. var stock_min_number int64
  2387. for _, it := range outInfo {
  2388. if it.CountUnit == drug.MaxUnit {
  2389. it.Count = it.Count * drug.MinNumber
  2390. }
  2391. out_count += it.Count
  2392. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2393. stock_max_number = warehouseInfoList.StockMaxNumber
  2394. stock_min_number = warehouseInfoList.StockMinNumber
  2395. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2396. }
  2397. if out_count > 0 {
  2398. if (number_count - device_number) > in_count {
  2399. tx.Rollback()
  2400. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2401. return
  2402. }
  2403. }
  2404. // 未出库
  2405. if out_count == 0 {
  2406. var sum_in_count int64
  2407. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2408. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2409. if sum_in_count == 0 {
  2410. tx.Rollback()
  2411. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2412. return
  2413. }
  2414. //如果修改的数量大于有库存的第一个批次
  2415. if number_count > sum_in_count {
  2416. tx.Rollback()
  2417. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2418. return
  2419. }
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. //校验耗材库存
  2435. if goodOutConfig.IsOpen == 1 {
  2436. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2437. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2438. if len(prescriptions) > 0 {
  2439. for _, item := range prescriptions {
  2440. items := item.(map[string]interface{})
  2441. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2442. projects := items["project"].([]interface{})
  2443. if len(projects) > 0 {
  2444. for _, project := range projects {
  2445. var project_id int64
  2446. var project_type int64
  2447. var totals float64
  2448. var project_name string
  2449. var parsetotal int64
  2450. var id int64
  2451. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2452. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2453. }
  2454. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2455. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2456. }
  2457. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2458. total, _ := project.(map[string]interface{})["total"].(string)
  2459. totals, _ = strconv.ParseFloat(total, 64)
  2460. }
  2461. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2462. project_name = project.(map[string]interface{})["project_name"].(string)
  2463. }
  2464. if project_type == 3 {
  2465. //查找该耗材的出库记录
  2466. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2467. if len(goodWarehouseInfo) == 0 {
  2468. //查询耗材库存
  2469. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2470. var stock_count int64
  2471. for _, it := range list {
  2472. stock_count += it.StockCount
  2473. }
  2474. stock_counts := strconv.FormatInt(stock_count, 10)
  2475. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2476. if stock_total_count == 0 {
  2477. tx.Rollback()
  2478. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2479. return
  2480. }
  2481. if totals > stock_total_count {
  2482. tx.Rollback()
  2483. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2484. return
  2485. }
  2486. }
  2487. if len(goodWarehouseInfo) > 0 {
  2488. //查询该患者耗材的历史数据
  2489. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2490. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2491. //数量发生改变
  2492. if parsetotal != count {
  2493. //如果现在的数量大于历史数量,就要看库存是否足够
  2494. if parsetotal > count {
  2495. //查询耗材所有库存
  2496. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2497. var stock_count int64
  2498. for _, it := range list {
  2499. stock_count += it.StockCount
  2500. }
  2501. //库存不足
  2502. if stock_count == 0 {
  2503. tx.Rollback()
  2504. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2505. return
  2506. }
  2507. if (parsetotal - count) > stock_count {
  2508. tx.Rollback()
  2509. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2510. return
  2511. }
  2512. }
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. //不使用耗材保存处方出库
  2524. if goodOutConfig.IsOpen != 1 {
  2525. if stockConfig.IsOpen == 1 {
  2526. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2527. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2528. if len(prescriptions) > 0 {
  2529. for _, item := range prescriptions {
  2530. items := item.(map[string]interface{})
  2531. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2532. projects := items["project"].([]interface{})
  2533. if len(projects) > 0 {
  2534. for _, project := range projects {
  2535. var project_id int64
  2536. var project_type int64
  2537. var totals float64
  2538. var project_name string
  2539. var parsetotal int64
  2540. var id int64
  2541. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2542. id = int64(project.(map[string]interface{})["id"].(float64))
  2543. }
  2544. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2545. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2546. }
  2547. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2548. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2549. }
  2550. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2551. total, _ := project.(map[string]interface{})["total"].(string)
  2552. totals, _ = strconv.ParseFloat(total, 64)
  2553. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2554. }
  2555. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2556. project_name = project.(map[string]interface{})["project_name"].(string)
  2557. }
  2558. if project_type == 3 {
  2559. //查找该耗材的出库记录
  2560. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2561. //没有出库记录
  2562. if len(goodWarehouseInfo) == 0 {
  2563. //查询耗材库存
  2564. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2565. var stock_count int64
  2566. for _, it := range list {
  2567. stock_count += it.StockCount
  2568. }
  2569. stock_counts := strconv.FormatInt(stock_count, 10)
  2570. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2571. if stock_total_count == 0 {
  2572. tx.Rollback()
  2573. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2574. return
  2575. }
  2576. if totals > stock_total_count {
  2577. tx.Rollback()
  2578. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2579. return
  2580. }
  2581. //查找今日该患者已经出库的所有耗材
  2582. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2583. for _, item := range goodList {
  2584. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2585. var flush_count int64
  2586. for _, it := range goodListSix {
  2587. flush_count += it.StockCount
  2588. }
  2589. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2590. creater := adminInfo.AdminUser.Id
  2591. if errs != nil {
  2592. goodErrcode := models.XtGoodErrcode{
  2593. UserOrgId: item.OrgId,
  2594. Errcode: "手动出库更新剩余出库失败",
  2595. GoodId: item.GoodId,
  2596. Status: 1,
  2597. Ctime: time.Now().Unix(),
  2598. Mtime: 0,
  2599. Count: 0,
  2600. StockCount: 0,
  2601. Creater: creater,
  2602. BatchNumberId: 0,
  2603. WarehouseOutId: 0,
  2604. }
  2605. service.CreateGoodErrcode(goodErrcode)
  2606. }
  2607. }
  2608. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2609. }
  2610. //有出库记录
  2611. if len(goodWarehouseInfo) > 0 {
  2612. //查询该患者耗材的历史数据
  2613. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2614. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2615. //数量发生改变
  2616. if parsetotal != count {
  2617. //查找今日该患者已经出库的所有耗材
  2618. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2619. for _, item := range goodList {
  2620. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2621. var flush_count int64
  2622. for _, it := range goodListSix {
  2623. flush_count += it.StockCount
  2624. }
  2625. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2626. //减少出库数量
  2627. creater := adminInfo.AdminUser.Id
  2628. if errs != nil {
  2629. goodErrcode := models.XtGoodErrcode{
  2630. UserOrgId: item.OrgId,
  2631. Errcode: "手动出库更新剩余出库失败",
  2632. GoodId: item.GoodId,
  2633. Status: 1,
  2634. Ctime: time.Now().Unix(),
  2635. Mtime: 0,
  2636. Count: 0,
  2637. StockCount: 0,
  2638. Creater: creater,
  2639. BatchNumberId: 0,
  2640. WarehouseOutId: 0,
  2641. }
  2642. service.CreateGoodErrcode(goodErrcode)
  2643. }
  2644. //查询默认仓库
  2645. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2646. var total_count int64
  2647. for _, it := range stockList {
  2648. total_count += it.StockCount
  2649. }
  2650. //基础库插入数据
  2651. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2652. }
  2653. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2654. }
  2655. }
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2666. var hpInfo models.HisPrescriptionInfo
  2667. if info.ID == 0 {
  2668. var randNum int
  2669. randNum = rand.Intn(10000) + 1000
  2670. timestamp := time.Now().Unix()
  2671. tempTime := time.Unix(timestamp, 0)
  2672. timeFormat := tempTime.Format("20060102150405")
  2673. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2674. hpInfo = models.HisPrescriptionInfo{
  2675. HisPatientId: his_patient_id,
  2676. UserOrgId: adminInfo.CurrentOrgId,
  2677. RecordDate: theTime.Unix(),
  2678. PatientId: patient_id,
  2679. Status: 1,
  2680. Ctime: time.Now().Unix(),
  2681. Mtime: time.Now().Unix(),
  2682. Creator: adminInfo.AdminUser.Id,
  2683. Modifier: adminInfo.AdminUser.Id,
  2684. Diagnosis: diagnose,
  2685. SickHistory: sick_history,
  2686. Departments: department,
  2687. RegisterType: reg_type,
  2688. PrescriptionNumber: p_number,
  2689. PrescriptionStatus: 1,
  2690. Doctor: role.UserName,
  2691. DoctorId: doctor_id,
  2692. SickType: sick_type,
  2693. PType: p_type,
  2694. PatientDiagnosis: patient_diagnose,
  2695. }
  2696. service.SavePatientPrescriptionInfo(hpInfo)
  2697. //创建步骤表
  2698. finish := models.XtDialysisFinish{
  2699. IsFinish: 1,
  2700. UserOrgId: adminInfo.CurrentOrgId,
  2701. Status: 1,
  2702. Ctime: time.Now().Unix(),
  2703. Mtime: 0,
  2704. Module: 4,
  2705. RecordDate: theTime.Unix(),
  2706. Sourse: 1,
  2707. PatientId: patient_id,
  2708. }
  2709. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2710. if dialysisFinish.ID == 0 {
  2711. service.CreateDialysisFinish(finish)
  2712. }
  2713. redis := service.RedisClient()
  2714. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2715. redis.Set(key, "", time.Second)
  2716. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2717. redis.Set(keyOne, "", time.Second)
  2718. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2719. redis.Set(keySeven, "", time.Second)
  2720. defer redis.Close()
  2721. } else {
  2722. hpInfo = models.HisPrescriptionInfo{
  2723. ID: info.ID,
  2724. UserOrgId: adminInfo.CurrentOrgId,
  2725. RecordDate: info.RecordDate,
  2726. PatientId: info.PatientId,
  2727. Status: 1,
  2728. Ctime: info.Ctime,
  2729. Mtime: time.Now().Unix(),
  2730. Creator: info.Creator,
  2731. Modifier: adminInfo.AdminUser.Id,
  2732. Diagnosis: diagnose,
  2733. SickHistory: sick_history,
  2734. Departments: department,
  2735. RegisterType: reg_type,
  2736. PrescriptionNumber: info.PrescriptionNumber,
  2737. Doctor: role.UserName,
  2738. PrescriptionStatus: info.PrescriptionStatus,
  2739. DoctorId: doctor_id,
  2740. SickType: sick_type,
  2741. PType: info.PType,
  2742. HisPatientId: info.HisPatientId,
  2743. PatientDiagnosis: patient_diagnose,
  2744. }
  2745. service.SavePatientPrescriptionInfo(hpInfo)
  2746. //创建步骤表
  2747. finish := models.XtDialysisFinish{
  2748. IsFinish: 1,
  2749. UserOrgId: adminInfo.CurrentOrgId,
  2750. Status: 1,
  2751. Ctime: time.Now().Unix(),
  2752. Mtime: 0,
  2753. Module: 4,
  2754. RecordDate: info.RecordDate,
  2755. Sourse: 1,
  2756. PatientId: info.PatientId,
  2757. }
  2758. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2759. if dialysisFinish.ID == 0 {
  2760. service.CreateDialysisFinish(finish)
  2761. }
  2762. redis := service.RedisClient()
  2763. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2764. redis.Set(key, "", time.Second)
  2765. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2766. redis.Set(keyOne, "", time.Second)
  2767. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2768. redis.Set(keySeven, "", time.Second)
  2769. defer redis.Close()
  2770. }
  2771. //定义切片
  2772. var adviceList []models.HisDoctorAdviceInfo
  2773. var projectList []models.HisPrescriptionProject
  2774. 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 {
  2775. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2776. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2777. var tempPrescription *models.HisPrescription
  2778. if len(prescriptions) > 0 {
  2779. for _, item := range prescriptions {
  2780. // 开始外部循环的事务
  2781. tx := db.Begin()
  2782. // 在函数结束时处理事务回滚
  2783. defer func() {
  2784. if r := recover(); r != nil {
  2785. tx.Rollback()
  2786. }
  2787. }()
  2788. items := item.(map[string]interface{})
  2789. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2790. utils.ErrorLog("id")
  2791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2792. return
  2793. }
  2794. id := int64(items["id"].(float64))
  2795. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2796. tempPrescription = &new_prescription
  2797. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2798. utils.ErrorLog("type")
  2799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2800. return
  2801. }
  2802. types := int64(items["type"].(float64))
  2803. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2804. utils.ErrorLog("med_type")
  2805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2806. return
  2807. }
  2808. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2809. if med_type == "0" {
  2810. med_type = "14"
  2811. }
  2812. //if order_status == 0 {
  2813. // order_status = 1
  2814. //}
  2815. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2816. utils.ErrorLog("pre_time")
  2817. }
  2818. preTime, _ := items["pre_time"].(string)
  2819. fmt.Println("preTime", preTime)
  2820. timeLayout := "2006-01-02"
  2821. loc, _ := time.LoadLocation("Local")
  2822. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2823. result := strings.Split(preTime, " ")
  2824. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2825. if err != nil {
  2826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2827. return
  2828. }
  2829. pTime := theTime2.Unix()
  2830. ctime := time.Now().Unix()
  2831. if tempPrescription.ID == 0 {
  2832. prescription := &models.HisPrescription{
  2833. ID: 0,
  2834. PatientId: patient_id,
  2835. UserOrgId: adminInfo.CurrentOrgId,
  2836. RecordDate: recordDateTime,
  2837. Ctime: ctime,
  2838. Mtime: ctime,
  2839. Type: types,
  2840. Modifier: adminInfo.AdminUser.Id,
  2841. Creator: adminInfo.AdminUser.Id,
  2842. Status: 1,
  2843. Doctor: role.UserName,
  2844. HisPatientId: his_patient_id,
  2845. OrderStatus: 1,
  2846. BatchNumber: "",
  2847. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2848. PreTime: pTime,
  2849. PType: p_type,
  2850. MedType: med_type,
  2851. }
  2852. tempPrescription = prescription
  2853. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2854. redis := service.RedisClient()
  2855. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2856. redis.Set(key, "", time.Second)
  2857. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2858. redis.Set(keyOne, "", time.Second)
  2859. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2860. redis.Set(keySeven, "", time.Second)
  2861. defer redis.Close()
  2862. } else {
  2863. tempPrescription.ID = id
  2864. tempPrescription.Type = types
  2865. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2866. tempPrescription.Mtime = time.Now().Unix()
  2867. tempPrescription.Doctor = role.UserName
  2868. //tempPrescription.OrderStatus = order_status
  2869. tempPrescription.PreTime = pTime
  2870. tempPrescription.MedType = med_type
  2871. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2872. redis := service.RedisClient()
  2873. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2874. redis.Set(key, "", time.Second)
  2875. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2876. redis.Set(keyOne, "", time.Second)
  2877. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2878. redis.Set(keySeven, "", time.Second)
  2879. defer redis.Close()
  2880. }
  2881. //service.SaveHisPrescription(prescription)
  2882. //更改患者挂号状态
  2883. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2884. fmt.Println("更改失败", err2)
  2885. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2886. advices := items["advices"].([]interface{})
  2887. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2888. groupNo := int64(0)
  2889. if len(advices) > 0 {
  2890. for _, advice := range advices {
  2891. tx := db.Begin()
  2892. // 在函数结束时处理事务回滚
  2893. defer func() {
  2894. if r := recover(); r != nil {
  2895. tx.Rollback()
  2896. }
  2897. }()
  2898. var s models.HisDoctorAdviceInfo
  2899. s.PrescriptionId = tempPrescription.ID
  2900. s.AdviceType = 2
  2901. s.AdviceDoctor = doctor_id
  2902. s.StopState = 2
  2903. s.ExecutionState = 2
  2904. s.AdviceDate = theTime3.Unix()
  2905. s.Status = 1
  2906. s.UserOrgId = adminInfo.CurrentOrgId
  2907. s.RecordDate = theTime3.Unix()
  2908. s.StartTime = tempPrescription.PreTime
  2909. s.Groupno = groupNo
  2910. s.PatientId = patient_id
  2911. s.HisPatientId = his_patient_id
  2912. s.StartTime = pTime
  2913. s.IsSettle = 2
  2914. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2915. if errcode > 0 {
  2916. c.ServeFailJSONWithSGJErrorCode(errcode)
  2917. return
  2918. }
  2919. s.StartTime = pTime
  2920. var total_count int64 //处方总库存
  2921. //查询改药品信息
  2922. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2923. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2924. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2925. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2926. total_count += prescribingNumberSeven * medical.MinNumber
  2927. }
  2928. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2929. total_count += prescribingNumberSeven
  2930. }
  2931. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2932. total_count += prescribingNumberSeven
  2933. }
  2934. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2935. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2936. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2937. if s.Price != lastWarehouse.RetailPrice {
  2938. s.Price = lastWarehouse.RetailPrice
  2939. }
  2940. if s.Price == 0 {
  2941. if lastWarehouse.ID == 0 {
  2942. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2943. s.Price = lastWarehouseTwo.RetailPrice
  2944. }
  2945. }
  2946. }
  2947. //查询保存处方出库开关是否打开
  2948. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2949. if s.PatientId != 30038 {
  2950. if drugOutConfig.IsOpen == 1 {
  2951. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2952. // 查询该药品最后一次出库记录
  2953. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2954. var is_user_total int64
  2955. var no_user_total int64
  2956. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2957. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2958. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2959. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2960. }
  2961. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2962. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2963. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2964. no_user_total += prescribingNumberSevenTy
  2965. }
  2966. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2967. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2968. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2969. no_user_total += prescribingNumberSevenTy
  2970. }
  2971. if len(druginfo) > 0 {
  2972. for _, it := range druginfo {
  2973. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2974. it.Count = it.Count * drug.MinNumber
  2975. is_user_total += it.Count
  2976. }
  2977. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2978. is_user_total += it.Count
  2979. }
  2980. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2981. is_user_total += it.Count
  2982. }
  2983. }
  2984. }
  2985. //fmt.Println("药品名称----------------------", drug.DrugName)
  2986. //fmt.Println("药品名称----------------------", drug.IsUse)
  2987. //fmt.Println("is_user_total-------------------------", is_user_total)
  2988. //fmt.Println("no_user_total-------------------------", no_user_total)
  2989. if is_user_total != no_user_total {
  2990. //出库
  2991. if drug.IsUse == 2 {
  2992. creater := adminInfo.AdminUser.Id
  2993. newadviceInfo := &models.HisDoctorAdviceInfo{
  2994. ID: s.ID,
  2995. UserOrgId: s.UserOrgId,
  2996. PatientId: s.PatientId,
  2997. HisPatientId: s.HisPatientId,
  2998. AdviceType: s.AdviceType,
  2999. AdviceDate: s.AdviceDate,
  3000. StartTime: s.StartTime,
  3001. AdviceName: s.AdviceName,
  3002. AdviceDesc: s.AdviceDesc,
  3003. ReminderDate: s.ReminderDate,
  3004. SingleDose: s.SingleDose,
  3005. SingleDoseUnit: s.SingleDoseUnit,
  3006. PrescribingNumber: s.PrescribingNumber,
  3007. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3008. DeliveryWay: s.DeliveryWay,
  3009. ExecutionFrequency: s.ExecutionFrequency,
  3010. AdviceDoctor: s.AdviceDoctor,
  3011. Status: s.Status,
  3012. CreatedTime: s.CreatedTime,
  3013. UpdatedTime: s.UpdatedTime,
  3014. AdviceAffirm: s.AdviceAffirm,
  3015. Remark: s.Remark,
  3016. StopTime: s.StopTime,
  3017. StopReason: s.StopReason,
  3018. StopDoctor: s.StopDoctor,
  3019. StopState: s.StopState,
  3020. ParentId: s.ParentId,
  3021. ExecutionTime: s.ExecutionTime,
  3022. ExecutionStaff: s.ExecutionStaff,
  3023. ExecutionState: s.ExecutionState,
  3024. Checker: s.Checker,
  3025. RecordDate: s.RecordDate,
  3026. DialysisOrderId: s.DialysisOrderId,
  3027. CheckTime: s.CheckTime,
  3028. CheckState: s.CheckState,
  3029. DrugSpec: s.DrugSpec,
  3030. DrugSpecUnit: s.DrugSpecUnit,
  3031. Groupno: s.Groupno,
  3032. RemindType: s.RemindType,
  3033. FrequencyType: s.FrequencyType,
  3034. DayCount: s.DayCount,
  3035. WeekDay: s.WeekDay,
  3036. TemplateId: s.TemplateId,
  3037. Modifier: s.Modifier,
  3038. DrugId: s.DrugId,
  3039. Price: s.Price,
  3040. PrescriptionId: s.PrescriptionId,
  3041. MedListCodg: s.MedListCodg,
  3042. FeedetlSn: s.FeedetlSn,
  3043. Day: s.DayCount,
  3044. ChildDoctorAdvice: nil,
  3045. Drug: models.Drug{},
  3046. Diagnosis: s.Diagnosis,
  3047. Way: s.Way,
  3048. HospApprFlag: s.HospApprFlag,
  3049. LmtUsedFlag: s.LmtUsedFlag,
  3050. HisOrderInfo: models.HisOrderInfo{},
  3051. IsMedicine: s.IsMedicine,
  3052. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3053. Child: nil,
  3054. IsSettle: s.IsSettle,
  3055. IsMobile: s.IsMobile,
  3056. IsSelfDrug: s.IsSelfDrug,
  3057. DrugWayCount: s.DrugWayCount,
  3058. }
  3059. var history_count int64
  3060. var local_count int64
  3061. //查找已经开过的医嘱信息
  3062. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3063. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3064. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3065. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3066. local_count += prescribingNumberSevenTy * drug.MinNumber
  3067. }
  3068. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3069. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3070. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3071. local_count += prescribingNumberSevenTy
  3072. }
  3073. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3074. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3075. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3076. local_count += prescribingNumberSevenTy
  3077. }
  3078. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3079. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3080. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3081. history_count += prescribingNumberSevenTy * drug.MinNumber
  3082. }
  3083. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3084. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3085. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3086. history_count += prescribingNumberSevenTy
  3087. }
  3088. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3089. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3090. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3091. history_count += prescribingNumberSevenTy
  3092. }
  3093. //如果当前出库数量大于历史出库数量则需要出库
  3094. if local_count > history_count {
  3095. //按最小单位出库
  3096. var cha_count = local_count - history_count
  3097. newadviceInfo.PrescribingNumber = float64(cha_count)
  3098. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3099. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3100. }
  3101. //如果当前出库数量小于历史出库数量则需要退库
  3102. if local_count < history_count {
  3103. var cha_count = history_count - local_count
  3104. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3105. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3106. }
  3107. if local_count == history_count {
  3108. if is_user_total == 0 {
  3109. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3110. }
  3111. }
  3112. }
  3113. //更新字典里面的库存
  3114. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3115. var sum_count int64
  3116. for _, its := range stockInfo {
  3117. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3118. if its.MaxUnit == baseDrug.MaxUnit {
  3119. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3120. }
  3121. sum_count += its.StockMaxNumber + its.StockMinNumber
  3122. }
  3123. //更新基础库存
  3124. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3125. //剩余库存
  3126. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3127. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3128. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3129. //创建医嘱
  3130. service.CreateHisDoctorAdviceOne(&s, tx)
  3131. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3132. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3133. if len(outInfoTwo) > 0 {
  3134. for _, item := range outInfoTwo {
  3135. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3136. }
  3137. }
  3138. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3139. if len(drugAutoDetail) > 0 {
  3140. for _, item := range drugAutoDetail {
  3141. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3142. }
  3143. }
  3144. }
  3145. }
  3146. }
  3147. //记录日志
  3148. byterequest, _ := json.Marshal(s)
  3149. adviceLog := models.XtDoctorAdviceLog{
  3150. UserOrgId: s.UserOrgId,
  3151. PatientId: s.PatientId,
  3152. AdminUserId: adminInfo.AdminUser.Id,
  3153. Module: 1,
  3154. ErrLog: string(byterequest),
  3155. Status: 1,
  3156. Ctime: time.Now().Unix(),
  3157. Mtime: 0,
  3158. Source: "电脑端新建his医嘱",
  3159. RecordDate: s.AdviceDate,
  3160. }
  3161. service.CreateDoctorAdviceLog(adviceLog)
  3162. //存储切片中
  3163. adviceList = append(adviceList, s)
  3164. redis := service.RedisClient()
  3165. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3166. redis.Set(key, "", time.Second)
  3167. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3168. redis.Set(keyOne, "", time.Second)
  3169. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3170. redis.Set(keySeven, "", time.Second)
  3171. var randNum int
  3172. randNum = rand.Intn(10000) + 1000
  3173. timestamp := time.Now().Unix()
  3174. tempTime := time.Unix(timestamp, 0)
  3175. timeFormat := tempTime.Format("20060102150405")
  3176. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3177. //查询改药品是否已经停用
  3178. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3179. if base.ID > 0 {
  3180. tx.Rollback()
  3181. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3182. return
  3183. }
  3184. service.CreateHisDoctorAdviceOne(&s, tx)
  3185. tx.Commit()
  3186. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3187. redis.Set(keySix, "", time.Second)
  3188. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3189. redis.Set(keyFive, "", time.Second)
  3190. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3191. redis.Set(keyEight, "", time.Second)
  3192. defer redis.Close()
  3193. }
  3194. }
  3195. }
  3196. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3197. projects := items["project"].([]interface{})
  3198. if len(projects) > 0 {
  3199. for _, project := range projects {
  3200. tx := db.Begin()
  3201. // 在函数结束时处理事务回滚
  3202. defer func() {
  3203. if r := recover(); r != nil {
  3204. tx.Rollback()
  3205. }
  3206. }()
  3207. var p models.HisPrescriptionProject
  3208. p.PrescriptionId = tempPrescription.ID
  3209. p.PatientId = patient_id
  3210. p.RecordDate = theTime3.Unix()
  3211. p.Doctor = doctor_id
  3212. p.UserOrgId = adminInfo.CurrentOrgId
  3213. p.HisPatientId = his_patient_id
  3214. p.Status = 1
  3215. p.StartTime = pTime
  3216. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3217. if errcode > 0 {
  3218. c.ServeFailJSONWithSGJErrorCode(errcode)
  3219. return
  3220. }
  3221. if p.ID == 0 {
  3222. p.IsOut = 2
  3223. }
  3224. if p.ID > 0 {
  3225. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3226. p.IsOut = projectDetail.IsOut
  3227. }
  3228. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
  3229. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3230. if p.Type == 3 {
  3231. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3232. if p.Price != lastWarehouse.PackingPrice {
  3233. p.Price = lastWarehouse.PackingPrice
  3234. }
  3235. if p.Price == 0 {
  3236. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3237. p.Price = lastWarehouseTwo.PackingPrice
  3238. }
  3239. if p.Unit == "" {
  3240. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3241. p.Unit = goodInfoOne.PackingUnit
  3242. }
  3243. }
  3244. }
  3245. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3246. //
  3247. // if p.Type == 3 {
  3248. // //查询该耗材是否停用
  3249. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3250. // //表示该耗材已经停用,不能保存
  3251. // if goodInfoSeven.ID == 0 {
  3252. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3253. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3254. // return
  3255. // }
  3256. // }
  3257. //
  3258. //}
  3259. //查询保存耗材出库开关是否打开
  3260. if p.PatientId != 30038 {
  3261. if goodOutConfig.IsOpen == 1 {
  3262. //耗材出库
  3263. if p.Type == 3 {
  3264. //对比当前数据和历史出库数据
  3265. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3266. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3267. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3268. //如果当前处方数量大于历史数据,则需要出库
  3269. if nowCount > historyCount {
  3270. var cha_count int64
  3271. cha_count = nowCount - historyCount
  3272. timeStr := time.Now().Format("2006-01-02")
  3273. timeArr := strings.Split(timeStr, "-")
  3274. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3275. total = total + 1
  3276. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3277. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3278. number = number + total
  3279. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3280. operation_time := time.Now().Unix()
  3281. creater := c.GetAdminUserInfo().AdminUser.Id
  3282. recordDateStr := time.Now().Format("2006-01-02")
  3283. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3284. nowtime := recordDate.Unix()
  3285. warehouseOut := models.WarehouseOut{
  3286. WarehouseOutOrderNumber: warehousing_out_order,
  3287. OperationTime: operation_time,
  3288. OrgId: adminInfo.CurrentOrgId,
  3289. Creater: creater,
  3290. Ctime: time.Now().Unix(),
  3291. Status: 1,
  3292. WarehouseOutTime: nowtime,
  3293. Type: 1,
  3294. StorehouseId: storeConfig.StorehouseOutInfo,
  3295. IsCheck: 1,
  3296. IsSys: 1,
  3297. }
  3298. //查询是否生成出库单
  3299. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3300. if out.ID == 0 {
  3301. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3302. }
  3303. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3304. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3305. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3306. dialyPrepareOne := models.DialysisBeforePrepare{
  3307. GoodTypeId: goodObj.GoodTypeId,
  3308. GoodId: p.ProjectId,
  3309. PatientId: p.PatientId,
  3310. RecordDate: p.RecordDate,
  3311. UserOrgId: adminInfo.CurrentOrgId,
  3312. Count: cha_count,
  3313. Ctime: time.Now().Unix(),
  3314. Creater: creater,
  3315. Status: 1,
  3316. StorehouseId: houseConfig.StorehouseOutInfo,
  3317. ProjectId: p.ID,
  3318. }
  3319. //出库
  3320. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3321. }
  3322. //如果当前处方数量小于历史数据,怎需要退库
  3323. if nowCount < historyCount {
  3324. var cha_count int64
  3325. cha_count = historyCount - nowCount
  3326. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3327. creater := c.GetAdminUserInfo().AdminUser.Id
  3328. newPrescriptionProject := &models.HisPrescriptionProject{
  3329. ID: p.ID,
  3330. ProjectId: p.ProjectId,
  3331. Price: p.Price,
  3332. UserOrgId: p.UserOrgId,
  3333. Status: 1,
  3334. Ctime: time.Now().Unix(),
  3335. Mtime: time.Now().Unix(),
  3336. PatientId: p.PatientId,
  3337. HisPatientId: p.HisPatientId,
  3338. RecordDate: p.RecordDate,
  3339. PrescriptionId: p.PrescriptionId,
  3340. Count: p.Count,
  3341. FeedetlSn: p.FeedetlSn,
  3342. MedListCodg: p.MedListCodg,
  3343. SingleDose: p.SingleDose,
  3344. DeliveryWay: p.DeliveryWay,
  3345. ExecutionFrequency: p.ExecutionFrequency,
  3346. Day: p.Day,
  3347. HisProject: models.HisProject{},
  3348. GoodInfo: models.GoodInfo{},
  3349. Remark: p.Remark,
  3350. Unit: p.Unit,
  3351. Type: p.Type,
  3352. Doctor: p.Doctor,
  3353. ExecutionTime: p.ExecutionTime,
  3354. ExecutionStaff: p.ExecutionStaff,
  3355. ExecutionState: p.ExecutionState,
  3356. CheckTime: p.CheckTime,
  3357. CheckState: p.CheckState,
  3358. Checker: p.Checker,
  3359. StartTime: p.StartTime,
  3360. TeamId: p.TeamId,
  3361. XtHisProjectTeam: models.XtHisProjectTeam{},
  3362. FrequencyType: p.FrequencyType,
  3363. DayCount: p.DayCount,
  3364. WeekDay: p.WeekDay,
  3365. IsCheckTeam: p.IsCheckTeam,
  3366. HisOrderInfo: models.HisOrderInfo{},
  3367. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3368. IsOut: p.IsOut,
  3369. YbSyncStatus: p.YbSyncStatus,
  3370. }
  3371. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3372. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3373. }
  3374. if nowCount == historyCount {
  3375. if historyCount == 0 {
  3376. recordDateStr := time.Now().Format("2006-01-02")
  3377. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3378. nowtime := recordDate.Unix()
  3379. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3380. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3381. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3382. creater := c.GetAdminUserInfo().AdminUser.Id
  3383. dialyPrepareOne := models.DialysisBeforePrepare{
  3384. GoodTypeId: goodObj.GoodTypeId,
  3385. GoodId: p.ProjectId,
  3386. PatientId: p.PatientId,
  3387. RecordDate: p.RecordDate,
  3388. UserOrgId: adminInfo.CurrentOrgId,
  3389. Count: nowCount,
  3390. Ctime: time.Now().Unix(),
  3391. Creater: creater,
  3392. Status: 1,
  3393. StorehouseId: houseConfig.StorehouseOutInfo,
  3394. ProjectId: p.ID,
  3395. }
  3396. //出库
  3397. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3398. }
  3399. }
  3400. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3401. ////查询历史出库数据
  3402. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3403. //
  3404. //var out_count_five int64
  3405. //for _, item := range flowGood {
  3406. // out_count_five += item.Count
  3407. //}
  3408. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3409. //
  3410. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3411. //if out_count_five != parseIntCount {
  3412. // //查询耗材最后一次出库记录
  3413. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3414. // //查询默认出库仓库库存
  3415. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3416. // if len(wareOut) > 0 {
  3417. //
  3418. // for _, it := range wareOut {
  3419. // //回退库存
  3420. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3421. //
  3422. // //删除出库记录
  3423. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3424. //
  3425. // }
  3426. // }
  3427. //
  3428. // timeStr := time.Now().Format("2006-01-02")
  3429. // timeArr := strings.Split(timeStr, "-")
  3430. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3431. //
  3432. // total = total + 1
  3433. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3434. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3435. // number = number + total
  3436. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3437. //
  3438. // operation_time := time.Now().Unix()
  3439. // creater := c.GetAdminUserInfo().AdminUser.Id
  3440. //
  3441. // recordDateStr := time.Now().Format("2006-01-02")
  3442. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3443. // nowtime := recordDate.Unix()
  3444. // warehouseOut := models.WarehouseOut{
  3445. // WarehouseOutOrderNumber: warehousing_out_order,
  3446. // OperationTime: operation_time,
  3447. // OrgId: adminInfo.CurrentOrgId,
  3448. // Creater: creater,
  3449. // Ctime: time.Now().Unix(),
  3450. // Status: 1,
  3451. // WarehouseOutTime: nowtime,
  3452. // Type: 1,
  3453. // StorehouseId: storeConfig.StorehouseOutInfo,
  3454. // IsCheck: 1,
  3455. // IsSys: 1,
  3456. // }
  3457. // //查询是否生成出库单
  3458. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3459. // if out.ID == 0 {
  3460. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3461. // }
  3462. //
  3463. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3464. //
  3465. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3466. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3467. //
  3468. // dialyPrepareOne := models.DialysisBeforePrepare{
  3469. // GoodTypeId: goodObj.GoodTypeId,
  3470. // GoodId: p.ProjectId,
  3471. // PatientId: p.PatientId,
  3472. // RecordDate: p.RecordDate,
  3473. // UserOrgId: adminInfo.CurrentOrgId,
  3474. // Count: parseIntCount,
  3475. // Ctime: time.Now().Unix(),
  3476. // Creater: creater,
  3477. // Status: 1,
  3478. // StorehouseId: houseConfig.StorehouseOutInfo,
  3479. // ProjectId: lastHisProject.ID,
  3480. // }
  3481. // //判断是否是零用耗材(非零用)
  3482. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3483. //
  3484. // //查询历史出库数据
  3485. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3486. // var out_count int64
  3487. // for _, item := range flowGood {
  3488. // out_count += item.Count
  3489. // }
  3490. // //如果历史数和当前数据不想等才进行退库出库
  3491. // if out_count != parseIntCount {
  3492. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3493. //
  3494. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3495. // detail := models.AutomaticReduceDetail{
  3496. // WarehouseOutId: 0,
  3497. // WarehouseOutOrderNumber: "",
  3498. // PatientId: p.PatientId,
  3499. // Ctime: time.Now().Unix(),
  3500. // Mtime: 0,
  3501. // Status: 1,
  3502. // RecordTime: p.RecordDate,
  3503. // OrgId: p.UserOrgId,
  3504. // GoodId: p.ProjectId,
  3505. // GoodTypeId: 0,
  3506. // Count: parseIntCount,
  3507. // Type: 0,
  3508. // ProjectId: lastHisProject.ID,
  3509. // StorehouseId: 0,
  3510. // }
  3511. //
  3512. // service.CreateNewAutoDetail(detail, tx)
  3513. //
  3514. // //查询剩余库存
  3515. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3516. // var sum_count int64
  3517. // for _, item := range goodList {
  3518. // sum_count += item.StockCount
  3519. // }
  3520. //
  3521. // //更新剩余库存
  3522. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3523. //
  3524. // //耗材
  3525. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3526. //
  3527. // }
  3528. // //判断是否是零用耗材(零用但是是出库耗材)
  3529. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3530. //
  3531. // //查询历史出库数据
  3532. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3533. // var out_count int64
  3534. // for _, item := range flowGood {
  3535. // out_count += item.Count
  3536. // }
  3537. // //如果历史数和当前数据不想等才进行退库出库
  3538. // if out_count != parseIntCount {
  3539. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3540. //
  3541. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3542. // detail := models.AutomaticReduceDetail{
  3543. // WarehouseOutId: 0,
  3544. // WarehouseOutOrderNumber: "",
  3545. // PatientId: p.PatientId,
  3546. // Ctime: time.Now().Unix(),
  3547. // Mtime: 0,
  3548. // Status: 1,
  3549. // RecordTime: p.RecordDate,
  3550. // OrgId: p.UserOrgId,
  3551. // GoodId: p.ProjectId,
  3552. // GoodTypeId: 0,
  3553. // Count: parseIntCount,
  3554. // Type: 0,
  3555. // ProjectId: p.ID,
  3556. // StorehouseId: 0,
  3557. // }
  3558. //
  3559. // service.CreateNewAutoDetail(detail, tx)
  3560. //
  3561. // //查询剩余库存
  3562. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3563. // var sum_count int64
  3564. // for _, item := range goodList {
  3565. // sum_count += item.StockCount
  3566. // }
  3567. //
  3568. // //更新剩余库存
  3569. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3570. //
  3571. // //耗材
  3572. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3573. // }
  3574. //
  3575. // }
  3576. //
  3577. // }
  3578. //
  3579. //}
  3580. //记录日志
  3581. byterequest, _ := json.Marshal(p)
  3582. adviceLog := models.XtDoctorAdviceLog{
  3583. UserOrgId: p.UserOrgId,
  3584. PatientId: p.PatientId,
  3585. AdminUserId: adminInfo.AdminUser.Id,
  3586. Module: 1,
  3587. ErrLog: string(byterequest),
  3588. Status: 1,
  3589. Ctime: time.Now().Unix(),
  3590. Mtime: 0,
  3591. Source: "电脑端新建his项目",
  3592. RecordDate: p.RecordDate,
  3593. }
  3594. service.CreateDoctorAdviceLog(adviceLog)
  3595. projectList = append(projectList, p)
  3596. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3597. //新增或者编辑项目,修改对应的标签数据
  3598. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3599. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3600. var label models.HisLabelPrintInfo
  3601. project, _ := service.GetProjectDetail(p.ProjectId)
  3602. if project.CostClassify == 3 { //类别为检验检查
  3603. if p.TeamId > 0 { //检验检查组套
  3604. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3605. if tempLabel.ID == 0 {
  3606. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3607. label.Number = tempPrescription.PrescriptionNumber
  3608. label.ProjectId = project.ID
  3609. label.Status = 1
  3610. label.IsPrint = 2
  3611. label.DoctorId = info.DoctorId
  3612. label.UserOrgId = p.UserOrgId
  3613. label.PatientId = patient_id
  3614. label.RecordDate = recordDateTime
  3615. label.Ctime = time.Now().Unix()
  3616. label.Mtime = time.Now().Unix()
  3617. label.ItemId = p.TeamId
  3618. label.FeedetlSn = p.FeedetlSn
  3619. label.PProjectId = p.ID
  3620. label.ProjectName = team.ProjectTeam
  3621. label.PatientName = patient.Name
  3622. service.CreateNewHisLabelRecord(&label, tx)
  3623. }
  3624. } else { //单条检验检查项目
  3625. label.Number = tempPrescription.PrescriptionNumber
  3626. label.ProjectId = project.ID
  3627. label.Status = 1
  3628. label.DoctorId = info.DoctorId
  3629. label.UserOrgId = p.UserOrgId
  3630. label.PatientId = patient_id
  3631. label.RecordDate = recordDateTime
  3632. label.IsPrint = 2
  3633. label.Ctime = time.Now().Unix()
  3634. label.Mtime = time.Now().Unix()
  3635. label.FeedetlSn = p.FeedetlSn
  3636. label.PProjectId = p.ID
  3637. label.ItemId = p.TeamId
  3638. label.ProjectName = project.ProjectName
  3639. label.PatientName = patient.Name
  3640. service.CreateNewHisLabelRecord(&label, tx)
  3641. }
  3642. }
  3643. }
  3644. }
  3645. }
  3646. }
  3647. }
  3648. service.CreateNewHisProjectTwo(&p, tx)
  3649. var randNum int
  3650. randNum = rand.Intn(10000) + 1000
  3651. timestamp := time.Now().Unix()
  3652. tempTime := time.Unix(timestamp, 0)
  3653. timeFormat := tempTime.Format("20060102150405")
  3654. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3655. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3656. if goodBase.ID > 0 {
  3657. tx.Rollback()
  3658. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3659. return
  3660. }
  3661. service.CreateNewHisProjectTwo(&p, tx)
  3662. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3663. //查询剩余库存
  3664. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3665. var sum_count int64
  3666. for _, item := range goodList {
  3667. sum_count += item.StockCount
  3668. }
  3669. //更新剩余库存
  3670. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3671. //耗材
  3672. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3673. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3674. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3675. if len(outInfoTwo) > 0 {
  3676. for _, item := range outInfoTwo {
  3677. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3678. }
  3679. }
  3680. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3681. if len(drugAutoDetail) > 0 {
  3682. for _, item := range drugAutoDetail {
  3683. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3684. }
  3685. }
  3686. tx.Commit()
  3687. }
  3688. }
  3689. }
  3690. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3691. // addition := items["addition"].([]interface{})
  3692. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3693. // ctime := time.Now().Unix()
  3694. // mtime := ctime
  3695. // if len(addition) > 0 {
  3696. // for _, item := range addition {
  3697. // var s models.HisAdditionalCharge
  3698. // s.PrescriptionId = tempPrescription.ID
  3699. // s.Status = 1
  3700. // s.UserOrgId = adminInfo.CurrentOrgId
  3701. // s.RecordDate = recordDateTime
  3702. // s.CreatedTime = ctime
  3703. // s.UpdatedTime = mtime
  3704. // s.PatientId = patient_id
  3705. // s.HisPatientId = his_patient_id
  3706. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3707. // if errcode > 0 {
  3708. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3709. // return
  3710. // }
  3711. // service.CreateAdditionalCharge(&s)
  3712. // var randNum int
  3713. // randNum = rand.Intn(10000) + 1000
  3714. // timestamp := time.Now().Unix()
  3715. // tempTime := time.Unix(timestamp, 0)
  3716. // timeFormat := tempTime.Format("20060102150405")
  3717. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3718. // service.CreateAdditionalCharge(&s)
  3719. //
  3720. // }
  3721. // }
  3722. //}
  3723. }
  3724. }
  3725. }
  3726. tx.Commit()
  3727. if err == nil {
  3728. c.ServeSuccessJSON(map[string]interface{}{
  3729. "msg": "保存成功",
  3730. })
  3731. return
  3732. } else {
  3733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3734. return
  3735. }
  3736. } else {
  3737. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3738. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3739. var tempPrescription *models.HisPrescription
  3740. if len(prescriptions) > 0 {
  3741. for _, item := range prescriptions {
  3742. items := item.(map[string]interface{})
  3743. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3744. utils.ErrorLog("id")
  3745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3746. return
  3747. }
  3748. id := int64(items["id"].(float64))
  3749. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3750. tempPrescription = &new_prescription
  3751. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3752. utils.ErrorLog("type")
  3753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3754. return
  3755. }
  3756. types := int64(items["type"].(float64))
  3757. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3758. utils.ErrorLog("med_type")
  3759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3760. return
  3761. }
  3762. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3763. if med_type == "0" {
  3764. med_type = "14"
  3765. }
  3766. //if order_status == 0 {
  3767. // order_status = 1
  3768. //}
  3769. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3770. utils.ErrorLog("pre_time")
  3771. }
  3772. preTime, _ := items["pre_time"].(string)
  3773. timeLayout := "2006-01-02"
  3774. loc, _ := time.LoadLocation("Local")
  3775. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3776. result := strings.Split(preTime, " ")
  3777. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3778. if err != nil {
  3779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3780. return
  3781. }
  3782. pTime := theTime2.Unix()
  3783. ctime := time.Now().Unix()
  3784. if tempPrescription.ID == 0 {
  3785. prescription := &models.HisPrescription{
  3786. ID: 0,
  3787. PatientId: patient_id,
  3788. UserOrgId: adminInfo.CurrentOrgId,
  3789. RecordDate: recordDateTime,
  3790. Ctime: ctime,
  3791. Mtime: ctime,
  3792. Type: types,
  3793. Modifier: adminInfo.AdminUser.Id,
  3794. Creator: adminInfo.AdminUser.Id,
  3795. Status: 1,
  3796. Doctor: role.UserName,
  3797. HisPatientId: his_patient_id,
  3798. OrderStatus: 1,
  3799. BatchNumber: "",
  3800. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3801. PreTime: pTime,
  3802. PType: p_type,
  3803. MedType: med_type,
  3804. }
  3805. tempPrescription = prescription
  3806. service.SaveHisPrescription(tempPrescription)
  3807. redis := service.RedisClient()
  3808. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3809. redis.Set(key, "", time.Second)
  3810. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3811. redis.Set(keyOne, "", time.Second)
  3812. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3813. redis.Set(keySeven, "", time.Second)
  3814. defer redis.Close()
  3815. } else {
  3816. tempPrescription.ID = id
  3817. tempPrescription.Type = types
  3818. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3819. tempPrescription.Mtime = time.Now().Unix()
  3820. tempPrescription.Doctor = role.UserName
  3821. //tempPrescription.OrderStatus = order_status
  3822. tempPrescription.PreTime = pTime
  3823. tempPrescription.MedType = med_type
  3824. service.SaveHisPrescription(tempPrescription)
  3825. redis := service.RedisClient()
  3826. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3827. redis.Set(key, "", time.Second)
  3828. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3829. redis.Set(keyOne, "", time.Second)
  3830. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3831. redis.Set(keySeven, "", time.Second)
  3832. defer redis.Close()
  3833. }
  3834. //service.SaveHisPrescription(prescription)
  3835. //更改患者挂号状态
  3836. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3837. fmt.Println("更改失败", err2)
  3838. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3839. advices := items["advices"].([]interface{})
  3840. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3841. groupNo := int64(0)
  3842. if len(advices) > 0 {
  3843. for _, advice := range advices {
  3844. var s models.HisDoctorAdviceInfo
  3845. s.PrescriptionId = tempPrescription.ID
  3846. s.AdviceType = 2
  3847. s.AdviceDoctor = doctor_id
  3848. s.StopState = 2
  3849. s.ExecutionState = 2
  3850. s.AdviceDate = theTime3.Unix()
  3851. s.Status = 1
  3852. s.UserOrgId = adminInfo.CurrentOrgId
  3853. s.RecordDate = theTime3.Unix()
  3854. s.StartTime = tempPrescription.PreTime
  3855. s.Groupno = groupNo
  3856. s.PatientId = patient_id
  3857. s.HisPatientId = his_patient_id
  3858. s.StartTime = pTime
  3859. s.IsSettle = 2
  3860. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3861. if errcode > 0 {
  3862. c.ServeFailJSONWithSGJErrorCode(errcode)
  3863. return
  3864. }
  3865. s.StartTime = pTime
  3866. var total_count int64 //处方总库存
  3867. //查询改药品信息
  3868. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3869. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3870. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3871. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3872. total_count += prescribingNumberSeven * medical.MinNumber
  3873. }
  3874. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3875. total_count += prescribingNumberSeven
  3876. }
  3877. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3878. total_count += prescribingNumberSeven
  3879. }
  3880. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3881. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3882. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3883. if s.Price != lastWarehouse.RetailPrice {
  3884. s.Price = lastWarehouse.RetailPrice
  3885. }
  3886. if s.Price == 0 {
  3887. if lastWarehouse.ID == 0 {
  3888. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3889. s.Price = lastWarehouseTwo.RetailPrice
  3890. }
  3891. }
  3892. }
  3893. service.CreateHisDoctorAdvice(&s)
  3894. //记录日志
  3895. byterequest, _ := json.Marshal(s)
  3896. adviceLog := models.XtDoctorAdviceLog{
  3897. UserOrgId: s.UserOrgId,
  3898. PatientId: s.PatientId,
  3899. AdminUserId: adminInfo.AdminUser.Id,
  3900. Module: 1,
  3901. ErrLog: string(byterequest),
  3902. Status: 1,
  3903. Ctime: time.Now().Unix(),
  3904. Mtime: 0,
  3905. Source: "电脑端新建his医嘱",
  3906. RecordDate: s.AdviceDate,
  3907. }
  3908. service.CreateDoctorAdviceLog(adviceLog)
  3909. //存储切片中
  3910. adviceList = append(adviceList, s)
  3911. redis := service.RedisClient()
  3912. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3913. redis.Set(key, "", time.Second)
  3914. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3915. redis.Set(keyOne, "", time.Second)
  3916. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3917. redis.Set(keySeven, "", time.Second)
  3918. var randNum int
  3919. randNum = rand.Intn(10000) + 1000
  3920. timestamp := time.Now().Unix()
  3921. tempTime := time.Unix(timestamp, 0)
  3922. timeFormat := tempTime.Format("20060102150405")
  3923. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3924. service.CreateHisDoctorAdvice(&s)
  3925. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3926. redis.Set(keySix, "", time.Second)
  3927. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3928. redis.Set(keyFive, "", time.Second)
  3929. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3930. redis.Set(keyEight, "", time.Second)
  3931. defer redis.Close()
  3932. }
  3933. }
  3934. }
  3935. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3936. projects := items["project"].([]interface{})
  3937. if len(projects) > 0 {
  3938. for _, project := range projects {
  3939. var p models.HisPrescriptionProject
  3940. p.PrescriptionId = tempPrescription.ID
  3941. p.PatientId = patient_id
  3942. p.RecordDate = theTime3.Unix()
  3943. p.Doctor = doctor_id
  3944. p.UserOrgId = adminInfo.CurrentOrgId
  3945. p.HisPatientId = his_patient_id
  3946. p.Status = 1
  3947. p.StartTime = pTime
  3948. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3949. if errcode > 0 {
  3950. c.ServeFailJSONWithSGJErrorCode(errcode)
  3951. return
  3952. }
  3953. if p.ID == 0 {
  3954. p.IsOut = 2
  3955. }
  3956. if p.ID > 0 {
  3957. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3958. p.IsOut = projectDetail.IsOut
  3959. }
  3960. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3961. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3962. if p.Type == 3 {
  3963. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3964. if p.Price != lastWarehouse.PackingPrice {
  3965. p.Price = lastWarehouse.PackingPrice
  3966. }
  3967. if p.Price == 0 {
  3968. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3969. p.Price = lastWarehouseTwo.PackingPrice
  3970. }
  3971. if p.Unit == "" {
  3972. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3973. p.Unit = goodInfoOne.PackingUnit
  3974. }
  3975. }
  3976. }
  3977. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3978. //
  3979. // if p.Type == 3 {
  3980. // //查询该耗材是否停用
  3981. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3982. // //表示该耗材已经停用,不能保存
  3983. // if goodInfoSeven.ID == 0 {
  3984. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3985. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3986. // return
  3987. // }
  3988. // }
  3989. //
  3990. //}
  3991. service.CreateHisProjectTwo(&p)
  3992. //记录日志
  3993. byterequest, _ := json.Marshal(p)
  3994. adviceLog := models.XtDoctorAdviceLog{
  3995. UserOrgId: p.UserOrgId,
  3996. PatientId: p.PatientId,
  3997. AdminUserId: adminInfo.AdminUser.Id,
  3998. Module: 1,
  3999. ErrLog: string(byterequest),
  4000. Status: 1,
  4001. Ctime: time.Now().Unix(),
  4002. Mtime: 0,
  4003. Source: "电脑端新建his项目",
  4004. RecordDate: p.RecordDate,
  4005. }
  4006. service.CreateDoctorAdviceLog(adviceLog)
  4007. projectList = append(projectList, p)
  4008. var randNum int
  4009. randNum = rand.Intn(10000) + 1000
  4010. timestamp := time.Now().Unix()
  4011. tempTime := time.Unix(timestamp, 0)
  4012. timeFormat := tempTime.Format("20060102150405")
  4013. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4014. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4015. //新增或者编辑项目,修改对应的标签数据
  4016. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4017. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4018. var label models.HisLabelPrintInfo
  4019. project, _ := service.GetProjectDetail(p.ProjectId)
  4020. if project.CostClassify == 3 { //类别为检验检查
  4021. if p.TeamId > 0 { //检验检查组套
  4022. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4023. if tempLabel.ID == 0 {
  4024. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4025. label.Number = tempPrescription.PrescriptionNumber
  4026. label.ProjectId = project.ID
  4027. label.Status = 1
  4028. label.IsPrint = 2
  4029. label.DoctorId = info.DoctorId
  4030. label.UserOrgId = p.UserOrgId
  4031. label.PatientId = patient_id
  4032. label.RecordDate = recordDateTime
  4033. label.Ctime = time.Now().Unix()
  4034. label.Mtime = time.Now().Unix()
  4035. label.ItemId = p.TeamId
  4036. label.FeedetlSn = p.FeedetlSn
  4037. label.PProjectId = p.ID
  4038. label.ProjectName = team.ProjectTeam
  4039. label.PatientName = patient.Name
  4040. service.CreateHisLabelRecord(&label)
  4041. }
  4042. } else { //单条检验检查项目
  4043. label.Number = tempPrescription.PrescriptionNumber
  4044. label.ProjectId = project.ID
  4045. label.Status = 1
  4046. label.DoctorId = info.DoctorId
  4047. label.UserOrgId = p.UserOrgId
  4048. label.PatientId = patient_id
  4049. label.RecordDate = recordDateTime
  4050. label.IsPrint = 2
  4051. label.Ctime = time.Now().Unix()
  4052. label.Mtime = time.Now().Unix()
  4053. label.FeedetlSn = p.FeedetlSn
  4054. label.PProjectId = p.ID
  4055. label.ItemId = p.TeamId
  4056. label.ProjectName = project.ProjectName
  4057. label.PatientName = patient.Name
  4058. service.CreateHisLabelRecord(&label)
  4059. }
  4060. }
  4061. }
  4062. }
  4063. service.SaveHisProjectTwo(&p)
  4064. }
  4065. }
  4066. }
  4067. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4068. // addition := items["addition"].([]interface{})
  4069. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4070. // ctime := time.Now().Unix()
  4071. // mtime := ctime
  4072. // if len(addition) > 0 {
  4073. // for _, item := range addition {
  4074. // var s models.HisAdditionalCharge
  4075. // s.PrescriptionId = tempPrescription.ID
  4076. // s.Status = 1
  4077. // s.UserOrgId = adminInfo.CurrentOrgId
  4078. // s.RecordDate = recordDateTime
  4079. // s.CreatedTime = ctime
  4080. // s.UpdatedTime = mtime
  4081. // s.PatientId = patient_id
  4082. // s.HisPatientId = his_patient_id
  4083. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4084. // if errcode > 0 {
  4085. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4086. // return
  4087. // }
  4088. // service.CreateAdditionalCharge(&s)
  4089. // var randNum int
  4090. // randNum = rand.Intn(10000) + 1000
  4091. // timestamp := time.Now().Unix()
  4092. // tempTime := time.Unix(timestamp, 0)
  4093. // timeFormat := tempTime.Format("20060102150405")
  4094. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4095. // service.CreateAdditionalCharge(&s)
  4096. //
  4097. // }
  4098. // }
  4099. //}
  4100. }
  4101. }
  4102. //查询今日该患者开的药品处方
  4103. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4104. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4105. //药品出库
  4106. if drugOutConfig.IsOpen == 1 {
  4107. for _, item := range hisdoctorlist {
  4108. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4109. // 查询该药品最后一次出库记录
  4110. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4111. if len(druginfo) > 0 {
  4112. //回退库存
  4113. for _, it := range druginfo {
  4114. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4115. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4116. }
  4117. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4118. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4119. }
  4120. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4121. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4122. }
  4123. }
  4124. }
  4125. //删除记录
  4126. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4127. //查询最后一次数据
  4128. if drugOutConfig.IsOpen == 1 {
  4129. //出库
  4130. if drug.IsUse == 2 {
  4131. creater := adminInfo.AdminUser.Id
  4132. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4133. }
  4134. //更新字典里面的库存
  4135. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4136. var sum_count int64
  4137. for _, its := range stockInfo {
  4138. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4139. if its.MaxUnit == baseDrug.MaxUnit {
  4140. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4141. }
  4142. sum_count += its.StockMaxNumber + its.StockMinNumber
  4143. }
  4144. //更新基础库存
  4145. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4146. //剩余库存
  4147. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4148. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4149. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4150. }
  4151. }
  4152. }
  4153. //耗材保存处方出库
  4154. if goodOutConfig.IsOpen == 1 {
  4155. //查询今日耗材出库数量
  4156. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4157. for _, item := range hisgoodlist {
  4158. //查询历史出库数据
  4159. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4160. var out_count_five int64
  4161. for _, item := range flowGood {
  4162. out_count_five += item.Count
  4163. }
  4164. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4165. if out_count_five != parseIntCount {
  4166. //查询耗材最后一次出库记录
  4167. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4168. //查询默认出库仓库库存
  4169. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4170. if len(wareOut) > 0 {
  4171. for _, it := range wareOut {
  4172. //回退库存
  4173. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4174. //删除出库记录
  4175. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4176. }
  4177. }
  4178. timeStr := time.Now().Format("2006-01-02")
  4179. timeArr := strings.Split(timeStr, "-")
  4180. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4181. total = total + 1
  4182. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4183. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4184. number = number + total
  4185. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4186. operation_time := time.Now().Unix()
  4187. creater := c.GetAdminUserInfo().AdminUser.Id
  4188. recordDateStr := time.Now().Format("2006-01-02")
  4189. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4190. nowtime := recordDate.Unix()
  4191. warehouseOut := models.WarehouseOut{
  4192. WarehouseOutOrderNumber: warehousing_out_order,
  4193. OperationTime: operation_time,
  4194. OrgId: adminInfo.CurrentOrgId,
  4195. Creater: creater,
  4196. Ctime: time.Now().Unix(),
  4197. Status: 1,
  4198. WarehouseOutTime: nowtime,
  4199. Type: 1,
  4200. StorehouseId: storeConfig.StorehouseOutInfo,
  4201. IsCheck: 1,
  4202. IsSys: 1,
  4203. }
  4204. //查询是否生成出库单
  4205. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4206. if out.ID == 0 {
  4207. service.AddSigleWarehouseOut(&warehouseOut)
  4208. }
  4209. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4210. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4211. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4212. dialyPrepareOne := models.DialysisBeforePrepare{
  4213. GoodTypeId: goodObj.GoodTypeId,
  4214. GoodId: item.ProjectId,
  4215. PatientId: item.PatientId,
  4216. RecordDate: item.RecordDate,
  4217. UserOrgId: adminInfo.CurrentOrgId,
  4218. Count: parseIntCount,
  4219. Ctime: time.Now().Unix(),
  4220. Creater: creater,
  4221. Status: 1,
  4222. StorehouseId: houseConfig.StorehouseOutInfo,
  4223. ProjectId: item.ID,
  4224. }
  4225. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4226. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4227. //查询历史出库数据
  4228. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4229. var out_count int64
  4230. for _, item := range flowGood {
  4231. out_count += item.Count
  4232. }
  4233. //如果历史数和当前数据不想等才进行退库出库
  4234. if out_count != parseIntCount {
  4235. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4236. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4237. detail := models.AutomaticReduceDetail{
  4238. WarehouseOutId: 0,
  4239. WarehouseOutOrderNumber: "",
  4240. PatientId: item.PatientId,
  4241. Ctime: time.Now().Unix(),
  4242. Mtime: 0,
  4243. Status: 1,
  4244. RecordTime: item.RecordDate,
  4245. OrgId: item.UserOrgId,
  4246. GoodId: item.ProjectId,
  4247. GoodTypeId: 0,
  4248. Count: parseIntCount,
  4249. Type: 0,
  4250. ProjectId: item.ID,
  4251. StorehouseId: 0,
  4252. }
  4253. service.CreateAutoDetail(detail)
  4254. //查询剩余库存
  4255. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4256. var sum_count int64
  4257. for _, item := range goodList {
  4258. sum_count += item.StockCount
  4259. }
  4260. //更新剩余库存
  4261. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4262. //耗材
  4263. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4264. }
  4265. }
  4266. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4267. //查询历史出库数据
  4268. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4269. var out_count int64
  4270. for _, item := range flowGood {
  4271. out_count += item.Count
  4272. }
  4273. //如果历史数和当前数据不想等才进行退库出库
  4274. if out_count != parseIntCount {
  4275. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4276. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4277. detail := models.AutomaticReduceDetail{
  4278. WarehouseOutId: 0,
  4279. WarehouseOutOrderNumber: "",
  4280. PatientId: item.PatientId,
  4281. Ctime: time.Now().Unix(),
  4282. Mtime: 0,
  4283. Status: 1,
  4284. RecordTime: item.RecordDate,
  4285. OrgId: item.UserOrgId,
  4286. GoodId: item.ProjectId,
  4287. GoodTypeId: 0,
  4288. Count: parseIntCount,
  4289. Type: 0,
  4290. ProjectId: item.ID,
  4291. StorehouseId: 0,
  4292. }
  4293. service.CreateAutoDetail(detail)
  4294. //查询剩余库存
  4295. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4296. var sum_count int64
  4297. for _, item := range goodList {
  4298. sum_count += item.StockCount
  4299. }
  4300. //更新剩余库存
  4301. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4302. //耗材
  4303. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4304. }
  4305. }
  4306. }
  4307. }
  4308. }
  4309. ////同步到自备药
  4310. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4311. if selfPrescriptionOpen.IsOpen == 1 {
  4312. timeStr := time.Now().Format("2006-01-02")
  4313. timeArr := strings.Split(timeStr, "-")
  4314. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4315. total = total + 1
  4316. operation_time := time.Now().Unix()
  4317. creater := adminInfo.AdminUser.Id
  4318. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4319. warehousing := models.XtSelfDrugWarehouse{
  4320. WarehousingOrder: warehousing_order,
  4321. OperationTime: operation_time,
  4322. OrgId: adminInfo.CurrentOrgId,
  4323. Creater: creater,
  4324. Ctime: time.Now().Unix(),
  4325. Status: 1,
  4326. WarehousingTime: recordDateTime,
  4327. Type: 0,
  4328. StorehouseId: 0,
  4329. IsCheck: 1,
  4330. PatientId: patient_id,
  4331. IsSys: 1,
  4332. }
  4333. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4334. if selfDrugWarehouse.ID == 0 {
  4335. service.AddSelfDrugWarehouse(&warehousing, tx)
  4336. }
  4337. if selfDrugWarehouse.ID > 0 {
  4338. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4339. }
  4340. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4341. fmt.Println(info)
  4342. for _, item := range hisdoctorlist {
  4343. //查询该病人的该药品是否已经入库
  4344. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4345. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4346. var in_count int64
  4347. if len(selfdruginfo) > 0 {
  4348. for _, item := range selfdruginfo {
  4349. var in_count_one int64
  4350. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4351. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4352. }
  4353. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4354. in_count_one = item.WarehousingCount
  4355. }
  4356. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4357. in_count_one = item.WarehousingCount
  4358. }
  4359. in_count += in_count_one
  4360. }
  4361. }
  4362. if selfBasedrug.IsSelfDrug == 1 {
  4363. var total_count int64
  4364. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4365. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4366. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4367. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4368. }
  4369. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4370. total_count += prescribingNumberSeven
  4371. }
  4372. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4373. total_count += prescribingNumberSeven
  4374. }
  4375. //入库
  4376. if total_count > in_count {
  4377. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4378. WarehousingOrder: warehousing_order,
  4379. WarehousingId: info.ID,
  4380. DrugId: item.DrugId,
  4381. Number: "",
  4382. ProductDate: 0,
  4383. ExpiryDate: 0,
  4384. WarehousingCount: total_count - in_count,
  4385. WarehouseingUnit: selfBasedrug.MinUnit,
  4386. Price: 0,
  4387. TotalPrice: 0,
  4388. Status: 1,
  4389. Ctime: time.Now().Unix(),
  4390. Remark: "",
  4391. OrgId: adminInfo.CurrentOrgId,
  4392. Type: 0,
  4393. Manufacturer: selfBasedrug.Manufacturer,
  4394. Dealer: selfBasedrug.Dealer,
  4395. StockMaxNumber: total_count - in_count,
  4396. RetailTotalPrice: 0,
  4397. BatchNumber: "",
  4398. MaxUnit: selfBasedrug.MinUnit,
  4399. MinUnit: selfBasedrug.MinUnit,
  4400. RetailPrice: 0,
  4401. StorehouseId: 0,
  4402. IsCheck: 1,
  4403. StockMinNumber: 0,
  4404. PatientId: patient_id,
  4405. IsSys: 1,
  4406. RecordDate: item.RecordDate,
  4407. AdviceId: item.ID,
  4408. }
  4409. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4410. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4411. Creator := adminInfo.AdminUser.Id
  4412. //查询默认仓库剩余多少库存
  4413. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4414. var sum_count int64
  4415. for _, it := range list {
  4416. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4417. if it.MaxUnit == baseDrug.MaxUnit {
  4418. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4419. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4420. }
  4421. sum_count += it.StockMaxNumber + it.StockMinNumber
  4422. }
  4423. flow := &models.XtSelfDrugFlow{
  4424. WarehousingId: info.ID,
  4425. DrugId: item.DrugId,
  4426. Number: "",
  4427. BatchNumber: "",
  4428. Count: total_count - in_count,
  4429. UserOrgId: adminInfo.CurrentOrgId,
  4430. PatientId: item.PatientId,
  4431. SystemTime: time.Now().Unix(),
  4432. ConsumableType: 1,
  4433. IsSys: 1,
  4434. WarehousingOrder: warehousing_order,
  4435. WarehouseOutId: 0,
  4436. WarehouseOutOrderNumber: "",
  4437. IsEdit: 0,
  4438. CancelStockId: 0,
  4439. CancelOrderNumber: "",
  4440. Manufacturer: selfBasedrug.Manufacturer,
  4441. Dealer: selfBasedrug.Dealer,
  4442. Creator: Creator,
  4443. UpdateCreator: Creator,
  4444. Status: 1,
  4445. Ctime: item.AdviceDate,
  4446. Mtime: 0,
  4447. Price: item.Price,
  4448. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4449. WarehouseOutDetailId: 0,
  4450. CancelOutDetailId: 0,
  4451. ExpireDate: 0,
  4452. ProductDate: 0,
  4453. MaxUnit: selfBasedrug.MinUnit,
  4454. MinUnit: selfBasedrug.MinUnit,
  4455. StorehouseId: 0,
  4456. OverCount: sum_count,
  4457. OperateTime: time.Now().Unix(),
  4458. AdviceId: item.ID,
  4459. }
  4460. service.CreateSelfDrugFlow(flow, tx)
  4461. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4462. var total_count int64 // 入库总数量
  4463. var over_count int64 //剩余库存
  4464. for _, it := range drugInfolist {
  4465. if it.MaxUnit == selfBasedrug.MaxUnit {
  4466. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4467. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4468. }
  4469. }
  4470. for _, it := range drugInfolist {
  4471. total_count += it.WarehousingCount
  4472. over_count += it.StockMaxNumber + it.StockMinNumber
  4473. }
  4474. //查询该仓库是否有默认数据
  4475. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4476. if selfDrugStock.ID == 0 {
  4477. drugStock := models.XtSelfDrugStockCount{
  4478. UserOrgId: item.UserOrgId,
  4479. PatientId: item.PatientId,
  4480. SumInCount: total_count,
  4481. SumOutCount: 0,
  4482. SumCancelCount: 0,
  4483. DrugId: item.DrugId,
  4484. Ctime: time.Now().Unix(),
  4485. Mtime: 0,
  4486. Status: 1,
  4487. FlushCount: over_count,
  4488. SumActOutCount: 0,
  4489. }
  4490. service.CreateSelfDrugStockSum(drugStock, tx)
  4491. }
  4492. if selfDrugStock.ID > 0 {
  4493. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4494. }
  4495. }
  4496. //查询这个单据的出库数量
  4497. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4498. var his_out_count int64
  4499. for _, item := range drugFlowList {
  4500. his_out_count += item.Count
  4501. }
  4502. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4503. if (total_count + his_out_count) <= in_count {
  4504. // 出库
  4505. if total_count < in_count {
  4506. var cha_count int64
  4507. cha_count = in_count - total_count
  4508. var stock_number int64 = 0
  4509. //查询库存是否充足
  4510. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4511. // 将该批次的剩余库存数量转换为拆零数量
  4512. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4513. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4514. }
  4515. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4516. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4517. }
  4518. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4519. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4520. }
  4521. if stock_number >= cha_count {
  4522. var maxNumber int64 = 0
  4523. var minNumber int64 = 0
  4524. maxNumber = cha_count / selfBasedrug.MinNumber
  4525. minNumber = cha_count % selfBasedrug.MinNumber
  4526. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4527. minNumber = maxNumber
  4528. }
  4529. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4530. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4532. return
  4533. }
  4534. }
  4535. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4536. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4537. }
  4538. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4539. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4540. }
  4541. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4542. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4543. }
  4544. if warehouse.StockMaxNumber < 0 {
  4545. warehouse.StockMaxNumber = 0
  4546. }
  4547. if warehouse.StockMinNumber < 0 {
  4548. warehouse.StockMinNumber = 0
  4549. }
  4550. warehouse.Mtime = time.Now().Unix()
  4551. if warehouse.StockMinNumber < minNumber {
  4552. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4553. if warehouse.MaxUnit != warehouse.MinUnit {
  4554. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4555. }
  4556. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4557. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4558. }
  4559. } else {
  4560. if minNumber > 0 {
  4561. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4562. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4563. }
  4564. }
  4565. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4566. if warehouse.StockMinNumber > 0 {
  4567. if warehouse.StockMinNumber-cha_count >= 0 {
  4568. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4569. }
  4570. }
  4571. }
  4572. }
  4573. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4574. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4575. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4576. }
  4577. }
  4578. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4579. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4581. return
  4582. }
  4583. }
  4584. if warehouse.StockMinNumber <= 0 {
  4585. warehouse.StockMinNumber = 0
  4586. }
  4587. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4588. //查询该药品剩余库存
  4589. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4590. var over_count int64
  4591. for _, its := range infolist {
  4592. if its.MaxUnit == selfBasedrug.MaxUnit {
  4593. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4594. }
  4595. over_count += its.StockMaxNumber + its.StockMinNumber
  4596. }
  4597. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4598. drugflow := models.XtSelfDrugFlow{
  4599. WarehouseOutId: 0,
  4600. WarehouseOutOrderNumber: warehousing_order,
  4601. WarehousingOrder: warehousing_order,
  4602. DrugId: item.DrugId,
  4603. Number: warehouse.Number,
  4604. ProductDate: warehouse.ProductDate,
  4605. ExpireDate: warehouse.ExpiryDate,
  4606. Count: cha_count,
  4607. Price: warehouse.RetailPrice,
  4608. Status: 1,
  4609. Ctime: item.AdviceDate,
  4610. Mtime: time.Now().Unix(),
  4611. UserOrgId: item.UserOrgId,
  4612. Manufacturer: warehouse.Manufacturer,
  4613. Dealer: warehouse.Dealer,
  4614. BatchNumber: warehouse.BatchNumber,
  4615. MaxUnit: selfBasedrug.MinUnit,
  4616. ConsumableType: 20,
  4617. IsEdit: 1,
  4618. Creator: 0,
  4619. IsSys: 3,
  4620. WarehouseOutDetailId: drugWareInfo.ID,
  4621. AdviceId: item.ID,
  4622. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4623. StorehouseId: 0,
  4624. AdminUserId: creater,
  4625. LastPrice: warehouse.Price,
  4626. StockCount: "",
  4627. WarehousingDetailId: 0,
  4628. OverCount: over_count,
  4629. RetailPrice: item.Price, //手动出库出库价格
  4630. WarehousingId: warehouse.ID,
  4631. SystemTime: item.AdviceDate,
  4632. PatientId: item.PatientId,
  4633. Remark: "保存处方入库数据差",
  4634. OperateTime: time.Now().Unix(),
  4635. }
  4636. if warehouse.RetailPrice == 0 {
  4637. drugflow.Price = item.Price
  4638. }
  4639. service.CreateSelfDrugFlowOne(drugflow, tx)
  4640. var out_count int64
  4641. out_count = in_count - total_count
  4642. fmt.Println("in_count------------------", in_count)
  4643. fmt.Println("total_count------------------", total_count)
  4644. //添加出库数量
  4645. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4646. //查询剩余库存
  4647. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4648. var sum_count int64
  4649. for _, its := range stockInfo {
  4650. if its.MaxUnit == selfBasedrug.MaxUnit {
  4651. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4652. }
  4653. sum_count += its.StockMaxNumber + its.StockMinNumber
  4654. }
  4655. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4656. } else {
  4657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4658. return
  4659. }
  4660. }
  4661. }
  4662. }
  4663. }
  4664. }
  4665. }
  4666. tx.Commit()
  4667. if err == nil {
  4668. c.ServeSuccessJSON(map[string]interface{}{
  4669. "msg": "保存成功",
  4670. })
  4671. return
  4672. } else {
  4673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4674. return
  4675. }
  4676. }
  4677. }
  4678. //func (c *HisApiController) EditHisPrescription() {
  4679. // record_date := c.GetString("record_date")
  4680. // patient_id, _ := c.GetInt64("patient_id")
  4681. // reg_type, _ := c.GetInt64("reg_type")
  4682. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4683. // diagnose := c.GetString("diagnose")
  4684. // sick_type, _ := c.GetInt64("sick_type")
  4685. // sick_history := c.GetString("sick_history")
  4686. // doctor_id, _ := c.GetInt64("doctor", 0)
  4687. // department, _ := c.GetInt64("department", 0)
  4688. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4689. // p_type, _ := c.GetInt64("p_type")
  4690. //
  4691. // dataBody := make(map[string]interface{}, 0)
  4692. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4693. // if err != nil {
  4694. // utils.ErrorLog(err.Error())
  4695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4696. // return
  4697. // }
  4698. //
  4699. // timeLayout := "2006-01-02"
  4700. // loc, _ := time.LoadLocation("Local")
  4701. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4702. // if err != nil {
  4703. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4704. // return
  4705. // }
  4706. // adminInfo := c.GetAdminUserInfo()
  4707. // recordDateTime := theTime.Unix()
  4708. //
  4709. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4710. //
  4711. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4712. // var hpInfo models.HisPrescriptionInfo
  4713. // if info.ID == 0 {
  4714. // var randNum int
  4715. // randNum = rand.Intn(10000) + 1000
  4716. // timestamp := time.Now().Unix()
  4717. // tempTime := time.Unix(timestamp, 0)
  4718. // timeFormat := tempTime.Format("20060102150405")
  4719. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4720. //
  4721. // hpInfo = models.HisPrescriptionInfo{
  4722. // UserOrgId: adminInfo.CurrentOrgId,
  4723. // RecordDate: theTime.Unix(),
  4724. // PatientId: patient_id,
  4725. // Status: 1,
  4726. // Ctime: time.Now().Unix(),
  4727. // Mtime: time.Now().Unix(),
  4728. // Creator: adminInfo.AdminUser.Id,
  4729. // Modifier: adminInfo.AdminUser.Id,
  4730. // Diagnosis: diagnose,
  4731. // SickHistory: sick_history,
  4732. // Departments: department,
  4733. // RegisterType: reg_type,
  4734. // PrescriptionNumber: p_number,
  4735. // PrescriptionStatus: 1,
  4736. // Doctor: role.UserName,
  4737. // DoctorId: doctor_id,
  4738. // SickType: sick_type,
  4739. // PType: p_type,
  4740. // }
  4741. // service.SavePatientPrescriptionInfo(hpInfo)
  4742. //
  4743. // } else {
  4744. // hpInfo = models.HisPrescriptionInfo{
  4745. // ID: info.ID,
  4746. // UserOrgId: adminInfo.CurrentOrgId,
  4747. // RecordDate: info.RecordDate,
  4748. // PatientId: info.PatientId,
  4749. // Status: 1,
  4750. // Ctime: info.Ctime,
  4751. // Mtime: time.Now().Unix(),
  4752. // Creator: info.Creator,
  4753. // Modifier: adminInfo.AdminUser.Id,
  4754. // Diagnosis: diagnose,
  4755. // SickHistory: sick_history,
  4756. // Departments: department,
  4757. // RegisterType: reg_type,
  4758. // PrescriptionNumber: info.PrescriptionNumber,
  4759. // Doctor: role.UserName,
  4760. // PrescriptionStatus: info.PrescriptionStatus,
  4761. // DoctorId: doctor_id,
  4762. // SickType: sick_type,
  4763. // PType: info.PType,
  4764. // }
  4765. // service.SavePatientPrescriptionInfo(hpInfo)
  4766. // }
  4767. //
  4768. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4769. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4770. //
  4771. // if len(prescriptions) > 0 {
  4772. // for _, item := range prescriptions {
  4773. // items := item.(map[string]interface{})
  4774. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4775. // utils.ErrorLog("id")
  4776. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4777. // return
  4778. // }
  4779. // id := int64(items["id"].(float64))
  4780. //
  4781. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4782. // utils.ErrorLog("type")
  4783. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4784. // return
  4785. // }
  4786. // types := int64(items["type"].(float64))
  4787. //
  4788. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4789. // utils.ErrorLog("med_type")
  4790. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4791. // return
  4792. // }
  4793. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4794. //
  4795. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4796. //
  4797. // ctime := time.Now().Unix()
  4798. //
  4799. // prescription := &models.HisPrescription{
  4800. // ID: id,
  4801. // PatientId: patient_id,
  4802. // UserOrgId: adminInfo.CurrentOrgId,
  4803. // RecordDate: recordDateTime,
  4804. // Ctime: ctime,
  4805. // Mtime: ctime,
  4806. // Type: types,
  4807. // Modifier: adminInfo.AdminUser.Id,
  4808. // Creator: adminInfo.AdminUser.Id,
  4809. // Status: 1,
  4810. // Doctor: role.UserName,
  4811. // HisPatientId: his_patient_id,
  4812. // OrderStatus: 1,
  4813. // BatchNumber: "",
  4814. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4815. // PType: hpInfo.PType,
  4816. // MedType: med_type,
  4817. // }
  4818. //
  4819. // if historyPrescription.ID > 0 {
  4820. // prescription.PreTime = historyPrescription.PreTime
  4821. //
  4822. // }
  4823. //
  4824. // service.SaveHisPrescription(prescription)
  4825. //
  4826. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4827. // advices := items["advices"].([]interface{})
  4828. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4829. // groupNo := int64(0)
  4830. // ctime := time.Now().Unix()
  4831. // mtime := ctime
  4832. // if len(advices) > 0 {
  4833. // for _, advice := range advices {
  4834. // var s models.HisDoctorAdviceInfo
  4835. // s.PrescriptionId = prescription.ID
  4836. // s.AdviceType = 2
  4837. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4838. // s.StopState = 2
  4839. // s.ExecutionState = 2
  4840. // s.AdviceDate = recordDateTime
  4841. // s.Status = 1
  4842. // s.UserOrgId = adminInfo.CurrentOrgId
  4843. // s.RecordDate = recordDateTime
  4844. // s.StartTime = prescription.PreTime
  4845. // s.Groupno = groupNo
  4846. // s.CreatedTime = ctime
  4847. // s.UpdatedTime = mtime
  4848. // s.PatientId = patient_id
  4849. // s.HisPatientId = his_patient_id
  4850. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4851. // if errcode > 0 {
  4852. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4853. // return
  4854. // }
  4855. //
  4856. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4857. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4858. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4859. // if s.Price == 0 {
  4860. // s.Price = lastWarehouse.RetailPrice
  4861. // }
  4862. // }
  4863. //
  4864. // service.CreateHisDoctorAdvice(&s)
  4865. // //记录日志
  4866. // byterequest, _ := json.Marshal(s)
  4867. // adviceLog := models.XtDoctorAdviceLog{
  4868. // UserOrgId: s.UserOrgId,
  4869. // PatientId: s.PatientId,
  4870. // AdminUserId: adminInfo.AdminUser.Id,
  4871. // Module: 1,
  4872. // ErrLog: string(byterequest),
  4873. // Status: 1,
  4874. // Ctime: time.Now().Unix(),
  4875. // Mtime: 0,
  4876. // Source: "电脑端his医嘱修改",
  4877. // RecordDate: s.AdviceDate,
  4878. // }
  4879. // service.CreateDoctorAdviceLog(adviceLog)
  4880. // redis := service.RedisClient()
  4881. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4882. // redis.Set(key, "", time.Second)
  4883. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4884. // fmt.Println("keyOne", keyOne)
  4885. // redis.Set(keyOne, "", time.Second)
  4886. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4887. // redis.Set(keySeven, "", time.Second)
  4888. // redis.Close()
  4889. //
  4890. // }
  4891. // }
  4892. // }
  4893. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4894. // projects := items["project"].([]interface{})
  4895. // if len(projects) > 0 {
  4896. // for _, project := range projects {
  4897. // var p models.HisPrescriptionProject
  4898. // p.PrescriptionId = prescription.ID
  4899. // p.Ctime = time.Now().Unix()
  4900. // p.Mtime = time.Now().Unix()
  4901. // p.PatientId = patient_id
  4902. // p.RecordDate = recordDateTime
  4903. // p.UserOrgId = adminInfo.CurrentOrgId
  4904. // p.HisPatientId = his_patient_id
  4905. // p.Status = 1
  4906. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4907. // if errcode > 0 {
  4908. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4909. // return
  4910. // }
  4911. // service.CreateHisProjectTwo(&p)
  4912. //
  4913. // //记录日志
  4914. // byterequest, _ := json.Marshal(p)
  4915. // adviceLog := models.XtDoctorAdviceLog{
  4916. // UserOrgId: p.UserOrgId,
  4917. // PatientId: p.PatientId,
  4918. // AdminUserId: adminInfo.AdminUser.Id,
  4919. // Module: 1,
  4920. // ErrLog: string(byterequest),
  4921. // Status: 1,
  4922. // Ctime: time.Now().Unix(),
  4923. // Mtime: 0,
  4924. // Source: "电脑端his项目修改",
  4925. // RecordDate: p.RecordDate,
  4926. // }
  4927. // service.CreateDoctorAdviceLog(adviceLog)
  4928. // }
  4929. // }
  4930. // }
  4931. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4932. // addition := items["addition"].([]interface{})
  4933. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4934. // ctime := time.Now().Unix()
  4935. // mtime := ctime
  4936. // if len(addition) > 0 {
  4937. // for _, item := range addition {
  4938. // var s models.HisAdditionalCharge
  4939. // s.PrescriptionId = prescription.ID
  4940. // s.Status = 1
  4941. // s.UserOrgId = adminInfo.CurrentOrgId
  4942. // s.RecordDate = recordDateTime
  4943. // s.CreatedTime = ctime
  4944. // s.UpdatedTime = mtime
  4945. // s.PatientId = patient_id
  4946. // s.HisPatientId = his_patient_id
  4947. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4948. // if errcode > 0 {
  4949. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4950. // return
  4951. // }
  4952. // service.CreateAdditionalCharge(&s)
  4953. // }
  4954. // }
  4955. // }
  4956. //
  4957. // }
  4958. // }
  4959. // }
  4960. // if err == nil {
  4961. // c.ServeSuccessJSON(map[string]interface{}{
  4962. // "msg": "保存成功",
  4963. // })
  4964. // return
  4965. //
  4966. // } else {
  4967. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4968. // return
  4969. // }
  4970. //}
  4971. func (c *HisApiController) DeletePrescription() {
  4972. prescription_id, _ := c.GetInt64("id")
  4973. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4974. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4975. ////同步到自备药
  4976. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  4977. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  4978. if selfPrescriptionOpen.IsOpen == 1 {
  4979. // 在函数结束时处理事务回滚
  4980. db := service.XTWriteDB()
  4981. tx := db.Begin()
  4982. defer func() {
  4983. if r := recover(); r != nil {
  4984. tx.Rollback()
  4985. } else {
  4986. tx.Commit()
  4987. }
  4988. }()
  4989. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  4990. for _, item := range advicesList {
  4991. timeStr := time.Now().Format("2006-01-02")
  4992. timeArr := strings.Split(timeStr, "-")
  4993. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  4994. total = total + 1
  4995. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4996. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4997. number = number + total
  4998. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  4999. operation_time := time.Now().Unix()
  5000. creater := c.GetAdminUserInfo().AdminUser.Id
  5001. //创建一个出库单
  5002. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5003. WarehouseOutOrderNumber: warehousing_out_order,
  5004. OperationTime: operation_time,
  5005. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5006. Creater: creater,
  5007. Ctime: time.Now().Unix(),
  5008. Status: 1,
  5009. WarehouseOutTime: item.AdviceDate,
  5010. Type: 0,
  5011. PatientId: item.PatientId,
  5012. IsCheck: 1,
  5013. }
  5014. //查询今日是否有出库数据
  5015. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5016. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5017. if lastWarehouseOut.ID == 0 {
  5018. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5019. }
  5020. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5021. var total_count int64
  5022. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5023. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5024. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5025. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5026. }
  5027. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5028. total_count += prescribingNumberSeven
  5029. }
  5030. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5031. total_count += prescribingNumberSeven
  5032. }
  5033. //出库
  5034. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5035. WarehouseOutOrderNumber: warehousing_out_order,
  5036. WarehouseOutId: lastWarehouseOut.ID,
  5037. DrugId: item.DrugId,
  5038. Count: total_count,
  5039. Price: 0,
  5040. TotalPrice: 0,
  5041. Status: 1,
  5042. Ctime: item.AdviceDate,
  5043. Mtime: item.AdviceDate,
  5044. Remark: "",
  5045. OrgId: item.UserOrgId,
  5046. Type: 0,
  5047. Manufacturer: selfBasedrug.Manufacturer,
  5048. Dealer: selfBasedrug.Dealer,
  5049. RetailPrice: 0,
  5050. RetailTotalPrice: 0,
  5051. CountUnit: selfBasedrug.MinUnit,
  5052. ExpiryDate: 0,
  5053. ProductDate: 0,
  5054. Number: "",
  5055. BatchNumber: "",
  5056. IsSys: 1,
  5057. WarehouseInfoId: 0,
  5058. AdminUserId: 0,
  5059. StockCount: "",
  5060. IsCheck: 1,
  5061. SysRecordTime: item.AdviceDate,
  5062. PatientId: item.PatientId,
  5063. ClassType: "",
  5064. AdviceId: item.ID,
  5065. }
  5066. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5067. }
  5068. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5069. for _, it := range warehousingOutInfo {
  5070. //查询今日是否有出库数据
  5071. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5072. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5073. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5074. //出库逻辑
  5075. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5076. //查询剩余库存
  5077. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5078. var sum_count int64
  5079. for _, its := range stockInfo {
  5080. if its.MaxUnit == medical.MaxUnit {
  5081. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5082. }
  5083. sum_count += its.StockMaxNumber + its.StockMinNumber
  5084. }
  5085. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5086. }
  5087. }
  5088. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5089. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5090. //耗材保存处方出库
  5091. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5092. //已收费和已发药限制逻辑
  5093. isCharge := false
  5094. isMedicine := false
  5095. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5096. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5097. if new_prescription.IsMedicine == 1 {
  5098. isMedicine = true
  5099. }
  5100. for _, item := range new_prescriptions {
  5101. if item.OrderStatus == 4 {
  5102. isCharge = true
  5103. }
  5104. }
  5105. if p_err != nil {
  5106. if new_prescription.ID > 0 {
  5107. if new_prescription.OrderStatus == 2 {
  5108. isCharge = true
  5109. }
  5110. }
  5111. }
  5112. for _, item := range advices {
  5113. if item.IsMedicine == 1 {
  5114. isMedicine = true
  5115. }
  5116. }
  5117. if isCharge {
  5118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5119. return
  5120. }
  5121. if isMedicine {
  5122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5123. return
  5124. }
  5125. //已收费和已发药限制逻辑
  5126. if len(projects) > 0 {
  5127. for _, item := range projects {
  5128. service.DeletePrintInfo(item.ID) //删除打印信息
  5129. if goodOutConfig.IsOpen != 1 {
  5130. if stockConfig.IsOpen == 1 {
  5131. if item.Type == 3 && item.IsOut == 1 {
  5132. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5133. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5134. good.Total = good.Total + f_count
  5135. service.UpdateGoodInfo(&good)
  5136. operation_time := time.Now().Unix()
  5137. creater := c.GetAdminUserInfo().AdminUser.Id
  5138. //创建退库单
  5139. timeStr := time.Now().Format("2006-01-02")
  5140. timeArr := strings.Split(timeStr, "-")
  5141. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5142. total = total + 1
  5143. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5144. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5145. cancelStock := models.CancelStock{
  5146. OrderNumber: orderNumber,
  5147. OperaTime: operation_time,
  5148. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5149. Creater: creater,
  5150. Ctime: time.Now().Unix(),
  5151. Status: 1,
  5152. ReturnTime: item.RecordDate,
  5153. Type: 1,
  5154. StorehouseId: houseConfig.StorehouseOutInfo,
  5155. IsCheck: 1,
  5156. }
  5157. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5158. if msgerrkonde == gorm.ErrRecordNotFound {
  5159. service.AddSigleCancelStock(&cancelStock)
  5160. }
  5161. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5162. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5163. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5164. //查询该耗材是否出库
  5165. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5166. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5167. deaerler, _ := service.GetDealerById(info.Dealer)
  5168. var total_count int64
  5169. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5170. total_count += count
  5171. if info.ID > 0 {
  5172. if info.Count >= total_count {
  5173. //回退库存
  5174. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5175. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5176. var flush_count int64
  5177. for _, it := range goodList {
  5178. flush_count += it.StockCount
  5179. }
  5180. cancelStockInfo := models.CancelStockInfo{
  5181. GoodId: item.ProjectId,
  5182. CancelStockId: cancel.ID,
  5183. GoodTypeId: good.GoodTypeId,
  5184. Count: prescribingNumber,
  5185. Price: info.Price,
  5186. Total: 0,
  5187. ProductDate: info.ProductDate,
  5188. ExpiryDate: info.ExpiryDate,
  5189. Ctime: time.Now().Unix(),
  5190. Status: 1,
  5191. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5192. OrderNumber: cancel.OrderNumber,
  5193. Type: 0,
  5194. Dealer: deaerler.DealerName,
  5195. Manufacturer: manufacturer.ManufacturerName,
  5196. Number: info.Number,
  5197. RegisterAccount: "",
  5198. Remark: "",
  5199. WarehouseInfoId: info.WarehouseInfotId,
  5200. PatientId: info.PatientId,
  5201. RecordDate: info.SysRecordTime,
  5202. StorehouseId: houseConfig.StorehouseOutInfo,
  5203. IsCheck: 1,
  5204. }
  5205. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5206. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5207. flow := models.VmStockFlow{
  5208. WarehousingId: info.WarehouseInfotId,
  5209. GoodId: item.ProjectId,
  5210. Number: info.Number,
  5211. LicenseNumber: info.LicenseNumber,
  5212. Count: prescribingNumber,
  5213. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5214. PatientId: item.PatientId,
  5215. SystemTime: info.SysRecordTime,
  5216. ConsumableType: 7,
  5217. IsSys: 0,
  5218. WarehousingOrder: "",
  5219. WarehouseOutId: info.WarehouseOutId,
  5220. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5221. IsEdit: 0,
  5222. CancelStockId: cancel.ID,
  5223. CancelOrderNumber: cancel.OrderNumber,
  5224. Manufacturer: manufacturer.ID,
  5225. Dealer: 0,
  5226. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5227. UpdateCreator: 0,
  5228. Status: 1,
  5229. Ctime: time.Now().Unix(),
  5230. Mtime: 0,
  5231. Price: info.Price,
  5232. WarehousingDetailId: info.WarehouseInfotId,
  5233. WarehouseOutDetailId: info.ID,
  5234. CancelOutDetailId: cancelInfo.ID,
  5235. ProductDate: info.ProductDate,
  5236. ExpireDate: info.ExpiryDate,
  5237. StorehouseId: houseConfig.StorehouseOutInfo,
  5238. OverCount: flush_count,
  5239. OperateTime: time.Now().Unix(),
  5240. }
  5241. service.CreateStockFlowOne(flow)
  5242. //退库数量增加
  5243. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5244. //出库数量减少
  5245. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5246. }
  5247. if info.Count < total_count {
  5248. //回退库存
  5249. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5250. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5251. var flush_count int64
  5252. for _, it := range goodList {
  5253. flush_count += it.StockCount
  5254. }
  5255. cancelStockInfo := models.CancelStockInfo{
  5256. GoodId: item.ProjectId,
  5257. CancelStockId: cancel.ID,
  5258. GoodTypeId: good.GoodTypeId,
  5259. Count: info.Count,
  5260. Price: info.Price,
  5261. Total: 0,
  5262. ProductDate: info.ProductDate,
  5263. ExpiryDate: info.ExpiryDate,
  5264. Ctime: time.Now().Unix(),
  5265. Status: 1,
  5266. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5267. OrderNumber: cancel.OrderNumber,
  5268. Type: 0,
  5269. Dealer: deaerler.DealerName,
  5270. Manufacturer: manufacturer.ManufacturerName,
  5271. Number: info.Number,
  5272. RegisterAccount: "",
  5273. Remark: "",
  5274. WarehouseInfoId: info.WarehouseInfotId,
  5275. PatientId: info.PatientId,
  5276. RecordDate: info.SysRecordTime,
  5277. StorehouseId: houseConfig.StorehouseOutInfo,
  5278. IsCheck: 1,
  5279. }
  5280. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5281. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5282. flow := models.VmStockFlow{
  5283. WarehousingId: info.WarehouseInfotId,
  5284. GoodId: item.ProjectId,
  5285. Number: info.Number,
  5286. LicenseNumber: info.LicenseNumber,
  5287. Count: info.Count,
  5288. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5289. PatientId: item.PatientId,
  5290. SystemTime: info.SysRecordTime,
  5291. ConsumableType: 7,
  5292. IsSys: 0,
  5293. WarehousingOrder: "",
  5294. WarehouseOutId: info.WarehouseOutId,
  5295. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5296. IsEdit: 0,
  5297. CancelStockId: cancel.ID,
  5298. CancelOrderNumber: cancel.OrderNumber,
  5299. Manufacturer: manufacturer.ID,
  5300. Dealer: 0,
  5301. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5302. UpdateCreator: 0,
  5303. Status: 1,
  5304. Ctime: time.Now().Unix(),
  5305. Mtime: 0,
  5306. Price: info.Price,
  5307. WarehousingDetailId: info.WarehouseInfotId,
  5308. WarehouseOutDetailId: info.ID,
  5309. CancelOutDetailId: cancelInfo.ID,
  5310. ProductDate: info.ProductDate,
  5311. ExpireDate: info.ExpiryDate,
  5312. StorehouseId: houseConfig.StorehouseOutInfo,
  5313. OverCount: flush_count,
  5314. OperateTime: time.Now().Unix(),
  5315. }
  5316. service.CreateStockFlowOne(flow)
  5317. //退库数量增加
  5318. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5319. //出库数量减少
  5320. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5321. }
  5322. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5323. var flush_count int64
  5324. for _, it := range goodList {
  5325. flush_count += it.StockCount
  5326. }
  5327. //查询已出库数量
  5328. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5329. if prescribingNumber < dialysisInfo.Count {
  5330. //改变数量
  5331. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5332. }
  5333. if prescribingNumber >= dialysisInfo.Count {
  5334. //删除出库表
  5335. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5336. }
  5337. //更新库存
  5338. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5339. //更新基础库库存
  5340. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5341. }
  5342. }
  5343. }
  5344. }
  5345. //保存耗材出库
  5346. if goodOutConfig.IsOpen == 1 {
  5347. if item.Type == 3 {
  5348. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5349. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5350. good.Total = good.Total + f_count
  5351. service.UpdateGoodInfo(&good)
  5352. operation_time := time.Now().Unix()
  5353. creater := c.GetAdminUserInfo().AdminUser.Id
  5354. //创建退库单
  5355. timeStr := time.Now().Format("2006-01-02")
  5356. timeArr := strings.Split(timeStr, "-")
  5357. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5358. total = total + 1
  5359. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5360. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5361. cancelStock := models.CancelStock{
  5362. OrderNumber: orderNumber,
  5363. OperaTime: operation_time,
  5364. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5365. Creater: creater,
  5366. Ctime: time.Now().Unix(),
  5367. Status: 1,
  5368. ReturnTime: item.RecordDate,
  5369. Type: 1,
  5370. StorehouseId: houseConfig.StorehouseOutInfo,
  5371. IsCheck: 1,
  5372. }
  5373. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5374. if msgerrkonde == gorm.ErrRecordNotFound {
  5375. service.AddSigleCancelStock(&cancelStock)
  5376. }
  5377. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5378. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5379. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5380. //查询该耗材是否出库
  5381. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5382. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5383. deaerler, _ := service.GetDealerById(info.Dealer)
  5384. var total_count int64
  5385. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5386. total_count += count
  5387. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5388. var flush_count int64
  5389. for _, it := range goodList {
  5390. flush_count += it.StockCount
  5391. }
  5392. fmt.Println("历史出库数据", info.Count)
  5393. fmt.Println("出库数量", total_count)
  5394. if info.ID > 0 {
  5395. cancelStockInfo := models.CancelStockInfo{
  5396. GoodId: item.ProjectId,
  5397. CancelStockId: cancel.ID,
  5398. GoodTypeId: good.GoodTypeId,
  5399. Count: prescribingNumber,
  5400. Price: info.Price,
  5401. Total: 0,
  5402. ProductDate: info.ProductDate,
  5403. ExpiryDate: info.ExpiryDate,
  5404. Ctime: time.Now().Unix(),
  5405. Status: 1,
  5406. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5407. OrderNumber: cancel.OrderNumber,
  5408. Type: 0,
  5409. Dealer: deaerler.DealerName,
  5410. Manufacturer: manufacturer.ManufacturerName,
  5411. Number: info.Number,
  5412. RegisterAccount: "",
  5413. Remark: "",
  5414. WarehouseInfoId: info.WarehouseInfotId,
  5415. PatientId: info.PatientId,
  5416. RecordDate: info.SysRecordTime,
  5417. StorehouseId: houseConfig.StorehouseOutInfo,
  5418. IsCheck: 1,
  5419. }
  5420. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5421. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5422. //查询出库数量
  5423. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5424. //出库数据 大于 退库数量
  5425. if len(list) > 0 {
  5426. for _, it := range list {
  5427. //回退库存
  5428. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5429. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5430. var flush_count_one int64
  5431. for _, it := range goodList {
  5432. flush_count_one += it.StockCount
  5433. }
  5434. //查询该批次是否有退库数据
  5435. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5436. creater := c.GetAdminUserInfo().AdminUser.Id
  5437. flow := models.VmStockFlow{
  5438. WarehousingId: it.WarehouseInfotId,
  5439. GoodId: it.GoodId,
  5440. Number: it.Number,
  5441. LicenseNumber: it.LicenseNumber,
  5442. Count: it.Count,
  5443. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5444. PatientId: it.PatientId,
  5445. SystemTime: it.SysRecordTime,
  5446. ConsumableType: 7,
  5447. IsSys: 0,
  5448. WarehousingOrder: "",
  5449. WarehouseOutId: it.WarehouseOutId,
  5450. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5451. IsEdit: 0,
  5452. CancelStockId: cancel.ID,
  5453. CancelOrderNumber: cancel.OrderNumber,
  5454. Manufacturer: manufacturer.ID,
  5455. Dealer: 0,
  5456. Creator: creater,
  5457. UpdateCreator: 0,
  5458. Status: 1,
  5459. Ctime: time.Now().Unix(),
  5460. Mtime: 0,
  5461. Price: it.Price,
  5462. WarehousingDetailId: it.WarehouseInfotId,
  5463. WarehouseOutDetailId: it.ID,
  5464. CancelOutDetailId: cancelInfo.ID,
  5465. ProductDate: it.ProductDate,
  5466. ExpireDate: it.ExpiryDate,
  5467. StorehouseId: houseConfig.StorehouseOutInfo,
  5468. OverCount: flush_count_one,
  5469. }
  5470. service.CreateStockFlowOne(flow)
  5471. //if flow.ID > 0 {
  5472. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5473. //}
  5474. }
  5475. }
  5476. //flow := models.VmStockFlow{
  5477. // WarehousingId: info.WarehouseInfotId,
  5478. // GoodId: item.ProjectId,
  5479. // Number: info.Number,
  5480. // LicenseNumber: info.LicenseNumber,
  5481. // Count: prescribingNumber,
  5482. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5483. // PatientId: item.PatientId,
  5484. // SystemTime: info.SysRecordTime,
  5485. // ConsumableType: 7,
  5486. // IsSys: 0,
  5487. // WarehousingOrder: "",
  5488. // WarehouseOutId: info.WarehouseOutId,
  5489. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5490. // IsEdit: 0,
  5491. // CancelStockId: cancel.ID,
  5492. // CancelOrderNumber: cancel.OrderNumber,
  5493. // Manufacturer: manufacturer.ID,
  5494. // Dealer: 0,
  5495. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5496. // UpdateCreator: 0,
  5497. // Status: 1,
  5498. // Ctime: time.Now().Unix(),
  5499. // Mtime: 0,
  5500. // Price: info.Price,
  5501. // WarehousingDetailId: info.WarehouseInfotId,
  5502. // WarehouseOutDetailId: info.ID,
  5503. // CancelOutDetailId: cancelInfo.ID,
  5504. // ProductDate: info.ProductDate,
  5505. // ExpireDate: info.ExpiryDate,
  5506. // StorehouseId: houseConfig.StorehouseOutInfo,
  5507. // OverCount: flush_count,
  5508. //}
  5509. //service.CreateStockFlowOne(flow)
  5510. //退库数量增加
  5511. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5512. //出库数量减少
  5513. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5514. //查询已出库数量
  5515. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5516. if prescribingNumber < dialysisInfo.Count {
  5517. //改变数量
  5518. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5519. }
  5520. if prescribingNumber >= dialysisInfo.Count {
  5521. //删除出库表
  5522. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5523. }
  5524. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5525. var flush_count_one int64
  5526. for _, it := range goodList {
  5527. flush_count_one += it.StockCount
  5528. }
  5529. //更新库存
  5530. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5531. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5532. //更新基础库库存
  5533. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5534. }
  5535. }
  5536. }
  5537. }
  5538. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5539. fmt.Println(err)
  5540. }
  5541. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5542. fmt.Println(err)
  5543. if len(advices) > 0 {
  5544. for _, item := range advices {
  5545. redis := service.RedisClient()
  5546. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5547. redis.Set(keyFive, "", time.Second)
  5548. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5549. redis.Set(keyOne, "", time.Second)
  5550. redis.Close()
  5551. }
  5552. }
  5553. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5554. if len(advices) > 0 {
  5555. for _, item := range advices {
  5556. creater := c.GetAdminUserInfo().AdminUser.Id
  5557. service.DrugAutoAddCancelInfo(item, creater)
  5558. }
  5559. }
  5560. } else {
  5561. if drugOutConfig.IsOpen == 1 {
  5562. if len(advices) > 0 {
  5563. for _, item := range advices {
  5564. creater := c.GetAdminUserInfo().AdminUser.Id
  5565. service.DrugAutoAddCancelInfo(item, creater)
  5566. }
  5567. }
  5568. } else {
  5569. if len(advices) > 0 {
  5570. for _, item := range advices {
  5571. creater := c.GetAdminUserInfo().AdminUser.Id
  5572. service.DrugAutoAddCancelInfo(item, creater)
  5573. }
  5574. }
  5575. }
  5576. }
  5577. c.ServeSuccessJSON(map[string]interface{}{
  5578. "msg": "删除成功",
  5579. })
  5580. return
  5581. }
  5582. func (c *HisApiController) DeleteDoctorAdvice() {
  5583. id, _ := c.GetInt64("id")
  5584. advice, _ := service.GetHisDoctorAdvicesById(id)
  5585. ////同步到自备药
  5586. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5587. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5588. if selfPrescriptionOpen.IsOpen == 1 {
  5589. db := service.XTWriteDB()
  5590. tx := db.Begin()
  5591. defer func() {
  5592. if r := recover(); r != nil {
  5593. tx.Rollback()
  5594. } else {
  5595. tx.Commit()
  5596. }
  5597. }()
  5598. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5599. var total_count int64
  5600. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5601. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5602. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5603. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5604. }
  5605. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5606. total_count += prescribingNumberSeven
  5607. }
  5608. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5609. total_count += prescribingNumberSeven
  5610. }
  5611. timeStr := time.Now().Format("2006-01-02")
  5612. timeArr := strings.Split(timeStr, "-")
  5613. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5614. total = total + 1
  5615. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5616. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5617. number = number + total
  5618. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5619. operation_time := time.Now().Unix()
  5620. creater := c.GetAdminUserInfo().AdminUser.Id
  5621. //创建一个出库单
  5622. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5623. WarehouseOutOrderNumber: warehousing_out_order,
  5624. OperationTime: operation_time,
  5625. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5626. Creater: creater,
  5627. Ctime: time.Now().Unix(),
  5628. Status: 1,
  5629. WarehouseOutTime: advice.AdviceDate,
  5630. Type: 0,
  5631. PatientId: advice.PatientId,
  5632. IsCheck: 1,
  5633. }
  5634. //查询今日是否有出库数据
  5635. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5636. if lastWarehouseOut.ID == 0 {
  5637. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5638. }
  5639. //出库
  5640. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5641. WarehouseOutId: lastWarehouseOut.ID,
  5642. WarehouseOutOrderNumber: warehousing_out_order,
  5643. DrugId: advice.DrugId,
  5644. Count: total_count,
  5645. Price: 0,
  5646. TotalPrice: 0,
  5647. Status: 1,
  5648. Ctime: advice.AdviceDate,
  5649. Mtime: advice.AdviceDate,
  5650. Remark: "",
  5651. OrgId: advice.UserOrgId,
  5652. Type: 0,
  5653. Manufacturer: selfBasedrug.Manufacturer,
  5654. Dealer: selfBasedrug.Dealer,
  5655. RetailPrice: 0,
  5656. RetailTotalPrice: 0,
  5657. CountUnit: advice.PrescribingNumberUnit,
  5658. ExpiryDate: 0,
  5659. ProductDate: 0,
  5660. Number: "",
  5661. BatchNumber: "",
  5662. IsSys: 0,
  5663. WarehouseInfoId: 0,
  5664. AdminUserId: 0,
  5665. StockCount: "",
  5666. IsCheck: 1,
  5667. SysRecordTime: advice.AdviceDate,
  5668. PatientId: advice.PatientId,
  5669. AdviceId: advice.ID,
  5670. ClassType: "",
  5671. }
  5672. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5673. for _, it := range warehousingOutInfo {
  5674. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5675. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5676. //出库逻辑
  5677. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5678. //查询剩余库存
  5679. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5680. var sum_count int64
  5681. for _, its := range stockInfo {
  5682. if its.MaxUnit == medical.MaxUnit {
  5683. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5684. }
  5685. sum_count += its.StockMaxNumber + its.StockMinNumber
  5686. }
  5687. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5688. }
  5689. }
  5690. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5691. //已收费和已发药的限制逻辑
  5692. isCharge := false
  5693. isMedicine := false
  5694. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5695. //获取今天该患者所有处方,判断是否发药或者收费
  5696. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5697. //for _, item := range new_prescriptions {
  5698. if new_prescription.IsMedicine == 1 {
  5699. isMedicine = true
  5700. }
  5701. //}
  5702. for _, item := range new_prescriptions {
  5703. if item.OrderStatus == 4 {
  5704. isCharge = true
  5705. }
  5706. }
  5707. if isMedicine {
  5708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5709. return
  5710. }
  5711. if isCharge {
  5712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5713. return
  5714. }
  5715. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5716. for _, item := range advices {
  5717. if item.IsMedicine == 1 {
  5718. isMedicine = true
  5719. }
  5720. }
  5721. if isMedicine {
  5722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5723. return
  5724. }
  5725. if new_prescription.ID > 0 {
  5726. if new_prescription.OrderStatus == 2 {
  5727. isCharge = true
  5728. }
  5729. }
  5730. if isCharge {
  5731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5732. return
  5733. }
  5734. //已收费和已发药的限制逻辑
  5735. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5736. redis := service.RedisClient()
  5737. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5738. redis.Set(keyFive, "", time.Second)
  5739. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5740. redis.Set(keyOne, "", time.Second)
  5741. defer redis.Close()
  5742. if err == nil {
  5743. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5744. //查询是否在处方中出库
  5745. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5746. if openConfig.IsOpen != 1 {
  5747. //判断该医嘱是否执行了
  5748. if advice.ExecutionState == 1 {
  5749. creater := c.GetAdminUserInfo().AdminUser.Id
  5750. service.DrugAutoAddCancelInfo(&advice, creater)
  5751. }
  5752. }
  5753. //开启保存处方扣减功能
  5754. if openConfig.IsOpen == 1 {
  5755. creater := c.GetAdminUserInfo().AdminUser.Id
  5756. service.DrugAutoAddCancelInfo(&advice, creater)
  5757. }
  5758. } else {
  5759. if drugOutConfig.IsOpen == 1 {
  5760. //查询是否在处方中出库
  5761. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5762. if openConfig.IsOpen != 1 {
  5763. //判断该医嘱是否执行了
  5764. if advice.ExecutionState == 1 {
  5765. creater := c.GetAdminUserInfo().AdminUser.Id
  5766. service.DrugAutoAddCancelInfo(&advice, creater)
  5767. }
  5768. }
  5769. //开启保存处方扣减功能
  5770. if openConfig.IsOpen == 1 {
  5771. creater := c.GetAdminUserInfo().AdminUser.Id
  5772. service.DrugAutoAddCancelInfo(&advice, creater)
  5773. }
  5774. } else {
  5775. //判断该医嘱是否执行了
  5776. if advice.ExecutionState == 1 {
  5777. creater := c.GetAdminUserInfo().AdminUser.Id
  5778. service.DrugAutoAddCancelInfo(&advice, creater)
  5779. }
  5780. }
  5781. }
  5782. c.ServeSuccessJSON(map[string]interface{}{
  5783. "msg": "删除成功",
  5784. })
  5785. return
  5786. } else {
  5787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5788. return
  5789. }
  5790. }
  5791. func (c *HisApiController) DeleteProject() {
  5792. id, _ := c.GetInt64("id")
  5793. adminInfo := c.GetAdminUserInfo()
  5794. project, _ := service.GetHisProjectByID(id)
  5795. // var consumable models.DialysisBeforePrepare
  5796. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5797. //耗材保存处方出库
  5798. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5799. isCharge := false
  5800. isMedicine := false
  5801. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5802. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5803. for _, item := range new_prescriptions {
  5804. if item.IsMedicine == 1 {
  5805. isMedicine = true
  5806. }
  5807. }
  5808. for _, item := range new_prescriptions {
  5809. if item.OrderStatus == 4 {
  5810. isCharge = true
  5811. }
  5812. }
  5813. if isMedicine {
  5814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5815. return
  5816. }
  5817. if isCharge {
  5818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5819. return
  5820. }
  5821. if new_prescription.ID > 0 {
  5822. if new_prescription.OrderStatus == 2 {
  5823. isCharge = true
  5824. }
  5825. }
  5826. if isCharge {
  5827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5828. return
  5829. }
  5830. service.DeletePrintInfo(id)
  5831. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5832. label.Status = 0
  5833. service.CreateHisLabelRecordTwo(&label)
  5834. fmt.Println(goodOutConfig.IsOpen)
  5835. if goodOutConfig.IsOpen != 1 {
  5836. if stockConfig.IsOpen == 1 {
  5837. if project.Type == 2 {
  5838. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5839. fmt.Println(err)
  5840. }
  5841. if project.Type == 3 && project.IsOut == 1 {
  5842. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5843. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5844. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5845. operation_time := time.Now().Unix()
  5846. creater := adminInfo.AdminUser.Id
  5847. //创建退库单
  5848. timeStr := time.Now().Format("2006-01-02")
  5849. timeArr := strings.Split(timeStr, "-")
  5850. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5851. total = total + 1
  5852. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5853. cancelStock := models.CancelStock{
  5854. OrderNumber: orderNumber,
  5855. OperaTime: operation_time,
  5856. OrgId: adminInfo.CurrentOrgId,
  5857. Creater: creater,
  5858. Ctime: time.Now().Unix(),
  5859. Status: 1,
  5860. ReturnTime: project.RecordDate,
  5861. Type: 1,
  5862. StorehouseId: houseConfig.StorehouseOutInfo,
  5863. IsCheck: 1,
  5864. }
  5865. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5866. if msgerrkonde == gorm.ErrRecordNotFound {
  5867. service.AddSigleCancelStock(&cancelStock)
  5868. }
  5869. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5870. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5871. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5872. //查询是否有出库
  5873. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5874. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5875. deaerler, _ := service.GetDealerById(info.Dealer)
  5876. if info.ID > 0 {
  5877. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5878. if info.Count >= prescribingNumber {
  5879. cancelStockInfo := models.CancelStockInfo{
  5880. GoodId: project.ProjectId,
  5881. CancelStockId: cancel.ID,
  5882. GoodTypeId: good.GoodTypeId,
  5883. Count: prescribingNumber,
  5884. Price: info.Price,
  5885. Total: 0,
  5886. ProductDate: info.ProductDate,
  5887. ExpiryDate: info.ExpiryDate,
  5888. Ctime: time.Now().Unix(),
  5889. Status: 1,
  5890. OrgId: adminInfo.CurrentOrgId,
  5891. OrderNumber: cancel.OrderNumber,
  5892. Type: 0,
  5893. Dealer: deaerler.DealerName,
  5894. Manufacturer: manufacturer.ManufacturerName,
  5895. Number: info.Number,
  5896. RegisterAccount: "",
  5897. Remark: "",
  5898. WarehouseInfoId: info.WarehouseInfotId,
  5899. PatientId: info.PatientId,
  5900. RecordDate: info.SysRecordTime,
  5901. StorehouseId: houseConfig.StorehouseOutInfo,
  5902. IsCheck: 1,
  5903. }
  5904. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5905. //回退库存
  5906. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5907. //退库数量增加
  5908. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5909. //出库数量减少
  5910. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5911. }
  5912. if info.Count < prescribingNumber {
  5913. cancelStockInfo := models.CancelStockInfo{
  5914. GoodId: project.ProjectId,
  5915. CancelStockId: cancel.ID,
  5916. GoodTypeId: good.GoodTypeId,
  5917. Count: info.Count,
  5918. Price: info.Price,
  5919. Total: 0,
  5920. ProductDate: info.ProductDate,
  5921. ExpiryDate: info.ExpiryDate,
  5922. Ctime: time.Now().Unix(),
  5923. Status: 1,
  5924. OrgId: adminInfo.CurrentOrgId,
  5925. OrderNumber: cancel.OrderNumber,
  5926. Type: 0,
  5927. Dealer: deaerler.DealerName,
  5928. Manufacturer: manufacturer.ManufacturerName,
  5929. Number: info.Number,
  5930. RegisterAccount: "",
  5931. Remark: "",
  5932. WarehouseInfoId: info.WarehouseInfotId,
  5933. PatientId: info.PatientId,
  5934. RecordDate: info.SysRecordTime,
  5935. StorehouseId: houseConfig.StorehouseOutInfo,
  5936. IsCheck: 1,
  5937. }
  5938. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5939. //回退库存
  5940. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5941. //退库数量增加
  5942. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5943. //出库数量减少
  5944. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5945. }
  5946. //查询剩余库存
  5947. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5948. var over_count int64
  5949. for _, it := range goodList {
  5950. over_count += it.StockCount
  5951. }
  5952. //出库数据 大于 退库数量
  5953. if info.Count >= prescribingNumber {
  5954. flow := models.VmStockFlow{
  5955. WarehousingId: info.WarehouseInfotId,
  5956. GoodId: project.ProjectId,
  5957. Number: info.Number,
  5958. LicenseNumber: info.LicenseNumber,
  5959. Count: prescribingNumber,
  5960. UserOrgId: adminInfo.CurrentOrgId,
  5961. PatientId: project.PatientId,
  5962. SystemTime: info.SysRecordTime,
  5963. ConsumableType: 7,
  5964. IsSys: 0,
  5965. WarehousingOrder: "",
  5966. WarehouseOutId: info.WarehouseOutId,
  5967. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5968. IsEdit: 0,
  5969. CancelStockId: cancel.ID,
  5970. CancelOrderNumber: cancel.OrderNumber,
  5971. Manufacturer: manufacturer.ID,
  5972. Dealer: 0,
  5973. Creator: adminInfo.AdminUser.Id,
  5974. UpdateCreator: 0,
  5975. Status: 1,
  5976. Ctime: time.Now().Unix(),
  5977. Mtime: 0,
  5978. Price: info.Price,
  5979. WarehousingDetailId: info.WarehouseInfotId,
  5980. WarehouseOutDetailId: info.ID,
  5981. CancelOutDetailId: cancelInfo.ID,
  5982. ProductDate: info.ProductDate,
  5983. ExpireDate: info.ExpiryDate,
  5984. StorehouseId: houseConfig.StorehouseOutInfo,
  5985. OverCount: over_count,
  5986. OperateTime: time.Now().Unix(),
  5987. }
  5988. service.CreateStockFlowOne(flow)
  5989. }
  5990. //出库数据小于退库数据
  5991. if info.Count < prescribingNumber {
  5992. flow := models.VmStockFlow{
  5993. WarehousingId: info.WarehouseInfotId,
  5994. GoodId: project.ProjectId,
  5995. Number: info.Number,
  5996. LicenseNumber: info.LicenseNumber,
  5997. Count: info.Count,
  5998. UserOrgId: adminInfo.CurrentOrgId,
  5999. PatientId: project.PatientId,
  6000. SystemTime: info.SysRecordTime,
  6001. ConsumableType: 7,
  6002. IsSys: 0,
  6003. WarehousingOrder: "",
  6004. WarehouseOutId: info.WarehouseOutId,
  6005. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6006. IsEdit: 0,
  6007. CancelStockId: cancel.ID,
  6008. CancelOrderNumber: cancel.OrderNumber,
  6009. Manufacturer: manufacturer.ID,
  6010. Dealer: 0,
  6011. Creator: adminInfo.AdminUser.Id,
  6012. UpdateCreator: 0,
  6013. Status: 1,
  6014. Ctime: time.Now().Unix(),
  6015. Mtime: 0,
  6016. Price: info.Price,
  6017. WarehousingDetailId: info.WarehouseInfotId,
  6018. WarehouseOutDetailId: info.ID,
  6019. CancelOutDetailId: cancelInfo.ID,
  6020. ProductDate: info.ProductDate,
  6021. ExpireDate: info.ExpiryDate,
  6022. StorehouseId: houseConfig.StorehouseOutInfo,
  6023. OverCount: over_count,
  6024. OperateTime: time.Now().Unix(),
  6025. }
  6026. service.CreateStockFlowOne(flow)
  6027. }
  6028. //查询已出库数量
  6029. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6030. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6031. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6032. if prescribingNumber < dialysisInfo.Count {
  6033. //改变数量
  6034. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6035. }
  6036. if prescribingNumber >= dialysisInfo.Count {
  6037. //删除出库表
  6038. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6039. }
  6040. //更新剩余库存
  6041. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6042. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6043. var total_count_one int64
  6044. for _, it := range stockList {
  6045. total_count_one += it.StockCount
  6046. }
  6047. //基础库插入数据
  6048. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6049. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6050. var flush_count int64
  6051. for _, it := range goodListOne {
  6052. flush_count += it.StockCount
  6053. }
  6054. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6055. if errs != nil {
  6056. goodErrcode := models.XtGoodErrcode{
  6057. UserOrgId: project.UserOrgId,
  6058. Errcode: "手动出库更新剩余出库失败",
  6059. GoodId: project.ProjectId,
  6060. Status: 1,
  6061. Ctime: time.Now().Unix(),
  6062. Mtime: 0,
  6063. Count: 0,
  6064. StockCount: 0,
  6065. Creater: creater,
  6066. BatchNumberId: 0,
  6067. WarehouseOutId: 0,
  6068. }
  6069. service.CreateGoodErrcode(goodErrcode)
  6070. }
  6071. }
  6072. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6073. fmt.Println(err)
  6074. } else {
  6075. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6076. fmt.Println(err)
  6077. }
  6078. } else {
  6079. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6080. fmt.Println(err)
  6081. }
  6082. }
  6083. //保存处方出库
  6084. if goodOutConfig.IsOpen == 1 {
  6085. if project.Type == 3 {
  6086. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6087. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6088. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6089. operation_time := time.Now().Unix()
  6090. creater := adminInfo.AdminUser.Id
  6091. //创建退库单
  6092. timeStr := time.Now().Format("2006-01-02")
  6093. timeArr := strings.Split(timeStr, "-")
  6094. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6095. total = total + 1
  6096. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6097. cancelStock := models.CancelStock{
  6098. OrderNumber: orderNumber,
  6099. OperaTime: operation_time,
  6100. OrgId: adminInfo.CurrentOrgId,
  6101. Creater: creater,
  6102. Ctime: time.Now().Unix(),
  6103. Status: 1,
  6104. ReturnTime: project.RecordDate,
  6105. Type: 1,
  6106. StorehouseId: houseConfig.StorehouseOutInfo,
  6107. IsCheck: 1,
  6108. }
  6109. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6110. if msgerrkonde == gorm.ErrRecordNotFound {
  6111. service.AddSigleCancelStock(&cancelStock)
  6112. }
  6113. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6114. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6115. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6116. //获取出库数据
  6117. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6118. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6119. deaerler, _ := service.GetDealerById(info.Dealer)
  6120. if info.ID > 0 {
  6121. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6122. if info.Count >= prescribingNumber {
  6123. cancelStockInfo := models.CancelStockInfo{
  6124. GoodId: project.ProjectId,
  6125. CancelStockId: cancel.ID,
  6126. GoodTypeId: good.GoodTypeId,
  6127. Count: prescribingNumber,
  6128. Price: info.Price,
  6129. Total: 0,
  6130. ProductDate: info.ProductDate,
  6131. ExpiryDate: info.ExpiryDate,
  6132. Ctime: time.Now().Unix(),
  6133. Status: 1,
  6134. OrgId: adminInfo.CurrentOrgId,
  6135. OrderNumber: cancel.OrderNumber,
  6136. Type: 0,
  6137. Dealer: deaerler.DealerName,
  6138. Manufacturer: manufacturer.ManufacturerName,
  6139. Number: info.Number,
  6140. RegisterAccount: "",
  6141. Remark: "",
  6142. WarehouseInfoId: info.WarehouseInfotId,
  6143. PatientId: info.PatientId,
  6144. RecordDate: info.SysRecordTime,
  6145. StorehouseId: houseConfig.StorehouseOutInfo,
  6146. IsCheck: 1,
  6147. }
  6148. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6149. //退库数量增加
  6150. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6151. //出库数量减少
  6152. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6153. }
  6154. if info.Count < prescribingNumber {
  6155. cancelStockInfo := models.CancelStockInfo{
  6156. GoodId: project.ProjectId,
  6157. CancelStockId: cancel.ID,
  6158. GoodTypeId: good.GoodTypeId,
  6159. Count: prescribingNumber,
  6160. Price: info.Price,
  6161. Total: 0,
  6162. ProductDate: info.ProductDate,
  6163. ExpiryDate: info.ExpiryDate,
  6164. Ctime: time.Now().Unix(),
  6165. Status: 1,
  6166. OrgId: adminInfo.CurrentOrgId,
  6167. OrderNumber: cancel.OrderNumber,
  6168. Type: 0,
  6169. Dealer: deaerler.DealerName,
  6170. Manufacturer: manufacturer.ManufacturerName,
  6171. Number: info.Number,
  6172. RegisterAccount: "",
  6173. Remark: "",
  6174. WarehouseInfoId: info.WarehouseInfotId,
  6175. PatientId: info.PatientId,
  6176. RecordDate: info.SysRecordTime,
  6177. StorehouseId: houseConfig.StorehouseOutInfo,
  6178. IsCheck: 1,
  6179. }
  6180. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6181. //回退库存
  6182. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6183. }
  6184. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6185. var over_count int64
  6186. for _, it := range goodList {
  6187. over_count += it.StockCount
  6188. }
  6189. //查询出库数量
  6190. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6191. //出库数据 大于 退库数量
  6192. if len(list) > 0 {
  6193. for _, it := range list {
  6194. //回退库存
  6195. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6196. //退库数量增加
  6197. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6198. //出库数量减少
  6199. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6200. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6201. var over_count_one int64
  6202. for _, it := range goodList {
  6203. over_count_one += it.StockCount
  6204. }
  6205. //查询该批次是否有退库数据
  6206. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6207. flow := models.VmStockFlow{
  6208. WarehousingId: it.WarehouseInfotId,
  6209. GoodId: it.GoodId,
  6210. Number: it.Number,
  6211. LicenseNumber: it.LicenseNumber,
  6212. Count: it.Count,
  6213. UserOrgId: adminInfo.CurrentOrgId,
  6214. PatientId: it.PatientId,
  6215. SystemTime: it.SysRecordTime,
  6216. ConsumableType: 7,
  6217. IsSys: 0,
  6218. WarehousingOrder: "",
  6219. WarehouseOutId: it.WarehouseOutId,
  6220. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6221. IsEdit: 0,
  6222. CancelStockId: cancel.ID,
  6223. CancelOrderNumber: cancel.OrderNumber,
  6224. Manufacturer: manufacturer.ID,
  6225. Dealer: 0,
  6226. Creator: adminInfo.AdminUser.Id,
  6227. UpdateCreator: 0,
  6228. Status: 1,
  6229. Ctime: time.Now().Unix(),
  6230. Mtime: 0,
  6231. Price: it.Price,
  6232. WarehousingDetailId: it.WarehouseInfotId,
  6233. WarehouseOutDetailId: it.ID,
  6234. CancelOutDetailId: cancelInfo.ID,
  6235. ProductDate: it.ProductDate,
  6236. ExpireDate: it.ExpiryDate,
  6237. StorehouseId: houseConfig.StorehouseOutInfo,
  6238. OverCount: over_count_one,
  6239. OperateTime: time.Now().Unix(),
  6240. }
  6241. service.CreateStockFlowOne(flow)
  6242. }
  6243. }
  6244. //查询已出库数量
  6245. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6246. if prescribingNumber < dialysisInfo.Count {
  6247. //改变数量
  6248. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6249. }
  6250. if prescribingNumber >= dialysisInfo.Count {
  6251. //删除出库表
  6252. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6253. }
  6254. //更新剩余库存
  6255. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6256. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6257. var total_count_one int64
  6258. for _, it := range stockList {
  6259. total_count_one += it.StockCount
  6260. }
  6261. //基础库插入数据
  6262. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6263. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6264. var flush_count int64
  6265. for _, it := range goodListOne {
  6266. flush_count += it.StockCount
  6267. }
  6268. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6269. if errs != nil {
  6270. goodErrcode := models.XtGoodErrcode{
  6271. UserOrgId: project.UserOrgId,
  6272. Errcode: "手动出库更新剩余出库失败",
  6273. GoodId: project.ProjectId,
  6274. Status: 1,
  6275. Ctime: time.Now().Unix(),
  6276. Mtime: 0,
  6277. Count: 0,
  6278. StockCount: 0,
  6279. Creater: creater,
  6280. BatchNumberId: 0,
  6281. WarehouseOutId: 0,
  6282. }
  6283. service.CreateGoodErrcode(goodErrcode)
  6284. }
  6285. }
  6286. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6287. fmt.Println(err)
  6288. } else {
  6289. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6290. fmt.Println(err)
  6291. }
  6292. }
  6293. c.ServeSuccessJSON(map[string]interface{}{
  6294. "msg": "删除成功",
  6295. })
  6296. return
  6297. }
  6298. func (c *HisApiController) CreateHisAdditionalCharge() {
  6299. his_patient_id, _ := c.GetInt64("his_patient_id")
  6300. patient_id, _ := c.GetInt64("patient_id")
  6301. record_date := c.GetString("record_date")
  6302. timeLayout := "2006-01-02"
  6303. loc, _ := time.LoadLocation("Local")
  6304. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6305. if err != nil {
  6306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6307. return
  6308. }
  6309. adminInfo := c.GetAdminUserInfo()
  6310. recordDateTime := theTime.Unix()
  6311. dataBody := make(map[string]interface{}, 0)
  6312. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6313. if err != nil {
  6314. utils.ErrorLog(err.Error())
  6315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6316. return
  6317. }
  6318. var additions []*models.HisAdditionalCharge
  6319. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6320. additions, _ := dataBody["addition"].([]interface{})
  6321. if len(additions) > 0 {
  6322. for _, item := range additions {
  6323. items := item.(map[string]interface{})
  6324. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6325. utils.ErrorLog("item_id")
  6326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6327. return
  6328. }
  6329. item_id := int64(items["item_id"].(float64))
  6330. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6331. utils.ErrorLog("item_name")
  6332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6333. return
  6334. }
  6335. item_name := items["item_name"].(string)
  6336. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6337. utils.ErrorLog("price")
  6338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6339. return
  6340. }
  6341. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6342. ctime := time.Now().Unix()
  6343. additional := &models.HisAdditionalCharge{
  6344. PatientId: patient_id,
  6345. HisPatientId: his_patient_id,
  6346. UserOrgId: adminInfo.CurrentOrgId,
  6347. RecordDate: recordDateTime,
  6348. CreatedTime: ctime,
  6349. UpdatedTime: ctime,
  6350. Modifier: adminInfo.AdminUser.Id,
  6351. Creator: adminInfo.AdminUser.Id,
  6352. Price: price,
  6353. ItemName: item_name,
  6354. ItemId: item_id,
  6355. Status: 1,
  6356. }
  6357. additions = append(additions, additional)
  6358. }
  6359. }
  6360. }
  6361. for _, item := range additions {
  6362. service.CreateAddtionalCharge(item)
  6363. }
  6364. c.ServeSuccessJSON(map[string]interface{}{
  6365. "msg": "创建成功",
  6366. })
  6367. }
  6368. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6369. blood_fat := c.GetString("blood_fat")
  6370. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6371. blood_sugar := c.GetString("blood_sugar")
  6372. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6373. chief_conplaint := c.GetString("chief_conplaint")
  6374. dbp := c.GetString("dbp")
  6375. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6376. delivery_way, _ := c.GetInt64("delivery_way")
  6377. diagnostic := c.GetString("diagnostic")
  6378. family_history := c.GetString("family_history")
  6379. height := c.GetString("height")
  6380. history_of_present_illness := c.GetString("history_of_present_illness")
  6381. is_infect, _ := c.GetInt64("is_infect")
  6382. past_history := c.GetString("past_history")
  6383. patient_id, _ := c.GetInt64("patient_id")
  6384. his_patient_id, _ := c.GetInt64("his_patient_id")
  6385. personal_history := c.GetString("personal_history")
  6386. pulse := c.GetString("pulse")
  6387. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6388. sbp := c.GetString("sbp")
  6389. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6390. heightfloat, _ := strconv.ParseFloat(height, 64)
  6391. sicktype := c.GetString("sick_type")
  6392. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6393. symptom := c.GetString("symptom")
  6394. sick_date := c.GetString("sick_date")
  6395. temperatures := c.GetString("temperature")
  6396. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6397. record_date := c.GetString("record_date")
  6398. breathing := c.GetString("breathing")
  6399. doctor_advice := c.GetString("doctor_advice")
  6400. remark := c.GetString("remark")
  6401. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6402. sick, _ := c.GetInt64("sick")
  6403. diagnose, _ := c.GetInt64("diagnose")
  6404. //id, _ := c.GetInt64("id")
  6405. timeLayout := "2006-01-02"
  6406. loc, _ := time.LoadLocation("Local")
  6407. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6408. allergic_history := c.GetString("allergic_history")
  6409. if err != nil {
  6410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6411. return
  6412. }
  6413. recordDateTime := theTime.Unix()
  6414. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6415. if err != nil {
  6416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6417. return
  6418. }
  6419. sickTimes := sickTime.Unix()
  6420. ctime := time.Now().Unix()
  6421. primary_disease := c.GetString("primary_disease")
  6422. confirm_failure_date := c.GetString("confirm_failure_date")
  6423. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6424. drug_allergy_history := c.GetString("drug_allergy_history")
  6425. physical_examination := c.GetString("physical_examination")
  6426. special_inspection := c.GetString("special_inspection")
  6427. lab_apparatus := c.GetString("lab_apparatus")
  6428. caseHistory := models.HisPatientCaseHistory{
  6429. HisPatientId: his_patient_id,
  6430. PatientId: patient_id,
  6431. Temperature: temperature,
  6432. BloodSugar: bloodsugarfloat,
  6433. Pulse: pulsefloat,
  6434. Sbp: sbpfloat,
  6435. Dbp: dbpfloat,
  6436. Height: heightfloat,
  6437. BloodFat: bloodfatfloat,
  6438. SickType: sick_type,
  6439. Symptom: symptom,
  6440. SickDate: sickTimes,
  6441. IsInfect: is_infect,
  6442. HistoryOfPresentIllness: history_of_present_illness,
  6443. PastHistory: past_history,
  6444. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6445. ChiefConplaint: chief_conplaint,
  6446. PersonalHistory: personal_history,
  6447. FamilyHistory: family_history,
  6448. Diagnostic: diagnostic,
  6449. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6450. Status: 1,
  6451. Ctime: ctime,
  6452. Mtime: ctime,
  6453. RecordDate: recordDateTime,
  6454. DeliveryWay: delivery_way,
  6455. Breathing: breathingfloat,
  6456. DoctorAdvice: doctor_advice,
  6457. Remark: remark,
  6458. Sick: sick,
  6459. Diagnose: diagnose,
  6460. AllergicHistory: allergic_history,
  6461. PrimaryDisease: primary_disease,
  6462. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6463. DrugAllergyHistory: drug_allergy_history,
  6464. PhysicalExamination: physical_examination,
  6465. SpecialInspection: special_inspection,
  6466. LabApparatus: lab_apparatus,
  6467. }
  6468. //查询该患者是否有病历
  6469. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6470. if errcodes == gorm.ErrRecordNotFound {
  6471. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6472. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6473. if err != nil {
  6474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6475. return
  6476. }
  6477. c.ServeSuccessJSON(map[string]interface{}{
  6478. "caseHistory": caseHistory,
  6479. "historyInfo": historyInfo,
  6480. })
  6481. return
  6482. } else if errcodes == nil {
  6483. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6484. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6485. if err != nil {
  6486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6487. return
  6488. }
  6489. c.ServeSuccessJSON(map[string]interface{}{
  6490. "caseHistory": caseHistory,
  6491. "historyInfo": historyInfo,
  6492. })
  6493. }
  6494. //查询该患者是否有病历
  6495. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6496. //if errcode == gorm.ErrRecordNotFound {
  6497. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6498. // if err != nil {
  6499. // c.ServeSuccessJSON(map[string]interface{}{
  6500. // "msg": "保存成功",
  6501. // })
  6502. // }
  6503. //} else if errcode == nil {
  6504. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6505. // return
  6506. //}
  6507. }
  6508. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6509. patient_id, _ := c.GetInt64("patient_id", 0)
  6510. adminUser := c.GetAdminUserInfo()
  6511. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6512. c.ServeSuccessJSON(map[string]interface{}{
  6513. "list": caseHistorys,
  6514. })
  6515. }
  6516. func (c *HisApiController) GetHisPatientCaseHistory() {
  6517. record_date, _ := c.GetInt64("record_date", 0)
  6518. patient_id, _ := c.GetInt64("patient_id", 0)
  6519. admin := c.GetAdminUserInfo()
  6520. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6521. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6522. c.ServeSuccessJSON(map[string]interface{}{
  6523. "info": info,
  6524. "case_history": case_history,
  6525. })
  6526. }
  6527. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6528. template_name := c.GetString("template_name")
  6529. template_remark := c.GetString("template_remark")
  6530. doctor := c.GetAdminUserInfo().AdminUser.Id
  6531. diagnostic := c.GetString("diagnostic")
  6532. chief_conplaint := c.GetString("chief_conplain")
  6533. history_of_present_illness := c.GetString("history_of_present_illness")
  6534. past_history := c.GetString("past_history")
  6535. personal_history := c.GetString("personal_history")
  6536. family_history := c.GetString("family_history")
  6537. user_name := c.GetString("user_name")
  6538. doctor_advice := c.GetString("doctor_advice")
  6539. remark := c.GetString("remark")
  6540. //record_date := c.GetString("record_date")
  6541. //fmt.Println("record_date--------",record_date)
  6542. //timeLayout := "2006-01-02"
  6543. //loc, _ := time.LoadLocation("Local")
  6544. //
  6545. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6546. //if err != nil {
  6547. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6548. // return
  6549. //}
  6550. //recordDateTime := theTime.Unix()
  6551. ctime := time.Now().Unix()
  6552. template := models.HisCaseHistoryTemplate{
  6553. HistoryOfPresentIllness: history_of_present_illness,
  6554. PastHistory: past_history,
  6555. ChiefConplaint: chief_conplaint,
  6556. PersonalHistory: personal_history,
  6557. FamilyHistory: family_history,
  6558. Diagnostic: diagnostic,
  6559. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6560. Status: 1,
  6561. Ctime: ctime,
  6562. Mtime: ctime,
  6563. RecordDate: time.Now().Unix(),
  6564. TemplateName: template_name,
  6565. TemplateRemark: template_remark,
  6566. Creator: doctor,
  6567. Modifier: doctor,
  6568. UserName: user_name,
  6569. DoctorAdvice: doctor_advice,
  6570. Remark: remark,
  6571. }
  6572. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6573. if err == nil {
  6574. c.ServeSuccessJSON(map[string]interface{}{
  6575. "msg": "保存成功",
  6576. })
  6577. } else {
  6578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6579. return
  6580. }
  6581. }
  6582. func (c *HisApiController) GetCaseHistoryTemplate() {
  6583. timeLayout := "2006-01-02"
  6584. loc, _ := time.LoadLocation("Local")
  6585. keyword := c.GetString("keyword")
  6586. start_time := c.GetString("start_time")
  6587. end_time := c.GetString("end_time")
  6588. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6589. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6590. admin := c.GetAdminUserInfo()
  6591. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6592. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6593. c.ServeSuccessJSON(map[string]interface{}{
  6594. "template": template,
  6595. //"history": history,
  6596. })
  6597. }
  6598. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6599. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6600. utils.ErrorLog("drug_name")
  6601. return enums.ErrorCodeParamWrong
  6602. }
  6603. adviceName, _ := json["drug_name"].(string)
  6604. if len(adviceName) == 0 {
  6605. utils.ErrorLog("len(advice_name) == 0")
  6606. return enums.ErrorCodeParamWrong
  6607. }
  6608. advice.AdviceName = adviceName
  6609. adviceDesc, _ := json["advice_desc"].(string)
  6610. advice.AdviceDesc = adviceDesc
  6611. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6612. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6613. advice.DrugSpec = drugSpec
  6614. }
  6615. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6616. remark, _ := json["remark"].(string)
  6617. advice.Remark = remark
  6618. }
  6619. if json["id"] == nil {
  6620. advice.DrugId = 0
  6621. } else {
  6622. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6623. drug_id := int64(json["id"].(float64))
  6624. advice.DrugId = drug_id
  6625. }
  6626. }
  6627. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6628. advice_id := int64(json["advice_id"].(float64))
  6629. advice.ID = advice_id
  6630. if advice.ID > 0 {
  6631. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6632. if err == nil {
  6633. if hisAdvice.ID > 0 {
  6634. advice.ExecutionTime = hisAdvice.ExecutionTime
  6635. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6636. advice.ExecutionState = hisAdvice.ExecutionState
  6637. advice.CheckTime = hisAdvice.CheckTime
  6638. advice.Checker = hisAdvice.Checker
  6639. advice.CheckState = hisAdvice.CheckState
  6640. advice.StartTime = hisAdvice.StartTime
  6641. advice.FeedetlSn = hisAdvice.FeedetlSn
  6642. }
  6643. }
  6644. }
  6645. }
  6646. //
  6647. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6648. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6649. // advice.ExecutionTime = execution_time
  6650. //}
  6651. //
  6652. //
  6653. //
  6654. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6655. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6656. // advice.ExecutionStaff = execution_staff
  6657. //}
  6658. //
  6659. //
  6660. //
  6661. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6662. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6663. // advice.ExecutionState = execution_state
  6664. //}
  6665. //
  6666. //
  6667. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6668. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6669. // advice.CheckTime = check_time
  6670. //}
  6671. //
  6672. //
  6673. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6674. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6675. // advice.CheckState = check_state
  6676. //}
  6677. //
  6678. //
  6679. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6680. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6681. // advice.Checker = checker
  6682. //}
  6683. //
  6684. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6685. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6686. // advice.StartTime = start_time
  6687. //}
  6688. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6689. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6690. advice.IsSelfDrug = is_self_drug
  6691. }
  6692. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6693. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6694. drug_way_count, _ := json["drug_way_count"].(string)
  6695. advice.DrugWayCount = drug_way_count
  6696. }
  6697. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6698. drugSpecUnit, _ := json["min_unit"].(string)
  6699. advice.DrugSpecUnit = drugSpecUnit
  6700. }
  6701. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6702. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6703. advice.SingleDose = singleDose
  6704. }
  6705. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6706. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6707. advice.SingleDoseUnit = singleDoseUnit
  6708. }
  6709. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6710. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6711. advice.PrescribingNumber = prescribingNumber
  6712. }
  6713. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6714. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6715. advice.PrescribingNumberUnit = prescribingNumberUnit
  6716. }
  6717. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6718. deliveryWay, _ := json["delivery_way"].(string)
  6719. advice.DeliveryWay = deliveryWay
  6720. }
  6721. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6722. executionFrequency, _ := json["execution_frequency"].(string)
  6723. advice.ExecutionFrequency = executionFrequency
  6724. }
  6725. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6726. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6727. advice.Price = price
  6728. }
  6729. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6730. med_list_codg, _ := json["medical_insurance_number"].(string)
  6731. advice.MedListCodg = med_list_codg
  6732. }
  6733. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6734. day := int64(json["day"].(float64))
  6735. advice.Day = day
  6736. }
  6737. return 0
  6738. }
  6739. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6740. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6741. id := int64(json["id"].(float64))
  6742. project.ID = id
  6743. historyProject, _ := service.GetHisProjectByID(id)
  6744. project.FeedetlSn = historyProject.FeedetlSn
  6745. }
  6746. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6747. project_id := int64(json["project_id"].(float64))
  6748. project.ProjectId = project_id
  6749. }
  6750. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6751. // price := int64(json["price"].(float64))
  6752. // formatInt_price := strconv.FormatInt(price, 10)
  6753. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6754. // project.Price = float_price
  6755. // }
  6756. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6757. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6758. project.Price = price
  6759. }
  6760. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6761. total, _ := json["total"].(string)
  6762. project.Count = total
  6763. }
  6764. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6765. medical_code, _ := json["medical_code"].(string)
  6766. project.MedListCodg = medical_code
  6767. }
  6768. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6769. single_dose, _ := json["single_dose"].(string)
  6770. project.SingleDose = single_dose
  6771. }
  6772. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6773. delivery_way, _ := json["delivery_way"].(string)
  6774. project.DeliveryWay = delivery_way
  6775. }
  6776. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6777. execution_frequency, _ := json["execution_frequency"].(string)
  6778. project.ExecutionFrequency = execution_frequency
  6779. }
  6780. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6781. remark, _ := json["remark"].(string)
  6782. project.Remark = remark
  6783. }
  6784. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6785. day, _ := json["number_days"].(string)
  6786. project.Day = day
  6787. }
  6788. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6789. unit, _ := json["unit"].(string)
  6790. project.Unit = unit
  6791. }
  6792. return 0
  6793. }
  6794. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6795. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6796. id := int64(json["id"].(float64))
  6797. historyAddtions, _ := service.GetHisAdditionByID(id)
  6798. additionalCharge.ID = id
  6799. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6800. }
  6801. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6802. item_id := int64(json["item_id"].(float64))
  6803. additionalCharge.ItemId = item_id
  6804. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6805. if config.ID > 0 {
  6806. if len(config.Code) > 0 {
  6807. additionalCharge.MedListCodg = config.Code
  6808. }
  6809. }
  6810. }
  6811. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6812. // price := int64(json["price"].(float64))
  6813. // formatInt_price := strconv.FormatInt(price, 10)
  6814. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6815. // additionalCharge.Price = float_price
  6816. // }
  6817. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6818. // price := int64(json["price"].(float64))
  6819. // formatInt_price := strconv.FormatInt(price, 10)
  6820. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6821. // additionalCharge.Price = float_price
  6822. //}
  6823. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6824. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6825. additionalCharge.Price = price
  6826. }
  6827. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6828. count, _ := json["count"].(string)
  6829. counts, _ := strconv.ParseInt(count, 10, 64)
  6830. additionalCharge.Count = counts
  6831. }
  6832. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6833. item_name, _ := json["item_name"].(string)
  6834. additionalCharge.ItemName = item_name
  6835. }
  6836. return 0
  6837. }
  6838. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6839. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6840. utils.ErrorLog("drug_name")
  6841. return enums.ErrorCodeParamWrong
  6842. }
  6843. adviceName, _ := json["drug_name"].(string)
  6844. if len(adviceName) == 0 {
  6845. utils.ErrorLog("len(advice_name) == 0")
  6846. return enums.ErrorCodeParamWrong
  6847. }
  6848. advice.AdviceName = adviceName
  6849. adviceDesc, _ := json["advice_desc"].(string)
  6850. advice.AdviceDesc = adviceDesc
  6851. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6852. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6853. advice.DrugSpec = drugSpec
  6854. }
  6855. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6856. remark, _ := json["remark"].(string)
  6857. advice.Remark = remark
  6858. }
  6859. if json["id"] == nil {
  6860. advice.DrugId = 0
  6861. } else {
  6862. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6863. drug_id := int64(json["id"].(float64))
  6864. advice.DrugId = drug_id
  6865. }
  6866. }
  6867. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6868. groupno := int64(json["groupno"].(float64))
  6869. advice.Groupno = groupno
  6870. }
  6871. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6872. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6873. advice.IsSelfDrug = is_self_drug
  6874. }
  6875. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6876. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6877. drug_way_count, _ := json["drug_way_count"].(string)
  6878. advice.DrugWayCount = drug_way_count
  6879. }
  6880. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6881. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6882. advice.HospApprFlag = hosp_appr_flag
  6883. }
  6884. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6885. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6886. advice.PrescribingNumber = prescribingNumber
  6887. }
  6888. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6889. // frequency_type := int64(json["frequency_type"].(float64))
  6890. // advice.FrequencyType = frequency_type
  6891. //}
  6892. //
  6893. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6894. // day_count := int64(json["day_count"].(float64))
  6895. // advice.DayCount = day_count
  6896. //}
  6897. //
  6898. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6899. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6900. // week_day, _ := json["week_day"].(string)
  6901. // advice.WeekDay = week_day
  6902. //}
  6903. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6904. drugSpecUnit, _ := json["min_unit"].(string)
  6905. advice.DrugSpecUnit = drugSpecUnit
  6906. }
  6907. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6908. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6909. advice.SingleDose = singleDose
  6910. }
  6911. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6912. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6913. advice.SingleDoseUnit = singleDoseUnit
  6914. }
  6915. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6916. deliveryWay, _ := json["delivery_way"].(string)
  6917. advice.DeliveryWay = deliveryWay
  6918. }
  6919. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6920. executionFrequency, _ := json["execution_frequency"].(string)
  6921. advice.ExecutionFrequency = executionFrequency
  6922. }
  6923. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6924. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6925. advice.Price = price
  6926. }
  6927. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6928. med_list_codg, _ := json["medical_insurance_number"].(string)
  6929. advice.MedListCodg = med_list_codg
  6930. }
  6931. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6932. day := int64(json["day"].(float64))
  6933. advice.Day = day
  6934. }
  6935. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6936. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6937. advice.PrescribingNumberUnit = prescribingNumberUnit
  6938. }
  6939. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6940. advice_id := int64(json["advice_id"].(float64))
  6941. advice.ID = advice_id
  6942. if advice.ID > 0 {
  6943. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6944. if err == nil {
  6945. if hisAdvice.ID > 0 {
  6946. advice.ExecutionTime = hisAdvice.ExecutionTime
  6947. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6948. advice.ExecutionState = hisAdvice.ExecutionState
  6949. advice.CheckTime = hisAdvice.CheckTime
  6950. advice.Checker = hisAdvice.Checker
  6951. advice.CheckState = hisAdvice.CheckState
  6952. advice.StartTime = hisAdvice.StartTime
  6953. advice.HospApprFlag = hisAdvice.HospApprFlag
  6954. advice.IsMedicine = hisAdvice.IsMedicine
  6955. if hisAdvice.UserOrgId == 10028 {
  6956. 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 {
  6957. advice.ExecutionTime = 0
  6958. advice.ExecutionStaff = 0
  6959. advice.ExecutionState = 2
  6960. advice.CheckTime = 0
  6961. advice.Checker = 0
  6962. advice.CheckState = 2
  6963. }
  6964. } else {
  6965. 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 {
  6966. advice.ExecutionTime = 0
  6967. advice.ExecutionStaff = 0
  6968. advice.ExecutionState = 2
  6969. advice.CheckTime = 0
  6970. advice.Checker = 0
  6971. advice.CheckState = 2
  6972. advice.UpdatedTime = time.Now().Unix()
  6973. }
  6974. }
  6975. //advice.Groupno = hisAdvice.Groupno
  6976. }
  6977. }
  6978. }
  6979. }
  6980. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6981. //
  6982. //if drugStockConfig.IsOpen == 1 {
  6983. //
  6984. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6985. // if advice.ID == 0 { //医嘱不存在
  6986. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6987. // drug.Total = drug.Total - advice.PrescribingNumber
  6988. // service.UpdateBaseDrugLib(&drug)
  6989. //
  6990. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6991. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6992. // drug.Total = drug.Total - num
  6993. // service.UpdateBaseDrugLib(&drug)
  6994. // }
  6995. //
  6996. // } else if advice.ID > 0 { //医嘱存在
  6997. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6998. // var num float64
  6999. //
  7000. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7001. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7002. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7003. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7004. // drug.Total = drug.Total + num
  7005. // service.UpdateBaseDrugLib(&drug)
  7006. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7007. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7008. // drug.Total = drug.Total - num
  7009. // service.UpdateBaseDrugLib(&drug)
  7010. // }
  7011. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7012. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7013. // if num2 > advice.PrescribingNumber {
  7014. // num = num2 - advice.PrescribingNumber
  7015. // drug.Total = drug.Total + num
  7016. // service.UpdateBaseDrugLib(&drug)
  7017. // } else if num2 < advice.PrescribingNumber {
  7018. // num = advice.PrescribingNumber - num2
  7019. // drug.Total = drug.Total - num
  7020. // service.UpdateBaseDrugLib(&drug)
  7021. // }
  7022. //
  7023. // }
  7024. //
  7025. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7026. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7027. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7028. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7029. // if num1 > num2 {
  7030. // num = num1 - num2
  7031. // drug.Total = drug.Total + num
  7032. // service.UpdateBaseDrugLib(&drug)
  7033. // } else if num1 < num2 {
  7034. // num = num2 - num1
  7035. // drug.Total = drug.Total - num
  7036. // service.UpdateBaseDrugLib(&drug)
  7037. // }
  7038. //
  7039. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7040. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7041. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7042. // if hisAdvice.PrescribingNumber > num2 {
  7043. // num = hisAdvice.PrescribingNumber - num2
  7044. // drug.Total = drug.Total + num
  7045. // service.UpdateBaseDrugLib(&drug)
  7046. // } else if num2 < advice.PrescribingNumber {
  7047. // num = num2 - hisAdvice.PrescribingNumber
  7048. // drug.Total = drug.Total - num
  7049. // service.UpdateBaseDrugLib(&drug)
  7050. // }
  7051. //
  7052. // }
  7053. // }
  7054. // }
  7055. //}
  7056. //
  7057. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7058. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7059. // advice.ExecutionTime = execution_time
  7060. //}
  7061. //
  7062. //
  7063. //
  7064. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7065. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7066. // advice.ExecutionStaff = execution_staff
  7067. //}
  7068. //
  7069. //
  7070. //
  7071. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7072. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7073. // advice.ExecutionState = execution_state
  7074. //}
  7075. //
  7076. //
  7077. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7078. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7079. // advice.CheckTime = check_time
  7080. //}
  7081. //
  7082. //
  7083. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7084. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7085. // advice.CheckState = check_state
  7086. //}
  7087. //
  7088. //
  7089. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7090. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7091. // advice.Checker = checker
  7092. //}
  7093. //
  7094. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7095. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7096. // advice.StartTime = start_time
  7097. //}
  7098. return 0
  7099. }
  7100. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7101. project.ExecutionStaff = 0
  7102. project.ExecutionState = 2
  7103. project.ExecutionTime = 0
  7104. project.Checker = 0
  7105. project.CheckState = 2
  7106. project.CheckTime = 0
  7107. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7108. id := int64(json["id"].(float64))
  7109. project.ID = id
  7110. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7111. project.ExecutionStaff = temp_project.ExecutionStaff
  7112. project.ExecutionState = temp_project.ExecutionState
  7113. project.ExecutionTime = temp_project.ExecutionTime
  7114. project.Checker = temp_project.Checker
  7115. project.CheckState = temp_project.CheckState
  7116. project.CheckTime = temp_project.CheckTime
  7117. project.TeamId = temp_project.TeamId
  7118. }
  7119. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7120. types := int64(json["type"].(float64))
  7121. project.Type = types
  7122. }
  7123. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7124. project_id := int64(json["project_id"].(float64))
  7125. project.ProjectId = project_id
  7126. }
  7127. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7128. team_id := int64(json["team_id"].(float64))
  7129. project.TeamId = team_id
  7130. }
  7131. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7132. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7133. project.Price = price
  7134. }
  7135. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7136. total, _ := json["total"].(string)
  7137. //totals, _ := strconv.ParseInt(total, 10, 64)
  7138. project.Count = total
  7139. }
  7140. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7141. medical_code, _ := json["medical_code"].(string)
  7142. project.MedListCodg = medical_code
  7143. }
  7144. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7145. single_dose, _ := json["single_dose"].(string)
  7146. project.SingleDose = single_dose
  7147. }
  7148. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7149. delivery_way, _ := json["delivery_way"].(string)
  7150. project.DeliveryWay = delivery_way
  7151. }
  7152. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7153. execution_frequency, _ := json["execution_frequency"].(string)
  7154. project.ExecutionFrequency = execution_frequency
  7155. }
  7156. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7157. remark, _ := json["remark"].(string)
  7158. project.Remark = remark
  7159. }
  7160. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7161. day, _ := json["number_days"].(string)
  7162. project.Day = day
  7163. }
  7164. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7165. unit, _ := json["unit"].(string)
  7166. project.Unit = unit
  7167. }
  7168. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7169. // frequency_type := int64(json["frequency_type"].(float64))
  7170. // project.FrequencyType = frequency_type
  7171. //}
  7172. //
  7173. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7174. // day_count := int64(json["day_count"].(float64))
  7175. // project.DayCount = day_count
  7176. //}
  7177. //
  7178. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7179. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7180. // week_day, _ := json["week_day"].(string)
  7181. // project.WeekDay = week_day
  7182. //}
  7183. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7184. //
  7185. //if project.ID == 0 {
  7186. // if stockConfig.IsOpen == 1 {
  7187. // if project.Type == 3 {
  7188. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7189. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7190. // good.Total = good.Total - f_count
  7191. // service.UpdateGoodInfo(&good)
  7192. // }
  7193. // }
  7194. //
  7195. //} else {
  7196. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7197. //
  7198. // if stockConfig.IsOpen == 1 {
  7199. // if project.Type == 3 {
  7200. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7201. // if project.Count < temp_project.Count {
  7202. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7203. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7204. //
  7205. // other_count := f_count_two - f_count_one
  7206. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7207. // good.Total = good.Total + other_count_two
  7208. // service.UpdateGoodInfo(&good)
  7209. // } else if project.Count > temp_project.Count {
  7210. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7211. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7212. //
  7213. // other_count := f_count_one - f_count_two
  7214. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7215. // good.Total = good.Total - other_count_two
  7216. // service.UpdateGoodInfo(&good)
  7217. // }
  7218. //
  7219. // }
  7220. // }
  7221. //
  7222. //}
  7223. return 0
  7224. }
  7225. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7226. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7227. utils.ErrorLog("drug_name")
  7228. return enums.ErrorCodeParamWrong
  7229. }
  7230. adviceName, _ := json["drug_name"].(string)
  7231. if len(adviceName) == 0 {
  7232. utils.ErrorLog("len(advice_name) == 0")
  7233. return enums.ErrorCodeParamWrong
  7234. }
  7235. advice.AdviceName = adviceName
  7236. adviceDesc, _ := json["advice_desc"].(string)
  7237. advice.AdviceDesc = adviceDesc
  7238. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7239. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7240. advice.DrugSpec = drugSpec
  7241. }
  7242. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7243. remark, _ := json["remark"].(string)
  7244. advice.Remark = remark
  7245. }
  7246. if json["id"] == nil {
  7247. advice.DrugId = 0
  7248. } else {
  7249. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7250. drug_id := int64(json["id"].(float64))
  7251. advice.DrugId = drug_id
  7252. }
  7253. }
  7254. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7255. groupno := int64(json["groupno"].(float64))
  7256. advice.Groupno = groupno
  7257. }
  7258. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7259. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7260. advice.IsSelfDrug = is_self_drug
  7261. }
  7262. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7263. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7264. drug_way_count, _ := json["drug_way_count"].(string)
  7265. advice.DrugWayCount = drug_way_count
  7266. }
  7267. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7268. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7269. advice.HospApprFlag = hosp_appr_flag
  7270. }
  7271. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7272. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7273. advice.PrescribingNumber = prescribingNumber
  7274. }
  7275. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7276. // frequency_type := int64(json["frequency_type"].(float64))
  7277. // advice.FrequencyType = frequency_type
  7278. //}
  7279. //
  7280. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7281. // day_count := int64(json["day_count"].(float64))
  7282. // advice.DayCount = day_count
  7283. //}
  7284. //
  7285. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7286. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7287. // week_day, _ := json["week_day"].(string)
  7288. // advice.WeekDay = week_day
  7289. //}
  7290. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7291. drugSpecUnit, _ := json["min_unit"].(string)
  7292. advice.DrugSpecUnit = drugSpecUnit
  7293. }
  7294. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7295. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7296. advice.SingleDose = singleDose
  7297. }
  7298. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7299. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7300. advice.SingleDoseUnit = singleDoseUnit
  7301. }
  7302. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7303. deliveryWay, _ := json["delivery_way"].(string)
  7304. advice.DeliveryWay = deliveryWay
  7305. }
  7306. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7307. executionFrequency, _ := json["execution_frequency"].(string)
  7308. advice.ExecutionFrequency = executionFrequency
  7309. }
  7310. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7311. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7312. advice.Price = price
  7313. }
  7314. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7315. med_list_codg, _ := json["medical_insurance_number"].(string)
  7316. advice.MedListCodg = med_list_codg
  7317. }
  7318. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7319. day := int64(json["day"].(float64))
  7320. advice.Day = day
  7321. }
  7322. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7323. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7324. advice.PrescribingNumberUnit = prescribingNumberUnit
  7325. }
  7326. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7327. advice_id := int64(json["advice_id"].(float64))
  7328. advice.ID = advice_id
  7329. if advice.ID > 0 {
  7330. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7331. if err == nil {
  7332. if hisAdvice.ID > 0 {
  7333. advice.ExecutionTime = hisAdvice.ExecutionTime
  7334. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7335. advice.ExecutionState = hisAdvice.ExecutionState
  7336. advice.CheckTime = hisAdvice.CheckTime
  7337. advice.Checker = hisAdvice.Checker
  7338. advice.CheckState = hisAdvice.CheckState
  7339. advice.StartTime = hisAdvice.StartTime
  7340. advice.HospApprFlag = hisAdvice.HospApprFlag
  7341. advice.IsMedicine = hisAdvice.IsMedicine
  7342. if hisAdvice.UserOrgId == 10028 {
  7343. 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 {
  7344. advice.ExecutionTime = 0
  7345. advice.ExecutionStaff = 0
  7346. advice.ExecutionState = 2
  7347. advice.CheckTime = 0
  7348. advice.Checker = 0
  7349. advice.CheckState = 2
  7350. }
  7351. } else {
  7352. 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 {
  7353. advice.ExecutionTime = 0
  7354. advice.ExecutionStaff = 0
  7355. advice.ExecutionState = 2
  7356. advice.CheckTime = 0
  7357. advice.Checker = 0
  7358. advice.CheckState = 2
  7359. //advice.UpdatedTime = time.Now().Unix()
  7360. advice.CreatedTime = hisAdvice.CreatedTime
  7361. advice.UpdatedTime = time.Now().Unix()
  7362. } else {
  7363. advice.CreatedTime = hisAdvice.CreatedTime
  7364. advice.UpdatedTime = hisAdvice.UpdatedTime
  7365. }
  7366. }
  7367. //advice.Groupno = hisAdvice.Groupno
  7368. } else {
  7369. advice.IsMedicine = 0
  7370. ctime := time.Now().Unix()
  7371. advice.CreatedTime = ctime
  7372. advice.UpdatedTime = ctime
  7373. }
  7374. }
  7375. } else {
  7376. advice.IsMedicine = 0
  7377. ctime := time.Now().Unix()
  7378. advice.CreatedTime = ctime
  7379. advice.UpdatedTime = ctime
  7380. }
  7381. }
  7382. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7383. //
  7384. //if drugStockConfig.IsOpen == 1 {
  7385. //
  7386. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7387. // if advice.ID == 0 { //医嘱不存在
  7388. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7389. // drug.Total = drug.Total - advice.PrescribingNumber
  7390. // service.UpdateBaseDrugLib(&drug)
  7391. //
  7392. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7393. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7394. // drug.Total = drug.Total - num
  7395. // service.UpdateBaseDrugLib(&drug)
  7396. // }
  7397. //
  7398. // } else if advice.ID > 0 { //医嘱存在
  7399. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7400. // var num float64
  7401. //
  7402. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7403. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7404. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7405. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7406. // drug.Total = drug.Total + num
  7407. // service.UpdateBaseDrugLib(&drug)
  7408. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7409. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7410. // drug.Total = drug.Total - num
  7411. // service.UpdateBaseDrugLib(&drug)
  7412. // }
  7413. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7414. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7415. // if num2 > advice.PrescribingNumber {
  7416. // num = num2 - advice.PrescribingNumber
  7417. // drug.Total = drug.Total + num
  7418. // service.UpdateBaseDrugLib(&drug)
  7419. // } else if num2 < advice.PrescribingNumber {
  7420. // num = advice.PrescribingNumber - num2
  7421. // drug.Total = drug.Total - num
  7422. // service.UpdateBaseDrugLib(&drug)
  7423. // }
  7424. //
  7425. // }
  7426. //
  7427. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7428. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7429. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7430. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7431. // if num1 > num2 {
  7432. // num = num1 - num2
  7433. // drug.Total = drug.Total + num
  7434. // service.UpdateBaseDrugLib(&drug)
  7435. // } else if num1 < num2 {
  7436. // num = num2 - num1
  7437. // drug.Total = drug.Total - num
  7438. // service.UpdateBaseDrugLib(&drug)
  7439. // }
  7440. //
  7441. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7442. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7443. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7444. // if hisAdvice.PrescribingNumber > num2 {
  7445. // num = hisAdvice.PrescribingNumber - num2
  7446. // drug.Total = drug.Total + num
  7447. // service.UpdateBaseDrugLib(&drug)
  7448. // } else if num2 < advice.PrescribingNumber {
  7449. // num = num2 - hisAdvice.PrescribingNumber
  7450. // drug.Total = drug.Total - num
  7451. // service.UpdateBaseDrugLib(&drug)
  7452. // }
  7453. //
  7454. // }
  7455. // }
  7456. // }
  7457. //}
  7458. //
  7459. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7460. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7461. // advice.ExecutionTime = execution_time
  7462. //}
  7463. //
  7464. //
  7465. //
  7466. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7467. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7468. // advice.ExecutionStaff = execution_staff
  7469. //}
  7470. //
  7471. //
  7472. //
  7473. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7474. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7475. // advice.ExecutionState = execution_state
  7476. //}
  7477. //
  7478. //
  7479. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7480. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7481. // advice.CheckTime = check_time
  7482. //}
  7483. //
  7484. //
  7485. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7486. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7487. // advice.CheckState = check_state
  7488. //}
  7489. //
  7490. //
  7491. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7492. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7493. // advice.Checker = checker
  7494. //}
  7495. //
  7496. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7497. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7498. // advice.StartTime = start_time
  7499. //}
  7500. return 0
  7501. }
  7502. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7503. project.ExecutionStaff = 0
  7504. project.ExecutionState = 2
  7505. project.ExecutionTime = 0
  7506. project.Checker = 0
  7507. project.CheckState = 2
  7508. project.CheckTime = 0
  7509. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7510. id := int64(json["id"].(float64))
  7511. project.ID = id
  7512. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7513. project.ExecutionStaff = temp_project.ExecutionStaff
  7514. project.ExecutionState = temp_project.ExecutionState
  7515. project.ExecutionTime = temp_project.ExecutionTime
  7516. project.Checker = temp_project.Checker
  7517. project.CheckState = temp_project.CheckState
  7518. project.CheckTime = temp_project.CheckTime
  7519. project.TeamId = temp_project.TeamId
  7520. }
  7521. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7522. types := int64(json["type"].(float64))
  7523. project.Type = types
  7524. }
  7525. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7526. project_id := int64(json["project_id"].(float64))
  7527. project.ProjectId = project_id
  7528. }
  7529. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7530. team_id := int64(json["team_id"].(float64))
  7531. project.TeamId = team_id
  7532. }
  7533. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7534. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7535. project.Price = price
  7536. }
  7537. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7538. total, _ := json["total"].(string)
  7539. //totals, _ := strconv.ParseInt(total, 10, 64)
  7540. project.Count = total
  7541. }
  7542. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7543. medical_code, _ := json["medical_code"].(string)
  7544. project.MedListCodg = medical_code
  7545. }
  7546. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7547. single_dose, _ := json["single_dose"].(string)
  7548. project.SingleDose = single_dose
  7549. }
  7550. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7551. delivery_way, _ := json["delivery_way"].(string)
  7552. project.DeliveryWay = delivery_way
  7553. }
  7554. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7555. execution_frequency, _ := json["execution_frequency"].(string)
  7556. project.ExecutionFrequency = execution_frequency
  7557. }
  7558. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7559. remark, _ := json["remark"].(string)
  7560. project.Remark = remark
  7561. }
  7562. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7563. day, _ := json["number_days"].(string)
  7564. project.Day = day
  7565. }
  7566. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7567. unit, _ := json["unit"].(string)
  7568. project.Unit = unit
  7569. }
  7570. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7571. // frequency_type := int64(json["frequency_type"].(float64))
  7572. // project.FrequencyType = frequency_type
  7573. //}
  7574. //
  7575. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7576. // day_count := int64(json["day_count"].(float64))
  7577. // project.DayCount = day_count
  7578. //}
  7579. //
  7580. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7581. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7582. // week_day, _ := json["week_day"].(string)
  7583. // project.WeekDay = week_day
  7584. //}
  7585. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7586. //
  7587. //if project.ID == 0 {
  7588. // if stockConfig.IsOpen == 1 {
  7589. // if project.Type == 3 {
  7590. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7591. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7592. // good.Total = good.Total - f_count
  7593. // service.UpdateGoodInfo(&good)
  7594. // }
  7595. // }
  7596. //
  7597. //} else {
  7598. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7599. //
  7600. // if stockConfig.IsOpen == 1 {
  7601. // if project.Type == 3 {
  7602. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7603. // if project.Count < temp_project.Count {
  7604. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7605. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7606. //
  7607. // other_count := f_count_two - f_count_one
  7608. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7609. // good.Total = good.Total + other_count_two
  7610. // service.UpdateGoodInfo(&good)
  7611. // } else if project.Count > temp_project.Count {
  7612. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7613. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7614. //
  7615. // other_count := f_count_one - f_count_two
  7616. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7617. // good.Total = good.Total - other_count_two
  7618. // service.UpdateGoodInfo(&good)
  7619. // }
  7620. //
  7621. // }
  7622. // }
  7623. //
  7624. //}
  7625. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7626. id := int64(json["id"].(float64))
  7627. if id > 0 {
  7628. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7629. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7630. fmt.Println("666666")
  7631. project.Mtime = time.Now().Unix()
  7632. project.Ctime = temp_project.Ctime
  7633. } else {
  7634. project.Mtime = temp_project.Mtime
  7635. project.Ctime = temp_project.Ctime
  7636. }
  7637. } else {
  7638. ctime := time.Now().Unix()
  7639. project.Mtime = ctime
  7640. project.Ctime = ctime
  7641. }
  7642. }
  7643. return 0
  7644. }
  7645. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7646. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7647. id := int64(json["id"].(float64))
  7648. additionalCharge.ID = id
  7649. }
  7650. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7651. item_id := int64(json["item_id"].(float64))
  7652. additionalCharge.ItemId = item_id
  7653. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7654. if config.ID > 0 {
  7655. if len(config.Code) > 0 {
  7656. additionalCharge.MedListCodg = config.Code
  7657. }
  7658. }
  7659. }
  7660. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7661. // price := int64(json["price"].(float64))
  7662. // formatInt_price := strconv.FormatInt(price, 10)
  7663. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7664. // additionalCharge.Price = float_price
  7665. // }
  7666. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7667. // price := int64(json["price"].(float64))
  7668. // formatInt_price := strconv.FormatInt(price, 10)
  7669. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7670. // additionalCharge.Price = float_price
  7671. //}
  7672. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7673. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7674. additionalCharge.Price = price
  7675. }
  7676. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7677. count, _ := json["count"].(string)
  7678. counts, _ := strconv.ParseInt(count, 10, 64)
  7679. additionalCharge.Count = counts
  7680. }
  7681. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7682. item_name, _ := json["item_name"].(string)
  7683. additionalCharge.ItemName = item_name
  7684. }
  7685. return 0
  7686. }
  7687. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7688. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7689. utils.ErrorLog("drug_name")
  7690. return enums.ErrorCodeParamWrong
  7691. }
  7692. adviceName, _ := json["drug_name"].(string)
  7693. if len(adviceName) == 0 {
  7694. utils.ErrorLog("len(advice_name) == 0")
  7695. return enums.ErrorCodeParamWrong
  7696. }
  7697. advice.AdviceName = adviceName
  7698. adviceDesc, _ := json["advice_desc"].(string)
  7699. advice.AdviceDesc = adviceDesc
  7700. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7701. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7702. advice.DrugSpec = drugSpec
  7703. }
  7704. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7705. remark, _ := json["remark"].(string)
  7706. advice.Remark = remark
  7707. }
  7708. if json["id"] == nil {
  7709. advice.DrugId = 0
  7710. } else {
  7711. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7712. drug_id := int64(json["id"].(float64))
  7713. advice.DrugId = drug_id
  7714. }
  7715. }
  7716. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7717. groupno := int64(json["groupno"].(float64))
  7718. advice.Groupno = groupno
  7719. }
  7720. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7721. drugSpecUnit, _ := json["min_unit"].(string)
  7722. advice.DrugSpecUnit = drugSpecUnit
  7723. }
  7724. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7725. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7726. advice.SingleDose = singleDose
  7727. }
  7728. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7729. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7730. advice.SingleDoseUnit = singleDoseUnit
  7731. }
  7732. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7733. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7734. advice.PrescribingNumber = prescribingNumber
  7735. }
  7736. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7737. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7738. advice.PrescribingNumberUnit = prescribingNumberUnit
  7739. }
  7740. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7741. deliveryWay, _ := json["delivery_way"].(string)
  7742. advice.DeliveryWay = deliveryWay
  7743. }
  7744. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7745. executionFrequency, _ := json["execution_frequency"].(string)
  7746. advice.ExecutionFrequency = executionFrequency
  7747. }
  7748. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7749. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7750. advice.Price = price
  7751. }
  7752. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7753. med_list_codg, _ := json["medical_insurance_number"].(string)
  7754. advice.MedListCodg = med_list_codg
  7755. }
  7756. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7757. day := int64(json["day"].(float64))
  7758. advice.Day = day
  7759. }
  7760. advice.FrequencyType = 1
  7761. return 0
  7762. }
  7763. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7764. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7765. types := int64(json["type"].(float64))
  7766. project.Type = types
  7767. }
  7768. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7769. project_id := int64(json["project_id"].(float64))
  7770. project.ProjectId = project_id
  7771. }
  7772. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7773. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7774. project.Price = price
  7775. }
  7776. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7777. total, _ := json["total"].(string)
  7778. //totals, _ := strconv.ParseInt(total, 10, 64)
  7779. project.Count = total
  7780. }
  7781. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7782. medical_code, _ := json["medical_code"].(string)
  7783. project.MedListCodg = medical_code
  7784. }
  7785. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7786. single_dose, _ := json["single_dose"].(string)
  7787. project.SingleDose = single_dose
  7788. }
  7789. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7790. delivery_way, _ := json["delivery_way"].(string)
  7791. project.DeliveryWay = delivery_way
  7792. }
  7793. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7794. execution_frequency, _ := json["execution_frequency"].(string)
  7795. project.ExecutionFrequency = execution_frequency
  7796. }
  7797. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7798. remark, _ := json["remark"].(string)
  7799. project.Remark = remark
  7800. }
  7801. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7802. day, _ := json["number_days"].(string)
  7803. project.Day = day
  7804. }
  7805. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7806. unit, _ := json["unit"].(string)
  7807. project.Unit = unit
  7808. }
  7809. project.FrequencyType = 1
  7810. return 0
  7811. }
  7812. func (c *HisApiController) GetHisOrderListTwo() {
  7813. start_time := c.GetString("start_time")
  7814. end_time := c.GetString("end_time")
  7815. timeLayout := "2006-01-02"
  7816. loc, _ := time.LoadLocation("Local")
  7817. var startTime int64
  7818. if len(start_time) > 0 {
  7819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7820. if err != nil {
  7821. //fmt.Println(err)
  7822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7823. return
  7824. }
  7825. startTime = theTime.Unix()
  7826. }
  7827. var endTime int64
  7828. if len(end_time) > 0 {
  7829. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7830. if err != nil {
  7831. utils.ErrorLog(err.Error())
  7832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7833. return
  7834. }
  7835. endTime = theTime.Unix()
  7836. }
  7837. adminUser := c.GetAdminUserInfo()
  7838. org_id := adminUser.CurrentOrgId
  7839. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7840. if err == nil {
  7841. c.ServeSuccessJSON(map[string]interface{}{
  7842. "order2": order,
  7843. })
  7844. } else {
  7845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7846. return
  7847. }
  7848. }
  7849. func (c *HisApiController) GetHisOrderList() {
  7850. page, _ := c.GetInt64("page", -1)
  7851. limit, _ := c.GetInt64("limit", -1)
  7852. start_time := c.GetString("start_time")
  7853. end_time := c.GetString("end_time")
  7854. types, _ := c.GetInt64("type", 0)
  7855. keywords := c.GetString("keywords")
  7856. p_type, _ := c.GetInt64("p_type", 0)
  7857. sort_type, _ := c.GetInt64("sort_type", 0)
  7858. charge_type, _ := c.GetInt64("charge_type", 0)
  7859. sch_type, _ := c.GetInt64("sch_type", 0)
  7860. zone_type, _ := c.GetInt64("zone_type", 0)
  7861. med_type, _ := c.GetInt64("med_type", 0)
  7862. timeLayout := "2006-01-02"
  7863. loc, _ := time.LoadLocation("Local")
  7864. var startTime int64
  7865. if len(start_time) > 0 {
  7866. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7867. if err != nil {
  7868. //fmt.Println(err)
  7869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7870. return
  7871. }
  7872. startTime = theTime.Unix()
  7873. }
  7874. var endTime int64
  7875. if len(end_time) > 0 {
  7876. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7877. if err != nil {
  7878. utils.ErrorLog(err.Error())
  7879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7880. return
  7881. }
  7882. endTime = theTime.Unix()
  7883. }
  7884. adminUser := c.GetAdminUserInfo()
  7885. org_id := adminUser.CurrentOrgId
  7886. 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)
  7887. for _, item := range order {
  7888. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7889. item.DoctorName = info.Doctor
  7890. item.DepartmentName = info.XtHisDepartment.Name
  7891. }
  7892. if err == nil {
  7893. c.ServeSuccessJSON(map[string]interface{}{
  7894. "order": order,
  7895. "total": total,
  7896. })
  7897. } else {
  7898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7899. return
  7900. }
  7901. }
  7902. func (c *HisApiController) GetHisOrder() {
  7903. patient_id, _ := c.GetInt64("patient_id", 0)
  7904. number := c.GetString("number")
  7905. adminInfo := c.GetAdminUserInfo()
  7906. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7907. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7908. if err == nil {
  7909. c.ServeSuccessJSON(map[string]interface{}{
  7910. "order": order,
  7911. "prescription": prescriptions,
  7912. })
  7913. } else {
  7914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7915. return
  7916. }
  7917. }
  7918. func (c *HisApiController) GetHisPrescriptionList() {
  7919. record_date := c.GetString("record_date")
  7920. keywords := c.GetString("keywords")
  7921. page, _ := c.GetInt64("page")
  7922. limit, _ := c.GetInt64("limit")
  7923. sch_type, _ := c.GetInt64("sch_type")
  7924. timeLayout := "2006-01-02"
  7925. loc, _ := time.LoadLocation("Local")
  7926. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7927. if err != nil {
  7928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7929. return
  7930. }
  7931. recordDateTime := theTime.Unix()
  7932. adminInfo := c.GetAdminUserInfo()
  7933. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7934. //adminInfo := c.GetAdminUserInfo()
  7935. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7936. //fmt.Println(prescriptionOrder)
  7937. if err == nil {
  7938. c.ServeSuccessJSON(map[string]interface{}{
  7939. "order": prescriptionOrder,
  7940. "total": total,
  7941. })
  7942. } else {
  7943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7944. return
  7945. }
  7946. }
  7947. func (c *HisApiController) GetHisPrescriptionInfo() {
  7948. id, _ := c.GetInt64("id")
  7949. adminInfo := c.GetAdminUserInfo()
  7950. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7951. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7952. if err == nil {
  7953. c.ServeSuccessJSON(map[string]interface{}{
  7954. "order": prescriptionOrder,
  7955. "prescription": prescription,
  7956. })
  7957. } else {
  7958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7959. return
  7960. }
  7961. }
  7962. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7963. adminUser := c.GetAdminUserInfo()
  7964. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7965. c.ServeSuccessJSON(map[string]interface{}{
  7966. "config": config,
  7967. })
  7968. }
  7969. type ResultTwo struct {
  7970. ErrMsg interface{} `json:"err_msg"`
  7971. InfRefmsgid string `json:"inf_refmsgid"`
  7972. Infcode int64 `json:"infcode"`
  7973. Output struct {
  7974. Baseinfo struct {
  7975. Age float64 `json:"age"`
  7976. Brdy string `json:"brdy"`
  7977. Certno string `json:"certno"`
  7978. Gend string `json:"gend"`
  7979. Naty string `json:"naty"`
  7980. PsnCertType string `json:"psn_cert_type"`
  7981. PsnName string `json:"psn_name"`
  7982. PsnNo string `json:"psn_no"`
  7983. } `json:"baseinfo"`
  7984. Idetinfo []interface{} `json:"idetinfo"`
  7985. Iinfo []struct {
  7986. Balc float64 `json:"balc"`
  7987. CvlservFlag string `json:"cvlserv_flag"`
  7988. EmpName string `json:"emp_name"`
  7989. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7990. Insutype string `json:"insutype"`
  7991. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7992. PausInsuDate interface{} `json:"paus_insu_date"`
  7993. PsnInsuDate string `json:"psn_insu_date"`
  7994. PsnInsuStas string `json:"psn_insu_stas"`
  7995. PsnType string `json:"psn_type"`
  7996. } `json:"insuinfo"`
  7997. } `json:"output"`
  7998. RefmsgTime string `json:"refmsg_time"`
  7999. RespondTime string `json:"respond_time"`
  8000. Signtype interface{} `json:"signtype"`
  8001. WarnInfo interface{} `json:"warn_info"`
  8002. }
  8003. type ResultThree struct {
  8004. Cainfo interface{} `json:"cainfo"`
  8005. ErrMsg interface{} `json:"err_msg"`
  8006. InfRefmsgid string `json:"inf_refmsgid"`
  8007. Infcode int64 `json:"infcode"`
  8008. Output struct {
  8009. Data struct {
  8010. IptOtpNo string `json:"ipt_otp_no"`
  8011. MdtrtID string `json:"mdtrt_id"`
  8012. PsnNo string `json:"psn_no"`
  8013. } `json:"data"`
  8014. } `json:"output"`
  8015. RefmsgTime string `json:"refmsg_time"`
  8016. RespondTime string `json:"respond_time"`
  8017. Signtype interface{} `json:"signtype"`
  8018. WarnMsg interface{} `json:"warn_msg"`
  8019. }
  8020. type ResultFour struct {
  8021. Cainfo string `json:"cainfo"`
  8022. ErrMsg string `json:"err_msg"`
  8023. InfRefmsgid string `json:"inf_refmsgid"`
  8024. Infcode int64 `json:"infcode"`
  8025. Output struct {
  8026. Result []struct {
  8027. BasMednFlag string `json:"bas_medn_flag"`
  8028. ChldMedcFlag string `json:"chld_medc_flag"`
  8029. ChrgitmLv string `json:"chrgitm_lv"`
  8030. Cnt float64 `json:"cnt"`
  8031. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8032. DrtReimFlag string `json:"drt_reim_flag"`
  8033. FeedetlSn string `json:"feedetl_sn"`
  8034. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8035. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8036. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8037. ListSpItemFlag string `json:"list_sp_item_flag"`
  8038. LmtUsedFlag string `json:"lmt_used_flag"`
  8039. MedChrgitmType string `json:"med_chrgitm_type"`
  8040. Memo string `json:"memo"`
  8041. OverlmtAmt float64 `json:"overlmt_amt"`
  8042. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8043. Pric float64 `json:"pric"`
  8044. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8045. SelfpayProp float64 `json:"selfpay_prop"`
  8046. } `json:"result"`
  8047. } `json:"output"`
  8048. RefmsgTime string `json:"refmsg_time"`
  8049. RespondTime string `json:"respond_time"`
  8050. Signtype string `json:"signtype"`
  8051. WarnMsg string `json:"warn_msg"`
  8052. }
  8053. type ResultFive struct {
  8054. Insutype string `json:"insutype"`
  8055. }
  8056. type ResultSix struct {
  8057. Cainfo interface{} `json:"cainfo"`
  8058. ErrMsg interface{} `json:"err_msg"`
  8059. InfRefmsgid string `json:"inf_refmsgid"`
  8060. Infcode int64 `json:"infcode"`
  8061. Output struct {
  8062. } `json:"output"`
  8063. RefmsgTime string `json:"refmsg_time"`
  8064. RespondTime string `json:"respond_time"`
  8065. Signtype interface{} `json:"signtype"`
  8066. WarnMsg interface{} `json:"warn_msg"`
  8067. }
  8068. type ResultSeven struct {
  8069. Cainfo string `json:"cainfo"`
  8070. ErrMsg string `json:"err_msg"`
  8071. InfRefmsgid string `json:"inf_refmsgid"`
  8072. Infcode int64 `json:"infcode"`
  8073. Output struct {
  8074. Setldetail []interface{} `json:"setldetail"`
  8075. Setlinfo struct {
  8076. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8077. AcctPay float64 `json:"acct_pay"`
  8078. ActPayDedc float64 `json:"act_pay_dedc"`
  8079. Age float64 `json:"age"`
  8080. Balc float64 `json:"balc"`
  8081. Brdy string `json:"brdy"`
  8082. Certno string `json:"certno"`
  8083. ClrOptins string `json:"clr_optins"`
  8084. ClrType string `json:"clr_type"`
  8085. ClrWay string `json:"clr_way"`
  8086. CvlservFlag string `json:"cvlserv_flag"`
  8087. CvlservPay float64 `json:"cvlserv_pay"`
  8088. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8089. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8090. Gend string `json:"gend"`
  8091. HifesPay float64 `json:"hifes_pay"`
  8092. HifmiPay float64 `json:"hifmi_pay"`
  8093. HifobPay float64 `json:"hifob_pay"`
  8094. HifpPay float64 `json:"hifp_pay"`
  8095. HospPartAmt float64 `json:"hosp_part_amt"`
  8096. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8097. Insutype string `json:"insutype"`
  8098. MafPay float64 `json:"maf_pay"`
  8099. MdtrtCertType string `json:"mdtrt_cert_type"`
  8100. MdtrtID string `json:"mdtrt_id"`
  8101. MedType string `json:"med_type"`
  8102. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8103. MedinsSetlID string `json:"medins_setl_id"`
  8104. Naty string `json:"naty"`
  8105. OthPay float64 `json:"oth_pay"`
  8106. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8107. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8108. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8109. PsnCashPay float64 `json:"psn_cash_pay"`
  8110. PsnCertType string `json:"psn_cert_type"`
  8111. PsnName string `json:"psn_name"`
  8112. PsnNo string `json:"psn_no"`
  8113. PsnPartAmt float64 `json:"psn_part_amt"`
  8114. PsnType string `json:"psn_type"`
  8115. SetlID string `json:"setl_id"`
  8116. SetlTime string `json:"setl_time"`
  8117. } `json:"setlinfo"`
  8118. } `json:"output"`
  8119. RefmsgTime string `json:"refmsg_time"`
  8120. RespondTime string `json:"respond_time"`
  8121. Signtype interface{} `json:"signtype"`
  8122. WarnMsg interface{} `json:"warn_msg"`
  8123. }
  8124. type ResultEight struct {
  8125. Cainfo string `json:"cainfo"`
  8126. ErrMsg string `json:"err_msg"`
  8127. InfRefmsgid string `json:"inf_refmsgid"`
  8128. Infcode int64 `json:"infcode"`
  8129. Output struct {
  8130. Stmtinfo struct {
  8131. SetlOptins string `json:"setl_optins"`
  8132. StmtRslt string `json:"stmt_rslt"`
  8133. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8134. } `json:"stmtinfo"`
  8135. } `json:"output"`
  8136. RefmsgTime string `json:"refmsg_time"`
  8137. RespondTime string `json:"respond_time"`
  8138. Signtype interface{} `json:"signtype"`
  8139. WarnMsg interface{} `json:"warn_msg"`
  8140. }
  8141. type ResultNine struct {
  8142. Cainfo string `json:"cainfo"`
  8143. ErrMsg string `json:"err_msg"`
  8144. InfRefmsgid string `json:"inf_refmsgid"`
  8145. Infcode int64 `json:"infcode"`
  8146. Output struct {
  8147. FileQuryNo string `json:"file_qury_no"`
  8148. } `json:"output"`
  8149. RefmsgTime string `json:"refmsg_time"`
  8150. RespondTime string `json:"respond_time"`
  8151. Signtype interface{} `json:"signtype"`
  8152. WarnMsg interface{} `json:"warn_msg"`
  8153. }
  8154. type ResultTen struct {
  8155. Cainfo string `json:"cainfo"`
  8156. ErrMsg string `json:"err_msg"`
  8157. InfRefmsgid string `json:"inf_refmsgid"`
  8158. Infcode int64 `json:"infcode"`
  8159. Output struct {
  8160. DldEndtime string `json:"dld_endtime"`
  8161. FileQuryNo string `json:"file_qury_no"`
  8162. Filename string `json:"filename"`
  8163. } `json:"output"`
  8164. RefmsgTime string `json:"refmsg_time"`
  8165. RespondTime string `json:"respond_time"`
  8166. Signtype interface{} `json:"signtype"`
  8167. WarnMsg interface{} `json:"warn_msg"`
  8168. }
  8169. type ResultEleven struct {
  8170. Cainfo string `json:"cainfo"`
  8171. ErrMsg string `json:"err_msg"`
  8172. InfRefmsgid string `json:"inf_refmsgid"`
  8173. Infcode int64 `json:"infcode"`
  8174. Output struct {
  8175. Setlinfo struct {
  8176. FixmedinsName string `json:"fixmedins_name"`
  8177. FixmedinsCode string `json:"fixmedins_code"`
  8178. PsnNo string `json:"psn_no"`
  8179. PsnName string `json:"psn_name"`
  8180. HifobPay float64 `json:"hifob_pay"`
  8181. Gend string `json:"gend"`
  8182. Brdy string `json:"brdy"`
  8183. PsnCertType string `json:"psn_cert_type"`
  8184. PsnType string `json:"psn_type"`
  8185. EmpName string `json:"emp_name"`
  8186. Certno string `json:"certno"`
  8187. Insutype string `json:"insutype"`
  8188. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8189. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8190. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8191. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8192. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8193. ActPayDedc float64 `json:"act_pay_dedc"`
  8194. HifpPay float64 `json:"hifp_pay"`
  8195. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8196. CvlservPay float64 `json:"cvlserv_pay"`
  8197. HifesPay float64 `json:"hifes_pay"`
  8198. HifmiPay float64 `json:"hifmi_pay"`
  8199. MafPay float64 `json:"maf_pay"`
  8200. OthPay float64 `json:"oth_pay"`
  8201. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8202. PsnPay float64 `json:"psn_pay"`
  8203. AcctPay float64 `json:"acct_pay"`
  8204. CashPayamt float64 `json:"cash_payamt"`
  8205. Balc float64 `json:"balc"`
  8206. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8207. MedinsSetlId string `json:"medins_setl_id"`
  8208. RefdSetlFlag string `json:"refd_setl_flag"`
  8209. SetlTime string `json:"setl_time"`
  8210. MedType string `json:"med_type"`
  8211. } `json:"setlinfo"`
  8212. } `json:"output"`
  8213. RefmsgTime string `json:"refmsg_time"`
  8214. RespondTime string `json:"respond_time"`
  8215. Signtype interface{} `json:"signtype"`
  8216. WarnMsg interface{} `json:"warn_msg"`
  8217. }
  8218. type Custom struct {
  8219. DetItemFeeSumamt string
  8220. Cut string
  8221. FeedetlSn string
  8222. Price string
  8223. MedListCodg string
  8224. Type int64
  8225. AdviceId int64
  8226. ProjectId int64
  8227. ItemId int64
  8228. }
  8229. // 获取个人信息----挂号-----上传就诊信息
  8230. func (c *HisApiController) GetRegisterInfo() {
  8231. id, _ := c.GetInt64("id")
  8232. record_time := c.GetString("record_time")
  8233. settlementValue, _ := c.GetInt64("settlement_value")
  8234. medical_insurance_card := c.GetString("medical_insurance_card")
  8235. name := c.GetString("name")
  8236. id_card_type, _ := c.GetInt64("id_card_type")
  8237. certificates, _ := c.GetInt64("certificates")
  8238. medical_care, _ := c.GetInt64("medical_care")
  8239. birthday := c.GetString("birthday")
  8240. age, _ := c.GetInt64("age")
  8241. id_card := c.GetString("id_card")
  8242. register_type, _ := c.GetInt64("register")
  8243. doctor, _ := c.GetInt64("doctor")
  8244. department, _ := c.GetInt64("department")
  8245. gender, _ := c.GetInt64("sex")
  8246. phone := c.GetString("phone")
  8247. registration_fee, _ := c.GetFloat("registration_fee")
  8248. medical_expenses, _ := c.GetFloat("medical_expenses")
  8249. social_type, _ := c.GetInt64("social_type")
  8250. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8251. diagnosis_ids := c.GetString("diagnosis")
  8252. sick_type, _ := c.GetInt64("sick_type")
  8253. reg_type := c.GetString("p_type")
  8254. timeLayout := "2006-01-02"
  8255. loc, _ := time.LoadLocation("Local")
  8256. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8257. birthUnix := birthdays.Unix()
  8258. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8259. if err != nil {
  8260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8261. return
  8262. }
  8263. recordDateTime := theTime.Unix()
  8264. adminInfo := c.GetAdminUserInfo()
  8265. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8266. if tempPatient.ID == 0 {
  8267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8268. return
  8269. }
  8270. var patient service.Patients
  8271. if id == 0 {
  8272. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8273. } else {
  8274. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8275. }
  8276. if patient.ID == 0 {
  8277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8278. return
  8279. }
  8280. if len(patient.IdCardNo) == 0 {
  8281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8282. return
  8283. }
  8284. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8285. if len(his) >= 1 {
  8286. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8287. if len(his) >= 1 && order.ID == 0 {
  8288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8289. return
  8290. }
  8291. }
  8292. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8293. fmt.Println(timeStr)
  8294. timeArr := strings.Split(timeStr, " ")
  8295. fmt.Println(timeArr)
  8296. timeArrTwo := strings.Split(timeArr[0], "-")
  8297. timeArrThree := strings.Split(timeArr[1], ":")
  8298. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8299. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8300. if len(lists) == 0 {
  8301. var hisPatient models.XtHisPatient
  8302. hisPatient = models.XtHisPatient{
  8303. Name: name,
  8304. Age: age,
  8305. Gender: gender,
  8306. Birthday: birthUnix,
  8307. Phone: phone,
  8308. MedicalTreatmentType: medical_care,
  8309. IdType: certificates,
  8310. IdCardNo: id_card,
  8311. BalanceAccountsType: settlementValue,
  8312. SocialType: social_type,
  8313. MedicalInsuranceNumber: medical_insurance_card,
  8314. RegisterType: register_type,
  8315. RegisterCost: registration_fee,
  8316. TreatmentCost: medical_expenses,
  8317. AdminUserId: adminInfo.AdminUser.Id,
  8318. UserOrgId: adminInfo.CurrentOrgId,
  8319. Status: 1,
  8320. RecordDate: recordDateTime,
  8321. IsReturn: 1,
  8322. PatientId: patient.ID,
  8323. Ctime: time.Now().Unix(),
  8324. Mtime: time.Now().Unix(),
  8325. Number: str,
  8326. IdCardType: id_card_type,
  8327. Departments: department,
  8328. Doctor: doctor,
  8329. PType: reg_type,
  8330. Diagnosis: diagnosis_ids,
  8331. SickType: sick_type,
  8332. }
  8333. service.CreateHisPatient(&hisPatient)
  8334. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8335. c.ServeSuccessJSON(map[string]interface{}{
  8336. "his_info": hisPatient,
  8337. })
  8338. } else {
  8339. //chrgBchno := rand.Intn(1000000) + 10000
  8340. var hisPatient models.XtHisPatient
  8341. hisPatient = models.XtHisPatient{
  8342. Name: name,
  8343. Age: age,
  8344. Gender: gender,
  8345. Birthday: birthUnix,
  8346. Phone: phone,
  8347. MedicalTreatmentType: medical_care,
  8348. IdType: certificates,
  8349. IdCardNo: id_card,
  8350. BalanceAccountsType: settlementValue,
  8351. SocialType: social_type,
  8352. MedicalInsuranceNumber: medical_insurance_card,
  8353. RegisterType: register_type,
  8354. RegisterCost: registration_fee,
  8355. TreatmentCost: medical_expenses,
  8356. AdminUserId: adminInfo.AdminUser.Id,
  8357. UserOrgId: adminInfo.CurrentOrgId,
  8358. Status: 1,
  8359. RecordDate: recordDateTime,
  8360. IsReturn: 1,
  8361. PatientId: patient.ID,
  8362. Ctime: time.Now().Unix(),
  8363. Mtime: time.Now().Unix(),
  8364. Number: str,
  8365. IdCardType: id_card_type,
  8366. Departments: department,
  8367. Doctor: doctor,
  8368. PType: reg_type,
  8369. Diagnosis: diagnosis_ids,
  8370. SickType: sick_type,
  8371. }
  8372. service.CreateHisPatient(&hisPatient)
  8373. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8374. c.ServeSuccessJSON(map[string]interface{}{
  8375. "his_info": hisPatient,
  8376. })
  8377. }
  8378. }
  8379. // 上传明细----结算
  8380. func (c *HisApiController) GetUploadInfo() {
  8381. id, _ := c.GetInt64("id")
  8382. record_time := c.GetString("record_time")
  8383. his_patient_id, _ := c.GetInt64("his_patient_id")
  8384. oth_desc := c.GetString("oth_desc")
  8385. pay_way, _ := c.GetInt64("pay_way")
  8386. pay_ways := c.GetString("pay_ways")
  8387. pay_price, _ := c.GetFloat("pay_price")
  8388. pay_card_no := c.GetString("pay_card_no")
  8389. discount_price, _ := c.GetFloat("discount_price")
  8390. preferential_price, _ := c.GetFloat("preferential_price")
  8391. reality_price, _ := c.GetFloat("reality_price")
  8392. found_price, _ := c.GetFloat("found_price")
  8393. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8394. private_price, _ := c.GetFloat("private_price")
  8395. timeLayout := "2006-01-02"
  8396. loc, _ := time.LoadLocation("Local")
  8397. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8398. fapiao_code := c.GetString("fapiao_code")
  8399. fapiao_number := c.GetString("fapiao_number")
  8400. diagnosis_id := c.GetString("diagnosis")
  8401. sick_type, _ := c.GetInt64("sick_type")
  8402. reg_type, _ := c.GetInt64("p_type")
  8403. order_id, _ := c.GetInt64("order_id")
  8404. cash_pay := c.GetString("cash_pay")
  8405. wechat_pay := c.GetString("wechat_pay")
  8406. ali_pay := c.GetString("ali_pay")
  8407. jifen_pay := c.GetString("jifen_pay")
  8408. band_card_pay := c.GetString("band_card_pay")
  8409. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8410. tmp_decimal := c.GetString("tmp_decimal")
  8411. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8412. var decimal float64 //本次使用的押金
  8413. var errmsg error
  8414. tx := service.XTWriteDB().Begin() //开了事务
  8415. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8416. defer func() {
  8417. if errmsg != nil {
  8418. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8419. tx.Rollback()
  8420. } else {
  8421. tx.Commit()
  8422. }
  8423. }()
  8424. fmt.Println("dec_way", dec_way)
  8425. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8426. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8427. return
  8428. }
  8429. if len(tmp_decimal) > 0 {
  8430. if tmp_decimal[0] == 45 {
  8431. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8432. return
  8433. }
  8434. }
  8435. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8436. fmt.Println(errs)
  8437. decimal = tt
  8438. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8439. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8440. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8441. if err != nil {
  8442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8443. return
  8444. }
  8445. recordDateTime := theTime.Unix()
  8446. adminUser := c.GetAdminUserInfo()
  8447. var prescriptions []*models.HisPrescription
  8448. var prescriptionsOne []*models.HisPrescription
  8449. var start_time int64
  8450. var end_time int64
  8451. ids_str := c.GetString("ids")
  8452. ids_arr := strings.Split(ids_str, ",")
  8453. if tempOrder.ID == 0 {
  8454. if settle_accounts_type == 1 { //日结
  8455. fmt.Println(reg_type)
  8456. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8457. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8458. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8459. } else {
  8460. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8461. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8462. }
  8463. } else { //月结
  8464. start_time_str := c.GetString("start_time")
  8465. end_time_str := c.GetString("end_time")
  8466. timeLayout := "2006-01-02"
  8467. loc, _ := time.LoadLocation("Local")
  8468. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8469. if err != nil {
  8470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8471. return
  8472. }
  8473. recordStartTime := theStartTime.Unix()
  8474. start_time = recordStartTime
  8475. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8476. if err != nil {
  8477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8478. return
  8479. }
  8480. recordEndTime := theEndTime.Unix()
  8481. end_time = recordEndTime
  8482. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8483. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8484. }
  8485. var goods []*models.DialysisBeforePrepareGoods
  8486. var newGoods []*models.NewDialysisBeforePrepareGoods
  8487. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8488. var infos []*models.HisDoctorAdviceInfo
  8489. var infoList []*models.HisDoctorAdviceInfo
  8490. var hisAdvice []*models.HisDoctorAdviceInfo
  8491. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8492. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8493. //判断库存不足
  8494. //结算出库开关
  8495. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8496. if settConfig.IsOpen == 1 {
  8497. //判断库存的地方
  8498. for _, info := range prescriptions {
  8499. if info.Type == 1 {
  8500. infos = append(infos, info.HisDoctorAdviceInfo...)
  8501. }
  8502. if info.Type == 2 {
  8503. for _, sumItem := range info.HisPrescriptionProject {
  8504. if sumItem.Type == 3 {
  8505. var good models.DialysisBeforePrepareGoods
  8506. var newGood models.NewDialysisBeforePrepareGoods
  8507. good.GoodId = sumItem.GoodInfo.ID
  8508. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8509. count, _ := strconv.Atoi(sumItem.Count)
  8510. good.Count = int64(count)
  8511. good.StorehouseId = houseConfig.StorehouseOutInfo
  8512. good.ProjectId = sumItem.ID
  8513. goods = append(goods, &good)
  8514. newGood.GoodId = sumItem.GoodInfo.ID
  8515. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8516. count2, _ := strconv.Atoi(sumItem.Count)
  8517. newGood.Count = int64(count2)
  8518. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8519. newGood.ProjectId = sumItem.ID
  8520. newGoods = append(newGoods, &newGood)
  8521. }
  8522. }
  8523. }
  8524. }
  8525. for _, info := range prescriptionsOne {
  8526. if info.Type == 1 {
  8527. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8528. }
  8529. if info.Type == 2 {
  8530. for _, sumItem := range info.HisPrescriptionProject {
  8531. if sumItem.Type == 3 {
  8532. var newGood models.NewDialysisBeforePrepareGoods
  8533. newGood.GoodId = sumItem.GoodInfo.ID
  8534. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8535. count2, _ := strconv.Atoi(sumItem.Count)
  8536. newGood.Count = int64(count2)
  8537. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8538. newGood.ProjectId = sumItem.ID
  8539. newGoodOne = append(newGoodOne, &newGood)
  8540. }
  8541. }
  8542. }
  8543. }
  8544. //判断
  8545. for _, itemOne := range infos {
  8546. for _, itemTwo := range hisAdvice {
  8547. if itemOne.DrugId == itemTwo.DrugId {
  8548. itemTwo.Child = append(itemTwo.Child, itemOne)
  8549. }
  8550. }
  8551. }
  8552. for _, itemTwo := range hisAdvice {
  8553. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8554. var sum_out_count int64
  8555. for _, itemThree := range itemTwo.Child {
  8556. var prescribing_number int64
  8557. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8558. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8559. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8560. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8561. }
  8562. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8563. prescribing_number = parseIntPrescribingNumber
  8564. }
  8565. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8566. prescribing_number = parseIntPrescribingNumber
  8567. }
  8568. sum_out_count += prescribing_number
  8569. }
  8570. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8571. if sum_out_count > drugStockOut.FlushCount {
  8572. c.ServeSuccessJSON(map[string]interface{}{
  8573. "msg": "2",
  8574. "drug": medical,
  8575. })
  8576. return
  8577. }
  8578. }
  8579. for _, itemOne := range newGoods {
  8580. for _, item := range newGoodOne {
  8581. if itemOne.GoodId == item.GoodId {
  8582. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8583. }
  8584. }
  8585. }
  8586. for _, item := range newGoodOne {
  8587. var sum_out_count_one int64
  8588. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8589. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8590. sum_out_count_one += itemOne.Count
  8591. }
  8592. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8593. fmt.Println("sum_out_count_one", sum_out_count_one)
  8594. fmt.Println("list.FlushCount", list.FlushCount)
  8595. if sum_out_count_one > list.FlushCount {
  8596. c.ServeSuccessJSON(map[string]interface{}{
  8597. "msg": "3",
  8598. "good": good,
  8599. })
  8600. return
  8601. }
  8602. }
  8603. }
  8604. timestamp := time.Now().Unix()
  8605. tempTime := time.Unix(timestamp, 0)
  8606. timeFormat := tempTime.Format("20060102150405")
  8607. chrgBchno := rand.Intn(100000) + 10000
  8608. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8609. strconv.FormatInt(his.PatientId, 10)
  8610. var ids []int64
  8611. for _, item := range prescriptions {
  8612. ids = append(ids, item.ID)
  8613. }
  8614. var total float64
  8615. for _, item := range prescriptions {
  8616. fmt.Println(item)
  8617. if item.Type == 1 { //药品
  8618. for _, subItem := range item.HisDoctorAdviceInfo {
  8619. total = total + (subItem.Price * subItem.PrescribingNumber)
  8620. }
  8621. }
  8622. if item.Type == 2 { //项目
  8623. for _, subItem := range item.HisPrescriptionProject {
  8624. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8625. total = total + (subItem.Price * cnt)
  8626. }
  8627. }
  8628. for _, subItem := range item.HisAdditionalCharge {
  8629. total = total + (subItem.Price * float64(subItem.Count))
  8630. }
  8631. }
  8632. if reg_type == 1111 || reg_type == 1112 {
  8633. reg_type = 11
  8634. }
  8635. tm := time.Unix(time.Now().Unix(), 0)
  8636. allTotal := fmt.Sprintf("%.4f", total)
  8637. totals, _ := strconv.ParseFloat(allTotal, 64)
  8638. order := &models.HisOrder{
  8639. UserOrgId: adminUser.CurrentOrgId,
  8640. HisPatientId: his.ID,
  8641. PatientId: id,
  8642. SettleAccountsDate: recordDateTime,
  8643. Ctime: time.Now().Unix(),
  8644. Mtime: time.Now().Unix(),
  8645. Status: 1,
  8646. OrderStatus: 2,
  8647. MdtrtId: his.Number,
  8648. Number: chrg_bchno,
  8649. MedfeeSumamt: totals,
  8650. PayWay: pay_way,
  8651. PayWays: pay_ways,
  8652. PayPrice: pay_price,
  8653. MedType: strconv.Itoa(int(reg_type)),
  8654. PayCardNo: pay_card_no,
  8655. DiscountPrice: discount_price,
  8656. PreferentialPrice: preferential_price,
  8657. RealityPrice: reality_price,
  8658. FoundPrice: found_price,
  8659. MedicalInsurancePrice: medical_insurance_price,
  8660. PrivatePrice: private_price,
  8661. SettleEndTime: end_time,
  8662. SettleStartTime: start_time,
  8663. PsnPartAmt: totals,
  8664. PsnCashPay: totals,
  8665. SettleType: settle_accounts_type,
  8666. FaPiaoCode: fapiao_code,
  8667. FaPiaoNumber: fapiao_number,
  8668. Diagnosis: diagnosis_id,
  8669. PType: 2,
  8670. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8671. Decimal: decimal,
  8672. OthDesc: oth_desc,
  8673. CashPay: cash_pay,
  8674. WechatPay: wechat_pay,
  8675. AliPay: ali_pay,
  8676. JifenPay: jifen_pay,
  8677. BandCardPay: band_card_pay,
  8678. Creator: adminUser.AdminUser.Id,
  8679. }
  8680. err = service.CreateOrderTX(order, tx)
  8681. if err != nil {
  8682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8683. return
  8684. }
  8685. var customs []*Custom
  8686. for _, item := range prescriptions {
  8687. if item.Type == 1 { //药品a
  8688. for _, subItem := range item.HisDoctorAdviceInfo {
  8689. cus := &Custom{
  8690. AdviceId: subItem.ID,
  8691. ProjectId: 0,
  8692. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8693. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8694. FeedetlSn: subItem.FeedetlSn,
  8695. Price: fmt.Sprintf("%.4f", subItem.Price),
  8696. MedListCodg: subItem.MedListCodg,
  8697. Type: 1,
  8698. }
  8699. customs = append(customs, cus)
  8700. }
  8701. }
  8702. if item.Type == 2 { //项目
  8703. for _, subItem := range item.HisPrescriptionProject {
  8704. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8705. cus := &Custom{
  8706. AdviceId: 0,
  8707. ProjectId: subItem.ID,
  8708. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8709. Cut: fmt.Sprintf("%.4f", cnt),
  8710. FeedetlSn: subItem.FeedetlSn,
  8711. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8712. MedListCodg: subItem.MedListCodg,
  8713. Type: 2,
  8714. }
  8715. customs = append(customs, cus)
  8716. }
  8717. }
  8718. for _, item := range item.HisAdditionalCharge {
  8719. cus := &Custom{
  8720. ItemId: item.ID,
  8721. AdviceId: 0,
  8722. ProjectId: 0,
  8723. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8724. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8725. FeedetlSn: item.FeedetlSn,
  8726. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8727. MedListCodg: item.XtHisAddtionConfig.Code,
  8728. Type: 3,
  8729. }
  8730. customs = append(customs, cus)
  8731. }
  8732. }
  8733. for _, item := range customs {
  8734. var advice_id int64 = 0
  8735. var project_id int64 = 0
  8736. var item_id int64 = 0
  8737. var types int64 = 0
  8738. if item.Type == 1 {
  8739. advice_id = item.AdviceId
  8740. project_id = 0
  8741. item_id = 0
  8742. } else if item.Type == 2 {
  8743. advice_id = 0
  8744. item_id = 0
  8745. project_id = item.ProjectId
  8746. } else if item.Type == 3 {
  8747. advice_id = 0
  8748. item_id = item.ItemId
  8749. project_id = 0
  8750. }
  8751. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8752. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8753. pric, _ := strconv.ParseFloat(item.Price, 32)
  8754. info := &models.HisOrderInfo{
  8755. OrderNumber: order.Number,
  8756. UploadDate: time.Now().Unix(),
  8757. AdviceId: advice_id,
  8758. DetItemFeeSumamt: detItemFeeSumamt,
  8759. Cnt: cut,
  8760. Pric: pric,
  8761. PatientId: id,
  8762. Status: 1,
  8763. Mtime: time.Now().Unix(),
  8764. Ctime: time.Now().Unix(),
  8765. UserOrgId: adminUser.CurrentOrgId,
  8766. HisPatientId: his.ID,
  8767. OrderId: order.ID,
  8768. ProjectId: project_id,
  8769. Type: types,
  8770. ItemId: item_id,
  8771. }
  8772. service.CreateOrderInfoTX(info, tx)
  8773. }
  8774. his.Diagnosis = diagnosis_id
  8775. his.SickType = sick_type
  8776. his.RegisterType = reg_type
  8777. his.MedicalTreatmentType = reg_type
  8778. service.UpdataHisPateintTX(&his, tx)
  8779. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8780. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8781. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8782. //判断是否使用了押金
  8783. if dec_way == "true" {
  8784. tmpstring := strconv.FormatInt(order.ID, 10)
  8785. //扣押金
  8786. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8787. order.Decimal = decimal
  8788. service.UpDateOrderTwo(order, tx)
  8789. if errmsg != nil {
  8790. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8791. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8792. return
  8793. }
  8794. }
  8795. if err == nil {
  8796. for _, info := range prescriptions {
  8797. if info.Type == 1 {
  8798. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8799. }
  8800. if info.Type == 2 {
  8801. for _, sumItem := range info.HisPrescriptionProject {
  8802. if sumItem.Type == 3 {
  8803. var good models.DialysisBeforePrepareGoods
  8804. var newGood models.NewDialysisBeforePrepareGoods
  8805. var oldGood models.OldDialysisBeforePrepareGoods
  8806. good.GoodId = sumItem.GoodInfo.ID
  8807. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8808. count, _ := strconv.Atoi(sumItem.Count)
  8809. good.Count = int64(count)
  8810. good.StorehouseId = houseConfig.StorehouseOutInfo
  8811. good.ProjectId = sumItem.ID
  8812. good.PatientId = sumItem.PatientId
  8813. goods = append(goods, &good)
  8814. newGood.GoodId = sumItem.GoodInfo.ID
  8815. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8816. count2, _ := strconv.Atoi(sumItem.Count)
  8817. newGood.Count = int64(count2)
  8818. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8819. newGood.ProjectId = sumItem.ID
  8820. newGood.PatientId = sumItem.HisPatientId
  8821. newGoods = append(newGoods, &newGood)
  8822. oldGood.GoodId = sumItem.GoodInfo.ID
  8823. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8824. count3, _ := strconv.Atoi(sumItem.Count)
  8825. oldGood.Count = int64(count3)
  8826. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8827. oldGood.ProjectId = sumItem.ID
  8828. oldGood.RecordDate = sumItem.RecordDate
  8829. oldGood.PatientId = sumItem.HisPatientId
  8830. oldGoods = append(oldGoods, &oldGood)
  8831. }
  8832. }
  8833. }
  8834. }
  8835. if settConfig.IsOpen == 1 {
  8836. for _, item := range infoList {
  8837. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8838. if medical.IsUse == 2 {
  8839. //药品出库
  8840. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8841. //查询默认仓库
  8842. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8843. //查询默认仓库剩余多少库存
  8844. var sum_count int64
  8845. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8846. for _, its := range stockInfo {
  8847. if its.MaxUnit == medical.MaxUnit {
  8848. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8849. }
  8850. sum_count += its.StockMaxNumber + its.StockMinNumber
  8851. }
  8852. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8853. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8854. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8855. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8856. }
  8857. }
  8858. orgId := c.GetAdminUserInfo().CurrentOrgId
  8859. if len(oldGoods) > 0 {
  8860. timeStr := time.Now().Format("2006-01-02")
  8861. timeArr := strings.Split(timeStr, "-")
  8862. total, _ := service.FindAllWarehouseOut(orgId)
  8863. total = total + 1
  8864. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8865. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8866. number = number + total
  8867. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8868. operation_time := time.Now().Unix()
  8869. creater := c.GetAdminUserInfo().AdminUser.Id
  8870. //查询默认出库仓库库存
  8871. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8872. recordDateStr := time.Now().Format("2006-01-02")
  8873. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8874. nowtime := recordDate.Unix()
  8875. warehouseOut := models.WarehouseOut{
  8876. WarehouseOutOrderNumber: warehousing_out_order,
  8877. OperationTime: operation_time,
  8878. OrgId: orgId,
  8879. Creater: creater,
  8880. Ctime: time.Now().Unix(),
  8881. Status: 1,
  8882. WarehouseOutTime: nowtime,
  8883. Type: 1,
  8884. StorehouseId: storeConfig.StorehouseOutInfo,
  8885. IsCheck: 1,
  8886. OrderId: order.ID,
  8887. IsSys: 5,
  8888. }
  8889. //查询是否生成出库单
  8890. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8891. if out.ID == 0 {
  8892. service.AddSigleWarehouseOut(&warehouseOut)
  8893. }
  8894. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8895. for _, item := range oldGoods {
  8896. dialyPrepareOne := models.DialysisBeforePrepare{
  8897. GoodTypeId: item.GoodTypeId,
  8898. GoodId: item.GoodId,
  8899. PatientId: his.PatientId,
  8900. RecordDate: item.RecordDate,
  8901. UserOrgId: adminUser.CurrentOrgId,
  8902. Count: item.Count,
  8903. Ctime: time.Now().Unix(),
  8904. Creater: adminUser.AdminUser.Id,
  8905. CommdityCode: item.CommdityCode,
  8906. Status: 1,
  8907. StorehouseId: houseConfig.StorehouseOutInfo,
  8908. }
  8909. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8910. //非零用
  8911. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8912. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8913. //查询剩余库存
  8914. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8915. var sum_count int64
  8916. for _, item := range goodList {
  8917. sum_count += item.StockCount
  8918. }
  8919. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8920. //耗材
  8921. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8922. }
  8923. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8924. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8925. //查询剩余库存
  8926. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8927. var sum_count int64
  8928. for _, item := range goodList {
  8929. sum_count += item.StockCount
  8930. }
  8931. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8932. //耗材
  8933. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8934. }
  8935. }
  8936. }
  8937. }
  8938. c.ServeSuccessJSON(map[string]interface{}{
  8939. "msg": "结算成功",
  8940. })
  8941. }
  8942. }
  8943. }
  8944. // 退款
  8945. func (c *HisApiController) Refund() {
  8946. order_id, _ := c.GetInt64("order_id")
  8947. order, _ := service.GetHisOrderByID(order_id)
  8948. adminUser := c.GetAdminUserInfo()
  8949. orgid := c.GetAdminUserInfo().CurrentOrgId
  8950. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8951. if err != nil {
  8952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8953. return
  8954. }
  8955. tmp := strconv.FormatInt(order.ID, 10)
  8956. //当押金不为零时产生退费记录
  8957. if order.Decimal != 0 {
  8958. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8959. if err != nil {
  8960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8961. return
  8962. }
  8963. }
  8964. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8965. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8966. var goods []*models.DialysisBeforePrepareGoods
  8967. var newGoods []*models.NewDialysisBeforePrepareGoods
  8968. var infos []*models.HisDoctorAdviceInfo
  8969. for _, info := range orders {
  8970. if info.AdviceId > 0 && info.ProjectId == 0 {
  8971. infos = append(infos, &info.HisDoctorAdviceInfo)
  8972. }
  8973. if info.ProjectId > 0 && info.AdviceId == 0 {
  8974. if info.HisPrescriptionProject.Type == 3 {
  8975. var good models.DialysisBeforePrepareGoods
  8976. var newGood models.NewDialysisBeforePrepareGoods
  8977. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8978. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8979. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8980. good.Count = int64(count)
  8981. good.StorehouseId = houseConfig.StorehouseOutInfo
  8982. good.ProjectId = info.HisPrescriptionProject.ID
  8983. good.PatientId = info.PatientId
  8984. good.OrderId = order_id
  8985. goods = append(goods, &good)
  8986. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8987. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8988. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8989. newGood.Count = int64(count2)
  8990. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8991. newGood.ProjectId = info.HisPrescriptionProject.ID
  8992. newGood.RecordDate = order.SettleAccountsDate
  8993. newGood.UserOrgId = order.UserOrgId
  8994. newGood.PatientId = info.PatientId
  8995. newGood.OrderId = order_id
  8996. newGoods = append(newGoods, &newGood)
  8997. }
  8998. }
  8999. }
  9000. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9001. if settConfig.IsOpen == 1 {
  9002. for _, item := range infos {
  9003. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9004. }
  9005. for _, item := range newGoods {
  9006. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9007. }
  9008. }
  9009. c.ServeSuccessJSON(map[string]interface{}{
  9010. "msg": "退费成功",
  9011. })
  9012. }
  9013. func (c *HisApiController) RefundNumber() {
  9014. his_patient_id, _ := c.GetInt64("id")
  9015. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9016. info.Status = 0
  9017. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9018. if count > 0 {
  9019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9020. return
  9021. }
  9022. err := service.SaveHisPatient(info)
  9023. if err == nil {
  9024. c.ServeSuccessJSON(map[string]interface{}{
  9025. "msg": "退号成功",
  9026. })
  9027. } else {
  9028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9029. return
  9030. }
  9031. }
  9032. func (this *HisApiController) AdditionalCharge() {
  9033. dataBody := make(map[string]interface{}, 0)
  9034. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9035. fmt.Println(err)
  9036. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9037. patient_id := int64(dataBody["patient_id"].(float64))
  9038. medicineData, _ := dataBody["medicineData"].([]interface{})
  9039. adminUserInfo := this.GetAdminUserInfo()
  9040. orgId := adminUserInfo.CurrentOrgId
  9041. admin_user_id := adminUserInfo.AdminUser.Id
  9042. timeStr := time.Now().Format("2006-01-02")
  9043. timeLayout := "2006-01-02 15:04:05"
  9044. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9045. timenow := timeStringToTime.Unix()
  9046. var additionalCharges []*models.HisAdditionalCharge
  9047. for _, item := range medicineData {
  9048. var randNum int
  9049. randNum = rand.Intn(10000) + 1000
  9050. timestamp := time.Now().Unix()
  9051. tempTime := time.Unix(timestamp, 0)
  9052. timeFormat := tempTime.Format("20060102150405")
  9053. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9054. items := item.(map[string]interface{})
  9055. money := items["price"].(string)
  9056. item_id_str := items["item_id"].(string)
  9057. name := items["name"].(string)
  9058. id_str := items["id"].(string)
  9059. moneys, _ := strconv.ParseInt(money, 10, 64)
  9060. monStr := strconv.FormatInt(moneys, 10)
  9061. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9062. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9063. id, _ := strconv.ParseInt(id_str, 10, 64)
  9064. additionalCharge := &models.HisAdditionalCharge{
  9065. ID: id,
  9066. HisPatientId: his_patient_id,
  9067. UserOrgId: orgId,
  9068. PatientId: patient_id,
  9069. RecordDate: timenow,
  9070. Price: monneyStr,
  9071. Status: 1,
  9072. ItemName: name,
  9073. ItemId: item_id,
  9074. AdminUserId: admin_user_id,
  9075. CreatedTime: time.Now().Unix(),
  9076. OrderStatus: 0,
  9077. PrescriptionNumber: "",
  9078. BatchNumber: "",
  9079. FeedetlSn: p_number,
  9080. }
  9081. service.CreateAdditionalCharge(additionalCharge)
  9082. additionalCharges = append(additionalCharges, additionalCharge)
  9083. }
  9084. this.ServeSuccessJSON(map[string]interface{}{
  9085. "msg": "添加成功",
  9086. "additional_charges": additionalCharges,
  9087. })
  9088. }
  9089. func (this *HisApiController) DeleteAddition() {
  9090. id, _ := this.GetInt64("id")
  9091. //TODO 需要判断是否已经结算
  9092. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9093. if err == nil {
  9094. this.ServeSuccessJSON(map[string]interface{}{
  9095. "msg": "删除成功",
  9096. })
  9097. return
  9098. } else {
  9099. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9100. return
  9101. }
  9102. }
  9103. func (this *HisApiController) GetAdminUsers() {
  9104. adminUser := this.GetAdminUserInfo()
  9105. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9106. this.ServeSuccessJSON(map[string]interface{}{
  9107. "doctors": doctors,
  9108. })
  9109. }
  9110. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9111. change_type, _ := this.GetInt64("type", 0)
  9112. record_date := this.GetString("record_time")
  9113. patient_id, _ := this.GetInt64("patient_id", 0)
  9114. p_type, _ := this.GetInt64("p_type", 0)
  9115. timeLayout := "2006-01-02"
  9116. loc, _ := time.LoadLocation("Local")
  9117. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9118. record_time := theAdviceRecordTime.Unix()
  9119. adminUserInfo := this.GetAdminUserInfo()
  9120. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9121. if adminUserInfo.CurrentOrgId == 10265 {
  9122. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9123. if config.ID > 0 && config.IsOpen == 1 {
  9124. for _, subitems := range prescriptions {
  9125. for _, item := range subitems.VMHisPrescription {
  9126. for _, subItem := range item.HisDoctorAdviceInfo {
  9127. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9128. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9129. if info.RetailPrice > 0 {
  9130. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9131. subItem.Drug.RetailPrice = drug.RetailPrice
  9132. }
  9133. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9134. subItem.Drug.MinPrice = info.RetailPrice
  9135. subItem.Drug.RetailPrice = info.RetailPrice
  9136. }
  9137. }
  9138. }
  9139. }
  9140. }
  9141. }
  9142. if config.ID > 0 && config.IsOpen == 1 {
  9143. for _, subitems := range prescriptions {
  9144. for _, item := range subitems.VMHisPrescription {
  9145. for _, subItem := range item.HisPrescriptionProject {
  9146. if subItem.Type == 3 {
  9147. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9148. if info.Price > 0 {
  9149. subItem.GoodInfo.PackingPrice = info.Price
  9150. }
  9151. }
  9152. }
  9153. }
  9154. }
  9155. }
  9156. }
  9157. if err == nil {
  9158. if len(prescriptions) == 0 {
  9159. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9160. return
  9161. } else {
  9162. this.ServeSuccessJSON(map[string]interface{}{
  9163. "prescriptions": prescriptions,
  9164. })
  9165. return
  9166. }
  9167. } else {
  9168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9169. return
  9170. }
  9171. }
  9172. func (this *HisApiController) GetCallHisPrescription() {
  9173. patient_id, _ := this.GetInt64("patient_id", 0)
  9174. timeLayout := "2006-01-02"
  9175. loc, _ := time.LoadLocation("Local")
  9176. start_time := this.GetString("start_time")
  9177. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9178. end_time := this.GetString("end_time")
  9179. p_type, _ := this.GetInt64("p_type")
  9180. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9181. adminUserInfo := this.GetAdminUserInfo()
  9182. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9183. //if
  9184. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9185. //
  9186. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9187. if adminUserInfo.CurrentOrgId == 10265 {
  9188. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9189. if config.ID > 0 && config.IsOpen == 1 {
  9190. for _, subitems := range prescriptions {
  9191. for _, item := range subitems.VMHisPrescription {
  9192. for _, subItem := range item.HisDoctorAdviceInfo {
  9193. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9194. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9195. if info.RetailPrice > 0 {
  9196. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9197. subItem.Drug.RetailPrice = drug.RetailPrice
  9198. }
  9199. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9200. subItem.Drug.MinPrice = info.RetailPrice
  9201. subItem.Drug.RetailPrice = info.RetailPrice
  9202. }
  9203. }
  9204. }
  9205. }
  9206. }
  9207. }
  9208. if config.ID > 0 && config.IsOpen == 1 {
  9209. for _, subitems := range prescriptions {
  9210. for _, item := range subitems.VMHisPrescription {
  9211. for _, subItem := range item.HisPrescriptionProject {
  9212. if subItem.Type == 3 {
  9213. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9214. if info.Price > 0 {
  9215. subItem.GoodInfo.PackingPrice = info.Price
  9216. }
  9217. }
  9218. }
  9219. }
  9220. }
  9221. }
  9222. }
  9223. if err == nil {
  9224. this.ServeSuccessJSON(map[string]interface{}{
  9225. "prescriptions": prescriptions,
  9226. })
  9227. return
  9228. } else {
  9229. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9230. return
  9231. }
  9232. }
  9233. func (this *HisApiController) GetHisDayPrescription() {
  9234. timeLayout := "2006-01-02"
  9235. loc, _ := time.LoadLocation("Local")
  9236. start_time := this.GetString("start_time")
  9237. patient_id, _ := this.GetInt64("patient_id", 0)
  9238. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9239. end_time := this.GetString("end_time")
  9240. p_type, _ := this.GetInt64("p_type")
  9241. order_status, _ := this.GetInt64("type")
  9242. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9243. adminUserInfo := this.GetAdminUserInfo()
  9244. var dayHisPrescription []*models.HisPrescription
  9245. var err error
  9246. if order_status == 1 || order_status == 0 {
  9247. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9248. } else if order_status == 2 {
  9249. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9250. }
  9251. var settle_total float64
  9252. for _, item := range dayHisPrescription {
  9253. if len(item.HisPrescriptionProject) > 0 {
  9254. for _, subItem := range item.HisPrescriptionProject {
  9255. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9256. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9257. settle_total = settle_total + total
  9258. }
  9259. }
  9260. if len(item.HisDoctorAdviceInfo) > 0 {
  9261. for _, subItem := range item.HisDoctorAdviceInfo {
  9262. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9263. settle_total = settle_total + total
  9264. }
  9265. }
  9266. }
  9267. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9268. if err == nil {
  9269. this.ServeSuccessJSON(map[string]interface{}{
  9270. "day_prescription": dayHisPrescription,
  9271. "settle_total": settle_total,
  9272. })
  9273. return
  9274. } else {
  9275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9276. return
  9277. }
  9278. }
  9279. func (c *HisApiController) GetHisChargePatientList() {
  9280. record_date := c.GetString("record_date")
  9281. order_status, _ := c.GetInt64("type")
  9282. sch_type, _ := c.GetInt64("sch_type")
  9283. timeLayout := "2006-01-02"
  9284. loc, _ := time.LoadLocation("Local")
  9285. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9286. if err != nil {
  9287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9288. return
  9289. }
  9290. recordDateTime := theTime.Unix()
  9291. adminInfo := c.GetAdminUserInfo()
  9292. var tempPatients []*service.NewTempPatients
  9293. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9294. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9295. if order_status != 2 {
  9296. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9297. } else {
  9298. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9299. }
  9300. } else {
  9301. if order_status != 2 {
  9302. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9303. } else {
  9304. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9305. }
  9306. }
  9307. var patients []*service.NewTempPatients
  9308. var patients_two []*service.NewTempPatients
  9309. for _, item := range tempPatients {
  9310. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9311. //过滤掉没挂号的和没开处方的
  9312. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9313. patients = append(patients, item)
  9314. }
  9315. //过滤掉没挂号的
  9316. if len(item.HisPatient) > 0 {
  9317. patients_two = append(patients_two, item)
  9318. }
  9319. } else {
  9320. if len(item.HisPrescription) > 0 {
  9321. patients = append(patients, item)
  9322. }
  9323. }
  9324. }
  9325. c.ServeSuccessJSON(map[string]interface{}{
  9326. "list": patients,
  9327. "list_two": patients_two,
  9328. })
  9329. }
  9330. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9331. record_date := c.GetString("record_date")
  9332. timeLayout := "2006-01-02"
  9333. loc, _ := time.LoadLocation("Local")
  9334. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9335. if err != nil {
  9336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9337. return
  9338. }
  9339. recordDateTime := theTime.Unix()
  9340. adminUser := c.GetAdminUserInfo()
  9341. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9342. var patients []*service.Patients
  9343. for _, item := range tempPatients {
  9344. if item.HisPatient.ID == 0 {
  9345. patients = append(patients, item)
  9346. }
  9347. }
  9348. c.ServeSuccessJSON(map[string]interface{}{
  9349. "list": patients,
  9350. //"list_two": patients_two,
  9351. })
  9352. }
  9353. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9354. newArr = make([]*service.Patients, 0)
  9355. for i := 0; i < len(patient); i++ {
  9356. repeat := false
  9357. for j := i + 1; j < len(patient); j++ {
  9358. if patient[i].ID == patient[j].ID {
  9359. repeat = true
  9360. break
  9361. }
  9362. }
  9363. if !repeat {
  9364. newArr = append(newArr, patient[i])
  9365. }
  9366. }
  9367. return
  9368. }
  9369. func (c *HisApiController) GetHisChargePatientInfo() {
  9370. patient_id, _ := c.GetInt64("patient_id")
  9371. his_patient_id, _ := c.GetInt64("his_patient_id")
  9372. record_date := c.GetString("record_date")
  9373. //start_time := c.GetString("start_time")
  9374. //end_time := c.GetString("end_time")
  9375. order_status, _ := c.GetInt64("type", 0)
  9376. p_type, _ := c.GetInt64("p_type", 0)
  9377. order_id, _ := c.GetInt64("order_id", 0)
  9378. timeLayout := "2006-01-02"
  9379. loc, _ := time.LoadLocation("Local")
  9380. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9381. if err != nil {
  9382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9383. return
  9384. }
  9385. recordDateTime := theTime.Unix()
  9386. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9387. //if err != nil {
  9388. //
  9389. //}
  9390. //startRecordDateTime := startTime.Unix()
  9391. //
  9392. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9393. //if err != nil {
  9394. //
  9395. //}
  9396. //endRecordDateTime := endTime.Unix()
  9397. admin := c.GetAdminUserInfo()
  9398. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9399. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9400. var prescriptions []*models.HisPrescription
  9401. //var unChargeMonthPrescriptions []*models.HisPrescription
  9402. order, _ := service.GetHisOrderByID(order_id)
  9403. if order_status == 1 || order_status == 0 {
  9404. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9405. } else if order_status == 2 {
  9406. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9407. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9408. }
  9409. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9410. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9411. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9412. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9413. //获取所有科室信息
  9414. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9415. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9416. c.ServeSuccessJSON(map[string]interface{}{
  9417. "his_info": his_patient_info,
  9418. "xt_info": xt_patient_info,
  9419. "prescription": prescriptions,
  9420. "case_history": case_history,
  9421. "info": patientPrescriptionInfo,
  9422. "last_info": lastPatientPrescriptionInfo,
  9423. "order": order,
  9424. "doctors": doctors,
  9425. "department": department,
  9426. "sch": sch,
  9427. })
  9428. return
  9429. }
  9430. func (c *HisApiController) GetAllOrderDetail() {
  9431. order_id, _ := c.GetInt64("id", 0)
  9432. order, _ := service.GetHisOrderByID(order_id)
  9433. if order.ID == 0 {
  9434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9435. return
  9436. }
  9437. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9438. org_id := c.GetAdminUserInfo().CurrentOrgId
  9439. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9440. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9441. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9442. c.ServeSuccessJSON(map[string]interface{}{
  9443. "order": order,
  9444. "order_info": order_info,
  9445. "patient": patient,
  9446. "admin_info": adminInfo,
  9447. "hospital_record": record,
  9448. })
  9449. return
  9450. }
  9451. func (c *HisApiController) GetAllOrderDetailCollect() {
  9452. order_id, _ := c.GetInt64("id", 0)
  9453. order, _ := service.GetHisOrderByID(order_id)
  9454. if order.ID == 0 {
  9455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9456. return
  9457. }
  9458. org_id := c.GetAdminUserInfo().CurrentOrgId
  9459. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9460. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9461. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9462. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9463. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9464. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9465. var bedCostTotal float64 = 0 //床位总费
  9466. //var bedCostSelfTotal float64 = 0 //床位自费
  9467. var operationCostTotal float64 = 0 //手术费
  9468. //var operationCostSelfTotal float64 = 0 //手术费
  9469. var otherCostTotal float64 = 0 //其他费用
  9470. //var otherCostSelfTotal float64 = 0 //其他费用
  9471. var materialCostTotal float64 = 0 //材料费
  9472. //var materialCostSelfTotal float64 = 0 //材料费
  9473. var westernMedicineCostTotal float64 = 0 //西药费
  9474. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9475. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9476. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9477. var checkCostTotal float64 = 0 //检查费
  9478. //var checkCostSelfTotal float64 = 0 //检查费
  9479. var laboratoryCostTotal float64 = 0 //化验费
  9480. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9481. var treatCostTotal float64 = 0 //治疗费用
  9482. //var treatCostSelfTotal float64 = 0 //治疗费用
  9483. var zhenChaCostTotal float64 = 0 //其他费用
  9484. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9485. decimal.DivisionPrecision = 2
  9486. var BalanceAccountsType int64
  9487. if his.ID > 0 {
  9488. BalanceAccountsType = his.BalanceAccountsType
  9489. } else {
  9490. BalanceAccountsType = record.BalanceAccountsType
  9491. }
  9492. if BalanceAccountsType != 2 {
  9493. for _, item := range order_info {
  9494. if org_id == 10215 {
  9495. if item.MedChrgitmType == "01" { //床位费
  9496. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9497. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9498. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9499. }
  9500. if item.MedChrgitmType == "02" { //诊察费
  9501. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9502. //zhenChaCostSelfTotal = zhenChaCostTotal
  9503. }
  9504. if item.MedChrgitmType == "03" { //检查费
  9505. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9506. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9507. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9508. }
  9509. //if item.MedChrgitmType == "02" { //检查费
  9510. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9511. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9512. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9513. //}
  9514. if item.MedChrgitmType == "04" { //化验费
  9515. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9516. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9517. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9518. }
  9519. if item.MedChrgitmType == "05" { //治疗费
  9520. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9521. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9522. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9523. }
  9524. if item.MedChrgitmType == "06" { //手术费
  9525. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9526. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9527. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9528. }
  9529. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9530. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9531. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9532. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9533. }
  9534. if item.MedChrgitmType == "09" { //西药费
  9535. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9536. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9537. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9538. }
  9539. if item.MedChrgitmType == "11" { //中成费
  9540. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9541. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9542. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9543. }
  9544. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9545. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9546. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9547. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9548. }
  9549. } else if org_id == 10188 || org_id == 10217 {
  9550. if item.MedChrgitmType == "01" { //床位费
  9551. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9552. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9553. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9554. }
  9555. if item.MedChrgitmType == "02" { //诊察费
  9556. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9557. //zhenChaCostSelfTotal = zhenChaCostTotal
  9558. }
  9559. if item.MedChrgitmType == "03" { //检查费
  9560. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9561. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9562. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9563. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9564. }
  9565. //if item.MedChrgitmType == "02" { //检查费
  9566. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9567. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9568. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9569. //}
  9570. if item.MedChrgitmType == "04" { //化验费
  9571. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9572. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9573. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9574. }
  9575. if item.MedChrgitmType == "05" { //治疗费
  9576. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9577. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9578. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9579. }
  9580. if item.MedChrgitmType == "06" { //手术费
  9581. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9582. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9583. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9584. }
  9585. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9586. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9587. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9588. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9589. }
  9590. if item.MedChrgitmType == "09" { //西药费
  9591. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9592. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9593. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9594. }
  9595. if item.MedChrgitmType == "11" { //中成费
  9596. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9597. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9598. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9599. }
  9600. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9601. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9602. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9603. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9604. }
  9605. } else {
  9606. if item.MedChrgitmType == "01" { //床位费
  9607. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9608. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9609. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9610. }
  9611. //if item.MedChrgitmType == "02" { //诊察费
  9612. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9613. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9614. //}
  9615. if item.MedChrgitmType == "03" { //检查费
  9616. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9617. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9618. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9619. }
  9620. //if item.MedChrgitmType == "02" { //检查费
  9621. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9622. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9623. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9624. //}
  9625. if item.MedChrgitmType == "04" { //化验费
  9626. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9627. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9628. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9629. }
  9630. if item.MedChrgitmType == "05" { //治疗费
  9631. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9632. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9633. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9634. }
  9635. if item.MedChrgitmType == "06" { //手术费
  9636. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9637. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9638. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9639. }
  9640. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9641. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9642. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9643. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9644. }
  9645. if item.MedChrgitmType == "09" { //西药费
  9646. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9647. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9648. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9649. }
  9650. if item.MedChrgitmType == "11" { //中成费
  9651. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9652. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9653. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9654. }
  9655. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9656. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9657. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9658. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9659. }
  9660. }
  9661. }
  9662. c.ServeSuccessJSON(map[string]interface{}{
  9663. "order": order,
  9664. "order_info": order_info,
  9665. "patient": patient,
  9666. "admin_info": adminInfo,
  9667. "his_hospital": record,
  9668. "bedCostTotal": bedCostTotal,
  9669. "operationCostTotal": operationCostTotal,
  9670. "otherCostTotal": otherCostTotal,
  9671. "materialCostTotal": materialCostTotal,
  9672. "westernMedicineCostTotal": westernMedicineCostTotal,
  9673. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9674. "checkCostTotal": checkCostTotal,
  9675. "zhenChaCostTotal": zhenChaCostTotal,
  9676. "laboratoryCostTotal": laboratoryCostTotal,
  9677. "treatCostTotal": treatCostTotal,
  9678. })
  9679. } else {
  9680. for _, item := range order_info {
  9681. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9682. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9683. item.MedChrgitmType = "09"
  9684. }
  9685. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9686. if item.HisPrescriptionProject.Type == 2 {
  9687. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9688. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9689. case 0:
  9690. item.MedChrgitmType = "0"
  9691. break
  9692. case 1:
  9693. item.MedChrgitmType = "14"
  9694. break
  9695. case 2:
  9696. item.MedChrgitmType = "05"
  9697. break
  9698. case 3:
  9699. item.MedChrgitmType = "03"
  9700. break
  9701. case 4:
  9702. item.MedChrgitmType = "03"
  9703. break
  9704. case 5:
  9705. item.MedChrgitmType = "08"
  9706. break
  9707. case 6:
  9708. item.MedChrgitmType = "14"
  9709. break
  9710. case 7:
  9711. item.MedChrgitmType = "14"
  9712. break
  9713. case 8:
  9714. item.MedChrgitmType = "03"
  9715. break
  9716. case 9:
  9717. item.MedChrgitmType = "14"
  9718. break
  9719. case 10:
  9720. item.MedChrgitmType = "14"
  9721. break
  9722. case 11:
  9723. item.MedChrgitmType = "06"
  9724. break
  9725. case 12:
  9726. item.MedChrgitmType = "12"
  9727. break
  9728. case 13:
  9729. item.MedChrgitmType = "01"
  9730. break
  9731. case 14:
  9732. item.MedChrgitmType = "04"
  9733. break
  9734. case 15:
  9735. item.MedChrgitmType = "14"
  9736. break
  9737. }
  9738. } else {
  9739. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9740. case 1:
  9741. item.MedChrgitmType = "14"
  9742. break
  9743. case 2:
  9744. item.MedChrgitmType = "05"
  9745. break
  9746. case 3:
  9747. item.MedChrgitmType = "04"
  9748. break
  9749. case 4:
  9750. item.MedChrgitmType = "14"
  9751. break
  9752. case 5:
  9753. item.MedChrgitmType = "08"
  9754. break
  9755. case 6:
  9756. item.MedChrgitmType = "14"
  9757. break
  9758. case 7:
  9759. item.MedChrgitmType = "14"
  9760. break
  9761. case 8:
  9762. item.MedChrgitmType = "03"
  9763. break
  9764. case 9:
  9765. item.MedChrgitmType = "14"
  9766. break
  9767. }
  9768. }
  9769. } else if item.HisPrescriptionProject.Type == 3 {
  9770. item.MedChrgitmType = "08"
  9771. }
  9772. }
  9773. }
  9774. for _, item := range order_info {
  9775. if org_id == 10215 {
  9776. if item.MedChrgitmType == "01" { //床位费
  9777. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9778. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9779. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9780. }
  9781. if item.MedChrgitmType == "02" { //诊察费
  9782. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9783. //zhenChaCostSelfTotal = zhenChaCostTotal
  9784. }
  9785. if item.MedChrgitmType == "03" { //检查费
  9786. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9787. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9788. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9789. }
  9790. //if item.MedChrgitmType == "02" { //检查费
  9791. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9792. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9793. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9794. //}
  9795. if item.MedChrgitmType == "04" { //化验费
  9796. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9797. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9798. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9799. }
  9800. if item.MedChrgitmType == "05" { //治疗费
  9801. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9802. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9803. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9804. }
  9805. if item.MedChrgitmType == "06" { //手术费
  9806. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9807. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9808. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9809. }
  9810. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9811. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9812. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9813. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9814. }
  9815. if item.MedChrgitmType == "09" { //西药费
  9816. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9817. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9818. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9819. }
  9820. if item.MedChrgitmType == "11" { //中成费
  9821. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9822. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9823. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9824. }
  9825. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9826. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9827. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9828. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9829. }
  9830. } else {
  9831. if item.MedChrgitmType == "01" { //床位费
  9832. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9833. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9834. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9835. }
  9836. //if item.MedChrgitmType == "02" { //诊察费
  9837. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9838. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9839. //}
  9840. if item.MedChrgitmType == "03" { //检查费
  9841. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9842. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9843. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9844. }
  9845. //if item.MedChrgitmType == "02" { //检查费
  9846. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9847. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9848. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9849. //}
  9850. if item.MedChrgitmType == "04" { //化验费
  9851. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9852. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9853. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9854. }
  9855. if item.MedChrgitmType == "05" { //治疗费
  9856. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9857. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9858. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9859. }
  9860. if item.MedChrgitmType == "06" { //手术费
  9861. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9862. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9863. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9864. }
  9865. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9866. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9867. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9868. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9869. }
  9870. if item.MedChrgitmType == "09" { //西药费
  9871. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9872. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9873. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9874. }
  9875. if item.MedChrgitmType == "11" { //中成费
  9876. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9877. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9878. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9879. }
  9880. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9881. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9882. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9883. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9884. }
  9885. }
  9886. }
  9887. c.ServeSuccessJSON(map[string]interface{}{
  9888. "order": order,
  9889. "order_info": order_info,
  9890. "patient": patient,
  9891. "admin_info": adminInfo,
  9892. "his_hospital": record,
  9893. "bedCostTotal": bedCostTotal,
  9894. "operationCostTotal": operationCostTotal,
  9895. "otherCostTotal": otherCostTotal,
  9896. "materialCostTotal": materialCostTotal,
  9897. "westernMedicineCostTotal": westernMedicineCostTotal,
  9898. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9899. "checkCostTotal": checkCostTotal,
  9900. "zhenChaCostTotal": zhenChaCostTotal,
  9901. "laboratoryCostTotal": laboratoryCostTotal,
  9902. "treatCostTotal": treatCostTotal,
  9903. })
  9904. }
  9905. }
  9906. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9907. page, _ := c.GetInt64("page")
  9908. limit, _ := c.GetInt64("limit")
  9909. keywords := c.GetString("keywords")
  9910. start_time := c.GetString("start_time")
  9911. end_time := c.GetString("end_time")
  9912. //clr_type := c.GetString("clr_type")
  9913. insutype := c.GetString("insutype")
  9914. timeLayout := "2006-01-02"
  9915. loc, _ := time.LoadLocation("Local")
  9916. var theStartTIme int64
  9917. if len(start_time) > 0 {
  9918. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9919. theStartTIme = theTime.Unix()
  9920. }
  9921. var theEndtTIme int64
  9922. if len(end_time) > 0 {
  9923. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9924. theEndtTIme = theTime.Unix()
  9925. }
  9926. if page <= 0 {
  9927. page = 1
  9928. }
  9929. if limit <= 0 {
  9930. limit = 10
  9931. }
  9932. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9933. c.ServeSuccessJSON(map[string]interface{}{
  9934. "total": total,
  9935. "list": list,
  9936. })
  9937. return
  9938. }
  9939. func (c *HisApiController) GetPutOnRecordList() {
  9940. page, _ := c.GetInt64("page")
  9941. limit, _ := c.GetInt64("limit")
  9942. keywords := c.GetString("keywords")
  9943. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9944. if page <= 0 {
  9945. page = 1
  9946. }
  9947. if limit <= 0 {
  9948. limit = 10
  9949. }
  9950. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9951. c.ServeSuccessJSON(map[string]interface{}{
  9952. "total": total,
  9953. "list": list,
  9954. })
  9955. return
  9956. }
  9957. func (c *HisApiController) GetCompareData() {
  9958. start_time := c.GetString("start_time")
  9959. end_time := c.GetString("end_time")
  9960. insutype := c.GetString("insutype")
  9961. clr_type := c.GetString("clr_type")
  9962. timeLayout := "2006-01-02"
  9963. loc, _ := time.LoadLocation("Local")
  9964. var theStartTIme int64
  9965. if len(start_time) > 0 {
  9966. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9967. if err != nil {
  9968. theStartTIme = 0
  9969. }
  9970. theStartTIme = theTime.Unix()
  9971. }
  9972. var theEndtTIme int64
  9973. if len(end_time) > 0 {
  9974. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9975. if err != nil {
  9976. theEndtTIme = 0
  9977. }
  9978. theEndtTIme = theTime.Unix()
  9979. }
  9980. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9981. fmt.Println(err)
  9982. if err == nil {
  9983. c.ServeSuccessJSON(map[string]interface{}{
  9984. "list": formData,
  9985. })
  9986. } else {
  9987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9988. return
  9989. }
  9990. }
  9991. func (c *HisApiController) GetFaPiaoData() {
  9992. order_id, _ := c.GetInt64("order_id")
  9993. patient_id, _ := c.GetInt64("patient_id")
  9994. //number := c.GetString("number")
  9995. adminUser := c.GetAdminUserInfo()
  9996. order, _ := service.GetHisOrderByID(order_id)
  9997. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9998. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9999. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10000. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10001. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10002. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10003. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10004. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10005. var bedCostTotal float64 = 0 //床位总费
  10006. var bedCostSelfTotal float64 = 0 //床位自费
  10007. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10008. var operationCostTotal float64 = 0 //手术费
  10009. var operationCostSelfTotal float64 = 0 //手术费
  10010. var operationCostPartSelfTotal float64 = 0 //手术费
  10011. var otherCostTotal float64 = 0 //其他费用
  10012. var otherCostSelfTotal float64 = 0 //其他费用
  10013. var otherCostPartSelfTotal float64 = 0 //其他费用
  10014. var materialCostTotal float64 = 0 //材料费
  10015. var materialCostSelfTotal float64 = 0 //材料费
  10016. var materialCostPartSelfTotal float64 = 0 //材料费
  10017. var westernMedicineCostTotal float64 = 0 //西药费
  10018. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10019. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10020. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10021. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10022. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10023. var checkCostTotal float64 = 0 //检查费
  10024. var checkCostSelfTotal float64 = 0 //检查费
  10025. var checkCostPartSelfTotal float64 = 0 //检查费
  10026. var hiliCostTotal float64 = 0 //护理费
  10027. var hiliCostSelfTotal float64 = 0 //护理费
  10028. var hiliCostPartSelfTotal float64 = 0 //护理费
  10029. var laboratoryCostTotal float64 = 0 //化验费
  10030. var laboratoryCostSelfTotal float64 = 0 //化验费
  10031. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10032. var treatCostTotal float64 = 0 //治疗费用
  10033. var treatCostSelfTotal float64 = 0 //治疗费用
  10034. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10035. var zhenChaCostTotal float64 = 0 //其他费用
  10036. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10037. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10038. decimal.DivisionPrecision = 2
  10039. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10040. var balanceAccountsType int64
  10041. if his.ID > 0 {
  10042. balanceAccountsType = his.BalanceAccountsType
  10043. } else {
  10044. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10045. }
  10046. if balanceAccountsType == 2 {
  10047. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10048. for _, item := range orderInfos_two {
  10049. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10050. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10051. item.MedChrgitmType = "09"
  10052. }
  10053. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10054. if item.HisPrescriptionProject.Type == 2 {
  10055. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10056. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10057. case 0:
  10058. item.MedChrgitmType = "0"
  10059. break
  10060. case 1:
  10061. item.MedChrgitmType = "14"
  10062. break
  10063. case 2:
  10064. item.MedChrgitmType = "05"
  10065. break
  10066. case 3:
  10067. item.MedChrgitmType = "03"
  10068. break
  10069. case 4:
  10070. item.MedChrgitmType = "03"
  10071. break
  10072. case 5:
  10073. item.MedChrgitmType = "08"
  10074. break
  10075. case 6:
  10076. item.MedChrgitmType = "14"
  10077. break
  10078. case 7:
  10079. item.MedChrgitmType = "14"
  10080. break
  10081. case 8:
  10082. item.MedChrgitmType = "03"
  10083. break
  10084. case 9:
  10085. item.MedChrgitmType = "14"
  10086. break
  10087. case 10:
  10088. item.MedChrgitmType = "14"
  10089. break
  10090. case 11:
  10091. item.MedChrgitmType = "06"
  10092. break
  10093. case 12:
  10094. item.MedChrgitmType = "12"
  10095. break
  10096. case 13:
  10097. item.MedChrgitmType = "01"
  10098. break
  10099. case 14:
  10100. item.MedChrgitmType = "04"
  10101. break
  10102. case 15:
  10103. item.MedChrgitmType = "02"
  10104. break
  10105. }
  10106. } else {
  10107. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10108. case 1:
  10109. item.MedChrgitmType = "14"
  10110. break
  10111. case 2:
  10112. item.MedChrgitmType = "05"
  10113. break
  10114. case 3:
  10115. item.MedChrgitmType = "04"
  10116. break
  10117. case 4:
  10118. item.MedChrgitmType = "03"
  10119. break
  10120. case 5:
  10121. item.MedChrgitmType = "08"
  10122. break
  10123. case 6:
  10124. item.MedChrgitmType = "14"
  10125. break
  10126. case 7:
  10127. item.MedChrgitmType = "14"
  10128. break
  10129. case 8:
  10130. item.MedChrgitmType = "03"
  10131. break
  10132. case 9:
  10133. item.MedChrgitmType = "14"
  10134. break
  10135. }
  10136. }
  10137. } else if item.HisPrescriptionProject.Type == 3 {
  10138. item.MedChrgitmType = "08"
  10139. }
  10140. }
  10141. }
  10142. for _, item := range orderInfos_two {
  10143. fmt.Println(item.MedChrgitmType)
  10144. if item.MedChrgitmType == "07" { //床位费
  10145. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10146. hiliCostSelfTotal = hiliCostTotal
  10147. }
  10148. if item.MedChrgitmType == "01" { //床位费
  10149. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10150. bedCostSelfTotal = bedCostTotal
  10151. }
  10152. if item.MedChrgitmType == "02" { //诊察费
  10153. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10154. zhenChaCostSelfTotal = zhenChaCostTotal
  10155. }
  10156. if item.MedChrgitmType == "03" { //检查费
  10157. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10158. checkCostSelfTotal = checkCostTotal
  10159. }
  10160. if item.MedChrgitmType == "04" { //化验费
  10161. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10162. laboratoryCostSelfTotal = laboratoryCostTotal
  10163. }
  10164. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10165. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10166. treatCostSelfTotal = treatCostTotal
  10167. }
  10168. if item.MedChrgitmType == "06" { //手术费
  10169. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10170. operationCostSelfTotal = treatCostTotal
  10171. }
  10172. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10173. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10174. materialCostSelfTotal = materialCostTotal
  10175. }
  10176. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10177. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10178. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10179. }
  10180. if item.MedChrgitmType == "11" { //中成费
  10181. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10182. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10183. }
  10184. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10185. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10186. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10187. otherCostSelfTotal = otherCostTotal
  10188. }
  10189. } else {
  10190. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10191. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10192. otherCostSelfTotal = otherCostTotal
  10193. }
  10194. }
  10195. }
  10196. } else {
  10197. for _, item := range orderInfos {
  10198. if item.MedChrgitmType == "01" { //床位费
  10199. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10200. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10201. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10202. }
  10203. if item.MedChrgitmType == "02" { //诊察费
  10204. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10205. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10206. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10207. }
  10208. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10209. if item.MedChrgitmType == "03" { //检查费
  10210. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10211. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10212. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10213. }
  10214. } else {
  10215. if item.MedChrgitmType == "03" { //检查费
  10216. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10217. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10218. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10219. }
  10220. }
  10221. if item.MedChrgitmType == "04" { //化验费
  10222. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10223. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10224. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10225. }
  10226. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10227. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10228. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10229. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10230. }
  10231. if item.MedChrgitmType == "06" { //手术费
  10232. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10233. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10234. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10235. }
  10236. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10237. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10238. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10239. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10240. }
  10241. if item.MedChrgitmType == "07" { //护理
  10242. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10243. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10244. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10245. }
  10246. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10247. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10248. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10249. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10250. }
  10251. if item.MedChrgitmType == "11" { //中成费
  10252. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10253. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10254. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10255. }
  10256. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10257. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10258. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10259. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10260. }
  10261. }
  10262. }
  10263. timeLayout := "2006-01-02"
  10264. loc, _ := time.LoadLocation("Local")
  10265. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10266. if err != nil {
  10267. }
  10268. startRecordDateTime := startTime.Unix()
  10269. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10270. if err != nil {
  10271. }
  10272. endRecordDateTime := endTime.Unix()
  10273. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10274. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10275. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10276. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10277. c.ServeSuccessJSON(map[string]interface{}{
  10278. "charge_admin_name": charge_admin.UserName,
  10279. "order_number": order.Number, //业务流水号
  10280. "id_card_no": his.IdCardNo, //社会保障号
  10281. "patient": patient,
  10282. "department_name": department.Name, //科室
  10283. "number": his.Number, //门诊号
  10284. "date": order.SettleAccountsDate, //结算日期
  10285. "name": order.PsnName, //姓名
  10286. "gender": patient.Gender, //性别
  10287. "psn_cash_money": order.PsnCashPay, //个人支付
  10288. "pay_way": "门诊", //结算方式
  10289. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10290. "admin_user_name": admin.UserName, //收款员
  10291. "order": order,
  10292. "order_info": orderInfos_two,
  10293. "his": his,
  10294. "bedCostTotal": bedCostTotal,
  10295. "bedCostSelfTotal": bedCostSelfTotal,
  10296. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10297. "operationCostTotal": operationCostTotal,
  10298. "operationCostSelfTotal": operationCostSelfTotal,
  10299. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10300. "otherCostTotal": otherCostTotal,
  10301. "otherCostSelfTotal": otherCostSelfTotal,
  10302. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10303. "materialCostTotal": materialCostTotal,
  10304. "materialCostSelfTotal": materialCostSelfTotal,
  10305. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10306. "westernMedicineCostTotal": westernMedicineCostTotal,
  10307. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10308. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10309. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10310. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10311. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10312. "checkCostTotal": checkCostTotal,
  10313. "checkCostSelfTotal": checkCostSelfTotal,
  10314. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10315. "laboratoryCostTotal": laboratoryCostTotal,
  10316. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10317. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10318. "treatCostTotal": treatCostTotal,
  10319. "treatCostSelfTotal": treatCostSelfTotal,
  10320. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10321. "zhenChaCostTotal": zhenChaCostTotal,
  10322. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10323. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10324. "his_hospital_record": his_hospital_record,
  10325. "pre_pay_money": pre_pay_money,
  10326. "refund_sum": sum,
  10327. "doctor_info": doctor_info,
  10328. "hiliCostTotal": hiliCostTotal,
  10329. "hiliCostSelfTotal": hiliCostSelfTotal,
  10330. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10331. })
  10332. }
  10333. //func (c *HisApiController) GetFaPiaoDatas() {
  10334. // order_ids := c.GetString("order_ids")
  10335. // patient_id, _ := c.GetInt64("patient_id")
  10336. // adminUser := c.GetAdminUserInfo()
  10337. //
  10338. // orders := strings.Split(order_ids, ",")
  10339. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10340. //
  10341. // for _, item := range orders {
  10342. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10343. // order, _ := service.GetHisOrderByID(order_id)
  10344. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10345. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10346. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10347. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10348. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10349. //
  10350. // }
  10351. //
  10352. // var bedCostTotal float64 = 0 //床位总费
  10353. // var bedCostSelfTotal float64 = 0 //床位自费
  10354. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10355. //
  10356. // var operationCostTotal float64 = 0 //手术费
  10357. // var operationCostSelfTotal float64 = 0 //手术费
  10358. // var operationCostPartSelfTotal float64 = 0 //手术费
  10359. //
  10360. // var otherCostTotal float64 = 0 //其他费用
  10361. // var otherCostSelfTotal float64 = 0 //其他费用
  10362. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10363. //
  10364. // var materialCostTotal float64 = 0 //材料费
  10365. // var materialCostSelfTotal float64 = 0 //材料费
  10366. // var materialCostPartSelfTotal float64 = 0 //材料费
  10367. //
  10368. // var westernMedicineCostTotal float64 = 0 //西药费
  10369. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10370. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10371. //
  10372. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10373. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10374. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10375. //
  10376. // var checkCostTotal float64 = 0 //检查费
  10377. // var checkCostSelfTotal float64 = 0 //检查费
  10378. // var checkCostPartSelfTotal float64 = 0 //检查费
  10379. //
  10380. // var laboratoryCostTotal float64 = 0 //化验费
  10381. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10382. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10383. //
  10384. // var treatCostTotal float64 = 0 //治疗费用
  10385. // var treatCostSelfTotal float64 = 0 //治疗费用
  10386. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10387. //
  10388. // var zhenChaCostTotal float64 = 0 //其他费用
  10389. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10390. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10391. //
  10392. // decimal.DivisionPrecision = 2
  10393. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10394. //
  10395. // var balanceAccountsType int64
  10396. // if his.ID > 0 {
  10397. // balanceAccountsType = his.BalanceAccountsType
  10398. // } else {
  10399. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10400. // }
  10401. // if balanceAccountsType == 2 {
  10402. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10403. // for _, item := range orderInfos_two {
  10404. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10405. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10406. // item.MedChrgitmType = "09"
  10407. // }
  10408. //
  10409. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10410. // if item.HisPrescriptionProject.Type == 2 {
  10411. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10412. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10413. // case 0:
  10414. // item.MedChrgitmType = "0"
  10415. // break
  10416. // case 1:
  10417. // item.MedChrgitmType = "14"
  10418. // break
  10419. // case 2:
  10420. // item.MedChrgitmType = "05"
  10421. //
  10422. // break
  10423. // case 3:
  10424. // item.MedChrgitmType = "03"
  10425. //
  10426. // break
  10427. // case 4:
  10428. // item.MedChrgitmType = "03"
  10429. //
  10430. // break
  10431. // case 5:
  10432. // item.MedChrgitmType = "08"
  10433. //
  10434. // break
  10435. // case 6:
  10436. // item.MedChrgitmType = "14"
  10437. //
  10438. // break
  10439. // case 7:
  10440. // item.MedChrgitmType = "14"
  10441. //
  10442. // break
  10443. // case 8:
  10444. // item.MedChrgitmType = "03"
  10445. // break
  10446. // case 9:
  10447. // item.MedChrgitmType = "14"
  10448. // break
  10449. // case 10:
  10450. // item.MedChrgitmType = "14"
  10451. // break
  10452. // case 11:
  10453. // item.MedChrgitmType = "06"
  10454. // break
  10455. // case 12:
  10456. // item.MedChrgitmType = "12"
  10457. // break
  10458. // case 13:
  10459. // item.MedChrgitmType = "01"
  10460. // break
  10461. // case 14:
  10462. // item.MedChrgitmType = "04"
  10463. // break
  10464. // case 15:
  10465. // item.MedChrgitmType = "02"
  10466. // break
  10467. //
  10468. // }
  10469. //
  10470. // } else {
  10471. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10472. //
  10473. // case 1:
  10474. // item.MedChrgitmType = "14"
  10475. // break
  10476. // case 2:
  10477. // item.MedChrgitmType = "05"
  10478. //
  10479. // break
  10480. // case 3:
  10481. // item.MedChrgitmType = "03"
  10482. //
  10483. // break
  10484. // case 4:
  10485. // item.MedChrgitmType = "03"
  10486. //
  10487. // break
  10488. // case 5:
  10489. // item.MedChrgitmType = "08"
  10490. //
  10491. // break
  10492. // case 6:
  10493. // item.MedChrgitmType = "14"
  10494. //
  10495. // break
  10496. // case 7:
  10497. // item.MedChrgitmType = "14"
  10498. //
  10499. // break
  10500. // case 8:
  10501. // item.MedChrgitmType = "03"
  10502. // break
  10503. // case 9:
  10504. // item.MedChrgitmType = "14"
  10505. // break
  10506. //
  10507. // }
  10508. //
  10509. // }
  10510. //
  10511. // } else if item.HisPrescriptionProject.Type == 3 {
  10512. // item.MedChrgitmType = "08"
  10513. // }
  10514. // }
  10515. // }
  10516. //
  10517. // for _, item := range orderInfos_two {
  10518. // fmt.Println(item.MedChrgitmType)
  10519. // if item.MedChrgitmType == "01" { //床位费
  10520. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10521. // bedCostSelfTotal = bedCostTotal
  10522. // }
  10523. //
  10524. // if item.MedChrgitmType == "02" { //诊察费
  10525. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10526. // zhenChaCostSelfTotal = zhenChaCostTotal
  10527. // }
  10528. //
  10529. // if item.MedChrgitmType == "03" { //检查费
  10530. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10531. // checkCostSelfTotal = checkCostTotal
  10532. // }
  10533. //
  10534. // if item.MedChrgitmType == "04" { //化验费
  10535. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10536. // laboratoryCostSelfTotal = laboratoryCostTotal
  10537. // }
  10538. //
  10539. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10540. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10541. // treatCostSelfTotal = treatCostTotal
  10542. // }
  10543. //
  10544. // if item.MedChrgitmType == "06" { //手术费
  10545. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10546. // operationCostSelfTotal = treatCostTotal
  10547. // }
  10548. //
  10549. // if item.MedChrgitmType == "08" { //材料费
  10550. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10551. // materialCostSelfTotal = materialCostTotal
  10552. // }
  10553. //
  10554. // if item.MedChrgitmType == "09" { //西药费
  10555. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10556. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10557. // }
  10558. //
  10559. // if item.MedChrgitmType == "11" { //中成费
  10560. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10561. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10562. // }
  10563. //
  10564. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10565. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10566. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10567. // otherCostSelfTotal = otherCostTotal
  10568. // }
  10569. // } else {
  10570. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10571. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10572. // otherCostSelfTotal = otherCostTotal
  10573. // }
  10574. //
  10575. // }
  10576. //
  10577. // }
  10578. //
  10579. // } else {
  10580. // for _, item := range orderInfos {
  10581. // if item.MedChrgitmType == "01" { //床位费
  10582. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10583. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10584. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10585. // }
  10586. //
  10587. // if item.MedChrgitmType == "02" { //诊察费
  10588. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10589. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10590. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10591. // }
  10592. //
  10593. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10594. // if item.MedChrgitmType == "03" { //检查费
  10595. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10596. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10597. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10598. //
  10599. // }
  10600. // } else {
  10601. // if item.MedChrgitmType == "03" { //检查费
  10602. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10603. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10604. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10605. // }
  10606. //
  10607. // }
  10608. //
  10609. // if item.MedChrgitmType == "04" { //化验费
  10610. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10611. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10612. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10613. //
  10614. // }
  10615. //
  10616. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10617. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10618. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10619. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10620. //
  10621. // }
  10622. //
  10623. // if item.MedChrgitmType == "06" { //手术费
  10624. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10625. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10626. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10627. // }
  10628. //
  10629. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10630. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10631. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10632. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10633. // }
  10634. //
  10635. // if item.MedChrgitmType == "09" { //西药费
  10636. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10637. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10638. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10639. // }
  10640. //
  10641. // if item.MedChrgitmType == "11" { //中成费
  10642. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10643. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10644. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10645. // }
  10646. //
  10647. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10648. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10649. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10650. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10651. // }
  10652. //
  10653. // }
  10654. // }
  10655. // timeLayout := "2006-01-02"
  10656. // loc, _ := time.LoadLocation("Local")
  10657. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10658. // if err != nil {
  10659. // }
  10660. // startRecordDateTime := startTime.Unix()
  10661. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10662. // if err != nil {
  10663. // }
  10664. // endRecordDateTime := endTime.Unix()
  10665. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10666. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10667. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10668. //
  10669. // c.ServeSuccessJSON(map[string]interface{}{
  10670. // "order_number": order.Number, //业务流水号
  10671. // "id_card_no": his.IdCardNo, //社会保障号
  10672. // "department_name": department.Name, //科室
  10673. // "number": his.Number, //门诊号
  10674. // "date": order.SettleAccountsDate, //结算日期
  10675. // "name": order.PsnName, //姓名
  10676. // "gender": patient.Gender, //性别
  10677. // "psn_cash_money": order.PsnCashPay, //个人支付
  10678. // "pay_way": "门诊", //结算方式
  10679. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10680. // "admin_user_name": admin.UserName, //收款员
  10681. // "order": order,
  10682. // "order_info": orderInfos_two,
  10683. // "his": his,
  10684. // "bedCostTotal": bedCostTotal,
  10685. // "bedCostSelfTotal": bedCostSelfTotal,
  10686. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10687. // "operationCostTotal": operationCostTotal,
  10688. // "operationCostSelfTotal": operationCostSelfTotal,
  10689. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10690. // "otherCostTotal": otherCostTotal,
  10691. // "otherCostSelfTotal": otherCostSelfTotal,
  10692. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10693. // "materialCostTotal": materialCostTotal,
  10694. // "materialCostSelfTotal": materialCostSelfTotal,
  10695. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10696. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10697. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10698. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10699. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10700. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10701. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10702. // "checkCostTotal": checkCostTotal,
  10703. // "checkCostSelfTotal": checkCostSelfTotal,
  10704. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10705. // "laboratoryCostTotal": laboratoryCostTotal,
  10706. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10707. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10708. // "treatCostTotal": treatCostTotal,
  10709. // "treatCostSelfTotal": treatCostSelfTotal,
  10710. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10711. // "zhenChaCostTotal": zhenChaCostTotal,
  10712. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10713. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10714. // "his_hospital_record": his_hospital_record,
  10715. // "pre_pay_money": pre_pay_money,
  10716. // "refund_sum": sum,
  10717. // })
  10718. //
  10719. //}
  10720. func (this *HisApiController) GetIncomeStatisticsData() {
  10721. start_time := this.GetString("start_time")
  10722. end_time := this.GetString("end_time")
  10723. key_words := this.GetString("key_words")
  10724. limit, _ := this.GetInt64("limit")
  10725. page, _ := this.GetInt64("page")
  10726. if page <= 0 {
  10727. page = 1
  10728. }
  10729. if limit <= 0 {
  10730. limit = 10
  10731. }
  10732. statistics_type, _ := this.GetInt64("statistics_type")
  10733. admin := this.GetAdminUserInfo()
  10734. timeLayout := "2006-01-02"
  10735. loc, _ := time.LoadLocation("Local")
  10736. var theStartTIme int64
  10737. if len(start_time) > 0 {
  10738. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10739. if err != nil {
  10740. theStartTIme = 0
  10741. }
  10742. theStartTIme = theTime.Unix()
  10743. }
  10744. var theEndtTIme int64
  10745. if len(end_time) > 0 {
  10746. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10747. if err != nil {
  10748. theEndtTIme = 0
  10749. }
  10750. theEndtTIme = theTime.Unix()
  10751. }
  10752. if statistics_type == 1 {
  10753. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10754. this.ServeSuccessJSON(map[string]interface{}{
  10755. "list": list,
  10756. "total": total,
  10757. })
  10758. } else {
  10759. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10760. this.ServeSuccessJSON(map[string]interface{}{
  10761. "list": list,
  10762. "total": total,
  10763. })
  10764. }
  10765. }
  10766. func (c *HisApiController) PostProjectInformation() {
  10767. adminUser := c.GetAdminUserInfo()
  10768. orgId := adminUser.CurrentOrgId
  10769. dataBody := make(map[string]interface{}, 0)
  10770. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10771. if err != nil {
  10772. utils.ErrorLog(err.Error())
  10773. return
  10774. }
  10775. utils.ErrorLog("%v", dataBody)
  10776. var projectList []*models.HisProject
  10777. var total_goods []interface{}
  10778. tempProjects := dataBody["projects"].([]interface{})
  10779. total_goods = tempProjects
  10780. for index, projectMap := range tempProjects {
  10781. projectM := projectMap.(map[string]interface{})
  10782. var project models.HisProject
  10783. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10784. utils.ErrorLog("project_name")
  10785. return
  10786. }
  10787. project_name, _ := projectM["project_name"].(string)
  10788. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10789. err_log := models.ExportErrLog{
  10790. LogType: 6,
  10791. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10792. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10793. Status: 1,
  10794. CreateTime: time.Now().Unix(),
  10795. UpdateTime: time.Now().Unix(),
  10796. ExportTime: time.Now().Unix(),
  10797. }
  10798. service.CreateExportErrLog(&err_log)
  10799. continue
  10800. }
  10801. project.ProjectName = project_name
  10802. prices := projectM["price"].(string)
  10803. price, _ := strconv.ParseFloat(prices, 64)
  10804. if price <= 0 { //名字为空则生成一条导入错误日志
  10805. err_log := models.ExportErrLog{
  10806. LogType: 6,
  10807. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10808. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10809. Status: 1,
  10810. CreateTime: time.Now().Unix(),
  10811. UpdateTime: time.Now().Unix(),
  10812. ExportTime: time.Now().Unix(),
  10813. }
  10814. service.CreateExportErrLog(&err_log)
  10815. continue
  10816. }
  10817. project.Price = price
  10818. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10819. utils.ErrorLog("unit_id")
  10820. return
  10821. }
  10822. unit := projectM["unit"].(string)
  10823. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10824. err_log := models.ExportErrLog{
  10825. LogType: 6,
  10826. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10827. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10828. Status: 1,
  10829. CreateTime: time.Now().Unix(),
  10830. UpdateTime: time.Now().Unix(),
  10831. ExportTime: time.Now().Unix(),
  10832. }
  10833. service.CreateExportErrLog(&err_log)
  10834. continue
  10835. }
  10836. project.Unit = unit
  10837. cost_classify := projectM["cost_classify"].(string)
  10838. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10839. err_log := models.ExportErrLog{
  10840. LogType: 6,
  10841. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10842. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10843. Status: 1,
  10844. CreateTime: time.Now().Unix(),
  10845. UpdateTime: time.Now().Unix(),
  10846. ExportTime: time.Now().Unix(),
  10847. }
  10848. service.CreateExportErrLog(&err_log)
  10849. continue
  10850. }
  10851. var costClassify = "费用类别"
  10852. var cost_classify_id int64
  10853. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10854. if len(cost_classify) != 0 {
  10855. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10856. if errcode == gorm.ErrRecordNotFound {
  10857. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10858. dataconfig := models.DictDataconfig{
  10859. ParentId: costClassifyConfig.ID,
  10860. Module: "system",
  10861. OrgId: orgId,
  10862. Name: cost_classify,
  10863. FieldName: "",
  10864. Value: costConfig.Value + 1,
  10865. CreatedTime: "",
  10866. UpdatedTime: "",
  10867. CreateUserId: adminUser.AdminUser.Id,
  10868. Status: 1,
  10869. Remark: "",
  10870. DeleteIdSystem: 0,
  10871. Title: "",
  10872. Content: "",
  10873. Order: 0,
  10874. Code: "",
  10875. }
  10876. service.CreatedDicConfig(&dataconfig)
  10877. }
  10878. }
  10879. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10880. for _, it := range costClassList {
  10881. if cost_classify == it.Name {
  10882. cost_classify_id = int64(it.Value)
  10883. }
  10884. }
  10885. project.CostClassify = cost_classify_id
  10886. executive_section := projectM["executive_section"].(string)
  10887. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10888. err_log := models.ExportErrLog{
  10889. LogType: 6,
  10890. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10891. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10892. Status: 1,
  10893. CreateTime: time.Now().Unix(),
  10894. UpdateTime: time.Now().Unix(),
  10895. ExportTime: time.Now().Unix(),
  10896. }
  10897. service.CreateExportErrLog(&err_log)
  10898. continue
  10899. }
  10900. if len(executive_section) != 0 {
  10901. //查找科室是否有内容
  10902. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10903. if errcodedepart == gorm.ErrRecordNotFound {
  10904. department := models.XtHisDepartment{
  10905. Name: executive_section,
  10906. Status: 1,
  10907. UserOrgId: adminUser.CurrentOrgId,
  10908. CreatedTime: time.Now().Unix(),
  10909. }
  10910. service.CreateDePartment(&department)
  10911. }
  10912. }
  10913. var executive_section_id int64
  10914. departMentList, _ := service.GetAllDepartMent(orgId)
  10915. for _, it := range departMentList {
  10916. if executive_section == it.Name {
  10917. executive_section_id = it.ID
  10918. }
  10919. }
  10920. project.ExecutiveSection = executive_section_id
  10921. medical_coverage := projectM["medical_coverage"].(string)
  10922. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10923. err_log := models.ExportErrLog{
  10924. LogType: 6,
  10925. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10926. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10927. Status: 1,
  10928. CreateTime: time.Now().Unix(),
  10929. UpdateTime: time.Now().Unix(),
  10930. ExportTime: time.Now().Unix(),
  10931. }
  10932. service.CreateExportErrLog(&err_log)
  10933. continue
  10934. }
  10935. var medicalCoverage = "医保等级"
  10936. var medical_coverage_id int64
  10937. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10938. if len(medical_coverage) != 0 {
  10939. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10940. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10941. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10942. dataconfig := models.DictDataconfig{
  10943. ParentId: medicalCoverageConfig.ID,
  10944. Module: "system",
  10945. OrgId: orgId,
  10946. Name: medical_coverage,
  10947. FieldName: "",
  10948. Value: medicalCoverageConfig.Value + 1,
  10949. CreatedTime: "",
  10950. UpdatedTime: "",
  10951. CreateUserId: adminUser.AdminUser.Id,
  10952. Status: 1,
  10953. Remark: "",
  10954. DeleteIdSystem: 0,
  10955. Title: "",
  10956. Content: "",
  10957. Order: 0,
  10958. Code: "",
  10959. }
  10960. service.CreatedDicConfig(&dataconfig)
  10961. }
  10962. }
  10963. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10964. for _, it := range medicalCoverageList {
  10965. if medical_coverage == it.Name {
  10966. medical_coverage_id = int64(it.Value)
  10967. }
  10968. }
  10969. project.MedicalCoverage = medical_coverage_id
  10970. pinyin := projectM["pinyin"].(string)
  10971. project.Pinyin = pinyin
  10972. wubi := projectM["wubi"].(string)
  10973. project.Wubi = wubi
  10974. statistical_classification := projectM["statistical_classification"].(string)
  10975. var statisticalClassification = "统计分类"
  10976. var statistical_classification_id int64
  10977. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10978. if len(statistical_classification) != 0 {
  10979. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10980. if classificationerrcodes == gorm.ErrRecordNotFound {
  10981. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10982. dataconfig := models.DictDataconfig{
  10983. ParentId: classiFication.ID,
  10984. Module: "system",
  10985. OrgId: orgId,
  10986. Name: statistical_classification,
  10987. FieldName: "",
  10988. Value: classiFicationConfig.Value + 1,
  10989. CreatedTime: "",
  10990. UpdatedTime: "",
  10991. CreateUserId: adminUser.AdminUser.Id,
  10992. Status: 1,
  10993. Remark: "",
  10994. DeleteIdSystem: 0,
  10995. Title: "",
  10996. Content: "",
  10997. Order: 0,
  10998. Code: "",
  10999. }
  11000. service.CreatedDicConfig(&dataconfig)
  11001. }
  11002. }
  11003. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11004. for _, it := range classiFicationList {
  11005. if statistical_classification == it.Name {
  11006. statistical_classification_id = int64(it.Value)
  11007. }
  11008. }
  11009. project.StatisticalClassification = statistical_classification_id
  11010. disease_directory := int64(projectM["disease_directory"].(float64))
  11011. project.DiseaseDirectory = disease_directory
  11012. is_record := int64(projectM["is_record"].(float64))
  11013. project.IsRecord = is_record
  11014. medical_code := projectM["medical_code"].(string)
  11015. project.MedicalCode = medical_code
  11016. tube_color := projectM["tube_color"].(string)
  11017. var tubeColor = "试管颜色"
  11018. var tube_color_id int64
  11019. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11020. if len(tube_color) != 0 {
  11021. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11022. if errcodetube == gorm.ErrRecordNotFound {
  11023. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11024. dataconfig := models.DictDataconfig{
  11025. ParentId: tubeColorConfig.ID,
  11026. Module: "system",
  11027. OrgId: orgId,
  11028. Name: tube_color,
  11029. FieldName: "",
  11030. Value: tubeConfig.Value + 1,
  11031. CreatedTime: "",
  11032. UpdatedTime: "",
  11033. CreateUserId: adminUser.AdminUser.Id,
  11034. Status: 1,
  11035. Remark: "",
  11036. DeleteIdSystem: 0,
  11037. Title: "",
  11038. Content: "",
  11039. Order: 0,
  11040. Code: "",
  11041. }
  11042. service.CreatedDicConfig(&dataconfig)
  11043. }
  11044. }
  11045. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11046. for _, it := range tubeColorList {
  11047. if tube_color == it.Name {
  11048. tube_color_id = int64(it.Value)
  11049. }
  11050. }
  11051. project.TubeColor = tube_color_id
  11052. single_dose := projectM["single_dose"].(string)
  11053. project.SingleDose = single_dose
  11054. execution_frequency := projectM["execution_frequency"].(string)
  11055. project.ExecutionFrequency = execution_frequency
  11056. delivery_way := projectM["delivery_way"].(string)
  11057. project.DeliveryWay = delivery_way
  11058. number_days := projectM["number_days"].(string)
  11059. project.NumberDays = number_days
  11060. total := projectM["total"].(string)
  11061. project.Total = total
  11062. medical_status := int64(projectM["medical_status"].(float64))
  11063. project.MedicalStatus = medical_status
  11064. category := int64(projectM["category"].(float64))
  11065. project.Category = category
  11066. specail_project := int64(projectM["specail_project"].(float64))
  11067. project.SpecailProject = specail_project
  11068. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11069. project.SocialSecurityDirectoryCode = social_security_directory_code
  11070. remark := projectM["remark"].(string)
  11071. project.Remark = remark
  11072. record_date := projectM["record_date"].(string)
  11073. timeLayout := "2006-01-02"
  11074. loc, _ := time.LoadLocation("Local")
  11075. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11076. project.RecordDate = theTime.Unix()
  11077. projectList = append(projectList, &project)
  11078. }
  11079. export_time := time.Now().Unix()
  11080. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11081. if len(projectList) > 0 {
  11082. for _, item := range projectList {
  11083. hans := item.ProjectName // 要转换的汉字字符串
  11084. // 创建一个拼音转换器
  11085. p := pinyin.NewArgs()
  11086. // 将汉字转为拼音
  11087. pinyinSlice := pinyin.Pinyin(hans, p)
  11088. // 输出拼音
  11089. fmt.Println("Pinyin:", pinyinSlice)
  11090. // 获取首字母
  11091. firstLetter := ""
  11092. for _, py := range pinyinSlice {
  11093. if len(py) > 0 {
  11094. firstLetter += string(py[0][0])
  11095. }
  11096. }
  11097. item.FirstLetter = firstLetter
  11098. project := models.HisProject{
  11099. ProjectName: item.ProjectName,
  11100. Price: item.Price,
  11101. Unit: item.Unit,
  11102. CostClassify: item.CostClassify,
  11103. ExecutiveSection: item.ExecutiveSection,
  11104. MedicalCoverage: item.MedicalCoverage,
  11105. UserOrgId: orgId,
  11106. Status: 1,
  11107. CreatedTime: time.Now().Unix(),
  11108. Pinyin: item.Pinyin,
  11109. Wubi: item.Wubi,
  11110. StatisticalClassification: item.StatisticalClassification,
  11111. DiseaseDirectory: item.DiseaseDirectory,
  11112. IsRecord: item.IsRecord,
  11113. MedicalCode: item.MedicalCode,
  11114. TubeColor: item.TubeColor,
  11115. SingleDose: item.SingleDose,
  11116. DeliveryWay: item.DeliveryWay,
  11117. NumberDays: item.NumberDays,
  11118. Total: item.Total,
  11119. Category: item.Category,
  11120. MedicalStatus: item.MedicalStatus,
  11121. SpecailProject: item.SpecailProject,
  11122. RecordDate: item.RecordDate,
  11123. Remark: item.Remark,
  11124. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11125. ExecutionFrequency: item.ExecutionFrequency,
  11126. FirstLetter: item.FirstLetter,
  11127. }
  11128. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11129. if errcodeproject == gorm.ErrRecordNotFound {
  11130. service.CreateProjectInfomation(&project)
  11131. } else if errcodeproject == nil {
  11132. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11133. }
  11134. log := models.ExportLog{
  11135. LogType: 6,
  11136. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11137. TotalNum: int64(len(total_goods)),
  11138. FailNum: int64(len(errLogs)),
  11139. SuccessNum: int64(len(projectList)),
  11140. CreateTime: time.Now().Unix(),
  11141. UpdateTime: time.Now().Unix(),
  11142. ExportTime: export_time,
  11143. Status: 1,
  11144. }
  11145. service.CreateExportLog(&log)
  11146. c.ServeSuccessJSON(map[string]interface{}{
  11147. "msg": "导入成功",
  11148. "total_num": len(total_goods),
  11149. "success_num": len(projectList),
  11150. "fail_num": int64(len(errLogs)),
  11151. })
  11152. }
  11153. } else {
  11154. log := models.ExportLog{
  11155. LogType: 6,
  11156. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11157. TotalNum: int64(len(total_goods)),
  11158. FailNum: int64(len(errLogs)),
  11159. SuccessNum: int64(len(projectList)),
  11160. CreateTime: time.Now().Unix(),
  11161. UpdateTime: time.Now().Unix(),
  11162. ExportTime: export_time,
  11163. Status: 1,
  11164. }
  11165. service.CreateExportLog(&log)
  11166. c.ServeSuccessJSON(map[string]interface{}{
  11167. "msg": "导入成功",
  11168. "total_num": len(total_goods),
  11169. "success_num": len(projectList),
  11170. "fail_num": int64(len(errLogs)),
  11171. })
  11172. }
  11173. }
  11174. //func (this *HisApiController) EditProjectInformation(){
  11175. //
  11176. // id, _ := this.GetInt64("id")
  11177. // project_team := this.GetString("project_team")
  11178. // price := this.GetString("price")
  11179. // price_float, _ := strconv.ParseFloat(price, 64)
  11180. // pinyin := this.GetString("pinyin")
  11181. // wubi := this.GetString("wubi")
  11182. // tube_color, _ := this.GetInt64("tube_color")
  11183. // team_type, _ := this.GetInt64("team_type")
  11184. // remark := this.GetString("remark")
  11185. // ids := this.GetString("ids")
  11186. // item_id := this.GetString("item_id")
  11187. // projectTeam := models.XtHisProjectTeam{
  11188. // ProjectTeam: project_team,
  11189. // Price: price_float,
  11190. // Pinyin: pinyin,
  11191. // Wubi: wubi,
  11192. // TubeColor: tube_color,
  11193. // TeamType: team_type,
  11194. // Remark: remark,
  11195. // ProjectId: ids,
  11196. // ItemId: item_id,
  11197. // }
  11198. //
  11199. //
  11200. // dataBody := make(map[string]interface{}, 0)
  11201. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11202. // if err != nil {
  11203. // utils.ErrorLog(err.Error())
  11204. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11205. // return
  11206. // }
  11207. //
  11208. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11209. //
  11210. //
  11211. // if err != nil {
  11212. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11213. // return
  11214. // }
  11215. //
  11216. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11217. // infos, _ := dataBody["info"].([]interface{})
  11218. // if len(infos) > 0 {
  11219. // var ids []string
  11220. //
  11221. // for _, item := range infos {
  11222. // items := item.(map[string]interface{})
  11223. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11224. // utils.ErrorLog("id")
  11225. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11226. // return
  11227. // }
  11228. // id := int64(items["id"].(float64))
  11229. //
  11230. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11231. // utils.ErrorLog("type")
  11232. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11233. // return
  11234. // }
  11235. // types := int64(items["type"].(float64))
  11236. //
  11237. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11238. // utils.ErrorLog("number")
  11239. // }
  11240. //
  11241. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11242. //
  11243. // projectList := models.XtHisProjectList{
  11244. // Number: number,
  11245. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11246. // ProjectId: id,
  11247. // Status: 1,
  11248. // CreatedTime: time.Now().Unix(),
  11249. // UpdatedTime: time.Now().Unix(),
  11250. // TeamId: projectTeam.ID,
  11251. // Type: types,
  11252. // }
  11253. // list := projectList
  11254. //
  11255. // service.CreateProjectList(&list)
  11256. //
  11257. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11258. //
  11259. // }
  11260. // ids_str := strings.Join(ids, ",")
  11261. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11262. // service.SaveProjectTeam(&projectTeam)
  11263. // this.ServeSuccessJSON(map[string]interface{}{
  11264. // "projectTeam": projectTeam,
  11265. // })
  11266. // }
  11267. // }
  11268. //}
  11269. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11270. name := c.GetString("name")
  11271. mode_id, _ := c.GetInt64("mode", 0)
  11272. types, _ := c.GetInt64("type", 0)
  11273. patient_id, _ := c.GetInt64("patient_id", 0)
  11274. types = 1
  11275. adminInfo := c.GetAdminUserInfo()
  11276. template := &models.HisPrescriptionTemplate{
  11277. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11278. PatientId: patient_id,
  11279. Type: types,
  11280. Status: 1,
  11281. Ctime: time.Now().Unix(),
  11282. Mtime: time.Now().Unix(),
  11283. Name: name,
  11284. Mode: mode_id,
  11285. }
  11286. dataBody := make(map[string]interface{}, 0)
  11287. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11288. if err != nil {
  11289. utils.ErrorLog(err.Error())
  11290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11291. return
  11292. }
  11293. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11294. //如果已经存在记录则删除处方
  11295. if template_one.ID > 0 {
  11296. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11297. var ids []int64
  11298. var org_id int64
  11299. for _, item := range ps {
  11300. org_id = c.GetAdminUserInfo().CurrentOrgId
  11301. ids = append(ids, item.ID)
  11302. }
  11303. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11304. if err2 == nil {
  11305. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11306. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11307. if len(prescriptions) > 0 {
  11308. for _, item := range prescriptions {
  11309. items := item.(map[string]interface{})
  11310. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11311. utils.ErrorLog("type")
  11312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11313. return
  11314. }
  11315. types := int64(items["type"].(float64))
  11316. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11317. utils.ErrorLog("med_type")
  11318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11319. return
  11320. }
  11321. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11322. ctime := time.Now().Unix()
  11323. prescription := &models.HisPrescriptionInfoTemplate{
  11324. PatientId: patient_id,
  11325. UserOrgId: adminInfo.CurrentOrgId,
  11326. Ctime: ctime,
  11327. Mtime: ctime,
  11328. Type: types,
  11329. Modifier: adminInfo.AdminUser.Id,
  11330. Creator: adminInfo.AdminUser.Id,
  11331. Status: 1,
  11332. PTemplateId: template_one.ID,
  11333. MedType: med_type,
  11334. }
  11335. service.CreateHisPrescriptionInfoTemplate(prescription)
  11336. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11337. advices := items["advices"].([]interface{})
  11338. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11339. ctime := time.Now().Unix()
  11340. mtime := ctime
  11341. if len(advices) > 0 {
  11342. for _, advice := range advices {
  11343. var s models.HisPrescriptionAdviceTemplate
  11344. s.PrescriptionId = prescription.ID
  11345. s.AdviceType = 2
  11346. s.StopState = 2
  11347. s.ExecutionState = 2
  11348. s.Status = 1
  11349. s.UserOrgId = adminInfo.CurrentOrgId
  11350. s.CreatedTime = ctime
  11351. s.UpdatedTime = mtime
  11352. s.PatientId = patient_id
  11353. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11354. if errcode > 0 {
  11355. c.ServeFailJSONWithSGJErrorCode(errcode)
  11356. return
  11357. }
  11358. service.CreateHisPrescriptionAdviceTemplate(&s)
  11359. }
  11360. }
  11361. }
  11362. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11363. projects := items["project"].([]interface{})
  11364. if len(projects) > 0 {
  11365. for _, project := range projects {
  11366. var p models.HisPrescriptionProjectTemplate
  11367. p.PrescriptionId = prescription.ID
  11368. p.Ctime = time.Now().Unix()
  11369. p.Mtime = time.Now().Unix()
  11370. p.PatientId = patient_id
  11371. p.UserOrgId = adminInfo.CurrentOrgId
  11372. p.Status = 1
  11373. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11374. if errcode > 0 {
  11375. c.ServeFailJSONWithSGJErrorCode(errcode)
  11376. return
  11377. }
  11378. service.CreateHisPrescriptionProjectTemplate(&p)
  11379. }
  11380. }
  11381. }
  11382. }
  11383. c.ServeSuccessJSON(map[string]interface{}{
  11384. "msg": "创建成功",
  11385. })
  11386. }
  11387. }
  11388. } else {
  11389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11390. return
  11391. }
  11392. } else {
  11393. err3 := service.CreateHisPrescriptionTemplate(template)
  11394. if err3 == nil {
  11395. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11396. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11397. if len(prescriptions) > 0 {
  11398. for _, item := range prescriptions {
  11399. items := item.(map[string]interface{})
  11400. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11401. utils.ErrorLog("type")
  11402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11403. return
  11404. }
  11405. types := int64(items["type"].(float64))
  11406. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11407. utils.ErrorLog("med_type")
  11408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11409. return
  11410. }
  11411. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11412. ctime := time.Now().Unix()
  11413. prescription := &models.HisPrescriptionInfoTemplate{
  11414. PatientId: patient_id,
  11415. UserOrgId: adminInfo.CurrentOrgId,
  11416. Ctime: ctime,
  11417. Mtime: ctime,
  11418. Type: types,
  11419. Modifier: adminInfo.AdminUser.Id,
  11420. Creator: adminInfo.AdminUser.Id,
  11421. Status: 1,
  11422. PTemplateId: template.ID,
  11423. MedType: med_type,
  11424. }
  11425. service.CreateHisPrescriptionInfoTemplate(prescription)
  11426. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11427. advices := items["advices"].([]interface{})
  11428. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11429. ctime := time.Now().Unix()
  11430. mtime := ctime
  11431. if len(advices) > 0 {
  11432. for _, advice := range advices {
  11433. var s models.HisPrescriptionAdviceTemplate
  11434. s.PrescriptionId = prescription.ID
  11435. s.AdviceType = 2
  11436. s.StopState = 2
  11437. s.ExecutionState = 2
  11438. s.Status = 1
  11439. s.UserOrgId = adminInfo.CurrentOrgId
  11440. s.CreatedTime = ctime
  11441. s.UpdatedTime = mtime
  11442. s.PatientId = patient_id
  11443. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11444. if errcode > 0 {
  11445. c.ServeFailJSONWithSGJErrorCode(errcode)
  11446. return
  11447. }
  11448. service.CreateHisPrescriptionAdviceTemplate(&s)
  11449. }
  11450. }
  11451. }
  11452. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11453. projects := items["project"].([]interface{})
  11454. if len(projects) > 0 {
  11455. for _, project := range projects {
  11456. var p models.HisPrescriptionProjectTemplate
  11457. p.PrescriptionId = prescription.ID
  11458. p.Ctime = time.Now().Unix()
  11459. p.Mtime = time.Now().Unix()
  11460. p.PatientId = patient_id
  11461. p.UserOrgId = adminInfo.CurrentOrgId
  11462. p.Status = 1
  11463. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11464. if errcode > 0 {
  11465. c.ServeFailJSONWithSGJErrorCode(errcode)
  11466. return
  11467. }
  11468. service.CreateHisPrescriptionProjectTemplate(&p)
  11469. }
  11470. }
  11471. }
  11472. }
  11473. c.ServeSuccessJSON(map[string]interface{}{
  11474. "msg": "创建成功",
  11475. })
  11476. }
  11477. }
  11478. } else {
  11479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11480. return
  11481. }
  11482. }
  11483. }
  11484. func (c *HisApiController) PreSettle() {
  11485. id, _ := c.GetInt64("id")
  11486. record_time := c.GetString("record_time")
  11487. his_patient_id, _ := c.GetInt64("his_patient_id")
  11488. timeLayout := "2006-01-02"
  11489. loc, _ := time.LoadLocation("Local")
  11490. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11491. diagnosis_id := c.GetString("diagnosis")
  11492. sick_type, _ := c.GetInt64("sick_type")
  11493. reg_type, _ := c.GetInt64("p_type")
  11494. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11495. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11496. if err != nil {
  11497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11498. return
  11499. }
  11500. recordDateTime := theTime.Unix()
  11501. adminUser := c.GetAdminUserInfo()
  11502. var prescriptions []*models.HisPrescription
  11503. var start_time int64
  11504. var end_time int64
  11505. ids_str := c.GetString("ids")
  11506. ids_arr := strings.Split(ids_str, ",")
  11507. fmt.Println(reg_type)
  11508. if settle_accounts_type == 1 { //日结
  11509. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11510. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11511. } else {
  11512. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11513. }
  11514. fmt.Println(prescriptions)
  11515. } else { //月结
  11516. start_time_str := c.GetString("start_time")
  11517. end_time_str := c.GetString("end_time")
  11518. timeLayout := "2006-01-02"
  11519. loc, _ := time.LoadLocation("Local")
  11520. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11521. if err != nil {
  11522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11523. return
  11524. }
  11525. recordStartTime := theStartTime.Unix()
  11526. start_time = recordStartTime
  11527. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11528. if err != nil {
  11529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11530. return
  11531. }
  11532. recordEndTime := theEndTime.Unix()
  11533. end_time = recordEndTime
  11534. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11535. }
  11536. if reg_type == 1111 || reg_type == 1112 {
  11537. reg_type = 11
  11538. }
  11539. timestamp := time.Now().Unix()
  11540. tempTime := time.Unix(timestamp, 0)
  11541. timeFormat := tempTime.Format("20060102150405")
  11542. chrgBchno := rand.Intn(100000) + 10000
  11543. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11544. strconv.FormatInt(his.PatientId, 10)
  11545. var ids []int64
  11546. for _, item := range prescriptions {
  11547. ids = append(ids, item.ID)
  11548. }
  11549. fmt.Println(ids)
  11550. var total float64
  11551. for _, item := range prescriptions {
  11552. fmt.Println(item)
  11553. if item.Type == 1 { //药品
  11554. for _, subItem := range item.HisDoctorAdviceInfo {
  11555. total = total + (subItem.Price * subItem.PrescribingNumber)
  11556. }
  11557. }
  11558. if item.Type == 2 { //项目
  11559. for _, subItem := range item.HisPrescriptionProject {
  11560. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11561. total = total + (subItem.Price * cnt)
  11562. }
  11563. }
  11564. for _, subItem := range item.HisAdditionalCharge {
  11565. total = total + (subItem.Price * float64(subItem.Count))
  11566. }
  11567. }
  11568. allTotal := fmt.Sprintf("%.2f", total)
  11569. totals, _ := strconv.ParseFloat(allTotal, 64)
  11570. order := &models.HisOrder{
  11571. UserOrgId: adminUser.CurrentOrgId,
  11572. HisPatientId: his.ID,
  11573. PatientId: id,
  11574. SettleAccountsDate: recordDateTime,
  11575. Ctime: time.Now().Unix(),
  11576. Mtime: time.Now().Unix(),
  11577. Status: 1,
  11578. OrderStatus: 1,
  11579. MdtrtId: his.Number,
  11580. Number: chrg_bchno,
  11581. MedfeeSumamt: totals,
  11582. SettleEndTime: end_time,
  11583. SettleStartTime: start_time,
  11584. SettleType: settle_accounts_type,
  11585. PsnPartAmt: totals,
  11586. PsnCashPay: totals,
  11587. PType: 2,
  11588. IsPre: 1,
  11589. MedType: strconv.Itoa(int(reg_type)),
  11590. Diagnosis: diagnosis_id,
  11591. }
  11592. err = service.CreateOrder(order)
  11593. if err != nil {
  11594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11595. return
  11596. }
  11597. var customs []*Custom
  11598. for _, item := range prescriptions {
  11599. fmt.Println(item.Type)
  11600. if item.Type == 1 { //药品
  11601. for _, subItem := range item.HisDoctorAdviceInfo {
  11602. cus := &Custom{
  11603. AdviceId: subItem.ID,
  11604. ProjectId: 0,
  11605. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11606. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11607. FeedetlSn: subItem.FeedetlSn,
  11608. Price: fmt.Sprintf("%.2f", subItem.Price),
  11609. MedListCodg: subItem.MedListCodg,
  11610. Type: 1,
  11611. }
  11612. customs = append(customs, cus)
  11613. }
  11614. }
  11615. if item.Type == 2 { //项目
  11616. for _, subItem := range item.HisPrescriptionProject {
  11617. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11618. cus := &Custom{
  11619. AdviceId: 0,
  11620. ProjectId: subItem.ID,
  11621. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11622. Cut: fmt.Sprintf("%.2f", cnt),
  11623. FeedetlSn: subItem.FeedetlSn,
  11624. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11625. MedListCodg: subItem.MedListCodg,
  11626. Type: 2,
  11627. }
  11628. customs = append(customs, cus)
  11629. }
  11630. }
  11631. for _, item := range item.HisAdditionalCharge {
  11632. cus := &Custom{
  11633. ItemId: item.ID,
  11634. AdviceId: 0,
  11635. ProjectId: 0,
  11636. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11637. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11638. FeedetlSn: item.FeedetlSn,
  11639. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11640. MedListCodg: item.XtHisAddtionConfig.Code,
  11641. Type: 3,
  11642. }
  11643. customs = append(customs, cus)
  11644. }
  11645. }
  11646. fmt.Println(customs)
  11647. for _, item := range customs {
  11648. var advice_id int64 = 0
  11649. var project_id int64 = 0
  11650. var item_id int64 = 0
  11651. var types int64 = 0
  11652. if item.Type == 1 {
  11653. advice_id = item.AdviceId
  11654. project_id = 0
  11655. item_id = 0
  11656. } else if item.Type == 2 {
  11657. advice_id = 0
  11658. item_id = 0
  11659. project_id = item.ProjectId
  11660. } else if item.Type == 3 {
  11661. advice_id = 0
  11662. item_id = item.ItemId
  11663. project_id = 0
  11664. }
  11665. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11666. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11667. pric, _ := strconv.ParseFloat(item.Price, 32)
  11668. info := &models.HisOrderInfo{
  11669. OrderNumber: order.Number,
  11670. UploadDate: time.Now().Unix(),
  11671. AdviceId: advice_id,
  11672. DetItemFeeSumamt: detItemFeeSumamt,
  11673. Cnt: cut,
  11674. Pric: pric,
  11675. PatientId: id,
  11676. Status: 1,
  11677. Mtime: time.Now().Unix(),
  11678. Ctime: time.Now().Unix(),
  11679. UserOrgId: adminUser.CurrentOrgId,
  11680. HisPatientId: his.ID,
  11681. OrderId: order.ID,
  11682. ProjectId: project_id,
  11683. Type: types,
  11684. ItemId: item_id,
  11685. }
  11686. service.CreateOrderInfo(info)
  11687. }
  11688. his.SickType = sick_type
  11689. service.UpdataHisPateint(&his)
  11690. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11691. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11692. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11693. if err == nil {
  11694. c.ServeSuccessJSON(map[string]interface{}{
  11695. "msg": "结算成功",
  11696. })
  11697. }
  11698. }
  11699. type CustomOrderInfo struct {
  11700. Name string
  11701. Spec string
  11702. Unit string
  11703. Count float64
  11704. Price float64
  11705. Total float64
  11706. }
  11707. func (c *HisApiController) GetPrivateExpensesInfo() {
  11708. order_id, _ := c.GetInt64("id", 0)
  11709. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11710. order, _ := service.GetHisOrderByID(order_id)
  11711. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11712. if order.ID == 0 {
  11713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11714. return
  11715. }
  11716. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11717. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11718. org_id := c.GetAdminUserInfo().CurrentOrgId
  11719. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11720. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11721. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11722. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11723. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11724. //var orderInfos_four []*models.HisOrderInfoTwo
  11725. //for _, item := range orderInfos_three {
  11726. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11727. // item.HisPrescriptionProject.IsCheckTeam = 1
  11728. // orderInfos_four = append(orderInfos_four, item)
  11729. //
  11730. // }
  11731. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11732. // item.HisPrescriptionProject.IsCheckTeam = 2
  11733. // orderInfos_two = append(orderInfos_two, item)
  11734. // }
  11735. //}
  11736. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11737. //var cus_slice []CustomOrderInfo
  11738. //for _, item := range new_order_info {
  11739. // var cus CustomOrderInfo
  11740. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11741. // cus.Unit = ""
  11742. // cus.Spec = ""
  11743. // var total float64
  11744. // for _, subItem := range orderInfos_four {
  11745. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11746. // total = total + subItem.DetItemFeeSumamt
  11747. // fmt.Println(subItem.DetItemFeeSumamt)
  11748. // }
  11749. // }
  11750. // cus.Count = 1
  11751. // cus.Total = total
  11752. // cus_slice = append(cus_slice, cus)
  11753. //}
  11754. orderInfos = append(orderInfos, orderInfos_two...)
  11755. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11756. //orderInfos = append(orderInfos, orderInfos_three...)
  11757. //}/**/
  11758. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11759. c.ServeSuccessJSON(map[string]interface{}{
  11760. "order": order,
  11761. "order_info": orderInfos,
  11762. "patient": patient,
  11763. "admin_info": adminInfo,
  11764. "his": his,
  11765. "current_admin": role,
  11766. "org_config": miConfig,
  11767. //"new_order_info": cus_slice,
  11768. })
  11769. }
  11770. func (this *HisApiController) ChangeMedType() {
  11771. med_type := this.GetString("med_type")
  11772. old_med_type := this.GetString("old_med_type")
  11773. ids := this.GetString("ids")
  11774. settle_type, _ := this.GetInt64("settle_type")
  11775. start_time := this.GetString("start_time")
  11776. end_time := this.GetString("end_time")
  11777. ids_arr := strings.Split(ids, ",")
  11778. if settle_type == 1 { //日结
  11779. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11780. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11781. prescription.MedType = med_type
  11782. err := service.SaveHisPrescriptionTwo(&prescription)
  11783. if err == nil {
  11784. this.ServeSuccessJSON(map[string]interface{}{
  11785. "msg": "修改成功",
  11786. })
  11787. } else {
  11788. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11789. return
  11790. }
  11791. } else if settle_type == 2 {
  11792. timeLayout := "2006-01-02"
  11793. loc, _ := time.LoadLocation("Local")
  11794. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11795. if err != nil {
  11796. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11797. return
  11798. }
  11799. recordStartTime := theStartTime.Unix()
  11800. start_time_timestamp := recordStartTime
  11801. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11802. if err != nil {
  11803. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11804. return
  11805. }
  11806. recordEndTime := theEndTime.Unix()
  11807. end_time_timestamp := recordEndTime
  11808. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11809. if updateErr == nil {
  11810. this.ServeSuccessJSON(map[string]interface{}{
  11811. "msg": "修改成功",
  11812. })
  11813. } else {
  11814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11815. return
  11816. }
  11817. }
  11818. }
  11819. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11820. patient_id, _ := c.GetInt64("patient_id")
  11821. his_patient_id, _ := c.GetInt64("his_patient_id")
  11822. record_date := c.GetString("record_date")
  11823. start_time := c.GetString("start_time")
  11824. end_time := c.GetString("end_time")
  11825. order_status, _ := c.GetInt64("type", 0)
  11826. p_type, _ := c.GetInt64("p_type", 0)
  11827. order_id, _ := c.GetInt64("order_id", 0)
  11828. timeLayout := "2006-01-02"
  11829. loc, _ := time.LoadLocation("Local")
  11830. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11831. if err != nil {
  11832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11833. return
  11834. }
  11835. recordDateTime := theTime.Unix()
  11836. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11837. if err != nil {
  11838. }
  11839. startRecordDateTime := startTime.Unix()
  11840. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11841. if err != nil {
  11842. }
  11843. endRecordDateTime := endTime.Unix()
  11844. admin := c.GetAdminUserInfo()
  11845. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11846. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11847. order, _ := service.GetHisOrderByID(order_id)
  11848. var monthPrescriptions []*models.HisPrescription
  11849. if order_status == 1 || order_status == 0 {
  11850. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11851. } else if order_status == 2 {
  11852. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11853. }
  11854. var settle_total float64
  11855. for _, item := range monthPrescriptions {
  11856. if len(item.HisPrescriptionProject) > 0 {
  11857. for _, subItem := range item.HisPrescriptionProject {
  11858. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11859. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11860. settle_total = settle_total + total
  11861. }
  11862. }
  11863. if len(item.HisDoctorAdviceInfo) > 0 {
  11864. for _, subItem := range item.HisDoctorAdviceInfo {
  11865. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11866. settle_total = settle_total + total
  11867. }
  11868. }
  11869. }
  11870. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11871. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11872. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11873. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11874. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11875. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11876. //获取所有科室信息
  11877. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11878. var dia string
  11879. for _, item := range month_p_info {
  11880. if len(dia) == 0 {
  11881. dia = item.Diagnosis
  11882. } else {
  11883. dia = dia + "," + item.Diagnosis
  11884. }
  11885. }
  11886. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11887. dia_arr = removeEmptyStrings(dia_arr)
  11888. c.ServeSuccessJSON(map[string]interface{}{
  11889. "his_info": his_patient_info,
  11890. "xt_info": xt_patient_info,
  11891. "case_history": case_history,
  11892. "info": patientPrescriptionInfo,
  11893. "last_info": lastPatientPrescriptionInfo,
  11894. "month_prescriptions": monthPrescriptions,
  11895. "order": order,
  11896. "doctors": doctors,
  11897. "department": department,
  11898. "settle_total": settle_total,
  11899. "dia_arr": dia_arr,
  11900. })
  11901. return
  11902. }
  11903. func removeEmptyStrings(input []string) []string {
  11904. var output []string
  11905. for _, s := range input {
  11906. if s != "" {
  11907. output = append(output, s)
  11908. }
  11909. }
  11910. return output
  11911. }
  11912. func removeDuplicates(input []string) []string {
  11913. seen := make(map[string]bool)
  11914. output := []string{}
  11915. for _, s := range input {
  11916. if _, exists := seen[s]; !exists {
  11917. seen[s] = true
  11918. output = append(output, s)
  11919. }
  11920. }
  11921. return output
  11922. }
  11923. func (c *HisApiController) GetHisMonthPatientInfo() {
  11924. patient_id, _ := c.GetInt64("patient_id")
  11925. his_patient_id, _ := c.GetInt64("his_patient_id")
  11926. record_date := c.GetString("record_date")
  11927. number := c.GetString("number")
  11928. start_time := c.GetString("start_time")
  11929. end_time := c.GetString("end_time")
  11930. p_type, _ := c.GetInt64("p_type")
  11931. timeLayout := "2006-01-02"
  11932. loc, _ := time.LoadLocation("Local")
  11933. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11934. if err != nil {
  11935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11936. return
  11937. }
  11938. recordDateTime := theTime.Unix()
  11939. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11940. if err != nil {
  11941. }
  11942. startRecordDateTime := startTime.Unix()
  11943. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11944. if err != nil {
  11945. }
  11946. endRecordDateTime := endTime.Unix()
  11947. admin := c.GetAdminUserInfo()
  11948. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11949. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11950. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11951. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11952. var settle_total float64
  11953. for _, item := range monthPrescriptions {
  11954. if len(item.HisPrescriptionProject) > 0 {
  11955. for _, subItem := range item.HisPrescriptionProject {
  11956. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11957. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11958. settle_total = settle_total + total
  11959. }
  11960. }
  11961. if len(item.HisDoctorAdviceInfo) > 0 {
  11962. for _, subItem := range item.HisDoctorAdviceInfo {
  11963. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11964. settle_total = settle_total + total
  11965. }
  11966. }
  11967. }
  11968. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11969. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11970. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11971. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11972. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11973. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11974. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11975. //获取所有科室信息
  11976. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11977. c.ServeSuccessJSON(map[string]interface{}{
  11978. "his_info": his_patient_info,
  11979. "xt_info": xt_patient_info,
  11980. "case_history": case_history,
  11981. "info": patientPrescriptionInfo,
  11982. "month_prescriptions": monthPrescriptions,
  11983. "order": order,
  11984. "doctors": doctors,
  11985. "department": department,
  11986. "count": count,
  11987. "drugStockConfig": drugStockConfig,
  11988. "last_info": lastPatientPrescriptionInfo,
  11989. "settle_total": settle_total,
  11990. })
  11991. return
  11992. }
  11993. func (c *HisApiController) GetAllOrder() {
  11994. org_id := c.GetAdminUserInfo().CurrentOrgId
  11995. orders, _ := service.GetNewHisOrderList(org_id)
  11996. c.ServeSuccessJSON(map[string]interface{}{
  11997. "order": orders,
  11998. })
  11999. return
  12000. }
  12001. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12002. newArr = make([]*models.HisOrderInfoTwo, 0)
  12003. for i := 0; i < len(arr); i++ {
  12004. repeat := false
  12005. for j := i + 1; j < len(arr); j++ {
  12006. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12007. repeat = true
  12008. break
  12009. }
  12010. }
  12011. if !repeat {
  12012. newArr = append(newArr, arr[i])
  12013. }
  12014. }
  12015. return
  12016. }
  12017. // 修改处方退库操作 参数传修改之前的处方数据
  12018. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12019. if advice.ExecutionState == 1 {
  12020. //查询该病人该药品是否有库存记录
  12021. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12022. if errcode == gorm.ErrRecordNotFound {
  12023. } else {
  12024. //退库
  12025. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12026. if advice.PrescribingNumberUnit == drug.MinUnit {
  12027. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12028. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12029. //退库
  12030. warehouseInfo := models.DrugWarehouseInfo{
  12031. StockMinNumber: prescribingNumber,
  12032. }
  12033. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12034. operation_time := time.Now().Unix()
  12035. creater := advice.AdviceDoctor
  12036. ctime := time.Now().Unix()
  12037. timeStr := time.Now().Format("2006-01-02")
  12038. timeArr := strings.Split(timeStr, "-")
  12039. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12040. total = total + 1
  12041. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12042. cancelStock := models.DrugCancelStock{
  12043. OrderNumber: orderNumber,
  12044. OperaTime: operation_time,
  12045. OrgId: advice.UserOrgId,
  12046. Creater: creater,
  12047. Ctime: ctime,
  12048. Status: 1,
  12049. ReturnTime: advice.AdviceDate,
  12050. Dealer: info.Dealer,
  12051. Manufacturer: info.Manufacturer,
  12052. Type: 1,
  12053. }
  12054. service.AddSigleDrugCancelStock(&cancelStock)
  12055. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12056. dealer, _ := service.GetDealerById(info.Dealer)
  12057. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12058. cancelStockInfo := models.DrugCancelStockInfo{
  12059. OrderNumber: cancelInfo.OrderNumber,
  12060. CancelStockId: cancelInfo.ID,
  12061. DrugId: info.DrugId,
  12062. Count: info.Count,
  12063. Status: 1,
  12064. Ctime: ctime,
  12065. OrgId: advice.UserOrgId,
  12066. Type: 1,
  12067. Manufacturer: manufactureName.ManufacturerName,
  12068. Dealer: dealer.DealerName,
  12069. Total: 0,
  12070. RetailPrice: info.RetailPrice,
  12071. RetailTotalPrice: info.RetailTotalPrice,
  12072. Price: info.Price,
  12073. RegisterAccount: "",
  12074. Remark: info.Remark,
  12075. BatchNumber: info.BatchNumber,
  12076. MaxUnit: info.CountUnit,
  12077. ProductDate: info.ProductDate,
  12078. ExpiryDate: info.ExpiryDate,
  12079. BatchNumberId: info.WarehouseInfoId,
  12080. }
  12081. flow := models.DrugFlow{
  12082. WarehousingId: 0,
  12083. DrugId: info.DrugId,
  12084. Number: "",
  12085. BatchNumber: info.BatchNumber,
  12086. Count: info.Count,
  12087. UserOrgId: advice.UserOrgId,
  12088. PatientId: 0,
  12089. SystemTime: ctime,
  12090. ConsumableType: 4,
  12091. IsSys: 0,
  12092. WarehousingOrder: "",
  12093. WarehouseOutId: 0,
  12094. WarehouseOutOrderNumber: "",
  12095. IsEdit: 0,
  12096. CancelStockId: cancelStock.ID,
  12097. CancelOrderNumber: cancelStock.OrderNumber,
  12098. Manufacturer: info.Manufacturer,
  12099. Dealer: info.Dealer,
  12100. Creator: advice.UserOrgId,
  12101. UpdateCreator: 0,
  12102. Status: 1,
  12103. Ctime: time.Now().Unix(),
  12104. Mtime: 0,
  12105. Price: info.Price,
  12106. WarehousingDetailId: 0,
  12107. WarehouseOutDetailId: 0,
  12108. CancelOutDetailId: 0,
  12109. ExpireDate: info.ExpiryDate,
  12110. ProductDate: info.ProductDate,
  12111. MaxUnit: info.CountUnit,
  12112. MinUnit: "",
  12113. }
  12114. service.CreatedCancelStock(cancelStockInfo)
  12115. service.CreateDrugFlowOne(flow)
  12116. } else {
  12117. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12118. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12119. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12120. warehouseInfo := models.DrugWarehouseInfo{
  12121. StockMinNumber: prescribingNumber,
  12122. }
  12123. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12124. }
  12125. operation_time := time.Now().Unix()
  12126. creater := advice.AdviceDoctor
  12127. ctime := time.Now().Unix()
  12128. timeStr := time.Now().Format("2006-01-02")
  12129. timeArr := strings.Split(timeStr, "-")
  12130. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12131. total = total + 1
  12132. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12133. cancelStock := models.DrugCancelStock{
  12134. OrderNumber: orderNumber,
  12135. OperaTime: operation_time,
  12136. OrgId: advice.UserOrgId,
  12137. Creater: creater,
  12138. Ctime: ctime,
  12139. Status: 1,
  12140. ReturnTime: advice.AdviceDate,
  12141. Dealer: info.Dealer,
  12142. Manufacturer: info.Manufacturer,
  12143. Type: 1,
  12144. }
  12145. service.AddSigleDrugCancelStock(&cancelStock)
  12146. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12147. dealer, _ := service.GetDealerById(info.Dealer)
  12148. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12149. cancelStockInfo := models.DrugCancelStockInfo{
  12150. OrderNumber: cancelInfo.OrderNumber,
  12151. CancelStockId: cancelInfo.ID,
  12152. DrugId: info.DrugId,
  12153. Count: info.Count,
  12154. Status: 1,
  12155. Ctime: ctime,
  12156. OrgId: advice.UserOrgId,
  12157. Type: 1,
  12158. Manufacturer: manufactureName.ManufacturerName,
  12159. Dealer: dealer.DealerName,
  12160. Total: 0,
  12161. RetailPrice: info.RetailPrice,
  12162. RetailTotalPrice: info.RetailTotalPrice,
  12163. Price: info.Price,
  12164. RegisterAccount: "",
  12165. Remark: info.Remark,
  12166. BatchNumber: info.BatchNumber,
  12167. MaxUnit: info.CountUnit,
  12168. ProductDate: info.ProductDate,
  12169. ExpiryDate: info.ExpiryDate,
  12170. BatchNumberId: info.WarehouseInfoId,
  12171. }
  12172. flow := models.DrugFlow{
  12173. WarehousingId: 0,
  12174. DrugId: info.DrugId,
  12175. Number: "",
  12176. BatchNumber: info.BatchNumber,
  12177. Count: info.Count,
  12178. UserOrgId: advice.UserOrgId,
  12179. PatientId: 0,
  12180. SystemTime: ctime,
  12181. ConsumableType: 4,
  12182. IsSys: 0,
  12183. WarehousingOrder: "",
  12184. WarehouseOutId: 0,
  12185. WarehouseOutOrderNumber: "",
  12186. IsEdit: 0,
  12187. CancelStockId: cancelStock.ID,
  12188. CancelOrderNumber: cancelStock.OrderNumber,
  12189. Manufacturer: info.Manufacturer,
  12190. Dealer: info.Dealer,
  12191. Creator: advice.AdviceDoctor,
  12192. UpdateCreator: 0,
  12193. Status: 1,
  12194. Ctime: time.Now().Unix(),
  12195. Mtime: 0,
  12196. Price: info.Price,
  12197. WarehousingDetailId: 0,
  12198. WarehouseOutDetailId: 0,
  12199. CancelOutDetailId: 0,
  12200. ExpireDate: info.ExpiryDate,
  12201. ProductDate: info.ProductDate,
  12202. MaxUnit: info.CountUnit,
  12203. MinUnit: "",
  12204. }
  12205. service.CreatedCancelStock(cancelStockInfo)
  12206. service.CreateDrugFlowOne(flow)
  12207. }
  12208. }
  12209. }
  12210. return err
  12211. }
  12212. func (this *HisApiController) DeleteNCDS() {
  12213. id, _ := this.GetInt64("id", 0)
  12214. if id > 0 {
  12215. service.DeletePsnNCDSRecordById(id)
  12216. this.ServeSuccessJSON(map[string]interface{}{
  12217. "msg": "删除成功",
  12218. })
  12219. } else {
  12220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12221. return
  12222. }
  12223. }
  12224. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12225. id, _ := c.GetInt64("id")
  12226. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12227. c.ServeSuccessJSON(map[string]interface{}{
  12228. "advice": advice,
  12229. })
  12230. return
  12231. }
  12232. func (c *HisApiController) GetHisMonthChargePatientList() {
  12233. record_date := c.GetString("record_date")
  12234. start_time := c.GetString("start_time")
  12235. end_time := c.GetString("end_time")
  12236. timeLayout := "2006-01-02"
  12237. loc, _ := time.LoadLocation("Local")
  12238. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12239. if err != nil {
  12240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12241. return
  12242. }
  12243. if err != nil {
  12244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12245. return
  12246. }
  12247. recordDateTime := theTime.Unix()
  12248. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12249. if err != nil {
  12250. }
  12251. startRecordDateTime := startTime.Unix()
  12252. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12253. if err != nil {
  12254. }
  12255. endRecordDateTime := endTime.Unix()
  12256. adminInfo := c.GetAdminUserInfo()
  12257. var tempMonthChargePatients []*service.MonthChargePatients
  12258. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12259. for _, item := range tempPatients {
  12260. //过滤没有处方的
  12261. if len(item.HisPrescription) == 0 {
  12262. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12263. }
  12264. }
  12265. c.ServeSuccessJSON(map[string]interface{}{
  12266. "list": tempMonthChargePatients,
  12267. })
  12268. }
  12269. // PrescriptionDifference 医嘱数量差值结构体
  12270. type PrescriptionDrugDifference struct {
  12271. DrugID int64 //基础库药品id
  12272. ID int64 //医嘱id
  12273. Difference float64 //差值
  12274. Unit string //单位
  12275. }
  12276. type PrescriptionGoodDifference struct {
  12277. GoodID int64 //基础库项目耗材id
  12278. ID int64 //医嘱id
  12279. Difference int64 //差值
  12280. Unit string //单位
  12281. Type int64 //类型
  12282. }
  12283. type EditCustomData struct {
  12284. adviceList []*models.HisDoctorAdviceInfo
  12285. projectList []*models.HisPrescriptionProject
  12286. }
  12287. type SrcCustomData struct {
  12288. adviceList []*models.HisDoctorAdviceInfo
  12289. projectList []*models.HisPrescriptionProject
  12290. }
  12291. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12292. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12293. differences := make([]*PrescriptionDrugDifference, 0)
  12294. // 创建一个 map 来存储第一个切片中的药品信息
  12295. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12296. for _, advice := range firstPrescription {
  12297. firstMap[advice.DrugId] = advice
  12298. }
  12299. // 遍历第二个切片中的药品信息,并比较数量差值
  12300. for _, advice := range secondPrescription {
  12301. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12302. diff := &PrescriptionDrugDifference{
  12303. DrugID: advice.DrugId,
  12304. ID: firstAdvice.ID,
  12305. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12306. Unit: firstAdvice.PrescribingNumberUnit,
  12307. }
  12308. differences = append(differences, diff)
  12309. }
  12310. }
  12311. return differences
  12312. }
  12313. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12314. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12315. differences := make([]*PrescriptionGoodDifference, 0)
  12316. // 创建一个 map 来存储第一个切片中的耗材信息
  12317. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12318. for _, good := range firstPrescription {
  12319. firstMap[good.ProjectId] = good
  12320. }
  12321. // 遍历第二个切片中的耗材信息,并比较数量差值
  12322. for _, good := range secondPrescription {
  12323. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12324. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12325. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12326. diff := &PrescriptionGoodDifference{
  12327. GoodID: good.ProjectId,
  12328. ID: firstGood.ID,
  12329. Difference: count - firstCount,
  12330. Unit: firstGood.Unit,
  12331. Type: firstGood.Type,
  12332. }
  12333. differences = append(differences, diff)
  12334. }
  12335. }
  12336. return differences
  12337. }
  12338. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12339. var adviceList []*models.HisDoctorAdviceInfo
  12340. var projectList []*models.HisPrescriptionProject
  12341. var advice_ids []int64
  12342. var project_ids []int64
  12343. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12344. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12345. //var tempPrescription *models.HisPrescriptionProjectscription
  12346. if len(prescriptions) > 0 {
  12347. for _, item := range prescriptions {
  12348. items := item.(map[string]interface{})
  12349. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12350. advices := items["advices"].([]interface{})
  12351. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12352. groupNo := int64(0)
  12353. ctime := time.Now().Unix()
  12354. mtime := ctime
  12355. if len(advices) > 0 {
  12356. for _, advice := range advices {
  12357. var s models.HisDoctorAdviceInfo
  12358. s.AdviceType = 2
  12359. s.StopState = 2
  12360. s.ExecutionState = 2
  12361. s.Status = 1
  12362. s.Groupno = groupNo
  12363. s.CreatedTime = ctime
  12364. s.UpdatedTime = mtime
  12365. s.IsSettle = 2
  12366. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12367. //存储切片中
  12368. if s.ID > 0 {
  12369. advice_ids = append(advice_ids, s.ID)
  12370. adviceList = append(adviceList, &s)
  12371. }
  12372. }
  12373. }
  12374. }
  12375. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12376. projects := items["project"].([]interface{})
  12377. if len(projects) > 0 {
  12378. for _, project := range projects {
  12379. var p models.HisPrescriptionProject
  12380. p.Ctime = time.Now().Unix()
  12381. p.Mtime = time.Now().Unix()
  12382. p.Status = 1
  12383. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12384. if p.ID > 0 {
  12385. project_ids = append(project_ids, p.ID)
  12386. projectList = append(projectList, &p)
  12387. }
  12388. }
  12389. }
  12390. }
  12391. }
  12392. }
  12393. }
  12394. editCustomData.projectList = projectList
  12395. editCustomData.adviceList = adviceList
  12396. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12397. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12398. srcCustomData.adviceList = list
  12399. srcCustomData.projectList = list2
  12400. return
  12401. }